home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / dec93 / dev / misc / cweb.lha / CWeb / common-p.ch < prev    next >
Encoding:
Text File  |  1993-12-21  |  31.7 KB  |  931 lines

  1.                                 -*-Web-*-
  2. This file, COMMON-P.CH, is part of CWEB-p.
  3. It is a changefile for COMMON.H, Version 3.0.
  4.  
  5. Authors and Contributors:
  6. (H2B) Hans-Hermann Bode, Universität Osnabrück,
  7.   (hhbode@@dosuni1.rz.uni-osnabrueck.de or HHBODE@@DOSUNI1.BITNET).
  8.  
  9. (KG) Klaus Guntermann, TH Darmstadt,
  10.   (guntermann@@iti.informatik.th-darmstadt.de).
  11.  
  12. (AS) Andreas Scherer,
  13.   Abt-Wolf-Straße 17, 96215 Lichtenfels, Germany.
  14.  
  15. (CS) Carsten Steger, Universität München,
  16.   carsten.steger@informatik.tu-muenchen.de
  17.  
  18. Caveat utilitor:  Some of the source code introduced by this change file is
  19. made conditional to the use of specific compilers on specific systems.
  20. This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
  21.  
  22. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  23.  
  24. The following copyright notice extends to this changefile only, not to
  25. the masterfile COMMON.W.
  26.  
  27. Copyright (C) 1993 Andreas Scherer
  28. Copyright (C) 1991, 1993 Carsten Steger
  29. Copyright (C) 1991, 1992, 1993 Hans-Hermann Bode
  30.  
  31. Permission is granted to make and distribute verbatim copies of this
  32. document provided that the copyright notice and this permission notice
  33. are preserved on all copies.
  34.  
  35. Permission is granted to copy and distribute modified versions of this
  36. document under the conditions for verbatim copying, provided that the
  37. entire resulting derived work is distributed under the terms of a
  38. permission notice identical to this one.
  39.  
  40. Version history:
  41.  
  42. Version    Date        Author    Comment
  43. a1/t1    10 Oct 1991    H2B    First attempt for COMMON.W 2.0.
  44. p2    13 Feb 1992    H2B    Updated for COMMON.W 2.1, ANSI and Turbo
  45.                 changefiles merged together.
  46. p3    16 Apr 1992    H2B    Updated for COMMON.W 2.2, change option for
  47.                 |@@i| completed.
  48. p4    22 Jun 1992    H2B    Updated for COMMON.W 2.4, getting INCLUDEDIR
  49.                 from environment variable CWEBINCLUDE.
  50. p5    19 Jul 1992    H2B    string.h included, usage message extended.
  51. p5a    24 Jul 1992    KG    adaptions for other ANSI C compiler
  52. p5b    28 Jul 1992    H2B    Remaining headers converted to ANSI style.
  53. p5c    30 Jul 1992    KG    removed comments used after #endif
  54. p6    06 Sep 1992    H2B    Updated for COMMON.W 2.7.
  55. p6a     15 Mar 1993     AS      adaptions for SAS/C 6.0 compiler
  56. p6b     28 Jul 1993     AS      path delimiters are `/' or `:' for AMIGA
  57.     31 Aug 1993    AS    return codes extended to AMIGA values
  58. p6c    04 Sep 1993    AS    path searching with CWEBINCLUDE
  59. p6d    09 Oct 1993    AS    Updated for COMMON.W 2.8. (This was p7 for me)
  60. p7    06 Nov 1992    H2B    Converted to master change file, updated for
  61.                 common.w 2.8. [Not released.]
  62. p7.5    29 Nov 1992    H2B    Updated for common.w 2.9beta. [Not released.]
  63. p8    04 Dec 1992    H2B    Updated for common.w 2.9++ (stuff went into
  64.                 the source file). [Not released.]
  65. p8a    10 Mar 1993    H2B    Restructured for public release.
  66.                 [Not released.]
  67. p8b    15 Apr 1993    H2B    Updated for common.w 3.0beta. [Not released.]
  68. p8c    21 Jun 1993    H2B    Updated for final common.w 3.0.
  69. p8d    26 Oct 1993    AS    Incorporated with Amiga version 2.8 [p7] and
  70.                 updated to version 3.0.
  71. ------------------------------------------------------------------------------
  72. @x l.1
  73. % This file is part of CWEB.
  74. % This program by Silvio Levy and Donald E. Knuth
  75. % is based on a program by Knuth.
  76. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  77. % Version 3.0 --- June 1993
  78.  
  79. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  80. @y
  81. % This file, common.w, is part of CWEB-p.
  82. % This program by Silvio Levy and Donald E. Knuth
  83. % is based on a program by Knuth.
  84. % It is distributed WITHOUT ANY WARRANTY, express or implied.
  85. % Version 2.4 --- Don Knuth, June 1992
  86. % Version 2.4 [p5] --- Hans-Hermann Bode, July 1992
  87. % Version 2.4 [p5a] --- Klaus Guntermann, July 1992
  88. % Version 2.4 [p5b] --- Hans-Hermann Bode, July 1992
  89. % Version 2.4 [p5c] --- Klaus Guntermann, July 1992
  90. % Version 2.7 [p6] --- Hans-Hermann Bode, September 1992
  91. % Version 2.7 [p6a] --- Andreas Scherer, March 1993
  92. % Version 2.7 [p6b] --- Andreas Scherer, August 1993
  93. % Version 2.7 [p6c] --- Andreas Scherer, September 1993
  94. % Version 2.8 --- Don Knuth, June 1992
  95. % Version 2.8 [p7] --- Andreas Scherer, October 1993
  96. % Version 3.0 --- Don Knuth, June 1993
  97. % Version 3.0 [p8c] --- Hans-Hermann Bode, June 1993
  98. % Version 3.0 [p8d] --- Andreas Scherer, October 1993
  99.  
  100. % Copyright (C) 1987,1990,1993 Silvio Levy and Donald E. Knuth
  101. % Copyright (C) 1991,1992,1993 Hans-Hermann Bode
  102. % Copyright (C) 1991,1993 Carsten Steger
  103. % Copyright (C) 1993 Andreas Scherer
  104. @z
  105. ------------------------------------------------------------------------------
  106. @x l.20
  107. \def\title{Common code for CTANGLE and CWEAVE (Version 3.0)}
  108. @y
  109. \def\title{Common code for CTANGLE and CWEAVE (Version 3.0 [p8d])}
  110. @z
  111. ------------------------------------------------------------------------------
  112. @x l.25
  113.   \centerline{(Version 3.0)}
  114. @y
  115.   \centerline{(Version 3.0 [p8d])}
  116. @z
  117. ------------------------------------------------------------------------------
  118. @x l.29
  119. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  120. @y
  121. Copyright \copyright\ 1987, 1990, 1993 Silvio Levy and Donald E. Knuth
  122. \smallskip\noindent
  123. Copyright \copyright\ 1991, 1992, 1993 Hans-Hermann Bode
  124. \smallskip\noindent
  125. Copyright \copyright\ 1991, 1993 Carsten Steger
  126. \smallskip\noindent
  127. Copyright \copyright\ 1993 Andreas Scherer
  128. @z
  129. ------------------------------------------------------------------------------
  130. Activate this, if only the changed modules should be printed.
  131. x l.43
  132. \let\maybe=\iftrue
  133. y
  134. \let\maybe=\iffalse
  135. z
  136. ------------------------------------------------------------------------------
  137. @x l.58
  138. @<Include files@>@/
  139. @y
  140. @<Include files@>@/
  141. @<Macro definitions@>@/
  142. @z
  143. ------------------------------------------------------------------------------
  144. @x l.89
  145. void
  146. common_init()
  147. @y
  148. void common_init(void)
  149. @z
  150. ------------------------------------------------------------------------------
  151. Correct a type.
  152. @x l.108
  153. character set can type things like \.{\char'32} and \.{char'4} instead
  154. @y
  155. character set can type things like \.{\char'32} and \.{\char'4} instead
  156. @z
  157. ------------------------------------------------------------------------------
  158. @x l.169
  159. int input_ln(fp) /* copies a line into |buffer| or returns 0 */
  160. FILE *fp; /* what file to read from */
  161. @y
  162. static int input_ln(FILE *fp) /* copies a line into |buffer| or returns 0 */
  163. /* |fp|: what file to read from */
  164. @z
  165. ------------------------------------------------------------------------------
  166. AmigaDOS allows path names with up to 255 characters.
  167. @x l.203
  168. @d max_file_name_length 60
  169. @y
  170. @d max_file_name_length 256
  171. @z
  172. ------------------------------------------------------------------------------
  173. Correct a typo.
  174. @x l.225
  175. @ When |changing=0|, the next line of |change_file| is kept in
  176. @y
  177. @ When |changing==0|, the next line of |change_file| is kept in
  178. @z
  179. ------------------------------------------------------------------------------
  180. @x l.248
  181. void
  182. prime_the_change_buffer()
  183. @y
  184. static void prime_the_change_buffer(void)
  185. @z
  186. ------------------------------------------------------------------------------
  187. @x l.317
  188. void
  189. check_change() /* switches to |change_file| if the buffers match */
  190. @y
  191. static void check_change(void) /* switches to |change_file| if the buffers match */
  192. @z
  193. ------------------------------------------------------------------------------
  194. @x l.375
  195. void
  196. reset_input()
  197. @y
  198. void reset_input(void)
  199. @z
  200. ------------------------------------------------------------------------------
  201. @x l.423
  202. int get_line() /* inputs the next line */
  203. @y
  204. int get_line(void) /* inputs the next line */
  205. @z
  206. ------------------------------------------------------------------------------
  207. @x l.452
  208. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  209. stop reading it and start reading from the named include file.  The
  210. \.{@@i} line should give a complete file name with or without
  211. double quotes.
  212. If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag
  213. of the same name was defined at compile time,
  214. \.{CWEB} will look for include files in the directory thus named, if
  215. it cannot find them in the current directory.
  216. (Colon-separated paths are not supported.)
  217. The remainder of the \.{@@i} line after the file name is ignored.
  218. @y
  219. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  220. stop reading it and start reading from the named include file.  The
  221. \.{@@i} line should give a complete file name with or without
  222. double quotes.  The remainder of the \.{@@i} line after the file name
  223. is ignored.  \.{CWEB} will look for include files in standard directories
  224. specified in the environment variable \.{CWEBINPUTS}. Multiple search paths
  225. can be specified by delimiting them with \.{PATH\_SEPARATOR}s.  The given
  226. file is searched for in the current directory first.  You also may include
  227. device names; these must have a \.{DEVICE\_SEPARATOR} as their rightmost
  228. character.
  229.  
  230. @d PATH_SEPARATOR   ','
  231. @d DIR_SEPARATOR    '/'
  232. @d DEVICE_SEPARATOR ':'
  233. @z
  234. ------------------------------------------------------------------------------
  235. CWEB will perform a path search for `@i'nclude files along the environment
  236. variable CWEBINPUTS in case the given file can not be opened in the current
  237. directory or in the absolute path.  The single paths are delimited by
  238. PATH_SEPARATORs.
  239. @x l.483
  240.   kk=getenv("CWEBINPUTS");
  241.   if (kk!=NULL) {
  242.     if ((l=strlen(kk))>max_file_name_length-2) too_long();
  243.     strcpy(temp_file_name,kk);
  244.   }
  245.   else {
  246. #ifdef CWEBINPUTS
  247.     if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
  248.     strcpy(temp_file_name,CWEBINPUTS);
  249. #else
  250.     l=0;
  251. #endif /* |CWEBINPUTS| */
  252.   }
  253.   if (l>0) {
  254.     if (k+l+2>=cur_file_name_end)  too_long();
  255. @.Include file name ...@>
  256.     for (; k>= cur_file_name; k--) *(k+l+1)=*k;
  257.     strcpy(cur_file_name,temp_file_name);
  258.     cur_file_name[l]='/'; /* \UNIX/ pathname separator */
  259.     if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
  260.       cur_line=0; print_where=1;
  261.       goto restart; /* success */
  262.     }
  263.   }
  264. @y
  265.   if(0==set_path(include_path,getenv("CWEBINPUTS"))) {
  266.     include_depth--; goto restart; /* internal error */
  267.   }
  268.   path_prefix = include_path;
  269.   while(path_prefix) {
  270.     for(kk=temp_file_name, p=path_prefix, l=0;
  271.       p && *p && *p!=PATH_SEPARATOR;
  272.       *kk++ = *p++, l++);
  273.     if(path_prefix && *path_prefix && *path_prefix!=PATH_SEPARATOR &&
  274.       *--p!=DEVICE_SEPARATOR && *p!=DIR_SEPARATOR) {
  275.       *kk++ = DIR_SEPARATOR; l++;
  276.     }
  277.     if(k+l+2>=cur_file_name_end) too_long(); /* emergency break */
  278.     strcpy(kk,cur_file_name);
  279.     if(cur_file = fopen(temp_file_name,"r")) {
  280.       cur_line=0; print_where=1; goto restart; /* success */
  281.     }
  282.     if(next_path_prefix = strchr(path_prefix,PATH_SEPARATOR))
  283.       path_prefix = next_path_prefix+1;
  284.     else break; /* no more paths to search; no file found */
  285.   }
  286. @z
  287. ------------------------------------------------------------------------------
  288. @x l.560
  289. void
  290. check_complete(){
  291. @y
  292. void check_complete(void){
  293. @z
  294. ------------------------------------------------------------------------------
  295. @x l.586
  296.   char *byte_start; /* beginning of the name in |byte_mem| */
  297. @y
  298.   char HUGE *byte_start; /* beginning of the name in |byte_mem| */
  299. @z
  300. ------------------------------------------------------------------------------
  301. @x l.589
  302. typedef name_info *name_pointer; /* pointer into array of |name_info|s */
  303. char byte_mem[max_bytes]; /* characters of names */
  304. char *byte_mem_end = byte_mem+max_bytes-1; /* end of |byte_mem| */
  305. name_info name_dir[max_names]; /* information about names */
  306. name_pointer name_dir_end = name_dir+max_names-1; /* end of |name_dir| */
  307. @y
  308. typedef name_info HUGE *name_pointer; /* pointer into array of |name_info|s */
  309. #ifdef __TURBOC__
  310. char HUGE *byte_mem; /* characters of names */
  311. char HUGE *byte_mem_end; /* end of |byte_mem| */
  312. name_info HUGE *name_dir; /* information about names */
  313. name_pointer name_dir_end; /* end of |name_dir| */
  314. #else
  315. char byte_mem[max_bytes]; /* characters of names */
  316. char *byte_mem_end = byte_mem+max_bytes-1; /* end of |byte_mem| */
  317. name_info name_dir[max_names]; /* information about names */
  318. name_pointer name_dir_end = name_dir+max_names-1; /* end of |name_dir| */
  319. #endif
  320. @z
  321. ------------------------------------------------------------------------------
  322. @x l.609
  323. char *byte_ptr; /* first unused position in |byte_mem| */
  324. @y
  325. char HUGE *byte_ptr; /* first unused position in |byte_mem| */
  326. @z
  327. ------------------------------------------------------------------------------
  328. @x l.612
  329. name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
  330. @y
  331. #ifdef __TURBOC__
  332. byte_mem=allocsafe(max_bytes,sizeof(*byte_mem));
  333. byte_mem_end=byte_mem+max_bytes-1;
  334. name_dir=allocsafe(max_names,sizeof(*name_dir));
  335. name_dir_end=name_dir+max_names-1;
  336. #endif
  337. name_dir->byte_start=byte_ptr=byte_mem; /* position zero in both arrays */
  338. @z
  339. ------------------------------------------------------------------------------
  340. @x l.622
  341. struct name_info *link;
  342. @y
  343. struct name_info HUGE *link;
  344. @z
  345. ------------------------------------------------------------------------------
  346. @x l.640
  347. @ @<Predec...@>=
  348. extern int names_match();
  349. @y
  350. @ @<Predec...@>=
  351. extern int names_match(name_pointer,char *,int,eight_bits);@/
  352. @z
  353. ------------------------------------------------------------------------------
  354. In the following, the parameter t must be of type char to be accordant with
  355. CWEAVE.
  356. @x l.652
  357. name_pointer
  358. id_lookup(first,last,t) /* looks up a string in the identifier table */
  359. char *first; /* first character of string */
  360. char *last; /* last character of string plus one */
  361. char t; /* the |ilk|; used by \.{CWEAVE} only */
  362. @y
  363. name_pointer id_lookup(char *first,char *last,char t)
  364. /* looks up a string in the identifier table */
  365. /* |first|: first character of string */
  366. /* |last|:  last character of string plus one */
  367. /* |t|:     the |ilk|; used by \.{CWEAVE} only */
  368. @z
  369. ------------------------------------------------------------------------------
  370. @x l.693
  371. @<Pred...@>=
  372. void init_p();
  373. @y
  374. @<Pred...@>=
  375. extern void init_p(name_pointer,eight_bits);@/
  376. @z
  377. ------------------------------------------------------------------------------
  378. @x l.722
  379.   struct name_info *Rlink; /* right link in binary search tree for section
  380. @y
  381.   struct name_info HUGE *Rlink; /* right link in binary search tree for section
  382. @z
  383. ------------------------------------------------------------------------------
  384. @x l.755
  385. void
  386. print_section_name(p)
  387. name_pointer p;
  388. @y
  389. void print_section_name(name_pointer p)
  390. @z
  391. ------------------------------------------------------------------------------
  392. @x l.759
  393.   char *ss, *s = first_chunk(p);
  394. @y
  395.   char HUGE *ss;
  396.   char HUGE *s = first_chunk(p);
  397. @z
  398. ------------------------------------------------------------------------------
  399. @x l.774
  400. void
  401. sprint_section_name(dest,p)
  402.   char*dest;
  403.   name_pointer p;
  404. @y
  405. void sprint_section_name(char *dest,name_pointer p)
  406. @z
  407. ------------------------------------------------------------------------------
  408. @x l.779
  409.   char *ss, *s = first_chunk(p);
  410. @y
  411.   char HUGE *ss;
  412.   char HUGE *s = first_chunk(p);
  413. @z
  414. ------------------------------------------------------------------------------
  415. @x l.795
  416. void
  417. print_prefix_name(p)
  418. name_pointer p;
  419. @y
  420. void print_prefix_name(name_pointer p)
  421. @z
  422. ------------------------------------------------------------------------------
  423. @x l.799
  424.   char *s = first_chunk(p);
  425. @y
  426.   char HUGE *s = first_chunk(p);
  427. @z
  428. ------------------------------------------------------------------------------
  429. @x l.816
  430. int web_strcmp(j,j_len,k,k_len) /* fuller comparison than |strcmp| */
  431.   char *j, *k; /* beginning of first and second strings */
  432.   int j_len, k_len; /* length of strings */
  433. {
  434.   char *j1=j+j_len, *k1=k+k_len;
  435. @y
  436. static int web_strcmp(char HUGE *j, int j_len, char HUGE *k, int k_len)
  437.  /* fuller comparison than |strcmp| */
  438.  /* |j|: beginning of first string */
  439.  /* |k|: beginning of second string */
  440.  /* |j_len|: length of first string */
  441.  /* |k_len|: length of second string */
  442. {
  443.   char HUGE *j1=j+j_len;
  444.   char HUGE *k1=k+k_len;
  445. @z
  446. ------------------------------------------------------------------------------
  447. @x l.842
  448. @<Prede...@>=
  449. extern void init_node();
  450. @y
  451. @<Prede...@>=
  452. extern void init_node(name_pointer);@/
  453. @z
  454. ------------------------------------------------------------------------------
  455. @x l.846
  456. name_pointer
  457. add_section_name(par,c,first,last,ispref) /* install a new node in the tree */
  458. name_pointer par; /* parent of new node */
  459. int c; /* right or left? */
  460. char *first; /* first character of section name */
  461. char *last; /* last character of section name, plus one */
  462. int ispref; /* are we adding a prefix or a full name? */
  463. @y
  464. name_pointer add_section_name(name_pointer par, int c,
  465.   char *first, char *last, int ispref)
  466.   /* install a new node in the tree */
  467.   /* par: parent of new node */
  468.   /* c: right or left? */
  469.   /* first: first character of section name */
  470.   /* last: last character of section name, plus one */
  471.   /* ispref: are we adding a prefix or a full name? */
  472. @z
  473. ------------------------------------------------------------------------------
  474. @x l.855
  475.   char *s=first_chunk(p);
  476. @y
  477.   char HUGE *s=first_chunk(p);
  478. @z
  479. ------------------------------------------------------------------------------
  480. @x l.875
  481. void
  482. extend_section_name(p,first,last,ispref)
  483. name_pointer p; /* name to be extended */
  484. char *first; /* beginning of extension text */
  485. char *last; /* one beyond end of extension text */
  486. int ispref; /* are we adding a prefix or a full name? */
  487. @y
  488. void extend_section_name(name_pointer p,char *first,char *last,int ispref)
  489.   /* p: name to be extended */
  490.   /* first: beginning of extension text */
  491.   /* last: one beyond end of extension text */
  492.   /* ispref: are we adding a prefix or a full name? */
  493. @z
  494. ------------------------------------------------------------------------------
  495. @x l.882
  496.   char *s;
  497. @y
  498.   char HUGE *s;
  499. @z
  500. ------------------------------------------------------------------------------
  501. Correct a typo.
  502. @x l.898
  503. its doesn't match an existing one. The new name is the string
  504. @y
  505. it doesn't match an existing one. The new name is the string
  506. @z
  507. ------------------------------------------------------------------------------
  508. @x l.903
  509. name_pointer
  510. section_lookup(first,last,ispref) /* find or install section name in tree */
  511. char *first, *last; /* first and last characters of new name */
  512. int ispref; /* is the new name a prefix or a full name? */
  513. @y
  514. name_pointer section_lookup(char *first,char *last,int ispref)
  515.   /* find or install section name in tree */
  516.   /* first, last: first and last characters of new name */
  517.   /* ispref: is the new name a prefix or a full name? */
  518. @z
  519. ------------------------------------------------------------------------------
  520. @x l.1007
  521. @<Predec...@>=
  522. int section_name_cmp();
  523. @y
  524. @<Predec...@>=
  525. static int section_name_cmp(char **,int,name_pointer);@/
  526. @z
  527. ------------------------------------------------------------------------------
  528. @x l.1011
  529. int section_name_cmp(pfirst,len,r)
  530. char **pfirst; /* pointer to beginning of comparison string */
  531. int len; /* length of string */
  532. name_pointer r; /* section name being compared */
  533. @y
  534. static int section_name_cmp(char **pfirst,int len,name_pointer r)
  535.   /*pfirst: pointer to beginning of comparison string */
  536.   /* len: length of string */
  537.   /* r: section name being compared */
  538. @z
  539. ------------------------------------------------------------------------------
  540. @x l.1018
  541.   char *ss, *s=first_chunk(r);
  542. @y
  543.   char HUGE *ss;
  544.   char HUGE *s=first_chunk(r);
  545. @z
  546. ------------------------------------------------------------------------------
  547. @x l.1053
  548. char *equiv_or_xref; /* info corresponding to names */
  549. @y
  550. char HUGE *equiv_or_xref; /* info corresponding to names */
  551. @z
  552. ------------------------------------------------------------------------------
  553. Correct a typo.
  554. @x l.1080
  555. if the string begins with |"|"|.
  556. @y
  557. if the string begins with |"!"|.
  558. @z
  559. ------------------------------------------------------------------------------
  560. @x l.1082
  561. @<Predecl...@>=
  562. void  err_print();
  563. @y
  564. @<Predecl...@>=
  565. extern void err_print(char *);@/
  566. @z
  567. ------------------------------------------------------------------------------
  568. @x l.1087
  569. void
  570. err_print(s) /* prints `\..' and location of error message */
  571. char *s;
  572. @y
  573. void err_print(char *s) /* prints `\..' and location of error message */
  574. @z
  575. ------------------------------------------------------------------------------
  576. @x l.1130
  577. @<Prede...@>=
  578. int wrap_up();
  579. extern void print_stats();
  580. @y
  581. @<Prede...@>=
  582. int wrap_up(void);@/
  583. extern void print_stats(void);@/
  584. @z
  585. ------------------------------------------------------------------------------
  586. On the AMIGA it is very convenient to know a little bit more about the reasons
  587. why a program failed.  There are four levels of return for this purpose.
  588. Let CWeb be so kind to use them, so ARexx scripts can be made better.
  589. @x l.1134
  590. @ Some implementations may wish to pass the |history| value to the
  591. operating system so that it can be used to govern whether or not other
  592. programs are started. Here, for instance, we pass the operating system
  593. a status of 0 if and only if only harmless messages were printed.
  594. @^system dependencies@>
  595.  
  596. @c
  597. int wrap_up() {
  598.   putchar('\n');
  599.   if (show_stats)
  600.     print_stats(); /* print statistics about memory usage */
  601.   @<Print the job |history|@>;
  602.   if (history > harmless_message) return(1);
  603.   else return(0);
  604. }
  605. @y
  606. @ On multi-tasking systems like the Amiga it is very convenient to know
  607. a little bit more about the reasons why a program failed.  The four levels
  608. of return indicated by the |history| value are very suitable for this
  609. purpose.  Here, for instance, we pass the operating system a status of~0
  610. if and only if the run was a complete success.  Any warning or error
  611. message will result in a higher return value, so ARexx scripts can be
  612. made sensitive to these conditions.
  613. @^system dependencies@>
  614.  
  615. @d RETURN_OK     0 /* No problems, success */
  616. @d RETURN_WARN   5 /* A warning only */
  617. @d RETURN_ERROR 10 /* Something wrong */
  618. @d RETURN_FAIL  20 /* Complete or severe failure */
  619.  
  620. @c
  621. int wrap_up(void) {
  622.   putchar('\n');
  623.   if (show_stats) print_stats(); /* print statistics about memory usage */
  624.   @<Print the job |history|@>;
  625.   switch(history) {
  626.   case harmless_message: return(RETURN_WARN); break;
  627.   case error_message: return(RETURN_ERROR); break;
  628.   case fatal_message: return(RETURN_FAIL); break;
  629.   default: return(RETURN_OK);
  630.     }
  631.   }
  632. @z
  633. ------------------------------------------------------------------------------
  634. @x l.1163
  635. @<Predec...@>=
  636. void fatal(), overflow();
  637. @y
  638. @<Predec...@>=
  639. extern void fatal(char *,char *);
  640. extern void overflow(char *);
  641. @z
  642. ------------------------------------------------------------------------------
  643. On the AMIGA there is a list of additional identifiers that have to be
  644. formatted correctly.  Also for German programmers it is more convenient to
  645. write German program documentations.  This changes by Andreas Scherer are
  646. based on ideas of Carsten Steger as of his `CWeb 2.0' port from ><> 551 and
  647. his `CWeb 2.8' port from the electronic nets.  First we correct a typo.
  648. @x l.1199
  649. or flags to be turned on (beginning with |"+"|.
  650. The following globals are for communicating the user's desires to the rest
  651. of the program. The various file name variables contain strings with
  652. the names of those files. Most of the 128 flags are undefined but available
  653. for future extensions.
  654.  
  655. @d show_banner flags['b'] /* should the banner line be printed? */
  656. @d show_progress flags['p'] /* should progress reports be printed? */
  657. @d show_stats flags['s'] /* should statistics be printed at end of run? */
  658. @d show_happiness flags['h'] /* should lack of errors be announced? */
  659. @y
  660. or flags to be turned on (beginning with |"+"|).
  661. The following globals are for communicating the user's desires to the rest
  662. of the program. The various file name variables contain strings with
  663. the names of those files. Most of the 256 flags are undefined but available
  664. for future extensions.
  665.  
  666. @d show_banner flags['b'] /* should the banner line be printed? */
  667. @d show_progress flags['p'] /* should progress reports be printed? */
  668. @d show_stats flags['s'] /* should statistics be printed at end of run? */
  669. @d show_happiness flags['h'] /* should lack of errors be announced? */
  670. @d use_amiga_keywords flags['a'] /* should Amiga/SAS C keywords be used? */
  671. @d use_german_macros flags['g'] /* should the output be German? */
  672. @d indent_param_decl flags['i'] /* should formal parameter declarations be indented? */
  673. @z
  674. ----------------------------------------------------------------------
  675. @x l.1217
  676. boolean flags[128]; /* an option for each 7-bit code */
  677. @y
  678. boolean flags[256]; /* an option for each 8-bit code */
  679. @z
  680. ------------------------------------------------------------------------------
  681. @x l.1223
  682. @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
  683. show_banner=show_happiness=show_progress=1;
  684. @y
  685. @<Set the default options common to \.{CTANGLE} and \.{CWEAVE}@>=
  686. show_banner=show_happiness=show_progress=1;
  687. #ifdef _AMIGA
  688. use_amiga_keywords=
  689. #endif
  690. use_german_macros=indent_param_decl=1;
  691. @z
  692. ----------------------------------------------------------------------
  693. @x l.1235
  694. An omitted change file argument means that |"/dev/null"| should be used,
  695. when no changes are desired.
  696. @y
  697. An omitted change file argument means that |"/dev/null"| or---on {\mc
  698. MS-DOS} systems---|"nul"| or---on {\mc AMIGA} systems---|"NIL:"| should be
  699. used, when no changes are desired.
  700. @z
  701. ------------------------------------------------------------------------------
  702. @x l.1241
  703. @<Pred...@>=
  704. void scan_args();
  705. @y
  706. @<Pred...@>=
  707. static void scan_args(void);@/
  708. @z
  709. ------------------------------------------------------------------------------
  710. @x l.1245
  711. void
  712. scan_args()
  713. @y
  714. static void scan_args(void)
  715. @z
  716. ------------------------------------------------------------------------------
  717. For consistency we include both AMIGA path delimiters; else there would be
  718. a difference in the output file name when compiling files from an other
  719. device, especially `RAM:'.
  720. @x l.1259
  721.       while (*s) {
  722.         if (*s=='.') dot_pos=s++;
  723.         else if (*s=='/') dot_pos=NULL,name_pos=++s;
  724.         else s++;
  725.       }
  726. @y
  727.       while (*s) {
  728.         if (*s=='.') dot_pos=s++;
  729. #ifdef _AMIGA
  730.         else if ((*s=='/') || (*s==':')) dot_pos=NULL,name_pos=++s;
  731. #else
  732.         else if (*s=='/') dot_pos=NULL,name_pos=++s;
  733. #endif
  734.         else s++;
  735.       }
  736. @z
  737. ------------------------------------------------------------------------------
  738. @x l.1272
  739.   if (!found_change) strcpy(change_file_name,"/dev/null");
  740. @y
  741. #if defined( __TURBOC__ )
  742.   if (!found_change) strcpy(change_file_name,"nul");
  743. #elif defined( _AMIGA )
  744.   if (!found_change) strcpy(change_file_name,"NIL:");
  745. #else
  746.   if (!found_change) strcpy(change_file_name,"/dev/null");
  747. #endif
  748. @z
  749. ------------------------------------------------------------------------------
  750. @x l.1346
  751.   fatal(
  752. "! Usage: ctangle [options] webfile[.w] [changefile[.ch] [outfile[.c]]]\n"
  753.    ,"");
  754. @.Usage:@>
  755. else fatal(
  756. "! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"
  757.    ,"");
  758. @y
  759.   fatal(
  760.     "! Usage: ctangle [options] webfile[.w] [changefile[.ch] [outfile[.c]]]\n"@|
  761.     "Options are (+ turns on, - turns off, default in brackets):\n"@|
  762.     "b print banner line [+]\n"@|
  763.     "h print happy message [+]\n"@|
  764.     "p give progress reports [+]\n"@|
  765.     "s show statistics [-]\n"@|
  766.    ,"");
  767. @.Usage:@>
  768. #ifdef _AMIGA
  769. else fatal(
  770.     "! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"@|
  771.     "Options are (+ turns on, - turns off, default in brackets):\n"@|
  772.     "a use AMIGA specific keywords [+]\n"@|
  773.     "b print banner line [+]\n"@|
  774.     "f force line breaks [+]\n"@|
  775.     "g use German macros as of gcwebmac.tex [+]\n"@|
  776.     "h print happy message [+]\n"@|
  777.     "i indent parameter declarations [+]\n"@|
  778.     "p give progress reports [+]\n"@|
  779.     "s show statistics [-]\n"@|
  780.     "x include indexes and table of contents [+]\n"@|
  781.    ,"");
  782. #else
  783. else fatal(
  784.     "! Usage: cweave [options] webfile[.w] [changefile[.ch] [outfile[.tex]]]\n"@|
  785.     "Options are (+ turns on, - turns off, default in brackets):\n"@|
  786.     "b print banner line [+]\n"@|
  787.     "f force line breaks [+]\n"@|
  788.     "g use German macros as of gcwebmac.tex [+]\n"@|
  789.     "h print happy message [+]\n"@|
  790.     "i indent parameter declarations [+]\n"@|
  791.     "p give progress reports [+]\n"@|
  792.     "s show statistics [-]\n"@|
  793.     "x include indexes and table of contents [+]\n"@|
  794.    ,"");
  795. #endif
  796. @z
  797. ------------------------------------------------------------------------------
  798. @x l.1402 Will be declared in <string.h> below.
  799. @<Predecl...@>=
  800. extern int strlen(); /* length of string */
  801. extern int strcmp(); /* compare strings lexicographically */
  802. extern char* strcpy(); /* copy one string to another */
  803. extern int strncmp(); /* compare up to $n$ string characters */
  804. extern char* strncpy(); /* copy up to $n$ string characters */
  805.  
  806. @** Index.
  807. @y
  808. @<Include...@>=
  809. #include <string.h>
  810.  
  811. @* Path searching.  On default, CTangle and CWeave are looking for include
  812. files along the path |CWEBINPUTS| given in this source file.  By setting
  813. the environment variable of the same name to a different search path that
  814. suits your personal needs, you may override the default on startup.  The
  815. following procdure copies the value of the environment variable (if any) to
  816. the variable |include_path| used for path searching.
  817.  
  818. @c
  819. static boolean set_path(char *ptr,char *override)
  820. {
  821.   if(override) {
  822.     if(strlen(override) >= MAXPATHLENGTH) {
  823.       err_print("! Include path too long"); return(0);
  824. @.Include path too long@>
  825.     }
  826.     else strcpy(ptr, override);
  827.   }
  828.   return(1);
  829. }
  830.  
  831. @ The path search algorithm defined in section |@<Try to open...@>|
  832. needs a few extra variables.  The search path given in the environment
  833. variable |CWEBINPUTS| must not be longer than |MAXPATHLENGTH|.  If no
  834. string is given in this variable, the internal default |CWEBINPUTS| is
  835. used instead, which holds some sensible paths.
  836.  
  837. @d MAXPATHLENGTH 4095
  838. @d CWEBINPUTS ",CWeb:,CWeb:include,CWeb:inputs"
  839.  
  840. @<Other...@>=
  841. char include_path[MAXPATHLENGTH+1]=CWEBINPUTS;@/
  842. char *p, *path_prefix, *next_path_prefix;@/
  843.  
  844. @* Memory allocation. Due to restrictions of most {\mc MS-DOS}-\CEE/ compilers,
  845. large arrays will be allocated dynamically rather than statically. In the {\mc
  846. TURBO}-\CEE/ implementation the |farcalloc| function provides a way to allocate
  847. more than 64~KByte of data. The |allocsafe| function tries to carry out an
  848. allocation of |nunits| blocks of size |unitsz| by calling |farcalloc| and takes
  849. a safe method, when this fails: the program will be aborted.
  850.  
  851. To deal with such allocated data areas |huge| pointers will be used in this
  852. implementation.
  853.  
  854. @f far int
  855. @f huge int
  856. @f HUGE int
  857.  
  858. @<Pred...@>=
  859. extern void far *allocsafe(unsigned long,unsigned long);
  860. @^system dependencies@>
  861.  
  862. @ @c
  863. #ifdef __TURBOC__
  864. void far *allocsafe (unsigned long nunits,unsigned long unitsz)
  865. {
  866.   void far *p = farcalloc(nunits,unitsz);
  867.   if (p==NULL) fatal("","! Memory allocation failure");
  868. @.Memory allocation failure@>
  869.   return p;
  870. }
  871. #endif
  872. @^system dependencies@>
  873.  
  874. @ @<Include...@>=
  875. #ifdef __TURBOC__
  876. #include <alloc.h> /* import |farcalloc| */
  877. #include <io.h> /* import |write| */
  878. #endif
  879. @^system dependencies@>
  880.  
  881. @ @<Macro...@>=
  882. #ifdef __TURBOC__
  883. #define HUGE huge
  884. #else
  885. #define HUGE
  886. #endif
  887. @^system dependencies@>
  888.  
  889. @* Function declarations. Here are declarations, conforming to {\mc ANSI~C}, of
  890. all functions in this code that appear in |"common.h"| and thus should
  891. agree with \.{CTANGLE} and \.{CWEAVE}.
  892.  
  893. @<Other...@>=
  894. #ifdef _AMIGA /* I don't know, which form is correct */
  895. typedef unsigned char eight_bits;
  896. #else
  897. typedef char unsigned eight_bits;
  898. #endif
  899. void common_init(void);@/
  900. void reset_input(void);@/
  901. int get_line(void);@/
  902. void check_complete(void);@/
  903. name_pointer id_lookup(char *first,char *last,char t);@/
  904. void print_section_name(name_pointer);@/
  905. void sprint_section_name(char *,name_pointer);@/
  906. void print_prefix_name(name_pointer);@/
  907. name_pointer add_section_name(name_pointer par, int c,
  908.   char *first, char *last, int ispref);@/
  909. void extend_section_name(name_pointer p,char *first,char *last,int ispref);@/
  910. name_pointer section_lookup(char *first,char *last,int ispref);
  911.  
  912. @ The following functions are private to |"common.w"|.
  913.  
  914. @<Other...@>=
  915. static int input_ln(FILE *fp);@/
  916. static void prime_the_change_buffer(void);@/
  917. static void check_change(void);@/
  918. static int web_strcmp(char HUGE *j, int j_len, char HUGE *k, int k_len);@/
  919. static boolean set_path(char *ptr, char *override);@/
  920.  
  921. @ Finally, we include \.{stdlib.h} that contains the prototype for the
  922. |getenv| function used above and \.{string.h} for |strncmp|, |strncpy|,
  923. |strcpy|, and |strlen|.
  924.  
  925. @<Include...@>=
  926. #include <stdlib.h>
  927.  
  928. @** Index.
  929. @z
  930. ------------------------------------------------------------------------------
  931.