home *** CD-ROM | disk | FTP | other *** search
/ Dream 57 / Amiga_Dream_57.iso / Amiga / Programmation / c / Docs / cwebbin-p13.lha / cwebbin-p13 / ctangle.cxx < prev    next >
Encoding:
C/C++ Source or Header  |  1995-09-19  |  37.4 KB  |  1,896 lines

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