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

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