星火微课系统客户端
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #!/usr/bin/perl
  2. # $Id: fixmswrd.pl 6300 2005-12-28 19:56:24Z giles $
  3. # (C) 1997 Anthony Shipman
  4. #
  5. # This software is provided 'as-is', without any express or implied
  6. # warranty. In no event will the authors be held liable for any damages
  7. # arising from the use of this software.
  8. #
  9. # Permission is granted to anyone to use this software for any purpose,
  10. # including commercial applications, and to alter it and redistribute it
  11. # freely, subject to the following restrictions:
  12. #
  13. # 1. The origin of this software must not be misrepresented; you must not
  14. # claim that you wrote the original software. If you use this software
  15. # in a product, an acknowledgment in the product documentation would be
  16. # appreciated but is not required.
  17. # 2. Altered source versions must be plainly marked as such, and must not be
  18. # misrepresented as being the original software.
  19. # 3. This notice may not be removed or altered from any source distribution.
  20. #
  21. # Anthony Shipman shipmana@acm.org
  22. # This program patches the postscript generated by MS Word printer drivers
  23. # so that they work with ghostview 1.5. The problem is that the document
  24. # structuring conventions are not followed by Word. The pages are supposed
  25. # to be independent but they depend on a dictionary being opened outside
  26. # of the pages. The erroneous structure is
  27. #
  28. # %%EndSetup
  29. # NTPSOct95 begin
  30. # %%Page: 1 1
  31. # <text>
  32. # showpage
  33. # %%Page: 2 2
  34. # <text>
  35. # showpage
  36. # ......
  37. # %%Trailer
  38. # ...
  39. # end
  40. # %%EOF
  41. #
  42. # This only works if the all of the structure around the pages is preserved.
  43. # The opening of NTPSOct95 happens outside of any structured section so
  44. # it is never seen by ghostview. We change the structure to
  45. #
  46. # %%EndSetup
  47. # %%Page: 1 1
  48. # NTPSOct95 begin
  49. # <text>
  50. # showpage
  51. # end
  52. # %%Page: 2 2
  53. # NTPSOct95 begin
  54. # <text>
  55. # showpage
  56. # end
  57. # ......
  58. # %%Trailer
  59. # ...
  60. # %%EOF
  61. #
  62. # That is the dictionary opening is repeated inside each page.
  63. #
  64. # We add a comment to the document to mark that it has been converted.
  65. # This has the form
  66. # %LOCALGhostviewPatched
  67. #
  68. # Usage:
  69. # fixmswrd [-v] [file [output-file]]
  70. require 'getopts.pl';
  71. #=================================================================
  72. $program = "fixmswrd";
  73. sub usage {
  74. die "Usage: $program [-v] [file [output-file]]\n";
  75. }
  76. #=================================================================
  77. &Getopts("v") || &usage;
  78. $verbose = $opt_v;
  79. $infile = shift(@ARGV);
  80. if ($infile)
  81. {
  82. open(INFILE, $infile) || die "$program: Cannot read from $infile\n";
  83. $handle = "INFILE";
  84. }
  85. else
  86. {
  87. $handle = "STDIN";
  88. }
  89. $outfile = shift(@ARGV);
  90. if ($outfile)
  91. {
  92. open(OUTFILE, ">$outfile") || die "$program: Cannot write to $outfile\n";
  93. select(OUTFILE);
  94. }
  95. # This reads the header comments and detects the presence of the marker.
  96. $have_marker = 0;
  97. undef $dict_name;
  98. undef $dict_line;
  99. &read_comments;
  100. &put_comments;
  101. if ($have_marker)
  102. {
  103. $verbose && print STDERR "$program: Warning - already converted\n";
  104. while(<$handle>) # pass the file through unchanged.
  105. {
  106. print;
  107. }
  108. }
  109. else
  110. {
  111. $seen_trailer = 0;
  112. while(<$handle>) # massage the file
  113. {
  114. if ($dict_line)
  115. {
  116. next if (/$dict_line/o); # drop the old begin line
  117. $seen_trailer = 1 if (/^%%Trailer/);
  118. next if ($seen_trailer and /^end/); # drop the old end line
  119. }
  120. print;
  121. if (/^%%Page:/)
  122. {
  123. print "$dict_name begin\n"; # add at the start of the page
  124. }
  125. elsif (/^showpage/)
  126. {
  127. print "end\n"; # add at the end of the page
  128. }
  129. elsif (/^%%BeginResource: procset (\S+)/)
  130. {
  131. $dict_name = $1;
  132. $dict_line = "^$dict_name begin";
  133. }
  134. elsif (/^%%BeginProcSet: (\S+)/) # for older document versions
  135. {
  136. $dict_name = $1;
  137. $dict_line = "^$dict_name begin";
  138. }
  139. elsif (/^%%EndProlog:/)
  140. {
  141. unless ($dict_line)
  142. {
  143. $verbose &&
  144. print STDERR "$program: Warning - unrecognised document structure\n";
  145. }
  146. }
  147. }
  148. }
  149. exit 0;
  150. #=================================================================
  151. # This reads all of the header comments into an array which we can write
  152. # out again later. In addition we detect the presence of the marker comment.
  153. sub read_comments
  154. {
  155. @headers = ();
  156. while (<$handle>)
  157. { # without chopping
  158. push(@headers, $_);
  159. if (/^%LOCALGhostviewPatched/)
  160. {
  161. $have_marker = 1;
  162. }
  163. last if /^%%EndComments/;
  164. }
  165. }
  166. sub put_comments
  167. {
  168. foreach $h (@headers)
  169. {
  170. if (!$have_marker and ($h =~ /^%%EndComments/))
  171. {
  172. print "%LOCALGhostviewPatched\n";
  173. }
  174. print $h; # contains the newline
  175. }
  176. }