#define version_string "3.04" #define banner "This is CWEAVE (Version x" version_string ")\n" #define max_refs 10000 #define max_toks 10000 #define max_texts 2500 #define max_scraps 4000 #define max_no_of_nodes 215 #define line_length 80 #define stack_size 400 #define sort_stack_size 500 #define variant xref_info #include #include #include #include #include #include "common.h" #define max_bytes 50000L #define max_modules 1000 #define max_idents 5000 #define max_sections 4000 #define hash_size 353 #define buf_size 100 #define longest_name 1000 #define long_buf_size (buf_size+longest_name) #define local static #define array_size(a)((int)(sizeof(a)/sizeof(a[0]))) #define false (boolean)0 #define true (boolean)1 #define ctangle 0 #define cweave 1 #define and_and 04 #define lt_lt 020 #define gt_gt 021 #define plus_plus 013 #define minus_minus 01 #define minus_gt 031 #define not_eq 032 #define lt_eq 034 #define gt_eq 035 #define eq_eq 036 #define or_or 037 #define find_char()(loc<=limit||get_line()) #define id_index(p)((sixteen_bits)((p)-id_table)) #define id_at(i)(&id_table[i]) #define mod_index(p)((sixteen_bits)((p)-mod_table)) #define mod_at(i)(&mod_table[i]) #define name_begin(p)((p)->byte_start) #define length(p)((int)(strlen(name_begin(p)))) #define name_end(p)(name_begin(p)+length(p)) #define complete_name(p)((p)->byte_start[-1]=='\0') #define print_mod(p) \ printf(": <%s%s>",name_begin(p),complete_name(p)?"":"...") #define spotless 0 #define harmless_message 1 #define error_message 2 #define fatal_message 3 #define mark_harmless() \ if(history==spotless)history=harmless_message;else #define mark_error()(history=error_message) #define overflow(t)fatal("\n! Sorry, %s capacity exceeded",t) #define confusion(s)fatal("\n! This can't happen: %s",s) #define show_banner flags['b'] #define show_happiness flags['h'] #define show_progress flags['p'] #define show_stats flags['s'] #define C_plus_plus flags['+'] #define compatibility_mode flags['c'] #define update_terminal()fflush(stdout) #define new_line()putchar('\n') #define term_write(string,leng)printf("%.*s",(int)(leng),string) #define reserved(a)(a->ilk>=type_defined) #define unindexed(a)(a->ilk>=NULL_like) #define xref equiv_or_xref #define next_xref(x)(&xmem[(x)->next]) #define xnum(i)(xmem[i].num) #define xlink(i)(xmem[i].next) #define xref_index(p)((sixteen_bits)((p)-xmem)) #define cite_flag 0x4000 #define def_flag 0x8000 #define num_mask (cite_flag-1) #define make_xref(n,i) \ \ if(++xref_ptr>= &xmem[max_refs]) \ overflow("cross-reference"); \ else xref_ptr->num=n,xref_ptr->next=i #define no_xref (!flags['x']) #define make_xrefs flags['x'] #define file_flag (cite_flag-1) #define tok_mem_end (&tok_mem[max_toks]) #define text_mem_end (&text_mem[max_texts]) #define text_index(p)((sixteen_bits)((p)-text_mem)) #define text_at(i)(&text_mem[i]) #define text_begin(p)(*(p)) #define text_end(p)(*(p+1)) #define code_of(c)ccode[(unsigned char)(c)] #define compress2(char2,code)if(*loc==char2)return++loc,code #define compress3(char2,char3,code) \ if(*loc==char2&&loc[1]==char3)return loc+=2,code #define comp_ass_op2(code) \ if(*loc=='='&&!compatibility_mode)return++loc,code #define comp_ass_op3(char2,code) \ if(*loc==char2&&loc[1]=='='&&!compatibility_mode)return loc+=2,code #define shift_and_store(ch)(*id_loc++=ch,c= * ++loc) #define shift()(next_control=get_next()) #define emit_space()out_str("\\Y"); #define scrap_info scrap_union.scrap_field #define scrap_info_end (&scrap_info[max_scraps]) #define app(a)(*tok_ptr++=a) #define app_tok(a) \ if(tok_ptr>tok_mem_end-2)overflow("token"); \ else app(a) #define app_char_tok(c)app_tok((unsigned char)(c)) #define freeze_text()(* ++text_ptr=tok_ptr) #define pack_scrap(c,m) \ (scrap_ptr->cat=c,scrap_ptr->trans=text_ptr,freeze_text(), \ (scrap_ptr++)->mathness=5*(m)) #define id_flag 10240U #define res_flag (2*id_flag) #define mod_flag (3*id_flag) #define text_flag (4*id_flag) #define inner_text_flag (5*id_flag) #define enter_block(i)save[i].txt=text_ptr,save[i].tok=tok_ptr; #define leave_block(i)text_ptr=save[i].txt,tok_ptr=save[i].tok; #define check_toks(n)if(tok_ptr>tok_mem_end-n) \ overflow("token");else #define check_text()if(text_ptr>=text_mem_end-1) \ overflow("text");else #define check_scrap()if(scrap_ptr>=scrap_info_end) \ overflow("scrap");else check_text() #define dangling_tokens()(compatibility_mode&&tok_ptr> *text_ptr) #define typedef_tracking(b)(typedef_master+=b?5:-5) #define max_category end_expr #define max_rule_cat return_like #define valid_cat(c)((c)>0&&(c)<=max_rule_cat) #define yes_math 1 #define no_math 2 #define maybe_math 0 #define start_scrap(s,c,m)p= &token_trans[s],p->cat=c,p->mathness=5*(m) #define end_scrap p->trans=text_ptr,freeze_text(); #define left_math(a)(a->mathness>>2) #define right_math(a)(a->mathness&0x3) #define set_mode(x) \ if(cur_mathness==maybe_math)cur_mathness=init_mathness=x; \ else if(cur_mathness!=x){app('$');cur_mathness=x;} \ else #define app_trans(a)app_tok(text_flag+text_index((a)->trans)) #define add_trans(a) \ {scrap_pointer scr=a; \ if(left_math(scr)!=maybe_math) \ {if(cur_mathness==maybe_math)init_mathness=left_math(scr); \ else if(cur_mathness!=left_math(scr))app('$'); \ cur_mathness=right_math(scr); \ } \ app_trans(scr); \ } #define max_lhs_length 4 #define trie_root (&trie_node_mem[0]) #define successor(q,c) \ (&trie_node_mem[(q)->next[(c)-1]]) #define no_successor(q,c)((q)->next[(c)-1]==0) #define set_successor(q,c,x)((q)->next[(c)-1]=(eight_bits)((x)-trie_node_mem)) #define rule_error install_failed=true,print #define math_char(x)((x)==yes_math?'+':(x)==no_math?'-':'?') #define cwebx 0x0001 #define compatibility 0x0002 #define only_plus_plus 0x0004 #define no_plus_plus 0x0008 #define unaligned_braces 0x0050 #define aligned_braces 0x0020 #define wide_braces 0x0030 #define standard_braces 0x0060 #define merged_decls 0x0080 #define forced_statements 0x0100 #define no_forced_statements 0x0600 #define all_stats_forced 0x0300 #define not_all_stats_forced 0x0400 #define cur_tok cur_state.tok_field #define cur_end cur_state.end_field #define cur_mode cur_state.mode_field #define cur_state stack[0] #define stack_end (&stack[stack_size]) #define pop_level()cur_state= * --stack_ptr #define out_id_full(p)out_id_part(name_begin(p),length(p)) #define out_line (&out_buf[1]) #define out_buf_end (&out_line[line_length]) #define tex_putc(c)putc(c,tex_file) #define tex_new_line()(putc('\n',tex_file),++out_line_nr) #define tex_printf(format)fprintf(tex_file,format) #define output_line_empty()(out_ptr==out_line) #define out(c) \ *(out_ptr>=out_buf_end?(break_out(),out_ptr++):out_ptr++)=c #define triple_file_output flags['t'] #define even_out_pages flags['e'] #define sort_info scrap_union.id_list_field #define sort_info_end (&sort_info[sort_stack_size]) #define ilink(p)index_link[id_index(p)] #define infinity 255 #define report(k,c,m) \ printf("\t%lu %ss (out of %lu)\n",(unsigned long)(c),k,(unsigned long)(m)) /*3:*//*11:*/ #line 122 "common.inc" boolean names_match(id_pointer,char*,int,int); void init_id_name(id_pointer,int); void init_module_name(mod_pointer);/*:11*//*16:*/ #line 182 "cweave.w" enum {normal, roman, wildcard, typewriter, reference, type_defined, TeX_like, NULL_like, const_like,typedef_like };/*:16*//*17:*/ #line 258 "cweave.w" typedef struct xref_info {sixteen_bits num; sixteen_bits next; }xref_info,*xref_pointer;/*:17*//*23:*/ #line 371 "cweave.w" typedef sixteen_bits token,*token_pointer,* *text_pointer;/*:23*//*36:*/ #line 719 "cweave.w" enum {at_sign_image=UCHAR_MAX+1, or, mul_assign,div_assign,mod_assign,plus_assign,minus_assign, left_assign,right_assign,and_assign,xor_assign,or_assign, sh_sh,ellipsis,colon_colon, start_preproc,end_preproc, join, thin_space, math_break, line_break, big_line_break, no_line_break, backup_line, pseudo_semi, force_expr_open,force_expr_close, include_preproc, ignore, constant,string, identifier, xref_roman,xref_wildcard,xref_typewriter,xref_mark, refer, TeX_string, verbatim, ignored_text, char_trans, ASCII_code, begin_comment,end_comment, underline, #ifdef DEBUG trace0,trace1,trace2,trace3, #endif format, definition, header, begin_C, module_name, new_section };/*:36*//*84:*/ #line 1843 "cweave.w" typedef struct {eight_bits cat; eight_bits mathness; text_pointer trans; }scrap,*scrap_pointer;/*:84*//*87:*/ #line 1969 "cweave.w" enum {cancel=UCHAR_MAX+1, indent,outdent,opt,flush_left,break_space,force,big_force, backup,big_backup, relax, space=opt,tilde=flush_left };/*:87*//*115:*/ #line 177 "parser.w" enum {unop=1, binop, unorbinop, select, question, lbrace,rbrace,lpar,rpar,lbrack,rbrack, comma,semi,colon,colcol,magic, subscript, struct_head, short_lbrace,short_struct_head, compound_statement, statement, function, function_head, parameters, label, if_head, if_else_head, do_head, mod_scrap, declarator, declaration, expression, while_like, do_like, if_like, else_like, int_like, case_like, sizeof_like, struct_like, return_like, lproc, rproc, insert, begin_expr,end_expr };/*:115*//*131:*/ #line 693 "parser.w" typedef struct {short id; struct {eight_bits category[max_lhs_length];signed char context,length;}lhs; struct{eight_bits category;char*translation;}rhs; sixteen_bits mask; short displacement; }reduction;/*:131*//*132:*/ #line 720 "parser.w" typedef struct{reduction*rule;eight_bits next[max_rule_cat];}trie_node;/*:132*//*182:*/ #line 2626 "cweave.w" typedef enum{inner,outer}mode; typedef struct {token_pointer tok_field; token_pointer end_field; mode mode_field; }output_stack_element,*stack_pointer;/*:182*//*215:*/ #line 3307 "cweave.w" typedef struct{id_pointer head;int depth;}sort_node,*sort_pointer;/*:215*//*4:*/ #line 108 "cweave.w" void phase_one(void); void phase_two(void); void phase_three(void);/*:4*//*33:*/ #line 621 "cweave.w" int scan_comment(int*bal,boolean one_liner);/*:33*//*40:*/ #line 858 "cweave.w" int get_next(void);/*:40*//*53:*/ #line 1157 "cweave.w" void C_xref(boolean); void outer_xref(void); void mod_check(mod_pointer);/*:53*//*68:*/ #line 1499 "cweave.w" void do_C(void); void outer_read(void); void finish_C(void); void finish_line(void); void out_str(char*); void out_sec_nr(int); xref_pointer list_refs(xref_pointer,sixteen_bits); void footnote(xref_pointer*,sixteen_bits); void app_str(char*);/*:68*//*83:*/ #line 1827 "cweave.w" text_pointer translate(void); void make_output(text_pointer,mode);/*:83*//*137:*/ #line 784 "parser.w" void install_rule(reduction*rule);/*:137*//*181:*/ #line 2609 "cweave.w" void out_identifier(id_pointer); void out_keyword(id_pointer); xref_pointer out_module_name(mod_pointer);/*:181*//*208:*/ #line 3170 "cweave.w" void break_out(void);/*:208*//*224:*/ #line 3464 "cweave.w" void unbucket(eight_bits);/*:224*//*229:*/ #line 3531 "cweave.w" void list_modules(mod_pointer);/*:229*//*18:*/ #line 279 "cweave.w" xref_info xmem[max_refs]; xref_pointer xref_ptr= &xmem[0]; sixteen_bits xref_switch=0,mod_xref_switch=0;/*:18*//*24:*/ #line 389 "cweave.w" token tok_mem[max_toks]; token_pointer text_mem[max_texts]; token_pointer tok_ptr=tok_mem; text_pointer text_ptr=text_mem; #ifdef STAT token_pointer max_tok_ptr=tok_mem; text_pointer max_text_ptr=text_mem; #endif/*:24*//*28:*/ #line 484 "cweave.w" int ccode[UCHAR_MAX+1];/*:28*//*39:*/ #line 849 "cweave.w" id_pointer cur_id; mod_pointer cur_mod; int preprocessing=0;/*:39*//*50:*/ #line 1122 "cweave.w" boolean change_exists=false; int next_control;/*:50*//*85:*/ #line 1884 "cweave.w" union {scrap scrap_field[max_scraps];/*216:*/ #line 3316 "cweave.w" sort_node id_list_field[sort_stack_size];/*:216*/ #line 1886 "cweave.w" }scrap_union; scrap_pointer scrap_base=scrap_info; scrap_pointer scrap_ptr=scrap_info; #ifdef STAT scrap_pointer max_scr_ptr=scrap_info; #endif/*:85*//*88:*/ #line 2009 "cweave.w" struct{text_pointer txt;token_pointer tok;}save[2];/*:88*//*90:*/ #line 2038 "cweave.w" scrap token_trans[ignore];/*:90*//*108:*/ #line 2430 "cweave.w" local int typedef_master= -5; local int brace_level,par_level;/*:108*//*122:*/ #line 483 "parser.w" scrap_pointer pp; scrap_pointer lo_ptr; scrap_pointer hi_ptr;/*:122*//*133:*/ #line 738 "parser.w" trie_node trie_node_mem[max_no_of_nodes]; int node_no=1; #ifdef DEBUG boolean install_failed=false; #endif/*:133*//*136:*/ #line 778 "parser.w" sixteen_bits rule_mask;/*:136*//*153:*/ #line 1159 "parser.w" #ifdef DEBUG int tracing; #endif/*:153*//*183:*/ #line 2643 "cweave.w" output_stack_element stack[stack_size]; stack_pointer stack_ptr= &stack[0]; #ifdef STAT stack_pointer max_stack_ptr=stack; #endif/*:183*//*203:*/ #line 3090 "cweave.w" char out_buf[line_length+1]; char*out_ptr; int out_line_nr=1;/*:203*//*217:*/ #line 3322 "cweave.w" sort_pointer sort_ptr=sort_info; #ifdef STAT sort_pointer max_sort_ptr=sort_info; #endif/*:217*//*218:*/ #line 3338 "cweave.w" eight_bits collate[UCHAR_MAX-25]; int end_collate;/*:218*//*220:*/ #line 3376 "cweave.w" id_pointer index_link[max_idents]; id_pointer bucket[UCHAR_MAX+1];/*:220*/ #line 82 "cweave.w" int main(int argc,char* *argv) {program=cweave; make_xrefs=true; common_init(argc,argv);/*19:*/ #line 289 "cweave.w" xnum(0)=0;/*:19*//*25:*/ #line 401 "cweave.w" *text_ptr=tok_ptr;/*:25*//*37:*/ #line 765 "cweave.w" {unsigned char c=0; do ccode[c]=isspace(c)?new_section:ignore;while(c++ !=UCHAR_MAX); ccode['@']=at_sign_image; ccode['v']=ccode['V']=or; ccode['!']=underline; ccode['^']=xref_roman; ccode['?']=xref_wildcard; ccode['.']=xref_typewriter; ccode[':']=xref_mark;ccode['#']=refer; ccode['t']=ccode['T']=TeX_string; ccode['=']=verbatim; ccode['q']=ccode['Q']=ignored_text; ccode['l']=ccode['L']=char_trans; ccode['\'']=ASCII_code; ccode['&']=join; ccode[',']=thin_space; ccode['|']=math_break; ccode['/']=line_break; ccode[')']=big_line_break; ccode['\\']=backup_line; ccode['+']=no_line_break; ccode[';']=pseudo_semi; ccode['[']=force_expr_open;ccode[']']=force_expr_close; ccode['p']=ccode['P']=include_preproc; #ifdef DEBUG ccode['0']=trace0;ccode['1']=trace1; ccode['2']=trace2;ccode['3']=trace3; #endif ccode['f']=ccode['F']=ccode['s']=ccode['S']=format; ccode['d']=ccode['D']=definition; ccode['h']=ccode['H']=header; ccode['c']=ccode['C']=begin_C; ccode['<']=ccode['(']=module_name; ccode['~']=ccode['*']=new_section; if(compatibility_mode)/*38:*/ #line 813 "cweave.w" {ccode['h']=ccode['H']=include_preproc; ccode['p']=ccode['P']=begin_C; ccode['#']=big_line_break; ccode[':']=xref_wildcard; }/*:38*/ #line 802 "cweave.w" }/*:37*//*91:*/ #line 2050 "cweave.w" {static struct{short tok;eight_bits cat,mathness;char*tr;} trans_ini[]={/*116:*/ #line 229 "parser.w" {'!',unop,yes_math,"\\R"}, {'~',unop,yes_math,"\\CM"}, {'/',binop,yes_math,"/"}, {'<',binop,yes_math,"<"}, {'>',binop,yes_math,">"}, {'.',select,yes_math,"."}, {'=',binop,yes_math,"\\K"}, {'|',binop,yes_math,"\\OR"}, {or,binop,yes_math,"\\OR"}, {'^',binop,yes_math,"\\XOR"}, {'%',binop,yes_math,"\\MOD"}, {'+',unorbinop,yes_math,"+"}, {'-',unorbinop,yes_math,"-"}, {'*',unorbinop,yes_math,"*"}, {'&',unorbinop,yes_math,"\\AND"}, {'?',question,yes_math,"\\?"}, {'(',lpar,yes_math,"("}, {')',rpar,yes_math,")"}, {'[',lbrack,maybe_math,"["}, {']',rbrack,maybe_math,"]"}, {'{',lbrace,yes_math,"\\{"}, {'}',rbrace,yes_math,"\\}"}, {',',comma,yes_math,","}, {';',semi,yes_math,";"}, {':',colon,maybe_math,":"}, {'#',insert,maybe_math,"\\#"}, {at_sign_image,insert,maybe_math,"@"}, {not_eq,binop,yes_math,"\\I"}, {lt_eq,binop,yes_math,"\\Z"}, {gt_eq,binop,yes_math,"\\G"}, {eq_eq,binop,yes_math,"\\E"}, {and_and,binop,yes_math,"\\W"}, {or_or,binop,yes_math,"\\V"}, {plus_plus,unop,yes_math,"\\PP"}, {minus_minus,unop,yes_math,"\\MM"}, {minus_gt,select,yes_math,"\\MG"}, {gt_gt,binop,yes_math,"\\GG"}, {lt_lt,binop,yes_math,"\\LL"}, {mul_assign,binop,yes_math,"\\KK*"}, {div_assign,binop,yes_math,"\\KK/"}, {mod_assign,binop,yes_math,"\\KK\\MOD"}, {plus_assign,binop,yes_math,"\\KK+"}, {minus_assign,binop,yes_math,"\\KK-"}, {left_assign,binop,yes_math,"\\KK\\LL"}, {right_assign,binop,yes_math,"\\KK\\GG"}, {and_assign,binop,yes_math,"\\KK\\AND"}, {xor_assign,binop,yes_math,"\\KK\\XOR"}, {or_assign,binop,yes_math,"\\KK\\OR"}, {thin_space,insert,yes_math,"\\,"}, {pseudo_semi,magic,maybe_math,""}, {force_expr_open,begin_expr,maybe_math,""}, {force_expr_close,end_expr,maybe_math,""}, {join,insert,no_math,"\\J"}, {ellipsis,int_like,yes_math,"\\ldots"}, {sh_sh,binop,yes_math,"\\SS"}, {colon_colon,colcol,yes_math,"\\CC"}/*:116*/ #line 2051 "cweave.w" }; int i,n=array_size(trans_ini); scrap o={insert,5*maybe_math,NULL}; for(i=0;icat=trans_ini[i].cat;p->mathness=5*trans_ini[i].mathness; app_str(trans_ini[i].tr);p->trans=text_ptr;freeze_text(); }/*117:*/ #line 297 "parser.w" {scrap*p; start_scrap(math_break,insert,maybe_math); app(opt),app('0');end_scrap; start_scrap(line_break,insert,no_math); app(force);end_scrap; start_scrap(end_preproc,rproc,no_math); app(force);end_scrap; start_scrap(' ',insert,no_math); app(break_space);end_scrap; start_scrap(big_line_break,insert,no_math); app(big_force);end_scrap; start_scrap(backup_line,insert,no_math); app(backup);end_scrap; start_scrap(no_line_break,insert,no_math); app(cancel),app(relax),app(break_space),app(relax),app(cancel);end_scrap; start_scrap(include_preproc,insert,yes_math); app(force),app_str("\\ATP"),app(force);end_scrap; }/*:117*/ #line 2062 "cweave.w" o.trans=text_ptr;freeze_text(); for(i=0;i<=UCHAR_MAX;++i) if(token_trans[i].cat==0)token_trans[i]=o; enter_block(0); }/*:91*//*154:*/ #line 1171 "parser.w" #ifdef DEBUG tracing=flags['d']?trace1:trace0; #endif/*:154*//*158:*/ #line 34 "rules.w" rule_mask=(compatibility_mode?0x0001:0x0002) |(C_plus_plus?0x0008:0x0004) |(flags['w']?0x0040:flags['u']?0x0020:0x0010) |(flags['m']?0x0000:0x0080) |(flags['a']?0x0400:flags['f']?0x0200:0x0100) ; {static reduction rule[]={/*159:*/ #line 62 "rules.w" {1,{{expression,unop}},{expression,NULL}}, {2,{{expression,binop,expression}},{expression,NULL}}, {3,{{expression,unorbinop,expression}},{expression,NULL}}, {4,{{expression,select,expression}},{expression,NULL}}, {5,{{expression,select,int_like}},{expression,"__$_"}}, {6,{{expression,comma,expression}},{expression,"__p1_"}}, {7,{{expression,expression}},{expression,NULL}}, {8,{{expression,lpar,rpar}},{expression,"__,_"}}, {9,{{expression,subscript}},{expression,NULL}}, {10,{{lpar,expression,rpar}},{expression,NULL}}, {11,{{lbrack,expression,rbrack}},{subscript,NULL}}, {12,{{lbrack,rbrack}},{subscript,"_,_"}}, {13,{{unop,expression}},{expression,NULL}}, {14,{{unorbinop,expression}},{expression,"o__"}},/*:159*//*160:*/ #line 87 "rules.w" {20,{{question,expression,colon}},{binop,"__m_"}}, {21,{{parameters,expression}},{expression,"_,_"}}, {22,{{sizeof_like,parameters}},{expression,NULL}}, {23,{{sizeof_like,expression}},{expression,NULL}}, {24,{{sizeof_like,int_like}},{expression,"_~_"},only_plus_plus},/*:160*//*161:*/ #line 135 "rules.w" {30,{{int_like,int_like}},{int_like,"_~_"}}, {31,{{int_like,expression,semi}},{declaration,"_~!__"}}, {32,{{int_like,semi}},{declaration,NULL}}, {33,{{int_like,expression,comma}},{int_like,"_~!__p1"}}, {34,{{unorbinop,int_like}},{int_like,"o__"}},/*:161*//*162:*/ #line 166 "rules.w" {35,{{magic,int_like}},{expression,"_$_"}}, {36,{{expression,parameters}},{function_head,"_B_"}}, {37,{{lpar,int_like,expression,rpar}},{parameters,"_+++_~!_---_"}}, {38,{{int_like,expression,colon}},{int_like,"_~!_m_"}}, {39,{{int_like,colon}},{int_like,"_m_"}},/*:162*//*163:*/ #line 212 "rules.w" {40,{{unorbinop,rpar},-1},{declarator,"_,"}}, {41,{{unorbinop,comma},-1},{declarator,"_,"}}, {42,{{int_like,subscript},1},{declarator,",_"}}, {43,{{unorbinop,subscript},1},{declarator,",_"}}, {44,{{lpar,subscript},1},{declarator,",_"}},/*:163*//*164:*/ #line 223 "rules.w" {45,{{unorbinop,declarator}},{declarator,"o__"}}, {46,{{declarator,subscript}},{declarator,NULL}}, {47,{{declarator,parameters}},{declarator,NULL}}, {48,{{lpar,declarator,rpar}},{declarator,NULL}},/*:164*//*165:*/ #line 241 "rules.w" {50,{{lpar,int_like,declarator,comma}},{lpar,"____p5"}}, {51,{{lpar,int_like,comma}},{lpar,"___p5"}}, {52,{{lpar,int_like,declarator,rpar}},{parameters,NULL}}, {53,{{lpar,int_like,rpar}},{parameters,NULL}}, {54,{{lpar,rpar}},{parameters,"_,_"}},/*:165*//*166:*/ #line 254 "rules.w" {60,{{struct_like,lbrace}},{struct_head,"_ft_"},standard_braces}, {60,{{struct_like,lbrace}},{struct_head,"_~_"},unaligned_braces}, {60,{{struct_like,lbrace}},{struct_head,"_f_"},wide_braces}, {61,{{struct_like,expression,lbrace}}, {struct_head,"_~!_ft_"},standard_braces}, {61,{{struct_like,expression,lbrace}}, {struct_head,"_~!_~_"},unaligned_braces}, {61,{{struct_like,expression,lbrace}}, {struct_head,"_~!_f_"},wide_braces}, {62,{{struct_like,int_like,lbrace}}, {struct_head,"_~!$_ft_"},standard_braces|no_plus_plus}, {62,{{struct_like,int_like,lbrace}}, {struct_head,"_~!_ft_"},standard_braces|only_plus_plus}, {62,{{struct_like,int_like,lbrace}}, {struct_head,"_~!$_~_"},unaligned_braces|no_plus_plus}, {62,{{struct_like,int_like,lbrace}}, {struct_head,"_~!_~_"},unaligned_braces|only_plus_plus}, {62,{{struct_like,int_like,lbrace}}, {struct_head,"_~!$_f_"},wide_braces|no_plus_plus}, {62,{{struct_like,int_like,lbrace}}, {struct_head,"_~!_f_"},wide_braces|only_plus_plus}, {63,{{struct_like,expression}},{int_like,"_~_"}}, {64,{{struct_like,int_like}},{int_like,"_~$_"},no_plus_plus}, {64,{{struct_like,int_like}},{int_like,"_~_"},only_plus_plus}, {65,{{struct_head,declaration,rbrace}}, {int_like,"_+_-f_"},standard_braces}, {65,{{struct_head,declaration,rbrace}}, {int_like,"_+f_-f_"},unaligned_braces&wide_braces}, {66,{{label,declaration}},{declaration,"b_f_"},only_plus_plus},/*:166*//*167:*/ #line 288 "rules.w" {67,{{struct_like,lbrace,expression},-1},{struct_head,"_B_"}}, {68,{{struct_like,expression,lbrace,expression},-1}, {struct_head,"_~_B_"}}, {69,{{struct_head,expression,comma,expression},1}, {expression,"__B!_"}}, {70,{{struct_head,expression,rbrace}},{int_like,"_~+!_-B_"}},/*:167*//*168:*/ #line 302 "rules.w" {71,{{struct_like,lbrace,magic}},{short_struct_head,"_B__+"}}, {72,{{struct_like,expression,lbrace,magic}}, {short_struct_head,"_~!_B__+"}}, {73,{{struct_like,int_like,lbrace,magic}}, {short_struct_head,"_~!$_B__+"},no_plus_plus}, {73,{{struct_like,int_like,lbrace,magic}}, {short_struct_head,"_~!_B__+"},only_plus_plus}, {74,{{short_struct_head,declaration}},{short_struct_head,"_B_"}}, {75,{{short_struct_head,rbrace}},{int_like,"_-B_"}},/*:168*//*169:*/ #line 330 "rules.w" {80,{{expression,semi}},{statement,NULL}}, {81,{{semi}},{statement,NULL}}, {82,{{expression,colon}},{label,"!_h_"}}, {83,{{case_like,expression,colon}},{label,"_ _h_"}}, {84,{{case_like,colon}},{label,"_h_"}}, {85,{{label,label}},{label,"_B_"}}, {86,{{label,statement}},{statement,"b_B_"},not_all_stats_forced}, {86,{{label,statement}},{statement,"b_f_"},all_stats_forced}, {87,{{magic}},{semi,NULL}},/*:169*//*170:*/ #line 360 "rules.w" {90,{{declaration,declaration}},{declaration,"_f_"}}, {91,{{lbrace,declaration,declaration},1}, {declaration,"_B_"},merged_decls}, {92,{{declaration,statement}},{statement,"_F_"},no_plus_plus}, {92,{{declaration,statement}},{statement,"_f_"},only_plus_plus}, {93,{{statement,statement}},{statement,"_f_"},forced_statements}, {93,{{statement,statement}},{statement,"_B_"},no_forced_statements}, {94,{{statement,declaration}},{declaration,"_f_"},only_plus_plus}, {95,{{lbrace,rbrace}},{statement,"_,_"}}, {96,{{lbrace,statement,rbrace}}, {compound_statement,"ft_+_-f_"},standard_braces}, {96,{{lbrace,statement,rbrace}}, {compound_statement,"_+f_-f_"},unaligned_braces}, {96,{{lbrace,statement,rbrace}}, {compound_statement,"f_+f_-f_"},wide_braces}, {97,{{lbrace,declaration,rbrace}}, {compound_statement,"ft_+_-f_"},standard_braces}, {97,{{lbrace,declaration,rbrace}}, {compound_statement,"_+f_-f_"},unaligned_braces}, {97,{{lbrace,declaration,rbrace}}, {compound_statement,"f_+f_-f_"},wide_braces}, {98,{{compound_statement}},{statement,"f_f"}}, {99,{{lbrace,expression,comma,rbrace}},{expression,"_,__,_"}}, {100,{{lbrace,expression,rbrace}},{expression,"_,_,_"}},/*:170*//*171:*/ #line 391 "rules.w" {101,{{lbrace,magic}},{short_lbrace,"__+"}}, {102,{{short_lbrace,declaration}},{short_lbrace,"_B_"}}, {103,{{short_lbrace,statement}},{short_lbrace,"_B_"}}, {104,{{short_lbrace,rbrace}},{statement,"_-B_"}},/*:171*//*172:*/ #line 419 "rules.w" {110,{{if_like,expression}},{if_head,"f_~_"}}, {111,{{lbrace,if_like,expression},1},{if_head,"_~_"},standard_braces}, {112,{{if_head,compound_statement,else_like,if_like}}, {if_like,"__f_~_"},aligned_braces}, {112,{{if_head,compound_statement,else_like,if_like}}, {if_like,"_~_~_~_"},unaligned_braces}, {113,{{if_head,statement,else_like,if_like}}, {if_like,"_+B_-f_~_"},not_all_stats_forced}, {113,{{if_head,statement,else_like,if_like}}, {if_like,"_+f_-f_~_"},all_stats_forced}, {114,{{if_head,compound_statement,else_like}}, {if_else_head,"__f_"},aligned_braces}, {114,{{if_head,compound_statement,else_like}}, {if_else_head,"_~_~_"},unaligned_braces}, {115,{{if_head,statement,else_like}}, {if_else_head,"_+B_-f_"},not_all_stats_forced}, {115,{{if_head,statement,else_like}}, {if_else_head,"_+f_-f_"},all_stats_forced}, {116,{{if_head,compound_statement}}, {statement,"__f"},aligned_braces}, {116,{{if_head,compound_statement}}, {statement,"_~_f"},unaligned_braces}, {117,{{if_head,statement}}, {statement,"_+B_-f"},not_all_stats_forced}, {117,{{if_head,statement}}, {statement,"_+f_-f"},all_stats_forced}, {118,{{if_else_head,compound_statement}}, {statement,"__f"},aligned_braces}, {118,{{if_else_head,compound_statement}}, {statement,"_~_f"},unaligned_braces}, {119,{{if_else_head,statement}}, {statement,"_+B_-f"},not_all_stats_forced}, {119,{{if_else_head,statement}}, {statement,"_+f_-f"},all_stats_forced},/*:172*//*173:*/ #line 458 "rules.w" {120,{{short_lbrace,if_like,expression},1}, {if_head,"_~_"}}, {121,{{short_lbrace,if_head,statement,else_like}}, {short_lbrace,"_B_B_B_"}}, {122,{{short_lbrace,if_head,statement}}, {short_lbrace,"_B_B_"}},/*:173*//*174:*/ #line 484 "rules.w" {130,{{while_like,expression}},{if_else_head,"f_~_"}}, {131,{{lbrace,while_like,expression},1}, {if_else_head,"_~_"},standard_braces}, {132,{{lpar,statement,statement},1}, {statement,"_B_"},forced_statements}, {133,{{lpar,statement,expression,rpar}},{expression,"__B__"}}, {134,{{lpar,statement,rpar}},{expression,NULL}}, {135,{{do_like,compound_statement,while_like}}, {do_head,"__~_"},standard_braces}, {135,{{do_like,compound_statement,while_like}}, {do_head,"_~_~_"},unaligned_braces}, {135,{{do_like,compound_statement,while_like}}, {do_head,"__f_"},wide_braces}, {136,{{do_like,statement,while_like}}, {do_head,"_+B_-B_"},not_all_stats_forced}, {136,{{do_like,statement,while_like}}, {do_head,"_+f_-f_"},all_stats_forced}, {137,{{do_head,expression,semi}},{statement,"f_~__f"}}, {138,{{lbrace,do_head,expression,semi},1},{statement,"_~__f"}},/*:174*//*175:*/ #line 512 "rules.w" {139,{{short_lbrace,while_like,expression}}, {short_lbrace,"_B_~_"}}, {140,{{short_lbrace,do_like,statement,while_like},1}, {do_head,"_B_B_"}}, {141,{{short_lbrace,do_head,expression,semi}}, {short_lbrace,"_B_~__"}},/*:175*//*176:*/ #line 528 "rules.w" {145,{{return_like,semi}},{statement,NULL}}, {146,{{return_like,expression}},{expression,"_~_"}},/*:176*//*177:*/ #line 556 "rules.w" {150,{{function_head,statement}},{function,"!_f_"}}, {151,{{expression,statement}},{function,"!_f_"}}, {152,{{expression,declaration,statement}}, {function,"!_++f_--f_"}}, {153,{{int_like,function}},{function,"_ _"}}, {154,{{declaration,function}},{function,"_F_"}}, {155,{{function,declaration}},{declaration,"_F_"}}, {156,{{function,function}},{function,"_F_"}}, {157,{{function_head,semi},-1},{expression,NULL},no_plus_plus}, {158,{{function_head,comma},-1},{expression,NULL}}, {159,{{function_head,rpar},-1},{expression,NULL}},/*:177*//*178:*/ #line 582 "rules.w" {160,{{mod_scrap}},{statement,"_f"},cwebx}, {161,{{short_lbrace,mod_scrap},1},{statement,NULL},cwebx}, {162,{{mod_scrap,magic}},{declaration,"f__f"},cwebx}, {163,{{lbrace,mod_scrap,magic},1}, {declaration,"__f"},cwebx|standard_braces}, {164,{{short_lbrace,mod_scrap,magic},1},{declaration,NULL},cwebx}, {165,{{short_struct_head,mod_scrap,magic},1}, {declaration,NULL},cwebx}, {166,{{mod_scrap,magic,magic}},{expression,NULL},cwebx}, {167,{{lbrace,mod_scrap,magic,magic},1}, {expression,NULL},cwebx|standard_braces}, {168,{{short_lbrace,mod_scrap,magic,magic},1}, {expression,NULL},cwebx},/*:178*//*179:*/ #line 633 "rules.w" {160,{{mod_scrap,semi}},{statement,"__f"},compatibility}, {161,{{mod_scrap,magic}},{statement,"__f"},compatibility}, {162,{{short_lbrace,mod_scrap,semi},1}, {statement,NULL},compatibility}, {163,{{short_lbrace,mod_scrap,magic},1}, {statement,NULL},compatibility}, {164,{{mod_scrap}},{expression,NULL},compatibility}, {165,{{statement,function}},{function,"_F_"},compatibility}, {170,{{binop,binop}},{binop,"r__"},compatibility}, {171,{{unorbinop,binop}},{binop,"r__"},compatibility}, {172,{{lpar,expression,comma}},{lpar,"___p1"},compatibility},/*:179*//*180:*/ #line 686 "rules.w" {180,{{case_like,binop}},{expression,"_o_"},only_plus_plus}, {181,{{case_like,unorbinop}},{expression,"_o_"},only_plus_plus}, {182,{{case_like,unop}},{expression,NULL},only_plus_plus}, {183,{{int_like,colcol,expression}}, {expression,NULL},only_plus_plus}, {184,{{colcol,expression}},{expression,"o__"},only_plus_plus}, {185,{{int_like,colcol,int_like}}, {int_like,NULL},only_plus_plus}, {186,{{colcol,int_like}},{int_like,"o__"},only_plus_plus}, {187,{{int_like,binop,expression}}, {int_like,NULL},only_plus_plus}, {190,{{int_like,parameters}},{function_head,"_B_"},only_plus_plus}, {191,{{int_like,lpar,rpar}},{function_head,"_B_,_"},only_plus_plus}, {192,{{int_like,function_head}}, {function_head,"_ _"},only_plus_plus}, {193,{{function_head,semi}},{declaration,"!__"},only_plus_plus},/*:180*/ #line 40 "rules.w" }; int i=array_size(rule);do install_rule(&rule[--i]);while(i>0); #ifdef DEBUG if(install_failed)fatal("inconsistent grammar",0); #endif }/*:158*//*206:*/ #line 3149 "cweave.w" {char*line1=" \\input cwebxmac"; out_ptr= &out_buf[0];do*out_ptr++= *line1++;while(*line1!='\0'); if(compatibility_mode)out_ptr[-4]='c'; }/*:206*//*219:*/ #line 3352 "cweave.w" {char*p="_abcdefghijklmnopqrstuvwxyz0123456789"; int c='\1',k=2; collate[0]='\0';collate[1]=' '; do if(!isalnum(c)&&c!='_'&&c!=' ')collate[k++]=c; while(++c<=UCHAR_MAX); while((c= *p++)!='\0')collate[k++]=c; end_collate=k; }/*:219*/ #line 89 "cweave.w" if(show_banner)print(banner);/*119:*/ #line 355 "parser.w" {int i;static char*int_likes[]= {"auto","char","double","extern","float","int","long","register" ,"short","signed","static","unsigned","void"}; static char*defined_types[]= {"FILE","size_t","ptrdiff_t","wchar_t" ,"jmp_buf","sig_atomic_t","fpos_t","div_t","ldiv_t" ,"clock_t","time_t" ,"va_list" }; static char*return_likes[]= {"break","continue","goto","return"}; int int_like_nr=array_size(int_likes), defined_type_nr=array_size(defined_types), return_like_nr=array_size(return_likes); for(i=0;iharmless_message)wrap_up(); open_output_file(); phase_two(); if(history>harmless_message)wrap_up(); phase_three(); wrap_up(); return 0; }/*:3*//*20:*/ #line 307 "cweave.w" void new_id_xref(id_pointer p) {sixteen_bits f=xref_switch;xref_switch=0; if(p->ilk==reference)f=0; else if(f==0&&(unindexed(p)||length(p)==1) ||no_xref||including_header_file)return; if((p->xref->num&num_mask)==section_count)p->xref->num|=f; else {make_xref(section_count|f,xref_index(p->xref));p->xref=xref_ptr;} }/*:20*//*21:*/ #line 339 "cweave.w" void new_mod_xref(mod_pointer p) {sixteen_bits head,*q,m=section_count+mod_xref_switch; if(p->xref->num==file_flag)q= &p->xref->next; else head=xref_index(p->xref),q= &head; if(mod_xref_switch!=def_flag) {while(xnum(*q)>m) q= &xlink(*q); if(xnum(*q)==m)return; } make_xref(m,*q);mod_xref_switch=0; if(q== &head)p->xref=xref_ptr;else*q=xref_index(xref_ptr); }/*:21*//*22:*/ #line 355 "cweave.w" void set_file_flag(mod_pointer p) {if(p->xref->num!=file_flag) {make_xref(file_flag,xref_index(p->xref));p->xref=xref_ptr;} }/*:22*//*26:*/ #line 415 "cweave.w" boolean names_match(id_pointer x,char*q,int l,int ilk) {char*p=name_begin(x); if((x->ilk==ilk||ilk==normal&&reserved(x))) {while(--l>=0)if(*p++ != *q++)return false;return*p=='\0';} else return false; } void init_id_name(id_pointer p,int t) {p->ilk=t;p->xref= &xmem[0];} void init_module_name(mod_pointer p){p->xref= &xmem[0];}/*:26*//*30:*/ #line 527 "cweave.w" void copy_limbo(void) {while(loc<=limit||(finish_line(),get_line())) {eight_bits c; limit[1]='@'; while((c= *loc++)!='@') if(!(output_line_empty()&&isspace(c)))out(c); if(loc<=limit) switch(code_of(*loc++)) { case new_section:return; case ignored_text:get_control_text();break; case format:get_next();get_next();break; case char_trans:out_str("\\ATL ");break; default:err_print("! Double @ required in limbo part"); case at_sign_image:out('@'); } } }/*:30*//*31:*/ #line 561 "cweave.w" int skip_TeX(void) {char c; while(find_char()) {limit[1]='@'; while((c= *loc++)!='@'&&c!='%') if(c=='|')return c; else if(c=='\\'&& *loc!='@')++loc; if(loc<=limit) if(c=='@')return code_of(*loc++); else do if((c= *loc++)=='@'&&code_of(*loc++)>=format) return code_of(loc[-1]); while(loc=format) return finish_line(),code_of(loc[-1]); while(loc0)-- *bal; else err_print("! Extra } in comment"); break; case '/':if(*loc=='*')err_print("! Nested comment"); } if(phase==2)app_char_tok(c); }/*:35*/ #line 641 "cweave.w" if(input_has_ended) forced_out=true,err_print("! Input ended in mid-comment"); else if(!one_liner)loc+=2; done: if(*bal>0)err_print("! Too few closing braces in comment"); return forced_out?new_section:end_comment; }/*:34*//*41:*/ #line 860 "cweave.w" int get_next(void) {eight_bits c; restart: if(!find_char()){preprocessing=0;return new_section;}/*43:*/ #line 917 "cweave.w" if(preprocessing>0&&loc==limit) {preprocessing=0;return end_preproc;}/*:43*/ #line 865 "cweave.w" if((c= *loc++)=='@')/*47:*/ #line 1049 "cweave.w" if(including_header_file)goto restart; else {int cc=code_of(*loc++); switch(cc) {case ignore:goto restart; case underline:xref_switch=def_flag;goto restart; #ifdef DEBUG case trace0:case trace1:case trace2:case trace3: if(phase==2)tracing=cc;goto restart; #endif case char_trans: err_print("! `@l' only allowed in limbo");goto restart; case ASCII_code:/*48:*/ #line 1081 "cweave.w" {id_first= &mod_text[1];strncpy(id_first,"@'",2);id_loc= &id_first[2]; while((*id_loc++=c= *loc++)!='\'') {if(c=='\\') *id_loc++= *loc++; else if(c=='@'&& *loc++ !='@') {err_print("! Double @ required in strings");--loc;} if(loc>=limit){err_print("! ASCII constant didn't end");break;} } }/*:48*/ #line 1062 "cweave.w" return string; case module_name:/*49:*/ #line 1098 "cweave.w" {boolean file_module=loc[-1]=='('; cur_mod=get_module_name(); if(file_module&&phase==1&&cur_mod!=NULL)set_file_flag(cur_mod); }/*:49*/ #line 1064 "cweave.w" break; case ignored_text:get_control_text();goto restart; case verbatim:case TeX_string:get_control_text();break; case xref_roman:case xref_wildcard:case xref_typewriter: case xref_mark:case refer: if(get_control_text())goto restart; if(cc==refer)cur_id=id_lookup(id_first,id_loc,reference); else if(phase==1) cur_id=id_lookup(id_first,id_loc,cc-xref_roman+roman); } return cc; }/*:47*/ #line 868 "cweave.w" if(isspace(c)) if(preprocessing>0)return ' '; else goto restart; if(c=='L'&&(*loc=='\''|| *loc=='"')) {get_string();return string;} if(isalpha(c)||c=='_'||c>=0x80) {/*45:*/ #line 988 "cweave.w" {id_first= --loc; do c= * ++loc;while(isalnum(c)||c=='_'||c>=0x80); cur_id=id_lookup(id_first,loc,normal); }/*:45*/ #line 874 "cweave.w" return identifier;} if(isdigit(c)||c=='.'&&isdigit((eight_bits)*loc)) {/*46:*/ #line 1012 "cweave.w" {id_first=id_loc= &mod_text[1]; if(c=='0'&&(isdigit(c= *loc)||tolower(c)=='x')) {if(isdigit(c)) {*id_loc++='~'; do shift_and_store(c);while(isdigit(c)); } else {shift_and_store('^'); while(isxdigit(c))shift_and_store(c); } } else {c= * --loc; while(isdigit(c))shift_and_store(c); if(c=='.')do shift_and_store(c);while(isdigit(c)); if(tolower(c)=='e') {shift_and_store('_'); if(c=='+'||c=='-'){*id_loc++=c;c= * ++loc;} while(isdigit(c))shift_and_store(c); } } if(isalpha(c)) {*id_loc++='$';do shift_and_store(c);while(isalpha(c));} }/*:46*/ #line 876 "cweave.w" return constant;} if(c=='\''||c=='"'||(c=='<'&&preprocessing==2)) {get_string();return string;} if(c=='#'&&loc== &buffer[1]) {/*42:*/ #line 902 "cweave.w" {while(loc=7&&strncmp(loc,"include",7)==0) if(including_header_file) {loc+=7;push_input_file(true,false);goto restart;} else preprocessing=2; else preprocessing=1; }/*:42*/ #line 881 "cweave.w" return start_preproc;} if(c=='\\'&&preprocessing>0&&loc==limit) {++loc; goto restart; }/*44:*/ #line 958 "cweave.w" switch(c){ case '/':compress2('*',begin_comment); if(C_plus_plus)compress2('/',begin_comment); comp_ass_op2(div_assign);break; case '*':compress2('/',end_comment);comp_ass_op2(mul_assign);break; case '%':comp_ass_op2(mod_assign);break; case '+':compress2('+',plus_plus);comp_ass_op2(plus_assign);break; case '-':compress2('-',minus_minus);compress2('>',minus_gt); comp_ass_op2(minus_assign);break; case '=':compress2('=',eq_eq);break; case '>':compress2('=',gt_eq);comp_ass_op3('>',right_assign); compress2('>',gt_gt);break; case '<':compress2('=',lt_eq);comp_ass_op3('<',left_assign); compress2('<',lt_lt);break; case '&':compress2('&',and_and);comp_ass_op2(and_assign);break; case '^':comp_ass_op2(xor_assign);break; case '|':compress2('|',or_or);comp_ass_op2(or_assign);break; case '!':compress2('=',not_eq);break; case '.':compress3('.','.',ellipsis);break; case '#':compress2('#',sh_sh);break; case ':':if(C_plus_plus)compress2(':',colon_colon); }/*:44*/ #line 887 "cweave.w" return c; }/*:41*//*51:*/ #line 1129 "cweave.w" void phase_one(void) {phase=1;reset_input();section_count=0;/*29:*/ #line 499 "cweave.w" while(find_char()) {limit[1]='@'; while(*loc++ !='@'){} if(loc<=limit) {int c=code_of(*loc++); if(c==new_section)break; if(c==format)/*59:*/ #line 1277 "cweave.w" if(tolower((eight_bits)loc[-1])=='f') err_print("! Double @ required in limbo part"); else {id_pointer lhs; if(shift()==identifier&&(lhs=cur_id,shift()==identifier)) lhs->ilk=cur_id->ilk; else err_print("! Improper format definition"); }/*:59*/ #line 506 "cweave.w" } }/*:29*/ #line 1133 "cweave.w" while(!input_has_ended)/*52:*/ #line 1144 "cweave.w" {if(++section_count==max_sections) overflow("section number"); if(loc[-1]=='*')print_section_progress();/*56:*/ #line 1240 "cweave.w" do switch(next_control=skip_TeX()) {case underline:xref_switch=def_flag;break; case '|':C_xref(true);break; case module_name:case refer:loc-=2;get_next();break; case ignored_text:get_control_text();break; case char_trans:err_print("! `@l' only allowed in limbo");break; case xref_roman:case xref_wildcard:case xref_typewriter: case xref_mark:loc-=2;get_next();new_id_xref(cur_id); } while(next_controlilk=cur_id->ilk; } else err_print("! Improper format definition"); }/*:60*/ #line 1266 "cweave.w" outer_xref(); } else/*61:*/ #line 1311 "cweave.w" {if(push_input_file(true,true)) including_header_file=true; typedef_tracking(true); outer_xref(); typedef_tracking(false); }/*:61*//*:58*//*62:*/ #line 1328 "cweave.w" {if(next_controlhash_link)/*66:*/ #line 1416 "cweave.w" {sixteen_bits x=xref_index(name->xref),t,y=0; while(xnum(x)!=0){t=x;x=xlink(t);xlink(t)=y;y=t;} name->xref= &xmem[y]; }/*:66*/ #line 1400 "cweave.w" }/*:65*/ #line 1139 "cweave.w" }/*:51*//*54:*/ #line 1188 "cweave.w" void C_xref(boolean inner) {while(next_controlilk==typedef_like) {typedef_master=2;brace_level=par_level=0;} else if(typedef_master>0)switch(next_control) {case identifier: if(brace_level==0) if(typedef_master==2) {if(cur_id->ilk==int_like||cur_id->ilk==type_defined) typedef_master=4; else if(cur_id->ilk==struct_like)typedef_master=3; } else if(typedef_master==4) {if(cur_id->ilk==normal||cur_id->ilk==type_defined) cur_id->ilk=type_defined,typedef_master=1; } else if(typedef_master==3)typedef_master=4; break; case '{': if(brace_level++ ==0&&typedef_master==3)typedef_master=4;break; case '}':--brace_level;break; case ',': if(typedef_master==1&&par_level==0)typedef_master=4;break; case '(':++par_level;break; case ')':--par_level;break; case ';':if(brace_level==0)typedef_master=0; } if(C_plus_plus)/*110:*/ #line 2487 "cweave.w" {static boolean class_seen=false; if(class_seen) {if(next_control==identifier&&cur_id->ilk==normal) cur_id->ilk=type_defined; class_seen=false; } else if(next_control==identifier&&cur_id->ilk==struct_like) class_seen=true; }/*:110*/ #line 2480 "cweave.w" }/*:109*/ #line 1191 "cweave.w" if(next_control>=identifier&&next_control<=xref_mark) new_id_xref(cur_id); else if(next_control==module_name&&cur_mod!=NULL) mod_xref_switch=cite_flag,new_mod_xref(cur_mod); if(next_control==start_preproc&&shift()!=end_preproc &&next_control!=identifier) err_print("! Identifier should follow `#'"); else shift(); if(next_control=='|'&&inner ||next_control==begin_comment||next_control==end_comment) return; } }/*:54*//*55:*/ #line 1222 "cweave.w" void outer_xref(void) {shift(); while(next_controlllink); {boolean file_module=p->xref->num==file_flag; sixteen_bits head,*q,threshold; if(file_module)q= &p->xref->next; else head=xref_index(p->xref),q= &head; if(!complete_name(p)) {print("\n! Never completed");print_mod(p);mark_harmless();} if(xnum(*q)<=(threshold=def_flag)) {print("\n! Never defined");print_mod(p);mark_harmless();} else/*67:*/ #line 1451 "cweave.w" {sixteen_bits x= *q,y=0,t; do{t=xlink(x);xlink(x)=y;y=x;}while(xnum(x=t)>threshold); xlink(t= *q)=x;*q=y;q= &xlink(t); }/*:67*/ #line 1366 "cweave.w" if(xnum(*q)>(threshold=cite_flag))/*67:*/ #line 1451 "cweave.w" {sixteen_bits x= *q,y=0,t; do{t=xlink(x);xlink(x)=y;y=x;}while(xnum(x=t)>threshold); xlink(t= *q)=x;*q=y;q= &xlink(t); }/*:67*/ #line 1367 "cweave.w" if(xnum(*q)==(threshold=0)) {if(!file_module) {print("\n! Never used");print_mod(p);mark_harmless();} } else/*67:*/ #line 1451 "cweave.w" {sixteen_bits x= *q,y=0,t; do{t=xlink(x);xlink(x)=y;y=x;}while(xnum(x=t)>threshold); xlink(t= *q)=x;*q=y;q= &xlink(t); }/*:67*/ #line 1373 "cweave.w" if(!file_module)p->xref= &xmem[head]; } mod_check(p->rlink); } }/*:63*//*69:*/ #line 1514 "cweave.w" void phase_two(void) {phase=2;reset_input(); print_progress("\nWriting the output file..."); section_count=0;copy_limbo();finish_line(); tex_new_line(); while(!input_has_ended)/*70:*/ #line 1533 "cweave.w" {section_count++;/*71:*/ #line 1555 "cweave.w" {out('\\');out(loc[-1]=='*'?'N':loc[-1]=='~'?'n':'M'); if(loc[-1]=='*') {print_section_progress();/*72:*/ #line 1569 "cweave.w" {if(*loc=='*')++loc,out_str("-1"); else if(!isdigit((eight_bits)*loc))out('0'); else do out(*loc++);while(isdigit((eight_bits)*loc)); out(' '); }/*:72*/ #line 1558 "cweave.w" } out_sec_nr(section_count);out_str(". "); }/*:71*//*73:*/ #line 1582 "cweave.w" do switch(next_control=copy_TeX()) {case '|':typedef_master=0;do_C();break; case at_sign_image:out('@');break; case thin_space:case math_break:case ASCII_code:case line_break: case big_line_break:case no_line_break:case join:case pseudo_semi: case force_expr_open:case force_expr_close: err_print("! You can't do that in TeX text"); break; #ifdef DEBUG case trace0:case trace1:case trace2:case trace3:tracing=next_control; break; #endif case module_name:loc-=2;get_next();break; case refer:loc-=2;get_next(); if(cur_id->xref->num==0)err_print("! Undefined reference"); else list_refs(cur_id->xref,0); break; case TeX_string:err_print("! TeX string should be in C text only"); case xref_roman:case xref_wildcard:case xref_typewriter: case xref_mark:case ignored_text: get_control_text(); } while(next_controlilk!=TeX_like&&cur_id->ilk!=NULL_like) app(id_flag+id_index(cur_id)); else/*76:*/ #line 1676 "cweave.w" {char*p=name_begin(cur_id); saved_mathness=cur_id->ilk==TeX_like?no_math:yes_math; saved_code=id_flag+id_index(cur_id); app_str("\\\\{"); do{if(*p=='_')app('\\');app_tok(*p);}while(* ++p!='\0'); app('}');check_toks(10); }/*:76*/ #line 1657 "cweave.w" app('~');pack_scrap(insert,yes_math);shift(); app((cur_id->ilk==normal||cur_id->ilk==TeX_like||cur_id->ilk==NULL_like ?id_flag:res_flag )+id_index(cur_id)); check_scrap(); pack_scrap(insert,cur_id->ilk==TeX_like?no_math:yes_math); shift(); if(saved_code!=0) {app_str("\\quad(");app(saved_code);app(')'); check_scrap();pack_scrap(insert,saved_mathness); } }/*:75*/ #line 1623 "cweave.w" else if(next_control==definition)/*77:*/ #line 1693 "cweave.w" {if(shift()!=identifier) err_print("! Improper macro definition"); else {app_str("\\D$"); app(id_flag+id_index(cur_id)); if(*loc=='(') {shift(); do {app_char_tok(next_control); if(shift()!=identifier)break; app(id_flag+id_index(cur_id)); }while(shift()==','); check_toks(2); if(next_control==')'){app(')');shift();} else err_print("! Improper macro definition"); } else shift(); app('$');app(break_space);pack_scrap(insert,no_math); } }/*:77*/ #line 1624 "cweave.w" else/*78:*/ #line 1719 "cweave.w" {app_str("\\h"); pack_scrap(insert,no_math); {int save=preprocessing;preprocessing=2; while(shift()==' '){} preprocessing=save; } }/*:78*/ #line 1625 "cweave.w" if(!suppressed)outer_read(),finish_C(); else if(next_controlxref; if(x->num==file_flag)x=next_xref(x); app_str("\\4$"); app(mod_flag+mod_index(this_module)); if(x->num!=section_count+def_flag) {app_str("\\PE"); this_module=NULL; } else app_str("\\EQ"); app_str("{}$");app(force);pack_scrap(insert,no_math); } }/*:80*/ #line 1749 "cweave.w" } do {outer_read(); if(next_control==new_section)break; if(next_control==module_name)/*99:*/ #line 2220 "cweave.w" {if(cur_mod!=NULL) app(mod_flag+mod_index(cur_mod)),pack_scrap(mod_scrap,yes_math); }/*:99*/ #line 1754 "cweave.w" else err_print("! You can't do that in C text"); shift(); }while(true); finish_C(); }/*:79*//*81:*/ #line 1799 "cweave.w" {if(this_module!=NULL) {xref_pointer foot_ref=this_module->xref; if(foot_ref->num==file_flag)foot_ref=next_xref(foot_ref); foot_ref=next_xref(foot_ref); footnote(&foot_ref,def_flag); footnote(&foot_ref,cite_flag); footnote(&foot_ref,0); } }/*:81*/ #line 1544 "cweave.w" }/*82:*/ #line 1815 "cweave.w" {out_str("\\fi");finish_line();tex_new_line();}/*:82*/ #line 1546 "cweave.w" }/*:70*/ #line 1522 "cweave.w" }/*:69*//*89:*/ #line 2023 "cweave.w" void C_read(boolean inner) {while(next_controlilk;/*111:*/ #line 2547 "cweave.w" {if(typedef_master==0&&cat==typedef_like) typedef_master=2,brace_level=par_level=0; else if(typedef_master>0&&brace_level==0) if(typedef_master==2) {if(cat==int_like||cat==type_defined)typedef_master=4; else if(cat==struct_like)typedef_master=3; } else if(typedef_master==4&&cat==type_defined) cat=expression,typedef_master=1; else if(typedef_master==3)typedef_master=4; }/*:111*/ #line 2204 "cweave.w" if(cat==normal||cat==TeX_like||cat==NULL_like) {app(id_flag+id_index(p)); pack_scrap(expression ,cat==TeX_like&&!compatibility_mode?no_math:yes_math); } else {if(cat==type_defined||cat==const_like||cat==typedef_like) cat=int_like; app(res_flag+id_index(p));pack_scrap(cat,maybe_math); } }/*:98*/ #line 2077 "cweave.w" goto done; case module_name:/*99:*/ #line 2220 "cweave.w" {if(cur_mod!=NULL) app(mod_flag+mod_index(cur_mod)),pack_scrap(mod_scrap,yes_math); }/*:99*/ #line 2078 "cweave.w" goto done; case start_preproc:/*100:*/ #line 2232 "cweave.w" {app(force);app(flush_left);app_str("\\&\\#"); if(shift()==identifier) {app(res_flag+id_index(cur_id));pack_scrap(lproc,no_math);} else if(next_control==end_preproc) {pack_scrap(lproc,no_math); check_scrap();*scrap_ptr++=token_trans[end_preproc]; } else confusion("no identifier after `#'"); }/*:100*/ #line 2080 "cweave.w" goto done; case refer: err_print("! You can't use `@#' in C text"); case ignore:case begin_comment:case end_comment: case xref_roman:case xref_wildcard:case xref_typewriter: case xref_mark:goto done;/*112:*/ #line 2563 "cweave.w" case '{': if(typedef_master>0&&brace_level++ ==0&&typedef_master==3) typedef_master=4; break; case '}':if(typedef_master>0)--brace_level;break; case ',':if(typedef_master==1&&par_level==0)typedef_master=4;break; case '(':if(typedef_master>0)++par_level;break; case ')':if(typedef_master>0)--par_level;break; case ';':if(typedef_master>0&&brace_level==0)typedef_master=0;break;/*:112*/ #line 2087 "cweave.w" case '|':if(inner)goto done; } *scrap_ptr=token_trans[next_control];/*97:*/ #line 2181 "cweave.w" {if(dangling_tokens()) {app_trans(scrap_ptr);scrap_ptr->trans=text_ptr;freeze_text();} }/*:97*/ #line 2091 "cweave.w" ++scrap_ptr; done:{} }/*:92*/ #line 2026 "cweave.w" if(shift()=='|'&&inner ||next_control==begin_comment||next_control==end_comment)return; } }/*:89*//*94:*/ #line 2118 "cweave.w" void app_str(char*s){while(*s!='\0')app(*s++);}/*:94*//*101:*/ #line 2252 "cweave.w" text_pointer C_translate(void) {text_pointer p;scrap_pointer save_base=scrap_base; scrap_base=scrap_ptr; C_read(true); if(next_control!='|')err_print("! Missing `|' after C text"); p=translate(); #ifdef STAT if(scrap_ptr>max_scr_ptr)max_scr_ptr=scrap_ptr; #endif scrap_ptr=scrap_base;scrap_base=save_base;return p; }/*:101*//*102:*/ #line 2278 "cweave.w" void outer_read(void) {while(next_controlmax_text_ptr)max_text_ptr=text_ptr; if(tok_ptr>max_tok_ptr)max_tok_ptr=tok_ptr; #endif leave_block(1); }/*:104*//*105:*/ #line 2338 "cweave.w" void finish_C(void) {out_str("\\B"); make_output(translate(),outer); out_str("\\par");finish_line(); #ifdef STAT if(text_ptr>max_text_ptr)max_text_ptr=text_ptr; if(tok_ptr>max_tok_ptr)max_tok_ptr=tok_ptr; if(scrap_ptr>max_scr_ptr)max_scr_ptr=scrap_ptr; #endif leave_block(0);scrap_ptr=scrap_info; }/*:105*//*106:*/ #line 2362 "cweave.w" void footnote(xref_pointer*p,sixteen_bits flag) {if((*p)->num<=flag)return; finish_line();out('\\'); out(flag==0?'U':flag==cite_flag?'Q':'A'); *p=list_refs(*p,flag); out('.'); }/*:106*//*107:*/ #line 2378 "cweave.w" xref_pointer list_refs(xref_pointer x,sixteen_bits flag) {xref_pointer q=next_xref(x); if(q->num>flag)out('s'); out(' '); while(out_sec_nr(x->num&num_mask),x=next_xref(x),x->num>flag) if(next_xref(x)->num>flag)out_str(", "); else {out_str("\\ET"); if(x!=q)out('s'); } return x; }/*:107*//*118:*/ #line 321 "parser.w" #ifdef DEBUG void print_cat(int c) {static char*cat_name[]= {"unop","binop","op","select" ,"?","{","}","(",")","[","]",",",";",":","::","@;" ,"subscr","struct_head","short_{","short_struct_head" ,"cmp_stmt","stmt" ,"function","function_head","params","label" ,"if_head","if_else_head","do_head" ,"mod_name","declarator","decl","exp","for","do","if","else" ,"int","case","sizeof","struct","return" ,"#{","#}","insert","@[","@]" }; if(c<=max_category&&c>0)printf(cat_name[c-1]); else printf("IMPOSSIBLE"); } #endif /*:118*//*127:*/ #line 553 "parser.w" void fuse(scrap_pointer s,int n) {int cur_mathness=maybe_math,init_mathness=maybe_math;scrap_pointer p=s; check_toks(n);check_text(); do add_trans(p++)while(--n>0); s->trans=text_ptr;freeze_text(); s->mathness=(init_mathness<<2)+cur_mathness; }/*:127*//*128:*/ #line 579 "parser.w" void make_nonreserved(scrap_pointer p) {text_pointer q=p->trans;token t; while(text_flag<=(t=text_begin(q)[0])&&t=text_ptr)confusion("first_ident"); for(q=text_begin(p);qtrans); if(name==NULL)return; {sixteen_bits head=xref_index(name->xref),*r= &head;int n; while((n=xnum(*r)&num_mask)!=0&&nxref=xref_ptr;else*r=xref_index(xref_ptr); } } }/*:130*//*134:*/ #line 751 "parser.w" trie_node*get_new_trie_node(void) {if(node_no>=max_no_of_nodes) overflow("trie node"); trie_node_mem[node_no].rule=NULL; return&trie_node_mem[node_no++]; }/*:134*//*138:*/ #line 788 "parser.w" void install_rule(reduction*rule) {if((rule_mask&rule->mask)==0) {eight_bits*p=rule->lhs.category,i=0; while(ilhs.length=i; #ifdef DEBUG/*139:*/ #line 807 "parser.w" {if(rule->lhs.length<=abs(rule->lhs.context)) rule_error("\nNo scraps to replace in rule %d.\n",rule->id); for(i=0;ilhs.length;++i) if(!valid_cat(p[i])) rule_error("\nUnknown category %d in LHS of rule %d.\n",p[i],rule->id); }/*:139*//*140:*/ #line 822 "parser.w" {int c=rule->rhs.category;char*s=rule->rhs.translation; if(!valid_cat(c)) rule_error("\nUnknown category %d in RHS of rule %d.\n",c,rule->id); if(s!=NULL) {if(*s=='\0')s=rule->rhs.translation=NULL; else {i=0; do if(*s!='p')i+= *s++ =='_'; else if(++s,isdigit((eight_bits)*s))++s; else rule_error("\nDigit should follow 'p' in format of rule %d.\n" ,rule->id); while(*s!='\0'); if(i!=rule->lhs.length-abs(rule->lhs.context)) rule_error("\nCount of '_' not equal to length LHS in rule %d.\n" ,rule->id); } } }/*:140*/ #line 796 "parser.w" #endif/*141:*/ #line 846 "parser.w" {trie_node*q=trie_root; for(i=0;ilhs.length;++i) {if(no_successor(q,p[i]))set_successor(q,p[i],get_new_trie_node()); q=successor(q,p[i]); } #ifdef DEBUG if(q->rule!=NULL) rule_error("\nIdentical left-hand sides in rules %d and %d.\n" ,q->rule->id,rule->id); #endif q->rule=rule; }/*:141*//*142:*/ #line 875 "parser.w" {int k=rule->lhs.context,d; if(k<0){rule->lhs.length+=k;k=0;}else rule->lhs.length-=k; d=1-max_lhs_length+k; if(rule->lhs.category[k]==rule->rhs.category) {++d; #ifdef DEBUG if(rule->lhs.length==1) rule_error("\nNo categories change in rule %d.\n",rule->id); #endif } rule->lhs.context=k; rule->displacement=d; }/*:142*/ #line 800 "parser.w" } }/*:138*//*143:*/ #line 897 "parser.w" reduction*match(scrap_pointer p) {trie_node*q=trie_root;reduction*rule=NULL;int c; while(c=p++ ->cat,valid_cat(c)&&!no_successor(q,c)) if((q=successor(q,c))->rule!=NULL)rule=q->rule; return rule; }/*:143*//*144:*/ #line 915 "parser.w" void reduce(reduction*rule) {int k=rule->lhs.context,l=rule->lhs.length; scrap_pointer s=pp+k,p=s; char*f=rule->rhs.translation; s->cat=rule->rhs.category; if(l>1||f!=NULL) {if(f==NULL)fuse(s,l),p+=l; else/*147:*/ #line 993 "parser.w" {int cur_mathness=maybe_math,init_mathness=maybe_math; check_toks(23);check_text(); do switch(*f++) {case '+':app(indent);break; case '-':app(outdent);break; case 'p':app(opt);app(*f++);break; case 'f':set_mode(no_math);app(force);break; case 'F':set_mode(no_math);app(big_force);break; case 'b':set_mode(no_math);app(backup);break; case 'B':set_mode(no_math);app(break_space);break; case 't':set_mode(yes_math);app_str("\\a");break; case ',':set_mode(yes_math);app_str("\\,");break; case 'h':set_mode(no_math);break; case 'm':set_mode(yes_math);app(' ');break; case 'o':set_mode(yes_math);app_str("\\m");break; case 'r':set_mode(yes_math);app_str("\\MRL");break; case '!':make_underlined(p);break; case '$':make_nonreserved(p);break; case ' ':set_mode(no_math);app(' ');break; case '~':app('~');break; default:printf("%c: ",f[-1]); confusion("illegal character in format string"); case '_':add_trans(p++); } while(*f!='\0'); s->trans=text_ptr;freeze_text(); s->mathness=(init_mathness<<2)+cur_mathness; }/*:147*/ #line 925 "parser.w" if(l>1)/*145:*/ #line 942 "parser.w" {scrap_pointer q=s+1; while(p=trace2) {print("\n%3d:",rule->id); for(k=scrap_base;k'),print_cat(k->cat),putchar('<'); else print_cat(k->cat); if(tracing==trace3)putchar(math_char(right_math(k))); } print("%s\n",hi_ptrdisplacement)pp=scrap_base; else pp+=rule->displacement;/*:146*/ #line 930 "parser.w" }/*:144*//*148:*/ #line 1046 "parser.w" text_pointer translate(void) {pp=lo_ptr=hi_ptr=scrap_base; if(scrap_ptr==pp||dangling_tokens()) {check_scrap();pack_scrap(insert,no_math);}/*156:*/ #line 1196 "parser.w" #ifdef DEBUG {if(tracing>=trace2) {print("\nTracing after l.%d:\n",cur_line); if(loc>buffer+50) {printf("...");term_write(loc-50,50);} else term_write(buffer,loc-buffer); new_line(); } } #endif/*:156*//*149:*/ #line 1063 "parser.w" do {reduction*rule;/*150:*/ #line 1086 "parser.w" {scrap_pointer lo_min=pp+max_lhs_length; while(lo_ptrcat!=0) if(hi_ptr>=scrap_ptr)lo_ptr->cat=0; else {*lo_ptr++= *hi_ptr++; while(hi_ptrcat==insert) {*lo_ptr= *hi_ptr++;fuse(lo_ptr-1,2);} } }/*:150*/ #line 1067 "parser.w" if((rule=match(pp))!=NULL)reduce(rule); else {++pp;/*151:*/ #line 1111 "parser.w" if(pp->cat==end_expr||pp->cat==rproc) {int start=pp->cat-1; scrap_pointer s=pp,p=pp+1; while((--s)->cat!=start&&s>scrap_base){} if(s->cat==start) {if(start==begin_expr)s->cat=expression; else if(s==scrap_base)s->cat=insert; else--s; fuse(s,(int)(p-s));/*145:*/ #line 942 "parser.w" {scrap_pointer q=s+1; while(pcat==insert&&lo_ptr>scrap_base+1) {fuse(scrap_base,2); j=scrap_base;j->cat=j[1].cat;--lo_ptr;while(++j=scrap_base+2) {print("\nIrreducible scrap sequence at line %d in section %d:\n" ,cur_line,section_count); mark_harmless(); for(j=scrap_base;jcat),putchar(' '); print_cat(j->cat);new_line(); } } #endif/*:155*/ #line 1138 "parser.w" check_toks(1); for(j=scrap_base;jmax_stack_ptr)max_stack_ptr=stack_ptr; #endif cur_tok=text_begin(p);cur_end=text_end(p); }/*:184*//*185:*/ #line 2686 "cweave.w" void make_output(text_pointer t,mode m) {int save_next_control=next_control;id_pointer save_cur_id=cur_id; stack_pointer stack_bot=stack_ptr;token state=cancel; push_level(t);cur_mode=m; do if(cur_tok==cur_end)pop_level(); else {token a= *cur_tok%id_flag; switch(*cur_tok++ /id_flag) {/*187:*/ #line 2736 "cweave.w" case 1:/*186:*/ #line 2721 "cweave.w" {if(state>=space) if(state=space) if(state=space) if(state=space) if(state=space) if(state=break_space)break; default:/*186:*/ #line 2721 "cweave.w" {if(state>=space) if(statestack_bot);/*188:*/ #line 2750 "cweave.w" {if(cur_mode==outer&&(state==big_force||state==big_backup)) out_str("\\Y"); }/*:188*/ #line 2704 "cweave.w" next_control=save_next_control;cur_id=save_cur_id; }/*:185*//*190:*/ #line 2824 "cweave.w" void out_sec_nr(int n) {char s[6]; sprintf(s,"%d",n);out_str(s); if(section_changed(n))out_str("\\*"); }/*:190*//*191:*/ #line 2842 "cweave.w" void out_id_part(char*s,int l) {boolean b=l!=1; if(b)out('{'); while(--l>=0){if(*s=='_')out('\\');out(*s++);} if(b)out('}'); }/*:191*//*192:*/ #line 2862 "cweave.w" void out_index(id_pointer p) {char*s=name_begin(p);boolean b=s[1]!='\0'; if(compatibility_mode){out_id_full(p);return;} if(b)out('{'); out_str(s); if(b)out('}'); }/*:192*//*193:*/ #line 2874 "cweave.w" void out_keyword(id_pointer p){out_str("\\&");out_id_full(p);}/*:193*//*194:*/ #line 2888 "cweave.w" void out_identifier(id_pointer p) {int k=length(p);eight_bits*ch=(eight_bits*)name_begin(p); enum{ord,indexed,caps,single,indexed_single}kind; if(p->ilk==TeX_like||p->ilk==NULL_like) {/*195:*/ #line 2916 "cweave.w" {if(p->ilk==TeX_like)out_str("\\\\{"); out('\\');do out(*ch=='_'?'x':*ch);while(* ++ch!='\0'); if(p->ilk==TeX_like)out('}'); }/*:195*/ #line 2894 "cweave.w" return; } if(!compatibility_mode) {do--k;while(isdigit((eight_bits)ch[k])); ++k; }/*196:*/ #line 2928 "cweave.w" if(k==1){out(' ');kind=length(p)==1?single:indexed_single;} else {int i=k; while(--i>=0)if(!isupper(ch[i])&&!isdigit(ch[i])&&ch[i]!='_')break; kind=i<0?caps:kxref;boolean file_module=x->num==file_flag; if(file_module)x=next_xref(x); out_str("\\X"); if(x->num>=def_flag) {out_sec_nr(x->num-def_flag); if(phase==3) while(x=next_xref(x),x->num>=def_flag) out_str(", "),out_sec_nr(x->num-def_flag); } else out('0'); out(':');if(file_module)out_str("\\.{");/*198:*/ #line 2983 "cweave.w" {char*k=name_begin(name),c; while((c= *k++)!='\0') {if(file_module){if(strchr(" \\#%$^{}~&_",c)!=NULL)out('\\');} if(c=='@'&& *k++ !='@')/*199:*/ #line 3000 "cweave.w" {print("\n! Illegal control code in module name");print_mod(name); mark_error(); }/*:199*/ #line 2987 "cweave.w" if(file_module||c!='|')out(c); else {char*save_loc=loc,*save_limit=limit;/*200:*/ #line 3021 "cweave.w" {char delimiter='\0'; next_control= *limit++='|';loc=limit; do if((c= *k++)=='\0')/*202:*/ #line 3065 "cweave.w" {print("\n! C text in module name didn't end");print_mod(name); mark_error(); if(delimiter!='\0')*limit++=delimiter; *limit++='|'; if(limit> &buffer[long_buf_size-2]) fatal("fix that first, you sneaky devil"); break; }/*:202*/ #line 3025 "cweave.w" else {*limit++=c;/*201:*/ #line 3044 "cweave.w" {if(c=='@') {if((*limit++= *k++)=='\''&&delimiter=='\0') delimiter='\''; } else if(c=='\\'&&delimiter!='\0') {char d= *limit++= *k++; if(d=='\0')--k,limit-=2; } else if(c=='\''||c=='"') if(delimiter=='\0')delimiter=c; else if(delimiter==c)delimiter='\0'; }/*:201*/ #line 3029 "cweave.w" } while(c!='|'||delimiter!='\0'); *limit=' '; }/*:200*/ #line 2991 "cweave.w" do_C();loc=save_loc;*(limit=save_limit)=' '; } } }/*:198*/ #line 2973 "cweave.w" if(file_module)out_str("}"); out_str("\\X"); return x; }/*:197*//*204:*/ #line 3107 "cweave.w" void flush_buffer(char*b,boolean percent) {int j=(int)(b-out_line); if(!percent)while(j>0&&out_line[j-1]==' ')--j; fprintf(tex_file,"%.*s",j,out_line); if(percent)tex_putc('%'); tex_new_line(); {char*p=out_line; while(bout_line)flush_buffer(k,c!=' ');else/*210:*/ #line 3201 "cweave.w" if(count==0)flush_buffer(out_ptr-1,true); else if(count>=2)flush_buffer (&out_line[count&=~1]==out_buf_end?out_buf_end-2:&out_line[count],true); else {print("\n! Line had to be broken (output l.%d):\n",out_line_nr); term_write(out_line,out_ptr-out_line);new_line();mark_harmless(); flush_buffer(out_ptr,false); }/*:210*/ #line 3185 "cweave.w" }/*:209*//*211:*/ #line 3223 "cweave.w" void phase_three(void) {finish_line(); if(no_xref)out_str("\\endcodemode\\vfill\\end"); else {phase=3;print_progress("\nWriting the index..."); typedef_tracking(false); if(change_exists) {/*214:*/ #line 3282 "cweave.w" {int k=0;boolean first=true; out_str("\\ch "); while(khash_link) if(name->ilk!=reference&&name->xref->num!=0) {c=name_begin(name)[0];c=tolower(c); ilink(name)=bucket[c];bucket[c]=name; } }/*:222*/ #line 3396 "cweave.w" unbucket(1); while(sort_ptr>sort_info) {eight_bits depth=(--sort_ptr)->depth; id_pointer name=sort_ptr->head; if(ilink(name)==NULL||depth==infinity)/*226:*/ #line 3486 "cweave.w" do {out_str("\\@");/*227:*/ #line 3499 "cweave.w" switch(name->ilk) {case normal:case NULL_like:out('m');out_identifier(name);break; case TeX_like:out('h');out_identifier(name);break; case roman:out('h');out_index(name);break; case wildcard:out_str("h\\9");out_index(name);break; case typewriter:out_str("h\\.");out_index(name);break; default:out('h');out_keyword(name); }/*:227*//*228:*/ #line 3513 "cweave.w" {xref_pointer x=name->xref; do {sixteen_bits n=x->num; out_str(", "); if(nnum!=0); out('.');finish_line(); }/*:228*/ #line 3490 "cweave.w" }while((name=ilink(name))!=NULL);/*:226*/ #line 3404 "cweave.w" else {/*223:*/ #line 3441 "cweave.w" do {eight_bits c=tolower((eight_bits)name_begin(name)[depth]); id_pointer next_name=ilink(name); ilink(name)=bucket[c];bucket[c]=name;name=next_name; } while(name!=NULL);/*:223*/ #line 3406 "cweave.w" unbucket(depth+1); } } }/*:221*/ #line 3236 "cweave.w" if(triple_file_output)/*213:*/ #line 3271 "cweave.w" {finish_line();fclose(tex_file); if((tex_file=fopen(scn_file_name,"w"))==NULL) fatal("! Cannot open \"%s\" as output file",scn_file_name); }/*:213*/ #line 3238 "cweave.w" else{out_str("\\fin"),finish_line();}/*231:*/ #line 3553 "cweave.w" list_modules(root);/*:231*/ #line 3240 "cweave.w" if(!triple_file_output) {out_str("\\con"); if(even_out_pages)out_str("even"); } } finish_line();fclose(tex_file); print_progress("\nDone.\n"); check_complete(); }/*:211*//*225:*/ #line 3467 "cweave.w" void unbucket(eight_bits d) {int i=end_collate; while(--i>=0)if(bucket[collate[i]]!=NULL) {if(sort_ptr>=sort_info_end) overflow("sorting"); sort_ptr->depth=i==0?infinity:d; sort_ptr++ ->head=bucket[collate[i]]; bucket[collate[i]]=NULL; #ifdef STAT if(sort_ptr>max_sort_ptr)max_sort_ptr=sort_ptr; #endif } }/*:225*//*230:*/ #line 3538 "cweave.w" void list_modules(mod_pointer p) {if(p!=NULL) {list_modules(p->llink); out_str("\\@$"); leave_block(0);scrap_ptr=scrap_info; {xref_pointer x=out_module_name(p);out('$'); footnote(&x,cite_flag);footnote(&x,0); } finish_line(); list_modules(p->rlink); } }/*:230*//*232:*/ #line 3561 "cweave.w" #ifdef STAT void print_stats() {print("\nMemory usage statistics:\n"); report("identifier",id_index(id_ptr),max_idents); report("module name",mod_index(mod_ptr),max_modules); report("byte",byte_ptr-byte_mem,max_bytes); report("cross-reference",xref_ptr-xmem,max_refs-1); printf("Parsing:\n"); report("scrap",max_scr_ptr-scrap_info,max_scraps); report("text",max_text_ptr-text_mem,max_texts); report("token",max_tok_ptr-tok_mem,max_toks); report("trie node",node_no,max_no_of_nodes); report("level",max_stack_ptr-stack,stack_size); printf("Sorting:\n"); report("level",max_sort_ptr-sort_info,sort_stack_size); } #endif/*:232*/