home *** CD-ROM | disk | FTP | other *** search
/ The Datafile PD-CD 3 / PDCD_3.iso / tex / texsrc2 / Src / fontutil / pltotf / ch next >
Encoding:
Text File  |  1993-05-21  |  10.9 KB  |  348 lines

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