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).
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
18 \centerline{(Version 3.64)}
20 \def\botofcontents{\vfill
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
30 \centerline{(Version 3.64)}
32 \def\botofcontents{\vfill
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.
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? */
109 if ((**(++argv)=='-'||**argv=='+')&&*(*argv+1)) @<Handle flag argument@>@;
111 s=name_pos=*argv;@+dot_pos=NULL;
113 if (*s=='.') dot_pos=s++;
114 else if (*s=='/') dot_pos=NULL,name_pos=++s;
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@>;
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@>;
140 sprintf(web_file_name,"%s.w",*argv);
142 strcpy(web_file_name,*argv);
143 *dot_pos=0; /* string now ends where the dot was */
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);
153 @ @<Make |change_file_name|...@>=
155 if (strcmp(*argv,"-")==0) found_change=-1;
157 if (s-*argv > max_file_name_length-4)
158 @<Complain about argument length@>;
160 sprintf(change_file_name,"%s.ch",*argv);
161 else strcpy(change_file_name,*argv);
168 if (s-*argv > max_file_name_length-5)
169 @<Complain about argument length@>;
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);
176 strcpy(tex_file_name,*argv);
177 strcpy(C_file_name,*argv);
178 if (flags['x']) { /* indexes will be generated */
180 sprintf(idx_file_name,"%s.idx",*argv);
181 sprintf(scn_file_name,"%s.scn",*argv);
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.
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? */
223 if ((**(++argv)=='-'||**argv=='+')&&*(*argv+1)) @<Handle flag argument@>@;
225 s=name_pos=*argv;@+dot_pos=NULL;
227 if (*s=='_') dot_pos=s++;
228 else if (*s=='_') dot_pos=NULL,name_pos=++s;
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@>;
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@>;
259 sprintf(web_file_name,"%s_w",*argv);
261 strcpy(web_file_name,*argv);
262 *dot_pos=0; /* string now ends where the dot was */
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);
272 @ @<Make |change_file_name|...@>=
274 if (strcmp(*argv,"-")==0) found_change=-1;
276 if (s-*argv > max_file_name_length-4)
277 @<Complain about argument length@>;
279 sprintf(change_file_name,"%s_ch",*argv);
280 else strcpy(change_file_name,*argv);
287 if (s-*argv > max_file_name_length-5)
288 @<Complain about argument length@>;
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);
295 strcpy(tex_file_name,*argv);
296 strcpy(C_file_name,*argv);
297 if (flags['x']) { /* indexes will be generated */
299 sprintf(idx_file_name,"%s_idx",*argv);
300 sprintf(scn_file_name,"%s_scn",*argv);
309 @ @<Print usage error message and quit@>=
311 if (program==ctangle)
313 "! Usage: ctangle [options] webfile[.w] [{changefile[.ch]|-} [outfile[.c]]]\n"
317 "! Usage: cweave [options] webfile[.w] [{changefile[.ch]|-} [outfile[.tex]]]\n"
321 @ @<Print usage error message and quit@>=
323 if (program==ctangle)
325 "! Usage: ctangle [options] webfile[_w] [{changefile[_ch]|-} [outfile[_c]]]\n"
329 "! Usage: cweave [options] webfile[_w] [{changefile[_ch]|-} [outfile[_tex]]]\n"