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 / web / weave.ch < prev    next >
Text File  |  1996-09-28  |  20KB  |  569 lines

  1. % weave.ch for C compilation using web2c.
  2. %
  3. % The original version of this file, for Pascal compilation using pc,
  4. % was created by Howard Trickey and Pavel Curtis.
  5. %
  6. % History:
  7. %  11/29/82 HWT Original version. This modifies weave to allow a new
  8. %               control sequence:
  9. %                       @=...text...@>   Put ...text... verbatim on a line
  10. %                                        by itself in the Pascal output.
  11. %                                        (argument must fit on one line)
  12. %               This control sequence facilitates putting #include "gcons.h"
  13. %               (for example) in files meant for the pc compiler.
  14. %               Also, there is a command line option, -c, which means that
  15. %               only the modules affected by the change file are to generate
  16. %               TeX output.  (All the limbo stuff still goes to the output
  17. %               file, as does the index and table of contents.)
  18. %
  19. %  2/12/83 HWT  Brought up for use with version 1.3.  Uses Knuth's new
  20. %               control sequences for verbatim Pascal (as above, without
  21. %               the "on one line" part), and the force_line (@\) primitive.
  22. %               Also, he added stuff to keep track of changed modules, and
  23. %               output enough information that macros can choose only to
  24. %               print changed modules.  This isn't as efficient as my
  25. %               implementation because I avoided outputting the text for
  26. %               non-changed modules altogether, but this feature won't be
  27. %               used too often (just for TeX and TeXware), so Knuth's
  28. %               solution is accepted.
  29. %               The change file changes that used
  30. %               to implement these features have been removed.
  31. %               There is a -x flag to cause WEAVE to omit cross referencing
  32. %               of identifiers, and index and T.of.C. processing.
  33. %               This, too, is unnecessary, for one could simply redefine some
  34. %               WEB macros to avoid the printing, but there are only a couple
  35. %               of easy changes, so they have been made.
  36. %
  37. %  2/18     HWT Increased stack size to 400 (not for TeX-related programs).
  38. %
  39. %  3/18     HWT Brought up for Version 1.5.  Made it print newline at end of
  40. %               run.
  41. %
  42. %  4/13     PC  Merged with Pavel's version, including adding a call to
  43. %               exit() at the end of the program, based upon the value of
  44. %               `history'.
  45. %  4/16     PC  Brought up to version 1.5 released with TeX 0.97 in April 1983
  46. %  6/29     HWT Brought up to version 1.7 released with TeX 0.99 in June 1983,
  47. %        introducing a new change file format
  48. %  7/17        HWT Brought up to version 2.0 released with TeX 0.999 in July 1983
  49. %  7/29     HWT Brought up to version 2.1
  50. % 11/17     HWT Brought up to version 2.4 released with TeX 1.0.  Made
  51. %        changes to use C routines for I/O, for speedup.
  52. %  1/31     HWT Brought up to version 2.6
  53. %  12/15/85 ETM Brought up to version 2.8
  54. %  03/15/88 ETM Converted for use with WEB to C, and for version 2.9 of Weave.
  55. %  11/30/89 KB  Version 4.
  56. % (more recent changes in ../ChangeLog.W2C and ChangeLog)
  57.  
  58.  
  59. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  60. % [0] WEAVE: print changes only
  61. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  62. @x
  63. \pageno=\contentspagenumber \advance\pageno by 1
  64. @y
  65. \pageno=\contentspagenumber \advance\pageno by 1
  66. \let\maybe=\iffalse
  67. \def\title{WEAVE changes for C}
  68. @z
  69.  
  70. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  71. % [1] Change banner message
  72. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  73. @x
  74. @d banner=='This is WEAVE, Version 4.4'
  75. @y
  76. @d banner=='This is WEAVE, Version 4.4' {more is printed later}
  77. @z
  78.  
  79. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  80. % [2] add input and output, remove other files, add ref to scan_args,
  81. % [2]       and #include external definition for exit(), etc.
  82. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  83. @x
  84. program WEAVE(@!web_file,@!change_file,@!tex_file);
  85. label end_of_WEAVE; {go here to finish}
  86. const @<Constants in the outer block@>@/
  87. type @<Types in the outer block@>@/
  88. var @<Globals in the outer block@>@/
  89. @<Error handling procedures@>@/
  90. @y
  91. program WEAVE;
  92. const @<Constants in the outer block@>@/
  93. type @<Types in the outer block@>@/
  94. var @<Globals in the outer block@>@/
  95. @\
  96. @\@/
  97. @<Error handling procedures@>@/
  98. @<|scan_args| procedure@>@/
  99. @z
  100.  
  101. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  102. % [4] compiler options
  103. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  104. @x
  105. @{@&$C-,A+,D-@} {no range check, catch arithmetic overflow, no debug overhead}
  106. @!debug @{@&$C+,D+@}@+ gubed {but turn everything on when debugging}
  107. @y
  108. @z
  109.  
  110. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  111. % [8] Constants: increase stack size.
  112. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  113. @x
  114. @!stack_size=200; {number of simultaneous output levels}
  115. @y
  116. @!stack_size=400; {number of simultaneous output levels}
  117. @z
  118.  
  119. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  120. % [??] The text_char type is used as an array index into xord.  The
  121. % default type `char' produces signed integers, which are bad array
  122. % indices in C.
  123. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 
  124. @x
  125. @d text_char == char {the data type of characters in text files}
  126. @y
  127. @d text_char == ASCII_code {the data type of characters in text files}
  128. @z
  129.  
  130. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  131. % [17] enable maximum character set
  132. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  133. @x
  134. for i:=1 to @'37 do xchr[i]:=' ';
  135. for i:=@'200 to @'377 do xchr[i]:=' ';
  136. @y
  137. for i:=1 to @'37 do xchr[i]:=chr(i);
  138. for i:=@'200 to @'377 do xchr[i]:=chr(i);
  139. @z
  140.  
  141. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  142. % [20] Terminal I/O.
  143. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  144. @x
  145. @d print(#)==write(term_out,#) {`|print|' means write on the terminal}
  146. @y
  147. @d term_out==stdout
  148. @d print(#)==write(term_out,#) {`|print|' means write on the terminal}
  149. @z
  150.  
  151. @x
  152. @<Globals...@>=
  153. @!term_out:text_file; {the terminal as an output file}
  154. @y
  155. @z
  156.  
  157. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  158. % [21] Don't initialize the terminal.
  159. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  160. @x
  161. @ Different systems have different ways of specifying that the output on a
  162. certain file will appear on the user's terminal. Here is one way to do this
  163. on the \PASCAL\ system that was used in \.{TANGLE}'s initial development:
  164. @^system dependencies@>
  165.  
  166. @<Set init...@>=
  167. rewrite(term_out,'TTY:'); {send |term_out| output to the terminal}
  168. @y
  169. @ Different systems have different ways of specifying that the output on a
  170. certain file will appear on the user's terminal.
  171. @^system dependencies@>
  172.  
  173. @<Set init...@>=
  174. {nothing need be done}
  175. @z
  176.  
  177. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  178. % [22] `break' is `flush'.
  179. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  180. @x
  181. @d update_terminal == break(term_out) {empty the terminal output buffer}
  182. @y
  183. @d update_terminal == flush(term_out) {empty the terminal output buffer}
  184. @z
  185.  
  186. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  187. % [24] Open input files.
  188. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  189. @x
  190. @ The following code opens the input files.  Since these files were listed
  191. in the program header, we assume that the \PASCAL\ runtime system has
  192. already checked that suitable file names have been given; therefore no
  193. additional error checking needs to be done. We will see below that
  194. \.{WEAVE} reads through the entire input twice.
  195. @^system dependencies@>
  196.  
  197. @p procedure open_input; {prepare to read |web_file| and |change_file|}
  198. begin reset(web_file); reset(change_file);
  199. end;
  200. @y
  201. @ The following code opens the input files.
  202. This is called after |scan_args| has set the file name variables
  203. appropriately.
  204. @^system dependencies@>
  205.  
  206. @p procedure open_input; {prepare to read |web_file| and |change_file|}
  207. begin reset(web_file,web_file_name);
  208.       reset(change_file,change_file_name);
  209. end;
  210. @z
  211.  
  212. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  213. % [26] Opening the .tex file.
  214. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  215. @x
  216. @ The following code opens |tex_file|.
  217. Since this file was listed in the program header, we assume that the
  218. \PASCAL\ runtime system has checked that a suitable external file name has
  219. been given.
  220. @^system dependencies@>
  221.  
  222. @<Set init...@>=
  223. rewrite(tex_file);
  224. @y
  225. @ The following code opens |tex_file|.
  226. The |scan_args| procedure is used to set up |tex_file_name| as required.
  227. @^system dependencies@>
  228.  
  229. @<Set init...@>=
  230. scan_args;
  231. rewrite(tex_file,tex_file_name);
  232. @z
  233.  
  234. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  235. % [28] web2c doesn't understand f^.
  236. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  237. @x
  238.     begin buffer[limit]:=xord[f^]; get(f);
  239.     incr(limit);
  240.     if buffer[limit-1]<>" " then final_limit:=limit;
  241.     if limit=buf_size then
  242.       begin while not eoln(f) do get(f);
  243. @y
  244.     begin buffer[limit]:=xord[getc(f)];
  245.     incr(limit);
  246.     if buffer[limit-1]<>" " then final_limit:=limit;
  247.     if limit=buf_size then
  248.       begin while not eoln(f) do vgetc(f);
  249. @z
  250.  
  251. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  252. % [??] Fix jump_out
  253. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  254. @x
  255. @ The |jump_out| procedure just cuts across all active procedure levels
  256. and jumps out of the program. This is the only non-local \&{goto} statement
  257. in \.{WEAVE}. It is used when no recovery from a particular error has
  258. been provided.
  259.  
  260. Some \PASCAL\ compilers do not implement non-local |goto| statements.
  261. @^system dependencies@>
  262. In such cases the code that appears at label |end_of_WEAVE| should be
  263. copied into the |jump_out| procedure, followed by a call to a system procedure
  264. that terminates the program.
  265.  
  266. @d fatal_error(#)==begin new_line; print(#); error; mark_fatal; jump_out;
  267.   end
  268.  
  269. @<Error handling...@>=
  270. procedure jump_out;
  271. begin goto end_of_WEAVE;
  272. end;
  273. @y
  274. @ The |jump_out| procedure cleans up, prints appropriate messages,
  275. and exits back to the operating system.
  276.  
  277. @d fatal_error(#)==begin new_line; print(#); error; mark_fatal; jump_out;
  278.     end
  279.  
  280. @<Error handling...@>=
  281. procedure jump_out;
  282. begin
  283. stat @<Print statistics about memory usage@>;@+tats@;@/
  284. @t\4\4@>{here files should be closed if the operating system requires it}
  285.   @<Print the job |history|@>;
  286.   new_line;
  287.   if (history <> spotless) and (history <> harmless_message) then
  288.     uexit(1)
  289.   else
  290.     uexit(0);
  291. end;
  292. @z
  293.  
  294. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  295. % [50] don't enter xrefs if no_xref set
  296. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  297. @x
  298. @d append_xref(#)==if xref_ptr=max_refs then overflow('cross reference')
  299.   else  begin incr(xref_ptr); num(xref_ptr):=#;
  300.     end
  301.  
  302. @p procedure new_xref(@!p:name_pointer);
  303. label exit;
  304. var q:xref_number; {pointer to previous cross reference}
  305. @!m,@!n: sixteen_bits; {new and previous cross-reference value}
  306. begin if (reserved(p)or(byte_start[p]+1=byte_start[p+ww]))and
  307. @y
  308. If the user has sent the |no_xref| flag (the -x option of the command line),
  309. then it is unnecessary to keep track of cross references for identifers.
  310. If one were careful, one could probably make more changes around module
  311. 100 to avoid a lot of identifier looking up.
  312.  
  313. @d append_xref(#)==if xref_ptr=max_refs then overflow('cross reference')
  314.   else  begin incr(xref_ptr); num(xref_ptr):=#;
  315.     end
  316.  
  317. @p procedure new_xref(@!p:name_pointer);
  318. label exit;
  319. var q:xref_number; {pointer to previous cross-reference}
  320. @!m,@!n: sixteen_bits; {new and previous cross-reference value}
  321. begin if no_xref then return;
  322. if (reserved(p)or(byte_start[p]+1=byte_start[p+ww]))and
  323. @z
  324.  
  325. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  326. % [239] omit index and module names if no_xref set
  327. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  328. @x
  329. @<Phase III: Output the cross-reference index@>=
  330. @y
  331. If the user has set the |no_xref| flag (the -x option on the command line),
  332. just finish off the page, omitting the index, module name list, and table of
  333. contents.
  334.  
  335. @<Phase III: Output the cross-reference index@>=
  336. if no_xref then begin
  337.         finish_line;
  338.         out("\"); out5("v")("f")("i")("l")("l");
  339.         out4("\")("e")("n")("d");
  340.         finish_line;
  341.         end
  342. else begin
  343. @z
  344.  
  345. @x
  346. print('Done.');
  347. @y
  348. end;
  349. print('Done.');
  350. @z
  351.  
  352. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  353. % [258] term_in == stdin, when debugging.
  354. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  355. @x
  356. any error stop will set |debug_cycle| to zero.
  357. @y
  358. any error stop will set |debug_cycle| to zero.
  359.  
  360. @d term_in==stdin
  361. @z
  362.  
  363. @x
  364. @!term_in:text_file; {the user's terminal as an input file}
  365. @y
  366. @z
  367.  
  368. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  369. % [259] Take out reset(term_in)
  370. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  371. @x
  372. reset(term_in,'TTY:','/I'); {open |term_in| as the terminal, don't do a |get|}
  373. @y
  374. @z
  375.  
  376. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  377. % [261] print newline at end of run and exit based upon value of history
  378. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  379. @x
  380. print_ln(banner); {print a ``banner line''}
  381. @y
  382. print (banner); {print a ``banner line''}
  383. print_ln (version_string);
  384. @z
  385.  
  386. @x
  387. end_of_WEAVE:
  388. stat @<Print statistics about memory usage@>;@+tats@;@/
  389. @t\4\4@>{here files should be closed if the operating system requires it}
  390. @<Print the job |history|@>;
  391. end.
  392. @y
  393. jump_out;
  394. end.
  395. @z
  396.  
  397. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  398. % [264] system dependent changes--the scan_args procedure
  399. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  400. @x
  401. @* System-dependent changes.
  402. This module should be replaced, if necessary, by changes to the program
  403. that are necessary to make \.{WEAVE} work at a particular installation.
  404. It is usually best to design your change file so that all changes to
  405. previous modules preserve the module numbering; then everybody's version
  406. will be consistent with the printed program. More extensive changes,
  407. which introduce new modules, can be inserted here; then only the index
  408. itself will get a new module number.
  409. @^system dependencies@>
  410. @y
  411. @* System-dependent changes.
  412. The user calls \.{WEAVE} with arguments on the command line.
  413. These are either file names or flags (beginning with '-').
  414. The following globals are for communicating the user's desires to the rest
  415. of the program.  The various |file_name| variables contain strings with
  416. the full names of those files, as UNIX knows them.
  417.  
  418. The only flag that affects weave is |'-x'| whose status is kept in |no_xref|.
  419.  
  420. @d max_file_name_length==100
  421.  
  422. @<Globals...@>=
  423. @!web_file_name,@!change_file_name,@!tex_file_name:
  424.         array[1..max_file_name_length] of char;
  425. @!no_xref:boolean;
  426.  
  427. @ The |scan_args| procedure looks at the command line arguments and sets
  428. the |file_name| variables accordingly.  At least one file name must be
  429. present: the \.{WEB} file.  It may have an extension, or it may omit it
  430. to get |'.web'| added.  The \TeX\ output file name is formed by
  431. replacing the \.{WEB} file name extension by |'.tex'|.
  432.  
  433. If there is another file name present among the arguments, it is the
  434. change file, again either with an extension or without one to get
  435. |'.ch'| An omitted change file argument means that |'/dev/null'| should
  436. be used, when no changes are desired.
  437.  
  438. An argument beginning with a minus sign is a flag.  Any letters
  439. following the minus sign may cause global flag variables to be set.
  440. Currently, an |x| means that the cross referencing information---the
  441. index, the module name list, and the table of contents---is to be
  442. suppressed.
  443.  
  444. @<|scan_args|...@>=
  445. procedure scan_args;
  446. var slash_pos, dot_pos,i,a: integer; {indices}
  447. @!fname: array[1..max_file_name_length-5] of char; {temporary argument holder}
  448. @!found_web,@!found_change: boolean; {|true| when those file names have
  449.                                         been seen}
  450. begin
  451. found_web:=false;
  452. found_change:=false;
  453. no_xref:=false;
  454. for a:=1 to argc-1 do begin
  455.         argv(a,fname); {put argument number |a| into |fname|}
  456.         if fname[1]<>'-' then begin
  457.                 if not found_web then
  458.                         @<Get |web_file_name|, |pascal_file_name|, and
  459.                                 | pool_file_name| variables from |fname|@>
  460.                 else if not found_change then
  461.                         @<Get |change_file_name| from |fname|@>
  462.                 else  @<Print usage error message and quit@>;
  463.                 end
  464.         else @<Handle flag argument in |fname|@>;
  465.         end;
  466. if not found_web then @<Print usage error message and quit@>;
  467. if not found_change then @<Set up null change file@>;
  468. end;
  469.  
  470. @ Use all of |fname| for the |web_file_name| if there is a |'.'| in it,
  471. otherwise add |'.web'|.  The other file names come from adding things
  472. after the dot.  The |argv| procedure will not put more than
  473. |max_file_name_length-5| characters into |fname|, and this leaves enough
  474. room in the |file_name| variables to add the extensions.
  475.  
  476. The end of a file name is marked with a |' '|, the convention assumed by 
  477. the |reset| and |rewrite| procedures.
  478.  
  479. @<Get |web_file_name|...@>=
  480. begin
  481.   dot_pos := -1;
  482.   slash_pos := -1;
  483.   i := 1;
  484.   while (fname[i] <> ' ') and (i <= max_file_name_length - 5)
  485.   do begin
  486.     web_file_name[i] := fname[i];
  487.     if fname[i] = '.' then dot_pos := i;
  488.     if fname[i] = '/' then slash_pos := i;
  489.     incr (i);
  490.   end;
  491.   web_file_name[i] := ' ';
  492.   
  493.   if (dot_pos = -1) or (dot_pos < slash_pos)
  494.   then begin
  495.     dot_pos := i;
  496.     web_file_name[dot_pos]   := '.';
  497.     web_file_name[dot_pos+1] := 'w';
  498.     web_file_name[dot_pos+2] := 'e';
  499.     web_file_name[dot_pos+3] := 'b';
  500.     web_file_name[dot_pos+4] := ' ';
  501.   end;
  502.  
  503.   for i := 1 to dot_pos do
  504.     tex_file_name[i] := web_file_name[i];
  505.  
  506.   tex_file_name[dot_pos+1] := 't';
  507.   tex_file_name[dot_pos+2] := 'e';
  508.   tex_file_name[dot_pos+3] := 'x';
  509.   tex_file_name[dot_pos+4] := ' ';
  510.  
  511.   found_web := true;
  512. end
  513.  
  514. @ @<Get |change_file_name|...@>=
  515. begin
  516.   dot_pos := -1;
  517.   slash_pos := -1;
  518.   i := 1;
  519.   while (fname[i] <> ' ') and (i <= max_file_name_length - 5)
  520.   do begin
  521.     change_file_name[i] := fname[i];
  522.     if fname[i] = '.' then dot_pos := i;
  523.     if fname[i] = '/' then slash_pos := i;
  524.     incr (i);
  525.   end;
  526.   change_file_name[i] := ' ';
  527.  
  528.   if (dot_pos = -1) or (dot_pos < slash_pos)
  529.   then begin
  530.     dot_pos := i;
  531.     change_file_name[dot_pos]   := '.';
  532.     change_file_name[dot_pos+1] := 'c';
  533.     change_file_name[dot_pos+2] := 'h';
  534.     change_file_name[dot_pos+3] := ' ';
  535.   end;
  536.  
  537.   found_change := true;
  538. end
  539.  
  540. @ @<Set up null...@>=
  541. begin
  542.   change_file_name[1]:='/';
  543.   change_file_name[2]:='d';
  544.   change_file_name[3]:='e';
  545.   change_file_name[4]:='v';
  546.   change_file_name[5]:='/';
  547.   change_file_name[6]:='n';
  548.   change_file_name[7]:='u';
  549.   change_file_name[8]:='l';
  550.   change_file_name[9]:='l';
  551.   change_file_name[10]:=' ';
  552. end
  553.  
  554. @ @<Handle flag...@>=
  555. begin
  556. i:=2;
  557. while (fname[i]<>' ') and (i<=max_file_name_length-5) do begin
  558.         if fname[i]='x' then no_xref:=true;
  559.         incr(i);
  560.         end;
  561. end
  562.  
  563. @ @<Print usage error message and quit@>=
  564. begin
  565.   print_ln ('Usage: weave webfile[.web] [changefile[.ch]] [-x].');
  566.   uexit (1);
  567. end
  568. @z
  569.