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 / dviutil / dvicopy.ch < prev    next >
Text File  |  1996-09-28  |  22KB  |  647 lines

  1. % dvicopy.ch for C compilation with web2c.
  2. % The original version of this file was created by Monika Jayme and
  3. % Klaus Guntermann at TH Darmstadt (THD), FR Germany.
  4. %                                       (xitikgun@ddathd21.bitnet)
  5. % Some parts are borrowed from the changes to dvitype, vftovp and vptovf.
  6. %
  7. % History:
  8. %  July 90   THD  First versions for dvicopy 0.91 and 0.92
  9. %  Aug 09 90 THD  Updated to dvicopy 1.0 and released
  10. %  Mar 20 91 THD  Updated to dvicopy 1.2
  11. %
  12.  
  13.  
  14. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  15. % [0] WEAVE: print changes only
  16. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  17. @x
  18. \pageno=\contentspagenumber \advance\pageno by 1
  19. @y
  20. \pageno=\contentspagenumber \advance\pageno by 1
  21. \let\maybe=\iffalse
  22. @z
  23.  
  24. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  25. % [1] Change banner string and preamble comment
  26. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  27. @x
  28. @d banner=='This is DVIcopy, Version 1.2' {printed when the program starts}
  29. @y
  30. @d banner=='This is DVIcopy, Version 1.2' {more is printed later}
  31. @z
  32.  
  33. @x
  34. @d preamble_comment=='DVIcopy 1.2 output from '
  35. @y
  36. @d preamble_comment==' DVIcopy 1.2 output from '
  37. @z
  38.  
  39. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  40. % [3] Change filenames in program statement
  41. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  42. @x
  43. program DVI_copy(@!dvi_file,@!out_file,@!output);
  44. @y
  45. program DVI_copy;
  46. @z
  47.  
  48. @x
  49.   begin print_ln(banner);@/
  50. @y
  51.   begin print (banner); print_ln (version_string);
  52. @z
  53.  
  54. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  55. % [5] Make name_length match the system constant.
  56. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  57. @x
  58. @<Constants...@>=
  59. @y
  60. @d name_length==PATH_MAX
  61.  
  62. @<Constants...@>=
  63. @z
  64.  
  65. @x
  66. @!name_length=50; {a file name shouldn't be longer than this}
  67. @y
  68. @z
  69.  
  70. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  71. % [11] Use `stdout' instead of `output'.
  72. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  73. @x
  74. @d print(#)==write(output,#)
  75. @y
  76. @d output == stdout
  77. @d print(#)==write(output,#)
  78. @z
  79.  
  80. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  81. % [12] Use C macros for incr/decr
  82. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  83. @x
  84. @d incr(#) == #:=#+1 {increase a variable by unity}
  85. @d decr(#) == #:=#-1 {decrease a variable by unity}
  86. @y
  87. @z
  88.  
  89. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  90. % [14] Permissive input.
  91. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  92. @x
  93. @!ASCII_code=" ".."~"; {a subrange of the integers}
  94. @y
  95. @!ASCII_code=0..255; {a subrange of the integers}
  96. @z
  97.  
  98. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  99. % [15] The text_char type is used as an array index into xord.  The
  100. % default type `char' produces signed integers, which are bad array
  101. % indices in C.
  102. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  103. @x
  104. @d text_char == char {the data type of characters in text files}
  105. @d first_text_char=0 {ordinal number of the smallest element of |text_char|}
  106. @d last_text_char=127 {ordinal number of the largest element of |text_char|}
  107. @y
  108. @d text_char == ASCII_code {the data type of characters in text files}
  109. @d first_text_char=0 {ordinal number of the smallest element of |text_char|}
  110. @d last_text_char=255 {ordinal number of the largest element of |text_char|}
  111. @z
  112.  
  113. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  114. % [23] Remove non-local goto
  115. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  116. @x
  117. @ If an input (\.{DVI}, \.{TFM}, \.{VF}, or other) file is badly malformed,
  118. the whole process must be aborted; \.{\title} will give up, after issuing
  119. an error message about what caused the error. These messages will, however,
  120. in most cases just indicate which input file caused the error. One of the
  121. programs \.{DVItype}, \.{TFtoPL} or \.{VFtoVP} should then be used to
  122. diagnose the error in full detail.
  123.  
  124. Such errors might be discovered inside of subroutines inside of subroutines,
  125. so a procedure called |jump_out| has been introduced. This procedure, which
  126. transfers control to the label |final_end| at the end of the program,
  127. contains the only non-local |@!goto| statement in \.{\title}.
  128. @^system dependencies@>
  129. Some \PASCAL\ compilers do not implement non-local |goto| statements. In
  130. such cases the |goto final_end| in |jump_out| should simply be replaced
  131. by a call on some system procedure that quietly terminates the program.
  132. @^system dependencies@>
  133.  
  134. @d abort(#)==begin print_ln(' ',#,'.'); jump_out;
  135.     end
  136.  
  137. @<Error handling...@>=
  138. @<Basic printing procedures@>@;
  139. procedure close_files_and_terminate; forward;
  140. @#
  141. procedure jump_out;
  142. begin mark_fatal; close_files_and_terminate;
  143. goto final_end;
  144. end;
  145. @y
  146. @ If an input (\.{DVI}, \.{TFM}, \.{VF}, or other) file is badly malformed,
  147. the whole process must be aborted; \.{\title} will give up, after issuing
  148. an error message about what caused the error. These messages will, however,
  149. in most cases just indicate which input file caused the error. One of the
  150. programs \.{DVItype}, \.{TFtoPL} or \.{VFtoVP} should then be used to
  151. diagnose the error in full detail.
  152.  
  153. Such errors might be discovered inside of subroutines inside of subroutines,
  154. so a procedure called |jump_out| has been introduced. This procedure is
  155. actually a macro which calls |uexit()| with a non-zero exit status.
  156.  
  157. @d abort(#)==begin print_ln(' ',#,'.'); jump_out;
  158.     end
  159.  
  160. @<Error handling...@>=
  161. @<Basic printing procedures@>@;
  162. procedure close_files_and_terminate; forward;
  163. @#
  164. procedure jump_out;
  165. begin mark_fatal; close_files_and_terminate;
  166. uexit(1);
  167. end;
  168. @z
  169.  
  170. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  171. % [51] Fix casting problem in C.
  172. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  173. @x
  174. @d comp_spair(#) == if a<128 then #:=a*256+b @+ else #:=(a-256)*256+b
  175. @d comp_upair(#) == #:=a*256+b
  176. @y
  177. @d comp_spair(#) == if a<128 then #:=a*toint(256)+b
  178.                              @+ else #:=(a-toint(256))*toint(256)+b
  179. @d comp_upair(#) == #:=a*toint(256)+b
  180. @z
  181.  
  182. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  183. % [52]
  184. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  185. @x
  186. if a<128 then #:=(a*256+b)*256+c @+ else #:=((a-256)*256+b)*256+c
  187. @d comp_utrio(#) == #:=(a*256+b)*256+c
  188. @y
  189. if a<128 then #:=(a*toint(256)+b)*toint(256)+c @+
  190. else #:=((a-toint(256))*toint(256)+b)*toint(256)+c
  191. @d comp_utrio(#) == #:=(a*toint(256)+b)*toint(256)+c
  192. @z
  193.  
  194. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  195. % [53]
  196. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  197. @x
  198. if a<128 then #:=((a*256+b)*256+c)*256+d
  199. else #:=(((a-256)*256+b)*256+c)*256+d
  200. @y
  201. if a<128 then #:=((a*toint(256)+b)*toint(256)+c)*toint(256)+d
  202. else #:=(((a-toint(256))*toint(256)+b)*toint(256)+c)*toint(256)+d
  203. @z
  204.  
  205. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  206. % [63]
  207. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  208. @x
  209. @ For \.{TFM} and \.{VF} files we just append the apropriate extension
  210. to the file name packet; in addition a system dependent area part
  211. (usually different for \.{TFM} and \.{VF} files) is prepended if
  212. the file name packet contains no area part.
  213. @^system dependencies@>
  214.  
  215. @d append_to_name(#)==
  216.   if cur_name_length<name_length then
  217.     begin incr(cur_name_length); cur_name[cur_name_length]:=#;
  218.     end
  219.   else overflow(str_name_length,name_length)
  220. @d make_font_name_end(#)==
  221.   append_to_name(#[l]); make_name
  222. @d make_font_name(#)==
  223.   cur_name_length:=0; for l:=1 to # do make_font_name_end
  224. @y
  225. @ For \.{TFM} and \.{VF} files we just append the apropriate extension
  226. to the file name packet.
  227. Since files are actually searched through path definitions given in
  228. the environment variables area definitions are ignored here.
  229. To reduce the required changes we ignore most of the parameters given
  230. to |make_font_name| and just keep the requested extension.
  231. @^system dependencies@>
  232.  
  233. @d append_to_name(#)==
  234.   if cur_name_length<name_length then
  235.     begin incr(cur_name_length); cur_name[cur_name_length]:=#;
  236.     end
  237.   else overflow(str_name_length,name_length)
  238. @d make_font_name_end(#)==
  239.   make_name
  240. @d make_font_name(#)==
  241.   cur_name_length:=0; make_font_name_end
  242. @z
  243.  
  244. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  245. % [67] No conversion of file names in lower case
  246. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  247. @x
  248.   if (b>="a")and(b<="z") then Decr(b)("a"-"A"); {convert to upper case}
  249. @y
  250. @z
  251.  
  252. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  253. % [92] File names in lower case
  254. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  255. @x
  256. id4(".")("T")("F")("M")(tfm_ext); {file name extension for \.{TFM} files}
  257. @y
  258. id4(".")("t")("f")("m")(tfm_ext); {file name extension for \.{TFM} files}
  259. @z
  260.  
  261. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  262. % [93] Set default directory name
  263. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  264. @x
  265. @ If no font directory has been specified, \.{\title} is supposed to use
  266. the default \.{TFM} directory, which is a system-dependent place where
  267. the \.{TFM} files for standard fonts are kept.
  268. The string variable |TFM_default_area| contains the name of this area.
  269. @^system dependencies@>
  270.  
  271. @d TFM_default_area_name=='TeXfonts:' {change this to the correct name}
  272. @d TFM_default_area_name_length=9 {change this to the correct length}
  273.  
  274. @<Glob...@>=
  275. @!TFM_default_area:packed array[1..TFM_default_area_name_length] of char;
  276. @y
  277. @ If no font directory has been specified, \.{\title} is supposed to use
  278. the default \.{TFM} directory, which is a system-dependent place where
  279. the \.{TFM} files for standard fonts are kept.
  280. @^system dependencies@>
  281.  
  282. Actually, under UNIX the standard area is defined in an external
  283. file \.{site.h}.  And the users have a path searched for fonts,
  284. by setting the \.{TEXFONTS} environment variable.
  285. @z
  286.  
  287. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  288. % [94] Remove initialization of now-defunct array
  289. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  290. @x
  291. @ @<Set init...@>=
  292. TFM_default_area:=TFM_default_area_name;
  293. @y
  294. @ (No initialization to be done.  Keep this module to preserve numbering.)
  295. @z
  296.  
  297. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  298. % [96] Open TFM file
  299. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  300. @x
  301. @<TFM: Open |tfm_file|@>=
  302. make_font_name(TFM_default_area_name_length)(TFM_default_area)(tfm_ext);
  303. reset(tfm_file,cur_name);
  304. if eof(tfm_file) then
  305. @^system dependencies@>
  306.   abort('---not loaded, TFM file can''t be opened!')
  307. @.TFM file can\'t be opened@>
  308. @y
  309. In C, we use the external |test_access| procedure, which also does path
  310. searching based on the user's environment or the default path.
  311. Note that |TFM_default_area_name_length| and |TFM_default_area| will not
  312. be used by |make_font_name|.
  313.  
  314. @<TFM: Open |tfm_file|@>=
  315. make_font_name(TFM_default_area_name_length)(TFM_default_area)(tfm_ext);
  316. if test_read_access(cur_name,TFM_FILE_PATH) then begin
  317.     reset(tfm_file,cur_name);
  318. end else begin
  319.     print_pascal_string(cur_name);
  320.     abort('---not loaded, TFM file can''t be opened!');
  321. @.TFM file can\'t be opened@>
  322. end;
  323. @z
  324.  
  325. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  326. % [103] Fix casting problem in C.
  327. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  328. @x
  329. @d tfm_b01(#)== {|tfm_b0..tfm_b1| as non-negative integer}
  330. if tfm_b0>127 then bad_font
  331. else #:=tfm_b0*256+tfm_b1
  332. @d tfm_b23(#)== {|tfm_b2..tfm_b3| as non-negative integer}
  333. if tfm_b2>127 then bad_font
  334. else #:=tfm_b2*256+tfm_b3
  335. @d tfm_squad(#)== {|tfm_b0..tfm_b3| as signed integer}
  336. if tfm_b0<128 then #:=((tfm_b0*256+tfm_b1)*256+tfm_b2)*256+tfm_b3
  337. else #:=(((tfm_b0-256)*256+tfm_b1)*256+tfm_b2)*256+tfm_b3
  338. @d tfm_uquad== {|tfm_b0..tfm_b3| as unsigned integer}
  339. (((tfm_b0*256+tfm_b1)*256+tfm_b2)*256+tfm_b3)
  340. @y
  341. @d tfm_b01(#)== {|tfm_b0..tfm_b1| as non-negative integer}
  342. if tfm_b0>127 then bad_font
  343. else #:=tfm_b0*toint(256)+tfm_b1
  344. @d tfm_b23(#)== {|tfm_b2..tfm_b3| as non-negative integer}
  345. if tfm_b2>127 then bad_font
  346. else #:=tfm_b2*toint(256)+tfm_b3
  347. @d tfm_squad(#)== {|tfm_b0..tfm_b3| as signed integer}
  348. if tfm_b0<128
  349. then #:=((tfm_b0*toint(256)+tfm_b1)*toint(256)+tfm_b2)*toint(256)+tfm_b3
  350. else #:=(((tfm_b0-toint(256))*toint(256)+tfm_b1)
  351.         *toint(256)+tfm_b2)*toint(256)+tfm_b3
  352. @d tfm_uquad== {|tfm_b0..tfm_b3| as unsigned integer}
  353. (((tfm_b0*toint(256)+tfm_b1)*toint(256)+tfm_b2)*toint(256)+tfm_b3)
  354. @z
  355.  
  356. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  357. % [109] Declare real_name_of_file.
  358. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  359. @x
  360. The program uses the binary file variable |dvi_file| for its main input
  361. file; |dvi_loc| is the number of the byte about to be read next from
  362. |dvi_file|.
  363.  
  364. @<Glob...@>=
  365. @!dvi_file:byte_file; {the stuff we are \.{\title}ing}
  366. @!dvi_loc:int_32; {where we are about to look, in |dvi_file|}
  367. @y
  368. The program uses the binary file variable |dvi_file| for its main input
  369. file; |dvi_loc| is the number of the byte about to be read next from
  370. |dvi_file|.
  371. In C, we also have a |real_name_of_file| string, that gets
  372. set by the external |test_access| procedure after path searching.
  373.  
  374. @<Glob...@>=
  375. @!dvi_file:byte_file; {the stuff we are \.{\title}ing}
  376. @!dvi_loc:int_32; {where we are about to look, in |dvi_file|}
  377. @!real_name_of_file:packed array[0..name_length] of text_char;
  378. i:integer; {loop control}
  379. @z
  380.  
  381. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  382. % [111] Fix up opening the binary files
  383. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  384. @x
  385. @ To prepare |dvi_file| for input, we |reset| it.
  386.  
  387. @<Open input file(s)@>=
  388. reset(dvi_file); {prepares to read packed bytes from |dvi_file|}
  389. dvi_loc:=0;
  390. @y
  391. @ To prepare |dvi_file| for input, we |reset| it.
  392.  
  393. @<Open input file(s)@>=
  394. argv(toint(1), cur_name);
  395. reset(dvi_file, cur_name);
  396. dvi_loc:=0;
  397. @z
  398.  
  399. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  400. % [113] Make dvi_length() and dvi_move() work.
  401. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  402. @x
  403. @p function dvi_length:int_32;
  404. begin set_pos(dvi_file,-1); dvi_length:=cur_pos(dvi_file);
  405. end;
  406. @#
  407. procedure dvi_move(@!n:int_32);
  408. begin set_pos(dvi_file,n); dvi_loc:=n;
  409. end;
  410. @y
  411. @p function dvi_length:int_32;
  412. begin checked_fseek(dvi_file, 0, 2);
  413. dvi_loc:=ftell(dvi_file);
  414. dvi_length:=dvi_loc;
  415. end;
  416. @#
  417. procedure dvi_move(n:int_32);
  418. begin checked_fseek(dvi_file, n, 0);
  419. dvi_loc:=n;
  420. end;
  421. @z
  422.  
  423. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  424. % [135] File names in lower case
  425. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  426. @x
  427. id3(".")("V")("F")(vf_ext); {file name extension for \.{VF} files}
  428. @y
  429. id3(".")("v")("f")(vf_ext); {file name extension for \.{VF} files}
  430. @z
  431.  
  432. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  433. % [137/138] Set default directory name
  434. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  435. @x
  436. @ If no font directory has been specified, \.{\title} is supposed to use
  437. the default \.{VF} directory, which is a system-dependent place where
  438. the \.{VF} files for standard fonts are kept.
  439. The string variable |VF_default_area| contains the name of this area.
  440. @^system dependencies@>
  441.  
  442. @d VF_default_area_name=='TeXvfonts:' {change this to the correct name}
  443. @d VF_default_area_name_length=10 {change this to the correct length}
  444.  
  445. @<Glob...@>=
  446. @!VF_default_area:packed array[1..VF_default_area_name_length] of char;
  447.  
  448. @ @<Set init...@>=
  449. VF_default_area:=VF_default_area_name;
  450. @y
  451. @ If no font directory has been specified, \.{\title} is supposed to use
  452. the default \.{VF} directory, which is a system-dependent place where
  453. the \.{VF} files for standard fonts are kept.
  454.  
  455. Actually, under UNIX the standard area is defined in an external
  456. file \.{site.h}.  And the users have a path searched for fonts,
  457. by setting the \.{VFFONTS} environment variable.
  458.  
  459. @ (No initialization to be done.  Keep this module to preserve numbering.)
  460. @z
  461.  
  462. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  463. % [139] Open VF file
  464. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  465. @x
  466. @<VF: Open |vf_file| or |goto not_found|@>=
  467. make_font_name(VF_default_area_name_length)(VF_default_area)(vf_ext);
  468. reset(vf_file,cur_name);
  469. if eof(vf_file) then
  470. @^system dependencies@>
  471.   goto not_found;
  472. vf_loc:=0
  473. @y
  474. In C, we use the external |test_access| procedure, which also does path
  475. searching based on the user's environment or the default path.
  476. Note that |VF_default_area_name_length| and |VF_default_area| will not
  477. be used by |make_font_name|.
  478.  
  479. @<VF: Open |vf_file| or |goto not_found|@>=
  480. make_font_name(VF_default_area_name_length)(VF_default_area)(vf_ext);
  481. if test_read_access(cur_name,VF_FILE_PATH) then begin
  482.     reset(vf_file,cur_name);
  483. end else goto not_found;
  484. vf_loc:=0
  485. @z
  486.  
  487. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  488. % [163] copy elements of array piece by piece
  489. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  490. @x
  491. @ @<VF: Start a new level@>=
  492. append_one(push);
  493. vf_move[vf_ptr]:=vf_move[vf_ptr-1];
  494. @y
  495. @ \.{web2c} does not like array assignments. So we need to do them
  496. through a macro replacement.
  497.  
  498. @d do_vf_move(#) == vf_move[vf_ptr]# := vf_move[vf_ptr-1]#
  499. @d vf_move_assign == begin do_vf_move([0][0]); do_vf_move([0][1]);
  500.                do_vf_move([1][0]); do_vf_move([1][1])
  501.              end
  502.  
  503. @<VF: Start a new level@>=
  504. append_one(push);
  505. vf_move_assign;
  506. @z
  507.  
  508. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  509. % [170] and again...
  510. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  511. @x
  512.   vf_move[vf_ptr]:=vf_move[vf_ptr-1];
  513. @y
  514.   vf_move_assign;
  515. @z
  516.  
  517.  
  518. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  519. % [175]
  520. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  521. @x
  522. @d update_terminal == break(output) {empty the terminal output buffer}
  523. @y
  524. @d update_terminal == flush(stdout) {empty the terminal output buffer}
  525. @d input == stdin {standard input}
  526. @z
  527.  
  528. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  529. % [175]
  530. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  531. @x
  532. procedure input_ln; {inputs a line from the terminal}
  533. var k:0..terminal_line_length;
  534. begin print('Enter option: '); update_terminal; reset(input);
  535. if eoln(input) then read_ln(input);
  536. k:=0; pckt_room(terminal_line_length);
  537. while (k<terminal_line_length)and not eoln(input) do
  538.   begin append_byte(xord[input^]); incr(k); get(input);
  539.   end;
  540. end;
  541. @y
  542. procedure input_ln; {inputs a line from the terminal}
  543. var k:0..terminal_line_length;
  544. begin print('Enter option: '); update_terminal;
  545. {|if eoln(input) then read_ln(input);|}
  546. k:=0; pckt_room(terminal_line_length);
  547. while (k<terminal_line_length)and not eoln(input) do
  548.   begin append_byte(xord[getc(input)]); incr(k);
  549.   end;
  550. end;
  551. @z
  552.  
  553. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  554. % [179] update read pointer within loop
  555. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  556. @x
  557.   else  begin print_ln('Valid options are:'); @<Print valid options@>@;
  558.     end;
  559. @y
  560.   else  begin print_ln('Valid options are:'); @<Print valid options@>@;
  561.     end;
  562.   if eoln(input) then read_ln(input); 
  563. @z
  564.  
  565. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  566. % [231] Check usage; remove unused label
  567. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  568. @x
  569. @p begin initialize; {get all variables initialized}
  570. @<Initialize predefined strings@>@;
  571. @y
  572. @p begin
  573. set_paths (TFM_FILE_PATH_BIT + VF_FILE_PATH_BIT);
  574. initialize; {get all variables initialized}
  575. if argc <> 3 then
  576.   begin write_ln('Usage: dvicopy <dvi file> <outfile>.'); 
  577.   uexit(1);
  578.   end;
  579. @<Initialize predefined strings@>@;
  580. @z
  581.  
  582. @x
  583. final_end:end.
  584. @y
  585. end.
  586. @z
  587.  
  588. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  589. % [234] Declare DVI filename
  590. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  591. @x
  592. @!out_file:byte_file; {the \.{DVI} file we are writing}
  593. @y
  594. @!out_file:byte_file; {the \.{DVI} file we are writing}
  595. @!outf_name:packed array[1..PATH_MAX] of char;
  596. @z
  597.  
  598. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  599. % [236] Get DVI filename
  600. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  601. @x
  602. @<Open output file(s)@>=
  603. rewrite(out_file); {prepares to write packed bytes to |out_file|}
  604. @y
  605. @<Open output file(s)@>=
  606. argv(toint(2), outf_name);
  607. rewrite(out_file, outf_name); {prepares to write packed bytes to |out_file|}
  608. @z
  609.  
  610. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  611. % [238] Fix up output of bytes.
  612. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  613. @x
  614. @ Writing the |out_file| should be done as efficient as possible for a
  615. particular system; on many systems this means that a large number of
  616. bytes will be accumulated in a buffer and is then written from that
  617. buffer to |out_file|. In order to simplify such system dependent changes
  618. we use the \.{WEB} macro |out_byte| to write the next \.{DVI} byte. Here
  619. we give a simple minded definition for this macro in terms of standard
  620. \PASCAL.
  621. @^system dependencies@>
  622. @^optimization@>
  623.  
  624. @d out_byte(#) == write(out_file,#) {write next \.{DVI} byte}
  625. @y
  626. @ Writing the |out_file| should be done as efficient as possible;
  627. on many systems this means that a large number of
  628. bytes will be accumulated in a buffer and is then written from that
  629. buffer to |out_file|.
  630. Under UNIX we assume that using the buffered I/O will be sufficiently
  631. efficient. Thus we map |out_byte| to |put_byte|, which is defined
  632. externally.
  633. @^optimization@>
  634.  
  635. @d out_byte(#) == put_byte(#,out_file) {write next \.{DVI} byte}
  636. @z
  637.  
  638. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  639. % [250] Initialization of the out_pre_string
  640. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  641. @x
  642. @!comment:packed array[1..comm_length] of char; {preamble comment prefix}
  643. @y
  644. @!comment:c_char_pointer; {preamble comment prefix}
  645. @z
  646.  
  647.