home *** CD-ROM | disk | FTP | other *** search
/ ARM Club 3 / TheARMClub_PDCD3.iso / hensa / programming / cweb / cwebsrc / CWEB / src / c / ctangle < prev    next >
Encoding:
Text File  |  1996-10-30  |  29.5 KB  |  1,561 lines

  1. /*1:*/
  2. #line 61 "ctangle.w"
  3.  
  4. /*6:*/
  5. #line 35 "common.h"
  6.  
  7. #include <stdio.h>
  8.  
  9. /*:6*//*62:*/
  10. #line 881 "ctangle.w"
  11.  
  12. #include <ctype.h> 
  13. #include <stdlib.h> 
  14.  
  15. /*:62*/
  16. #line 62 "ctangle.w"
  17.  
  18. #define banner "This is CTANGLE (Version 3.4)\n" \
  19.  
  20. #define max_bytes 90000 \
  21.  
  22. #define max_toks 270000
  23. #define max_names 4000 \
  24.  
  25. #define max_texts 2500
  26. #define hash_size 353
  27. #define longest_name 1000
  28. #define stack_size 50
  29. #define buf_size 100 \
  30.  
  31. #define ctangle 0
  32. #define cweave 1 \
  33.  
  34. #define and_and 04
  35. #define lt_lt 020
  36. #define gt_gt 021
  37. #define plus_plus 013
  38. #define minus_minus 01
  39. #define minus_gt 031
  40. #define not_eq 032
  41. #define lt_eq 034
  42. #define gt_eq 035
  43. #define eq_eq 036
  44. #define or_or 037
  45. #define dot_dot_dot 016
  46. #define colon_colon 06
  47. #define period_ast 026
  48. #define minus_gt_ast 027 \
  49.  
  50. #define xisalpha(c) (isalpha(c) &&((eight_bits) c<0200) ) 
  51. #define xisdigit(c) (isdigit(c) &&((eight_bits) c<0200) ) 
  52. #define xisspace(c) (isspace(c) &&((eight_bits) c<0200) ) 
  53. #define xislower(c) (islower(c) &&((eight_bits) c<0200) ) 
  54. #define xisupper(c) (isupper(c) &&((eight_bits) c<0200) ) 
  55. #define xisxdigit(c) (isxdigit(c) &&((eight_bits) c<0200) )  \
  56.  
  57. #define length(c) (c+1) ->byte_start-(c) ->byte_start
  58. #define print_id(c) term_write((c) ->byte_start,length((c) ) ) 
  59. #define llink link
  60. #define rlink dummy.Rlink
  61. #define root name_dir->rlink \
  62.  
  63. #define chunk_marker 0 \
  64.  
  65. #define spotless 0
  66. #define harmless_message 1
  67. #define error_message 2
  68. #define fatal_message 3
  69. #define mark_harmless {if(history==spotless) history= harmless_message;}
  70. #define mark_error history= error_message
  71. #define confusion(s) fatal("! This can't happen: ",s)  \
  72.  
  73. #define max_file_name_length 60
  74. #define cur_file file[include_depth]
  75. #define cur_file_name file_name[include_depth]
  76. #define web_file_name file_name[0]
  77. #define cur_line line[include_depth] \
  78.  
  79. #define show_banner flags['b']
  80. #define show_progress flags['p']
  81. #define show_happiness flags['h'] \
  82.  
  83. #define update_terminal fflush(stdout) 
  84. #define new_line putchar('\n') 
  85. #define putxchar putchar
  86. #define term_write(a,b) fflush(stdout) ,fwrite(a,sizeof(char) ,b,stdout) 
  87. #define C_printf(c,a) fprintf(C_file,c,a) 
  88. #define C_putc(c) putc(c,C_file)  \
  89.  
  90. #define equiv equiv_or_xref \
  91.  
  92. #define section_flag max_texts \
  93.  
  94. #define string 02
  95. #define join 0177
  96. #define output_defs_flag (2*024000-1)  \
  97.  
  98. #define cur_end cur_state.end_field
  99. #define cur_byte cur_state.byte_field
  100. #define cur_name cur_state.name_field
  101. #define cur_repl cur_state.repl_field
  102. #define cur_section cur_state.section_field \
  103.  
  104. #define section_number 0201
  105. #define identifier 0202 \
  106.  
  107. #define normal 0
  108. #define num_or_id 1
  109. #define post_slash 2
  110. #define unbreakable 3
  111. #define verbatim 4 \
  112.  
  113. #define max_files 256
  114. #define translit_length 10 \
  115.  
  116. #define ignore 0
  117. #define ord 0302
  118. #define control_text 0303
  119. #define translit_code 0304
  120. #define output_defs_code 0305
  121. #define format_code 0306
  122. #define definition 0307
  123. #define begin_C 0310
  124. #define section_name 0311
  125. #define new_section 0312 \
  126.  
  127. #define constant 03 \
  128.  
  129. #define isxalpha(c) ((c) =='_') 
  130. #define ishigh(c) ((unsigned char) (c) >0177)  \
  131.  \
  132.  
  133. #define compress(c) if(loc++<=limit) return(c)  \
  134.  
  135. #define macro 0
  136. #define app_repl(c) {if(tok_ptr==tok_mem_end) overflow("token") ;*tok_ptr++= c;} \
  137.  
  138.  
  139. #line 63 "ctangle.w"
  140.  
  141. /*5:*/
  142. #line 29 "common.h"
  143.  
  144. typedef short boolean;
  145. typedef char unsigned eight_bits;
  146. extern boolean program;
  147. extern int phase;
  148.  
  149. /*:5*//*7:*/
  150. #line 57 "common.h"
  151.  
  152. char section_text[longest_name+1];
  153. char*section_text_end= section_text+longest_name;
  154. char*id_first;
  155. char*id_loc;
  156.  
  157. /*:7*//*8:*/
  158. #line 72 "common.h"
  159.  
  160. extern char buffer[];
  161. extern char*buffer_end;
  162. extern char*loc;
  163. extern char*limit;
  164.  
  165. /*:8*//*9:*/
  166. #line 87 "common.h"
  167.  
  168. typedef struct name_info{
  169. char*byte_start;
  170. struct name_info*link;
  171. union{
  172. struct name_info*Rlink;
  173.  
  174. char Ilk;
  175. }dummy;
  176. char*equiv_or_xref;
  177. }name_info;
  178. typedef name_info*name_pointer;
  179. typedef name_pointer*hash_pointer;
  180. extern char byte_mem[];
  181. extern char*byte_mem_end;
  182. extern name_info name_dir[];
  183. extern name_pointer name_dir_end;
  184. extern name_pointer name_ptr;
  185. extern char*byte_ptr;
  186. extern name_pointer hash[];
  187. extern hash_pointer hash_end;
  188. extern hash_pointer h;
  189. extern name_pointer id_lookup();
  190. extern name_pointer section_lookup();
  191. extern void print_section_name(),sprint_section_name();
  192.  
  193. /*:9*//*10:*/
  194. #line 122 "common.h"
  195.  
  196. extern history;
  197. extern err_print();
  198. extern wrap_up();
  199. extern void fatal();
  200. extern void overflow();
  201.  
  202. /*:10*//*11:*/
  203. #line 137 "common.h"
  204.  
  205. extern include_depth;
  206. extern FILE*file[];
  207. extern FILE*change_file;
  208. extern char C_file_name[];
  209. extern char tex_file_name[];
  210. extern char idx_file_name[];
  211. extern char scn_file_name[];
  212. extern char file_name[][max_file_name_length];
  213.  
  214. extern char change_file_name[];
  215. extern line[];
  216. extern change_line;
  217. extern boolean input_has_ended;
  218. extern boolean changing;
  219. extern boolean web_file_open;
  220. extern reset_input();
  221. extern get_line();
  222. extern check_complete();
  223.  
  224. /*:11*//*12:*/
  225. #line 158 "common.h"
  226.  
  227. typedef unsigned short sixteen_bits;
  228. extern sixteen_bits section_count;
  229. extern boolean changed_section[];
  230. extern boolean change_pending;
  231. extern boolean print_where;
  232.  
  233. /*:12*//*13:*/
  234. #line 170 "common.h"
  235.  
  236. extern int argc;
  237. extern char**argv;
  238. extern boolean flags[];
  239.  
  240. /*:13*//*14:*/
  241. #line 182 "common.h"
  242.  
  243. extern FILE*C_file;
  244. extern FILE*tex_file;
  245. extern FILE*idx_file;
  246. extern FILE*scn_file;
  247. extern FILE*active_file;
  248.  
  249. /*:14*//*15:*/
  250. #line 191 "common.h"
  251.  
  252. extern void common_init();
  253. #line 125 "ctangle.w"
  254.  
  255. /*:15*/
  256. #line 64 "ctangle.w"
  257.  
  258. /*16:*/
  259. #line 149 "ctangle.w"
  260.  
  261. typedef struct{
  262. eight_bits*tok_start;
  263. sixteen_bits text_link;
  264. }text;
  265. typedef text*text_pointer;
  266.  
  267. /*:16*//*27:*/
  268. #line 293 "ctangle.w"
  269.  
  270. typedef struct{
  271. eight_bits*end_field;
  272. eight_bits*byte_field;
  273. name_pointer name_field;
  274. text_pointer repl_field;
  275. sixteen_bits section_field;
  276. }output_state;
  277. typedef output_state*stack_pointer;
  278.  
  279. /*:27*/
  280. #line 65 "ctangle.w"
  281.  
  282. /*17:*/
  283. #line 156 "ctangle.w"
  284.  
  285. text text_info[max_texts];
  286. text_pointer text_info_end= text_info+max_texts-1;
  287. text_pointer text_ptr;
  288. eight_bits tok_mem[max_toks];
  289. eight_bits*tok_mem_end= tok_mem+max_toks-1;
  290. eight_bits*tok_ptr;
  291.  
  292. /*:17*//*23:*/
  293. #line 224 "ctangle.w"
  294.  
  295. text_pointer last_unnamed;
  296.  
  297. /*:23*//*28:*/
  298. #line 309 "ctangle.w"
  299.  
  300. output_state cur_state;
  301.  
  302. output_state stack[stack_size+1];
  303. stack_pointer stack_ptr;
  304. stack_pointer stack_end= stack+stack_size;
  305.  
  306. /*:28*//*32:*/
  307. #line 381 "ctangle.w"
  308.  
  309. int cur_val;
  310.  
  311. /*:32*//*36:*/
  312. #line 470 "ctangle.w"
  313.  
  314. eight_bits out_state;
  315. boolean protect;
  316.  
  317. /*:36*//*38:*/
  318. #line 499 "ctangle.w"
  319.  
  320. name_pointer output_files[max_files];
  321. name_pointer*cur_out_file,*end_output_files,*an_output_file;
  322. char cur_section_name_char;
  323. char output_file_name[longest_name];
  324.  
  325. /*:38*//*45:*/
  326. #line 596 "ctangle.w"
  327.  
  328. boolean output_defs_seen= 0;
  329.  
  330. /*:45*//*51:*/
  331. #line 706 "ctangle.w"
  332.  
  333. char translit[128][translit_length];
  334.  
  335. /*:51*//*56:*/
  336. #line 782 "ctangle.w"
  337.  
  338. eight_bits ccode[256];
  339.  
  340. /*:56*//*59:*/
  341. #line 838 "ctangle.w"
  342.  
  343. boolean comment_continues= 0;
  344.  
  345. /*:59*//*61:*/
  346. #line 877 "ctangle.w"
  347.  
  348. name_pointer cur_section_name;
  349. int no_where;
  350.  
  351. /*:61*//*75:*/
  352. #line 1191 "ctangle.w"
  353.  
  354. text_pointer cur_text;
  355. eight_bits next_control;
  356.  
  357. /*:75*//*82:*/
  358. #line 1341 "ctangle.w"
  359.  
  360. extern sixteen_bits section_count;
  361.  
  362. /*:82*/
  363. #line 66 "ctangle.w"
  364.  
  365. /*2:*/
  366. #line 74 "ctangle.w"
  367.  
  368. extern int strlen();
  369. extern int strcmp();
  370. extern char*strcpy();
  371. extern int strncmp();
  372. extern char*strncpy();
  373.  
  374. /*:2*//*41:*/
  375. #line 530 "ctangle.w"
  376.  
  377. void phase_two();
  378.  
  379. /*:41*//*46:*/
  380. #line 599 "ctangle.w"
  381.  
  382. void output_defs();
  383.  
  384. /*:46*//*48:*/
  385. #line 645 "ctangle.w"
  386.  
  387. static void out_char();
  388.  
  389. /*:48*//*90:*/
  390. #line 1448 "ctangle.w"
  391.  
  392. void phase_one();
  393.  
  394. /*:90*//*92:*/
  395. #line 1466 "ctangle.w"
  396.  
  397. void skip_limbo();
  398.  
  399. /*:92*/
  400. #line 67 "ctangle.w"
  401.  
  402.  
  403. /*:1*//*3:*/
  404. #line 88 "ctangle.w"
  405.  
  406. int main(ac,av)
  407. int ac;
  408. char**av;
  409. {
  410. argc= ac;argv= av;
  411. program= ctangle;
  412. /*18:*/
  413. #line 164 "ctangle.w"
  414.  
  415. text_info->tok_start= tok_ptr= tok_mem;
  416. text_ptr= text_info+1;text_ptr->tok_start= tok_mem;
  417.  
  418.  
  419. /*:18*//*20:*/
  420. #line 174 "ctangle.w"
  421.  
  422. name_dir->equiv= (char*)text_info;
  423.  
  424. /*:20*//*24:*/
  425. #line 227 "ctangle.w"
  426. last_unnamed= text_info;text_info->text_link= 0;
  427.  
  428. /*:24*//*39:*/
  429. #line 509 "ctangle.w"
  430.  
  431. cur_out_file= end_output_files= output_files+max_files;
  432.  
  433. /*:39*//*52:*/
  434. #line 709 "ctangle.w"
  435.  
  436. {
  437. int i;
  438. for(i= 0;i<128;i++)sprintf(translit[i],"X%02X",(unsigned)(128+i));
  439. }
  440.  
  441. /*:52*//*57:*/
  442. #line 785 "ctangle.w"
  443. {
  444. int c;
  445. for(c= 0;c<256;c++)ccode[c]= ignore;
  446. ccode[' ']= ccode['\t']= ccode['\n']= ccode['\v']= ccode['\r']= ccode['\f']
  447. = ccode['*']= new_section;
  448. ccode['@']= '@';ccode['=']= string;
  449. ccode['d']= ccode['D']= definition;
  450. ccode['f']= ccode['F']= ccode['s']= ccode['S']= format_code;
  451. ccode['c']= ccode['C']= ccode['p']= ccode['P']= begin_C;
  452. ccode['^']= ccode[':']= ccode['.']= ccode['t']= ccode['T']= 
  453. ccode['q']= ccode['Q']= control_text;
  454. ccode['h']= ccode['H']= output_defs_code;
  455. ccode['l']= ccode['L']= translit_code;
  456. ccode['&']= join;
  457. ccode['<']= ccode['(']= section_name;
  458. ccode['\'']= ord;
  459. }
  460.  
  461. /*:57*//*71:*/
  462. #line 1112 "ctangle.w"
  463. section_text[0]= ' ';
  464.  
  465. /*:71*/
  466. #line 95 "ctangle.w"
  467. ;
  468. common_init();
  469. if(show_banner)printf(banner);
  470. phase_one();
  471. phase_two();
  472. return wrap_up();
  473. }
  474.  
  475. /*:3*//*21:*/
  476. #line 180 "ctangle.w"
  477.  
  478. int names_match(p,first,l)
  479. name_pointer p;
  480. char*first;
  481. int l;
  482. {
  483. if(length(p)!=l)return 0;
  484. return!strncmp(first,p->byte_start,l);
  485. }
  486.  
  487. /*:21*//*22:*/
  488. #line 195 "ctangle.w"
  489.  
  490. void
  491. init_node(node)
  492. name_pointer node;
  493. {
  494. node->equiv= (char*)text_info;
  495. }
  496. void
  497. init_p(){}
  498.  
  499. /*:22*//*26:*/
  500. #line 257 "ctangle.w"
  501.  
  502. void
  503. store_two_bytes(x)
  504. sixteen_bits x;
  505. {
  506. if(tok_ptr+2>tok_mem_end)overflow("token");
  507. *tok_ptr++= x>>8;
  508. *tok_ptr++= x&0377;
  509. }
  510.  
  511. /*:26*//*30:*/
  512. #line 333 "ctangle.w"
  513.  
  514. void
  515. push_level(p)
  516. name_pointer p;
  517. {
  518. if(stack_ptr==stack_end)overflow("stack");
  519. *stack_ptr= cur_state;
  520. stack_ptr++;
  521. if(p!=NULL){
  522. cur_name= p;cur_repl= (text_pointer)p->equiv;
  523. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  524. cur_section= 0;
  525. }
  526. }
  527.  
  528. /*:30*//*31:*/
  529. #line 352 "ctangle.w"
  530.  
  531. void
  532. pop_level(flag)
  533. int flag;
  534. {
  535. if(flag&&cur_repl->text_link<section_flag){
  536. cur_repl= cur_repl->text_link+text_info;
  537. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;
  538. return;
  539. }
  540. stack_ptr--;
  541. if(stack_ptr>stack)cur_state= *stack_ptr;
  542. }
  543.  
  544. /*:31*//*33:*/
  545. #line 388 "ctangle.w"
  546.  
  547. void
  548. get_output()
  549. {
  550. sixteen_bits a;
  551. restart:if(stack_ptr==stack)return;
  552. if(cur_byte==cur_end){
  553. cur_val= -((int)cur_section);
  554. pop_level(1);
  555. if(cur_val==0)goto restart;
  556. out_char(section_number);return;
  557. }
  558. a= *cur_byte++;
  559. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  560. C_putc(a);
  561. else if(a<0200)out_char(a);
  562. else{
  563. a= (a-0200)*0400+*cur_byte++;
  564. switch(a/024000){
  565. case 0:cur_val= a;out_char(identifier);break;
  566. case 1:if(a==output_defs_flag)output_defs();
  567. else/*34:*/
  568. #line 420 "ctangle.w"
  569.  
  570. {
  571. a-= 024000;
  572. if((a+name_dir)->equiv!=(char*)text_info)push_level(a+name_dir);
  573. else if(a!=0){
  574. printf("\n! Not present: <");
  575. print_section_name(a+name_dir);err_print(">");
  576.  
  577. }
  578. goto restart;
  579. }
  580.  
  581. /*:34*/
  582. #line 409 "ctangle.w"
  583. ;
  584. break;
  585. default:cur_val= a-050000;if(cur_val>0)cur_section= cur_val;
  586. out_char(section_number);
  587. }
  588. }
  589. }
  590.  
  591. /*:33*//*37:*/
  592. #line 478 "ctangle.w"
  593.  
  594. void
  595. flush_buffer()
  596. {
  597. C_putc('\n');
  598. if(cur_line%100==0&&show_progress){
  599. printf(".");
  600. if(cur_line%500==0)printf("%d",cur_line);
  601. update_terminal;
  602. }
  603. cur_line++;
  604. }
  605.  
  606. /*:37*//*42:*/
  607. #line 533 "ctangle.w"
  608.  
  609. void
  610. phase_two(){
  611. web_file_open= 0;
  612. cur_line= 1;
  613. /*29:*/
  614. #line 322 "ctangle.w"
  615.  
  616. stack_ptr= stack+1;cur_name= name_dir;cur_repl= text_info->text_link+text_info;
  617. cur_byte= cur_repl->tok_start;cur_end= (cur_repl+1)->tok_start;cur_section= 0;
  618.  
  619. /*:29*/
  620. #line 538 "ctangle.w"
  621. ;
  622. /*44:*/
  623. #line 592 "ctangle.w"
  624.  
  625. if(!output_defs_seen)
  626. output_defs();
  627.  
  628. /*:44*/
  629. #line 539 "ctangle.w"
  630. ;
  631. if(text_info->text_link==0&&cur_out_file==end_output_files){
  632. printf("\n! No program text was specified.");mark_harmless;
  633.  
  634. }
  635. else{
  636. if(cur_out_file==end_output_files){
  637. if(show_progress)
  638. printf("\nWriting the output file (%s):",C_file_name);
  639. }
  640. else{
  641. if(show_progress){
  642. printf("\nWriting the output files:");
  643.  
  644. printf(" (%s)",C_file_name);
  645. update_terminal;
  646. }
  647. if(text_info->text_link==0)goto writeloop;
  648. }
  649. while(stack_ptr>stack)get_output();
  650. flush_buffer();
  651. writeloop:/*43:*/
  652. #line 569 "ctangle.w"
  653.  
  654. for(an_output_file= end_output_files;an_output_file>cur_out_file;){
  655. an_output_file--;
  656. sprint_section_name(output_file_name,*an_output_file);
  657. fclose(C_file);
  658. C_file= fopen(output_file_name,"w");
  659. if(C_file==0)fatal("! Cannot open output file:",output_file_name);
  660.  
  661. printf("\n(%s)",output_file_name);update_terminal;
  662. cur_line= 1;
  663. stack_ptr= stack+1;
  664. cur_name= (*an_output_file);
  665. cur_repl= (text_pointer)cur_name->equiv;
  666. cur_byte= cur_repl->tok_start;
  667. cur_end= (cur_repl+1)->tok_start;
  668. while(stack_ptr>stack)get_output();
  669. flush_buffer();
  670. }
  671.  
  672. /*:43*/
  673. #line 560 "ctangle.w"
  674. ;
  675. if(show_happiness)printf("\nDone.");
  676. }
  677. }
  678.  
  679. /*:42*//*47:*/
  680. #line 602 "ctangle.w"
  681.  
  682. void
  683. output_defs()
  684. {
  685. sixteen_bits a;
  686. push_level(NULL);
  687. for(cur_text= text_info+1;cur_text<text_ptr;cur_text++)
  688. if(cur_text->text_link==0){
  689. cur_byte= cur_text->tok_start;
  690. cur_end= (cur_text+1)->tok_start;
  691. C_printf("%s","#define ");
  692. out_state= normal;
  693. protect= 1;
  694. while(cur_byte<cur_end){
  695. a= *cur_byte++;
  696. if(cur_byte==cur_end&&a=='\n')break;
  697. if(out_state==verbatim&&a!=string&&a!=constant&&a!='\n')
  698. C_putc(a);
  699.  
  700. else if(a<0200)out_char(a);
  701. else{
  702. a= (a-0200)*0400+*cur_byte++;
  703. if(a<024000){
  704. cur_val= a;out_char(identifier);
  705. }
  706. else if(a<050000){confusion("macro defs have strange char");}
  707. else{
  708. cur_val= a-050000;cur_section= cur_val;out_char(section_number);
  709. }
  710.  
  711. }
  712. }
  713. protect= 0;
  714. flush_buffer();
  715. }
  716. pop_level(0);
  717. }
  718.  
  719. /*:47*//*49:*/
  720. #line 648 "ctangle.w"
  721.  
  722. static void
  723. out_char(cur_char)
  724. eight_bits cur_char;
  725. {
  726. char*j,*k;
  727. restart:
  728. switch(cur_char){
  729. case'\n':if(protect)C_putc(' ');
  730. if(protect||out_state==verbatim)C_putc('\\');
  731. flush_buffer();if(out_state!=verbatim)out_state= normal;break;
  732. /*53:*/
  733. #line 715 "ctangle.w"
  734.  
  735. case identifier:
  736. if(out_state==num_or_id)C_putc(' ');
  737. j= (cur_val+name_dir)->byte_start;
  738. k= (cur_val+name_dir+1)->byte_start;
  739. while(j<k){
  740. if((unsigned char)(*j)<0200)C_putc(*j);
  741.  
  742. else C_printf("%s",translit[(unsigned char)(*j)-0200]);
  743. j++;
  744. }
  745. out_state= num_or_id;break;
  746.  
  747. /*:53*/
  748. #line 659 "ctangle.w"
  749. ;
  750. /*54:*/
  751. #line 728 "ctangle.w"
  752.  
  753. case section_number:
  754. if(cur_val>0)C_printf("/*%d:*/",cur_val);
  755. else if(cur_val<0)C_printf("/*:%d*/",-cur_val);
  756. else if(protect){
  757. cur_byte+= 4;
  758. cur_char= '\n';
  759. goto restart;
  760. }else{
  761. sixteen_bits a;
  762. a= 0400**cur_byte++;
  763. a+= *cur_byte++;
  764. C_printf("\n#line %d \"",a);
  765.  
  766. cur_val= *cur_byte++;
  767. cur_val= 0400*(cur_val-0200)+*cur_byte++;
  768. for(j= (cur_val+name_dir)->byte_start,k= (cur_val+name_dir+1)->byte_start;
  769. j<k;j++)C_putc(*j);
  770. C_printf("%s","\"\n");
  771. }
  772. break;
  773.  
  774. /*:54*/
  775. #line 660 "ctangle.w"
  776. ;
  777. /*50:*/
  778. #line 677 "ctangle.w"
  779.  
  780. case plus_plus:C_putc('+');C_putc('+');out_state= normal;break;
  781. case minus_minus:C_putc('-');C_putc('-');out_state= normal;break;
  782. case minus_gt:C_putc('-');C_putc('>');out_state= normal;break;
  783. case gt_gt:C_putc('>');C_putc('>');out_state= normal;break;
  784. case eq_eq:C_putc('=');C_putc('=');out_state= normal;break;
  785. case lt_lt:C_putc('<');C_putc('<');out_state= normal;break;
  786. case gt_eq:C_putc('>');C_putc('=');out_state= normal;break;
  787. case lt_eq:C_putc('<');C_putc('=');out_state= normal;break;
  788. case not_eq:C_putc('!');C_putc('=');out_state= normal;break;
  789. case and_and:C_putc('&');C_putc('&');out_state= normal;break;
  790. case or_or:C_putc('|');C_putc('|');out_state= normal;break;
  791. case dot_dot_dot:C_putc('.');C_putc('.');C_putc('.');out_state= normal;
  792. break;
  793. case colon_colon:C_putc(':');C_putc(':');out_state= normal;break;
  794. case period_ast:C_putc('.');C_putc('*');out_state= normal;break;
  795. case minus_gt_ast:C_putc('-');C_putc('>');C_putc('*');out_state= normal;
  796. break;
  797.  
  798. /*:50*/
  799. #line 661 "ctangle.w"
  800. ;
  801. case'=':C_putc('=');C_putc(' ');out_state= normal;break;
  802. case join:out_state= unbreakable;break;
  803. case constant:if(out_state==verbatim){
  804. out_state= num_or_id;break;
  805. }
  806. if(out_state==num_or_id)C_putc(' ');out_state= verbatim;break;
  807. case string:if(out_state==verbatim)out_state= normal;
  808. else out_state= verbatim;break;
  809. case'/':C_putc('/');out_state= post_slash;break;
  810. case'*':if(out_state==post_slash)C_putc(' ');
  811.  
  812. default:C_putc(cur_char);out_state= normal;break;
  813. }
  814. }
  815.  
  816. /*:49*//*58:*/
  817. #line 806 "ctangle.w"
  818.  
  819. eight_bits
  820. skip_ahead()
  821. {
  822. eight_bits c;
  823. while(1){
  824. if(loc>limit&&(get_line()==0))return(new_section);
  825. *(limit+1)= '@';
  826. while(*loc!='@')loc++;
  827. if(loc<=limit){
  828. loc++;c= ccode[(eight_bits)*loc];loc++;
  829. if(c!=ignore||*(loc-1)=='>')return(c);
  830. }
  831. }
  832. }
  833.  
  834. /*:58*//*60:*/
  835. #line 841 "ctangle.w"
  836.  
  837. int skip_comment(is_long_comment)
  838. boolean is_long_comment;
  839. {
  840. char c;
  841. while(1){
  842. if(loc>limit){
  843. if(is_long_comment){
  844. if(get_line())return(comment_continues= 1);
  845. else{
  846. err_print("! Input ended in mid-comment");
  847.  
  848. return(comment_continues= 0);
  849. }
  850. }
  851. else return(comment_continues= 0);
  852. }
  853. c= *(loc++);
  854. if(is_long_comment&&c=='*'&&*loc=='/'){
  855. loc++;return(comment_continues= 0);
  856. }
  857. if(c=='@'){
  858. if(ccode[(eight_bits)*loc]==new_section){
  859. err_print("! Section name ended in mid-comment");loc--;
  860.  
  861. return(comment_continues= 0);
  862. }
  863. else loc++;
  864. }
  865. }
  866. }
  867.  
  868. /*:60*//*63:*/
  869. #line 892 "ctangle.w"
  870.  
  871. eight_bits
  872. get_next()
  873. {
  874. static int preprocessing= 0;
  875. eight_bits c;
  876. while(1){
  877. if(loc>limit){
  878. if(preprocessing&&*(limit-1)!='\\')preprocessing= 0;
  879. if(get_line()==0)return(new_section);
  880. else if(print_where&&!no_where){
  881. print_where= 0;
  882. /*77:*/
  883. #line 1221 "ctangle.w"
  884.  
  885. store_two_bytes(0150000);
  886. if(changing)id_first= change_file_name;
  887. else id_first= cur_file_name;
  888. id_loc= id_first+strlen(id_first);
  889. if(changing)store_two_bytes((sixteen_bits)change_line);
  890. else store_two_bytes((sixteen_bits)cur_line);
  891. {int a= id_lookup(id_first,id_loc,0)-name_dir;app_repl((a/0400)+0200);
  892. app_repl(a%0400);}
  893.  
  894. /*:77*/
  895. #line 904 "ctangle.w"
  896. ;
  897. }
  898. else return('\n');
  899. }
  900. c= *loc;
  901. if(comment_continues||(c=='/'&&(*(loc+1)=='*'||*(loc+1)=='/'))){
  902. skip_comment(comment_continues||*(loc+1)=='*');
  903.  
  904. if(comment_continues)return('\n');
  905. else continue;
  906. }
  907. loc++;
  908. if(xisdigit(c)||c=='\\'||c=='.')/*66:*/
  909. #line 970 "ctangle.w"
  910. {
  911. id_first= loc-1;
  912. if(*id_first=='.'&&!xisdigit(*loc))goto mistake;
  913. if(*id_first=='\\')while(xisdigit(*loc))loc++;
  914. else{
  915. if(*id_first=='0'){
  916. if(*loc=='x'||*loc=='X'){
  917. loc++;while(xisxdigit(*loc))loc++;goto found;
  918. }
  919. }
  920. while(xisdigit(*loc))loc++;
  921. if(*loc=='.'){
  922. loc++;
  923. while(xisdigit(*loc))loc++;
  924. }
  925. if(*loc=='e'||*loc=='E'){
  926. if(*++loc=='+'||*loc=='-')loc++;
  927. while(xisdigit(*loc))loc++;
  928. }
  929. }
  930. found:while(*loc=='u'||*loc=='U'||*loc=='l'||*loc=='L'
  931. ||*loc=='f'||*loc=='F')loc++;
  932. id_loc= loc;
  933. return(constant);
  934. }
  935.  
  936. /*:66*/
  937. #line 916 "ctangle.w"
  938.  
  939. else if(c=='\''||c=='"'||(c=='L'&&(*loc=='\''||*loc=='"')))
  940. /*67:*/
  941. #line 1001 "ctangle.w"
  942. {
  943. char delim= c;
  944. id_first= section_text+1;
  945. id_loc= section_text;*++id_loc= delim;
  946. if(delim=='L'){
  947. delim= *loc++;*++id_loc= delim;
  948. }
  949. while(1){
  950. if(loc>=limit){
  951. if(*(limit-1)!='\\'){
  952. err_print("! String didn't end");loc= limit;break;
  953.  
  954. }
  955. if(get_line()==0){
  956. err_print("! Input ended in middle of string");loc= buffer;break;
  957.  
  958. }
  959. else if(++id_loc<=section_text_end)*id_loc= '\n';
  960.  
  961. }
  962. if((c= *loc++)==delim){
  963. if(++id_loc<=section_text_end)*id_loc= c;
  964. break;
  965. }
  966. if(c=='\\'){
  967. if(loc>=limit)continue;
  968. if(++id_loc<=section_text_end)*id_loc= '\\';
  969. c= *loc++;
  970. }
  971. if(++id_loc<=section_text_end)*id_loc= c;
  972. }
  973. if(id_loc>=section_text_end){
  974. printf("\n! String too long: ");
  975.  
  976. term_write(section_text+1,25);
  977. err_print("...");
  978. }
  979. id_loc++;
  980. return(string);
  981. }
  982.  
  983. /*:67*/
  984. #line 918 "ctangle.w"
  985.  
  986. else if(isalpha(c)||isxalpha(c)||ishigh(c))
  987. /*65:*/
  988. #line 964 "ctangle.w"
  989. {
  990. id_first= --loc;
  991. while(isalpha(*++loc)||isdigit(*loc)||isxalpha(*loc)||ishigh(*loc));
  992. id_loc= loc;return(identifier);
  993. }
  994.  
  995. /*:65*/
  996. #line 920 "ctangle.w"
  997.  
  998. else if(c=='@')/*68:*/
  999. #line 1045 "ctangle.w"
  1000. {
  1001. c= ccode[(eight_bits)*loc++];
  1002. switch(c){
  1003. case ignore:continue;
  1004. case output_defs_code:output_defs_seen= 1;return(c);
  1005. case translit_code:err_print("! Use @l in limbo only");continue;
  1006.  
  1007. case control_text:while((c= skip_ahead())=='@');
  1008.  
  1009. if(*(loc-1)!='>')
  1010. err_print("! Double @ should be used in control text");
  1011.  
  1012. continue;
  1013. case section_name:
  1014. cur_section_name_char= *(loc-1);
  1015. /*70:*/
  1016. #line 1094 "ctangle.w"
  1017. {
  1018. char*k;
  1019. /*72:*/
  1020. #line 1114 "ctangle.w"
  1021.  
  1022. k= section_text;
  1023. while(1){
  1024. if(loc>limit&&get_line()==0){
  1025. err_print("! Input ended in section name");
  1026.  
  1027. loc= buffer+1;break;
  1028. }
  1029. c= *loc;
  1030. /*73:*/
  1031. #line 1138 "ctangle.w"
  1032.  
  1033. if(c=='@'){
  1034. c= *(loc+1);
  1035. if(c=='>'){
  1036. loc+= 2;break;
  1037. }
  1038. if(ccode[(eight_bits)c]==new_section){
  1039. err_print("! Section name didn't end");break;
  1040.  
  1041. }
  1042. if(ccode[(eight_bits)c]==section_name){
  1043. err_print("! Nesting of section names not allowed");break;
  1044.  
  1045. }
  1046. *(++k)= '@';loc++;
  1047. }
  1048.  
  1049. /*:73*/
  1050. #line 1123 "ctangle.w"
  1051. ;
  1052. loc++;if(k<section_text_end)k++;
  1053. if(xisspace(c)){
  1054. c= ' ';if(*(k-1)==' ')k--;
  1055. }
  1056. *k= c;
  1057. }
  1058. if(k>=section_text_end){
  1059. printf("\n! Section name too long: ");
  1060.  
  1061. term_write(section_text+1,25);
  1062. printf("...");mark_harmless;
  1063. }
  1064. if(*k==' '&&k>section_text)k--;
  1065.  
  1066. /*:72*/
  1067. #line 1096 "ctangle.w"
  1068. ;
  1069. if(k-section_text>3&&strncmp(k-2,"...",3)==0)
  1070. cur_section_name= section_lookup(section_text+1,k-3,1);
  1071. else cur_section_name= section_lookup(section_text+1,k,0);
  1072. if(cur_section_name_char=='(')
  1073. /*40:*/
  1074. #line 513 "ctangle.w"
  1075.  
  1076. {
  1077. for(an_output_file= cur_out_file;
  1078. an_output_file<end_output_files;an_output_file++)
  1079. if(*an_output_file==cur_section_name)break;
  1080. if(an_output_file==end_output_files){
  1081. if(cur_out_file>output_files)
  1082. *--cur_out_file= cur_section_name;
  1083. else{
  1084. overflow("output files");
  1085. }
  1086. }
  1087. }
  1088.  
  1089. /*:40*/
  1090. #line 1102 "ctangle.w"
  1091. ;
  1092. return(section_name);
  1093. }
  1094.  
  1095. /*:70*/
  1096. #line 1060 "ctangle.w"
  1097. ;
  1098. case string:/*74:*/
  1099. #line 1160 "ctangle.w"
  1100. {
  1101. id_first= loc++;*(limit+1)= '@';*(limit+2)= '>';
  1102. while(*loc!='@'||*(loc+1)!='>')loc++;
  1103. if(loc>=limit)err_print("! Verbatim string didn't end");
  1104.  
  1105. id_loc= loc;loc+= 2;
  1106. return(string);
  1107. }
  1108.  
  1109. /*:74*/
  1110. #line 1061 "ctangle.w"
  1111. ;
  1112. case ord:/*69:*/
  1113. #line 1073 "ctangle.w"
  1114.  
  1115. id_first= loc;
  1116. if(*loc=='\\'){
  1117. if(*++loc=='\'')loc++;
  1118. }
  1119. while(*loc!='\''){
  1120. if(*loc=='@'){
  1121. if(*(loc+1)!='@')
  1122. err_print("! Double @ should be used in ASCII constant");
  1123.  
  1124. else loc++;
  1125. }
  1126. loc++;
  1127. if(loc>limit){
  1128. err_print("! String didn't end");loc= limit-1;break;
  1129.  
  1130. }
  1131. }
  1132. loc++;
  1133. return(ord);
  1134.  
  1135. /*:69*/
  1136. #line 1062 "ctangle.w"
  1137. ;
  1138. default:return(c);
  1139. }
  1140. }
  1141.  
  1142. /*:68*/
  1143. #line 921 "ctangle.w"
  1144.  
  1145. else if(xisspace(c)){
  1146. if(!preprocessing||loc>limit)continue;
  1147.  
  1148. else return(' ');
  1149. }
  1150. else if(c=='#'&&loc==buffer+1)preprocessing= 1;
  1151. mistake:/*64:*/
  1152. #line 942 "ctangle.w"
  1153.  
  1154. switch(c){
  1155. case'+':if(*loc=='+')compress(plus_plus);break;
  1156. case'-':if(*loc=='-'){compress(minus_minus);}
  1157. else if(*loc=='>')if(*(loc+1)=='*'){loc++;compress(minus_gt_ast);}
  1158. else compress(minus_gt);break;
  1159. case'.':if(*loc=='*'){compress(period_ast);}
  1160. else if(*loc=='.'&&*(loc+1)=='.'){
  1161. loc++;compress(dot_dot_dot);
  1162. }
  1163. break;
  1164. case':':if(*loc==':')compress(colon_colon);break;
  1165. case'=':if(*loc=='=')compress(eq_eq);break;
  1166. case'>':if(*loc=='='){compress(gt_eq);}
  1167. else if(*loc=='>')compress(gt_gt);break;
  1168. case'<':if(*loc=='='){compress(lt_eq);}
  1169. else if(*loc=='<')compress(lt_lt);break;
  1170. case'&':if(*loc=='&')compress(and_and);break;
  1171. case'|':if(*loc=='|')compress(or_or);break;
  1172. case'!':if(*loc=='=')compress(not_eq);break;
  1173. }
  1174.  
  1175. /*:64*/
  1176. #line 928 "ctangle.w"
  1177.  
  1178. return(c);
  1179. }
  1180. }
  1181.  
  1182. /*:63*//*76:*/
  1183. #line 1195 "ctangle.w"
  1184.  
  1185. void
  1186. scan_repl(t)
  1187. eight_bits t;
  1188. {
  1189. sixteen_bits a;
  1190. if(t==section_name){/*77:*/
  1191. #line 1221 "ctangle.w"
  1192.  
  1193. store_two_bytes(0150000);
  1194. if(changing)id_first= change_file_name;
  1195. else id_first= cur_file_name;
  1196. id_loc= id_first+strlen(id_first);
  1197. if(changing)store_two_bytes((sixteen_bits)change_line);
  1198. else store_two_bytes((sixteen_bits)cur_line);
  1199. {int a= id_lookup(id_first,id_loc,0)-name_dir;app_repl((a/0400)+0200);
  1200. app_repl(a%0400);}
  1201.  
  1202. /*:77*/
  1203. #line 1201 "ctangle.w"
  1204. ;}
  1205. while(1)switch(a= get_next()){
  1206. /*78:*/
  1207. #line 1231 "ctangle.w"
  1208.  
  1209. case identifier:a= id_lookup(id_first,id_loc,0)-name_dir;
  1210. app_repl((a/0400)+0200);
  1211. app_repl(a%0400);break;
  1212. case section_name:if(t!=section_name)goto done;
  1213. else{
  1214. /*79:*/
  1215. #line 1259 "ctangle.w"
  1216. {
  1217. char*try_loc= loc;
  1218. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1219. if(*try_loc=='+'&&try_loc<limit)try_loc++;
  1220. while(*try_loc==' '&&try_loc<limit)try_loc++;
  1221. if(*try_loc=='=')err_print("! Missing `@ ' before a named section");
  1222.  
  1223.  
  1224.  
  1225. }
  1226.  
  1227. /*:79*/
  1228. #line 1237 "ctangle.w"
  1229. ;
  1230. a= cur_section_name-name_dir;
  1231. app_repl((a/0400)+0250);
  1232. app_repl(a%0400);
  1233. /*77:*/
  1234. #line 1221 "ctangle.w"
  1235.  
  1236. store_two_bytes(0150000);
  1237. if(changing)id_first= change_file_name;
  1238. else id_first= cur_file_name;
  1239. id_loc= id_first+strlen(id_first);
  1240. if(changing)store_two_bytes((sixteen_bits)change_line);
  1241. else store_two_bytes((sixteen_bits)cur_line);
  1242. {int a= id_lookup(id_first,id_loc,0)-name_dir;app_repl((a/0400)+0200);
  1243. app_repl(a%0400);}
  1244.  
  1245. /*:77*/
  1246. #line 1241 "ctangle.w"
  1247. ;break;
  1248. }
  1249. case output_defs_code:
  1250. a= output_defs_flag;
  1251. app_repl((a/0400)+0200);
  1252. app_repl(a%0400);
  1253. /*77:*/
  1254. #line 1221 "ctangle.w"
  1255.  
  1256. store_two_bytes(0150000);
  1257. if(changing)id_first= change_file_name;
  1258. else id_first= cur_file_name;
  1259. id_loc= id_first+strlen(id_first);
  1260. if(changing)store_two_bytes((sixteen_bits)change_line);
  1261. else store_two_bytes((sixteen_bits)cur_line);
  1262. {int a= id_lookup(id_first,id_loc,0)-name_dir;app_repl((a/0400)+0200);
  1263. app_repl(a%0400);}
  1264.  
  1265. /*:77*/
  1266. #line 1247 "ctangle.w"
  1267. ;break;
  1268. case constant:case string:
  1269. /*80:*/
  1270. #line 1270 "ctangle.w"
  1271.  
  1272. app_repl(a);
  1273. while(id_first<id_loc){
  1274. if(*id_first=='@'){
  1275. if(*(id_first+1)=='@')id_first++;
  1276. else err_print("! Double @ should be used in string");
  1277.  
  1278. }
  1279. app_repl(*id_first++);
  1280. }
  1281. app_repl(a);break;
  1282.  
  1283. /*:80*/
  1284. #line 1249 "ctangle.w"
  1285. ;
  1286. case ord:
  1287. /*81:*/
  1288. #line 1286 "ctangle.w"
  1289. {
  1290. int c= (eight_bits)*id_first;
  1291. if(c=='\\'){
  1292. c= *++id_first;
  1293. if(c>='0'&&c<='7'){
  1294. c-= '0';
  1295. if(*(id_first+1)>='0'&&*(id_first+1)<='7'){
  1296. c= 8*c+*(++id_first)-'0';
  1297. if(*(id_first+1)>='0'&&*(id_first+1)<='7'&&c<32)
  1298. c= 8*c+*(++id_first)-'0';
  1299. }
  1300. }
  1301. else switch(c){
  1302. case't':c= '\t';break;
  1303. case'n':c= '\n';break;
  1304. case'b':c= '\b';break;
  1305. case'f':c= '\f';break;
  1306. case'v':c= '\v';break;
  1307. case'r':c= '\r';break;
  1308. case'a':c= '\7';break;
  1309. case'?':c= '?';break;
  1310. case'x':
  1311. if(xisdigit(*(id_first+1)))c= *(++id_first)-'0';
  1312. else if(xisxdigit(*(id_first+1))){
  1313. ++id_first;
  1314. c= toupper(*id_first)-'A'+10;
  1315. }
  1316. if(xisdigit(*(id_first+1)))c= 16*c+*(++id_first)-'0';
  1317. else if(xisxdigit(*(id_first+1))){
  1318. ++id_first;
  1319. c= 16*c+toupper(*id_first)-'A'+10;
  1320. }
  1321. break;
  1322. case'\\':c= '\\';break;
  1323. case'\'':c= '\'';break;
  1324. case'\"':c= '\"';break;
  1325. default:err_print("! Unrecognized escape sequence");
  1326.  
  1327. }
  1328. }
  1329.  
  1330. app_repl(constant);
  1331. if(c>=100)app_repl('0'+c/100);
  1332. if(c>=10)app_repl('0'+(c/10)%10);
  1333. app_repl('0'+c%10);
  1334. app_repl(constant);
  1335. }
  1336. break;
  1337.  
  1338. /*:81*/
  1339. #line 1251 "ctangle.w"
  1340. ;
  1341. case definition:case format_code:case begin_C:if(t!=section_name)goto done;
  1342. else{
  1343. err_print("! @d, @f and @c are ignored in C text");continue;
  1344.  
  1345. }
  1346. case new_section:goto done;
  1347.  
  1348. /*:78*/
  1349. #line 1206 "ctangle.w"
  1350.  
  1351. case')':app_repl(a);
  1352. if(t==macro)app_repl(' ');
  1353. break;
  1354. default:app_repl(a);
  1355. }
  1356. done:next_control= (eight_bits)a;
  1357. if(text_ptr>text_info_end)overflow("text");
  1358. cur_text= text_ptr;(++text_ptr)->tok_start= tok_ptr;
  1359. }
  1360.  
  1361. /*:76*//*83:*/
  1362. #line 1348 "ctangle.w"
  1363.  
  1364. void
  1365. scan_section()
  1366. {
  1367. name_pointer p;
  1368. text_pointer q;
  1369. sixteen_bits a;
  1370. section_count++;no_where= 1;
  1371. if(*(loc-1)=='*'&&show_progress){
  1372. printf("*%d",section_count);update_terminal;
  1373. }
  1374. next_control= 0;
  1375. while(1){
  1376. /*84:*/
  1377. #line 1387 "ctangle.w"
  1378.  
  1379. while(next_control<definition)
  1380.  
  1381. if((next_control= skip_ahead())==section_name){
  1382. loc-= 2;next_control= get_next();
  1383. }
  1384.  
  1385. /*:84*/
  1386. #line 1362 "ctangle.w"
  1387. ;
  1388. if(next_control==definition){
  1389. /*85:*/
  1390. #line 1394 "ctangle.w"
  1391. {
  1392. while((next_control= get_next())=='\n');
  1393. if(next_control!=identifier){
  1394. err_print("! Definition flushed, must start with identifier");
  1395.  
  1396. continue;
  1397. }
  1398. app_repl(((a= id_lookup(id_first,id_loc,0)-name_dir)/0400)+0200);
  1399.  
  1400. app_repl(a%0400);
  1401. if(*loc!='('){
  1402. app_repl(string);app_repl(' ');app_repl(string);
  1403. }
  1404. scan_repl(macro);
  1405. cur_text->text_link= 0;
  1406. }
  1407.  
  1408. /*:85*/
  1409. #line 1364 "ctangle.w"
  1410.  
  1411. continue;
  1412. }
  1413. if(next_control==begin_C){
  1414. p= name_dir;break;
  1415. }
  1416. if(next_control==section_name){
  1417. p= cur_section_name;
  1418. /*86:*/
  1419. #line 1419 "ctangle.w"
  1420.  
  1421. while((next_control= get_next())=='+');
  1422. if(next_control!='='&&next_control!=eq_eq)
  1423. continue;
  1424.  
  1425. /*:86*/
  1426. #line 1372 "ctangle.w"
  1427. ;
  1428. break;
  1429. }
  1430. return;
  1431. }
  1432. no_where= print_where= 0;
  1433. /*87:*/
  1434. #line 1424 "ctangle.w"
  1435.  
  1436. /*88:*/
  1437. #line 1429 "ctangle.w"
  1438.  
  1439. store_two_bytes((sixteen_bits)(0150000+section_count));
  1440.  
  1441.  
  1442. /*:88*/
  1443. #line 1425 "ctangle.w"
  1444. ;
  1445. scan_repl(section_name);
  1446. /*89:*/
  1447. #line 1433 "ctangle.w"
  1448.  
  1449. if(p==name_dir||p==0){
  1450. (last_unnamed)->text_link= cur_text-text_info;last_unnamed= cur_text;
  1451. }
  1452. else if(p->equiv==(char*)text_info)p->equiv= (char*)cur_text;
  1453.  
  1454. else{
  1455. q= (text_pointer)p->equiv;
  1456. while(q->text_link<section_flag)
  1457. q= q->text_link+text_info;
  1458. q->text_link= cur_text-text_info;
  1459. }
  1460. cur_text->text_link= section_flag;
  1461.  
  1462.  
  1463. /*:89*/
  1464. #line 1427 "ctangle.w"
  1465. ;
  1466.  
  1467. /*:87*/
  1468. #line 1378 "ctangle.w"
  1469. ;
  1470. }
  1471.  
  1472. /*:83*//*91:*/
  1473. #line 1451 "ctangle.w"
  1474.  
  1475. void
  1476. phase_one(){
  1477. phase= 1;
  1478. section_count= 0;
  1479. reset_input();
  1480. skip_limbo();
  1481. while(!input_has_ended)scan_section();
  1482. check_complete();
  1483. phase= 2;
  1484. }
  1485.  
  1486. /*:91*//*93:*/
  1487. #line 1469 "ctangle.w"
  1488.  
  1489. void
  1490. skip_limbo()
  1491. {
  1492. char c;
  1493. while(1){
  1494. if(loc>limit&&get_line()==0)return;
  1495. *(limit+1)= '@';
  1496. while(*loc!='@')loc++;
  1497. if(loc++<=limit){
  1498. c= *loc++;
  1499. if(ccode[(eight_bits)c]==new_section)break;
  1500. switch(ccode[(eight_bits)c]){
  1501. case translit_code:/*94:*/
  1502. #line 1498 "ctangle.w"
  1503.  
  1504. while(xisspace(*loc)&&loc<limit)loc++;
  1505. loc+= 3;
  1506. if(loc>limit||!xisxdigit(*(loc-3))||!xisxdigit(*(loc-2))
  1507. ||(*(loc-3)>='0'&&*(loc-3)<='7')||!xisspace(*(loc-1)))
  1508. err_print("! Improper hex number following @l");
  1509.  
  1510. else{
  1511. unsigned i;
  1512. char*beg;
  1513. sscanf(loc-3,"%x",&i);
  1514. while(xisspace(*loc)&&loc<limit)loc++;
  1515. beg= loc;
  1516. while(loc<limit&&(xisalpha(*loc)||xisdigit(*loc)||*loc=='_'))loc++;
  1517. if(loc-beg>=translit_length)
  1518. err_print("! Replacement string in @l too long");
  1519.  
  1520. else{
  1521. strncpy(translit[i-0200],beg,loc-beg);
  1522. translit[i-0200][loc-beg]= '\0';
  1523. }
  1524. }
  1525.  
  1526. /*:94*/
  1527. #line 1482 "ctangle.w"
  1528. ;break;
  1529. case format_code:case'@':break;
  1530. case control_text:if(c=='q'||c=='Q'){
  1531. while((c= skip_ahead())=='@');
  1532. if(*(loc-1)!='>')
  1533. err_print("! Double @ should be used in control text");
  1534.  
  1535. break;
  1536. }
  1537. default:err_print("! Double @ should be used in limbo");
  1538.  
  1539. }
  1540. }
  1541. }
  1542. }
  1543.  
  1544. /*:93*//*95:*/
  1545. #line 1524 "ctangle.w"
  1546.  
  1547. void
  1548. print_stats(){
  1549. printf("\nMemory usage statistics:\n");
  1550. printf("%ld names (out of %ld)\n",
  1551. (long)(name_ptr-name_dir),(long)max_names);
  1552. printf("%ld replacement texts (out of %ld)\n",
  1553. (long)(text_ptr-text_info),(long)max_texts);
  1554. printf("%ld bytes (out of %ld)\n",
  1555. (long)(byte_ptr-byte_mem),(long)max_bytes);
  1556. printf("%ld tokens (out of %ld)\n",
  1557. (long)(tok_ptr-tok_mem),(long)max_toks);
  1558. }
  1559.  
  1560. /*:95*/
  1561.