home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 2 / goldfish_vol2_cd1.bin / files / dev / c / cweb / wmerge.ch < prev    next >
Encoding:
Text File  |  1994-08-12  |  15.7 KB  |  495 lines

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