traceop.ps 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. % Copyright (C) 1992, 1993, 1994, 1999 Aladdin Enterprises. All rights reserved.
  2. %
  3. % This file is part of AFPL Ghostscript.
  4. %
  5. % AFPL Ghostscript is distributed with NO WARRANTY OF ANY KIND. No author or
  6. % distributor accepts any responsibility for the consequences of using it, or
  7. % for whether it serves any particular purpose or works at all, unless he or
  8. % she says so in writing. Refer to the Aladdin Free Public License (the
  9. % "License") for full details.
  10. %
  11. % Every copy of AFPL Ghostscript must include a copy of the License, normally
  12. % in a plain ASCII text file named PUBLIC. The License grants you the right
  13. % to copy, modify and redistribute AFPL Ghostscript, but only under certain
  14. % conditions described in the License. Among other things, the License
  15. % requires that the copyright notice and this notice be preserved on all
  16. % copies.
  17. % $Id: traceop.ps,v 1.2 2000/09/19 18:29:11 lpd Exp $
  18. % Trace individual operators or procedures.
  19. % <opref> is <opname> or <opname> <dict>
  20. % (dict defaults to dict where op is currently defined, if writable;
  21. % otherwise uses userdict)
  22. % <opref> traceop prints vmem usage before;
  23. % <opref> <numargs|preproc> prints arguments or runs proc before;
  24. % <opref> <numargs|preproc> <numresults|postproc>
  25. % also prints results or runs proc after.
  26. % If traceflush is true, flush the output after each printout.
  27. /traceflush true def
  28. currentpacking true setpacking
  29. .currentglobal true .setglobal
  30. % Define the default "before" action
  31. /tracebefore { vmstatus 3 traceprint pop pop pop } def
  32. % Define the default "after" action
  33. /traceafter { } def
  34. /traceprint {
  35. dup type /integertype eq {
  36. 1 sub -1 0 { ( ) print index ==only } for
  37. } {
  38. exec
  39. } ifelse
  40. } bind def
  41. /traceend {
  42. traceflush { flush } if
  43. } bind def
  44. /traceop {
  45. userdict begin
  46. dup type dup /nametype eq exch /dicttype eq or { { tracebefore } } if
  47. 1 index type dup /nametype eq exch /dicttype eq or { { traceafter } } if
  48. /.tpost exch def /.tpre exch def
  49. dup type /dicttype ne {
  50. dup where not { userdict 1 index {} put userdict } if
  51. } if
  52. dup dup wcheck not {
  53. (Warning: substituting userdict for non-writable dictionary.) =
  54. pop userdict
  55. } if
  56. /.tddict exch def /.tdict exch def /.tname exch cvlit def
  57. .currentglobal [
  58. .tname /=only cvx ( ) /print cvx
  59. /.tpre load /traceprint cvx /traceend cvx
  60. .tdict .tname get /.tdef 1 index cvlit def
  61. dup xcheck {
  62. dup type dup /arraytype eq exch /packedarraytype eq or {
  63. /exec cvx
  64. } if
  65. } if
  66. /.tpost load /traceprint cvx () /= cvx /traceend cvx
  67. .tdef gcheck /.tpre load gcheck and /.tpost load gcheck and .setglobal
  68. ] cvx
  69. .tdef type /operatortype eq {
  70. .tname exch .makeoperator
  71. } if
  72. exch .setglobal
  73. .tddict exch .tname exch put
  74. end % userdict
  75. } bind def
  76. /tracebind /bind load def % in case someone wants to put it back
  77. /bind { } def % disable
  78. .setglobal
  79. setpacking