home *** CD-ROM | disk | FTP | other *** search
/ Fresh Fish 2 / FFMCD02.bin / new / dev / misc / cweb / examples / wmerge-p.ch < prev    next >
Encoding:
Text File  |  1993-12-21  |  12.9 KB  |  396 lines

  1.                                 -*-Web-*-
  2. This file, WMERGE-P.CH, is part of CWEB-p.
  3. It is a changefile for WMERGE.W, 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. Caveat utilitor:  Some of the source code introduced by this change file is
  16. made conditional to the use of specific compilers on specific systems.
  17. This applies to places marked with `#ifdef __TURBOC__' and `#ifdef _AMIGA'.
  18.  
  19. This program is distributed WITHOUT ANY WARRANTY, express or implied.
  20.  
  21. The following copyright notice extends to this changefile only, not to
  22. the masterfile WMERGE.W.
  23.  
  24. Copyright (C) 1993 Andreas Scherer
  25. Copyright (C) 1991, 1992 Hans-Hermann Bode
  26.  
  27. Permission is granted to make and distribute verbatim copies of this
  28. document provided that the copyright notice and this permission notice
  29. are preserved on all copies.
  30.  
  31. Permission is granted to copy and distribute modified versions of this
  32. document under the conditions for verbatim copying, provided that the
  33. entire resulting derived work is distributed under the terms of a
  34. permission notice identical to this one.
  35.  
  36. Version history:
  37.  
  38. Version    Date        Author    Comment
  39. p2    13 Feb 1992    H2B    First hack.
  40. p3    16 Apr 1992    H2B    Change of |@@i| allowed, /dev/null in case
  41.                 replaced by nul.
  42. p4    21 Jun 1992    H2B    Nothing changed.
  43. p5    21 Jul 1992    H2B    Nothing changed.
  44. p5a    30 Jul 1992    KG    remove one #include <stdio.h>,
  45.                 use strchr instead of index and
  46.                 include <string.h> for |strchr| declaration
  47. p5b    06 Aug 1992    KG    fixed a typo
  48. p6    06 Sep 1992    H2B    Nothing changed.
  49. p6a     15 Mar 1993     AS      SAS/C 6.0 support
  50. p6b     28 Jul 1993     AS      make some functions return `void'
  51. p6c    04 Sep 1993    AS    path searching with CWEBINCLUDE
  52. p7    09 Oct 1993    AS    Updated to CWEB 2.8
  53. p8a    11 Mar 1993    H2B    Converted to master change file.
  54.                 [Not released.]
  55. p8b    15 Apr 1993    H2B    Updated for wmerge.w 3.0beta (?).
  56.                 [Not released.]
  57. p8c    22 Jun 1993    H2B    Updated for final wmerge.w 3.0 (?).
  58. p8d    26 Oct 1993    AS    Incorporated with Amiga version 2.8 [p7]
  59. ------------------------------------------------------------------------------
  60. @x l.14
  61. #include <stdio.h>
  62. @y
  63. #include <stdio.h>
  64. #include <string.h>
  65. @z
  66. ------------------------------------------------------------------------------
  67. @x l.45
  68. @<Predecl...@>=
  69. extern int strlen(); /* length of string */
  70. extern char* strcpy(); /* copy one string to another */
  71. extern int strncmp(); /* compare up to $n$ string characters */
  72. extern char* strncpy(); /* copy up to $n$ string characters */
  73. @y
  74. @z
  75. ------------------------------------------------------------------------------
  76. @x l.94
  77. input_ln(fp) /* copies a line into |buffer| or returns 0 */
  78. FILE *fp; /* what file to read from */
  79. @y
  80. int input_ln(FILE *fp) /* copies a line into |buffer| or returns 0 */
  81.   /* |fp|: what file to read from */
  82. @z
  83. ------------------------------------------------------------------------------
  84. AmigaDOS allows path names with up to 255 characters.
  85. @x l.127
  86. @d max_file_name_length 60
  87. @y
  88. @d max_file_name_length 256
  89. @z
  90. ------------------------------------------------------------------------------
  91. To avoid some nasty warnings by strict ANSI C compilers we redeclare all
  92. functions to `void' that return no concrete values.
  93. @x l.172
  94. void
  95. prime_the_change_buffer()
  96. @y
  97. void prime_the_change_buffer(void)
  98. @z
  99. ------------------------------------------------------------------------------
  100. Another `void' function, i.e., a procedure.
  101. @x l.231
  102. void
  103. check_change() /* switches to |change_file| if the buffers match */
  104. @y
  105. void check_change(void) /* switches to |change_file| if the buffers match */
  106. @z
  107. ------------------------------------------------------------------------------
  108. Another `void function, i.e., a procedure.
  109. @x l.283
  110. void
  111. reset_input()
  112. @y
  113. void reset_input(void)
  114. @z
  115. ------------------------------------------------------------------------------
  116. SAS/C defines `putchar' as a macro and reports a warning about multiple
  117. macro expansion.  The resulting `wmerge' is definitely wrong; it leaves
  118. every second letter out.
  119. @x l.345
  120. void put_line()
  121. {
  122.   char *ptr=buffer;
  123.   while (ptr<limit) putc(*ptr++,out_file);
  124.   putc('\n',out_file);
  125. }
  126. @y
  127. void put_line(void)
  128. {
  129.   char *ptr=buffer;
  130.   while (ptr<limit)
  131.   {
  132.     putc(*ptr,out_file);
  133.     *ptr++;
  134.   }
  135.   putc('\n',out_file);
  136. }
  137. @z
  138. ------------------------------------------------------------------------------
  139. @x l.352
  140. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  141. stop reading it and start reading from the named include file.  The
  142. \.{@@i} line should give a complete file name with or without
  143. double quotes.
  144. If the environment variable \.{CWEBINPUTS} is set, or if the compiler flag 
  145. of the same name was defined at compile time,
  146. \.{CWEB} will look for include files in the directory thus named, if
  147. it cannot find them in the current directory.
  148. (Colon-separated paths are not supported.)
  149. The remainder of the \.{@@i} line after the file name is ignored.
  150. @y
  151. @ When an \.{@@i} line is found in the |cur_file|, we must temporarily
  152. stop reading it and start reading from the named include file.  The
  153. \.{@@i} line should give a complete file name with or without
  154. double quotes.  The remainder of the \.{@@i} line after the file name
  155. is ignored.  \.{CWEB} will look for include files in standard directories
  156. specified in the environment variable \.{CWEBINPUTS}. Multiple search paths
  157. can be specified by delimiting them with \.{PATH\_SEPARATOR}s.  The given
  158. file is searched for in the current directory first.  You also may include
  159. device names; these must have a \.{DEVICE\_SEPARATOR} as their rightmost
  160. character.
  161.  
  162. @d PATH_SEPARATOR   ','
  163. @d DIR_SEPARATOR    '/'
  164. @d DEVICE_SEPARATOR ':'
  165. @z
  166. ------------------------------------------------------------------------------
  167. CWEB will perform a path search for `@i'nclude files along the environment
  168. variable CWEBINPUTS in case the given file can not be opened in the current
  169. directory or in the absolute path.  The single paths are delimited by
  170. PATH_SEPARATORs.
  171. @x l.380
  172.   kk=getenv("CWEBINPUTS");
  173.   if (kk!=NULL) {
  174.     if ((l=strlen(kk))>max_file_name_length-2) too_long();
  175.     strcpy(temp_file_name,kk);
  176.   }
  177.   else {
  178. #ifdef CWEBINPUTS
  179.     if ((l=strlen(CWEBINPUTS))>max_file_name_length-2) too_long();
  180.     strcpy(temp_file_name,CWEBINPUTS);
  181. #else
  182.     l=0; 
  183. #endif /* |CWEBINPUTS| */
  184.   }
  185.   if (l>0) {
  186.     if (k+l+2>=cur_file_name_end)  too_long();
  187. @.Include file name ...@>
  188.     for (; k>= cur_file_name; k--) *(k+l+1)=*k;
  189.     strcpy(cur_file_name,temp_file_name);
  190.     cur_file_name[l]='/'; /* \UNIX/ pathname separator */
  191.     if ((cur_file=fopen(cur_file_name,"r"))!=NULL) {
  192.       cur_line=0; 
  193.       goto restart; /* success */
  194.     }
  195.   }
  196. @y
  197.   if(0==set_path(include_path,getenv("CWEBINPUTS"))) {
  198.     include_depth--; goto restart; /* internal error */
  199.   }
  200.   path_prefix = include_path;
  201.   while(path_prefix) {
  202.     for(kk=temp_file_name, p=path_prefix, l=0;
  203.       p && *p && *p!=PATH_SEPARATOR;
  204.       *kk++ = *p++, l++);
  205.     if(path_prefix && *path_prefix && *path_prefix!=PATH_SEPARATOR &&
  206.       *--p!=DEVICE_SEPARATOR && *p!=DIR_SEPARATOR) {
  207.       *kk++ = DIR_SEPARATOR; l++;
  208.     }
  209.     if(k+l+2>=cur_file_name_end) too_long(); /* emergency break */
  210.     strcpy(kk,cur_file_name);
  211.     if(cur_file = fopen(temp_file_name,"r")) {
  212.       cur_line=0; goto restart; /* success */
  213.     }
  214.     if(next_path_prefix = strchr(path_prefix,PATH_SEPARATOR))
  215.       path_prefix = next_path_prefix+1;
  216.     else break; /* no more paths to search; no file found */
  217.   }
  218. @z
  219. ------------------------------------------------------------------------------
  220. Another `void' function, i.e., a procedure.
  221. @x l.450
  222. void
  223. check_complete(){
  224. @y
  225. void check_complete(void) {
  226. @z
  227. ------------------------------------------------------------------------------
  228. Another `void' function, i.e., a procedure.
  229. @x l.490
  230. @<Predecl...@>=
  231. void  err_print();
  232.  
  233. @
  234. @<Functions...@>=
  235. void
  236. err_print(s) /* prints `\..' and location of error message */
  237. char *s;
  238. @y
  239. @<Predecl...@>=
  240. void  err_print(char *);
  241.  
  242. @
  243. @<Functions...@>=
  244. void err_print(char *s) /* prints `\..' and location of error message */
  245. @z
  246. ------------------------------------------------------------------------------
  247. On the AMIGA it is very convenient to know a little bit more about the
  248. reasons why a program failed.  There are four levels of return for this
  249. purpose.  Let CWeb be so kind to use them, so scripts can be made better.
  250. @x l.540
  251. @ Some implementations may wish to pass the |history| value to the
  252. operating system so that it can be used to govern whether or not other
  253. programs are started. Here, for instance, we pass the operating system
  254. a status of 0 if and only if only harmless messages were printed.
  255. @^system dependencies@>
  256.  
  257. @<Func...@>=
  258. wrap_up() {
  259.   @<Print the job |history|@>;
  260.   if (history > harmless_message) return(1);
  261.   else return(0);
  262. }
  263. @y
  264. @ On multi-tasking systems like the Amiga it is very convenient to know
  265. a little bit more about the reasons why a program failed.  The four levels
  266. of return indicated by the |history| value are very suitable for this
  267. purpose.  Here, for instance, we pass the operating system a status of~0
  268. if and only if the run was a complete success.  Any warning or error
  269. message will result in a higher return value, so ARexx scripts can be
  270. made sensitive to these conditions.
  271. @^system dependencies@>
  272.  
  273. @d RETURN_OK     0 /* No problems, success */
  274. @d RETURN_WARN   5 /* A warning only */
  275. @d RETURN_ERROR 10 /* Something wrong */
  276. @d RETURN_FAIL  20 /* Complete or severe failure */
  277.  
  278. @<Func...@>=
  279. int wrap_up(void) {
  280.   @<Print the job |history|@>;
  281.   switch(history) {
  282.   case harmless_message: return(RETURN_WARN); break;
  283.   case error_message: return(RETURN_ERROR); break;
  284.   case fatal_message: return(RETURN_FAIL); break;
  285.   default: return(RETURN_OK);
  286.     }
  287. }
  288. @z
  289. ------------------------------------------------------------------------------
  290. @x l.569
  291. the names of those files. Most of the 128 flags are undefined but available
  292. @y
  293. the names of those files. Most of the 256 flags are undefined but available
  294. @z
  295. ------------------------------------------------------------------------------
  296. @x l.579
  297. boolean flags[128]; /* an option for each 7-bit code */
  298. @y
  299. boolean flags[256]; /* an option for each 8-bit code */
  300. @z
  301. ------------------------------------------------------------------------------
  302. @x l.593
  303. An omitted change file argument means that |'/dev/null'| should be used,
  304. @y
  305. An omitted change file argument means that |'/dev/null'| or---on {\mc
  306. MS-DOS} systems---|'nul'| or---on {\mc AMIGA} systems---|'NIL:'|
  307. should be used,
  308. @z
  309. ------------------------------------------------------------------------------
  310. Another `void' function, i.e., a procedure.
  311. @x l.599
  312. @<Pred...@>=
  313. void scan_args();
  314.  
  315. @
  316. @<Function...@>=
  317. void
  318. scan_args()
  319. @y
  320. @<Pred...@>=
  321. void scan_args(void);
  322.  
  323. @
  324. @<Function...@>=
  325. void scan_args(void)
  326. @z
  327. ------------------------------------------------------------------------------
  328. @x l.630
  329.   if (!found_change) strcpy(change_file_name,"/dev/null");
  330. @y
  331. #if defined( __TURBOC__ )
  332.   if (!found_change) strcpy(change_file_name,"nul");
  333. #elif defined( _AMIGA )
  334.   if (!found_change) strcpy(change_file_name,"NIL:");
  335. #else
  336.   if (!found_change) strcpy(change_file_name,"/dev/null");
  337. #endif
  338. @z
  339. ------------------------------------------------------------------------------
  340. @x l.612
  341. @* Index.
  342. @y
  343. @* Path searching.  On default, CTangle and CWeave are looking for include
  344. files along the path |CWEBINPUTS| given in this source file.  By setting
  345. the environment variable of the same name to a different search path that
  346. suits your personal needs, you may override the default on startup.  The
  347. following procdure copies the value of the environment variable (if any) to
  348. the variable |include_path| used for path searching.
  349.  
  350. @<Functions@>=
  351. static boolean set_path(char *ptr,char *override)
  352. {
  353.   if(override) {
  354.     if(strlen(override) >= MAXPATHLENGTH) {
  355.       err_print("! Include path too long"); return(0);
  356. @.Include path too long@>
  357.     }
  358.     else strcpy(ptr, override);
  359.   }
  360.   return(1);
  361. }
  362.  
  363. @ The path search algorithm defined in section |@<Try to open...@>|
  364. needs a few extra variables.  The search path given in the environment
  365. variable |CWEBINPUTS| must not be longer than |MAXPATHLENGTH|.  If no
  366. string is given in this variable, the internal default |CWEBINPUTS| is
  367. used instead, which holds some sensible paths.
  368.  
  369. @d MAXPATHLENGTH 4095
  370. @d CWEBINPUTS ",CWeb:,CWeb:include,CWeb:inputs"
  371.  
  372. @<Definitions...@>=
  373. char include_path[MAXPATHLENGTH+1]=CWEBINPUTS;@/
  374. char *p, *path_prefix, *next_path_prefix;@/
  375.  
  376. @ To satisfy all the {\mc ANSI} compilers out there, here are the
  377. prototypes of all internal functions.
  378.  
  379. @<Predecl...@>=
  380. int input_ln(FILE *fp);@/
  381. void prime_the_change_buffer(void);@/
  382. void check_change(void);@/
  383. void reset_input(void);@/
  384. int get_line(void);@/
  385. void put_line(void);@/
  386. void check_complete(void);@/
  387. void err_print(char *s);@/
  388. int wrap_up(void);@/
  389. void scan_args(void);@/
  390. static boolean set_path(char *ptr,char *override);@/
  391. int main(int argc,char **argv);
  392.  
  393. @* Index.
  394. @z
  395. ------------------------------------------------------------------------------
  396.