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 / fontutil / vptovf.ch < prev    next >
Text File  |  1996-09-28  |  9KB  |  309 lines

  1. % vptovf.ch for C compilation with web2c.
  2.  
  3.  
  4. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  5. % [0] WEAVE: print changes only.
  6. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  7. @x
  8. \pageno=\contentspagenumber \advance\pageno by 1
  9. @y
  10. \pageno=\contentspagenumber \advance\pageno by 1
  11. \let\maybe=\iffalse
  12. \def\title{VP$\,$\lowercase{to}$\,$VF changes for C}
  13. @z
  14.  
  15. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  16. % [1] Change banner string.
  17. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  18. @x
  19. @d banner=='This is VPtoVF, Version 1.3' {printed when the program starts}
  20. @y
  21. @d banner=='This is VPtoVF, Version 1.3' {more is printed later}
  22. @z
  23.  
  24. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  25. % [2] Remove filenames from program statement, and print the banner later.
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  27. @x
  28. @p program VPtoVF(@!vpl_file,@!vf_file,@!tfm_file,@!output);
  29. @y
  30. @p program VPtoVF;
  31. @z
  32.  
  33. @x
  34.   begin print_ln(banner);@/
  35. @y
  36.   begin
  37. @z
  38.  
  39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  40. % [6] Open VPL file.
  41. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  42. @x
  43. reset(vpl_file);
  44. @y
  45. if (argc < 4) or (argc > n_options + 4)
  46. then begin
  47.   print_ln ('Usage: vptovf [-verbose] <vpl file> <vfm file> <tfm file>.');
  48.   uexit (1);
  49. end;
  50. @<Initialize the option variables@>;
  51. @<Parse arguments@>;
  52. argv (optind, vpl_name);
  53. reset (vpl_file, vpl_name);
  54. if verbose then begin
  55.   print (banner);
  56.   print_ln (banner);
  57. end;
  58. @z
  59.  
  60. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  61. % [21] Declare filename variables.
  62. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  63. @x
  64. @!tfm_file:packed file of 0..255;
  65. @y
  66. @!tfm_file:packed file of 0..255;
  67. @!vf_name,@!tfm_name,@!vpl_name:packed array[1..PATH_MAX] of char;
  68. @z
  69.  
  70. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  71. % [22] Open output files.
  72. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  73. @x
  74. @ On some systems you may have to do something special to write a
  75. packed file of bytes. For example, the following code didn't work
  76. when it was first tried at Stanford, because packed files have to be
  77. opened with a special switch setting on the \PASCAL\ that was used.
  78. @^system dependencies@>
  79.  
  80. @<Set init...@>=
  81. rewrite(vf_file); rewrite(tfm_file);
  82. @y
  83. @ On some systems you may have to do something special to write a
  84. packed file of bytes.
  85. @^system dependencies@>
  86.  
  87. @<Set init...@>=
  88. argv(optind + 1, vf_name);
  89. rewrite(vf_file, vf_name);
  90. argv(optind + 2, tfm_name);
  91. rewrite(tfm_file, tfm_name);
  92. @z
  93.  
  94. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  95. % [89] `index' is not a good choice for an identifier on Unix systems.
  96. % Neither is `class', on AIX.
  97. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  98. @x
  99. |k|th element of its list.
  100.  
  101. @<Glob...@>=
  102. @!index:array[pointer] of byte;
  103. @y
  104. |k|th element of its list.
  105.  
  106. @d index == index_var
  107. @d class == class_var
  108.  
  109. @<Glob...@>=
  110. @!index:array[pointer] of byte;
  111. @z
  112.  
  113. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  114. % [118] No output unless verbose.
  115. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  116. @x
  117. @<Print |c| in octal notation@>;
  118. @y
  119. if verbose then @<Print |c| in octal notation@>;
  120. @z
  121.  
  122. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  123. % [144] Output of real numbers.
  124. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  125. @x
  126. @ @d round_message(#)==if delta>0 then print_ln('I had to round some ',
  127. @.I had to round...@>
  128.   #,'s by ',(((delta+1) div 2)/@'4000000):1:7,' units.')
  129. @y
  130. @ @d round_message(#)==if delta>0 then begin print('I had to round some ',
  131. @.I had to round...@>
  132.   #,'s by '); print_real((((delta+1) div 2)/@'4000000),1,7);
  133.   print_ln(' units.'); end
  134. @z
  135.  
  136. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  137. % [152] Fix up the mutually recursive procedures a la pltotf.
  138. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  139. @x
  140. @p function f(@!h,@!x,@!y:indx):indx; forward;@t\2@>
  141.   {compute $f$ for arguments known to be in |hash[h]|}
  142. @y
  143. @p 
  144. ifdef('notdef') 
  145. function f(@!h,@!x,@!y:indx):indx; begin end;@t\2@>
  146.   {compute $f$ for arguments known to be in |hash[h]|}
  147. endif('notdef')
  148. @z
  149.  
  150. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  151. % [153] Finish fixing up f.
  152. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  153. @x
  154. @p function f;
  155. @y
  156. @p function f(@!h,@!x,@!y:indx):indx; 
  157. @z
  158.  
  159. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  160. % [156] Change TFM-byte output to fix ranges.
  161. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  162. @x
  163. @d out(#)==write(tfm_file,#)
  164. @y
  165. @d out(#)==putbyte(#,tfm_file)
  166. @z
  167.  
  168. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  169. % [165] Fix output of reals.
  170. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  171. @x
  172. @p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|}
  173. var @!n:byte; {the first byte after the sign}
  174. @!m:0..65535; {the two least significant bytes}
  175. begin if abs(x/design_units)>=16.0 then
  176.   begin print_ln('The relative dimension ',x/@'4000000:1:3,
  177.     ' is too large.');
  178. @.The relative dimension...@>
  179.   print('  (Must be less than 16*designsize');
  180.   if design_units<>unity then print(' =',design_units/@'200000:1:3,
  181.       ' designunits');
  182. @y
  183. @p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|}
  184. var @!n:byte; {the first byte after the sign}
  185. @!m:0..65535; {the two least significant bytes}
  186. begin if fabs(x/design_units)>=16.0 then
  187.   begin print('The relative dimension ');
  188.     print_real(x/@'4000000,1,3);
  189.     print_ln(' is too large.');
  190. @.The relative dimension...@>
  191.   print('  (Must be less than 16*designsize');
  192.   if design_units<>unity then begin print(' =');
  193.     print_real(design_units/@'200000,1,3);
  194.     print(' designunits');
  195.   end;
  196. @z
  197.  
  198. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  199. % [141] char_remainder[c] is unsigned, and label_table[sort_ptr].rr
  200. % might be -1, and if -1 is coerced to being unsigned, it will be bigger
  201. % than anything else.
  202. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  203. @x
  204.   while label_table[sort_ptr].rr>char_remainder[c] do
  205. @y
  206.   while label_table[sort_ptr].rr>toint(char_remainder[c]) do
  207. @z
  208.  
  209. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  210. % [175] Change VF-byte output to fix ranges.
  211. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  212. @x
  213. @d vout(#)==write(vf_file,#)
  214. @y
  215. @d vout(#)==putbyte(#,vf_file)
  216. @z
  217.  
  218. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  219. % [181] Be quiet unless verbose. 
  220. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  221. @x
  222. read_input; print_ln('.');@/
  223. @y
  224. read_input;
  225. if verbose then print_ln('.');
  226. @z
  227.  
  228. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  229. % [182] System-dependent changes.
  230. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  231. @x
  232. @* System-dependent changes.
  233. This section should be replaced, if necessary, by changes to the program
  234. that are necessary to make \.{VPtoVF} work at a particular installation.
  235. It is usually best to design your change file so that all changes to
  236. previous sections preserve the section numbering; then everybody's version
  237. will be consistent with the printed program. More extensive changes,
  238. which introduce new sections, can be inserted here; then only the index
  239. itself will get a new section number.
  240. @^system dependencies@>
  241. @y
  242. @* System-dependent changes.  We want to parse a Unix-style command line.
  243.  
  244. @<Parse arguments@> =
  245. begin
  246.   @<Define the option table@>;
  247.   repeat
  248.     getopt_return_val := getopt_long_only (argc, gargv, '', long_options,
  249.                                            address_of_int (option_index));
  250.     if getopt_return_val <> -1
  251.     then begin
  252.       if getopt_return_val = "?"
  253.       then uexit (1); {|getopt| has already given an error message.}
  254.       {We don't have any non-flag options.}
  255.     end;
  256.   until getopt_return_val = -1;
  257.  
  258.   {Now |optind| is the index of first non-option on the command line.}
  259. end
  260.  
  261.  
  262. @ The array of information we pass in.  The type |getopt_struct| is
  263. defined in C, to avoid type clashes.  We also need to know the return
  264. value from getopt, and the index of the current option.
  265.  
  266. @<Local var...@> =
  267. @!long_options: array[0..n_options] of getopt_struct;
  268. @!getopt_return_val: integer;
  269. @!option_index: c_int_type;
  270.  
  271.  
  272. @ Here are the options we allow.
  273.  
  274. @<Define the option...@> =
  275. long_options[0].name := 'verbose';
  276. long_options[0].has_arg := 0;
  277. long_options[0].flag := address_of_int (verbose);
  278. long_options[0].val := 1;
  279.  
  280.  
  281. @ The global variable |verbose| determines whether or not we print
  282. progress information.
  283.  
  284. @<Glob...@> =
  285. @!verbose: c_int_type;
  286.  
  287. @ It starts off |false|.
  288.  
  289. @<Initialize the option...@> =
  290. verbose := false;
  291.  
  292.  
  293. @ An element with all zeros always ends the list.
  294.  
  295. @<Define the option...@> =
  296. long_options[1].name := 0;
  297. long_options[1].has_arg := 0;
  298. long_options[1].flag := 0;
  299. long_options[1].val := 0;
  300.  
  301.  
  302. @ Pascal compilers won't count the number of elements in an array
  303. constant for us.  This doesn't include the zero-element at the end,
  304. because this array starts at index zero.
  305.  
  306. @<Constants...@> =
  307. n_options = 1;
  308. @z
  309.