home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / tex / texsrc2 / Src / fontutil / vptovf / ch next >
Encoding:
Text File  |  1993-05-21  |  9.2 KB  |  308 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. riscos_type:=riscos_tfmtype;
  92. rewrite(tfm_file, tfm_name);
  93. @z
  94.  
  95. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  96. % [89] `index' is not a good choice for an identifier.
  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_type
  107.  
  108. @<Glob...@>=
  109. @!index:array[pointer] of byte;
  110. @z
  111.  
  112. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  113. % [118] No output unless verbose.
  114. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  115. @x
  116. @<Print |c| in octal notation@>;
  117. @y
  118. if verbose then @<Print |c| in octal notation@>;
  119. @z
  120.  
  121. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  122. % [144] Output of real numbers.
  123. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  124. @x
  125. @ @d round_message(#)==if delta>0 then print_ln('I had to round some ',
  126. @.I had to round...@>
  127.   #,'s by ',(((delta+1) div 2)/@'4000000):1:7,' units.')
  128. @y
  129. @ @d round_message(#)==if delta>0 then begin print('I had to round some ',
  130. @.I had to round...@>
  131.   #,'s by '); print_real((((delta+1) div 2)/@'4000000),1,7);
  132.   print_ln(' units.'); end
  133. @z
  134.  
  135. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  136. % [152] Fix up the mutually recursive procedures a la pltotf.
  137. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  138. @x
  139. @p function f(@!h,@!x,@!y:indx):indx; forward;@t\2@>
  140.   {compute $f$ for arguments known to be in |hash[h]|}
  141. @y
  142. @p 
  143. ifdef('notdef') 
  144. function f(@!h,@!x,@!y:indx):indx; begin end;@t\2@>
  145.   {compute $f$ for arguments known to be in |hash[h]|}
  146. endif('notdef')
  147. @z
  148.  
  149. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  150. % [153] Finish fixing up f.
  151. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  152. @x
  153. @p function f;
  154. @y
  155. @p function f(@!h,@!x,@!y:indx):indx; 
  156. @z
  157.  
  158. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  159. % [156] Change TFM-byte output to fix ranges.
  160. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  161. @x
  162. @d out(#)==write(tfm_file,#)
  163. @y
  164. @d out(#)==putbyte(#,tfm_file)
  165. @z
  166.  
  167. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  168. % [165] Fix output of reals.
  169. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  170. @x
  171. @p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|}
  172. var @!n:byte; {the first byte after the sign}
  173. @!m:0..65535; {the two least significant bytes}
  174. begin if abs(x/design_units)>=16.0 then
  175.   begin print_ln('The relative dimension ',x/@'4000000:1:3,
  176.     ' is too large.');
  177. @.The relative dimension...@>
  178.   print('  (Must be less than 16*designsize');
  179.   if design_units<>unity then print(' =',design_units/@'200000:1:3,
  180.       ' designunits');
  181. @y
  182. @p procedure out_scaled(x:fix_word); {outputs a scaled |fix_word|}
  183. var @!n:byte; {the first byte after the sign}
  184. @!m:0..65535; {the two least significant bytes}
  185. begin if fabs(x/design_units)>=16.0 then
  186.   begin print('The relative dimension ');
  187.     print_real(x/@'4000000,1,3);
  188.     print_ln(' is too large.');
  189. @.The relative dimension...@>
  190.   print('  (Must be less than 16*designsize');
  191.   if design_units<>unity then begin print(' =');
  192.     print_real(design_units/@'200000,1,3);
  193.     print(' designunits');
  194.   end;
  195. @z
  196.  
  197. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  198. % [141] char_remainder[c] is unsigned, and label_table[sort_ptr].rr
  199. % might be -1, and if -1 is coerced to being unsigned, it will be bigger
  200. % than anything else.
  201. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  202. @x
  203.   while label_table[sort_ptr].rr>char_remainder[c] do
  204. @y
  205.   while label_table[sort_ptr].rr>toint(char_remainder[c]) do
  206. @z
  207.  
  208. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  209. % [175] Change VF-byte output to fix ranges.
  210. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  211. @x
  212. @d vout(#)==write(vf_file,#)
  213. @y
  214. @d vout(#)==putbyte(#,vf_file)
  215. @z
  216.  
  217. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  218. % [181] Be quiet unless verbose. 
  219. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  220. @x
  221. read_input; print_ln('.');@/
  222. @y
  223. read_input;
  224. if verbose then print_ln('.');
  225. @z
  226.  
  227. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  228. % [182] System-dependent changes.
  229. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  230. @x
  231. @* System-dependent changes.
  232. This section should be replaced, if necessary, by changes to the program
  233. that are necessary to make \.{VPtoVF} work at a particular installation.
  234. It is usually best to design your change file so that all changes to
  235. previous sections preserve the section numbering; then everybody's version
  236. will be consistent with the printed program. More extensive changes,
  237. which introduce new sections, can be inserted here; then only the index
  238. itself will get a new section number.
  239. @^system dependencies@>
  240. @y
  241. @* System-dependent changes.  We want to parse a Unix-style command line.
  242.  
  243. @<Parse arguments@> =
  244. begin
  245.   @<Define the option table@>;
  246.   repeat
  247.     getopt_return_val := getopt_long_only (argc, gargv, '', long_options,
  248.                                            address_of_int (option_index));
  249.     if getopt_return_val <> -1
  250.     then begin
  251.       if getopt_return_val = "?"
  252.       then uexit (1); {|getopt| has already given an error message.}
  253.       {We don't have any non-flag options.}
  254.     end;
  255.   until getopt_return_val = -1;
  256.  
  257.   {Now |optind| is the index of first non-option on the command line.}
  258. end
  259.  
  260.  
  261. @ The array of information we pass in.  The type |getopt_struct| is
  262. defined in C, to avoid type clashes.  We also need to know the return
  263. value from getopt, and the index of the current option.
  264.  
  265. @<Local var...@> =
  266. @!long_options: array[0..n_options] of getopt_struct;
  267. @!getopt_return_val: integer;
  268. @!option_index: integer;
  269.  
  270.  
  271. @ Here are the options we allow.
  272.  
  273. @<Define the option...@> =
  274. long_options[0].name := 'verbose';
  275. long_options[0].has_arg := 0;
  276. long_options[0].flag := address_of_int (verbose);
  277. long_options[0].val := 1;
  278.  
  279.  
  280. @ The global variable |verbose| determines whether or not we print
  281. progress information.
  282.  
  283. @<Glob...@> =
  284. @!verbose: integer;
  285.  
  286. @ It starts off |false|.
  287.  
  288. @<Initialize the option...@> =
  289. verbose := false;
  290.  
  291.  
  292. @ An element with all zeros always ends the list.
  293.  
  294. @<Define the option...@> =
  295. long_options[1].name := 0;
  296. long_options[1].has_arg := 0;
  297. long_options[1].flag := 0;
  298. long_options[1].val := 0;
  299.  
  300.  
  301. @ Pascal compilers won't count the number of elements in an array
  302. constant for us.  This doesn't include the zero-element at the end,
  303. because this array starts at index zero.
  304.  
  305. @<Constants...@> =
  306. n_options = 1;
  307. @z
  308.