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

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