home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / cweb / cwebsrc / CWEB / src / c / cweave < prev   
Encoding:
Text File  |  1996-10-30  |  82.0 KB  |  4,203 lines

  1. /*1:*/
  2. #line 66 "cweave.w"
  3. /*6:*/
  4. #line 35 "common.h"
  5.  
  6. #include <stdio.h>
  7.  
  8. /*:6*//*38:*/
  9. #line 644 "cweave.w"
  10.  
  11. #include <ctype.h> 
  12. #include <stdlib.h> 
  13.  
  14. /*:38*/
  15. #line 66 "cweave.w"
  16.  
  17. #define banner "This is CWEAVE (Version 3.4)\n" \
  18.  
  19. #define max_bytes 90000 \
  20.  
  21. #define max_names 4000 \
  22.  
  23. #define max_sections 2000
  24. #define hash_size 353
  25. #define buf_size 100
  26. #define longest_name 1000
  27. #define long_buf_size (buf_size+longest_name) 
  28. #define line_length 80 \
  29.  
  30. #define max_refs 20000
  31. #define max_toks 20000 \
  32.  
  33. #define max_texts 4000 \
  34.  
  35. #define max_scraps 2000
  36. #define stack_size 400 \
  37.  
  38. #define ctangle 0
  39. #define cweave 1 \
  40.  
  41. #define and_and 04
  42. #define lt_lt 020
  43. #define gt_gt 021
  44. #define plus_plus 013
  45. #define minus_minus 01
  46. #define minus_gt 031
  47. #define not_eq 032
  48. #define lt_eq 034
  49. #define gt_eq 035
  50. #define eq_eq 036
  51. #define or_or 037
  52. #define dot_dot_dot 016
  53. #define colon_colon 06
  54. #define period_ast 026
  55. #define minus_gt_ast 027 \
  56.  
  57. #define xisalpha(c) (isalpha(c) &&((eight_bits) c<0200) ) 
  58. #define xisdigit(c) (isdigit(c) &&((eight_bits) c<0200) ) 
  59. #define xisspace(c) (isspace(c) &&((eight_bits) c<0200) ) 
  60. #define xislower(c) (islower(c) &&((eight_bits) c<0200) ) 
  61. #define xisupper(c) (isupper(c) &&((eight_bits) c<0200) ) 
  62. #define xisxdigit(c) (isxdigit(c) &&((eight_bits) c<0200) )  \
  63.  
  64. #define length(c) (c+1) ->byte_start-(c) ->byte_start
  65. #define print_id(c) term_write((c) ->byte_start,length((c) ) ) 
  66. #define llink link
  67. #define rlink dummy.Rlink
  68. #define root name_dir->rlink \
  69.  
  70. #define chunk_marker 0 \
  71.  
  72. #define spotless 0
  73. #define harmless_message 1
  74. #define error_message 2
  75. #define fatal_message 3
  76. #define mark_harmless {if(history==spotless) history= harmless_message;}
  77. #define mark_error history= error_message
  78. #define confusion(s) fatal("! This can't happen: ",s)  \
  79.  
  80. #define max_file_name_length 60
  81. #define cur_file file[include_depth]
  82. #define cur_file_name file_name[include_depth]
  83. #define web_file_name file_name[0]
  84. #define cur_line line[include_depth] \
  85.  
  86. #define show_banner flags['b']
  87. #define show_progress flags['p']
  88. #define show_happiness flags['h'] \
  89.  
  90. #define update_terminal fflush(stdout) 
  91. #define new_line putchar('\n') 
  92. #define putxchar putchar
  93. #define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) 
  94. #define C_printf(c,a) fprintf(C_file,c,a) 
  95. #define C_putc(c) putc(c,C_file)  \
  96.  
  97. #define ilk dummy.Ilk
  98. #define normal 0
  99. #define roman 1
  100. #define wildcard 2
  101. #define typewriter 3
  102. #define abnormal(a) (a->ilk>typewriter) 
  103. #define custom 4
  104. #define unindexed(a) (a->ilk>custom) 
  105. #define quoted 5
  106. #define else_like 26
  107. #define public_like 40
  108. #define operator_like 41
  109. #define new_like 42
  110. #define catch_like 43
  111. #define for_like 45
  112. #define do_like 46
  113. #define if_like 47
  114. #define raw_rpar 48
  115. #define raw_unorbin 49
  116. #define const_like 50
  117. #define raw_int 51
  118. #define int_like 52
  119. #define case_like 53
  120. #define sizeof_like 54
  121. #define struct_like 55
  122. #define typedef_like 56
  123. #define define_like 57 \
  124.  
  125. #define file_flag (3*cite_flag) 
  126. #define def_flag (2*cite_flag) 
  127. #define cite_flag 10240
  128. #define xref equiv_or_xref \
  129.  
  130. #define append_xref(c) if(xref_ptr==xmem_end) overflow("cross-reference") ; \
  131. else(++xref_ptr) ->num= c;
  132. #define no_xref (flags['x']==0) 
  133. #define make_xrefs flags['x']
  134. #define is_tiny(p) ((p+1) ->byte_start==(p) ->byte_start+1)  \
  135.  
  136. #define ignore 00
  137. #define verbatim 02
  138. #define begin_short_comment 03
  139. #define begin_comment '\t'
  140. #define underline '\n'
  141. #define noop 0177
  142. #define xref_roman 0203
  143. #define xref_wildcard 0204
  144. #define xref_typewriter 0205
  145. #define TeX_string 0206
  146. #define ord 0207
  147. #define join 0210
  148. #define thin_space 0211
  149. #define math_break 0212
  150. #define line_break 0213
  151. #define big_line_break 0214
  152. #define no_line_break 0215
  153. #define pseudo_semi 0216
  154. #define macro_arg_open 0220
  155. #define macro_arg_close 0221
  156. #define trace 0222
  157. #define translit_code 0223
  158. #define output_defs_code 0224
  159. #define format_code 0225
  160. #define definition 0226
  161. #define begin_C 0227
  162. #define section_name 0230
  163. #define new_section 0231 \
  164.  
  165. #define constant 0200
  166. #define string 0201
  167. #define identifier 0202 \
  168.  
  169. #define isxalpha(c) ((c) =='_') 
  170. #define ishigh(c) ((eight_bits) (c) >0177)  \
  171.  \
  172.  
  173. #define left_preproc ord
  174. #define right_preproc 0217 \
  175.  
  176. #define compress(c) if(loc++<=limit) return(c)  \
  177.  
  178. #define c_line_write(c) fflush(active_file) ,fwrite(out_buf+1,sizeof(char) ,c,active_file) 
  179. #define tex_putc(c) putc(c,active_file) 
  180. #define tex_new_line putc('\n',active_file) 
  181. #define tex_printf(c) fprintf(active_file,c)  \
  182.  
  183. #define out(c) {if(out_ptr>=out_buf_end) break_out() ;*(++out_ptr) = c;} \
  184.  
  185. #define app_tok(c) {if(tok_ptr+2>tok_mem_end) overflow("token") ;*(tok_ptr++) = c;} \
  186.  
  187. #define exp 1
  188. #define unop 2
  189. #define binop 3
  190. #define unorbinop 4 \
  191.  
  192. #define cast 5
  193. #define question 6
  194. #define lbrace 7
  195. #define rbrace 8
  196. #define decl_head 9
  197. #define comma 10
  198. #define lpar 11
  199. #define rpar 12
  200. #define prelangle 13
  201. #define prerangle 14
  202. #define langle 15
  203. #define colcol 18
  204. #define base 19
  205. #define decl 20
  206. #define struct_head 21
  207. #define stmt 23
  208. #define function 24
  209. #define fn_decl 25
  210. #define semi 27
  211. #define colon 28
  212. #define tag 29
  213. #define if_head 30
  214. #define else_head 31
  215. #define if_clause 32
  216. #define lproc 35
  217. #define rproc 36
  218. #define insert 37
  219. #define section_scrap 38
  220. #define dead 39
  221. #define begin_arg 58
  222. #define end_arg 59 \
  223.  
  224. #define math_rel 0206
  225. #define big_cancel 0210
  226. #define cancel 0211
  227. #define indent 0212
  228. #define outdent 0213
  229. #define opt 0214
  230. #define backup 0215
  231. #define break_space 0216
  232. #define force 0217
  233. #define big_force 0220
  234. #define preproc_line 0221 \
  235.  
  236. #define quoted_char 0222 \
  237.  
  238. #define end_translation 0223
  239. #define inserted 0224 \
  240.  
  241. #define trans trans_plus.Trans \
  242.  
  243. #define id_flag 10240
  244. #define res_flag 2*id_flag
  245. #define section_flag 3*id_flag
  246. #define tok_flag 4*id_flag
  247. #define inner_tok_flag 5*id_flag \
  248.  
  249. #define no_math 2
  250. #define yes_math 1
  251. #define maybe_math 0
  252. #define big_app2(a) big_app1(a) ;big_app1(a+1) 
  253. #define big_app3(a) big_app2(a) ;big_app1(a+2) 
  254. #define big_app4(a) big_app3(a) ;big_app1(a+3) 
  255. #define app(a) *(tok_ptr++) = a
  256. #define app1(a) *(tok_ptr++) = tok_flag+(int) ((a) ->trans-tok_start)  \
  257.  
  258. #define cat1 (pp+1) ->cat
  259. #define cat2 (pp+2) ->cat
  260. #define cat3 (pp+3) ->cat
  261. #define lhs_not_simple (pp->cat!=semi&&pp->cat!=raw_int&&pp->cat!=raw_unorbin \
  262. &&pp->cat!=raw_rpar&&pp->cat!=const_like)  \
  263.  
  264. #define no_ident_found 0 \
  265.  
  266. #define force_lines flags['f']
  267. #define freeze_text *(++text_ptr) = tok_ptr \
  268.  
  269. #define safe_tok_incr 20
  270. #define safe_text_incr 10
  271. #define safe_scrap_incr 10 \
  272.  
  273. #define app_scrap(c,b) { \
  274. (++scrap_ptr) ->cat= (c) ;scrap_ptr->trans= text_ptr; \
  275. scrap_ptr->mathness= 5*(b) ; \
  276. freeze_text; \
  277. } \
  278.  
  279. #define inner 0
  280. #define outer 1 \
  281.  
  282. #define cur_end cur_state.end_field
  283. #define cur_tok cur_state.tok_field
  284. #define cur_mode cur_state.mode_field
  285. #define init_stack stack_ptr= stack;cur_mode= outer \
  286.  
  287. #define res_word 0201
  288. #define section_code 0200 \
  289.  
  290. #define save_position save_line= out_line;save_place= out_ptr
  291. #define emit_space_if_needed if(save_line!=out_line||save_place!=out_ptr)  \
  292. out_str("\\Y") ; \
  293. space_checked= 1 \
  294.  \
  295.  
  296. #define depth cat
  297. #define head trans_plus.Head
  298. #define sort_pointer scrap_pointer
  299. #define sort_ptr scrap_ptr
  300. #define max_sorts max_scraps \
  301.  
  302. #define infinity 255 \
  303.  
  304.  
  305. #line 67 "cweave.w"
  306.  
  307. /*5:*/
  308. #line 29 "common.h"
  309.  
  310. typedef short boolean;
  311. typedef char unsigned eight_bits;
  312. extern boolean program;
  313. extern int phase;
  314.  
  315. /*:5*//*7:*/
  316. #line 57 "common.h"
  317.  
  318. char section_text[longest_name+1];
  319. char*section_text_end= section_text+longest_name;
  320. char*id_first;
  321. char*id_loc;
  322.  
  323. /*:7*//*8:*/
  324. #line 72 "common.h"
  325.  
  326. extern char buffer[];
  327. extern char*buffer_end;
  328. extern char*loc;
  329. extern char*limit;
  330.  
  331. /*:8*//*9:*/
  332. #line 87 "common.h"
  333.  
  334. typedef struct name_info{
  335. char*byte_start;
  336. struct name_info*link;
  337. union{
  338. struct name_info*Rlink;
  339.  
  340. char Ilk;
  341. }dummy;
  342. char*equiv_or_xref;
  343. }name_info;
  344. typedef name_info*name_pointer;
  345. typedef name_pointer*hash_pointer;
  346. extern char byte_mem[];
  347. extern char*byte_mem_end;
  348. extern name_info name_dir[];
  349. extern name_pointer name_dir_end;
  350. extern name_pointer name_ptr;
  351. extern char*byte_ptr;
  352. extern name_pointer hash[];
  353. extern hash_pointer hash_end;
  354. extern hash_pointer h;
  355. extern name_pointer id_lookup();
  356. extern name_pointer section_lookup();
  357. extern void print_section_name(),sprint_section_name();
  358.  
  359. /*:9*//*10:*/
  360. #line 122 "common.h"
  361.  
  362. extern history;
  363. extern err_print();
  364. extern wrap_up();
  365. extern void fatal();
  366. extern void overflow();
  367.  
  368. /*:10*//*11:*/
  369. #line 137 "common.h"
  370.  
  371. extern include_depth;
  372. extern FILE*file[];
  373. extern FILE*change_file;
  374. extern char C_file_name[];
  375. extern char tex_file_name[];
  376. extern char idx_file_name[];
  377. extern char scn_file_name[];
  378. extern char file_name[][max_file_name_length];
  379.  
  380. extern char change_file_name[];
  381. extern line[];
  382. extern change_line;
  383. extern boolean input_has_ended;
  384. extern boolean changing;
  385. extern boolean web_file_open;
  386. extern reset_input();
  387. extern get_line();
  388. extern check_complete();
  389.  
  390. /*:11*//*12:*/
  391. #line 158 "common.h"
  392.  
  393. typedef unsigned short sixteen_bits;
  394. extern sixteen_bits section_count;
  395. extern boolean changed_section[];
  396. extern boolean change_pending;
  397. extern boolean print_where;
  398.  
  399. /*:12*//*13:*/
  400. #line 170 "common.h"
  401.  
  402. extern int argc;
  403. extern char**argv;
  404. extern boolean flags[];
  405.  
  406. /*:13*//*14:*/
  407. #line 182 "common.h"
  408.  
  409. extern FILE*C_file;
  410. extern FILE*tex_file;
  411. extern FILE*idx_file;
  412. extern FILE*scn_file;
  413. extern FILE*active_file;
  414.  
  415. /*:14*//*15:*/
  416. #line 191 "common.h"
  417.  
  418. extern void common_init();
  419. #line 140 "cweave.w"
  420.  
  421. /*:15*/
  422. #line 68 "cweave.w"
  423.  
  424. /*18:*/
  425. #line 222 "cweave.w"
  426.  
  427. typedef struct xref_info{
  428. sixteen_bits num;
  429. struct xref_info*xlink;
  430. }xref_info;
  431. typedef xref_info*xref_pointer;
  432.  
  433. /*:18*//*24:*/
  434. #line 332 "cweave.w"
  435.  
  436. typedef sixteen_bits token;
  437. typedef token*token_pointer;
  438. typedef token_pointer*text_pointer;
  439.  
  440. /*:24*//*103:*/
  441. #line 2012 "cweave.w"
  442.  
  443. typedef struct{
  444. eight_bits cat;
  445. eight_bits mathness;
  446. union{
  447. text_pointer Trans;
  448. /*231:*/
  449. #line 4257 "cweave.w"
  450.  
  451. name_pointer Head;
  452.  
  453. /*:231*/
  454. #line 2018 "cweave.w"
  455.  
  456. }trans_plus;
  457. }scrap;
  458. typedef scrap*scrap_pointer;
  459.  
  460. /*:103*//*185:*/
  461. #line 3412 "cweave.w"
  462. typedef int mode;
  463. typedef struct{
  464. token_pointer end_field;
  465. token_pointer tok_field;
  466. boolean mode_field;
  467. }output_state;
  468. typedef output_state*stack_pointer;
  469.  
  470. /*:185*/
  471. #line 69 "cweave.w"
  472.  
  473. /*17:*/
  474. #line 197 "cweave.w"
  475.  
  476. boolean change_exists;
  477.  
  478. /*:17*//*19:*/
  479. #line 229 "cweave.w"
  480.  
  481. xref_info xmem[max_refs];
  482. xref_pointer xmem_end= xmem+max_refs-1;
  483. xref_pointer xref_ptr;
  484. sixteen_bits xref_switch,section_xref_switch;
  485.  
  486. /*:19*//*25:*/
  487. #line 342 "cweave.w"
  488.  
  489. token tok_mem[max_toks];
  490. token_pointer tok_mem_end= tok_mem+max_toks-1;
  491. token_pointer tok_start[max_texts];
  492. token_pointer tok_ptr;
  493. text_pointer text_ptr;
  494. text_pointer tok_start_end= tok_start+max_texts-1;
  495. token_pointer max_tok_ptr;
  496. text_pointer max_text_ptr;
  497.  
  498. /*:25*//*31:*/
  499. #line 521 "cweave.w"
  500.  
  501. eight_bits ccode[256];
  502.  
  503. /*:31*//*37:*/
  504. #line 640 "cweave.w"
  505.  
  506. name_pointer cur_section;
  507. char cur_section_char;
  508.  
  509. /*:37*//*41:*/
  510. #line 693 "cweave.w"
  511.  
  512. boolean preprocessing= 0;
  513.  
  514. /*:41*//*43:*/
  515. #line 706 "cweave.w"
  516.  
  517. boolean sharp_include_line= 0;
  518.  
  519. /*:43*//*58:*/
  520. #line 980 "cweave.w"
  521.  
  522. eight_bits next_control;
  523.  
  524. /*:58*//*68:*/
  525. #line 1136 "cweave.w"
  526.  
  527. name_pointer lhs,rhs;
  528.  
  529. /*:68*//*73:*/
  530. #line 1219 "cweave.w"
  531.  
  532. xref_pointer cur_xref;
  533. boolean an_output;
  534.  
  535. /*:73*//*77:*/
  536. #line 1261 "cweave.w"
  537.  
  538. char out_buf[line_length+1];
  539. char*out_ptr;
  540. char*out_buf_end= out_buf+line_length;
  541. int out_line;
  542.  
  543. /*:77*//*97:*/
  544. #line 1670 "cweave.w"
  545.  
  546. char cat_name[256][12];
  547. eight_bits cat_index;
  548.  
  549. /*:97*//*104:*/
  550. #line 2025 "cweave.w"
  551.  
  552. scrap scrap_info[max_scraps];
  553. scrap_pointer scrap_info_end= scrap_info+max_scraps-1;
  554. scrap_pointer pp;
  555. scrap_pointer scrap_base;
  556. scrap_pointer scrap_ptr;
  557. scrap_pointer lo_ptr;
  558. scrap_pointer hi_ptr;
  559. scrap_pointer max_scr_ptr;
  560.  
  561. /*:104*//*108:*/
  562. #line 2184 "cweave.w"
  563.  
  564. int cur_mathness,init_mathness;
  565.  
  566. /*:108*//*167:*/
  567. #line 2962 "cweave.w"
  568.  
  569. int tracing;
  570.  
  571. /*:167*//*186:*/
  572. #line 3425 "cweave.w"
  573.  
  574. output_state cur_state;
  575. output_state stack[stack_size];
  576. stack_pointer stack_ptr;
  577. stack_pointer stack_end= stack+stack_size-1;
  578. stack_pointer max_stack_ptr;
  579.  
  580. /*:186*//*190:*/
  581. #line 3475 "cweave.w"
  582.  
  583. name_pointer cur_name;
  584.  
  585. /*:190*//*206:*/
  586. #line 3831 "cweave.w"
  587.  
  588. int save_line;
  589. char*save_place;
  590. int sec_depth;
  591. boolean space_checked;
  592. boolean format_visible;
  593. boolean doing_format= 0;
  594. boolean group_found= 0;
  595.  
  596. /*:206*//*215:*/
  597. #line 4014 "cweave.w"
  598.  
  599. name_pointer this_section;
  600.  
  601. /*:215*//*226:*/
  602. #line 4198 "cweave.w"
  603.  
  604. sixteen_bits k_section;
  605.  
  606. /*:226*//*228:*/
  607. #line 4224 "cweave.w"
  608.  
  609. name_pointer bucket[256];
  610. name_pointer next_name;
  611. name_pointer blink[max_names];
  612.  
  613. /*:228*//*232:*/
  614. #line 4267 "cweave.w"
  615.  
  616. eight_bits cur_depth;
  617. char*cur_byte;
  618. sixteen_bits cur_val;
  619. sort_pointer max_sort_ptr;
  620.  
  621. /*:232*//*234:*/
  622. #line 4279 "cweave.w"
  623.  
  624. eight_bits collate[102+128];
  625.  
  626.  
  627. /*:234*//*243:*/
  628. #line 4432 "cweave.w"
  629.  
  630. xref_pointer next_xref,this_xref;
  631.  
  632.  
  633. /*:243*/
  634. #line 70 "cweave.w"
  635.  
  636. /*2:*/
  637. #line 78 "cweave.w"
  638.  
  639. extern int strlen();
  640. extern int strcmp();
  641. extern char*strcpy();
  642. extern int strncmp();
  643. extern char*strncpy();
  644.  
  645. /*:2*//*34:*/
  646. #line 562 "cweave.w"
  647.  
  648. void skip_limbo();
  649.  
  650. /*:34*//*39:*/
  651. #line 655 "cweave.w"
  652.  
  653. eight_bits get_next();
  654.  
  655. /*:39*//*55:*/
  656. #line 933 "cweave.w"
  657.  
  658. void skip_restricted();
  659.  
  660. /*:55*//*59:*/
  661. #line 986 "cweave.w"
  662.  
  663. void phase_one();
  664.  
  665. /*:59*//*62:*/
  666. #line 1038 "cweave.w"
  667.  
  668. void C_xref();
  669.  
  670. /*:62*//*64:*/
  671. #line 1066 "cweave.w"
  672.  
  673. void outer_xref();
  674.  
  675. /*:64*//*74:*/
  676. #line 1227 "cweave.w"
  677.  
  678. void section_check();
  679.  
  680. /*:74*//*83:*/
  681. #line 1363 "cweave.w"
  682.  
  683. void break_out();
  684.  
  685. /*:83*//*91:*/
  686. #line 1506 "cweave.w"
  687.  
  688. int copy_comment();
  689.  
  690. /*:91*//*114:*/
  691. #line 2388 "cweave.w"
  692.  
  693. void underline_xref();
  694.  
  695. /*:114*//*180:*/
  696. #line 3289 "cweave.w"
  697.  
  698. void app_cur_id();
  699.  
  700. /*:180*//*193:*/
  701. #line 3544 "cweave.w"
  702.  
  703. void make_output();
  704.  
  705. /*:193*//*204:*/
  706. #line 3804 "cweave.w"
  707.  
  708. void phase_two();
  709.  
  710. /*:204*//*211:*/
  711. #line 3927 "cweave.w"
  712.  
  713. void finish_C();
  714.  
  715. /*:211*//*220:*/
  716. #line 4098 "cweave.w"
  717.  
  718. void footnote();
  719.  
  720. /*:220*//*224:*/
  721. #line 4147 "cweave.w"
  722.  
  723. void phase_three();
  724.  
  725. /*:224*//*236:*/
  726. #line 4327 "cweave.w"
  727.  
  728. void unbucket();
  729.  
  730. /*:236*//*245:*/
  731. #line 4447 "cweave.w"
  732.  
  733. void section_print();
  734.  
  735. /*:245*/
  736. #line 71 "cweave.w"
  737.  
  738.  
  739. /*:1*//*3:*/
  740. #line 93 "cweave.w"
  741.  
  742. int main(ac,av)
  743. int ac;
  744. char**av;
  745. {
  746. argc= ac;argv= av;
  747. program= cweave;
  748. make_xrefs= force_lines= 1;
  749. common_init();
  750. /*20:*/
  751. #line 243 "cweave.w"
  752.  
  753. xref_ptr= xmem;name_dir->xref= (char*)xmem;xref_switch= 0;section_xref_switch= 0;
  754. xmem->num= 0;
  755.  
  756. /*:20*//*26:*/
  757. #line 352 "cweave.w"
  758.  
  759. tok_ptr= tok_mem+1;text_ptr= tok_start+1;tok_start[0]= tok_mem+1;
  760. tok_start[1]= tok_mem+1;
  761. max_tok_ptr= tok_mem+1;max_text_ptr= tok_start+1;
  762.  
  763. /*:26*//*32:*/
  764. #line 524 "cweave.w"
  765.  
  766. {int c;for(c= 0;c<256;c++)ccode[c]= 0;}
  767. ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']
  768. = ccode['*']= new_section;
  769. ccode['@']= '@';
  770. ccode['=']= verbatim;
  771. ccode['d']= ccode['D']= definition;
  772. ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;
  773. ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;
  774. ccode['t']= ccode['T']= TeX_string;
  775. ccode['l']= ccode['L']= translit_code;
  776. ccode['q']= ccode['Q']= noop;
  777. ccode['h']= ccode['H']= output_defs_code;
  778. ccode['&']= join;ccode['<']= ccode['(']= section_name;
  779. ccode['!']= underline;ccode['^']= xref_roman;
  780. ccode[':']= xref_wildcard;ccode['.']= xref_typewriter;ccode[',']= thin_space;
  781. ccode['|']= math_break;ccode['/']= line_break;ccode['#']= big_line_break;
  782. ccode['+']= no_line_break;ccode[';']= pseudo_semi;
  783. ccode['[']= macro_arg_open;ccode[']']= macro_arg_close;
  784. ccode['\'']= ord;
  785. /*33:*/
  786. #line 550 "cweave.w"
  787.  
  788. ccode['0']= ccode['1']= ccode['2']= trace;
  789.  
  790. /*:33*/
  791. #line 544 "cweave.w"
  792.  
  793.  
  794. /*:32*//*52:*/
  795. #line 888 "cweave.w"
  796. section_text[0]= ' ';
  797.  
  798. /*:52*//*80:*/
  799. #line 1330 "cweave.w"
  800.  
  801. out_ptr= out_buf+1;out_line= 1;active_file= tex_file;
  802. *out_ptr= 'c';tex_printf("\\input cwebma");
  803.  
  804. /*:80*//*82:*/
  805. #line 1356 "cweave.w"
  806.  
  807. out_buf[0]= '\\';
  808.  
  809. /*:82*//*98:*/
  810. #line 1674 "cweave.w"
  811.  
  812. for(cat_index= 0;cat_index<255;cat_index++)
  813. strcpy(cat_name[cat_index],"UNKNOWN");
  814. strcpy(cat_name[exp],"exp");
  815. strcpy(cat_name[unop],"unop");
  816. strcpy(cat_name[binop],"binop");
  817. strcpy(cat_name[unorbinop],"unorbinop");
  818. strcpy(cat_name[cast],"cast");
  819. strcpy(cat_name[question],"?");
  820. strcpy(cat_name[lbrace],"{");
  821. strcpy(cat_name[rbrace],"}");
  822. strcpy(cat_name[decl_head],"decl_head");
  823. strcpy(cat_name[comma],",");
  824. strcpy(cat_name[lpar],"(");
  825. strcpy(cat_name[rpar],")");
  826. strcpy(cat_name[prelangle],"<");
  827. strcpy(cat_name[prerangle],">");
  828. strcpy(cat_name[langle],"\\<");
  829. strcpy(cat_name[colcol],"::");
  830. strcpy(cat_name[base],"\\:");
  831. strcpy(cat_name[decl],"decl");
  832. strcpy(cat_name[struct_head],"struct_head");
  833. strcpy(cat_name[stmt],"stmt");
  834. strcpy(cat_name[function],"function");
  835. strcpy(cat_name[fn_decl],"fn_decl");
  836. strcpy(cat_name[else_like],"else_like");
  837. strcpy(cat_name[semi],";");
  838. strcpy(cat_name[colon],":");
  839. strcpy(cat_name[tag],"tag");
  840. strcpy(cat_name[if_head],"if_head");
  841. strcpy(cat_name[else_head],"else_head");
  842. strcpy(cat_name[if_clause],"if()");
  843. strcpy(cat_name[lproc],"#{");
  844. strcpy(cat_name[rproc],"#}");
  845. strcpy(cat_name[insert],"insert");
  846. strcpy(cat_name[section_scrap],"section");
  847. strcpy(cat_name[dead],"@d");
  848. strcpy(cat_name[public_like],"public");
  849. strcpy(cat_name[operator_like],"operator");
  850. strcpy(cat_name[new_like],"new");
  851. strcpy(cat_name[catch_like],"catch");
  852. strcpy(cat_name[for_like],"for");
  853. strcpy(cat_name[do_like],"do");
  854. strcpy(cat_name[if_like],"if");
  855. strcpy(cat_name[raw_rpar],")?");
  856. strcpy(cat_name[raw_unorbin],"unorbinop?");
  857. strcpy(cat_name[const_like],"const");
  858. strcpy(cat_name[raw_int],"raw");
  859. strcpy(cat_name[int_like],"int");
  860. strcpy(cat_name[case_like],"case");
  861. strcpy(cat_name[sizeof_like],"sizeof");
  862. strcpy(cat_name[struct_like],"struct");
  863. strcpy(cat_name[typedef_like],"typedef");
  864. strcpy(cat_name[define_like],"define");
  865. strcpy(cat_name[begin_arg],"@[");
  866. strcpy(cat_name[end_arg],"@]");
  867. strcpy(cat_name[0],"zero");
  868.  
  869. /*:98*//*105:*/
  870. #line 2035 "cweave.w"
  871.  
  872. scrap_base= scrap_info+1;
  873. max_scr_ptr= scrap_ptr= scrap_info;
  874.  
  875. /*:105*//*187:*/
  876. #line 3432 "cweave.w"
  877.  
  878. max_stack_ptr= stack;
  879.  
  880. /*:187*//*233:*/
  881. #line 4273 "cweave.w"
  882.  
  883. max_sort_ptr= scrap_info;
  884.  
  885. /*:233*//*235:*/
  886. #line 4292 "cweave.w"
  887.  
  888. collate[0]= 0;
  889. strcpy(collate+1," \1\2\3\4\5\6\7\10\11\12\13\14\15\16\17");
  890.  
  891. strcpy(collate+17,"\20\21\22\23\24\25\26\27\30\31\32\33\34\35\36\37");
  892.  
  893. strcpy(collate+33,"!\42#$%&'()*+,-./:;<=>?@[\\]^`{|}~_");
  894.  
  895. strcpy(collate+65,"abcdefghijklmnopqrstuvwxyz0123456789");
  896.  
  897. strcpy(collate+101,"\200\201\202\203\204\205\206\207\210\211\212\213\214\215\216\217");
  898.  
  899. strcpy(collate+117,"\220\221\222\223\224\225\226\227\230\231\232\233\234\235\236\237");
  900.  
  901. strcpy(collate+133,"\240\241\242\243\244\245\246\247\250\251\252\253\254\255\256\257");
  902.  
  903. strcpy(collate+149,"\260\261\262\263\264\265\266\267\270\271\272\273\274\275\276\277");
  904.  
  905. strcpy(collate+165,"\300\301\302\303\304\305\306\307\310\311\312\313\314\315\316\317");
  906.  
  907. strcpy(collate+181,"\320\321\322\323\324\325\326\327\330\331\332\333\334\335\336\337");
  908.  
  909. strcpy(collate+197,"\340\341\342\343\344\345\346\347\350\351\352\353\354\355\356\357");
  910.  
  911. strcpy(collate+213,"\360\361\362\363\364\365\366\367\370\371\372\373\374\375\376\377");
  912.  
  913.  
  914. /*:235*/
  915. #line 102 "cweave.w"
  916. ;
  917. if(show_banner)printf(banner);
  918. /*28:*/
  919. #line 392 "cweave.w"
  920.  
  921. id_lookup("asm",NULL,sizeof_like);
  922. id_lookup("auto",NULL,int_like);
  923. id_lookup("break",NULL,case_like);
  924. id_lookup("case",NULL,case_like);
  925. id_lookup("catch",NULL,catch_like);
  926. id_lookup("char",NULL,raw_int);
  927. id_lookup("class",NULL,struct_like);
  928. id_lookup("clock_t",NULL,raw_int);
  929. id_lookup("const",NULL,const_like);
  930. id_lookup("continue",NULL,case_like);
  931. id_lookup("default",NULL,case_like);
  932. id_lookup("define",NULL,define_like);
  933. id_lookup("defined",NULL,sizeof_like);
  934. id_lookup("delete",NULL,sizeof_like);
  935. id_lookup("div_t",NULL,raw_int);
  936. id_lookup("do",NULL,do_like);
  937. id_lookup("double",NULL,raw_int);
  938. id_lookup("elif",NULL,if_like);
  939. id_lookup("else",NULL,else_like);
  940. id_lookup("endif",NULL,if_like);
  941. id_lookup("enum",NULL,struct_like);
  942. id_lookup("error",NULL,if_like);
  943. id_lookup("extern",NULL,int_like);
  944. id_lookup("FILE",NULL,raw_int);
  945. id_lookup("float",NULL,raw_int);
  946. id_lookup("for",NULL,for_like);
  947. id_lookup("fpos_t",NULL,raw_int);
  948. id_lookup("friend",NULL,int_like);
  949. id_lookup("goto",NULL,case_like);
  950. id_lookup("if",NULL,if_like);
  951. id_lookup("ifdef",NULL,if_like);
  952. id_lookup("ifndef",NULL,if_like);
  953. id_lookup("include",NULL,if_like);
  954. id_lookup("inline",NULL,int_like);
  955. id_lookup("int",NULL,raw_int);
  956. id_lookup("jmp_buf",NULL,raw_int);
  957. id_lookup("ldiv_t",NULL,raw_int);
  958. id_lookup("line",NULL,if_like);
  959. id_lookup("long",NULL,raw_int);
  960. id_lookup("new",NULL,new_like);
  961. id_lookup("NULL",NULL,quoted);
  962. id_lookup("offsetof",NULL,sizeof_like);
  963. id_lookup("operator",NULL,operator_like);
  964. id_lookup("pragma",NULL,if_like);
  965. id_lookup("private",NULL,public_like);
  966. id_lookup("protected",NULL,public_like);
  967. id_lookup("ptrdiff_t",NULL,raw_int);
  968. id_lookup("public",NULL,public_like);
  969. id_lookup("register",NULL,int_like);
  970. id_lookup("return",NULL,case_like);
  971. id_lookup("short",NULL,raw_int);
  972. id_lookup("sig_atomic_t",NULL,raw_int);
  973. id_lookup("signed",NULL,raw_int);
  974. id_lookup("size_t",NULL,raw_int);
  975. id_lookup("sizeof",NULL,sizeof_like);
  976. id_lookup("static",NULL,int_like);
  977. id_lookup("struct",NULL,struct_like);
  978. id_lookup("switch",NULL,for_like);
  979. id_lookup("template",NULL,int_like);
  980. id_lookup("TeX",NULL,custom);
  981. id_lookup("this",NULL,quoted);
  982. id_lookup("throw",NULL,case_like);
  983. id_lookup("time_t",NULL,raw_int);
  984. id_lookup("try",NULL,else_like);
  985. id_lookup("typedef",NULL,typedef_like);
  986. id_lookup("undef",NULL,if_like);
  987. id_lookup("union",NULL,struct_like);
  988. id_lookup("unsigned",NULL,raw_int);
  989. id_lookup("va_dcl",NULL,decl);
  990. id_lookup("va_list",NULL,raw_int);
  991. id_lookup("virtual",NULL,int_like);
  992. id_lookup("void",NULL,raw_int);
  993. id_lookup("volatile",NULL,const_like);
  994. id_lookup("wchar_t",NULL,raw_int);
  995. id_lookup("while",NULL,for_like);
  996.  
  997. /*:28*/
  998. #line 104 "cweave.w"
  999. ;
  1000. phase_one();
  1001. phase_two();
  1002. phase_three();
  1003. return wrap_up();
  1004. }
  1005.  
  1006. /*:3*//*21:*/
  1007. #line 262 "cweave.w"
  1008.  
  1009. void
  1010. new_xref(p)
  1011. name_pointer p;
  1012. {
  1013. xref_pointer q;
  1014. sixteen_bits m,n;
  1015. if(no_xref)return;
  1016. if((unindexed(p)||is_tiny(p))&&xref_switch==0)return;
  1017. m= section_count+xref_switch;xref_switch= 0;q= (xref_pointer)p->xref;
  1018. if(q!=xmem){
  1019. n= q->num;
  1020. if(n==m||n==m+def_flag)return;
  1021. else if(m==n+def_flag){
  1022. q->num= m;return;
  1023. }
  1024. }
  1025. append_xref(m);xref_ptr->xlink= q;p->xref= (char*)xref_ptr;
  1026. }
  1027.  
  1028. /*:21*//*22:*/
  1029. #line 293 "cweave.w"
  1030.  
  1031. void
  1032. new_section_xref(p)
  1033. name_pointer p;
  1034. {
  1035. xref_pointer q,r;
  1036. q= (xref_pointer)p->xref;r= xmem;
  1037. if(q>xmem)
  1038. while(q->num>section_xref_switch){r= q;q= q->xlink;}
  1039. if(r->num==section_count+section_xref_switch)
  1040. return;
  1041. append_xref(section_count+section_xref_switch);
  1042. xref_ptr->xlink= q;section_xref_switch= 0;
  1043. if(r==xmem)p->xref= (char*)xref_ptr;
  1044. else r->xlink= xref_ptr;
  1045. }
  1046.  
  1047. /*:22*//*23:*/
  1048. #line 313 "cweave.w"
  1049.  
  1050. void
  1051. set_file_flag(p)
  1052. name_pointer p;
  1053. {
  1054. xref_pointer q;
  1055. q= (xref_pointer)p->xref;
  1056. if(q->num==file_flag)return;
  1057. append_xref(file_flag);
  1058. xref_ptr->xlink= q;
  1059. p->xref= (char*)xref_ptr;
  1060. }
  1061.  
  1062. /*:23*//*27:*/
  1063. #line 358 "cweave.w"
  1064.  
  1065. int names_match(p,first,l,t)
  1066. name_pointer p;
  1067. char*first;
  1068. int l;
  1069. eight_bits t;
  1070. {
  1071. if(length(p)!=l)return 0;
  1072. if(p->ilk!=t&&!(t==normal&&abnormal(p)))return 0;
  1073. return!strncmp(first,p->byte_start,l);
  1074. }
  1075.  
  1076. void
  1077. init_p(p,t)
  1078. name_pointer p;
  1079. eight_bits t;
  1080. {
  1081. p->ilk= t;p->xref= (char*)xmem;
  1082. }
  1083.  
  1084. void
  1085. init_node(p)
  1086. name_pointer p;
  1087. {
  1088. p->xref= (char*)xmem;
  1089. }
  1090.  
  1091. /*:27*//*35:*/
  1092. #line 565 "cweave.w"
  1093.  
  1094. void
  1095. skip_limbo(){
  1096. while(1){
  1097. if(loc>limit&&get_line()==0)return;
  1098. *(limit+1)= '@';
  1099. while(*loc!='@')loc++;
  1100. if(loc++<=limit){int c= ccode[(eight_bits)*loc++];
  1101. if(c==new_section)return;
  1102. if(c==noop)skip_restricted();
  1103. else if(c==format_code)/*71:*/
  1104. #line 1180 "cweave.w"
  1105.  
  1106. {
  1107. if(get_next()!=identifier)
  1108. err_print("! Missing left identifier of @s");
  1109.  
  1110. else{
  1111. lhs= id_lookup(id_first,id_loc,normal);
  1112. if(get_next()!=identifier)
  1113. err_print("! Missing right identifier of @s");
  1114.  
  1115. else{
  1116. rhs= id_lookup(id_first,id_loc,normal);
  1117. lhs->ilk= rhs->ilk;
  1118. }
  1119. }
  1120. }
  1121.  
  1122. /*:71*/
  1123. #line 575 "cweave.w"
  1124. ;
  1125. }
  1126. }
  1127. }
  1128.  
  1129. /*:35*//*36:*/
  1130. #line 587 "cweave.w"
  1131.  
  1132. unsigned
  1133. skip_TeX()
  1134. {
  1135. while(1){
  1136. if(loc>limit&&get_line()==0)return(new_section);
  1137. *(limit+1)= '@';
  1138. while(*loc!='@'&&*loc!='|')loc++;
  1139. if(*loc++=='|')return('|');
  1140. if(loc<=limit)return(ccode[(eight_bits)*(loc++)]);
  1141. }
  1142. }
  1143.  
  1144. /*:36*//*40:*/
  1145. #line 658 "cweave.w"
  1146.  
  1147. eight_bits
  1148. get_next()
  1149. {eight_bits c;
  1150. while(1){
  1151. /*45:*/
  1152. #line 717 "cweave.w"
  1153.  
  1154. while(loc==limit-1&&preprocessing&&*loc=='\\')
  1155. if(get_line()==0)return(new_section);
  1156. if(loc>=limit&&preprocessing){
  1157. preprocessing= sharp_include_line= 0;
  1158. return(right_preproc);
  1159. }
  1160.  
  1161. /*:45*/
  1162. #line 663 "cweave.w"
  1163. ;
  1164. if(loc>limit&&get_line()==0)return(new_section);
  1165. c= *(loc++);
  1166. if(xisdigit(c)||c=='\\'||c=='.')/*48:*/
  1167. #line 775 "cweave.w"
  1168. {
  1169. id_first= id_loc= section_text+1;
  1170. if(*(loc-1)=='\\'){*id_loc++= '~';
  1171. while(xisdigit(*loc))*id_loc++= *loc++;}
  1172. else if(*(loc-1)=='0'){
  1173. if(*loc=='x'||*loc=='X'){*id_loc++= '^';loc++;
  1174. while(xisxdigit(*loc))*id_loc++= *loc++;}
  1175. else if(xisdigit(*loc)){*id_loc++= '~';
  1176. while(xisdigit(*loc))*id_loc++= *loc++;}
  1177. else goto dec;
  1178. }
  1179. else{
  1180. if(*(loc-1)=='.'&&!xisdigit(*loc))goto mistake;
  1181. dec:*id_loc++= *(loc-1);
  1182. while(xisdigit(*loc)||*loc=='.')*id_loc++= *loc++;
  1183. if(*loc=='e'||*loc=='E'){
  1184. *id_loc++= '_';loc++;
  1185. if(*loc=='+'||*loc=='-')*id_loc++= *loc++;
  1186. while(xisdigit(*loc))*id_loc++= *loc++;
  1187. }
  1188. }
  1189. while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
  1190. ||*loc=='f'||*loc=='F'){
  1191. *id_loc++= '$';*id_loc++= toupper(*loc);loc++;
  1192. }
  1193. return(constant);
  1194. }
  1195.  
  1196. /*:48*/
  1197. #line 666 "cweave.w"
  1198.  
  1199. else if(c=='\''||c=='"'||(c=='L'&&(*loc=='\''||*loc=='"'))
  1200. ||(c=='<'&&sharp_include_line==1))
  1201. /*49:*/
  1202. #line 808 "cweave.w"
  1203. {
  1204. char delim= c;
  1205. id_first= section_text+1;
  1206. id_loc= section_text;
  1207. if(delim=='\''&&*(loc-2)=='@'){*++id_loc= '@';*++id_loc= '@';}
  1208. *++id_loc= delim;
  1209. if(delim=='L'){
  1210. delim= *loc++;*++id_loc= delim;
  1211. }
  1212. if(delim=='<')delim= '>';
  1213. while(1){
  1214. if(loc>=limit){
  1215. if(*(limit-1)!='\\'){
  1216. err_print("! String didn't end");loc= limit;break;
  1217.  
  1218. }
  1219. if(get_line()==0){
  1220. err_print("! Input ended in middle of string");loc= buffer;break;
  1221.  
  1222. }
  1223. }
  1224. if((c= *loc++)==delim){
  1225. if(++id_loc<=section_text_end)*id_loc= c;
  1226. break;
  1227. }
  1228. if(c=='\\')if(loc>=limit)continue;
  1229. else if(++id_loc<=section_text_end){
  1230. *id_loc= '\\';c= *loc++;
  1231. }
  1232. if(++id_loc<=section_text_end)*id_loc= c;
  1233. }
  1234. if(id_loc>=section_text_end){
  1235. printf("\n! String too long: ");
  1236.  
  1237. term_write(section_text+1,25);
  1238. printf("...");mark_error;
  1239. }
  1240. id_loc++;
  1241. return(string);
  1242. }
  1243.  
  1244. /*:49*/
  1245. #line 669 "cweave.w"
  1246.  
  1247. else if(xisalpha(c)||isxalpha(c)||ishigh(c))
  1248. /*47:*/
  1249. #line 758 "cweave.w"
  1250. {
  1251. id_first= --loc;
  1252. while(isalpha(*++loc)||isdigit(*loc)||isxalpha(*loc)||ishigh(*loc));
  1253. id_loc= loc;return(identifier);
  1254. }
  1255.  
  1256. /*:47*/
  1257. #line 671 "cweave.w"
  1258.  
  1259. else if(c=='@')/*50:*/
  1260. #line 852 "cweave.w"
  1261. {
  1262. c= *loc++;
  1263. switch(ccode[(eight_bits)c]){
  1264. case translit_code:err_print("! Use @l in limbo only");continue;
  1265.  
  1266. case underline:xref_switch= def_flag;continue;
  1267. case trace:tracing= c-'0';continue;
  1268. case xref_roman:case xref_wildcard:case xref_typewriter:
  1269. case noop:case TeX_string:c= ccode[c];skip_restricted();return(c);
  1270. case section_name:
  1271. /*51:*/
  1272. #line 872 "cweave.w"
  1273. {
  1274. char*k;
  1275. cur_section_char= *(loc-1);
  1276. /*53:*/
  1277. #line 890 "cweave.w"
  1278.  
  1279. k= section_text;
  1280. while(1){
  1281. if(loc>limit&&get_line()==0){
  1282. err_print("! Input ended in section name");
  1283.  
  1284. loc= buffer+1;break;
  1285. }
  1286. c= *loc;
  1287. /*54:*/
  1288. #line 914 "cweave.w"
  1289.  
  1290. if(c=='@'){
  1291. c= *(loc+1);
  1292. if(c=='>'){
  1293. loc+= 2;break;
  1294. }
  1295. if(ccode[(eight_bits)c]==new_section){
  1296. err_print("! Section name didn't end");break;
  1297.  
  1298. }
  1299. if(c!='@'){
  1300. err_print("! Control codes are forbidden in section name");break;
  1301.  
  1302. }
  1303. *(++k)= '@';loc++;
  1304. }
  1305.  
  1306. /*:54*/
  1307. #line 899 "cweave.w"
  1308. ;
  1309. loc++;if(k<section_text_end)k++;
  1310. if(xisspace(c)){
  1311. c= ' ';if(*(k-1)==' ')k--;
  1312. }
  1313. *k= c;
  1314. }
  1315. if(k>=section_text_end){
  1316. printf("\n! Section name too long: ");
  1317.  
  1318. term_write(section_text+1,25);
  1319. printf("...");mark_harmless;
  1320. }
  1321. if(*k==' '&&k>section_text)k--;
  1322.  
  1323. /*:53*/
  1324. #line 875 "cweave.w"
  1325. ;
  1326. if(k-section_text>3&&strncmp(k-2,"...",3)==0)
  1327. cur_section= section_lookup(section_text+1,k-3,1);
  1328. else cur_section= section_lookup(section_text+1,k,0);
  1329. xref_switch= 0;return(section_name);
  1330. }
  1331.  
  1332. /*:51*/
  1333. #line 862 "cweave.w"
  1334. ;
  1335. case verbatim:/*57:*/
  1336. #line 961 "cweave.w"
  1337. {
  1338. id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
  1339. while(*loc!='@'||*(loc+1)!='>')loc++;
  1340. if(loc>=limit)err_print("! Verbatim string didn't end");
  1341.  
  1342. id_loc= loc;loc+= 2;
  1343. return(verbatim);
  1344. }
  1345.  
  1346. /*:57*/
  1347. #line 863 "cweave.w"
  1348. ;
  1349. case ord:/*49:*/
  1350. #line 808 "cweave.w"
  1351. {
  1352. char delim= c;
  1353. id_first= section_text+1;
  1354. id_loc= section_text;
  1355. if(delim=='\''&&*(loc-2)=='@'){*++id_loc= '@';*++id_loc= '@';}
  1356. *++id_loc= delim;
  1357. if(delim=='L'){
  1358. delim= *loc++;*++id_loc= delim;
  1359. }
  1360. if(delim=='<')delim= '>';
  1361. while(1){
  1362. if(loc>=limit){
  1363. if(*(limit-1)!='\\'){
  1364. err_print("! String didn't end");loc= limit;break;
  1365.  
  1366. }
  1367. if(get_line()==0){
  1368. err_print("! Input ended in middle of string");loc= buffer;break;
  1369.  
  1370. }
  1371. }
  1372. if((c= *loc++)==delim){
  1373. if(++id_loc<=section_text_end)*id_loc= c;
  1374. break;
  1375. }
  1376. if(c=='\\')if(loc>=limit)continue;
  1377. else if(++id_loc<=section_text_end){
  1378. *id_loc= '\\';c= *loc++;
  1379. }
  1380. if(++id_loc<=section_text_end)*id_loc= c;
  1381. }
  1382. if(id_loc>=section_text_end){
  1383. printf("\n! String too long: ");
  1384.  
  1385. term_write(section_text+1,25);
  1386. printf("...");mark_error;
  1387. }
  1388. id_loc++;
  1389. return(string);
  1390. }
  1391.  
  1392. /*:49*/
  1393. #line 864 "cweave.w"
  1394. ;
  1395. default:return(ccode[(eight_bits)c]);
  1396. }
  1397. }
  1398.  
  1399. /*:50*/
  1400. #line 672 "cweave.w"
  1401.  
  1402. else if(xisspace(c))continue;
  1403. if(c=='#'&&loc==buffer+1)/*42:*/
  1404. #line 696 "cweave.w"
  1405. {
  1406. preprocessing= 1;
  1407. /*44:*/
  1408. #line 709 "cweave.w"
  1409.  
  1410. while(loc<=buffer_end-7&&xisspace(*loc))loc++;
  1411. if(loc<=buffer_end-6&&strncmp(loc,"include",7)==0)sharp_include_line= 1;
  1412.  
  1413. /*:44*/
  1414. #line 698 "cweave.w"
  1415. ;
  1416. return(left_preproc);
  1417. }
  1418.  
  1419. /*:42*/
  1420. #line 674 "cweave.w"
  1421. ;
  1422. mistake:/*46:*/
  1423. #line 734 "cweave.w"
  1424.  
  1425. switch(c){
  1426. case'/':if(*loc=='*'){compress(begin_comment);}
  1427. else if(*loc=='/')compress(begin_short_comment);break;
  1428. case'+':if(*loc=='+')compress(plus_plus);break;
  1429. case'-':if(*loc=='-'){compress(minus_minus);}
  1430. else if(*loc=='>')if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
  1431. else compress(minus_gt);break;
  1432. case'.':if(*loc=='*'){compress(period_ast);}
  1433. else if(*loc=='.'&&*(loc+1)=='.'){
  1434. loc++;compress(dot_dot_dot);
  1435. }
  1436. break;
  1437. case':':if(*loc==':')compress(colon_colon);break;
  1438. case'=':if(*loc=='=')compress(eq_eq);break;
  1439. case'>':if(*loc=='='){compress(gt_eq);}
  1440. else if(*loc=='>')compress(gt_gt);break;
  1441. case'<':if(*loc=='='){compress(lt_eq);}
  1442. else if(*loc=='<')compress(lt_lt);break;
  1443. case'&':if(*loc=='&')compress(and_and);break;
  1444. case'|':if(*loc=='|')compress(or_or);break;
  1445. case'!':if(*loc=='=')compress(not_eq);break;
  1446. }
  1447.  
  1448. /*:46*/
  1449. #line 675 "cweave.w"
  1450.  
  1451. return(c);
  1452. }
  1453. }
  1454.  
  1455. /*:40*//*56:*/
  1456. #line 936 "cweave.w"
  1457.  
  1458. void
  1459. skip_restricted()
  1460. {
  1461. id_first= loc;*(limit+1)= '@';
  1462. false_alarm:
  1463. while(*loc!='@')loc++;
  1464. id_loc= loc;
  1465. if(loc++>limit){
  1466. err_print("! Control text didn't end");loc= limit;
  1467.  
  1468. }
  1469. else{
  1470. if(*loc=='@'&&loc<=limit){loc++;goto false_alarm;}
  1471. if(*loc++!='>')
  1472. err_print("! Control codes are forbidden in control text");
  1473.  
  1474. }
  1475. }
  1476.  
  1477. /*:56*//*60:*/
  1478. #line 989 "cweave.w"
  1479.  
  1480. void
  1481. phase_one(){
  1482. phase= 1;reset_input();section_count= 0;
  1483. skip_limbo();change_exists= 0;
  1484. while(!input_has_ended)
  1485. /*61:*/
  1486. #line 1002 "cweave.w"
  1487.  
  1488. {
  1489. if(++section_count==max_sections)overflow("section number");
  1490. changed_section[section_count]= changing;
  1491.  
  1492. if(*(loc-1)=='*'&&show_progress){
  1493. printf("*%d",section_count);
  1494. update_terminal;
  1495. }
  1496. /*66:*/
  1497. #line 1093 "cweave.w"
  1498.  
  1499. while(1){
  1500. switch(next_control= skip_TeX()){
  1501. case translit_code:err_print("! Use @l in limbo only");continue;
  1502.  
  1503. case underline:xref_switch= def_flag;continue;
  1504. case trace:tracing= *(loc-1)-'0';continue;
  1505. case'|':C_xref(section_name);break;
  1506. case xref_roman:case xref_wildcard:case xref_typewriter:
  1507. case noop:case section_name:
  1508. loc-= 2;next_control= get_next();
  1509. if(next_control>=xref_roman&&next_control<=xref_typewriter){
  1510. /*67:*/
  1511. #line 1113 "cweave.w"
  1512.  
  1513. {
  1514. char*src= id_first,*dst= id_first;
  1515. while(src<id_loc){
  1516. if(*src=='@')src++;
  1517. *dst++= *src++;
  1518. }
  1519. id_loc= dst;
  1520. while(dst<src)*dst++= ' ';
  1521. }
  1522.  
  1523. /*:67*/
  1524. #line 1105 "cweave.w"
  1525.  
  1526. new_xref(id_lookup(id_first,id_loc,next_control-identifier));
  1527. }
  1528. break;
  1529. }
  1530. if(next_control>=format_code)break;
  1531. }
  1532.  
  1533. /*:66*/
  1534. #line 1011 "cweave.w"
  1535. ;
  1536. /*69:*/
  1537. #line 1141 "cweave.w"
  1538.  
  1539. while(next_control<=definition){
  1540. if(next_control==definition){
  1541. xref_switch= def_flag;
  1542. next_control= get_next();
  1543. }else/*70:*/
  1544. #line 1155 "cweave.w"
  1545. {
  1546. next_control= get_next();
  1547. if(next_control==identifier){
  1548. lhs= id_lookup(id_first,id_loc,normal);lhs->ilk= normal;
  1549. if(xref_switch)new_xref(lhs);
  1550. next_control= get_next();
  1551. if(next_control==identifier){
  1552. rhs= id_lookup(id_first,id_loc,normal);
  1553. lhs->ilk= rhs->ilk;
  1554. if(unindexed(lhs)){
  1555. xref_pointer q,r= NULL;
  1556. for(q= (xref_pointer)lhs->xref;q>xmem;q= q->xlink)
  1557. if(q->num<def_flag)
  1558. if(r)r->xlink= q->xlink;
  1559. else lhs->xref= (char*)q->xlink;
  1560. else r= q;
  1561. }
  1562. next_control= get_next();
  1563. }
  1564. }
  1565. }
  1566.  
  1567. /*:70*/
  1568. #line 1146 "cweave.w"
  1569. ;
  1570. outer_xref();
  1571. }
  1572.  
  1573. /*:69*/
  1574. #line 1012 "cweave.w"
  1575. ;
  1576. /*72:*/
  1577. #line 1200 "cweave.w"
  1578.  
  1579. if(next_control<=section_name){
  1580. if(next_control==begin_C)section_xref_switch= 0;
  1581. else{
  1582. section_xref_switch= def_flag;
  1583. if(cur_section_char=='('&&cur_section!=name_dir)
  1584. set_file_flag(cur_section);
  1585. }
  1586. do{
  1587. if(next_control==section_name&&cur_section!=name_dir)
  1588. new_section_xref(cur_section);
  1589. next_control= get_next();outer_xref();
  1590. }while(next_control<=section_name);
  1591. }
  1592.  
  1593. /*:72*/
  1594. #line 1013 "cweave.w"
  1595. ;
  1596. if(changed_section[section_count])change_exists= 1;
  1597. }
  1598.  
  1599. /*:61*/
  1600. #line 995 "cweave.w"
  1601. ;
  1602. changed_section[section_count]= change_exists;
  1603.  
  1604. phase= 2;
  1605. /*76:*/
  1606. #line 1253 "cweave.w"
  1607. section_check(root)
  1608.  
  1609. /*:76*/
  1610. #line 999 "cweave.w"
  1611. ;
  1612. }
  1613.  
  1614. /*:60*//*63:*/
  1615. #line 1041 "cweave.w"
  1616.  
  1617. void
  1618. C_xref(spec_ctrl)
  1619. eight_bits spec_ctrl;
  1620. {
  1621. name_pointer p;
  1622. while(next_control<format_code||next_control==spec_ctrl){
  1623. if(next_control>=identifier&&next_control<=xref_typewriter){
  1624. if(next_control>identifier)/*67:*/
  1625. #line 1113 "cweave.w"
  1626.  
  1627. {
  1628. char*src= id_first,*dst= id_first;
  1629. while(src<id_loc){
  1630. if(*src=='@')src++;
  1631. *dst++= *src++;
  1632. }
  1633. id_loc= dst;
  1634. while(dst<src)*dst++= ' ';
  1635. }
  1636.  
  1637. /*:67*/
  1638. #line 1049 "cweave.w"
  1639.  
  1640. p= id_lookup(id_first,id_loc,next_control-identifier);new_xref(p);
  1641. }
  1642. if(next_control==section_name){
  1643. section_xref_switch= cite_flag;
  1644. new_section_xref(cur_section);
  1645. }
  1646. next_control= get_next();
  1647. if(next_control=='|'||next_control==begin_comment||
  1648. next_control==begin_short_comment)return;
  1649. }
  1650. }
  1651.  
  1652. /*:63*//*65:*/
  1653. #line 1069 "cweave.w"
  1654.  
  1655. void
  1656. outer_xref()
  1657. {
  1658. int bal;
  1659. while(next_control<format_code)
  1660. if(next_control!=begin_comment&&next_control!=begin_short_comment)
  1661. C_xref(ignore);
  1662. else{
  1663. boolean is_long_comment= (next_control==begin_comment);
  1664. bal= copy_comment(is_long_comment,1);next_control= '|';
  1665. while(bal>0){
  1666. C_xref(section_name);
  1667. if(next_control=='|')bal= copy_comment(is_long_comment,bal);
  1668. else bal= 0;
  1669. }
  1670. }
  1671. }
  1672.  
  1673. /*:65*//*75:*/
  1674. #line 1230 "cweave.w"
  1675.  
  1676. void
  1677. section_check(p)
  1678. name_pointer p;
  1679. {
  1680. if(p){
  1681. section_check(p->llink);
  1682. cur_xref= (xref_pointer)p->xref;
  1683. if(cur_xref->num==file_flag){an_output= 1;cur_xref= cur_xref->xlink;}
  1684. else an_output= 0;
  1685. if(cur_xref->num<def_flag){
  1686. printf("\n! Never defined: <");print_section_name(p);putchar('>');mark_harmless;
  1687.  
  1688. }
  1689. while(cur_xref->num>=cite_flag)cur_xref= cur_xref->xlink;
  1690. if(cur_xref==xmem&&!an_output){
  1691. printf("\n! Never used: <");print_section_name(p);putchar('>');mark_harmless;
  1692.  
  1693. }
  1694. section_check(p->rlink);
  1695. }
  1696. }
  1697.  
  1698. /*:75*//*78:*/
  1699. #line 1283 "cweave.w"
  1700.  
  1701. void
  1702. flush_buffer(b,per_cent,carryover)
  1703. char*b;
  1704. boolean per_cent,carryover;
  1705. {
  1706. char*j;j= b;
  1707. if(!per_cent)
  1708. while(j>out_buf&&*j==' ')j--;
  1709. c_line_write(j-out_buf);
  1710. if(per_cent)tex_putc('%');
  1711. tex_new_line;out_line++;
  1712. if(carryover)
  1713. while(j>out_buf)
  1714. if(*j--=='%'&&(j==out_buf||*j!='\\')){
  1715. *b--= '%';break;
  1716. }
  1717. if(b<out_ptr)strncpy(out_buf+1,b+1,out_ptr-b);
  1718. out_ptr-= b-out_buf;
  1719. }
  1720.  
  1721. /*:78*//*79:*/
  1722. #line 1312 "cweave.w"
  1723.  
  1724. void
  1725. finish_line()
  1726. {
  1727. char*k;
  1728. if(out_ptr>out_buf)flush_buffer(out_ptr,0,0);
  1729. else{
  1730. for(k= buffer;k<=limit;k++)
  1731. if(!(xisspace(*k)))return;
  1732. flush_buffer(out_buf,0,0);
  1733. }
  1734. }
  1735.  
  1736. /*:79*//*81:*/
  1737. #line 1344 "cweave.w"
  1738.  
  1739. void
  1740. out_str(s)
  1741. char*s;
  1742. {
  1743. while(*s)out(*s++);
  1744. }
  1745.  
  1746. /*:81*//*84:*/
  1747. #line 1366 "cweave.w"
  1748.  
  1749. void
  1750. break_out()
  1751. {
  1752. char*k= out_ptr;
  1753. while(1){
  1754. if(k==out_buf)/*85:*/
  1755. #line 1387 "cweave.w"
  1756.  
  1757. {
  1758. printf("\n! Line had to be broken (output l. %d):\n",out_line);
  1759.  
  1760. term_write(out_buf+1,out_ptr-out_buf-1);
  1761. new_line;mark_harmless;
  1762. flush_buffer(out_ptr-1,1,1);return;
  1763. }
  1764.  
  1765. /*:85*/
  1766. #line 1372 "cweave.w"
  1767. ;
  1768. if(*k==' '){
  1769. flush_buffer(k,0,1);return;
  1770. }
  1771. if(*(k--)=='\\'&&*k!='\\'){
  1772. flush_buffer(k,1,1);return;
  1773. }
  1774. }
  1775. }
  1776.  
  1777. /*:84*//*86:*/
  1778. #line 1401 "cweave.w"
  1779.  
  1780. void
  1781. out_section(n)
  1782. sixteen_bits n;
  1783. {
  1784. char s[6];
  1785. sprintf(s,"%d",n);out_str(s);
  1786. if(changed_section[n])out_str("\\*");
  1787.  
  1788. }
  1789.  
  1790. /*:86*//*87:*/
  1791. #line 1415 "cweave.w"
  1792.  
  1793. void
  1794. out_name(p)
  1795. name_pointer p;
  1796. {
  1797. char*k,*k_end= (p+1)->byte_start;
  1798. out('{');
  1799. for(k= p->byte_start;k<k_end;k++){
  1800. if(isxalpha(*k))out('\\');
  1801. out(*k);
  1802. }
  1803. out('}');
  1804. }
  1805.  
  1806. /*:87*//*88:*/
  1807. #line 1442 "cweave.w"
  1808.  
  1809. void
  1810. copy_limbo()
  1811. {
  1812. char c;
  1813. while(1){
  1814. if(loc>limit&&(finish_line(),get_line()==0))return;
  1815. *(limit+1)= '@';
  1816. while(*loc!='@')out(*(loc++));
  1817. if(loc++<=limit){
  1818. c= *loc++;
  1819. if(ccode[(eight_bits)c]==new_section)break;
  1820. switch(ccode[(eight_bits)c]){
  1821. case translit_code:out_str("\\ATL");break;
  1822.  
  1823. case'@':out('@');break;
  1824. case noop:skip_restricted();break;
  1825. case format_code:if(get_next()==identifier)get_next();
  1826. if(loc>=limit)get_line();
  1827. break;
  1828. default:err_print("! Double @ should be used in limbo");
  1829.  
  1830. out('@');
  1831. }
  1832. }
  1833. }
  1834. }
  1835.  
  1836. /*:88*//*90:*/
  1837. #line 1477 "cweave.w"
  1838.  
  1839. eight_bits
  1840. copy_TeX()
  1841. {
  1842. char c;
  1843. while(1){
  1844. if(loc>limit&&(finish_line(),get_line()==0))return(new_section);
  1845. *(limit+1)= '@';
  1846. while((c= *(loc++))!='|'&&c!='@'){
  1847. out(c);
  1848. if(out_ptr==out_buf+1&&(xisspace(c)))out_ptr--;
  1849. }
  1850. if(c=='|')return('|');
  1851. if(loc<=limit)return(ccode[(eight_bits)*(loc++)]);
  1852. }
  1853. }
  1854.  
  1855. /*:90*//*92:*/
  1856. #line 1509 "cweave.w"
  1857.  
  1858. int copy_comment(is_long_comment,bal)
  1859. boolean is_long_comment;
  1860. int bal;
  1861. {
  1862. char c;
  1863. while(1){
  1864. if(loc>limit){
  1865. if(is_long_comment){
  1866. if(get_line()==0){
  1867. err_print("! Input ended in mid-comment");
  1868.  
  1869. loc= buffer+1;goto done;
  1870. }
  1871. }
  1872. else{
  1873. if(bal>1)err_print("! Missing } in comment");
  1874.  
  1875. goto done;
  1876. }
  1877. }
  1878. c= *(loc++);
  1879. if(c=='|')return(bal);
  1880. if(is_long_comment)/*93:*/
  1881. #line 1550 "cweave.w"
  1882.  
  1883. if(c=='*'&&*loc=='/'){
  1884. loc++;
  1885. if(bal>1)err_print("! Missing } in comment");
  1886.  
  1887. goto done;
  1888. }
  1889.  
  1890. /*:93*/
  1891. #line 1532 "cweave.w"
  1892. ;
  1893. if(phase==2){
  1894. if(ishigh(c))app_tok(quoted_char);
  1895. app_tok(c);
  1896. }
  1897. /*94:*/
  1898. #line 1558 "cweave.w"
  1899.  
  1900. if(c=='@'){
  1901. if(*(loc++)!='@'){
  1902. err_print("! Illegal use of @ in comment");
  1903.  
  1904. loc-= 2;if(phase==2)*(tok_ptr-1)= ' ';goto done;
  1905. }
  1906. }
  1907. else if(c=='\\'&&*loc!='@')
  1908. if(phase==2)app_tok(*(loc++))else loc++;
  1909.  
  1910. /*:94*/
  1911. #line 1537 "cweave.w"
  1912. ;
  1913. if(c=='{')bal++;
  1914. else if(c=='}'){
  1915. if(bal>1)bal--;
  1916. else{err_print("! Extra } in comment");
  1917.  
  1918. if(phase==2)tok_ptr--;
  1919. }
  1920. }
  1921. }
  1922. done:/*95:*/
  1923. #line 1572 "cweave.w"
  1924.  
  1925. if(phase==2)while(bal-->0)app_tok('}');
  1926. return(0);
  1927.  
  1928. /*:95*/
  1929. #line 1547 "cweave.w"
  1930. ;
  1931. }
  1932.  
  1933. /*:92*//*99:*/
  1934. #line 1734 "cweave.w"
  1935.  
  1936. void
  1937. print_cat(c)
  1938. eight_bits c;
  1939. {
  1940. printf(cat_name[c]);
  1941. }
  1942.  
  1943. /*:99*//*106:*/
  1944. #line 2062 "cweave.w"
  1945.  
  1946. void
  1947. print_text(p)
  1948. text_pointer p;
  1949. {
  1950. token_pointer j;
  1951. sixteen_bits r;
  1952. if(p>=text_ptr)printf("BAD");
  1953. else for(j= *p;j<*(p+1);j++){
  1954. r= *j%id_flag;
  1955. switch(*j/id_flag){
  1956. case 1:printf("\\\\{");print_id((name_dir+r));printf("}");
  1957. break;
  1958. case 2:printf("\\&{");print_id((name_dir+r));printf("}");
  1959. break;
  1960. case 3:printf("<");print_section_name((name_dir+r));printf(">");
  1961. break;
  1962. case 4:printf("[[%d]]",r);break;
  1963. case 5:printf("|[[%d]]|",r);break;
  1964. default:/*107:*/
  1965. #line 2087 "cweave.w"
  1966.  
  1967. switch(r){
  1968. case math_rel:printf("\\mathrel{");break;
  1969. case big_cancel:printf("[ccancel]");break;
  1970. case cancel:printf("[cancel]");break;
  1971. case indent:printf("[indent]");break;
  1972. case outdent:printf("[outdent]");break;
  1973. case backup:printf("[backup]");break;
  1974. case opt:printf("[opt]");break;
  1975. case break_space:printf("[break]");break;
  1976. case force:printf("[force]");break;
  1977. case big_force:printf("[fforce]");break;
  1978. case preproc_line:printf("[preproc]");break;
  1979. case quoted_char:j++;printf("[%o]",(unsigned)*j);break;
  1980. case end_translation:printf("[quit]");break;
  1981. case inserted:printf("[inserted]");break;
  1982. default:putxchar(r);
  1983. }
  1984.  
  1985. /*:107*/
  1986. #line 2081 "cweave.w"
  1987. ;
  1988. }
  1989. }
  1990. fflush(stdout);
  1991. }
  1992.  
  1993. /*:106*//*109:*/
  1994. #line 2187 "cweave.w"
  1995.  
  1996. void
  1997. app_str(s)
  1998. char*s;
  1999. {
  2000. while(*s)app_tok(*(s++));
  2001. }
  2002.  
  2003. void
  2004. big_app(a)
  2005. token a;
  2006. {
  2007. if(a==' '||(a>=big_cancel&&a<=big_force)){
  2008. if(cur_mathness==maybe_math)init_mathness= no_math;
  2009. else if(cur_mathness==yes_math)app_str("{}$");
  2010. cur_mathness= no_math;
  2011. }
  2012. else{
  2013. if(cur_mathness==maybe_math)init_mathness= yes_math;
  2014. else if(cur_mathness==no_math)app_str("${}");
  2015. cur_mathness= yes_math;
  2016. }
  2017. app(a);
  2018. }
  2019.  
  2020. void
  2021. big_app1(a)
  2022. scrap_pointer a;
  2023. {
  2024. switch(a->mathness%4){
  2025. case(no_math):
  2026. if(cur_mathness==maybe_math)init_mathness= no_math;
  2027. else if(cur_mathness==yes_math)app_str("{}$");
  2028. cur_mathness= a->mathness/4;
  2029. break;
  2030. case(yes_math):
  2031. if(cur_mathness==maybe_math)init_mathness= yes_math;
  2032. else if(cur_mathness==no_math)app_str("${}");
  2033. cur_mathness= a->mathness/4;
  2034. break;
  2035. case(maybe_math):break;
  2036. }
  2037. app(tok_flag+(int)((a)->trans-tok_start));
  2038. }
  2039.  
  2040. /*:109*//*111:*/
  2041. #line 2312 "cweave.w"
  2042.  
  2043. token_pointer
  2044. find_first_ident(p)
  2045. text_pointer p;
  2046. {
  2047. token_pointer q;
  2048. token_pointer j;
  2049. sixteen_bits r;
  2050. if(p>=text_ptr)confusion("find_first_ident");
  2051. for(j= *p;j<*(p+1);j++){
  2052. r= *j%id_flag;
  2053. switch(*j/id_flag){
  2054. case 1:case 2:return j;
  2055. case 4:case 5:
  2056. if((q= find_first_ident(tok_start+r))!=no_ident_found)
  2057. return q;
  2058. default:;
  2059. if(*j==inserted)return no_ident_found;
  2060. }
  2061. }
  2062. return no_ident_found;
  2063. }
  2064.  
  2065. /*:111*//*112:*/
  2066. #line 2339 "cweave.w"
  2067.  
  2068. void
  2069. make_reserved(p)
  2070. scrap_pointer p;
  2071. {
  2072. sixteen_bits tok_value;
  2073. token_pointer tok_loc;
  2074. if((tok_loc= find_first_ident(p->trans))==no_ident_found)
  2075. return;
  2076. tok_value= *tok_loc;
  2077. for(;p<=scrap_ptr;p==lo_ptr?p= hi_ptr:p++){
  2078. if(p->cat==exp){
  2079. if(**(p->trans)==tok_value){
  2080. p->cat= raw_int;
  2081. **(p->trans)= tok_value%id_flag+res_flag;
  2082. }
  2083. }
  2084. }
  2085. (name_dir+(sixteen_bits)(tok_value%id_flag))->ilk= raw_int;
  2086. *tok_loc= tok_value%id_flag+res_flag;
  2087. }
  2088.  
  2089. /*:112*//*113:*/
  2090. #line 2370 "cweave.w"
  2091.  
  2092. void
  2093. make_underlined(p)
  2094.  
  2095. scrap_pointer p;
  2096. {
  2097. token_pointer tok_loc;
  2098. if((tok_loc= find_first_ident(p->trans))==no_ident_found)
  2099. return;
  2100. xref_switch= def_flag;
  2101. underline_xref(*tok_loc%id_flag+name_dir);
  2102. }
  2103.  
  2104. /*:113*//*115:*/
  2105. #line 2391 "cweave.w"
  2106.  
  2107. void
  2108. underline_xref(p)
  2109. name_pointer p;
  2110. {
  2111. xref_pointer q= (xref_pointer)p->xref;
  2112. xref_pointer r;
  2113. sixteen_bits m;
  2114. sixteen_bits n;
  2115. if(no_xref)return;
  2116. m= section_count+xref_switch;
  2117. while(q!=xmem){
  2118. n= q->num;
  2119. if(n==m)return;
  2120. else if(m==n+def_flag){
  2121. q->num= m;return;
  2122. }
  2123. else if(n>=def_flag&&n<m)break;
  2124. q= q->xlink;
  2125. }
  2126. /*116:*/
  2127. #line 2421 "cweave.w"
  2128.  
  2129. append_xref(0);
  2130. xref_ptr->xlink= (xref_pointer)p->xref;r= xref_ptr;
  2131. p->xref= (char*)xref_ptr;
  2132. while(r->xlink!=q){r->num= r->xlink->num;r= r->xlink;}
  2133. r->num= m;
  2134.  
  2135. /*:116*/
  2136. #line 2411 "cweave.w"
  2137. ;
  2138. }
  2139.  
  2140. /*:115*//*162:*/
  2141. #line 2868 "cweave.w"
  2142.  
  2143. void
  2144. reduce(j,k,c,d,n)
  2145. scrap_pointer j;
  2146. eight_bits c;
  2147. short k,d,n;
  2148. {
  2149. scrap_pointer i,i1;
  2150. j->cat= c;j->trans= text_ptr;
  2151. j->mathness= 4*cur_mathness+init_mathness;
  2152. freeze_text;
  2153. if(k>1){
  2154. for(i= j+k,i1= j+1;i<=lo_ptr;i++,i1++){
  2155. i1->cat= i->cat;i1->trans= i->trans;
  2156. i1->mathness= i->mathness;
  2157. }
  2158. lo_ptr= lo_ptr-k+1;
  2159. }
  2160. /*163:*/
  2161. #line 2891 "cweave.w"
  2162.  
  2163. if(pp+d>=scrap_base)pp= pp+d;
  2164. else pp= scrap_base;
  2165.  
  2166. /*:163*/
  2167. #line 2886 "cweave.w"
  2168. ;
  2169. /*168:*/
  2170. #line 2965 "cweave.w"
  2171.  
  2172. {scrap_pointer k;
  2173. if(tracing==2){
  2174. printf("\n%d:",n);
  2175. for(k= scrap_base;k<=lo_ptr;k++){
  2176. if(k==pp)putxchar('*');else putxchar(' ');
  2177. if(k->mathness%4==yes_math)putchar('+');
  2178. else if(k->mathness%4==no_math)putchar('-');
  2179. print_cat(k->cat);
  2180. if(k->mathness/4==yes_math)putchar('+');
  2181. else if(k->mathness/4==no_math)putchar('-');
  2182. }
  2183. if(hi_ptr<=scrap_ptr)printf("...");
  2184. }
  2185. }
  2186.  
  2187. /*:168*/
  2188. #line 2887 "cweave.w"
  2189. ;
  2190. pp--;
  2191. }
  2192.  
  2193. /*:162*//*164:*/
  2194. #line 2898 "cweave.w"
  2195.  
  2196. void
  2197. squash(j,k,c,d,n)
  2198. scrap_pointer j;
  2199. eight_bits c;
  2200. short k,d,n;
  2201. {
  2202. scrap_pointer i;
  2203. if(k==1){
  2204. j->cat= c;/*163:*/
  2205. #line 2891 "cweave.w"
  2206.  
  2207. if(pp+d>=scrap_base)pp= pp+d;
  2208. else pp= scrap_base;
  2209.  
  2210. /*:163*/
  2211. #line 2907 "cweave.w"
  2212. ;
  2213. /*168:*/
  2214. #line 2965 "cweave.w"
  2215.  
  2216. {scrap_pointer k;
  2217. if(tracing==2){
  2218. printf("\n%d:",n);
  2219. for(k= scrap_base;k<=lo_ptr;k++){
  2220. if(k==pp)putxchar('*');else putxchar(' ');
  2221. if(k->mathness%4==yes_math)putchar('+');
  2222. else if(k->mathness%4==no_math)putchar('-');
  2223. print_cat(k->cat);
  2224. if(k->mathness/4==yes_math)putchar('+');
  2225. else if(k->mathness/4==no_math)putchar('-');
  2226. }
  2227. if(hi_ptr<=scrap_ptr)printf("...");
  2228. }
  2229. }
  2230.  
  2231. /*:168*/
  2232. #line 2908 "cweave.w"
  2233. ;
  2234. pp--;
  2235. return;
  2236. }
  2237. for(i= j;i<j+k;i++)big_app1(i);
  2238. reduce(j,k,c,d,n);
  2239. }
  2240.  
  2241. /*:164*//*169:*/
  2242. #line 2994 "cweave.w"
  2243.  
  2244. text_pointer
  2245. translate()
  2246. {
  2247. scrap_pointer i,
  2248. j;
  2249. pp= scrap_base;lo_ptr= pp-1;hi_ptr= pp;
  2250. /*172:*/
  2251. #line 3033 "cweave.w"
  2252.  
  2253. if(tracing==2){
  2254. printf("\nTracing after l. %d:\n",cur_line);mark_harmless;
  2255.  
  2256. if(loc>buffer+50){
  2257. printf("...");
  2258. term_write(loc-51,51);
  2259. }
  2260. else term_write(buffer,loc-buffer);
  2261. }
  2262.  
  2263. /*:172*/
  2264. #line 3001 "cweave.w"
  2265. ;
  2266. /*165:*/
  2267. #line 2929 "cweave.w"
  2268.  
  2269. while(1){
  2270. /*166:*/
  2271. #line 2948 "cweave.w"
  2272.  
  2273. if(lo_ptr<pp+3){
  2274. while(hi_ptr<=scrap_ptr&&lo_ptr!=pp+3){
  2275. (++lo_ptr)->cat= hi_ptr->cat;lo_ptr->mathness= (hi_ptr)->mathness;
  2276. lo_ptr->trans= (hi_ptr++)->trans;
  2277. }
  2278. for(i= lo_ptr+1;i<=pp+3;i++)i->cat= 0;
  2279. }
  2280.  
  2281. /*:166*/
  2282. #line 2931 "cweave.w"
  2283. ;
  2284. if(tok_ptr+safe_tok_incr>tok_mem_end){
  2285. if(tok_ptr>max_tok_ptr)max_tok_ptr= tok_ptr;
  2286. overflow("token");
  2287. }
  2288. if(text_ptr+safe_text_incr>tok_start_end){
  2289. if(text_ptr>max_text_ptr)max_text_ptr= text_ptr;
  2290. overflow("text");
  2291. }
  2292. if(pp>lo_ptr)break;
  2293. init_mathness= cur_mathness= maybe_math;
  2294. /*110:*/
  2295. #line 2243 "cweave.w"
  2296. {
  2297. if(cat1==end_arg&&lhs_not_simple)
  2298. if(pp->cat==begin_arg)squash(pp,2,exp,-2,110);
  2299. else squash(pp,2,end_arg,-1,111);
  2300. else if(cat1==insert)squash(pp,2,pp->cat,-2,0);
  2301. else if(cat2==insert)squash(pp+1,2,(pp+1)->cat,-1,0);
  2302. else if(cat3==insert)squash(pp+2,2,(pp+2)->cat,0,0);
  2303. else
  2304. switch(pp->cat){
  2305. case exp:/*117:*/
  2306. #line 2433 "cweave.w"
  2307.  
  2308. if(cat1==lbrace||cat1==int_like||cat1==decl){
  2309. make_underlined(pp);big_app1(pp);big_app(indent);app(indent);
  2310. reduce(pp,1,fn_decl,0,1);
  2311. }
  2312. else if(cat1==unop)squash(pp,2,exp,-2,2);
  2313. else if((cat1==binop||cat1==unorbinop)&&cat2==exp)
  2314. squash(pp,3,exp,-2,3);
  2315. else if(cat1==comma&&cat2==exp){
  2316. big_app2(pp);
  2317. app(opt);app('9');big_app1(pp+2);reduce(pp,3,exp,-2,4);
  2318. }
  2319. else if(cat1==exp||cat1==cast)squash(pp,2,exp,-2,5);
  2320. else if(cat1==semi)squash(pp,2,stmt,-1,6);
  2321. else if(cat1==colon){
  2322. make_underlined(pp);squash(pp,2,tag,0,7);
  2323. }
  2324. else if(cat1==base){
  2325. if(cat2==int_like&&cat3==comma){
  2326. big_app1(pp+1);big_app(' ');big_app2(pp+2);
  2327. app(opt);app('9');reduce(pp+1,3,base,0,8);
  2328. }
  2329. else if(cat2==int_like&&cat3==lbrace){
  2330. big_app1(pp);big_app(' ');big_app1(pp+1);big_app(' ');big_app1(pp+2);
  2331. reduce(pp,3,exp,-1,9);
  2332. }
  2333. }
  2334. else if(cat1==rbrace)squash(pp,1,stmt,-1,10);
  2335.  
  2336. /*:117*/
  2337. #line 2252 "cweave.w"
  2338. ;break;
  2339. case lpar:/*118:*/
  2340. #line 2462 "cweave.w"
  2341.  
  2342. if((cat1==exp||cat1==unorbinop)&&cat2==rpar)squash(pp,3,exp,-2,11);
  2343. else if(cat1==rpar){
  2344. big_app1(pp);app('\\');app(',');big_app1(pp+1);
  2345.  
  2346. reduce(pp,2,exp,-2,12);
  2347. }
  2348. else if(cat1==decl_head||cat1==int_like||cat1==exp){
  2349. if(cat2==rpar)squash(pp,3,cast,-2,13);
  2350. else if(cat2==comma){
  2351. big_app3(pp);app(opt);app('9');reduce(pp,3,lpar,0,14);
  2352. }
  2353. }
  2354. else if(cat1==stmt||cat1==decl){
  2355. big_app2(pp);big_app(' ');reduce(pp,2,lpar,0,15);
  2356. }
  2357.  
  2358. /*:118*/
  2359. #line 2253 "cweave.w"
  2360. ;break;
  2361. case question:/*119:*/
  2362. #line 2479 "cweave.w"
  2363.  
  2364. if(cat1==exp&&cat2==colon)squash(pp,3,binop,-2,16);
  2365.  
  2366. /*:119*/
  2367. #line 2254 "cweave.w"
  2368. ;break;
  2369. case unop:/*120:*/
  2370. #line 2482 "cweave.w"
  2371.  
  2372. if(cat1==exp||cat1==int_like)squash(pp,2,cat1,-2,17);
  2373.  
  2374. /*:120*/
  2375. #line 2255 "cweave.w"
  2376. ;break;
  2377. case unorbinop:/*121:*/
  2378. #line 2485 "cweave.w"
  2379.  
  2380. if(cat1==exp||cat1==int_like){
  2381. big_app('{');big_app1(pp);big_app('}');big_app1(pp+1);
  2382. reduce(pp,2,cat1,-2,18);
  2383. }
  2384. else if(cat1==binop){
  2385. big_app(math_rel);big_app1(pp);big_app('{');big_app1(pp+1);big_app('}');
  2386. big_app('}');reduce(pp,2,binop,-1,19);
  2387. }
  2388.  
  2389. /*:121*/
  2390. #line 2256 "cweave.w"
  2391. ;break;
  2392. case binop:/*122:*/
  2393. #line 2495 "cweave.w"
  2394.  
  2395. if(cat1==binop){
  2396. big_app(math_rel);big_app('{');big_app1(pp);big_app('}');
  2397. big_app('{');big_app1(pp+1);big_app('}');
  2398. big_app('}');reduce(pp,2,binop,-1,20);
  2399. }
  2400.  
  2401. /*:122*/
  2402. #line 2257 "cweave.w"
  2403. ;break;
  2404. case cast:/*123:*/
  2405. #line 2502 "cweave.w"
  2406.  
  2407. if(cat1==exp){
  2408. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,exp,-2,21);
  2409. }
  2410. else if(cat1==semi)squash(pp,1,exp,-2,22);
  2411.  
  2412. /*:123*/
  2413. #line 2258 "cweave.w"
  2414. ;break;
  2415. case sizeof_like:/*124:*/
  2416. #line 2508 "cweave.w"
  2417.  
  2418. if(cat1==cast)squash(pp,2,exp,-2,23);
  2419. else if(cat1==exp){
  2420. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,exp,-2,24);
  2421. }
  2422.  
  2423. /*:124*/
  2424. #line 2259 "cweave.w"
  2425. ;break;
  2426. case int_like:/*125:*/
  2427. #line 2514 "cweave.w"
  2428.  
  2429. if(cat1==int_like||cat1==struct_like){
  2430. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,cat1,-2,25);
  2431. }
  2432. else if(cat1==exp&&(cat2==raw_int||cat2==struct_like))
  2433. squash(pp,2,int_like,-2,26);
  2434. else if(cat1==exp||cat1==unorbinop||cat1==semi){
  2435. big_app1(pp);
  2436. if(cat1!=semi)big_app(' ');
  2437. reduce(pp,1,decl_head,-1,27);
  2438. }
  2439. else if(cat1==colon){
  2440. big_app1(pp);big_app(' ');reduce(pp,1,decl_head,0,28);
  2441. }
  2442. else if(cat1==prelangle)squash(pp+1,1,langle,1,29);
  2443. else if(cat1==colcol&&(cat2==exp||cat2==int_like))squash(pp,3,cat2,-2,30);
  2444. else if(cat1==cast){
  2445. if(cat2==lbrace){
  2446. big_app2(pp);big_app(indent);big_app(indent);
  2447. reduce(pp,2,fn_decl,1,31);
  2448. }
  2449. else squash(pp,2,int_like,-2,32);
  2450. }
  2451.  
  2452. /*:125*/
  2453. #line 2260 "cweave.w"
  2454. ;break;
  2455. case decl_head:/*126:*/
  2456. #line 2538 "cweave.w"
  2457.  
  2458. if(cat1==comma){
  2459. big_app2(pp);big_app(' ');reduce(pp,2,decl_head,-1,33);
  2460. }
  2461. else if(cat1==unorbinop){
  2462. big_app1(pp);big_app('{');big_app1(pp+1);big_app('}');
  2463. reduce(pp,2,decl_head,-1,34);
  2464. }
  2465. else if(cat1==exp&&cat2!=lpar&&cat2!=exp){
  2466. make_underlined(pp+1);squash(pp,2,decl_head,-1,35);
  2467. }
  2468. else if((cat1==binop||cat1==colon)&&cat2==exp&&(cat3==comma||
  2469. cat3==semi||cat3==rpar))
  2470. squash(pp,3,decl_head,-1,36);
  2471. else if(cat1==cast)squash(pp,2,decl_head,-1,37);
  2472. else if(cat1==lbrace||(cat1==int_like&&cat2!=colcol)||cat1==decl){
  2473. big_app1(pp);big_app(indent);app(indent);reduce(pp,1,fn_decl,0,38);
  2474. }
  2475. else if(cat1==semi)squash(pp,2,decl,-1,39);
  2476.  
  2477. /*:126*/
  2478. #line 2261 "cweave.w"
  2479. ;break;
  2480. case decl:/*127:*/
  2481. #line 2558 "cweave.w"
  2482.  
  2483. if(cat1==decl){
  2484. big_app1(pp);big_app(force);big_app1(pp+1);
  2485. reduce(pp,2,decl,-1,40);
  2486. }
  2487. else if(cat1==stmt||cat1==function){
  2488. big_app1(pp);big_app(big_force);
  2489. big_app1(pp+1);reduce(pp,2,cat1,-1,41);
  2490. }
  2491.  
  2492. /*:127*/
  2493. #line 2262 "cweave.w"
  2494. ;break;
  2495. case typedef_like:/*128:*/
  2496. #line 2568 "cweave.w"
  2497.  
  2498. if(cat1==decl_head)
  2499. if((cat2==exp&&cat3!=lpar&&cat3!=exp)||cat2==int_like){
  2500. make_underlined(pp+2);make_reserved(pp+2);
  2501. big_app2(pp+1);reduce(pp+1,2,decl_head,0,42);
  2502. }
  2503. else if(cat2==semi){
  2504. big_app1(pp);big_app(' ');big_app2(pp+1);reduce(pp,3,decl,-1,43);
  2505. }
  2506.  
  2507. /*:128*/
  2508. #line 2263 "cweave.w"
  2509. ;break;
  2510. case struct_like:/*129:*/
  2511. #line 2578 "cweave.w"
  2512.  
  2513. if(cat1==lbrace){
  2514. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,struct_head,0,44);
  2515. }
  2516. else if(cat1==exp||cat1==int_like){
  2517. if(cat2==lbrace||cat2==semi){
  2518. make_underlined(pp+1);make_reserved(pp+1);
  2519. big_app1(pp);big_app(' ');big_app1(pp+1);
  2520. if(cat2==semi)reduce(pp,2,decl_head,0,45);
  2521. else{
  2522. big_app(' ');big_app1(pp+2);reduce(pp,3,struct_head,0,46);
  2523. }
  2524. }
  2525. else if(cat2==colon)squash(pp+2,1,base,-1,47);
  2526. else if(cat2!=base){
  2527. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,int_like,-2,48);
  2528. }
  2529. }
  2530.  
  2531. /*:129*/
  2532. #line 2264 "cweave.w"
  2533. ;break;
  2534. case struct_head:/*130:*/
  2535. #line 2597 "cweave.w"
  2536.  
  2537. if((cat1==decl||cat1==stmt||cat1==function)&&cat2==rbrace){
  2538. big_app1(pp);big_app(indent);big_app(force);big_app1(pp+1);
  2539. big_app(outdent);big_app(force);big_app1(pp+2);
  2540. reduce(pp,3,int_like,-2,49);
  2541. }
  2542. else if(cat1==rbrace){
  2543. big_app1(pp);app_str("\\,");big_app1(pp+1);
  2544.  
  2545. reduce(pp,2,int_like,-2,50);
  2546. }
  2547.  
  2548. /*:130*/
  2549. #line 2265 "cweave.w"
  2550. ;break;
  2551. case fn_decl:/*131:*/
  2552. #line 2609 "cweave.w"
  2553.  
  2554. if(cat1==decl){
  2555. big_app1(pp);big_app(force);big_app1(pp+1);reduce(pp,2,fn_decl,0,51);
  2556. }
  2557. else if(cat1==stmt){
  2558. big_app1(pp);app(outdent);app(outdent);big_app(force);
  2559. big_app1(pp+1);reduce(pp,2,function,-1,52);
  2560. }
  2561.  
  2562. /*:131*/
  2563. #line 2266 "cweave.w"
  2564. ;break;
  2565. case function:/*132:*/
  2566. #line 2618 "cweave.w"
  2567.  
  2568. if(cat1==function||cat1==decl||cat1==stmt){
  2569. big_app1(pp);big_app(big_force);big_app1(pp+1);reduce(pp,2,cat1,-1,53);
  2570. }
  2571.  
  2572. /*:132*/
  2573. #line 2267 "cweave.w"
  2574. ;break;
  2575. case lbrace:/*133:*/
  2576. #line 2623 "cweave.w"
  2577.  
  2578. if(cat1==rbrace){
  2579. big_app1(pp);app('\\');app(',');big_app1(pp+1);
  2580.  
  2581. reduce(pp,2,stmt,-1,54);
  2582. }
  2583. else if((cat1==stmt||cat1==decl||cat1==function)&&cat2==rbrace){
  2584. big_app(force);big_app1(pp);big_app(indent);big_app(force);
  2585. big_app1(pp+1);big_app(force);big_app(backup);big_app1(pp+2);
  2586. big_app(outdent);big_app(force);reduce(pp,3,stmt,-1,55);
  2587. }
  2588. else if(cat1==exp){
  2589. if(cat2==rbrace)squash(pp,3,exp,-2,56);
  2590. else if(cat2==comma&&cat3==rbrace)squash(pp,4,exp,-2,56);
  2591. }
  2592.  
  2593. /*:133*/
  2594. #line 2268 "cweave.w"
  2595. ;break;
  2596. case do_like:/*140:*/
  2597. #line 2689 "cweave.w"
  2598.  
  2599. if(cat1==stmt&&cat2==else_like&&cat3==semi){
  2600. big_app1(pp);big_app(break_space);app(noop);big_app(cancel);
  2601. big_app1(pp+1);big_app(cancel);app(noop);big_app(break_space);
  2602. big_app2(pp+2);reduce(pp,4,stmt,-1,69);
  2603. }
  2604.  
  2605. /*:140*/
  2606. #line 2269 "cweave.w"
  2607. ;break;
  2608. case if_like:/*134:*/
  2609. #line 2639 "cweave.w"
  2610.  
  2611. if(cat1==exp){
  2612. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,if_clause,0,57);
  2613. }
  2614.  
  2615. /*:134*/
  2616. #line 2270 "cweave.w"
  2617. ;break;
  2618. case for_like:/*135:*/
  2619. #line 2644 "cweave.w"
  2620.  
  2621. if(cat1==exp){
  2622. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,else_like,-2,58);
  2623. }
  2624.  
  2625. /*:135*/
  2626. #line 2271 "cweave.w"
  2627. ;break;
  2628. case else_like:/*136:*/
  2629. #line 2649 "cweave.w"
  2630.  
  2631. if(cat1==lbrace)squash(pp,1,else_head,0,59);
  2632. else if(cat1==stmt){
  2633. big_app(force);big_app1(pp);big_app(indent);big_app(break_space);
  2634. big_app1(pp+1);big_app(outdent);big_app(force);
  2635. reduce(pp,2,stmt,-1,60);
  2636. }
  2637.  
  2638. /*:136*/
  2639. #line 2272 "cweave.w"
  2640. ;break;
  2641. case if_clause:/*138:*/
  2642. #line 2664 "cweave.w"
  2643.  
  2644. if(cat1==lbrace)squash(pp,1,if_head,0,62);
  2645. else if(cat1==stmt){
  2646. if(cat2==else_like){
  2647. big_app(force);big_app1(pp);big_app(indent);big_app(break_space);
  2648. big_app1(pp+1);big_app(outdent);big_app(force);big_app1(pp+2);
  2649. if(cat3==if_like){
  2650. big_app(' ');big_app1(pp+3);reduce(pp,4,if_like,0,63);
  2651. }else reduce(pp,3,else_like,0,64);
  2652. }
  2653. else squash(pp,1,else_like,0,65);
  2654. }
  2655.  
  2656. /*:138*/
  2657. #line 2273 "cweave.w"
  2658. ;break;
  2659. case if_head:/*139:*/
  2660. #line 2677 "cweave.w"
  2661.  
  2662. if(cat1==stmt||cat1==exp){
  2663. if(cat2==else_like){
  2664. big_app(force);big_app1(pp);big_app(break_space);app(noop);
  2665. big_app(cancel);big_app1(pp+1);big_app(force);big_app1(pp+2);
  2666. if(cat3==if_like){
  2667. big_app(' ');big_app1(pp+3);reduce(pp,4,if_like,0,66);
  2668. }else reduce(pp,3,else_like,0,67);
  2669. }
  2670. else squash(pp,1,else_head,0,68);
  2671. }
  2672.  
  2673. /*:139*/
  2674. #line 2274 "cweave.w"
  2675. ;break;
  2676. case else_head:/*137:*/
  2677. #line 2657 "cweave.w"
  2678.  
  2679. if(cat1==stmt||cat1==exp){
  2680. big_app(force);big_app1(pp);big_app(break_space);app(noop);
  2681. big_app(cancel);big_app1(pp+1);big_app(force);
  2682. reduce(pp,2,stmt,-1,61);
  2683. }
  2684.  
  2685. /*:137*/
  2686. #line 2275 "cweave.w"
  2687. ;break;
  2688. case case_like:/*141:*/
  2689. #line 2696 "cweave.w"
  2690.  
  2691. if(cat1==semi)squash(pp,2,stmt,-1,70);
  2692. else if(cat1==colon)squash(pp,2,tag,-1,71);
  2693. else if(cat1==exp){
  2694. if(cat2==semi){
  2695. big_app1(pp);big_app(' ');big_app1(pp+1);big_app1(pp+2);
  2696. reduce(pp,3,stmt,-1,72);
  2697. }
  2698. else if(cat2==colon){
  2699. big_app1(pp);big_app(' ');big_app1(pp+1);big_app1(pp+2);
  2700. reduce(pp,3,tag,-1,73);
  2701. }
  2702. }
  2703.  
  2704. /*:141*/
  2705. #line 2276 "cweave.w"
  2706. ;break;
  2707. case stmt:/*143:*/
  2708. #line 2723 "cweave.w"
  2709.  
  2710. if(cat1==stmt||cat1==decl||cat1==function){
  2711. big_app1(pp);
  2712. if(cat1==function)big_app(big_force);
  2713. else if(cat1==decl)big_app(big_force);
  2714. else if(force_lines)big_app(force);
  2715. else big_app(break_space);
  2716. big_app1(pp+1);reduce(pp,2,cat1,-1,76);
  2717. }
  2718.  
  2719. /*:143*/
  2720. #line 2277 "cweave.w"
  2721. ;break;
  2722. case tag:/*142:*/
  2723. #line 2710 "cweave.w"
  2724.  
  2725. if(cat1==tag){
  2726. big_app1(pp);big_app(break_space);big_app1(pp+1);reduce(pp,2,tag,-1,74);
  2727. }
  2728. else if(cat1==stmt||cat1==decl||cat1==function){
  2729. big_app(force);big_app(backup);big_app1(pp);big_app(break_space);
  2730. big_app1(pp+1);reduce(pp,2,cat1,-1,75);
  2731. }
  2732.  
  2733. /*:142*/
  2734. #line 2278 "cweave.w"
  2735. ;break;
  2736. case semi:/*144:*/
  2737. #line 2733 "cweave.w"
  2738.  
  2739. big_app(' ');big_app1(pp);reduce(pp,1,stmt,-1,77);
  2740.  
  2741. /*:144*/
  2742. #line 2279 "cweave.w"
  2743. ;break;
  2744. case lproc:/*145:*/
  2745. #line 2736 "cweave.w"
  2746.  
  2747. if(cat1==define_like)make_underlined(pp+2);
  2748. if(cat1==else_like||cat1==if_like||cat1==define_like)
  2749. squash(pp,2,lproc,0,78);
  2750. else if(cat1==rproc){
  2751. app(inserted);big_app2(pp);reduce(pp,2,insert,-1,79);
  2752. }else if(cat1==exp||cat1==function){
  2753. if(cat2==rproc){
  2754. app(inserted);big_app1(pp);big_app(' ');big_app2(pp+1);
  2755. reduce(pp,3,insert,-1,80);
  2756. }
  2757. else if(cat2==exp&&cat3==rproc&&cat1==exp){
  2758. app(inserted);big_app1(pp);big_app(' ');big_app1(pp+1);app_str(" \\5");
  2759.  
  2760. big_app2(pp+2);reduce(pp,4,insert,-1,80);
  2761. }
  2762. }
  2763.  
  2764. /*:145*/
  2765. #line 2280 "cweave.w"
  2766. ;break;
  2767. case section_scrap:/*146:*/
  2768. #line 2754 "cweave.w"
  2769.  
  2770. if(cat1==semi){
  2771. big_app2(pp);big_app(force);reduce(pp,2,stmt,-2,81);
  2772. }
  2773. else squash(pp,1,exp,-2,82);
  2774.  
  2775. /*:146*/
  2776. #line 2281 "cweave.w"
  2777. ;break;
  2778. case insert:/*147:*/
  2779. #line 2760 "cweave.w"
  2780.  
  2781. if(cat1)
  2782. squash(pp,2,cat1,0,83);
  2783.  
  2784. /*:147*/
  2785. #line 2282 "cweave.w"
  2786. ;break;
  2787. case prelangle:/*148:*/
  2788. #line 2764 "cweave.w"
  2789.  
  2790. init_mathness= cur_mathness= yes_math;
  2791. app('<');reduce(pp,1,binop,-2,84);
  2792.  
  2793. /*:148*/
  2794. #line 2283 "cweave.w"
  2795. ;break;
  2796. case prerangle:/*149:*/
  2797. #line 2768 "cweave.w"
  2798.  
  2799. init_mathness= cur_mathness= yes_math;
  2800. app('>');reduce(pp,1,binop,-2,85);
  2801.  
  2802. /*:149*/
  2803. #line 2284 "cweave.w"
  2804. ;break;
  2805. case langle:/*150:*/
  2806. #line 2772 "cweave.w"
  2807.  
  2808. if(cat1==exp&&cat2==prerangle)squash(pp,3,cast,-1,86);
  2809. else if(cat1==prerangle){
  2810. big_app1(pp);app('\\');app(',');big_app1(pp+1);
  2811.  
  2812. reduce(pp,2,cast,-1,87);
  2813. }
  2814. else if(cat1==decl_head||cat1==int_like){
  2815. if(cat2==prerangle)squash(pp,3,cast,-1,88);
  2816. else if(cat2==comma){
  2817. big_app3(pp);app(opt);app('9');reduce(pp,3,langle,0,89);
  2818. }
  2819. }
  2820.  
  2821. /*:150*/
  2822. #line 2285 "cweave.w"
  2823. ;break;
  2824. case public_like:/*151:*/
  2825. #line 2786 "cweave.w"
  2826.  
  2827. if(cat1==colon)squash(pp,2,tag,-1,90);
  2828. else squash(pp,1,int_like,-2,91);
  2829.  
  2830. /*:151*/
  2831. #line 2286 "cweave.w"
  2832. ;break;
  2833. case colcol:/*152:*/
  2834. #line 2790 "cweave.w"
  2835.  
  2836. if(cat1==exp||cat1==int_like)squash(pp,2,cat1,-2,92);
  2837.  
  2838. /*:152*/
  2839. #line 2287 "cweave.w"
  2840. ;break;
  2841. case new_like:/*153:*/
  2842. #line 2793 "cweave.w"
  2843.  
  2844. if(cat1==exp||(cat1==raw_int&&cat2!=prelangle&&cat2!=langle)){
  2845. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,new_like,0,93);
  2846. }
  2847. else if(cat1==raw_unorbin||cat1==colcol)
  2848. squash(pp,2,new_like,0,94);
  2849. else if(cat1==cast)squash(pp,2,exp,-2,95);
  2850. else if(cat1!=lpar&&cat1!=raw_int&&cat1!=struct_like)
  2851. squash(pp,1,exp,-2,96);
  2852.  
  2853. /*:153*/
  2854. #line 2288 "cweave.w"
  2855. ;break;
  2856. case operator_like:/*154:*/
  2857. #line 2803 "cweave.w"
  2858.  
  2859. if(cat1==binop||cat1==unop||cat1==unorbinop){
  2860. if(cat2==binop)break;
  2861. big_app1(pp);big_app('{');big_app1(pp+1);big_app('}');
  2862. reduce(pp,2,exp,-2,97);
  2863. }
  2864. else if(cat1==new_like||cat1==sizeof_like){
  2865. big_app1(pp);big_app(' ');big_app1(pp+1);reduce(pp,2,exp,-2,98);
  2866. }
  2867. else squash(pp,1,new_like,0,99);
  2868.  
  2869. /*:154*/
  2870. #line 2289 "cweave.w"
  2871. ;break;
  2872. case catch_like:/*155:*/
  2873. #line 2814 "cweave.w"
  2874.  
  2875. if(cat1==cast||cat1==exp){
  2876. big_app2(pp);big_app(indent);big_app(indent);
  2877. reduce(pp,2,fn_decl,0,100);
  2878. }
  2879.  
  2880. /*:155*/
  2881. #line 2290 "cweave.w"
  2882. ;break;
  2883. case base:/*156:*/
  2884. #line 2820 "cweave.w"
  2885.  
  2886. if(cat1==public_like&&cat2==exp){
  2887. if(cat3==comma){
  2888. big_app2(pp);big_app(' ');big_app2(pp+2);
  2889. reduce(pp,4,base,0,101);
  2890. }else{
  2891. big_app1(pp+1);big_app(' ');big_app1(pp+2);
  2892. reduce(pp+1,2,int_like,-1,102);
  2893. }
  2894. }
  2895.  
  2896. /*:156*/
  2897. #line 2291 "cweave.w"
  2898. ;break;
  2899. case raw_rpar:/*157:*/
  2900. #line 2831 "cweave.w"
  2901.  
  2902. if(cat1==const_like&&
  2903. (cat2==semi||cat2==lbrace||cat2==comma||cat2==binop
  2904. ||cat2==const_like)){
  2905. big_app1(pp);big_app(' ');
  2906. big_app1(pp+1);reduce(pp,2,raw_rpar,0,103);
  2907. }else squash(pp,1,rpar,-3,104);
  2908.  
  2909. /*:157*/
  2910. #line 2292 "cweave.w"
  2911. ;break;
  2912. case raw_unorbin:/*158:*/
  2913. #line 2839 "cweave.w"
  2914.  
  2915. if(cat1==const_like){
  2916. big_app2(pp);app_str("\\ ");reduce(pp,2,raw_unorbin,0,105);
  2917.  
  2918. }else squash(pp,1,unorbinop,-2,106);
  2919.  
  2920. /*:158*/
  2921. #line 2293 "cweave.w"
  2922. ;break;
  2923. case const_like:/*159:*/
  2924. #line 2845 "cweave.w"
  2925.  
  2926. squash(pp,1,int_like,-2,107);
  2927.  
  2928. /*:159*/
  2929. #line 2294 "cweave.w"
  2930. ;break;
  2931. case raw_int:/*160:*/
  2932. #line 2848 "cweave.w"
  2933.  
  2934. if(cat1==lpar)squash(pp,1,exp,-2,108);
  2935. else squash(pp,1,int_like,-3,109);
  2936.  
  2937. /*:160*/
  2938. #line 2295 "cweave.w"
  2939. ;break;
  2940. }
  2941. pp++;
  2942. }
  2943.  
  2944. /*:110*/
  2945. #line 2942 "cweave.w"
  2946. ;
  2947. }
  2948.  
  2949. /*:165*/
  2950. #line 3002 "cweave.w"
  2951. ;
  2952. /*170:*/
  2953. #line 3011 "cweave.w"
  2954. {
  2955. /*171:*/
  2956. #line 3023 "cweave.w"
  2957.  
  2958. if(lo_ptr>scrap_base&&tracing==1){
  2959. printf("\nIrreducible scrap sequence in section %d:",section_count);
  2960.  
  2961. mark_harmless;
  2962. for(j= scrap_base;j<=lo_ptr;j++){
  2963. printf(" ");print_cat(j->cat);
  2964. }
  2965. }
  2966.  
  2967. /*:171*/
  2968. #line 3012 "cweave.w"
  2969. ;
  2970. for(j= scrap_base;j<=lo_ptr;j++){
  2971. if(j!=scrap_base)app(' ');
  2972. if(j->mathness%4==yes_math)app('$');
  2973. app1(j);
  2974. if(j->mathness/4==yes_math)app('$');
  2975. if(tok_ptr+6>tok_mem_end)overflow("token");
  2976. }
  2977. freeze_text;return(text_ptr-1);
  2978. }
  2979.  
  2980. /*:170*/
  2981. #line 3003 "cweave.w"
  2982. ;
  2983. }
  2984.  
  2985. /*:169*//*173:*/
  2986. #line 3059 "cweave.w"
  2987.  
  2988. void
  2989. C_parse(spec_ctrl)
  2990. eight_bits spec_ctrl;
  2991. {
  2992. int count;
  2993. while(next_control<format_code||next_control==spec_ctrl){
  2994. /*175:*/
  2995. #line 3082 "cweave.w"
  2996.  
  2997. /*176:*/
  2998. #line 3156 "cweave.w"
  2999.  
  3000. if(scrap_ptr+safe_scrap_incr>scrap_info_end||
  3001. tok_ptr+safe_tok_incr>tok_mem_end||
  3002. text_ptr+safe_text_incr>tok_start_end){
  3003. if(scrap_ptr>max_scr_ptr)max_scr_ptr= scrap_ptr;
  3004. if(tok_ptr>max_tok_ptr)max_tok_ptr= tok_ptr;
  3005. if(text_ptr>max_text_ptr)max_text_ptr= text_ptr;
  3006. overflow("scrap/token/text");
  3007. }
  3008.  
  3009. /*:176*/
  3010. #line 3083 "cweave.w"
  3011. ;
  3012. switch(next_control){
  3013. case section_name:
  3014. app(section_flag+(int)(cur_section-name_dir));
  3015. app_scrap(section_scrap,maybe_math);
  3016. app_scrap(exp,yes_math);break;
  3017. case string:case constant:case verbatim:/*178:*/
  3018. #line 3211 "cweave.w"
  3019.  
  3020. count= -1;
  3021. if(next_control==constant)app_str("\\T{");
  3022.  
  3023. else if(next_control==string){
  3024. count= 20;app_str("\\.{");
  3025. }
  3026.  
  3027. else app_str("\\vb{");
  3028.  
  3029. while(id_first<id_loc){
  3030. if(count==0){
  3031. app_str("}\\)\\.{");count= 20;
  3032.  
  3033. }
  3034.  
  3035. if((eight_bits)(*id_first)>0177){
  3036. app_tok(quoted_char);
  3037. app_tok((eight_bits)(*id_first++));
  3038. }
  3039. else{
  3040. switch(*id_first){
  3041. case' ':case'\\':case'#':case'%':case'$':case'^':
  3042. case'{':case'}':case'~':case'&':case'_':app('\\');break;
  3043.  
  3044.  
  3045.  
  3046.  
  3047.  
  3048.  
  3049.  
  3050.  
  3051.  
  3052.  
  3053.  
  3054. case'@':if(*(id_first+1)=='@')id_first++;
  3055. else err_print("! Double @ should be used in strings");
  3056.  
  3057. }
  3058. app_tok(*id_first++);
  3059. }
  3060. count--;
  3061. }
  3062. app('}');
  3063. app_scrap(exp,maybe_math);
  3064.  
  3065. /*:178*/
  3066. #line 3089 "cweave.w"
  3067. ;
  3068. break;
  3069. case identifier:app_cur_id(1);break;
  3070. case TeX_string:/*179:*/
  3071. #line 3272 "cweave.w"
  3072.  
  3073. app_str("\\hbox{");
  3074.  
  3075. while(id_first<id_loc)
  3076. if((eight_bits)(*id_first)>0177){
  3077. app_tok(quoted_char);
  3078. app_tok((eight_bits)(*id_first++));
  3079. }
  3080. else{
  3081. if(*id_first=='@')id_first++;
  3082. app_tok(*id_first++);
  3083. }
  3084. app('}');
  3085.  
  3086. /*:179*/
  3087. #line 3092 "cweave.w"
  3088. ;break;
  3089. case'/':case'.':
  3090. app(next_control);app_scrap(binop,yes_math);break;
  3091. case'<':app_str("\\langle");app_scrap(prelangle,yes_math);break;
  3092.  
  3093. case'>':app_str("\\rangle");app_scrap(prerangle,yes_math);break;
  3094.  
  3095. case'=':app_str("\\K");app_scrap(binop,yes_math);break;
  3096.  
  3097. case'|':app_str("\\OR");app_scrap(binop,yes_math);break;
  3098.  
  3099. case'^':app_str("\\XOR");app_scrap(binop,yes_math);break;
  3100.  
  3101. case'%':app_str("\\MOD");app_scrap(binop,yes_math);break;
  3102.  
  3103. case'!':app_str("\\R");app_scrap(unop,yes_math);break;
  3104.  
  3105. case'~':app_str("\\CM");app_scrap(unop,yes_math);break;
  3106.  
  3107. case'+':case'-':app(next_control);app_scrap(unorbinop,yes_math);break;
  3108. case'*':app(next_control);app_scrap(raw_unorbin,yes_math);break;
  3109. case'&':app_str("\\AND");app_scrap(raw_unorbin,yes_math);break;
  3110.  
  3111. case'?':app_str("\\?");app_scrap(question,yes_math);break;
  3112.  
  3113. case'#':app_str("\\#");app_scrap(unorbinop,yes_math);break;
  3114.  
  3115. case ignore:case xref_roman:case xref_wildcard:
  3116. case xref_typewriter:case noop:break;
  3117. case'(':case'[':app(next_control);app_scrap(lpar,maybe_math);break;
  3118. case')':case']':app(next_control);app_scrap(raw_rpar,maybe_math);break;
  3119. case'{':app_str("\\{");app_scrap(lbrace,yes_math);break;
  3120.  
  3121. case'}':app_str("\\}");app_scrap(rbrace,yes_math);break;
  3122.  
  3123. case',':app(',');app_scrap(comma,yes_math);break;
  3124. case';':app(';');app_scrap(semi,maybe_math);break;
  3125. case':':app(':');app_scrap(colon,maybe_math);break;
  3126. /*177:*/
  3127. #line 3170 "cweave.w"
  3128.  
  3129. case not_eq:app_str("\\I");app_scrap(binop,yes_math);break;
  3130.  
  3131. case lt_eq:app_str("\\Z");app_scrap(binop,yes_math);break;
  3132.  
  3133. case gt_eq:app_str("\\G");app_scrap(binop,yes_math);break;
  3134.  
  3135. case eq_eq:app_str("\\E");app_scrap(binop,yes_math);break;
  3136.  
  3137. case and_and:app_str("\\W");app_scrap(binop,yes_math);break;
  3138.  
  3139. case or_or:app_str("\\V");app_scrap(binop,yes_math);break;
  3140.  
  3141. case plus_plus:app_str("\\PP");app_scrap(unop,yes_math);break;
  3142.  
  3143. case minus_minus:app_str("\\MM");app_scrap(unop,yes_math);break;
  3144.  
  3145. case minus_gt:app_str("\\MG");app_scrap(binop,yes_math);break;
  3146.  
  3147. case gt_gt:app_str("\\GG");app_scrap(binop,yes_math);break;
  3148.  
  3149. case lt_lt:app_str("\\LL");app_scrap(binop,yes_math);break;
  3150.  
  3151. case dot_dot_dot:app_str("\\,\\ldots\\,");app_scrap(exp,yes_math);break;
  3152.  
  3153.  
  3154. case colon_colon:app_str("\\DC");app_scrap(colcol,maybe_math);break;
  3155.  
  3156. case period_ast:app_str("\\PA");app_scrap(binop,yes_math);break;
  3157.  
  3158. case minus_gt_ast:app_str("\\MGA");app_scrap(binop,yes_math);break;
  3159.  
  3160.  
  3161. /*:177*/
  3162. #line 3130 "cweave.w"
  3163.  
  3164. case thin_space:app_str("\\,");app_scrap(insert,maybe_math);break;
  3165.  
  3166. case math_break:app(opt);app_str("0");
  3167. app_scrap(insert,maybe_math);break;
  3168. case line_break:app(force);app_scrap(insert,no_math);break;
  3169. case left_preproc:app(force);app(preproc_line);
  3170. app_str("\\#");app_scrap(lproc,no_math);break;
  3171.  
  3172. case right_preproc:app(force);app_scrap(rproc,no_math);break;
  3173. case big_line_break:app(big_force);app_scrap(insert,no_math);break;
  3174. case no_line_break:app(big_cancel);app(noop);app(break_space);
  3175. app(noop);app(big_cancel);
  3176. app_scrap(insert,no_math);break;
  3177. case pseudo_semi:app_scrap(semi,maybe_math);break;
  3178. case macro_arg_open:app_scrap(begin_arg,maybe_math);break;
  3179. case macro_arg_close:app_scrap(end_arg,maybe_math);break;
  3180. case join:app_str("\\J");app_scrap(insert,no_math);break;
  3181.  
  3182. case output_defs_code:app(force);app_str("\\ATH");app(force);
  3183. app_scrap(insert,no_math);break;
  3184.  
  3185. default:app(inserted);app(next_control);
  3186. app_scrap(insert,maybe_math);break;
  3187. }
  3188.  
  3189. /*:175*/
  3190. #line 3066 "cweave.w"
  3191. ;
  3192. next_control= get_next();
  3193. if(next_control=='|'||next_control==begin_comment||
  3194. next_control==begin_short_comment)return;
  3195. }
  3196. }
  3197.  
  3198. /*:173*//*181:*/
  3199. #line 3292 "cweave.w"
  3200.  
  3201. void
  3202. app_cur_id(scrapping)
  3203. boolean scrapping;
  3204. {
  3205. name_pointer p= id_lookup(id_first,id_loc,normal);
  3206. if(p->ilk<=quoted){
  3207. app(id_flag+(int)(p-name_dir));
  3208. if(scrapping)app_scrap(exp,p->ilk>=custom?yes_math:maybe_math);
  3209.  
  3210. }else{
  3211. app(res_flag+(int)(p-name_dir));
  3212. if(scrapping)app_scrap(p->ilk,maybe_math);
  3213. }
  3214. }
  3215.  
  3216. /*:181*//*182:*/
  3217. #line 3313 "cweave.w"
  3218.  
  3219. text_pointer
  3220. C_translate()
  3221. {
  3222. text_pointer p;
  3223. scrap_pointer save_base;
  3224. save_base= scrap_base;scrap_base= scrap_ptr+1;
  3225. C_parse(section_name);
  3226. if(next_control!='|')err_print("! Missing '|' after C text");
  3227.  
  3228. app_tok(cancel);app_scrap(insert,maybe_math);
  3229.  
  3230. p= translate();
  3231. if(scrap_ptr>max_scr_ptr)max_scr_ptr= scrap_ptr;
  3232. scrap_ptr= scrap_base-1;scrap_base= save_base;
  3233. return(p);
  3234. }
  3235.  
  3236. /*:182*//*183:*/
  3237. #line 3335 "cweave.w"
  3238.  
  3239. void
  3240. outer_parse()
  3241. {
  3242. int bal;
  3243. text_pointer p,q;
  3244. while(next_control<format_code)
  3245. if(next_control!=begin_comment&&next_control!=begin_short_comment)
  3246. C_parse(ignore);
  3247. else{
  3248. boolean is_long_comment= (next_control==begin_comment);
  3249. /*176:*/
  3250. #line 3156 "cweave.w"
  3251.  
  3252. if(scrap_ptr+safe_scrap_incr>scrap_info_end||
  3253. tok_ptr+safe_tok_incr>tok_mem_end||
  3254. text_ptr+safe_text_incr>tok_start_end){
  3255. if(scrap_ptr>max_scr_ptr)max_scr_ptr= scrap_ptr;
  3256. if(tok_ptr>max_tok_ptr)max_tok_ptr= tok_ptr;
  3257. if(text_ptr>max_text_ptr)max_text_ptr= text_ptr;
  3258. overflow("scrap/token/text");
  3259. }
  3260.  
  3261. /*:176*/
  3262. #line 3346 "cweave.w"
  3263. ;
  3264. app(cancel);app(inserted);
  3265. if(is_long_comment)app_str("\\C{");
  3266.  
  3267. else app_str("\\SHC{");
  3268.  
  3269. bal= copy_comment(is_long_comment,1);next_control= ignore;
  3270. while(bal>0){
  3271. p= text_ptr;freeze_text;q= C_translate();
  3272.  
  3273. app(tok_flag+(int)(p-tok_start));
  3274. app_str("\\PB{");app(inner_tok_flag+(int)(q-tok_start));app_tok('}');
  3275.  
  3276. if(next_control=='|'){
  3277. bal= copy_comment(is_long_comment,bal);
  3278. next_control= ignore;
  3279. }
  3280. else bal= 0;
  3281. }
  3282. app(force);app_scrap(insert,no_math);
  3283.  
  3284. }
  3285. }
  3286.  
  3287. /*:183*//*188:*/
  3288. #line 3439 "cweave.w"
  3289.  
  3290. void
  3291. push_level(p)
  3292. text_pointer p;
  3293. {
  3294. if(stack_ptr==stack_end)overflow("stack");
  3295. if(stack_ptr>stack){
  3296. stack_ptr->end_field= cur_end;
  3297. stack_ptr->tok_field= cur_tok;
  3298. stack_ptr->mode_field= cur_mode;
  3299. }
  3300. stack_ptr++;
  3301. if(stack_ptr>max_stack_ptr)max_stack_ptr= stack_ptr;
  3302. cur_tok= *p;cur_end= *(p+1);
  3303. }
  3304.  
  3305. /*:188*//*189:*/
  3306. #line 3459 "cweave.w"
  3307.  
  3308. void
  3309. pop_level()
  3310. {
  3311. cur_end= (--stack_ptr)->end_field;
  3312. cur_tok= stack_ptr->tok_field;cur_mode= stack_ptr->mode_field;
  3313. }
  3314.  
  3315. /*:189*//*191:*/
  3316. #line 3481 "cweave.w"
  3317.  
  3318. eight_bits
  3319. get_output()
  3320. {
  3321. sixteen_bits a;
  3322. restart:while(cur_tok==cur_end)pop_level();
  3323. a= *(cur_tok++);
  3324. if(a>=0400){
  3325. cur_name= a%id_flag+name_dir;
  3326. switch(a/id_flag){
  3327. case 2:return(res_word);
  3328. case 3:return(section_code);
  3329. case 4:push_level(a%id_flag+tok_start);goto restart;
  3330.  
  3331. case 5:push_level(a%id_flag+tok_start);cur_mode= inner;goto restart;
  3332.  
  3333. default:return(identifier);
  3334. }
  3335. }
  3336. return(a);
  3337. }
  3338.  
  3339. /*:191*//*192:*/
  3340. #line 3523 "cweave.w"
  3341.  
  3342. void
  3343. output_C()
  3344. {
  3345. token_pointer save_tok_ptr;
  3346. text_pointer save_text_ptr;
  3347. sixteen_bits save_next_control;
  3348. text_pointer p;
  3349. save_tok_ptr= tok_ptr;save_text_ptr= text_ptr;
  3350. save_next_control= next_control;next_control= ignore;p= C_translate();
  3351. app(inner_tok_flag+(int)(p-tok_start));
  3352. out_str("\\PB{");make_output();out('}');
  3353.  
  3354. if(text_ptr>max_text_ptr)max_text_ptr= text_ptr;
  3355. if(tok_ptr>max_tok_ptr)max_tok_ptr= tok_ptr;
  3356. text_ptr= save_text_ptr;tok_ptr= save_tok_ptr;
  3357. next_control= save_next_control;
  3358. }
  3359.  
  3360. /*:192*//*194:*/
  3361. #line 3547 "cweave.w"
  3362.  
  3363. void
  3364. make_output()
  3365. {
  3366. eight_bits a,
  3367. b;
  3368. int c;
  3369. char scratch[longest_name];
  3370. char*k,*k_limit;
  3371. char*j;
  3372. char*p;
  3373. char delim;
  3374. char*save_loc,*save_limit;
  3375. name_pointer cur_section_name;
  3376. boolean save_mode;
  3377. app(end_translation);
  3378. freeze_text;push_level(text_ptr-1);
  3379. while(1){
  3380. a= get_output();
  3381. reswitch:switch(a){
  3382. case end_translation:return;
  3383. case identifier:case res_word:/*195:*/
  3384. #line 3597 "cweave.w"
  3385.  
  3386. out('\\');
  3387. if(a==identifier){
  3388. if(cur_name->ilk>=custom&&cur_name->ilk<=quoted&&!doing_format){
  3389. for(p= cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
  3390. out(isxalpha(*p)?'x':*p);
  3391. break;
  3392. }else if(is_tiny(cur_name))out('|')
  3393.  
  3394. else{delim= '.';
  3395. for(p= cur_name->byte_start;p<(cur_name+1)->byte_start;p++)
  3396. if(xislower(*p)){
  3397. delim= '\\';break;
  3398. }
  3399. out(delim);
  3400. }
  3401.  
  3402.  
  3403. }
  3404. else out('&')
  3405.  
  3406. if(is_tiny(cur_name)){
  3407. if(isxalpha((cur_name->byte_start)[0]))
  3408. out('\\');
  3409. out((cur_name->byte_start)[0]);
  3410. }
  3411. else out_name(cur_name);
  3412.  
  3413. /*:195*/
  3414. #line 3568 "cweave.w"
  3415. ;break;
  3416. case section_code:/*199:*/
  3417. #line 3695 "cweave.w"
  3418. {
  3419. out_str("\\X");
  3420.  
  3421. cur_xref= (xref_pointer)cur_name->xref;
  3422. if(cur_xref->num==file_flag){an_output= 1;cur_xref= cur_xref->xlink;}
  3423. else an_output= 0;
  3424. if(cur_xref->num>=def_flag){
  3425. out_section(cur_xref->num-def_flag);
  3426. if(phase==3){
  3427. cur_xref= cur_xref->xlink;
  3428. while(cur_xref->num>=def_flag){
  3429. out_str(", ");
  3430. out_section(cur_xref->num-def_flag);
  3431. cur_xref= cur_xref->xlink;
  3432. }
  3433. }
  3434. }
  3435. else out('0');
  3436. out(':');
  3437. if(an_output)out_str("\\.{");
  3438.  
  3439. /*200:*/
  3440. #line 3721 "cweave.w"
  3441.  
  3442. sprint_section_name(scratch,cur_name);
  3443. k= scratch;
  3444. k_limit= scratch+strlen(scratch);
  3445. cur_section_name= cur_name;
  3446. while(k<k_limit){
  3447. b= *(k++);
  3448. if(b=='@')/*201:*/
  3449. #line 3756 "cweave.w"
  3450.  
  3451. if(*k++!='@'){
  3452. printf("\n! Illegal control code in section name: <");
  3453.  
  3454. print_section_name(cur_section_name);printf("> ");mark_error;
  3455. }
  3456.  
  3457. /*:201*/
  3458. #line 3728 "cweave.w"
  3459. ;
  3460. if(an_output)
  3461. switch(b){
  3462. case' ':case'\\':case'#':case'%':case'$':case'^':
  3463. case'{':case'}':case'~':case'&':case'_':
  3464. out('\\');
  3465.  
  3466.  
  3467.  
  3468.  
  3469.  
  3470.  
  3471.  
  3472.  
  3473.  
  3474.  
  3475.  
  3476. default:out(b);
  3477. }
  3478. else if(b!='|')out(b)
  3479. else{
  3480. /*202:*/
  3481. #line 3769 "cweave.w"
  3482.  
  3483. j= limit+1;*j= '|';delim= 0;
  3484. while(1){
  3485. if(k>=k_limit){
  3486. printf("\n! C text in section name didn't end: <");
  3487.  
  3488. print_section_name(cur_section_name);printf("> ");mark_error;break;
  3489. }
  3490. b= *(k++);
  3491. if(b=='@'||(b=='\\'&&delim!=0))
  3492. /*203:*/
  3493. #line 3792 "cweave.w"
  3494. {
  3495. if(j>buffer+long_buf_size-4)overflow("buffer");
  3496. *(++j)= b;*(++j)= *(k++);
  3497. }
  3498.  
  3499. /*:203*/
  3500. #line 3779 "cweave.w"
  3501.  
  3502. else{
  3503. if(b=='\''||b=='"')
  3504. if(delim==0)delim= b;
  3505. else if(delim==b)delim= 0;
  3506. if(b!='|'||delim!=0){
  3507. if(j>buffer+long_buf_size-3)overflow("buffer");
  3508. *(++j)= b;
  3509. }
  3510. else break;
  3511. }
  3512. }
  3513.  
  3514. /*:202*/
  3515. #line 3749 "cweave.w"
  3516. ;
  3517. save_loc= loc;save_limit= limit;loc= limit+2;limit= j+1;
  3518. *limit= '|';output_C();
  3519. loc= save_loc;limit= save_limit;
  3520. }
  3521. }
  3522.  
  3523. /*:200*/
  3524. #line 3716 "cweave.w"
  3525. ;
  3526. if(an_output)out_str(" }");
  3527. out_str("\\X");
  3528. }
  3529.  
  3530. /*:199*/
  3531. #line 3569 "cweave.w"
  3532. ;break;
  3533. case math_rel:out_str("\\MRL{");
  3534.  
  3535. case noop:case inserted:break;
  3536. case cancel:case big_cancel:c= 0;b= a;
  3537. while(1){
  3538. a= get_output();
  3539. if(a==inserted)continue;
  3540. if((a<indent&&!(b==big_cancel&&a==' '))||a>big_force)break;
  3541. if(a==indent)c++;else if(a==outdent)c--;
  3542. else if(a==opt)a= get_output();
  3543. }
  3544. /*198:*/
  3545. #line 3682 "cweave.w"
  3546.  
  3547. for(;c>0;c--)out_str("\\1");
  3548.  
  3549. for(;c<0;c++)out_str("\\2");
  3550.  
  3551.  
  3552. /*:198*/
  3553. #line 3581 "cweave.w"
  3554. ;
  3555. goto reswitch;
  3556. case indent:case outdent:case opt:case backup:case break_space:
  3557. case force:case big_force:case preproc_line:/*196:*/
  3558. #line 3628 "cweave.w"
  3559.  
  3560. if(a<break_space||a==preproc_line){
  3561. if(cur_mode==outer){
  3562. out('\\');out(a-cancel+'0');
  3563.  
  3564.  
  3565.  
  3566.  
  3567.  
  3568. if(a==opt){
  3569. b= get_output();
  3570. if(b!='0'||force_lines==0)out(b)
  3571. else out_str("{-1}");
  3572. }
  3573. }else if(a==opt)b= get_output();
  3574. }
  3575. else/*197:*/
  3576. #line 3652 "cweave.w"
  3577. {
  3578. b= a;save_mode= cur_mode;c= 0;
  3579. while(1){
  3580. a= get_output();
  3581. if(a==inserted)continue;
  3582. if(a==cancel||a==big_cancel){
  3583. /*198:*/
  3584. #line 3682 "cweave.w"
  3585.  
  3586. for(;c>0;c--)out_str("\\1");
  3587.  
  3588. for(;c<0;c++)out_str("\\2");
  3589.  
  3590.  
  3591. /*:198*/
  3592. #line 3658 "cweave.w"
  3593. ;
  3594. goto reswitch;
  3595. }
  3596. if((a!=' '&&a<indent)||a==backup||a>big_force){
  3597. if(save_mode==outer){
  3598. if(out_ptr>out_buf+3&&strncmp(out_ptr-3,"\\Y\\B",4)==0)
  3599. goto reswitch;
  3600. /*198:*/
  3601. #line 3682 "cweave.w"
  3602.  
  3603. for(;c>0;c--)out_str("\\1");
  3604.  
  3605. for(;c<0;c++)out_str("\\2");
  3606.  
  3607.  
  3608. /*:198*/
  3609. #line 3665 "cweave.w"
  3610. ;
  3611. out('\\');out(b-cancel+'0');
  3612.  
  3613.  
  3614.  
  3615. if(a!=end_translation)finish_line();
  3616. }
  3617. else if(a!=end_translation&&cur_mode==inner)out(' ');
  3618. goto reswitch;
  3619. }
  3620. if(a==indent)c++;
  3621. else if(a==outdent)c--;
  3622. else if(a==opt)a= get_output();
  3623. else if(a>b)b= a;
  3624. }
  3625. }
  3626.  
  3627. /*:197*/
  3628. #line 3644 "cweave.w"
  3629.  
  3630.  
  3631. /*:196*/
  3632. #line 3585 "cweave.w"
  3633. ;break;
  3634. case quoted_char:out(*(cur_tok++));break;
  3635. default:out(a);
  3636. }
  3637. }
  3638. }
  3639.  
  3640. /*:194*//*205:*/
  3641. #line 3807 "cweave.w"
  3642.  
  3643. void
  3644. phase_two(){
  3645. reset_input();if(show_progress)printf("\nWriting the output file...");
  3646.  
  3647. section_count= 0;format_visible= 1;copy_limbo();
  3648. finish_line();flush_buffer(out_buf,0,0);
  3649. while(!input_has_ended)/*207:*/
  3650. #line 3840 "cweave.w"
  3651. {
  3652. section_count++;
  3653. /*208:*/
  3654. #line 3858 "cweave.w"
  3655.  
  3656. if(*(loc-1)!='*')out_str("\\M");
  3657.  
  3658. else{
  3659. while(*loc==' ')loc++;
  3660. if(*loc=='*'){
  3661. sec_depth= -1;
  3662. loc++;
  3663. }
  3664. else{
  3665. for(sec_depth= 0;xisdigit(*loc);loc++)
  3666. sec_depth= sec_depth*10+(*loc)-'0';
  3667. }
  3668. while(*loc==' ')loc++;
  3669. group_found= 1;
  3670. out_str("\\N");
  3671.  
  3672. {char s[32];sprintf(s,"{%d}",sec_depth+1);out_str(s);}
  3673. if(show_progress)
  3674. printf("*%d",section_count);update_terminal;
  3675. }
  3676. out_str("{");out_section(section_count);out_str("}");
  3677.  
  3678. /*:208*/
  3679. #line 3842 "cweave.w"
  3680. ;
  3681. save_position;
  3682. /*209:*/
  3683. #line 3884 "cweave.w"
  3684. do{
  3685. next_control= copy_TeX();
  3686. switch(next_control){
  3687. case'|':init_stack;output_C();break;
  3688. case'@':out('@');break;
  3689. case TeX_string:case noop:
  3690. case xref_roman:case xref_wildcard:case xref_typewriter:
  3691. case section_name:loc-= 2;next_control= get_next();
  3692. if(next_control==TeX_string)
  3693. err_print("! TeX string should be in C text only");break;
  3694.  
  3695. case thin_space:case math_break:case ord:
  3696. case line_break:case big_line_break:case no_line_break:case join:
  3697. case pseudo_semi:case macro_arg_open:case macro_arg_close:
  3698. case output_defs_code:
  3699. err_print("! You can't do that in TeX text");break;
  3700.  
  3701. }
  3702. }while(next_control<format_code);
  3703.  
  3704. /*:209*/
  3705. #line 3844 "cweave.w"
  3706. ;
  3707. /*210:*/
  3708. #line 3907 "cweave.w"
  3709.  
  3710. space_checked= 0;
  3711. while(next_control<=definition){
  3712. init_stack;
  3713. if(next_control==definition)/*213:*/
  3714. #line 3965 "cweave.w"
  3715. {
  3716. if(save_line!=out_line||save_place!=out_ptr||space_checked)app(backup);
  3717. if(!space_checked){emit_space_if_needed;save_position;}
  3718. app_str("\\D");
  3719.  
  3720. if((next_control= get_next())!=identifier)
  3721. err_print("! Improper macro definition");
  3722.  
  3723. else{
  3724. app('$');app_cur_id(0);
  3725. if(*loc=='(')
  3726. reswitch:switch(next_control= get_next()){
  3727. case'(':case',':app(next_control);goto reswitch;
  3728. case identifier:app_cur_id(0);goto reswitch;
  3729. case')':app(next_control);next_control= get_next();break;
  3730. default:err_print("! Improper macro definition");break;
  3731. }
  3732. else next_control= get_next();
  3733. app_str("$ ");app(break_space);
  3734. app_scrap(dead,no_math);
  3735. }
  3736. }
  3737.  
  3738. /*:213*/
  3739. #line 3911 "cweave.w"
  3740.  
  3741. else/*214:*/
  3742. #line 3988 "cweave.w"
  3743. {
  3744. doing_format= 1;
  3745. if(*(loc-1)=='s'||*(loc-1)=='S')format_visible= 0;
  3746. if(!space_checked){emit_space_if_needed;save_position;}
  3747. app_str("\\F");
  3748.  
  3749. next_control= get_next();
  3750. if(next_control==identifier){
  3751. app(id_flag+(int)(id_lookup(id_first,id_loc,normal)-name_dir));
  3752. app(' ');
  3753. app(break_space);
  3754. next_control= get_next();
  3755. if(next_control==identifier){
  3756. app(id_flag+(int)(id_lookup(id_first,id_loc,normal)-name_dir));
  3757. app_scrap(exp,maybe_math);app_scrap(semi,maybe_math);
  3758. next_control= get_next();
  3759. }
  3760. }
  3761. if(scrap_ptr!=scrap_info+2)err_print("! Improper format definition");
  3762.  
  3763. }
  3764.  
  3765. /*:214*/
  3766. #line 3912 "cweave.w"
  3767. ;
  3768. outer_parse();finish_C(format_visible);format_visible= 1;
  3769. doing_format= 0;
  3770. }
  3771.  
  3772. /*:210*/
  3773. #line 3845 "cweave.w"
  3774. ;
  3775. /*216:*/
  3776. #line 4017 "cweave.w"
  3777.  
  3778. this_section= name_dir;
  3779. if(next_control<=section_name){
  3780. emit_space_if_needed;init_stack;
  3781. if(next_control==begin_C)next_control= get_next();
  3782. else{
  3783. this_section= cur_section;
  3784. /*217:*/
  3785. #line 4037 "cweave.w"
  3786.  
  3787. do next_control= get_next();
  3788. while(next_control=='+');
  3789. if(next_control!='='&&next_control!=eq_eq)
  3790. err_print("! You need an = sign after the section name");
  3791.  
  3792. else next_control= get_next();
  3793. if(out_ptr>out_buf+1&&*out_ptr=='Y'&&*(out_ptr-1)=='\\')app(backup);
  3794.  
  3795.  
  3796. app(section_flag+(int)(this_section-name_dir));
  3797. cur_xref= (xref_pointer)this_section->xref;
  3798. if(cur_xref->num==file_flag)cur_xref= cur_xref->xlink;
  3799. app_str("${}");
  3800. if(cur_xref->num!=section_count+def_flag){
  3801. app_str("\\mathrel+");
  3802. this_section= name_dir;
  3803. }
  3804. app_str("\\E");
  3805.  
  3806. app_str("{}$");
  3807. app(force);app_scrap(dead,no_math);
  3808.  
  3809.  
  3810. /*:217*/
  3811. #line 4025 "cweave.w"
  3812. ;
  3813. }
  3814. while(next_control<=section_name){
  3815. outer_parse();
  3816. /*218:*/
  3817. #line 4061 "cweave.w"
  3818.  
  3819. if(next_control<section_name){
  3820. err_print("! You can't do that in C text");
  3821.  
  3822. next_control= get_next();
  3823. }
  3824. else if(next_control==section_name){
  3825. app(section_flag+(int)(cur_section-name_dir));
  3826. app_scrap(section_scrap,maybe_math);
  3827. next_control= get_next();
  3828. }
  3829.  
  3830. /*:218*/
  3831. #line 4029 "cweave.w"
  3832. ;
  3833. }
  3834. finish_C(1);
  3835. }
  3836.  
  3837. /*:216*/
  3838. #line 3846 "cweave.w"
  3839. ;
  3840. /*219:*/
  3841. #line 4076 "cweave.w"
  3842.  
  3843. if(this_section>name_dir){
  3844. cur_xref= (xref_pointer)this_section->xref;
  3845. if(cur_xref->num==file_flag){an_output= 1;cur_xref= cur_xref->xlink;}
  3846. else an_output= 0;
  3847. if(cur_xref->num>def_flag)
  3848. cur_xref= cur_xref->xlink;
  3849. footnote(def_flag);footnote(cite_flag);footnote(0);
  3850. }
  3851.  
  3852. /*:219*/
  3853. #line 3847 "cweave.w"
  3854. ;
  3855. /*223:*/
  3856. #line 4134 "cweave.w"
  3857.  
  3858. out_str("\\fi");finish_line();
  3859.  
  3860. flush_buffer(out_buf,0,0);
  3861.  
  3862. /*:223*/
  3863. #line 3848 "cweave.w"
  3864. ;
  3865. }
  3866.  
  3867. /*:207*/
  3868. #line 3814 "cweave.w"
  3869. ;
  3870. }
  3871.  
  3872. /*:205*//*212:*/
  3873. #line 3930 "cweave.w"
  3874.  
  3875. void
  3876. finish_C(visible)
  3877. boolean visible;
  3878. {
  3879. text_pointer p;
  3880. if(visible){
  3881. out_str("\\B");app_tok(force);app_scrap(insert,no_math);
  3882. p= translate();
  3883.  
  3884. app(tok_flag+(int)(p-tok_start));make_output();
  3885. if(out_ptr>out_buf+1)
  3886. if(*(out_ptr-1)=='\\')
  3887.  
  3888.  
  3889.  
  3890. if(*out_ptr=='6')out_ptr-= 2;
  3891. else if(*out_ptr=='7')*out_ptr= 'Y';
  3892. out_str("\\par");finish_line();
  3893. }
  3894. if(text_ptr>max_text_ptr)max_text_ptr= text_ptr;
  3895. if(tok_ptr>max_tok_ptr)max_tok_ptr= tok_ptr;
  3896. if(scrap_ptr>max_scr_ptr)max_scr_ptr= scrap_ptr;
  3897. tok_ptr= tok_mem+1;text_ptr= tok_start+1;scrap_ptr= scrap_info;
  3898.  
  3899. }
  3900.  
  3901. /*:212*//*221:*/
  3902. #line 4101 "cweave.w"
  3903.  
  3904. void
  3905. footnote(flag)
  3906. sixteen_bits flag;
  3907. {
  3908. xref_pointer q;
  3909. if(cur_xref->num<=flag)return;
  3910. finish_line();out('\\');
  3911.  
  3912.  
  3913.  
  3914. out(flag==0?'U':flag==cite_flag?'Q':'A');
  3915. /*222:*/
  3916. #line 4121 "cweave.w"
  3917.  
  3918. q= cur_xref;if(q->xlink->num>flag)out('s');
  3919. while(1){
  3920. out_section(cur_xref->num-flag);
  3921. cur_xref= cur_xref->xlink;
  3922. if(cur_xref->num<=flag)break;
  3923. if(cur_xref->xlink->num>flag)out_str(", ");
  3924. else{out_str("\\ET");
  3925.  
  3926. if(cur_xref!=q->xlink)out('s');
  3927. }
  3928. }
  3929.  
  3930. /*:222*/
  3931. #line 4113 "cweave.w"
  3932. ;
  3933. out('.');
  3934. }
  3935.  
  3936. /*:221*//*225:*/
  3937. #line 4150 "cweave.w"
  3938.  
  3939. void
  3940. phase_three(){
  3941. if(no_xref){
  3942. finish_line();
  3943. out_str("\\end");
  3944.  
  3945. finish_line();
  3946. }
  3947. else{
  3948. phase= 3;if(show_progress)printf("\nWriting the index...");
  3949.  
  3950. finish_line();
  3951. if((idx_file= fopen(idx_file_name,"w"))==NULL)
  3952. fatal("! Cannot open index file ",idx_file_name);
  3953.  
  3954. if(change_exists){
  3955. /*227:*/
  3956. #line 4201 "cweave.w"
  3957. {
  3958.  
  3959. k_section= 0;
  3960. while(!changed_section[++k_section]);
  3961. out_str("\\ch ");
  3962.  
  3963. out_section(k_section);
  3964. while(k_section<section_count){
  3965. while(!changed_section[++k_section]);
  3966. out_str(", ");out_section(k_section);
  3967. }
  3968. out('.');
  3969. }
  3970.  
  3971. /*:227*/
  3972. #line 4167 "cweave.w"
  3973. ;finish_line();finish_line();
  3974. }
  3975. out_str("\\inx");finish_line();
  3976.  
  3977. active_file= idx_file;
  3978. /*229:*/
  3979. #line 4232 "cweave.w"
  3980. {
  3981. int c;
  3982. for(c= 0;c<=255;c++)bucket[c]= NULL;
  3983. for(h= hash;h<=hash_end;h++){
  3984. next_name= *h;
  3985. while(next_name){
  3986. cur_name= next_name;next_name= cur_name->link;
  3987. if(cur_name->xref!=(char*)xmem){
  3988. c= (eight_bits)((cur_name->byte_start)[0]);
  3989. if(xisupper(c))c= tolower(c);
  3990. blink[cur_name-name_dir]= bucket[c];bucket[c]= cur_name;
  3991. }
  3992. }
  3993. }
  3994. }
  3995.  
  3996. /*:229*/
  3997. #line 4172 "cweave.w"
  3998. ;
  3999. /*238:*/
  4000. #line 4348 "cweave.w"
  4001.  
  4002. sort_ptr= scrap_info;unbucket(1);
  4003. while(sort_ptr>scrap_info){
  4004. cur_depth= sort_ptr->depth;
  4005. if(blink[sort_ptr->head-name_dir]==0||cur_depth==infinity)
  4006. /*240:*/
  4007. #line 4373 "cweave.w"
  4008. {
  4009. cur_name= sort_ptr->head;
  4010. do{
  4011. out_str("\\I");
  4012.  
  4013. /*241:*/
  4014. #line 4385 "cweave.w"
  4015.  
  4016. switch(cur_name->ilk){
  4017. case normal:if(is_tiny(cur_name))out_str("\\|");
  4018. else{char*j;
  4019. for(j= cur_name->byte_start;j<(cur_name+1)->byte_start;j++)
  4020. if(xislower(*j))goto lowcase;
  4021. out_str("\\.");break;
  4022. lowcase:out_str("\\\\");
  4023. }
  4024. break;
  4025.  
  4026.  
  4027.  
  4028. case roman:break;
  4029. case wildcard:out_str("\\9");break;
  4030.  
  4031. case typewriter:out_str("\\.");break;
  4032.  
  4033. case custom:case quoted:{char*j;out_str("$\\");
  4034. for(j= cur_name->byte_start;j<(cur_name+1)->byte_start;j++)
  4035. out(isxalpha(*j)?'x':*j);
  4036. out('$');
  4037. goto name_done;
  4038. }
  4039. default:out_str("\\&");
  4040.  
  4041. }
  4042. out_name(cur_name);
  4043. name_done:
  4044.  
  4045. /*:241*/
  4046. #line 4378 "cweave.w"
  4047. ;
  4048. /*242:*/
  4049. #line 4418 "cweave.w"
  4050.  
  4051. /*244:*/
  4052. #line 4436 "cweave.w"
  4053.  
  4054. this_xref= (xref_pointer)cur_name->xref;cur_xref= xmem;
  4055. do{
  4056. next_xref= this_xref->xlink;this_xref->xlink= cur_xref;
  4057. cur_xref= this_xref;this_xref= next_xref;
  4058. }while(this_xref!=xmem);
  4059.  
  4060. /*:244*/
  4061. #line 4419 "cweave.w"
  4062. ;
  4063. do{
  4064. out_str(", ");cur_val= cur_xref->num;
  4065. if(cur_val<def_flag)out_section(cur_val);
  4066. else{out_str("\\[");out_section(cur_val-def_flag);out(']');}
  4067.  
  4068. cur_xref= cur_xref->xlink;
  4069. }while(cur_xref!=xmem);
  4070. out('.');finish_line();
  4071.  
  4072. /*:242*/
  4073. #line 4379 "cweave.w"
  4074. ;
  4075. cur_name= blink[cur_name-name_dir];
  4076. }while(cur_name);
  4077. --sort_ptr;
  4078. }
  4079.  
  4080. /*:240*/
  4081. #line 4353 "cweave.w"
  4082.  
  4083. else/*239:*/
  4084. #line 4357 "cweave.w"
  4085. {
  4086. eight_bits c;
  4087. next_name= sort_ptr->head;
  4088. do{
  4089. cur_name= next_name;next_name= blink[cur_name-name_dir];
  4090. cur_byte= cur_name->byte_start+cur_depth;
  4091. if(cur_byte==(cur_name+1)->byte_start)c= 0;
  4092. else{
  4093. c= (eight_bits)*cur_byte;
  4094. if(xisupper(c))c= tolower(c);
  4095. }
  4096. blink[cur_name-name_dir]= bucket[c];bucket[c]= cur_name;
  4097. }while(next_name);
  4098. --sort_ptr;unbucket(cur_depth+1);
  4099. }
  4100.  
  4101. /*:239*/
  4102. #line 4354 "cweave.w"
  4103. ;
  4104. }
  4105.  
  4106. /*:238*/
  4107. #line 4173 "cweave.w"
  4108. ;
  4109. finish_line();fclose(active_file);
  4110. active_file= tex_file;
  4111. out_str("\\fin");finish_line();
  4112.  
  4113. if((scn_file= fopen(scn_file_name,"w"))==NULL)
  4114. fatal("! Cannot open section file ",scn_file_name);
  4115.  
  4116. active_file= scn_file;
  4117. /*247:*/
  4118. #line 4467 "cweave.w"
  4119. section_print(root)
  4120.  
  4121. /*:247*/
  4122. #line 4182 "cweave.w"
  4123. ;
  4124. finish_line();fclose(active_file);
  4125. active_file= tex_file;
  4126. if(group_found)out_str("\\con");else out_str("\\end");
  4127.  
  4128.  
  4129. finish_line();
  4130. fclose(active_file);
  4131. }
  4132. if(show_happiness)printf("\nDone.");
  4133. check_complete();
  4134. }
  4135.  
  4136. /*:225*//*237:*/
  4137. #line 4330 "cweave.w"
  4138.  
  4139. void
  4140. unbucket(d)
  4141. eight_bits d;
  4142. {
  4143. int c;
  4144.  
  4145. for(c= 100+128;c>=0;c--)if(bucket[collate[c]]){
  4146.  
  4147. if(sort_ptr>=scrap_info_end)overflow("sorting");
  4148. sort_ptr++;
  4149. if(sort_ptr>max_sort_ptr)max_sort_ptr= sort_ptr;
  4150. if(c==0)sort_ptr->depth= infinity;
  4151. else sort_ptr->depth= d;
  4152. sort_ptr->head= bucket[collate[c]];bucket[collate[c]]= NULL;
  4153. }
  4154. }
  4155.  
  4156. /*:237*//*246:*/
  4157. #line 4450 "cweave.w"
  4158.  
  4159. void
  4160. section_print(p)
  4161. name_pointer p;
  4162. {
  4163. if(p){
  4164. section_print(p->llink);out_str("\\I");
  4165.  
  4166. tok_ptr= tok_mem+1;text_ptr= tok_start+1;scrap_ptr= scrap_info;init_stack;
  4167. app(p-name_dir+section_flag);make_output();
  4168. footnote(cite_flag);
  4169. footnote(0);
  4170. finish_line();
  4171. section_print(p->rlink);
  4172. }
  4173. }
  4174.  
  4175. /*:246*//*248:*/
  4176. #line 4472 "cweave.w"
  4177.  
  4178. void
  4179. print_stats(){
  4180. printf("\nMemory usage statistics:\n");
  4181.  
  4182. printf("%ld names (out of %ld)\n",
  4183. (long)(name_ptr-name_dir),(long)max_names);
  4184. printf("%ld cross-references (out of %ld)\n",
  4185. (long)(xref_ptr-xmem),(long)max_refs);
  4186. printf("%ld bytes (out of %ld)\n",
  4187. (long)(byte_ptr-byte_mem),(long)max_bytes);
  4188. printf("Parsing:\n");
  4189. printf("%ld scraps (out of %ld)\n",
  4190. (long)(max_scr_ptr-scrap_info),(long)max_scraps);
  4191. printf("%ld texts (out of %ld)\n",
  4192. (long)(max_text_ptr-tok_start),(long)max_texts);
  4193. printf("%ld tokens (out of %ld)\n",
  4194. (long)(max_tok_ptr-tok_mem),(long)max_toks);
  4195. printf("%ld levels (out of %ld)\n",
  4196. (long)(max_stack_ptr-stack),(long)stack_size);
  4197. printf("Sorting:\n");
  4198. printf("%ld levels (out of %ld)\n",
  4199. (long)(max_sort_ptr-scrap_info),(long)max_scraps);
  4200. }
  4201.  
  4202. /*:248*/
  4203.