1 % Kpathsea changes for CWEB by Wlodek Bzyl and Olaf Weber
2 % Copyright 2002 Wlodek Bzyl and Olaf Weber
3 % This file is in the Public Domain.
7 \def\title{CWEAVE (Version 3.64)}
8 \def\topofcontents{\null\vfill
9 \centerline{\titlefont The {\ttitlefont CWEAVE} processor}
11 \centerline{(Version 3.64)}
14 \def\Kpathsea/{{\mc KPATHSEA\spacefactor1000}}
15 \def\SQUARE{\vrule width 2pt depth -1pt height 3pt}
16 \def\sqitem{\item{\SQUARE}}
18 \def\title{CWEAVE (Version 3.64k)}
19 \def\topofcontents{\null\vfill
20 \centerline{\titlefont The {\ttitlefont CWEAVE} processor}
22 \centerline{(Version 3.64k)}
26 This change can not be applied when `tie' is used
27 (TOC file can not be typeset).
32 %\let\maybe=\iffalse % print only changed modules
39 The ``banner line'' defined here should be changed whenever \.{CWEAVE}
42 @d banner "This is CWEAVE (Version 3.64)\n"
44 The ``banner line'' defined here should be changed whenever \.{CWEAVE}
47 @d banner "This is CWEAVE, Version 3.64"
54 @ We predeclare several standard system functions here instead of including
55 their system header files, because the names of the header files are not as
56 standard as the names of the functions. (For example, some \CEE/ environments
57 have \.{<string.h>} where others have \.{<strings.h>}.)
60 extern int strlen(); /* length of string */
61 extern int strcmp(); /* compare strings lexicographically */
62 extern char* strcpy(); /* copy one string to another */
63 extern int strncmp(); /* compare up to $n$ string characters */
64 extern char* strncpy(); /* copy up to $n$ string characters */
72 int ac; /* argument count */
73 char **av; /* argument values */
75 int main (int ac, char **av)
78 @x l.107 - Add Web2C version to banner.
79 if (show_banner) printf(banner); /* print a ``banner line'' */
82 printf("%s%s\n", banner, versionstring); /* print a ``banner line'' */
86 @x l.112 - 'use' print_text(), used nowhere else
87 return wrap_up(); /* and exit gracefully */
89 if (0) print_text(text_ptr);
90 return wrap_up(); /* and exit gracefully */
94 @d max_bytes 90000 /* the number of bytes in identifiers,
96 @d max_bytes 1000000 /* the number of bytes in identifiers,
100 @d max_names 4000 /* number of identifiers, strings, section names;
102 @d max_names 10239 /* number of identifiers, strings, section names;
106 @d max_sections 2000 /* greater than the total number of sections */
107 @d hash_size 353 /* should be prime */
108 @d buf_size 100 /* maximum length of input line, plus one */
110 @d max_sections 10239 /* greater than the total number of sections */
111 @d hash_size 8501 /* should be prime */
112 @d buf_size 1000 /* maximum length of input line, plus one */
116 @d max_refs 20000 /* number of cross-references; must be less than 65536 */
117 @d max_toks 20000 /* number of symbols in \CEE/ texts being parsed;
119 @d max_refs 65535 /* number of cross-references; must be less than 65536 */
120 @d max_toks 65535 /* number of symbols in \CEE/ texts being parsed;
124 @d max_texts 4000 /* number of phrases in \CEE/ texts being parsed;
126 @d max_texts 10239 /* number of phrases in \CEE/ texts being parsed;
130 @d max_scraps 2000 /* number of tokens in \CEE/ texts being parsed */
132 @d max_scraps 10000 /* number of tokens in \CEE/ texts being parsed */
137 @x common.h l.30 - boolean comes from kpathsea.
138 typedef short boolean;
147 #include <kpathsea/kpathsea.h>
152 @d xisalpha(c) (isalpha(c)&&((eight_bits)c<0200))
153 @d xisdigit(c) (isdigit(c)&&((eight_bits)c<0200))
154 @d xisspace(c) (isspace(c)&&((eight_bits)c<0200))
155 @d xislower(c) (islower(c)&&((eight_bits)c<0200))
156 @d xisupper(c) (isupper(c)&&((eight_bits)c<0200))
157 @d xisxdigit(c) (isxdigit(c)&&((eight_bits)c<0200))
159 @d xisalpha(c) (isalpha((eight_bits)c)&&((eight_bits)c<0200))
160 @d xisdigit(c) (isdigit((eight_bits)c)&&((eight_bits)c<0200))
161 @d xisspace(c) (isspace((eight_bits)c)&&((eight_bits)c<0200))
162 @d xislower(c) (islower((eight_bits)c)&&((eight_bits)c<0200))
163 @d xisupper(c) (isupper((eight_bits)c)&&((eight_bits)c<0200))
164 @d xisxdigit(c) (isxdigit((eight_bits)c)&&((eight_bits)c<0200))
169 @x common.h l.109 - protos now all in cweb.h.
170 extern name_pointer id_lookup(); /* looks up a string in the identifier table */
171 extern name_pointer section_lookup(); /* finds section name */
172 extern void print_section_name(), sprint_section_name();
179 @x common.h l.123 - explicit types, protos now all in cweb.h.
180 extern history; /* indicates how bad this run was */
181 extern err_print(); /* print error message and context */
182 extern wrap_up(); /* indicate |history| and exit */
183 extern void fatal(); /* issue error message and die */
184 extern void overflow(); /* succumb because a table has overflowed */
186 extern int history; /* indicates how bad this run was */
191 @x common.h l.131 - max_file_name_length is way too small.
192 @d max_file_name_length 60
194 @d max_file_name_length 1024
197 @x common.h l.138 - explicit types.
198 extern include_depth; /* current level of nesting */
200 extern int include_depth; /* current level of nesting */
203 @x common.h l.148 - explicit types.
204 extern line[]; /* number of current line in the stacked files */
205 extern change_line; /* number of current line in change file */
207 extern int line[]; /* number of current line in the stacked files */
208 extern int change_line; /* number of current line in change file */
211 @x common.h l.153 - protos now all in cweb.h.
212 extern reset_input(); /* initialize to read the web file and change file */
213 extern get_line(); /* inputs the next line */
214 extern check_complete(); /* checks that all changes were picked up */
220 @x common.h l.192 - protos now all in cweb.h.
221 extern void common_init();
233 new_xref (name_pointer p)
244 new_section_xref (name_pointer p)
255 set_file_flag (name_pointer p)
261 int names_match(p,first,l,t)
262 name_pointer p; /* points to the proposed match */
263 char *first; /* position of first character of string */
264 int l; /* length of identifier */
265 eight_bits t; /* desired ilk */
268 names_match (name_pointer p, const char *first, int l, char t)
276 init_p (name_pointer p, char t)
283 init_node (name_pointer p)
291 static void skip_limbo (void);
308 skip_TeX() /* skip past pure \TEX/ code */
311 skip_TeX (void) /* skip past pure \TEX/ code */
316 @x l.682 - Add declaration for versionstring.
317 #include <ctype.h> /* definition of |isalpha|, |isdigit| and so on */
324 eight_bits get_next();
326 static eight_bits get_next (void);
333 get_next() /* produces the next input token */
336 get_next (void) /* produces the next input token */
342 else if (*loc=='>') if (*(loc+1)=='*') {loc++; compress(minus_gt_ast);}
343 else compress(minus_gt); break;
345 else if (*loc=='>') {if (*(loc+1)=='*') {loc++; compress(minus_gt_ast);}
346 else compress(minus_gt);} break;
350 while (isalpha(*++loc) || isdigit(*loc) || isxalpha(*loc) || ishigh(*loc));
352 while (isalpha((unsigned char)*++loc) || isdigit((unsigned char)*loc) || isxalpha(*loc) || ishigh(*loc));
356 *id_loc++='$'; *id_loc++=toupper(*loc); loc++;
358 *id_loc++='$'; *id_loc++=toupper((unsigned char)*loc); loc++;
364 if (c=='\\') if (loc>=limit) continue;
365 else if (++id_loc<=section_text_end) {
366 *id_loc = '\\'; c=*loc++;
370 if (loc>=limit) continue;
371 else if (++id_loc<=section_text_end) {
372 *id_loc = '\\'; c=*loc++;
380 void skip_restricted();
382 static void skip_restricted (void);
392 skip_restricted (void)
400 static void phase_one (void);
418 static void C_xref (eight_bits);
425 C_xref( spec_ctrl ) /* makes cross-references for \CEE/ identifiers */
426 eight_bits spec_ctrl;
429 C_xref (eight_bits spec_ctrl) /* makes cross-references for \CEE/ identifiers */
437 static void outer_xref (void);
444 outer_xref() /* extension of |C_xref| */
447 outer_xref (void) /* extension of |C_xref| */
453 void section_check();
455 static void section_check (name_pointer);
463 name_pointer p; /* print anomalies in subtree |p| */
466 section_check (name_pointer p) /* print anomalies in subtree |p| */
473 flush_buffer(b,per_cent,carryover)
474 char *b; /* outputs from |out_buf+1| to |b|,where |b<=out_ptr| */
475 boolean per_cent,carryover;
478 flush_buffer (char *b, boolean per_cent, boolean carryover)
485 finish_line() /* do this at the end of a line */
488 finish_line (void) /* do this at the end of a line */
495 out_str(s) /* output characters from |s| to end of string */
499 out_str (const char *s) /* output characters from |s| to end of string */
507 static void break_out (void);
514 break_out() /* finds a way to break the output line */
517 break_out (void) /* finds a way to break the output line */
528 out_section (sixteen_bits n)
535 out_name(p,quote_xalpha)
537 boolean quote_xalpha;
540 out_name (name_pointer p, boolean quote_xalpha)
568 static int copy_comment (boolean, int);
574 int copy_comment(is_long_comment,bal) /* copies \TEX/ code in comments */
575 boolean is_long_comment; /* is this a traditional \CEE/ comment? */
576 int bal; /* brace balance */
579 copy_comment (boolean is_long_comment, int bal)
585 if (phase==2) app_tok(*(loc++)) else loc++;
587 {if (phase==2) app_tok(*(loc++)) else loc++;}
594 print_cat(c) /* symbolic printout of a category */
598 print_cat (eight_bits c)
605 print_text(p) /* prints a token list for debugging; not used in |main| */
609 print_text (text_pointer p)
620 app_str (const char *s)
638 big_app1 (scrap_pointer a)
649 find_first_ident (text_pointer p)
656 make_reserved(p) /* make the first identifier in |p->trans| like |int| */
660 make_reserved (scrap_pointer p)
668 /* underline the entry for the first identifier in |p->trans| */
672 make_underlined (scrap_pointer p)
678 void underline_xref();
680 static void underline_xref (name_pointer);
691 underline_xref (name_pointer p)
704 reduce (scrap_pointer j, short k, eight_bits c, short d, short n)
717 squash (scrap_pointer j, short k, eight_bits c, short d, short n)
722 @x l.3096 -- rename local var, not to shadow param
723 { scrap_pointer k; /* pointer into |scrap_info| */
726 for (k=scrap_base; k<=lo_ptr; k++) {
727 if (k==pp) putxchar('*'); else putxchar(' ');
728 if (k->mathness %4 == yes_math) putchar('+');
729 else if (k->mathness %4 == no_math) putchar('-');
731 if (k->mathness /4 == yes_math) putchar('+');
732 else if (k->mathness /4 == no_math) putchar('-');
734 { scrap_pointer k_l; /* pointer into |scrap_info| */
737 for (k_l=scrap_base; k_l<=lo_ptr; k_l++) {
738 if (k_l==pp) putxchar('*'); else putxchar(' ');
739 if (k_l->mathness %4 == yes_math) putchar('+');
740 else if (k_l->mathness %4 == no_math) putchar('-');
742 if (k_l->mathness /4 == yes_math) putchar('+');
743 else if (k_l->mathness /4 == no_math) putchar('-');
750 translate() /* converts a sequence of scraps */
753 translate (void) /* converts a sequence of scraps */
760 C_parse(spec_ctrl) /* creates scraps from \CEE/ tokens */
761 eight_bits spec_ctrl;
764 C_parse (eight_bits spec_ctrl) /* creates scraps from \CEE/ tokens */
772 static void app_cur_id (boolean);
779 app_cur_id(scrapping)
780 boolean scrapping; /* are we making this into a scrap? */
783 app_cur_id (boolean scrapping)
800 outer_parse() /* makes scraps from \CEE/ tokens and comments */
803 outer_parse (void) /* makes scraps from \CEE/ tokens and comments */
810 push_level(p) /* suspends the current level */
814 push_level (text_pointer p) /* suspends the current level */
831 get_output() /* returns the next token of output */
834 get_output (void) /* returns the next token of output */
841 output_C() /* outputs the current token list */
844 output_C (void) /* outputs the current token list */
852 static void make_output (void);
859 make_output() /* outputs the equivalents of tokens */
862 make_output (void) /* outputs the equivalents of tokens */
868 if (b=='\'' || b=='"')
869 if (delim==0) delim=b;
870 else if (delim==b) delim=0;
872 if (b=='\'' || b=='"') {
873 if (delim==0) delim=b;
874 else if (delim==b) delim=0;
883 static void phase_two (void);
901 static void finish_C (boolean);
908 finish_C(visible) /* finishes a definition or a \CEE/ part */
909 boolean visible; /* nonzero if we should produce \TEX/ output */
912 finish_C (boolean visible) /* finishes a definition or a \CEE/ part */
918 if (*out_ptr=='6') out_ptr-=2;
919 else if (*out_ptr=='7') *out_ptr='Y';
922 if (*out_ptr=='6') out_ptr-=2;
923 else if (*out_ptr=='7') *out_ptr='Y';
932 static void footnote (sixteen_bits);
939 footnote(flag) /* outputs section cross-references */
943 footnote (sixteen_bits flag) /* outputs section cross-references */
951 static void phase_three (void);
964 @x l.4309 Use binary mode for output files
965 if ((idx_file=fopen(idx_file_name,"w"))==NULL)
967 if ((idx_file=fopen(idx_file_name,"wb"))==NULL)
970 @x l.4324 Use binary mode for output files
971 if ((scn_file=fopen(scn_file_name,"w"))==NULL)
973 if ((scn_file=fopen(scn_file_name,"wb"))==NULL)
979 strcpy(collate+1," \1\2\3\4\5\6\7\10\11\12\13\14\15\16\17");
980 /* 16 characters + 1 = 17 */
981 strcpy(collate+17,"\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37");
982 /* 16 characters + 17 = 33 */
983 strcpy(collate+33,"!\42#$%&'()*+,-./:;<=>?@@[\\]^`{|}~_");
984 /* 32 characters + 33 = 65 */
985 strcpy(collate+65,"abcdefghijklmnopqrstuvwxyz0123456789");
986 /* (26 + 10) characters + 65 = 101 */
987 strcpy(collate+101,"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217");
988 /* 16 characters + 101 = 117 */
989 strcpy(collate+117,"\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237");
990 /* 16 characters + 117 = 133 */
991 strcpy(collate+133,"\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257");
992 /* 16 characters + 133 = 149 */
993 strcpy(collate+149,"\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277");
994 /* 16 characters + 149 = 165 */
995 strcpy(collate+165,"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317");
996 /* 16 characters + 165 = 181 */
997 strcpy(collate+181,"\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337");
998 /* 16 characters + 181 = 197 */
999 strcpy(collate+197,"\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357");
1000 /* 16 characters + 197 = 213 */
1001 strcpy(collate+213,"\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377");
1003 strcpy((char *)collate+1," \1\2\3\4\5\6\7\10\11\12\13\14\15\16\17");
1004 /* 16 characters + 1 = 17 */
1005 strcpy((char *)collate+17,"\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37");
1006 /* 16 characters + 17 = 33 */
1007 strcpy((char *)collate+33,"!\42#$%&'()*+,-./:;<=>?@@[\\]^`{|}~_");
1008 /* 32 characters + 33 = 65 */
1009 strcpy((char *)collate+65,"abcdefghijklmnopqrstuvwxyz0123456789");
1010 /* (26 + 10) characters + 65 = 101 */
1011 strcpy((char *)collate+101,"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217");
1012 /* 16 characters + 101 = 117 */
1013 strcpy((char *)collate+117,"\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237");
1014 /* 16 characters + 117 = 133 */
1015 strcpy((char *)collate+133,"\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257");
1016 /* 16 characters + 133 = 149 */
1017 strcpy((char *)collate+149,"\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277");
1018 /* 16 characters + 149 = 165 */
1019 strcpy((char *)collate+165,"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317");
1020 /* 16 characters + 165 = 181 */
1021 strcpy((char *)collate+181,"\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337");
1022 /* 16 characters + 181 = 197 */
1023 strcpy((char *)collate+197,"\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357");
1024 /* 16 characters + 197 = 213 */
1025 strcpy((char *)collate+213,"\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377");
1033 static void unbucket (eight_bits);
1040 unbucket(d) /* empties buckets having depth |d| */
1044 unbucket (eight_bits d) /* empties buckets having depth |d| */
1050 void section_print();
1052 static void section_print (name_pointer);
1059 section_print(p) /* print all section names in subtree |p| */
1063 section_print (name_pointer p) /* print all section names in subtree |p| */
1071 print_stats (void) {
1074 Section 250. (added)
1076 @x l.4643 - declare print_text(), so it can be 'used' in main.
1080 static void print_text (text_pointer p);