home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 3 / goldfish_volume_3.bin / files / dev / c / cweb / ctangle.cc < prev    next >
Encoding:
C/C++ Source or Header  |  1994-12-14  |  37.1 KB  |  1,899 lines

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