beta-0.89.2
[luatex.git] / source / texk / web2c / cwebdir / comm-ql.ch
blob8859e215b2adc0c055e67b5cb4e83e93013a3d6a
1 This is the change file for CWEB's COMMON under QSOD/SMSQ
2 (Contributed by Robert H. Klein, September 1994)
4 This change file is intended for use with C68 v4.13 (or later).
5 compile with
6 ex <dev_>cc;'-v -h -c -=500000 -DCWEBINPUTS=flp2_ common_c'
11 \def\v{\char'174} % vertical (|) in typewriter font
13 \def\title{Common code for CTANGLE and CWEAVE (Version 3.64)}
14 \def\topofcontents{\null\vfill
15   \centerline{\titlefont Common code for {\ttitlefont CTANGLE} and
16     {\ttitlefont CWEAVE}}
17   \vskip 15pt
18   \centerline{(Version 3.64)}
19   \vfill}
20 \def\botofcontents{\vfill
21 \noindent
23 \def\v{\char'174} % vertical (|) in typewriter font
25 \def\title{Common code for CTANGLE and CWEAVE (QL Version 3.64)}
26 \def\topofcontents{\null\vfill
27   \centerline{\titlefont Common code for {\ttitlefont CTANGLE} and
28     {\ttitlefont CWEAVE}}
29   \vskip 15pt
30   \centerline{(Version 3.64)}
31   \vfill}
32 \def\botofcontents{\vfill
33 \noindent
37 The line number of each open file is also kept for error reporting and
38 for the benefit of \.{CTANGLE}.
40 @f line x /* make |line| an unreserved word */
41 @d max_include_depth 10 /* maximum number of source files open
42   simultaneously, not counting the change file */
43 @d max_file_name_length 60
44 @d cur_file file[include_depth] /* current file */
45 @d cur_file_name file_name[include_depth] /* current file name */
46 @d cur_line line[include_depth] /* number of current line in current file */
47 @d web_file file[0] /* main source file */
48 @d web_file_name file_name[0] /* main source file name */
50 The line number of each open file is also kept for error reporting and
51 for the benefit of \.{CTANGLE}.
53 For use on QDOS/SMSQ systems the variable |max_file_name_length| is shortened
54 to 42 characters, i.e. 5 characters for the device name, 36 characters
55 for the file name plus one character as string terminator. (Note that
56 (current) QDOS/SMSQ file systems have a limitation of 36 characters as
57 maximum length for a file name.
59 @f line x /* make |line| an unreserved word */
60 @d max_include_depth 10 /* maximum number of source files open
61   simultaneously, not counting the change file */
62 @d max_file_name_length 42
63 @d cur_file file[include_depth] /* current file */
64 @d cur_file_name file_name[include_depth] /* current file name */
65 @d cur_line line[include_depth] /* number of current line in current file */
66 @d web_file file[0] /* main source file */
67 @d web_file_name file_name[0] /* main source file name */
72     cur_file_name[l]='/'; /* \UNIX/ pathname separator */
74     cur_file_name[l]='_'; /* QDOS/SMSQ pathname separator */
79 @ We now must look at the command line arguments and set the file names
80 accordingly.  At least one file name must be present: the \.{CWEB}
81 file.  It may have an extension, or it may omit the extension to get |".w"| or
82 |".web"| added.  The \TEX/ output file name is formed by replacing the \.{CWEB}
83 file name extension by |".tex"|, and the \CEE/ file name by replacing
84 the extension by |".c"|, after removing the directory name (if any).
86 If there is a second file name present among the arguments, it is the
87 change file, again either with an extension or without one to get |".ch"|.
88 An omitted change file argument means that |"/dev/null"| should be used,
89 when no changes are desired.
90 @^system dependencies@>
92 If there's a third file name, it will be the output file.
94 @<Pred...@>=
95 void scan_args();
97 @ @c
98 void
99 scan_args()
101   char *dot_pos; /* position of |'.'| in the argument */
102   char *name_pos; /* file name beginning, sans directory */
103   register char *s; /* register for scanning strings */
104   boolean found_web=0,found_change=0,found_out=0;
105              /* have these names have been seen? */
106   boolean flag_change;
108   while (--argc > 0) {
109     if ((**(++argv)=='-'||**argv=='+')&&*(*argv+1)) @<Handle flag argument@>@;
110     else {
111       s=name_pos=*argv;@+dot_pos=NULL;
112       while (*s) {
113         if (*s=='.') dot_pos=s++;
114         else if (*s=='/') dot_pos=NULL,name_pos=++s;
115         else s++;
116       }
117       if (!found_web) @<Make
118        |web_file_name|, |tex_file_name| and |C_file_name|@>@;
119       else if (!found_change) @<Make |change_file_name| from |fname|@>@;
120       else if (!found_out) @<Override |tex_file_name| and |C_file_name|@>@;
121         else @<Print usage error message and quit@>;
122     }
123   }
124   if (!found_web) @<Print usage error message and quit@>;
125   if (found_change<=0) strcpy(change_file_name,"/dev/null");
128 @ We use all of |*argv| for the |web_file_name| if there is a |'.'| in it,
129 otherwise we add |".w"|. If this file can't be opened, we prepare an
130 |alt_web_file_name| by adding |"web"| after the dot.
131 The other file names come from adding other things
132 after the dot.  We must check that there is enough room in
133 |web_file_name| and the other arrays for the argument.
135 @<Make |web_file_name|...@>=
137   if (s-*argv > max_file_name_length-5)
138     @<Complain about argument length@>;
139   if (dot_pos==NULL)
140     sprintf(web_file_name,"%s.w",*argv);
141   else {
142     strcpy(web_file_name,*argv);
143     *dot_pos=0; /* string now ends where the dot was */
144   }
145   sprintf(alt_web_file_name,"%s.web",*argv);
146   sprintf(tex_file_name,"%s.tex",name_pos); /* strip off directory name */
147   sprintf(idx_file_name,"%s.idx",name_pos);
148   sprintf(scn_file_name,"%s.scn",name_pos);
149   sprintf(C_file_name,"%s.c",name_pos);
150   found_web=1;
153 @ @<Make |change_file_name|...@>=
155   if (strcmp(*argv,"-")==0) found_change=-1;
156   else {
157     if (s-*argv > max_file_name_length-4)
158       @<Complain about argument length@>;
159     if (dot_pos==NULL)
160       sprintf(change_file_name,"%s.ch",*argv);
161     else strcpy(change_file_name,*argv);
162     found_change=1;
163   }
166 @ @<Override...@>=
168   if (s-*argv > max_file_name_length-5)
169     @<Complain about argument length@>;
170   if (dot_pos==NULL) {
171     sprintf(tex_file_name,"%s.tex",*argv);
172     sprintf(idx_file_name,"%s.idx",*argv);
173     sprintf(scn_file_name,"%s.scn",*argv);
174     sprintf(C_file_name,"%s.c",*argv);
175   } else {
176     strcpy(tex_file_name,*argv);
177     strcpy(C_file_name,*argv);
178     if (flags['x']) { /* indexes will be generated */
179       *dot_pos=0;
180       sprintf(idx_file_name,"%s.idx",*argv);
181       sprintf(scn_file_name,"%s.scn",*argv);
182     }
183   }
184   found_out=1;
187 @ We now must look at the command line arguments and set the file names
188 accordingly.  At least one file name must be present: the \.{CWEB}
189 file.  It may have an extension, or it may omit the extension to get |"_w"| or
190 |"_web"| added.  The \TEX/ output file name is formed by replacing the \.{CWEB}
191 file name extension by |"_tex"|, and the \CEE/ file name by replacing
192 the extension by |"_c"|, after removing the directory name (if any).
194 If there is a second file name present among the arguments, it is the
195 change file, again either with an extension or without one to get |"_ch"|.
196 An omitted change file argument means that |"NUL"| should be used,
197 when no changes are desired.
198 @^system dependencies@>
200 If there's a third file name, it will be the output file.
202 Because |"_"| is a directory {\em and} extension separator, \.{CWEB} will
203 always use the {\em full} name (i.e. with full path).  Fortunately the
204 routine has been written to search for the last ``dot'', so the altered
205 version will search for the last |"_"| (including directory separators),
206 so we have what we want.
208 @<Pred...@>=
209 void scan_args();
211 @ @c
212 void
213 scan_args()
215   char *dot_pos; /* position of |'_'| in the argument */
216   char *name_pos; /* file name beginning, sans directory */
217   register char *s; /* register for scanning strings */
218   boolean found_web=0,found_change=0,found_out=0;
219              /* have these names have been seen? */
220   boolean flag_change;
222   while (--argc > 0) {
223     if ((**(++argv)=='-'||**argv=='+')&&*(*argv+1)) @<Handle flag argument@>@;
224     else {
225       s=name_pos=*argv;@+dot_pos=NULL;
226       while (*s) {
227         if (*s=='_') dot_pos=s++;
228         else if (*s=='_') dot_pos=NULL,name_pos=++s;
229         else s++;
230       }
231       if (!found_web) @<Make
232        |web_file_name|, |tex_file_name| and |C_file_name|@>@;
233       else if (!found_change) @<Make |change_file_name| from |fname|@>@;
234       else if (!found_out) @<Override |tex_file_name| and |C_file_name|@>@;
235         else @<Print usage error message and quit@>;
236     }
237   }
238   if (!found_web) @<Print usage error message and quit@>;
239   if (found_change<=0) strcpy(change_file_name,"NUL");
242 @ We use all of |*argv| for the |web_file_name| if there is a |'_'| in it,
243 otherwise we add |"_w"|. If this file can't be opened, we prepare an
244 |alt_web_file_name| by adding |"web"| after the dot.
245 The other file names come from adding other things
246 after the dot.  We must check that there is enough room in
247 |web_file_name| and the other arrays for the argument.
249 If you've read the section before carefully you'll have noticed, that
250 QDOS/SMSQ file names contain almost a |"_"|, so this routine will not work,
251 i.e. you'll {\em have} to add the |"_w"| always.  Nevertheless I adapted
252 the routine as if it would work.
254 @<Make |web_file_name|...@>=
256   if (s-*argv > max_file_name_length-5)
257     @<Complain about argument length@>;
258   if (dot_pos==NULL)
259     sprintf(web_file_name,"%s_w",*argv);
260   else {
261     strcpy(web_file_name,*argv);
262     *dot_pos=0; /* string now ends where the dot was */
263   }
264   sprintf(alt_web_file_name,"%s_web",*argv);
265   sprintf(tex_file_name,"%s_tex",name_pos); /* strip off directory name */
266   sprintf(idx_file_name,"%s_idx",name_pos);
267   sprintf(scn_file_name,"%s_scn",name_pos);
268   sprintf(C_file_name,"%s_c",name_pos);
269   found_web=1;
272 @ @<Make |change_file_name|...@>=
274   if (strcmp(*argv,"-")==0) found_change=-1;
275   else {
276     if (s-*argv > max_file_name_length-4)
277       @<Complain about argument length@>;
278     if (dot_pos==NULL)
279       sprintf(change_file_name,"%s_ch",*argv);
280     else strcpy(change_file_name,*argv);
281     found_change=1;
282   }
285 @ @<Override...@>=
287   if (s-*argv > max_file_name_length-5)
288     @<Complain about argument length@>;
289   if (dot_pos==NULL) {
290     sprintf(tex_file_name,"%s_tex",*argv);
291     sprintf(idx_file_name,"%s_idx",*argv);
292     sprintf(scn_file_name,"%s_scn",*argv);
293     sprintf(C_file_name,"%s_c",*argv);
294   } else {
295     strcpy(tex_file_name,*argv);
296     strcpy(C_file_name,*argv);
297     if (flags['x']) { /* indexes will be generated */
298       *dot_pos=0;
299       sprintf(idx_file_name,"%s_idx",*argv);
300       sprintf(scn_file_name,"%s_scn",*argv);
301     }
302   }
303   found_out=1;
309 @ @<Print usage error message and quit@>=
311 if (program==ctangle)
312   fatal(
313 "! Usage: ctangle [options] webfile[.w] [{changefile[.ch]|-} [outfile[.c]]]\n"
314    ,"");
315 @.Usage:@>
316 else fatal(
317 "! Usage: cweave [options] webfile[.w] [{changefile[.ch]|-} [outfile[.tex]]]\n"
318    ,"");
321 @ @<Print usage error message and quit@>=
323 if (program==ctangle)
324   fatal(
325 "! Usage: ctangle [options] webfile[_w] [{changefile[_ch]|-} [outfile[_c]]]\n"
326    ,"");
327 @.Usage:@>
328 else fatal(
329 "! Usage: cweave [options] webfile[_w] [{changefile[_ch]|-} [outfile[_tex]]]\n"
330    ,"");