home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / c / cweb / ctangle.c < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-12  |  35.5 KB  |  1,805 lines

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