Debian Codegraph @

texk/web2c/cwebboot.cin

raw
1 /*1:*/
2 #line 62 "cwebdir/common.w"
3
4 /*4:*/
5 #line 53 "cwebdir/comm-w2c.h"
6
7 #include <ctype.h>
8 #include <stdbool.h>
9 #include <stddef.h>
10 #include <stdint.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14
15 #ifndef HAVE_GETTEXT
16 #define HAVE_GETTEXT 0
17 #endif
18 #line 65 "cwebdir/comm-w2c.h"
19
20 #if HAVE_GETTEXT
21 #include <libintl.h>
22 #else
23 #line 69 "cwebdir/comm-w2c.h"
24 #define gettext(a) a
25 #endif
26 #line 71 "cwebdir/comm-w2c.h"
27
28 /*:4*//*91:*/
29 #line 699 "cwebdir/comm-w2c.ch"
30
31 #if HAVE_GETTEXT
32 #include <locale.h>
33 #else
34 #line 703 "cwebdir/comm-w2c.ch"
35 #define setlocale(a,b) ""
36 #define bindtextdomain(a,b) ""
37 #define textdomain(a) ""
38 #endif
39 #line 707 "cwebdir/comm-w2c.ch"
40
41 /*:91*//*93:*/
42 #line 746 "cwebdir/comm-w2c.ch"
43
44 #include <kpathsea/kpathsea.h>
45
46 #include <w2c/config.h>
47 #include <lib/lib.h>
48
49 /*:93*//*96:*/
50 #line 783 "cwebdir/comm-w2c.ch"
51
52 #define CWEB
53 #include "help.h"
54
55 /*:96*/
56 #line 63 "cwebdir/common.w"
57
58 #define _(s) gettext(s)
59 #define and_and 04
60 #define lt_lt 020
61 #define gt_gt 021
62 #define plus_plus 013
63 #define minus_minus 01
64 #define minus_gt 031
65 #define non_eq 032
66 #define lt_eq 034
67 #define gt_eq 035
68 #define eq_eq 036
69 #define or_or 037
70 #define dot_dot_dot 016
71 #define colon_colon 06
72 #define period_ast 026
73 #define minus_gt_ast 027
74 #define compress(c) if(loc++<=limit)return c
75 #define xisalpha(c) (isalpha((int)(c))&&!ishigh(c))
76 #define xisdigit(c) (isdigit((int)(c))&&!ishigh(c))
77 #define xisspace(c) (isspace((int)(c))&&!ishigh(c))
78 #define xislower(c) (islower((int)(c))&&!ishigh(c))
79 #define xisupper(c) (isupper((int)(c))&&!ishigh(c))
80 #define xisxdigit(c) (isxdigit((int)(c))&&!ishigh(c))
81 #define isxalpha(c) ((c)=='_'||(c)=='$')
82 #define ishigh(c) ((eight_bits)(c)> 0177)
83 #define max_include_depth 10
84 #define max_file_name_length 1024
85 #define cur_file file[include_depth]
86 #define cur_file_name file_name[include_depth]
87 #define cur_line line[include_depth]
88 #define web_file file[0]
89 #define web_file_name file_name[0]
90 #define length(c) (size_t)((c+1)->byte_start-(c)->byte_start)
91 #define print_id(c) term_write((c)->byte_start,length(c))
92 #define llink link
93 #define rlink dummy.Rlink
94 #define root name_dir->rlink
95 #define ilk dummy.Ilk
96 #define spotless 0
97 #define harmless_message 1
98 #define error_message 2
99 #define fatal_message 3
100 #define mark_harmless() if(history==spotless)history= harmless_message
101 #define mark_error() history= error_message
102 #define confusion(s) fatal(_("! This can't happen: "),s)
103 #define show_banner flags['b']
104 #define show_progress flags['p']
105 #define show_happiness flags['h']
106 #define show_stats flags['s']
107 #define make_xrefs flags['x']
108 #define check_for_change flags['c']
109 #define update_terminal() fflush(stdout)
110 #define new_line() putchar('\n')
111 #define term_write(a,b) fflush(stdout),fwrite(a,sizeof(char),b,stdout)
112 #define buf_size 1000
113 #define longest_name 10000
114 #define long_buf_size (buf_size+longest_name)
115 #define max_bytes 1000000
116 #define max_names 10239
117 #define max_sections 4000
118 #define lines_dont_match (change_limit-change_buffer!=limit-buffer|| \
119 strncmp(buffer,change_buffer,(size_t) (limit-buffer))!=0)
120 #define if_section_start_make_pending(b) \
121 *limit= '!'; \
122 for(loc= buffer;xisspace(*loc);loc++); \
123 *limit= ' '; \
124 if(*loc=='@'&&(xisspace(*(loc+1))||*(loc+1)=='*'))change_pending= b
125 #define too_long() {include_depth--; \
126 err_print(_("! Include file name too long"));goto restart;}
127 #define hash_size 8501
128 #define first_chunk(p) ((p)->byte_start+2)
129 #define prefix_length(p) (size_t)((eight_bits)*((p)->byte_start)*256+ \
130 (eight_bits)*((p)->byte_start+1))
131 #define set_prefix_length(p,m) (*((p)->byte_start)= (char)((m)/256), \
132 *((p)->byte_start+1)= (char)((m)%256))
133 #define less 0
134 #define equal 1
135 #define greater 2
136 #define prefix 3
137 #define extension 4
138 #define bad_extension 5
139 #define flag_change (**argv!='-')
140 #define max_banner 50
141 #define PATH_SEPARATOR separators[0]
142 #define DIR_SEPARATOR separators[1]
143 #define DEVICE_SEPARATOR separators[2]
144 #define kpse_find_cweb(name) kpse_find_file(name,kpse_cweb_format,true)
145
146 #line 64 "cwebdir/common.w"
147
148 /*2:*/
149 #line 32 "cwebdir/comm-w2c.h"
150
151 typedef uint8_t eight_bits;
152 typedef uint16_t sixteen_bits;
153 typedef enum{
154 ctangle,cweave,ctwill
155 }cweb;
156 extern cweb program;
157 extern int phase;
158
159 /*:2*//*5:*/
160 #line 108 "cwebdir/comm-w2c.h"
161
162 extern char section_text[];
163 extern char*section_text_end;
164 extern char*id_first;
165 extern char*id_loc;
166
167 /*:5*//*6:*/
168 #line 126 "cwebdir/comm-w2c.h"
169
170 extern char buffer[];
171 extern char*buffer_end;
172 extern char*loc;
173 extern char*limit;
174
175 /*:6*//*7:*/
176 #line 143 "cwebdir/comm-w2c.h"
177
178 extern int include_depth;
179 extern FILE*file[];
180 extern FILE*change_file;
181 extern char file_name[][max_file_name_length];
182
183 extern char change_file_name[];
184 extern char*found_filename;
185 extern int line[];
186 extern int change_line;
187 extern int change_depth;
188 extern bool input_has_ended;
189 extern bool changing;
190 extern bool web_file_open;
191
192 /*:7*//*9:*/
193 #line 164 "cwebdir/comm-w2c.h"
194
195 extern sixteen_bits section_count;
196 extern bool changed_section[];
197 extern bool change_pending;
198 extern bool print_where;
199
200 /*:9*//*10:*/
201 #line 179 "cwebdir/comm-w2c.h"
202
203 typedef struct name_info{
204 char*byte_start;
205 struct name_info*link;
206 union{
207 struct name_info*Rlink;
208
209 eight_bits Ilk;
210 }dummy;
211 void*equiv_or_xref;
212 }name_info;
213 typedef name_info*name_pointer;
214 typedef name_pointer*hash_pointer;
215 extern char byte_mem[];
216 extern char*byte_mem_end;
217 extern char*byte_ptr;
218 extern name_info name_dir[];
219 extern name_pointer name_dir_end;
220 extern name_pointer name_ptr;
221 extern name_pointer hash[];
222 extern hash_pointer hash_end;
223 extern hash_pointer hash_ptr;
224
225 /*:10*//*12:*/
226 #line 224 "cwebdir/comm-w2c.h"
227
228 extern int history;
229
230 /*:12*//*14:*/
231 #line 245 "cwebdir/comm-w2c.h"
232
233 extern int argc;
234 extern char**argv;
235 extern char C_file_name[];
236 extern char tex_file_name[];
237 extern char idx_file_name[];
238 extern char scn_file_name[];
239 extern char check_file_name[];
240 extern bool flags[];
241 extern const char*use_language;
242
243 /*:14*//*15:*/
244 #line 261 "cwebdir/comm-w2c.h"
245
246 extern FILE*C_file;
247 extern FILE*tex_file;
248 extern FILE*idx_file;
249 extern FILE*scn_file;
250 extern FILE*active_file;
251 extern FILE*check_file;
252
253 /*:15*/
254 #line 65 "cwebdir/common.w"
255
256 /*18:*/
257 #line 79 "cwebdir/common.w"
258
259 #line 72 "cwebdir/comm-w2c.ch"
260 cweb program;
261 #line 81 "cwebdir/common.w"
262
263 /*:18*//*19:*/
264 #line 88 "cwebdir/common.w"
265
266 int phase;
267
268 /*:19*//*21:*/
269 #line 126 "cwebdir/common.w"
270
271 char section_text[longest_name+1];
272 char*section_text_end= section_text+longest_name;
273 char*id_first;
274 char*id_loc;
275
276 /*:21*//*22:*/
277 #line 146 "cwebdir/common.w"
278
279 char buffer[long_buf_size];
280 char*buffer_end= buffer+buf_size-2;
281 char*loc= buffer;
282 char*limit= buffer;
283
284 /*:22*//*25:*/
285 #line 190 "cwebdir/common.w"
286
287 int include_depth;
288 FILE*file[max_include_depth];
289 FILE*change_file;
290 char file_name[max_include_depth][max_file_name_length];
291
292 char change_file_name[max_file_name_length];
293 #line 104 "cwebdir/comm-w2c.ch"
294 char*found_filename;
295 #line 198 "cwebdir/common.w"
296 int line[max_include_depth];
297 int change_line;
298 int change_depth;
299 bool input_has_ended;
300 bool changing;
301 bool web_file_open= false;
302
303 /*:25*//*26:*/
304 #line 216 "cwebdir/common.w"
305
306 static char change_buffer[buf_size];
307 static char*change_limit;
308
309 /*:26*//*42:*/
310 #line 545 "cwebdir/common.w"
311
312 sixteen_bits section_count;
313 bool changed_section[max_sections];
314 bool change_pending;
315
316 bool print_where= false;
317
318 /*:42*//*43:*/
319 #line 590 "cwebdir/common.w"
320
321 char byte_mem[max_bytes];
322 char*byte_mem_end= byte_mem+max_bytes-1;
323 name_info name_dir[max_names];
324 name_pointer name_dir_end= name_dir+max_names-1;
325
326 /*:43*//*44:*/
327 #line 601 "cwebdir/common.w"
328
329 char*byte_ptr;
330 name_pointer name_ptr;
331
332 /*:44*//*46:*/
333 #line 621 "cwebdir/common.w"
334
335 name_pointer hash[hash_size]= {NULL};
336 hash_pointer hash_end= hash+hash_size-1;
337 hash_pointer hash_ptr;
338
339 /*:46*//*65:*/
340 #line 999 "cwebdir/common.w"
341
342 int history= spotless;
343
344 /*:65*//*73:*/
345 #line 1124 "cwebdir/common.w"
346
347 int argc;
348 char**argv;
349 char C_file_name[max_file_name_length];
350 char tex_file_name[max_file_name_length];
351 char idx_file_name[max_file_name_length];
352 #line 422 "cwebdir/comm-w2c.ch"
353 char scn_file_name[max_file_name_length];
354 char check_file_name[max_file_name_length];
355 #line 1131 "cwebdir/common.w"
356 bool flags[128];
357
358 /*:73*//*83:*/
359 #line 1267 "cwebdir/common.w"
360
361 FILE*C_file;
362 FILE*tex_file;
363 FILE*idx_file;
364 FILE*scn_file;
365 #line 544 "cwebdir/comm-w2c.ch"
366 FILE*active_file;
367 FILE*check_file;
368 #line 1273 "cwebdir/common.w"
369
370 #line 561 "cwebdir/comm-w2c.ch"
371 /*:83*//*86:*/
372 #line 589 "cwebdir/comm-w2c.ch"
373
374 const char*use_language= "";
375
376
377 /*:86*//*87:*/
378 #line 602 "cwebdir/comm-w2c.ch"
379
380 char cb_banner[max_banner];
381 string texmf_locale;
382 #ifndef SEPARATORS
383 #define SEPARATORS "://"
384 #endif
385 #line 608 "cwebdir/comm-w2c.ch"
386 char separators[]= SEPARATORS;
387
388 /*:87*/
389 #line 66 "cwebdir/common.w"
390
391 /*3:*/
392 #line 42 "cwebdir/comm-w2c.h"
393
394 extern void common_init(void);
395
396 /*:3*//*8:*/
397 #line 158 "cwebdir/comm-w2c.h"
398
399 extern bool get_line(void);
400 extern void check_complete(void);
401 extern void reset_input(void);
402
403 /*:8*//*11:*/
404 #line 202 "cwebdir/comm-w2c.h"
405
406 extern name_pointer id_lookup(const char*,const char*,eight_bits);
407
408 extern name_pointer section_lookup(char*,char*,bool);
409 extern void print_prefix_name(name_pointer);
410 extern void print_section_name(name_pointer);
411 extern void sprint_section_name(char*,name_pointer);
412
413 extern bool names_match(name_pointer,const char*,size_t,eight_bits);
414
415 extern void init_node(name_pointer);
416
417 /*:11*//*13:*/
418 #line 227 "cwebdir/comm-w2c.h"
419
420 extern int wrap_up(void);
421 extern void err_print(const char*);
422 extern void fatal(const char*,const char*);
423 extern void overflow(const char*);
424
425 extern void cb_show_banner(void);
426
427 extern void print_stats(void);
428
429 /*:13*//*24:*/
430 #line 176 "cwebdir/common.w"
431 static bool input_ln(FILE*);
432
433 /*:24*//*28:*/
434 #line 237 "cwebdir/common.w"
435 static void prime_the_change_buffer(void);
436
437 /*:28*//*33:*/
438 #line 334 "cwebdir/common.w"
439 static void check_change(void);
440
441 /*:33*//*55:*/
442 #line 760 "cwebdir/common.w"
443
444 static int web_strcmp(char*,size_t,char*,size_t);
445 static name_pointer add_section_name(name_pointer,int,char*,char*,bool);
446 static void extend_section_name(name_pointer,char*,char*,bool);
447
448 /*:55*//*64:*/
449 #line 987 "cwebdir/common.w"
450 static int section_name_cmp(char**,size_t,name_pointer);
451
452 /*:64*//*76:*/
453 #line 1184 "cwebdir/common.w"
454 static void scan_args(void);
455
456 #line 474 "cwebdir/comm-w2c.ch"
457 /*:76*//*98:*/
458 #line 796 "cwebdir/comm-w2c.ch"
459
460 static void cb_usage(const_string str);
461 static void cb_usagehelp(const_string*message);
462
463 /*:98*/
464 #line 67 "cwebdir/common.w"
465
466
467 /*:1*//*20:*/
468 #line 95 "cwebdir/common.w"
469
470 void
471 common_init(void)
472 {
473 #line 78 "cwebdir/comm-w2c.ch"
474 /*45:*/
475 #line 605 "cwebdir/common.w"
476
477 name_dir->byte_start= byte_ptr= byte_mem;
478 name_ptr= name_dir+1;
479 name_ptr->byte_start= byte_mem;
480 root= NULL;
481
482 /*:45*/
483 #line 78 "cwebdir/comm-w2c.ch"
484
485 /*94:*/
486 #line 758 "cwebdir/comm-w2c.ch"
487
488 kpse_set_program_name(argv[0],"cweb");
489
490 /*:94*/
491 #line 79 "cwebdir/comm-w2c.ch"
492
493 #line 85 "cwebdir/comm-w2c.ch"
494 /*92:*/
495 #line 708 "cwebdir/comm-w2c.ch"
496
497 setlocale(LC_MESSAGES,setlocale(LC_CTYPE,""));
498 texmf_locale= kpse_var_expand("${TEXMFLOCALEDIR}");
499
500 bindtextdomain("cweb",
501 bindtextdomain("cweb-tl",
502 bindtextdomain("web2c-help",
503 strcmp(texmf_locale,"")?
504 texmf_locale:"/usr/share/locale")));
505
506 free(texmf_locale);
507 textdomain("cweb");
508
509
510 /*:92*/
511 #line 85 "cwebdir/comm-w2c.ch"
512
513 /*74:*/
514 #line 1137 "cwebdir/common.w"
515
516 show_banner= show_happiness= show_progress= make_xrefs= true;
517
518 /*:74*/
519 #line 86 "cwebdir/comm-w2c.ch"
520
521 #line 101 "cwebdir/common.w"
522 /*84:*/
523 #line 561 "cwebdir/comm-w2c.ch"
524
525 scan_args();
526 if(program==ctangle){
527 if(check_for_change)/*88:*/
528 #line 619 "cwebdir/comm-w2c.ch"
529 {
530 if((C_file= fopen(C_file_name,"a"))==NULL)
531 fatal(_("! Cannot open output file "),C_file_name);
532
533 else fclose(C_file);
534 strcpy(check_file_name,C_file_name);
535 if(check_file_name[0]!='\0'){
536 char*dot_pos= strrchr(check_file_name,'.');
537 if(dot_pos==NULL)strcat(check_file_name,".ttp");
538 else strcpy(dot_pos,".ttp");
539 }
540 if((C_file= fopen(check_file_name,"wb"))==NULL)
541 fatal(_("! Cannot open output file "),check_file_name);
542 }
543
544 /*:88*/
545 #line 564 "cwebdir/comm-w2c.ch"
546
547 else if((C_file= fopen(C_file_name,"wb"))==NULL)
548 fatal(_("! Cannot open output file "),C_file_name);
549
550 }
551 else{
552 if(check_for_change)/*89:*/
553 #line 634 "cwebdir/comm-w2c.ch"
554 {
555 if((tex_file= fopen(tex_file_name,"a"))==NULL)
556 fatal(_("! Cannot open output file "),tex_file_name);
557
558 else fclose(tex_file);
559 strcpy(check_file_name,tex_file_name);
560 if(check_file_name[0]!='\0'){
561 char*dot_pos= strrchr(check_file_name,'.');
562 if(dot_pos==NULL)strcat(check_file_name,".wtp");
563 else strcpy(dot_pos,".wtp");
564 }
565 if((tex_file= fopen(check_file_name,"wb"))==NULL)
566 fatal(_("! Cannot open output file "),check_file_name);
567 }
568
569 /*:89*/
570 #line 570 "cwebdir/comm-w2c.ch"
571
572 else if((tex_file= fopen(tex_file_name,"wb"))==NULL)
573 fatal(_("! Cannot open output file "),tex_file_name);
574 }
575 #line 1285 "cwebdir/common.w"
576
577 #line 579 "cwebdir/comm-w2c.ch"
578 /*:84*/
579 #line 101 "cwebdir/common.w"
580
581 }
582
583 /*:20*//*23:*/
584 #line 156 "cwebdir/common.w"
585
586 static bool input_ln(
587 FILE*fp)
588 {
589 int c= EOF;
590 char*k;
591 if(feof(fp))return false;
592 limit= k= buffer;
593 while(k<=buffer_end&&(c= getc(fp))!=EOF&&c!='\n')
594 #line 92 "cwebdir/comm-w2c.ch"
595 if((*(k++)= c)!=' '&&c!='\r')limit= k;
596 #line 166 "cwebdir/common.w"
597 if(k> buffer_end){
598 while((c= getc(fp))!=EOF&&c!='\n');
599 #line 98 "cwebdir/comm-w2c.ch"
600 loc= buffer;err_print(_("! Input line too long"));
601 #line 169 "cwebdir/common.w"
602
603 }
604 if(c==EOF&&limit==buffer)return false;
605
606 return true;
607 }
608
609 /*:23*//*27:*/
610 #line 227 "cwebdir/common.w"
611
612 static void
613 prime_the_change_buffer(void)
614 {
615 change_limit= change_buffer;
616 /*29:*/
617 #line 243 "cwebdir/common.w"
618
619 while(true){
620 change_line++;
621 if(!input_ln(change_file))return;
622 if(limit<buffer+2)continue;
623 if(buffer[0]!='@')continue;
624 if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
625 if(buffer[1]=='x')break;
626 if(buffer[1]=='y'||buffer[1]=='z'||buffer[1]=='i'){
627 loc= buffer+2;
628 #line 110 "cwebdir/comm-w2c.ch"
629 err_print(_("! Missing @x in change file"));
630 #line 254 "cwebdir/common.w"
631
632 }
633 }
634
635 /*:29*/
636 #line 232 "cwebdir/common.w"
637
638 /*30:*/
639 #line 260 "cwebdir/common.w"
640
641 do{
642 change_line++;
643 if(!input_ln(change_file)){
644 #line 116 "cwebdir/comm-w2c.ch"
645 err_print(_("! Change file ended after @x"));
646 #line 265 "cwebdir/common.w"
647
648 return;
649 }
650 }while(limit==buffer);
651
652 /*:30*/
653 #line 233 "cwebdir/common.w"
654
655 /*31:*/
656 #line 270 "cwebdir/common.w"
657
658 change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
659 strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
660
661 /*:31*/
662 #line 234 "cwebdir/common.w"
663
664 }
665
666 /*:27*//*32:*/
667 #line 296 "cwebdir/common.w"
668
669 static void
670 check_change(void)
671 {
672 int n= 0;
673 if(lines_dont_match)return;
674 change_pending= false;
675 if(!changed_section[section_count]){
676 if_section_start_make_pending(true);
677 if(!change_pending)changed_section[section_count]= true;
678 }
679 while(true){
680 changing= print_where= true;change_line++;
681 if(!input_ln(change_file)){
682 #line 122 "cwebdir/comm-w2c.ch"
683 err_print(_("! Change file ended before @y"));
684 #line 311 "cwebdir/common.w"
685
686 change_limit= change_buffer;changing= false;
687 return;
688 }
689 if(limit> buffer+1&&buffer[0]=='@'){
690 if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
691 /*34:*/
692 #line 336 "cwebdir/common.w"
693
694 if(buffer[1]=='x'||buffer[1]=='z'){
695 #line 134 "cwebdir/comm-w2c.ch"
696 loc= buffer+2;err_print(_("! Where is the matching @y?"));
697 #line 339 "cwebdir/common.w"
698
699 }
700 else if(buffer[1]=='y'){
701 if(n> 0){
702 loc= buffer+2;
703 printf("\n! Hmm... %d ",n);
704 #line 140 "cwebdir/comm-w2c.ch"
705 err_print(_("of the preceding lines failed to match"));
706 #line 346 "cwebdir/common.w"
707
708 }
709 change_depth= include_depth;
710 return;
711 }
712
713 /*:34*/
714 #line 318 "cwebdir/common.w"
715
716 }
717 /*31:*/
718 #line 270 "cwebdir/common.w"
719
720 change_limit= change_buffer+(ptrdiff_t)(limit-buffer);
721 strncpy(change_buffer,buffer,(size_t)(limit-buffer+1));
722
723 /*:31*/
724 #line 320 "cwebdir/common.w"
725
726 changing= false;cur_line++;
727 while(!input_ln(cur_file)){
728 if(include_depth==0){
729 #line 128 "cwebdir/comm-w2c.ch"
730 err_print(_("! CWEB file ended during a change"));
731 #line 325 "cwebdir/common.w"
732
733 input_has_ended= true;return;
734 }
735 include_depth--;cur_line++;
736 }
737 if(lines_dont_match)n++;
738 }
739 }
740
741 /*:32*//*35:*/
742 #line 362 "cwebdir/common.w"
743
744 bool get_line(void)
745 {
746 restart:
747 if(changing&&include_depth==change_depth)
748 /*38:*/
749 #line 470 "cwebdir/common.w"
750 {
751 change_line++;
752 if(!input_ln(change_file)){
753 #line 240 "cwebdir/comm-w2c.ch"
754 err_print(_("! Change file ended without @z"));
755 #line 474 "cwebdir/common.w"
756
757 buffer[0]= '@';buffer[1]= 'z';limit= buffer+2;
758 }
759 if(limit> buffer){
760 if(change_pending){
761 if_section_start_make_pending(false);
762 if(change_pending){
763 changed_section[section_count]= true;change_pending= false;
764 }
765 }
766 *limit= ' ';
767 if(buffer[0]=='@'){
768 if(xisupper(buffer[1]))buffer[1]= tolower((int)buffer[1]);
769 if(buffer[1]=='x'||buffer[1]=='y'){
770 loc= buffer+2;
771 #line 246 "cwebdir/comm-w2c.ch"
772 err_print(_("! Where is the matching @z?"));
773 #line 490 "cwebdir/common.w"
774
775 }
776 else if(buffer[1]=='z'){
777 prime_the_change_buffer();changing= !changing;print_where= true;
778 }
779 }
780 }
781 }
782
783 /*:38*/
784 #line 367 "cwebdir/common.w"
785
786 if(!changing||include_depth> change_depth){
787 /*37:*/
788 #line 453 "cwebdir/common.w"
789 {
790 cur_line++;
791 while(!input_ln(cur_file)){
792 print_where= true;
793 if(include_depth==0){input_has_ended= true;break;}
794 else{
795 fclose(cur_file);include_depth--;
796 if(changing&&include_depth==change_depth)break;
797 cur_line++;
798 }
799 }
800 if(!changing&&!input_has_ended)
801 if(limit-buffer==change_limit-change_buffer)
802 if(buffer[0]==change_buffer[0])
803 if(change_limit> change_buffer)check_change();
804 }
805
806 /*:37*/
807 #line 369 "cwebdir/common.w"
808
809 if(changing&&include_depth==change_depth)goto restart;
810 }
811 if(input_has_ended)return false;
812 loc= buffer;*limit= ' ';
813 if(buffer[0]=='@'&&(buffer[1]=='i'||buffer[1]=='I')){
814 loc= buffer+2;*limit= '"';
815 while(*loc==' '||*loc=='\t')loc++;
816 if(loc>=limit){
817 #line 146 "cwebdir/comm-w2c.ch"
818 err_print(_("! Include file name not given"));
819 #line 379 "cwebdir/common.w"
820
821 goto restart;
822 }
823 if(include_depth>=max_include_depth-1){
824 #line 152 "cwebdir/comm-w2c.ch"
825 err_print(_("! Too many nested includes"));
826 #line 384 "cwebdir/common.w"
827
828 goto restart;
829 }
830 include_depth++;
831 /*36:*/
832 #line 407 "cwebdir/common.w"
833 {
834 #line 189 "cwebdir/comm-w2c.ch"
835 char*cur_file_name_end= cur_file_name+max_file_name_length-1;
836 char*k= cur_file_name;
837 #line 412 "cwebdir/common.w"
838
839 if(*loc=='"'){
840 loc++;
841 while(*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
842 if(loc==limit)k= cur_file_name_end+1;
843 }else
844 while(*loc!=' '&&*loc!='\t'&&*loc!='"'&&k<=cur_file_name_end)*k++= *loc++;
845 if(k> cur_file_name_end)too_long();
846
847 *k= '\0';
848 #line 196 "cwebdir/comm-w2c.ch"
849 if((found_filename= kpse_find_cweb(cur_file_name))!=NULL
850 &&(cur_file= fopen(found_filename,"r"))!=NULL){
851
852 if(strlen(found_filename)<max_file_name_length){
853 if(strcmp(cur_file_name,found_filename))
854 strcpy(cur_file_name,found_filename+
855 ((strncmp(found_filename,"./",2)==0)?2:0));
856 free(found_filename);
857 }else fatal(_("! Filename too long\n"),found_filename);
858 #line 423 "cwebdir/common.w"
859 cur_line= 0;print_where= true;
860 goto restart;
861 }
862 #line 234 "cwebdir/comm-w2c.ch"
863 include_depth--;err_print(_("! Cannot open include file"));goto restart;
864 #line 451 "cwebdir/common.w"
865 }
866
867 /*:36*/
868 #line 388 "cwebdir/common.w"
869
870 }
871 return true;
872 }
873
874 #line 167 "cwebdir/comm-w2c.ch"
875 /*:35*//*39:*/
876 #line 502 "cwebdir/common.w"
877
878 void
879 check_complete(void){
880 if(change_limit!=change_buffer){
881 strncpy(buffer,change_buffer,(size_t)(change_limit-change_buffer+1));
882 limit= buffer+(ptrdiff_t)(change_limit-change_buffer);
883 changing= true;change_depth= include_depth;loc= buffer;
884 #line 252 "cwebdir/comm-w2c.ch"
885 err_print(_("! Change file entry did not match"));
886 #line 510 "cwebdir/common.w"
887
888 }
889 }
890
891 /*:39*//*40:*/
892 #line 518 "cwebdir/common.w"
893
894 void
895 reset_input(void)
896 {
897 limit= buffer;loc= buffer+1;buffer[0]= ' ';
898 /*41:*/
899 #line 533 "cwebdir/common.w"
900
901 #line 262 "cwebdir/comm-w2c.ch"
902 if((found_filename= kpse_find_cweb(web_file_name))==NULL
903 ||(web_file= fopen(found_filename,"r"))==NULL)
904 fatal(_("! Cannot open input file "),web_file_name);
905 else if(strlen(found_filename)<max_file_name_length){
906
907 if(strcmp(web_file_name,found_filename))
908 strcpy(web_file_name,found_filename+
909 ((strncmp(found_filename,"./",2)==0)?2:0));
910 free(found_filename);
911 }else fatal(_("! Filename too long\n"),found_filename);
912 #line 539 "cwebdir/common.w"
913
914
915 web_file_open= true;
916 #line 278 "cwebdir/comm-w2c.ch"
917 if((found_filename= kpse_find_cweb(change_file_name))==NULL
918 ||(change_file= fopen(found_filename,"r"))==NULL)
919 fatal(_("! Cannot open change file "),change_file_name);
920 else if(strlen(found_filename)<max_file_name_length){
921
922 if(strcmp(change_file_name,found_filename))
923 strcpy(change_file_name,found_filename+
924 ((strncmp(found_filename,"./",2)==0)?2:0));
925 free(found_filename);
926 }else fatal(_("! Filename too long\n"),found_filename);
927 #line 544 "cwebdir/common.w"
928
929 /*:41*/
930 #line 523 "cwebdir/common.w"
931
932 include_depth= cur_line= change_line= 0;
933 change_depth= include_depth;
934 changing= true;prime_the_change_buffer();changing= !changing;
935 limit= buffer;loc= buffer+1;buffer[0]= ' ';input_has_ended= false;
936 }
937
938 /*:40*//*48:*/
939 #line 630 "cwebdir/common.w"
940
941 name_pointer
942 id_lookup(
943 const char*first,
944 const char*last,
945 eight_bits t)
946 {
947 const char*i= first;
948 int h;
949 size_t l;
950 name_pointer p;
951 if(last==NULL)for(last= first;*last!='\0';last++);
952 l= (size_t)(last-first);
953 /*49:*/
954 #line 653 "cwebdir/common.w"
955
956 h= (int)((eight_bits)*i);
957 while(++i<last)h= (h+h+(int)((eight_bits)*i))%hash_size;
958
959
960 /*:49*/
961 #line 643 "cwebdir/common.w"
962
963 /*50:*/
964 #line 661 "cwebdir/common.w"
965
966 p= hash[h];
967 while(p&&!names_match(p,first,l,t))p= p->link;
968 if(p==NULL){
969 p= name_ptr;
970 p->link= hash[h];hash[h]= p;
971 }
972
973 /*:50*/
974 #line 644 "cwebdir/common.w"
975
976 if(p==name_ptr)/*51:*/
977 #line 672 "cwebdir/common.w"
978 {
979 #line 300 "cwebdir/comm-w2c.ch"
980 if(byte_ptr+l> byte_mem_end)overflow(_("byte memory"));
981 if(name_ptr>=name_dir_end)overflow(_("name"));
982 #line 675 "cwebdir/common.w"
983 strncpy(byte_ptr,first,l);
984 (++name_ptr)->byte_start= byte_ptr+= l;
985 #line 307 "cwebdir/comm-w2c.ch"
986 if(program!=ctangle)p->ilk= t,init_node(p);
987 #line 678 "cwebdir/common.w"
988 }
989
990 /*:51*/
991 #line 645 "cwebdir/common.w"
992
993 return p;
994 }
995
996 /*:48*//*52:*/
997 #line 704 "cwebdir/common.w"
998
999 void
1000 print_section_name(
1001 name_pointer p)
1002 {
1003 char*ss,*s= first_chunk(p);
1004 name_pointer q= p+1;
1005 while(p!=name_dir){
1006 ss= (p+1)->byte_start-1;
1007 if(*ss==' '&&ss>=s)p= q->link,q= p;
1008 else ss++,p= name_dir,q= NULL;
1009 term_write(s,(size_t)(ss-s));
1010 s= p->byte_start;
1011 }
1012 if(q)term_write("...",3);
1013 }
1014
1015 /*:52*//*53:*/
1016 #line 721 "cwebdir/common.w"
1017
1018 void
1019 sprint_section_name(
1020 char*dest,
1021 name_pointer p)
1022 {
1023 char*ss,*s= first_chunk(p);
1024 name_pointer q= p+1;
1025 while(p!=name_dir){
1026 ss= (p+1)->byte_start-1;
1027 if(*ss==' '&&ss>=s)p= q->link,q= p;
1028 else ss++,p= name_dir;
1029 strncpy(dest,s,(size_t)(ss-s)),dest+= ss-s;
1030 s= p->byte_start;
1031 }
1032 *dest= '\0';
1033 }
1034
1035 /*:53*//*54:*/
1036 #line 739 "cwebdir/common.w"
1037
1038 void
1039 print_prefix_name(
1040 name_pointer p)
1041 {
1042 char*s= first_chunk(p);
1043 size_t l= prefix_length(p);
1044 term_write(s,l);
1045 if(s+l<(p+1)->byte_start)term_write("...",3);
1046 }
1047
1048 /*:54*//*56:*/
1049 #line 765 "cwebdir/common.w"
1050
1051 static int web_strcmp(
1052 char*j,
1053 size_t j_len,
1054 char*k,
1055 size_t k_len)
1056 {
1057 char*j1= j+j_len,*k1= k+k_len;
1058 while(k<k1&&j<j1&&*j==*k)k++,j++;
1059 if(k==k1)if(j==j1)return equal;
1060 else return extension;
1061 else if(j==j1)return prefix;
1062 else if(*j<*k)return less;
1063 else return greater;
1064 }
1065
1066 /*:56*//*57:*/
1067 #line 794 "cwebdir/common.w"
1068
1069 static name_pointer
1070 add_section_name(
1071 name_pointer par,
1072 int c,
1073 char*first,
1074 char*last,
1075 bool ispref)
1076 {
1077 name_pointer p= name_ptr;
1078 char*s= first_chunk(p);
1079 size_t name_len= (size_t)(last-first+(int)ispref);
1080 #line 314 "cwebdir/comm-w2c.ch"
1081 if(s+name_len> byte_mem_end)overflow(_("byte memory"));
1082 if(name_ptr+1>=name_dir_end)overflow(_("name"));
1083 #line 808 "cwebdir/common.w"
1084 (++name_ptr)->byte_start= byte_ptr= s+name_len;
1085 if(ispref){
1086 *(byte_ptr-1)= ' ';
1087 name_len--;
1088 name_ptr->link= name_dir;
1089 (++name_ptr)->byte_start= byte_ptr;
1090 }
1091 set_prefix_length(p,name_len);
1092 strncpy(s,first,name_len);
1093 p->llink= p->rlink= NULL;
1094 init_node(p);
1095 return par==NULL?(root= p):c==less?(par->llink= p):(par->rlink= p);
1096 }
1097
1098 /*:57*//*58:*/
1099 #line 822 "cwebdir/common.w"
1100
1101 static void
1102 extend_section_name(
1103 name_pointer p,
1104 char*first,
1105 char*last,
1106 bool ispref)
1107 {
1108 char*s;
1109 name_pointer q= p+1;
1110 size_t name_len= (size_t)(last-first+(int)ispref);
1111 #line 321 "cwebdir/comm-w2c.ch"
1112 if(name_ptr>=name_dir_end)overflow(_("name"));
1113 #line 834 "cwebdir/common.w"
1114 while(q->link!=name_dir)q= q->link;
1115 q->link= name_ptr;
1116 s= name_ptr->byte_start;
1117 name_ptr->link= name_dir;
1118 #line 327 "cwebdir/comm-w2c.ch"
1119 if(s+name_len> byte_mem_end)overflow(_("byte memory"));
1120 #line 839 "cwebdir/common.w"
1121 (++name_ptr)->byte_start= byte_ptr= s+name_len;
1122 strncpy(s,first,name_len);
1123 if(ispref)*(byte_ptr-1)= ' ';
1124 }
1125
1126 /*:58*//*59:*/
1127 #line 850 "cwebdir/common.w"
1128
1129 name_pointer
1130 section_lookup(
1131 char*first,char*last,
1132 bool ispref)
1133 {
1134 int c= less;
1135 name_pointer p= root;
1136 name_pointer q= NULL;
1137 name_pointer r= NULL;
1138 name_pointer par= NULL;
1139
1140 size_t name_len= (size_t)(last-first+1);
1141 /*60:*/
1142 #line 874 "cwebdir/common.w"
1143
1144 while(p){
1145 c= web_strcmp(first,name_len,first_chunk(p),prefix_length(p));
1146 if(c==less||c==greater){
1147 if(r==NULL)
1148 par= p;
1149 p= (c==less?p->llink:p->rlink);
1150 }else{
1151 if(r!=NULL){
1152 #line 333 "cwebdir/comm-w2c.ch"
1153 printf("%s",_("\n! Ambiguous prefix: matches <"));
1154 #line 884 "cwebdir/common.w"
1155
1156 print_prefix_name(p);
1157 #line 339 "cwebdir/comm-w2c.ch"
1158 printf("%s",_(">\n and <"));
1159 #line 887 "cwebdir/common.w"
1160 print_prefix_name(r);
1161 err_print(">");
1162 return name_dir;
1163 }
1164 r= p;
1165 p= p->llink;
1166 q= r->rlink;
1167 }
1168 if(p==NULL)
1169 p= q,q= NULL;
1170 }
1171
1172 /*:60*/
1173 #line 864 "cwebdir/common.w"
1174
1175 /*61:*/
1176 #line 899 "cwebdir/common.w"
1177
1178 if(r==NULL)
1179 return add_section_name(par,c,first,last+1,ispref);
1180
1181 /*:61*/
1182 #line 865 "cwebdir/common.w"
1183
1184 /*62:*/
1185 #line 907 "cwebdir/common.w"
1186
1187 switch(section_name_cmp(&first,name_len,r)){
1188
1189 case prefix:
1190 if(!ispref){
1191 #line 345 "cwebdir/comm-w2c.ch"
1192 printf("%s",_("\n! New name is a prefix of <"));
1193 #line 913 "cwebdir/common.w"
1194
1195 print_section_name(r);
1196 err_print(">");
1197 }
1198 else if(name_len<prefix_length(r))set_prefix_length(r,name_len);
1199 /* fall through */
1200 case equal:break;
1201 case extension:if(!ispref||first<=last)
1202 extend_section_name(r,first,last+1,ispref);
1203 break;
1204 case bad_extension:
1205 #line 351 "cwebdir/comm-w2c.ch"
1206 printf("%s",_("\n! New name extends <"));
1207 #line 925 "cwebdir/common.w"
1208
1209 print_section_name(r);
1210 err_print(">");
1211 break;
1212 default:
1213 #line 357 "cwebdir/comm-w2c.ch"
1214 printf("%s",_("\n! Section name incompatible with <"));
1215 #line 931 "cwebdir/common.w"
1216
1217 print_prefix_name(r);
1218 #line 363 "cwebdir/comm-w2c.ch"
1219 printf("%s",_(">,\n which abbreviates <"));
1220 #line 934 "cwebdir/common.w"
1221 print_section_name(r);
1222 err_print(">");
1223 }
1224 return r;
1225
1226 /*:62*/
1227 #line 866 "cwebdir/common.w"
1228
1229 }
1230
1231 /*:59*//*63:*/
1232 #line 955 "cwebdir/common.w"
1233
1234 static int section_name_cmp(
1235 char**pfirst,
1236 size_t len,
1237 name_pointer r)
1238 {
1239 char*first= *pfirst;
1240 name_pointer q= r+1;
1241 char*ss,*s= first_chunk(r);
1242 int c= less;
1243 bool ispref;
1244 while(true){
1245 ss= (r+1)->byte_start-1;
1246 if(*ss==' '&&ss>=r->byte_start)ispref= true,q= q->link;
1247 else ispref= false,ss++,q= name_dir;
1248 switch(c= web_strcmp(first,len,s,(size_t)(ss-s))){
1249 case equal:if(q==name_dir)
1250 if(ispref){
1251 *pfirst= first+(ptrdiff_t)(ss-s);
1252 return extension;
1253 }else return equal;
1254 else return length(q)==0?equal:prefix;
1255 case extension:
1256 if(!ispref)return bad_extension;
1257 first+= ss-s;
1258 if(q!=name_dir){len-= (int)(ss-s);s= q->byte_start;r= q;continue;}
1259 *pfirst= first;return extension;
1260 default:return c;
1261 }
1262 }
1263 }
1264
1265 /*:63*//*66:*/
1266 #line 1009 "cwebdir/common.w"
1267
1268 void
1269 err_print(
1270 const char*s)
1271 {
1272 printf(*s=='!'?"\n%s":"%s",s);
1273 if(web_file_open)/*67:*/
1274 #line 1028 "cwebdir/common.w"
1275
1276 {char*k,*l;
1277 if(changing&&include_depth==change_depth&&change_line> 0)
1278 #line 372 "cwebdir/comm-w2c.ch"
1279 printf(_(". (l. %d of change file)\n"),change_line);
1280 else if(cur_line> 0){
1281 if(include_depth==0)printf(_(". (l. %d)\n"),cur_line);
1282 else printf(_(". (l. %d of include file %s)\n"),cur_line,cur_file_name);
1283 #line 1035 "cwebdir/common.w"
1284 }
1285 l= (loc>=limit?limit:loc);
1286 if(l> buffer){
1287 for(k= buffer;k<l;k++)
1288 if(*k=='\t')putchar(' ');
1289 else putchar(*k);
1290 new_line();
1291 for(k= buffer;k<l;k++)putchar(' ');
1292 }
1293 for(k= l;k<limit;k++)putchar(*k);
1294 if(*limit=='|')putchar('|');
1295 putchar(' ');
1296 }
1297
1298 /*:67*/
1299 #line 1015 "cwebdir/common.w"
1300
1301 update_terminal();mark_error();
1302 }
1303
1304 /*:66*//*68:*/
1305 #line 1063 "cwebdir/common.w"
1306
1307 int wrap_up(void){
1308 if(show_progress||show_happiness||history!=spotless)new_line();
1309 if(show_stats)
1310 print_stats();
1311 #line 381 "cwebdir/comm-w2c.ch"
1312 /*69:*/
1313 #line 1073 "cwebdir/common.w"
1314
1315 switch(history){
1316 #line 395 "cwebdir/comm-w2c.ch"
1317 case spotless:
1318 if(show_happiness)puts(_("(No errors were found.)"));break;
1319 case harmless_message:
1320 puts(_("(Did you see the warning message above?)"));break;
1321 case error_message:
1322 puts(_("(Pardon me, but I think I spotted something wrong.)"));break;
1323 case fatal_message:default:
1324 puts(_("(That was a fatal error, my friend.)"));
1325 #line 1083 "cwebdir/common.w"
1326 }
1327
1328 /*:69*/
1329 #line 381 "cwebdir/comm-w2c.ch"
1330
1331 /*90:*/
1332 #line 652 "cwebdir/comm-w2c.ch"
1333
1334 if(C_file)fclose(C_file);
1335 if(tex_file)fclose(tex_file);
1336 if(check_file)fclose(check_file);
1337 if(strlen(check_file_name))
1338 remove(check_file_name);
1339
1340 /*:90*/
1341 #line 382 "cwebdir/comm-w2c.ch"
1342
1343 #line 1069 "cwebdir/common.w"
1344 if(history> harmless_message)return EXIT_FAILURE;
1345 else return EXIT_SUCCESS;
1346 }
1347
1348 /*:68*//*70:*/
1349 #line 1091 "cwebdir/common.w"
1350 void
1351 fatal(
1352 const char*s,const char*t)
1353 {
1354 if(*s)printf("%s",s);
1355 err_print(t);
1356 history= fatal_message;exit(wrap_up());
1357 }
1358
1359 /*:70*//*71:*/
1360 #line 1102 "cwebdir/common.w"
1361 void
1362 overflow(
1363 const char*t)
1364 {
1365 #line 408 "cwebdir/comm-w2c.ch"
1366 printf(_("\n! Sorry, %s capacity exceeded"),t);fatal("","");
1367 #line 1107 "cwebdir/common.w"
1368 }
1369
1370
1371 /*:71*//*75:*/
1372 #line 1155 "cwebdir/common.w"
1373
1374 static void
1375 scan_args(void)
1376 {
1377 char*dot_pos;
1378 char*name_pos;
1379 char*s;
1380 bool found_web= false,found_change= false,found_out= false;
1381
1382
1383 #line 446 "cwebdir/comm-w2c.ch"
1384 strcpy(change_file_name,"/dev/null");
1385 #if defined DEV_NULL
1386 strncpy(change_file_name,DEV_NULL,max_file_name_length-2);
1387 change_file_name[max_file_name_length-2]= '\0';
1388 #elif defined _DEV_NULL
1389 #line 451 "cwebdir/comm-w2c.ch"
1390 strncpy(change_file_name,_DEV_NULL,max_file_name_length-2);
1391 change_file_name[max_file_name_length-2]= '\0';
1392 #endif
1393 #line 454 "cwebdir/comm-w2c.ch"
1394
1395 #line 1166 "cwebdir/common.w"
1396 while(--argc> 0){
1397 if((**(++argv)=='-'||**argv=='+')&&*(*argv+1))/*80:*/
1398 #line 1245 "cwebdir/common.w"
1399
1400 #line 487 "cwebdir/comm-w2c.ch"
1401 {
1402 if(strcmp("-help",*argv)==0||strcmp("--help",*argv)==0)
1403
1404 /*97:*/
1405 #line 787 "cwebdir/comm-w2c.ch"
1406
1407 cb_usagehelp(program==ctangle?CTANGLEHELP:
1408 program==cweave?CWEAVEHELP:CTWILLHELP);
1409
1410
1411 /*:97*/
1412 #line 490 "cwebdir/comm-w2c.ch"
1413
1414 if(strcmp("-version",*argv)==0||strcmp("--version",*argv)==0)
1415
1416 /*100:*/
1417 #line 833 "cwebdir/comm-w2c.ch"
1418
1419 printversionandexit(cb_banner,
1420 program==ctwill?"Donald E. Knuth":"Silvio Levy and Donald E. Knuth",
1421 NULL,"Contemporary development on https://github.com/ascherer/cweb.\n");
1422
1423
1424 /*:100*/
1425 #line 493 "cwebdir/comm-w2c.ch"
1426
1427 if(strcmp("-verbose",*argv)==0||strcmp("--verbose",*argv)==0)
1428
1429 strcpy(*argv,"-v");
1430 if(strcmp("-quiet",*argv)==0||strcmp("--quiet",*argv)==0)
1431
1432 strcpy(*argv,"-q");
1433 for(dot_pos= *argv+1;*dot_pos> '\0';dot_pos++){
1434 switch(*dot_pos){
1435 case'v':show_banner= show_progress= show_happiness= true;continue;
1436 case'q':show_banner= show_progress= show_happiness= false;continue;
1437 case'd':
1438 if(sscanf(++dot_pos,"%u",&kpathsea_debug)!=1)/*81:*/
1439 #line 530 "cwebdir/comm-w2c.ch"
1440
1441 cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill");
1442
1443 #line 1260 "cwebdir/common.w"
1444
1445 #line 538 "cwebdir/comm-w2c.ch"
1446 /*:81*/
1447 #line 505 "cwebdir/comm-w2c.ch"
1448
1449 while(isdigit(*dot_pos))dot_pos++;
1450 dot_pos--;
1451 continue;
1452 case'l':use_language= ++dot_pos;break;
1453 default:flags[(eight_bits)*dot_pos]= flag_change;continue;
1454 }
1455 break;
1456 }
1457 }
1458 #line 1248 "cwebdir/common.w"
1459
1460 #line 530 "cwebdir/comm-w2c.ch"
1461 /*:80*/
1462 #line 1167 "cwebdir/common.w"
1463
1464 else{
1465 s= name_pos= *argv;dot_pos= NULL;
1466 while(*s)
1467 #line 462 "cwebdir/comm-w2c.ch"
1468 if(*s=='.')dot_pos= s++;
1469 else if(*s==DIR_SEPARATOR||*s==DEVICE_SEPARATOR||*s=='/')
1470 dot_pos= NULL,name_pos= ++s;
1471 else s++;
1472
1473 #line 1174 "cwebdir/common.w"
1474 if(!found_web)/*77:*/
1475 #line 1193 "cwebdir/common.w"
1476
1477 {
1478 if(s-*argv> max_file_name_length-5)
1479 /*82:*/
1480 #line 538 "cwebdir/comm-w2c.ch"
1481 fatal(_("! Filename too long\n"),*argv);
1482 #line 1262 "cwebdir/common.w"
1483
1484
1485 /*:82*/
1486 #line 1196 "cwebdir/common.w"
1487
1488 if(dot_pos==NULL)
1489 sprintf(web_file_name,"%s.w",*argv);
1490 else{
1491 strcpy(web_file_name,*argv);
1492 *dot_pos= '\0';
1493 }
1494 #line 1204 "cwebdir/common.w"
1495 sprintf(tex_file_name,"%s.tex",name_pos);
1496 if(make_xrefs){
1497 sprintf(idx_file_name,"%s.idx",name_pos);
1498 sprintf(scn_file_name,"%s.scn",name_pos);
1499 }
1500 sprintf(C_file_name,"%s.c",name_pos);
1501 found_web= true;
1502 }
1503
1504 /*:77*/
1505 #line 1175 "cwebdir/common.w"
1506
1507 else if(!found_change)/*78:*/
1508 #line 1213 "cwebdir/common.w"
1509
1510 {
1511 if(strcmp(*argv,"-")!=0){
1512 if(s-*argv> max_file_name_length-4)
1513 /*82:*/
1514 #line 538 "cwebdir/comm-w2c.ch"
1515 fatal(_("! Filename too long\n"),*argv);
1516 #line 1262 "cwebdir/common.w"
1517
1518
1519 /*:82*/
1520 #line 1217 "cwebdir/common.w"
1521
1522 if(dot_pos==NULL)
1523 sprintf(change_file_name,"%s.ch",*argv);
1524 else strcpy(change_file_name,*argv);
1525 }
1526 found_change= true;
1527 }
1528
1529 /*:78*/
1530 #line 1176 "cwebdir/common.w"
1531
1532 else if(!found_out)/*79:*/
1533 #line 1225 "cwebdir/common.w"
1534
1535 {
1536 if(s-*argv> max_file_name_length-5)
1537 /*82:*/
1538 #line 538 "cwebdir/comm-w2c.ch"
1539 fatal(_("! Filename too long\n"),*argv);
1540 #line 1262 "cwebdir/common.w"
1541
1542
1543 /*:82*/
1544 #line 1228 "cwebdir/common.w"
1545
1546 if(dot_pos==NULL){
1547 sprintf(tex_file_name,"%s.tex",*argv);
1548 sprintf(C_file_name,"%s.c",*argv);
1549 }else{
1550 strcpy(tex_file_name,*argv);
1551 strcpy(C_file_name,*argv);
1552 *dot_pos= '\0';
1553 }
1554 if(make_xrefs){
1555 sprintf(idx_file_name,"%s.idx",*argv);
1556 sprintf(scn_file_name,"%s.scn",*argv);
1557 }
1558 found_out= true;
1559 }
1560
1561 /*:79*/
1562 #line 1177 "cwebdir/common.w"
1563
1564 else/*81:*/
1565 #line 530 "cwebdir/comm-w2c.ch"
1566
1567 cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill");
1568
1569 #line 1260 "cwebdir/common.w"
1570
1571 #line 538 "cwebdir/comm-w2c.ch"
1572 /*:81*/
1573 #line 1178 "cwebdir/common.w"
1574
1575 }
1576 }
1577 if(!found_web)/*81:*/
1578 #line 530 "cwebdir/comm-w2c.ch"
1579
1580 cb_usage(program==ctangle?"ctangle":program==cweave?"cweave":"ctwill");
1581
1582 #line 1260 "cwebdir/common.w"
1583
1584 #line 538 "cwebdir/comm-w2c.ch"
1585 /*:81*/
1586 #line 1181 "cwebdir/common.w"
1587
1588 }
1589
1590 /*:75*//*99:*/
1591 #line 800 "cwebdir/comm-w2c.ch"
1592
1593 static void cb_usage(const_string str)
1594 {
1595 textdomain("cweb-tl");
1596
1597 fprintf(stderr,_("%s: Need one to three file arguments.\n"),str);
1598 fprintf(stderr,_("Try `%s --help' for more information.\n"),str);
1599
1600 textdomain("cweb");
1601
1602 history= fatal_message;exit(wrap_up());
1603 }
1604
1605 static void cb_usagehelp(const_string*message)
1606 {
1607 textdomain("web2c-help");
1608
1609 while(*message){
1610
1611 printf("%s\n",strcmp("",*message)?_(*message):*message);
1612 ++message;
1613 }
1614 textdomain("cweb-tl");
1615
1616 printf(_("\nPackage home page: %s.\n"),"https://ctan.org/pkg/cweb");
1617 textdomain("cweb");
1618
1619 history= spotless;exit(wrap_up());
1620 }
1621
1622 /*:99*//*101:*/
1623 #line 841 "cwebdir/comm-w2c.ch"
1624
1625 void cb_show_banner(void)
1626 {
1627 textdomain("cweb-tl");
1628
1629 printf("%s%s\n",_(cb_banner),versionstring);
1630 textdomain("cweb");
1631
1632 }
1633
1634 /*:101*/