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

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