home *** CD-ROM | disk | FTP | other *** search
/ Geek Gadgets 1 / ADE-1.bin / ade-dist / unixtex-6.1b-src.tgz / tar.out / contrib / unixtex / web2c / tex / patgen.ch < prev    next >
Text File  |  1996-09-28  |  9KB  |  268 lines

  1. % patgen2.ch for C compilation with web2c.
  2. % The original version of this file was created by Howard Trickey.
  3. %
  4. % 07/01/83 (HWT) Original version, made to work with patgen released with
  5. %         version 0.99 of TeX in July 1983.  It may not work
  6. %         properly---it is hard to test without more information.
  7. % 03/23/88 (ETM) Brought up to date, converted for use with WEB to C.
  8. % (more recent changes in ../ChangeLog.W2C and ./ChangeLog)
  9.  
  10.  
  11.  
  12. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  13. % WEAVE: print changes only
  14. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  15. @x
  16. \pageno=\contentspagenumber \advance\pageno by 1
  17. @y
  18. \pageno=\contentspagenumber \advance\pageno by 1
  19. \let\maybe=\iffalse
  20. \def\title{PATGEN changes for C}
  21. @z
  22.  
  23. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  24. % Change banner string.
  25. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  26. @x
  27. @d banner=='This is PATGEN, Version 2.0' {printed when the program starts}
  28. @y
  29. @d banner=='This is PATGEN, Version 2.0' {more is printed later}
  30. @z
  31.  
  32. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  33. % Terminal I/O
  34. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  35. @x
  36. @d print(#)==write(output,#)
  37. @d print_ln(#)==write_ln(output,#)
  38. @d get_input(#)==read(input,#)
  39. @d get_input_ln(#)==
  40.   begin if eoln(input) then read_ln(input);
  41.   read(input,#);
  42.   end
  43. @#
  44. @y
  45. @d print(#)==write(std_output,#)
  46. @d print_ln(#)==writeln(std_output,#)
  47. @d get_input(#)==#:=input_int(std_input)
  48. @d get_input_ln(#)==begin #:=getc(std_input); readln(std_input); end @#
  49. @z
  50.  
  51. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  52. % Change files in program statement
  53. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  54. @x
  55. @p @<Compiler directives@>@/
  56. program PATGEN(@!dictionary,@!patterns,@!translate,@!patout);
  57. @y
  58. @d std_input==stdin
  59. @d std_output==stdout
  60.  
  61. @p @<Compiler directives@>@/
  62. program PATGEN;
  63. @z
  64.  
  65. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  66. % Add file opening to initialization
  67. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  68. @x
  69.   begin print_ln(banner);@/
  70. @y
  71.   begin @<Open files@>@/
  72.   print (banner);
  73.   print_ln (version_string);
  74. @z
  75.  
  76. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  77. % Error handling
  78. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  79. @x
  80. @d error(#)==begin print_ln(#); jump_out; end
  81. @y
  82. @d error(#)==begin print_ln(#); uexit(1); end;
  83. @z
  84.  
  85. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  86. % Compiler directives
  87. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  88. @x
  89. @{@&$C-,A+,D-@} {no range check, catch arithmetic overflow, no debug overhead}
  90. @y
  91. {none needed for C}
  92. @z
  93.  
  94. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  95. % Fix signed char problem
  96. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  97. @x
  98. @!text_char=char; {the data type of characters in text files}
  99. @!ASCII_code=0..last_ASCII_code; {internal representation of input characters}
  100. @y
  101. @!ASCII_code=0..last_ASCII_code; {internal representation of input characters}
  102. @!text_char=ASCII_code; {the data type of characters in text files}
  103. @z
  104.  
  105. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  106. % Remove file close
  107. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  108. @x
  109. @d close_out(#)==close(#) {close an output file}
  110. @d close_in(#)==do_nothing {close an input file}
  111. @y
  112. @d close_out(#)== {close an output file}
  113. @d close_in(#)== {close an input file}
  114. @z
  115.  
  116. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  117. % Add f_name declaration
  118. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  119. @x
  120. @!dictionary, @!patterns, @!translate, @!patout, @!pattmp: text_file;
  121. @y
  122. @!dictionary, @!patterns, @!translate, @!patout, @!pattmp: text_file;
  123. @!f_name: packed array [1..PATH_MAX] of char;
  124. @z
  125.  
  126. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  127. % Use args to get translate file name
  128. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  129. @x
  130. reset(translate);
  131. @y
  132. argv(4, f_name);
  133. reset(translate, f_name);
  134. @z
  135.  
  136. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  137. % Floating point output
  138. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  139. @x
  140.   print_ln(', efficiency = ',
  141.     good_count/(good_pat_count+bad_count/bad_eff):1:2)
  142. @y
  143.   begin print(', efficiency = ');
  144.     print_real(good_count/(good_pat_count+bad_count/bad_eff),1,2);
  145.     writeln(std_output);
  146.   end
  147. @z
  148.  
  149. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  150. % Make room for terminating space, needed by C routines
  151. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152. @x
  153. @!filnam: packed array[1..8] of char; {for |pattmp|}
  154. @y
  155. @!filnam: packed array[1..9] of char; {for |pattmp|}
  156. @z
  157.  
  158. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  159. % Use args to get dictionary file name
  160. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  161. @x
  162.   reset(dictionary);@/
  163. @y
  164. argv(1, f_name);
  165. reset(dictionary, f_name);
  166. @z
  167.  
  168. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  169. % Fix file name initialization and printing
  170. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  171. @x
  172.     begin filnam:='pattmp. ';
  173. @y
  174.     begin  filnam[1]:='p';
  175.       filnam[2]:='a';
  176.       filnam[3]:='t';
  177.       filnam[4]:='t';
  178.       filnam[5]:='m';
  179.       filnam[6]:='p';
  180.       filnam[7]:='.';
  181.       {|filnam[8]| is assigned |xdig[hyph_level]|.}
  182.       filnam[9]:=' ';
  183. @z
  184.  
  185. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  186. % Fix another floating point i/o problem
  187. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  188. @x
  189.   if (good_count+miss_count)>0 then
  190.     print_ln((100*good_count/(good_count+miss_count)):1:2,' %, ',
  191.       (100*bad_count/(good_count+miss_count)):1:2,' %, ',
  192.       (100*miss_count/(good_count+miss_count)):1:2,' %');
  193. @y
  194.   if (good_count+miss_count)>0 then
  195.   begin print_real((100*good_count/(good_count+miss_count)),1,2);
  196.     print(' %, ');
  197.     print_real((100*bad_count/(good_count+miss_count)),1,2);
  198.     print(' %, ');
  199.     print_real((100*miss_count/(good_count+miss_count)),1,2);
  200.     print_ln(' %');
  201.   end;
  202. @z
  203.  
  204. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  205. % Use the command line argument to get the file name
  206. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  207. @x
  208. reset(patterns);
  209. @y
  210. argv(2, f_name);
  211. reset(patterns, f_name);
  212. @z
  213.  
  214. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  215. % Fix reading of multiple variables in the same line
  216. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  217. @x
  218. repeat print('hyph_start, hyph_finish: '); get_input(n1,n2);@/
  219. @y
  220. repeat print('hyph_start, hyph_finish: '); input_2ints(n1,n2);@/
  221. @z
  222. @x
  223.   repeat print('pat_start, pat_finish: '); get_input(n1,n2);@/
  224. @y
  225.   repeat print('pat_start, pat_finish: '); input_2ints(n1,n2);@/
  226. @z
  227. @x
  228.   get_input(good_wt,bad_wt,thresh);@/
  229. @y
  230.   input_3ints(good_wt,bad_wt,thresh);@/
  231. @z
  232.  
  233. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  234. % Use args to get patout file name
  235. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  236. @x
  237. rewrite(patout);
  238. @y
  239. argv(3, f_name);
  240. rewrite(patout, f_name);
  241. @z
  242.  
  243. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  244. % Define <Open files>
  245. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  246. @x
  247. @* System-dependent changes.
  248. This section should be replaced, if necessary, by changes to the program
  249. that are necessary to make \.{PATGEN} work at a particular installation.
  250. It is usually best to design your change file so that all changes to
  251. previous sections preserve the section numbering; then everybody's version
  252. will be consistent with the printed program. More extensive changes,
  253. which introduce new sections, can be inserted here; then only the index
  254. itself will get a new section number.
  255. @^system dependencies@>
  256. @y
  257. @* System-dependent changes.
  258. Use the command line arguments to get the file names.  Open the
  259. output file here; the others are reset above.
  260.  
  261. @<Open files@>=
  262. if argc < 4 then begin
  263.     error('Usage: patgen <dictionary file> <pattern file> <output file>',
  264.           ' <translate file>')
  265. end;
  266. @z
  267.