home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume7 / patch2 / patch10 / text0000.txt < prev   
Encoding:
Text File  |  1988-06-04  |  44.3 KB  |  1,632 lines

  1. System: patch version 2.0
  2. Patch #: 10
  3. Priority: MEDIUM
  4. Subject: new Configure for better portability
  5. Subject: installation script needs to remove old cat files on some systems
  6. Subject: systems without flexfilenames now use ~ or # as extension
  7. Subject: -B lets you specify a backup prefix instead of a suffix
  8. Subject: some machines don't like backslash-newline in double quotes
  9. Subject: a Prereq: wouldn't match first thing on a line
  10. Subject: an malloc() is now supplied
  11. Subject: exit code wasn't set properly
  12. Subject: signals could get permanently ignored
  13. Subject: the argument to -D is now checked for sanity
  14. Subject: fixed some typos in the manual page
  15. Subject: can now extract patches from shar files with leading X
  16. Subject: handles some gnu diff ideosyncracies
  17. Subject: double swap of first hunk could cause core dump
  18.  
  19. Description:
  20.     Subject: new Configure for better portability.
  21.  
  22.     Now based on the latest version of metaconfig, which knows everything
  23.     I know about Unix portability.
  24.  
  25.     Subject: installation script needs to remove old cat files on some
  26.     systems.
  27.  
  28.     Some systems have a stupid man command that doesn't compare dates
  29.     between the man version and the cat version, so the cat version
  30.     has to be removed at installation time.
  31.  
  32.     Subject: systems without flexfilenames now use ~ or # as extension.
  33.  
  34.     Systems that are restricted to 14 character filenames now will not
  35.     find files disappearing because they resolve to the same name.
  36.  
  37.     Subject: -B lets you specify a backup prefix instead of a suffix.
  38.  
  39.     This also helps the 14 character filename problem.  It also lets
  40.     you put backup files into a subdirectory.
  41.  
  42.     Subject: some machines don't like backslash-newline in double quotes.
  43.  
  44.     What can I say?
  45.  
  46.     Subject: a Prereq: wouldn't match first thing on a line.
  47.  
  48.     Now it does.
  49.  
  50.     Subject: an malloc() is now supplied.
  51.  
  52.     No particular reason, except that the new Configure made it easy.
  53.  
  54.     Subject: exit code wasn't set properly.
  55.  
  56.     Now you can use patch in a shell loop and stop if something goes
  57.     wrong.
  58.  
  59.     Subject: signals could get permanently ignored.
  60.  
  61.     It now remembers better what the original signals handlers were.
  62.  
  63.     Subject: the argument to -D is now checked for sanity.
  64.  
  65.     If you confused -d and -D, you could make your program unparseable
  66.     by the C preprocessor.
  67.  
  68.     Subject: can now extract patches from shar files with leading X.
  69.  
  70.     An X is treated like a space or tab on the front of a patch now.
  71.     There must be a consistent number of them for the duration of
  72.     the diff, however.
  73.  
  74.     Subject: handles some gnu diff ideosyncracies.
  75.  
  76.     Gnu diff says 0,0 instead of 0.
  77.  
  78.     Subject: double swap of first hunk could cause core dump.
  79.  
  80.     If an initial hunk didn't match, was swapped to try -R, then
  81.     swapped back and applied with a fuzz factor, there could be
  82.     a duplicate free().
  83.  
  84. Fix:    You need to both this patch and the next one.
  85.  
  86.     From rn, say "| patch -p -N -d DIR", where DIR is your patch source
  87.     directory.  Outside of rn, say "cd DIR; patch -p -N <thisarticle".
  88.     If you don't have the patch program, apply the following by hand,
  89.     or get patch (version 2.0, latest patchlevel).
  90.  
  91.     After applying:
  92.         DO NOT RECOMPILE
  93.         Apply patch 11, which is a shar, not a normal patch.
  94.  
  95.     If patch indicates that patchlevel is the wrong version, you may need
  96.     to apply one or more previous patches, or the patch may already
  97.     have been applied.  See the patchlevel.h file to find out what has or
  98.     has not been applied.  In any event, don't continue with the patch.
  99.  
  100.     If you are missing previous patches they can be obtained from me:
  101.  
  102.     Larry Wall
  103.     lwall@jpl-devvax.jpl.nasa.gov
  104.  
  105.     If you send a mail message of the following form it will greatly speed
  106.     processing:
  107.  
  108.     Subject: Command
  109.     @SH mailpatch PATH patch 2.0 LIST
  110.            ^ note the c
  111.  
  112.     where PATH is a return path FROM ME TO YOU in Internet notation, and
  113.     LIST is the number of one or more patches you need, separated by spaces,
  114.     commas, and/or hyphens.  Saying 35- says everything from 35 to the end.
  115.  
  116.     You can also get the patches via anonymous FTP from
  117.     jpl-devvax.jpl.nasa.gov (128.149.8.43).
  118.  
  119. Index: patchlevel.h
  120. Prereq: 9
  121. 1c1
  122. < #define PATCHLEVEL 9
  123. ---
  124. > #define PATCHLEVEL 10
  125.  
  126. Index: Makefile.SH
  127. Prereq: 2.0
  128. *** Makefile.SH.old    Fri Jun  3 15:26:55 1988
  129. --- Makefile.SH    Fri Jun  3 15:26:56 1988
  130. ***************
  131. *** 3,11 ****
  132.   esac
  133.   echo "Extracting Makefile (with variable substitutions)"
  134.   cat >Makefile <<!GROK!THIS!
  135. ! # $Header: Makefile.SH,v 2.0 86/09/17 15:36:15 lwall Exp $
  136.   #
  137.   # $Log:    Makefile.SH,v $
  138.   # Revision 2.0  86/09/17  15:36:15  lwall
  139.   # Baseline for netwide release.
  140.   # 
  141. --- 3,14 ----
  142.   esac
  143.   echo "Extracting Makefile (with variable substitutions)"
  144.   cat >Makefile <<!GROK!THIS!
  145. ! # $Header: Makefile.SH,v 2.0.1.1 88/06/03 15:00:48 lwall Locked $
  146.   #
  147.   # $Log:    Makefile.SH,v $
  148. + # Revision 2.0.1.1  88/06/03  15:00:48  lwall
  149. + # patch10: upgraded to match some new metaconfig stuff
  150. + # 
  151.   # Revision 2.0  86/09/17  15:36:15  lwall
  152.   # Baseline for netwide release.
  153.   # 
  154. ***************
  155. *** 20,27 ****
  156.   bin = $bin
  157.   mansrc = $mansrc
  158.   manext = $manext
  159. ! CFLAGS = $iandd -O
  160. ! LDFLAGS = $iandd
  161.   
  162.   !GROK!THIS!
  163.   cat >>Makefile <<'!NO!SUBS!'
  164. --- 23,32 ----
  165.   bin = $bin
  166.   mansrc = $mansrc
  167.   manext = $manext
  168. ! CFLAGS = $ccflags -O
  169. ! LDFLAGS = $ldflags
  170. ! SMALL = $small
  171. ! LARGE = $large $split
  172.   
  173.   !GROK!THIS!
  174.   cat >>Makefile <<'!NO!SUBS!'
  175. ***************
  176. *** 43,49 ****
  177.   SHELL = /bin/sh
  178.   
  179.   .c.o:
  180. !     $(CC) -c $(CFLAGS) $*.c
  181.   
  182.   all: $(public) $(private) $(util)
  183.       touch all
  184. --- 48,54 ----
  185.   SHELL = /bin/sh
  186.   
  187.   .c.o:
  188. !     $(CC) -c $(CFLAGS) $(LARGE) $*.c
  189.   
  190.   all: $(public) $(private) $(util)
  191.       touch all
  192. ***************
  193. *** 59,64 ****
  194. --- 64,70 ----
  195.       cd $(bin); chmod 755 $(public)
  196.       - if test `pwd` != $(mansrc); then \
  197.   for page in $(manpages); do \
  198. + rm -f $(mansrc)/../cat$(manext)/`basename $$page .man`.$(manext); \
  199.   cp $$page $(mansrc)/`basename $$page .man`.$(manext); \
  200.   done; \
  201.   fi
  202.  
  203. Index: common.h
  204. Prereq: 2.0
  205. *** common.h.old    Fri Jun  3 15:27:03 1988
  206. --- common.h    Fri Jun  3 15:27:04 1988
  207. ***************
  208. *** 1,6 ****
  209. ! /* $Header: common.h,v 2.0 86/09/17 15:36:39 lwall Exp $
  210.    *
  211.    * $Log:    common.h,v $
  212.    * Revision 2.0  86/09/17  15:36:39  lwall
  213.    * Baseline for netwide release.
  214.    * 
  215. --- 1,9 ----
  216. ! /* $Header: common.h,v 2.0.1.1 88/06/03 15:01:56 lwall Locked $
  217.    *
  218.    * $Log:    common.h,v $
  219. +  * Revision 2.0.1.1  88/06/03  15:01:56  lwall
  220. +  * patch10: support for shorter extensions.
  221. +  * 
  222.    * Revision 2.0  86/09/17  15:36:39  lwall
  223.    * Baseline for netwide release.
  224.    * 
  225. ***************
  226. *** 42,53 ****
  227.   #define INITHUNKMAX 125            /* initial dynamic allocation size */
  228.   #define MAXLINELEN 1024
  229.   #define BUFFERSIZE 1024
  230. - #define ORIGEXT ".orig"
  231.   #define SCCSPREFIX "s."
  232.   #define GET "get -e %s"
  233.   #define RCSSUFFIX ",v"
  234.   #define CHECKOUT "co -l %s"
  235.   
  236.   /* handy definitions */
  237.   
  238.   #define Null(t) ((t)0)
  239. --- 45,63 ----
  240.   #define INITHUNKMAX 125            /* initial dynamic allocation size */
  241.   #define MAXLINELEN 1024
  242.   #define BUFFERSIZE 1024
  243.   #define SCCSPREFIX "s."
  244.   #define GET "get -e %s"
  245.   #define RCSSUFFIX ",v"
  246.   #define CHECKOUT "co -l %s"
  247.   
  248. + #ifdef FLEXFILENAMES
  249. + #define ORIGEXT ".orig"
  250. + #define REJEXT ".rej"
  251. + #else
  252. + #define ORIGEXT "~"
  253. + #define REJEXT "#"
  254. + #endif
  255.   /* handy definitions */
  256.   
  257.   #define Null(t) ((t)0)
  258. ***************
  259. *** 95,100 ****
  260. --- 105,111 ----
  261.   EXT char rejname[128];
  262.   
  263.   EXT char *origext INIT(Nullch);
  264. + EXT char *origprae INIT(Nullch);
  265.   
  266.   EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
  267.   EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX");    /* might want /usr/tmp here */
  268. ***************
  269. *** 134,140 ****
  270.   char *realloc();
  271.   char *strcpy();
  272.   char *strcat();
  273. - char *sprintf();        /* usually */
  274.   long atol();
  275.   long lseek();
  276.   char *mktemp();
  277. --- 145,155 ----
  278.   char *realloc();
  279.   char *strcpy();
  280.   char *strcat();
  281.   long atol();
  282.   long lseek();
  283.   char *mktemp();
  284. + #ifdef CHARSPRINTF
  285. + char *sprintf();
  286. + #else
  287. + int *sprintf();
  288. + #endif
  289.  
  290. Index: config.h.SH
  291. *** config.h.SH.old    Fri Jun  3 15:27:12 1988
  292. --- config.h.SH    Fri Jun  3 15:27:14 1988
  293. ***************
  294. *** 0 ****
  295. --- 1,136 ----
  296. + case $CONFIG in
  297. + '')
  298. +     if test ! -f config.sh; then
  299. +     ln ../config.sh . || \
  300. +     ln ../../config.sh . || \
  301. +     ln ../../../config.sh . || \
  302. +     (echo "Can't find config.sh."; exit 1)
  303. +     echo "Using config.sh from above..."
  304. +     fi
  305. +     . ./config.sh
  306. +     ;;
  307. + esac
  308. + echo "Extracting config.h (with variable substitutions)"
  309. + cat <<!GROK!THIS! >config.h
  310. + /* config.h
  311. +  * This file was produced by running the config.h.SH script, which
  312. +  * gets its values from config.sh, which is generally produced by
  313. +  * running Configure.
  314. +  *
  315. +  * Feel free to modify any of this as the need arises.  Note, however,
  316. +  * that running config.h.SH again will wipe out any changes you've made.
  317. +  * For a more permanent change edit config.sh and rerun config.h.SH.
  318. +  */
  319. + /* EUNICE:
  320. +  *    This symbol, if defined, indicates that the program is being compiled
  321. +  *    under the EUNICE package under VMS.  The program will need to handle
  322. +  *    things like files that don't go away the first time you unlink them,
  323. +  *    due to version numbering.  It will also need to compensate for lack
  324. +  *    of a respectable link() command.
  325. +  */
  326. + /* VMS:
  327. +  *    This symbol, if defined, indicates that the program is running under
  328. +  *    VMS.  It is currently only set in conjunction with the EUNICE symbol.
  329. +  */
  330. + #$d_eunice    EUNICE        /**/
  331. + #$d_eunice    VMS        /**/
  332. + /* CPPSTDIN:
  333. +  *    This symbol contains the first part of the string which will invoke
  334. +  *    the C preprocessor on the standard input and produce to standard
  335. +  *    output.     Typical value of "cc -E" or "/lib/cpp".
  336. +  */
  337. + /* CPPMINUS:
  338. +  *    This symbol contains the second part of the string which will invoke
  339. +  *    the C preprocessor on the standard input and produce to standard
  340. +  *    output.  This symbol will have the value "-" if CPPSTDIN needs a minus
  341. +  *    to specify standard input, otherwise the value is "".
  342. +  */
  343. + #define CPPSTDIN "$cppstdin"
  344. + #define CPPMINUS "$cppminus"
  345. + /* CHARSPRINTF:
  346. +  *    This symbol is defined if this system declares "char *sprintf()" in
  347. +  *    stdio.h.  The trend seems to be to declare it as "int sprintf()".  It
  348. +  *    is up to the package author to declare sprintf correctly based on the
  349. +  *    symbol.
  350. +  */
  351. + #$d_charsprf    CHARSPRINTF     /**/
  352. + /* FLEXFILENAMES:
  353. +  *    This symbol, if defined, indicates that the system supports filenames
  354. +  *    longer than 14 characters.
  355. +  */
  356. + #$d_flexfnam    FLEXFILENAMES        /**/
  357. + /* index:
  358. +  *    This preprocessor symbol is defined, along with rindex, if the system
  359. +  *    uses the strchr and strrchr routines instead.
  360. +  */
  361. + /* rindex:
  362. +  *    This preprocessor symbol is defined, along with index, if the system
  363. +  *    uses the strchr and strrchr routines instead.
  364. +  */
  365. + #$d_index    index strchr    /* cultural */
  366. + #$d_index    rindex strrchr    /*  differences? */
  367. + /* VOIDSIG:
  368. +  *    This symbol is defined if this system declares "void (*signal())()" in
  369. +  *    signal.h.  The old way was to declare it as "int (*signal())()".  It
  370. +  *    is up to the package author to declare things correctly based on the
  371. +  *    symbol.
  372. +  */
  373. + #$d_voidsig    VOIDSIG     /**/
  374. + /* Reg1:
  375. +  *    This symbol, along with Reg2, Reg3, etc. is either the word "register"
  376. +  *    or null, depending on whether the C compiler pays attention to this
  377. +  *    many register declarations.  The intent is that you don't have to
  378. +  *    order your register declarations in the order of importance, so you
  379. +  *    can freely declare register variables in sub-blocks of code and as
  380. +  *    function parameters.  Do not use Reg<n> more than once per routine.
  381. +  */
  382. + #define Reg1 $reg1        /**/
  383. + #define Reg2 $reg2        /**/
  384. + #define Reg3 $reg3        /**/
  385. + #define Reg4 $reg4        /**/
  386. + #define Reg5 $reg5        /**/
  387. + #define Reg6 $reg6        /**/
  388. + #define Reg7 $reg7        /**/
  389. + #define Reg8 $reg8        /**/
  390. + #define Reg9 $reg9        /**/
  391. + #define Reg10 $reg10        /**/
  392. + #define Reg11 $reg11        /**/
  393. + #define Reg12 $reg12        /**/
  394. + #define Reg13 $reg13        /**/
  395. + #define Reg14 $reg14        /**/
  396. + #define Reg15 $reg15        /**/
  397. + #define Reg16 $reg16        /**/
  398. + /* VOIDFLAGS:
  399. +  *    This symbol indicates how much support of the void type is given by this
  400. +  *    compiler.  What various bits mean:
  401. +  *
  402. +  *        1 = supports declaration of void
  403. +  *        2 = supports arrays of pointers to functions returning void
  404. +  *        4 = supports comparisons between pointers to void functions and
  405. +  *            addresses of void functions
  406. +  *
  407. +  *    The package designer should define VOIDUSED to indicate the requirements
  408. +  *    of the package.  This can be done either by #defining VOIDUSED before
  409. +  *    including config.h, or by defining defvoidused in Myinit.U.  If the
  410. +  *    level of void support necessary is not present, defines void to int.
  411. +  */
  412. + #ifndef VOIDUSED
  413. + #define VOIDUSED $defvoidused
  414. + #endif
  415. + #define VOIDFLAGS $voidflags
  416. + #if (VOIDFLAGS & VOIDUSED) != VOIDUSED
  417. + #$define void int        /* is void to be avoided? */
  418. + #$define M_VOID        /* Xenix strikes again */
  419. + #endif
  420. + !GROK!THIS!
  421.  
  422. Index: inp.c
  423. Prereq: 2.0
  424. *** inp.c.old    Fri Jun  3 15:27:20 1988
  425. --- inp.c    Fri Jun  3 15:27:21 1988
  426. ***************
  427. *** 1,6 ****
  428. ! /* $Header: inp.c,v 2.0 86/09/17 15:37:02 lwall Exp $
  429.    *
  430.    * $Log:    inp.c,v $
  431.    * Revision 2.0  86/09/17  15:37:02  lwall
  432.    * Baseline for netwide release.
  433.    * 
  434. --- 1,9 ----
  435. ! /* $Header: inp.c,v 2.0.1.1 88/06/03 15:06:13 lwall Locked $
  436.    *
  437.    * $Log:    inp.c,v $
  438. +  * Revision 2.0.1.1  88/06/03  15:06:13  lwall
  439. +  * patch10: made a little smarter about sccs files
  440. +  * 
  441.    * Revision 2.0  86/09/17  15:37:02  lwall
  442.    * Baseline for netwide release.
  443.    * 
  444. ***************
  445. *** 94,102 ****
  446.           fatal2("Can't check out %s.\n", filename);
  447.       }
  448.       else {
  449. !         Sprintf(buf, "SCCS/%s%s", SCCSPREFIX, filename);
  450. !         if (stat(buf, &filestat) >= 0 || stat(buf+5, &filestat) >= 0) {
  451. !         Sprintf(buf, GET, filename);
  452.           if (verbose)
  453.               say2("Can't find %s--attempting to get it from SCCS.\n",
  454.               filename);
  455. --- 97,106 ----
  456.           fatal2("Can't check out %s.\n", filename);
  457.       }
  458.       else {
  459. !         Sprintf(buf+20, "SCCS/%s%s", SCCSPREFIX, filename);
  460. !         if (stat(s=buf+20, &filestat) >= 0 ||
  461. !           stat(s=buf+25, &filestat) >= 0) {
  462. !         Sprintf(buf, GET, s);
  463.           if (verbose)
  464.               say2("Can't find %s--attempting to get it from SCCS.\n",
  465.               filename);
  466. ***************
  467. *** 171,183 ****
  468.       if (!rev_in_string(i_womp)) {
  469.           if (force) {
  470.           if (verbose)
  471. !             say2("\
  472. ! Warning: this file doesn't appear to be the %s version--patching anyway.\n",
  473.               revision);
  474.           }
  475.           else {
  476. !         ask2("\
  477. ! This file doesn't appear to be the %s version--patch anyway? [n] ",
  478.               revision);
  479.           if (*buf != 'y')
  480.           fatal1("Aborted.\n");
  481. --- 175,187 ----
  482.       if (!rev_in_string(i_womp)) {
  483.           if (force) {
  484.           if (verbose)
  485. !             say2(
  486. ! "Warning: this file doesn't appear to be the %s version--patching anyway.\n",
  487.               revision);
  488.           }
  489.           else {
  490. !         ask2(
  491. ! "This file doesn't appear to be the %s version--patch anyway? [n] ",
  492.               revision);
  493.           if (*buf != 'y')
  494.           fatal1("Aborted.\n");
  495. ***************
  496. *** 216,228 ****
  497.       if (!found_revision) {
  498.           if (force) {
  499.           if (verbose)
  500. !             say2("\
  501. ! Warning: this file doesn't appear to be the %s version--patching anyway.\n",
  502.               revision);
  503.           }
  504.           else {
  505. !         ask2("\
  506. ! This file doesn't appear to be the %s version--patch anyway? [n] ",
  507.               revision);
  508.           if (*buf != 'y')
  509.               fatal1("Aborted.\n");
  510. --- 220,232 ----
  511.       if (!found_revision) {
  512.           if (force) {
  513.           if (verbose)
  514. !             say2(
  515. ! "Warning: this file doesn't appear to be the %s version--patching anyway.\n",
  516.               revision);
  517.           }
  518.           else {
  519. !         ask2(
  520. ! "This file doesn't appear to be the %s version--patch anyway? [n] ",
  521.               revision);
  522.           if (*buf != 'y')
  523.               fatal1("Aborted.\n");
  524. ***************
  525. *** 302,307 ****
  526. --- 306,313 ----
  527.       if (revision == Nullch)
  528.       return TRUE;
  529.       patlen = strlen(revision);
  530. +     if (strnEQ(string,revision,patlen) && isspace(s[patlen]))
  531. +     return TRUE;
  532.       for (s = string; *s; s++) {
  533.       if (isspace(*s) && strnEQ(s+1, revision, patlen) && 
  534.           isspace(s[patlen+1] )) {
  535.  
  536. Index: malloc.c
  537. *** malloc.c.old    Fri Jun  3 15:27:28 1988
  538. --- malloc.c    Fri Jun  3 15:27:30 1988
  539. ***************
  540. *** 0 ****
  541. --- 1,467 ----
  542. + /*
  543. +  * @(#)nmalloc.c 1 (Caltech) 2/21/82
  544. +  *
  545. +  *    U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs
  546. +  *
  547. +  *    Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD.
  548. +  *
  549. +  * This is a very fast storage allocator.  It allocates blocks of a small 
  550. +  * number of different sizes, and keeps free lists of each size.  Blocks
  551. +  * that don't exactly fit are passed up to the next larger size.  In this 
  552. +  * implementation, the available sizes are (2^n)-4 (or -16) bytes long.
  553. +  * This is designed for use in a program that uses vast quantities of
  554. +  * memory, but bombs when it runs out.  To make it a little better, it
  555. +  * warns the user when he starts to get near the end.
  556. +  *
  557. +  * June 84, ACT: modified rcheck code to check the range given to malloc,
  558. +  * rather than the range determined by the 2-power used.
  559. +  *
  560. +  * Jan 85, RMS: calls malloc_warning to issue warning on nearly full.
  561. +  * No longer Emacs-specific; can serve as all-purpose malloc for GNU.
  562. +  * You should call malloc_init to reinitialize after loading dumped Emacs.
  563. +  * Call malloc_stats to get info on memory stats if MSTATS turned on.
  564. +  * realloc knows how to return same block given, just changing its size,
  565. +  * if the power of 2 is correct.
  566. +  */
  567. + /*
  568. +  * nextf[i] is the pointer to the next free block of size 2^(i+3).  The
  569. +  * smallest allocatable block is 8 bytes.  The overhead information will
  570. +  * go in the first int of the block, and the returned pointer will point
  571. +  * to the second.
  572. +  *
  573. + #ifdef MSTATS
  574. +  * nmalloc[i] is the difference between the number of mallocs and frees
  575. +  * for a given block size.
  576. + #endif /* MSTATS */
  577. +  */
  578. + #define ISALLOC ((char) 0xf7)    /* magic byte that implies allocation */
  579. + #define ISFREE ((char) 0x54)    /* magic byte that implies free block */
  580. +                 /* this is for error checking only */
  581. + extern char etext;
  582. + /* end of the program; can be changed by calling init_malloc */
  583. + static char *endofpure = &etext;
  584. + #ifdef MSTATS
  585. + static int nmalloc[30];
  586. + static int nmal, nfre;
  587. + #endif /* MSTATS */
  588. + /* If range checking is not turned on, all we have is a flag indicating
  589. +    whether memory is allocated, an index in nextf[], and a size field; to
  590. +    realloc() memory we copy either size bytes or 1<<(index+3) bytes depending
  591. +    on whether the former can hold the exact size (given the value of
  592. +    'index').  If range checking is on, we always need to know how much space
  593. +    is allocated, so the 'size' field is never used. */
  594. + struct mhead {
  595. +     char     mh_alloc;    /* ISALLOC or ISFREE */
  596. +     char     mh_index;    /* index in nextf[] */
  597. + /* Remainder are valid only when block is allocated */
  598. +     unsigned short mh_size;    /* size, if < 0x10000 */
  599. + #ifdef rcheck
  600. +     unsigned mh_nbytes;    /* number of bytes allocated */
  601. +     int      mh_magic4;    /* should be == MAGIC4 */
  602. + #endif /* rcheck */
  603. +     };
  604. + /* Access free-list pointer of a block.
  605. +   It is stored at block + 4.
  606. +   This is not a field in the mhead structure
  607. +   because we want sizeof (struct mhead)
  608. +   to describe the overhead for when the block is in use,
  609. +   and we do not want the free-list pointer to count in that.  */
  610. + #define CHAIN(a) \
  611. +   (*(struct mhead **) (sizeof (char *) + (char *) (a)))
  612. + #ifdef rcheck
  613. + /* To implement range checking, we write magic values in at the beginning and
  614. +    end of each allocated block, and make sure they are undisturbed whenever a
  615. +    free or a realloc occurs. */
  616. + /* Written in each of the 4 bytes following the block's real space */
  617. + #define MAGIC1 0x55
  618. + /* Written in the 4 bytes before the block's real space */
  619. + #define MAGIC4 0x55555555
  620. + #define ASSERT(p) if (!(p)) botch("p"); else
  621. + static
  622. + botch(s)
  623. +     char *s;
  624. + {
  625. +     printf("assertion botched: %s\n", s);
  626. +     abort();
  627. + }
  628. + #define EXTRA  4        /* 4 bytes extra for MAGIC1s */
  629. + #else
  630. + #define ASSERT(p)
  631. + #define EXTRA  0
  632. + #endif /* rcheck */
  633. + /* nextf[i] is free list of blocks of size 2**(i + 3)  */
  634. + static struct mhead *nextf[30];
  635. + #ifdef    M_WARN
  636. + /* Number of bytes of writable memory we can expect to be able to get */
  637. + static int  lim_data;
  638. + /* Level number of warnings already issued.
  639. +   0 -- no warnings issued.
  640. +   1 -- 75% warning already issued.
  641. +   2 -- 85% warning already issued.
  642. + */
  643. + static int  warnlevel;
  644. + #endif /* M_WARN */
  645. + /* nonzero once initial bunch of free blocks made */
  646. + static int gotpool;
  647. + /* Cause reinitialization based on job parameters;
  648. +   also declare where the end of pure storage is. */
  649. + malloc_init (end)
  650. +     char *end; {
  651. +     endofpure = end;
  652. + #ifdef    M_WARN
  653. +     lim_data = 0;
  654. +     warnlevel = 0;
  655. + #endif /* M_WARN */
  656. +     }
  657. + static
  658. + morecore (nu)            /* ask system for more memory */
  659. +     register int nu; {        /* size index to get more of  */
  660. +     char   *sbrk ();
  661. +     register char  *cp;
  662. +     register int    nblks;
  663. +     register int    siz;
  664. + #ifdef    M_WARN
  665. + #ifndef BSD42
  666. + #ifdef USG
  667. +     extern long ulimit ();
  668. +     if (lim_data == 0)        /* find out how much we can get */
  669. +         lim_data = ulimit (3, 0) - TEXT_START;
  670. + #else    /*HMS: was endif */
  671. +     if (lim_data == 0)        /* find out how much we can get */
  672. +         lim_data = vlimit (LIM_DATA, -1);
  673. + #endif /* USG */    /HMS:* was not here */
  674. + #else
  675. +     if (lim_data == 0) {
  676. +         struct rlimit   XXrlimit;
  677. +         getrlimit (RLIMIT_DATA, &XXrlimit);
  678. +         lim_data = XXrlimit.rlim_cur;}    /* soft limit */
  679. + #endif /* BSD42 */
  680. + #endif /* M_WARN */
  681. +     /* On initial startup, get two blocks of each size up to 1k bytes */
  682. +     if (!gotpool)
  683. +         getpool (), getpool (), gotpool = 1;
  684. +     /* Find current end of memory and issue warning if getting near max */
  685. +     cp = sbrk (0);
  686. +     siz = cp - endofpure;
  687. + #ifdef    M_WARN
  688. +     switch (warnlevel) {
  689. +         case 0: 
  690. +         if (siz > (lim_data / 4) * 3) {
  691. +             warnlevel++;
  692. +             malloc_warning ("Warning: past 75% of memory limit");}
  693. +         break;
  694. +         case 1: 
  695. +         if (siz > (lim_data / 20) * 17) {
  696. +             warnlevel++;
  697. +             malloc_warning ("Warning: past 85% of memory limit");}
  698. +         break;
  699. +         case 2: 
  700. +         if (siz > (lim_data / 20) * 19) {
  701. +             warnlevel++;
  702. +             malloc_warning ("Warning: past 95% of memory limit");}
  703. +         break;}
  704. + #endif /* M_WARN */
  705. +     if ((int) cp & 0x3ff)    /* land on 1K boundaries */
  706. +         sbrk (1024 - ((int) cp & 0x3ff));
  707. +     /* Take at least 2k, and figure out how many blocks of the desired size we're about to get */
  708. +     nblks = 1;
  709. +     if ((siz = nu) < 8)
  710. +         nblks = 1 << ((siz = 8) - nu);
  711. +     if ((cp = sbrk (1 << (siz + 3))) == (char *) -1)
  712. +         return;            /* no more room! */
  713. +     if ((int) cp & 7) {        /* shouldn't happen, but just in case */
  714. +         cp = (char *) (((int) cp + 8) & ~7);
  715. +         nblks--;}
  716. +     /* save new header and link the nblks blocks together */
  717. +     nextf[nu] = (struct mhead *) cp;
  718. +     siz = 1 << (nu + 3);
  719. +     while (1) {
  720. +         ((struct mhead *) cp) -> mh_alloc = ISFREE;
  721. +         ((struct mhead *) cp) -> mh_index = nu;
  722. +         if (--nblks <= 0) break;
  723. +         CHAIN ((struct mhead *) cp) = (struct mhead *) (cp + siz);
  724. +         cp += siz;}
  725. + /*    CHAIN ((struct mhead *) cp) = 0;    /* since sbrk() returns cleared core, this is already set */
  726. +     }
  727. + static
  728. + getpool () {
  729. +     register int nu;
  730. +     register char *cp = sbrk (0);
  731. +     if ((int) cp & 0x3ff)    /* land on 1K boundaries */
  732. +         sbrk (1024 - ((int) cp & 0x3ff));
  733. +     /* Get 2k of storage */
  734. +     cp = sbrk (04000);
  735. +     if (cp == (char *) -1)
  736. +         return;
  737. +     /* Divide it into an initial 8-word block
  738. +     plus one block of size 2**nu for nu = 3 ... 10.  */
  739. +     CHAIN (cp) = nextf[0];
  740. +     nextf[0] = (struct mhead *) cp;
  741. +     ((struct mhead *) cp) -> mh_alloc = ISFREE;
  742. +     ((struct mhead *) cp) -> mh_index = 0;
  743. +     cp += 8;
  744. +     for (nu = 0; nu < 7; nu++) {
  745. +         CHAIN (cp) = nextf[nu];
  746. +         nextf[nu] = (struct mhead *) cp;
  747. +         ((struct mhead *) cp) -> mh_alloc = ISFREE;
  748. +         ((struct mhead *) cp) -> mh_index = nu;
  749. +         cp += 8 << nu;}}
  750. + char *
  751. + malloc (n)        /* get a block */
  752. +     unsigned n; {
  753. +     register struct  mhead *p;
  754. +     register unsigned int  nbytes;
  755. +     register int    nunits = 0;
  756. +     /* Figure out how many bytes are required, rounding up to the nearest
  757. +     multiple of 4, then figure out which nextf[] area to use */
  758. +     nbytes = (n + sizeof *p + EXTRA + 3) & ~3;
  759. +         {
  760. +         register unsigned int   shiftr = (nbytes - 1) >> 2;
  761. +         while (shiftr >>= 1)
  762. +             nunits++;
  763. +         }
  764. +     /* If there are no blocks of the appropriate size, go get some */
  765. +     /* COULD SPLIT UP A LARGER BLOCK HERE ... ACT */
  766. +     if (nextf[nunits] == 0)
  767. +         morecore (nunits);
  768. +     /* Get one block off the list, and set the new list head */
  769. +     if ((p = nextf[nunits]) == 0)
  770. +         return 0;
  771. +     nextf[nunits] = CHAIN (p);
  772. +     /* Check for free block clobbered */
  773. +     /* If not for this check, we would gobble a clobbered free chain ptr */
  774. +     /* and bomb out on the NEXT allocate of this size block */
  775. +     if (p -> mh_alloc != ISFREE || p -> mh_index != nunits)
  776. + #ifdef rcheck
  777. +         botch ("block on free list clobbered");
  778. + #else
  779. +         abort ();
  780. + #endif /* rcheck */
  781. +     /* Fill in the info, and if range checking, set up the magic numbers */
  782. +     p -> mh_alloc = ISALLOC;
  783. + #ifdef rcheck
  784. +     p -> mh_nbytes = n;
  785. +     p -> mh_magic4 = MAGIC4;
  786. +         {
  787. +         register char  *m = (char *) (p + 1) + n;
  788. +         *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1;
  789. +         }
  790. + #else
  791. +     p -> mh_size = n;
  792. + #endif /* rcheck */
  793. + #ifdef MSTATS
  794. +     nmalloc[nunits]++;
  795. +     nmal++;
  796. + #endif /* MSTATS */
  797. +     return (char *) (p + 1);}
  798. + free (mem)
  799. +     char *mem; {
  800. +     register struct mhead *p;
  801. +         {
  802. +         register char *ap = mem;
  803. +         ASSERT (ap != 0);
  804. +         p = (struct mhead *) ap - 1;
  805. +         ASSERT (p -> mh_alloc == ISALLOC);
  806. + #ifdef rcheck
  807. +         ASSERT (p -> mh_magic4 == MAGIC4);
  808. +         ap += p -> mh_nbytes;
  809. +         ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1);
  810. +         ASSERT (*ap++ == MAGIC1); ASSERT (*ap   == MAGIC1);
  811. + #endif /* rcheck */
  812. +         }
  813. +         {
  814. +         register int nunits = p -> mh_index;
  815. +         ASSERT (nunits <= 29);
  816. +         p -> mh_alloc = ISFREE;
  817. +         CHAIN (p) = nextf[nunits];
  818. +         nextf[nunits] = p;
  819. + #ifdef MSTATS
  820. +         nmalloc[nunits]--;
  821. +         nfre++;
  822. + #endif /* MSTATS */
  823. +         }
  824. +     }
  825. + char *
  826. + realloc (mem, n)
  827. +     char *mem;
  828. +     register unsigned n; {
  829. +     register struct mhead *p;
  830. +     register unsigned int tocopy;
  831. +     register int nbytes;
  832. +     register int nunits;
  833. +     if ((p = (struct mhead *) mem) == 0)
  834. +         return malloc (n);
  835. +     p--;
  836. +     nunits = p -> mh_index;
  837. +     ASSERT (p -> mh_alloc == ISALLOC);
  838. + #ifdef rcheck
  839. +     ASSERT (p -> mh_magic4 == MAGIC4);
  840. +         {
  841. +         register char *m = mem + (tocopy = p -> mh_nbytes);
  842. +         ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1);
  843. +         ASSERT (*m++ == MAGIC1); ASSERT (*m   == MAGIC1);
  844. +         }
  845. + #else
  846. +     if (p -> mh_index >= 13)
  847. +         tocopy = (1 << (p -> mh_index + 3)) - sizeof *p;
  848. +     else
  849. +         tocopy = p -> mh_size;
  850. + #endif /* rcheck */
  851. +     /* See if desired size rounds to same power of 2 as actual size. */
  852. +     nbytes = (n + sizeof *p + EXTRA + 7) & ~7;
  853. +     /* If ok, use the same block, just marking its size as changed.  */
  854. +     if (nbytes > (4 << nunits) && nbytes <= (8 << nunits)) {
  855. + #ifdef rcheck
  856. +         register char *m = mem + tocopy;
  857. +         *m++ = 0;  *m++ = 0;  *m++ = 0;  *m++ = 0;
  858. +         p-> mh_nbytes = n;
  859. +         m = mem + n;
  860. +         *m++ = MAGIC1;  *m++ = MAGIC1;  *m++ = MAGIC1;  *m++ = MAGIC1;
  861. + #else
  862. +         p -> mh_size = n;
  863. + #endif /* rcheck */
  864. +         return mem;}
  865. +     if (n < tocopy)
  866. +         tocopy = n;
  867. +         {
  868. +         register char *new;
  869. +         void bcopy();    /*HMS: here? */
  870. +         if ((new = malloc (n)) == 0)
  871. +             return 0;
  872. +         bcopy (mem, new, tocopy);
  873. +         free (mem);
  874. +         return new;
  875. +         }
  876. +     }
  877. + #ifdef MSTATS
  878. + /* Return statistics describing allocation of blocks of size 2**n. */
  879. + struct mstats_value {
  880. +     int blocksize;
  881. +     int nfree;
  882. +     int nused;
  883. +     };
  884. + struct mstats_value
  885. + malloc_stats (size)
  886. +     int size; {
  887. +     struct mstats_value v;
  888. +     register int i;
  889. +     register struct mhead *p;
  890. +     v.nfree = 0;
  891. +     if (size < 0 || size >= 30) {
  892. +         v.blocksize = 0;
  893. +         v.nused = 0;
  894. +         return v;}
  895. +     v.blocksize = 1 << (size + 3);
  896. +     v.nused = nmalloc[size];
  897. +     for (p = nextf[size]; p; p = CHAIN (p))
  898. +         v.nfree++;
  899. +     return v;}
  900. + #endif
  901. + /* how much space is available? */
  902. + unsigned freespace() {
  903. +       register int i, j;
  904. +       register struct mhead *p;
  905. +       register unsigned space = 0;
  906. +     int local;    /* address only is used */
  907. +     space = (char *)&local - sbrk(0);    /* stack space */
  908. +       for (i = 0; i < 30; i++) {
  909. +           for (j = 0, p = nextf[i]; p; p = CHAIN (p), j++) ;
  910. +           space += j * (1 << (i + 3));}
  911. +     return(space);}
  912. + /* How big is this cell? */
  913. + unsigned mc_size(cp)
  914. +     char *cp;{
  915. +     register struct mhead *p;
  916. +     if ((p = (struct mhead *) cp) == 0) {
  917. +         /*HMS? */
  918. +         }
  919. +     p--;
  920. + #ifdef rcheck
  921. +     return p -> mh_nbytes;
  922. + #else
  923. +     return (1 << (p -> mh_index + 3)) - sizeof *p;
  924. + /**/
  925. + /*    if (p -> mh_index >= 13)
  926. + /*        return (1 << (p -> mh_index + 3)) - sizeof *p;
  927. + /*    else
  928. + /*        return p -> mh_size;
  929. + /**/
  930. + #endif /* rcheck */
  931. +     }
  932. + /*HMS: Really should use memcpy, if available... */
  933. + void bcopy(source, dest, len)
  934. +     register char *source, *dest;
  935. +     register len; {
  936. +     register i;
  937. +     
  938. +     for (i = 0; i < len; i++)
  939. +         *dest++ = *source++;}
  940.  
  941. Index: patch.c
  942. Prereq: 2.0.1.4
  943. *** patch.c.old    Fri Jun  3 15:27:40 1988
  944. --- patch.c    Fri Jun  3 15:27:44 1988
  945. ***************
  946. *** 1,5 ****
  947.   char rcsid[] =
  948. !     "$Header: patch.c,v 2.0.1.4 87/02/16 14:00:04 lwall Exp $";
  949.   
  950.   /* patch - a program to apply diffs to original files
  951.    *
  952. --- 1,5 ----
  953.   char rcsid[] =
  954. !     "$Header: patch.c,v 2.0.1.5 88/06/03 15:09:37 lwall Locked $";
  955.   
  956.   /* patch - a program to apply diffs to original files
  957.    *
  958. ***************
  959. *** 9,14 ****
  960. --- 9,18 ----
  961.    * money off of it, or pretend that you wrote it.
  962.    *
  963.    * $Log:    patch.c,v $
  964. +  * Revision 2.0.1.5  88/06/03  15:09:37  lwall
  965. +  * patch10: exit code improved.
  966. +  * patch10: better support for non-flexfilenames.
  967. +  * 
  968.    * Revision 2.0.1.4  87/02/16  14:00:04  lwall
  969.    * Short replacement caused spurious "Out of sync" message.
  970.    * 
  971. ***************
  972. *** 117,122 ****
  973. --- 121,127 ----
  974.       LINENUM mymaxfuzz;
  975.       int hunk = 0;
  976.       int failed = 0;
  977. +     int failtotal = 0;
  978.       int i;
  979.   
  980.       setbuf(stderr, serrbuf);
  981. ***************
  982. *** 133,139 ****
  983.       get_some_switches();
  984.       
  985.       /* make sure we clean up /tmp in case of disaster */
  986. !     set_signals();
  987.   
  988.       for (
  989.       open_patch_file(filearg[1]);
  990. --- 138,144 ----
  991.       get_some_switches();
  992.       
  993.       /* make sure we clean up /tmp in case of disaster */
  994. !     set_signals(0);
  995.   
  996.       for (
  997.       open_patch_file(filearg[1]);
  998. ***************
  999. *** 181,188 ****
  1000.                           /* dwim for reversed patch? */
  1001.               if (!pch_swap()) {
  1002.                   if (fuzz == Nulline)
  1003. !                 say1("\
  1004. ! Not enough memory to try swapped hunk!  Assuming unswapped.\n");
  1005.                   continue;
  1006.               }
  1007.               reverse = !reverse;
  1008. --- 186,193 ----
  1009.                           /* dwim for reversed patch? */
  1010.               if (!pch_swap()) {
  1011.                   if (fuzz == Nulline)
  1012. !                 say1(
  1013. ! "Not enough memory to try swapped hunk!  Assuming unswapped.\n");
  1014.                   continue;
  1015.               }
  1016.               reverse = !reverse;
  1017. ***************
  1018. *** 196,208 ****
  1019.                   if (!pch_swap())         /* put it back to normal */
  1020.                   fatal1("Lost hunk on alloc error!\n");
  1021.                   reverse = !reverse;
  1022. !                 say1("\
  1023. ! Ignoring previously applied (or reversed) patch.\n");
  1024.                   skip_rest_of_patch = TRUE;
  1025.               }
  1026.               else {
  1027. !                 ask3("\
  1028. ! %seversed (or previously applied) patch detected!  %s -R? [y] ",
  1029.                   reverse ? "R" : "Unr",
  1030.                   reverse ? "Assume" : "Ignore");
  1031.                   if (*buf == 'n') {
  1032. --- 201,213 ----
  1033.                   if (!pch_swap())         /* put it back to normal */
  1034.                   fatal1("Lost hunk on alloc error!\n");
  1035.                   reverse = !reverse;
  1036. !                 say1(
  1037. ! "Ignoring previously applied (or reversed) patch.\n");
  1038.                   skip_rest_of_patch = TRUE;
  1039.               }
  1040.               else {
  1041. !                 ask3(
  1042. ! "%seversed (or previously applied) patch detected!  %s -R? [y] ",
  1043.                   reverse ? "R" : "Unr",
  1044.                   reverse ? "Assume" : "Ignore");
  1045.                   if (*buf == 'n') {
  1046. ***************
  1047. *** 278,286 ****
  1048.       Fclose(rejfp);
  1049.       rejfp = Nullfp;
  1050.       if (failed) {
  1051.           if (!*rejname) {
  1052.           Strcpy(rejname, outname);
  1053. !         Strcat(rejname, ".rej");
  1054.           }
  1055.           if (skip_rest_of_patch) {
  1056.           say4("%d out of %d hunks ignored--saving rejects to %s\n",
  1057. --- 283,304 ----
  1058.       Fclose(rejfp);
  1059.       rejfp = Nullfp;
  1060.       if (failed) {
  1061. +         failtotal += failed;
  1062.           if (!*rejname) {
  1063.           Strcpy(rejname, outname);
  1064. ! #ifndef FLEXFILENAMES
  1065. !         {
  1066. !             char *s = rindex(rejname,'/');
  1067. !             if (!s)
  1068. !             s = rejname;
  1069. !             if (strlen(s) > 13)
  1070. !             if (s[12] == '.')    /* try to preserve difference */
  1071. !                 s[12] = s[13];    /* between .h, .c, .y, etc. */
  1072. !             s[13] = '\0';
  1073. !         }
  1074. ! #endif
  1075. !         Strcat(rejname, REJEXT);
  1076.           }
  1077.           if (skip_rest_of_patch) {
  1078.           say4("%d out of %d hunks ignored--saving rejects to %s\n",
  1079. ***************
  1080. *** 293,301 ****
  1081.           if (move_file(TMPREJNAME, rejname) < 0)
  1082.           trejkeep = TRUE;
  1083.       }
  1084. !     set_signals();
  1085.       }
  1086. !     my_exit(0);
  1087.   }
  1088.   
  1089.   /* Prepare to find the next patch to do in the patch file. */
  1090. --- 311,319 ----
  1091.           if (move_file(TMPREJNAME, rejname) < 0)
  1092.           trejkeep = TRUE;
  1093.       }
  1094. !     set_signals(1);
  1095.       }
  1096. !     my_exit(failtotal);
  1097.   }
  1098.   
  1099.   /* Prepare to find the next patch to do in the patch file. */
  1100. ***************
  1101. *** 366,371 ****
  1102. --- 384,393 ----
  1103.           origext = savestr(Argv[1]);
  1104.           Argc--,Argv++;
  1105.           break;
  1106. +         case 'B':
  1107. +         origprae = savestr(Argv[1]);
  1108. +         Argc--,Argv++;
  1109. +         break;
  1110.           case 'c':
  1111.           diff_type = CONTEXT_DIFF;
  1112.           break;
  1113. ***************
  1114. *** 383,388 ****
  1115. --- 405,412 ----
  1116.               Argc--,Argv++;
  1117.               s = Argv[0];
  1118.           }
  1119. +         if (!isalpha(*s))
  1120. +             fatal1("Argument to -D not an identifier.\n");
  1121.           Sprintf(if_defined, "#ifdef %s\n", s);
  1122.           Sprintf(not_defined, "#ifndef %s\n", s);
  1123.           Sprintf(end_defined, "#endif /* %s */\n", s);
  1124.  
  1125. Index: patch.man
  1126. Prereq: 2.0
  1127. *** patch.man.old    Fri Jun  3 15:27:54 1988
  1128. --- patch.man    Fri Jun  3 15:27:55 1988
  1129. ***************
  1130. *** 1,6 ****
  1131. ! ''' $Header: patch.man,v 2.0 86/09/17 15:39:09 lwall Exp $
  1132.   ''' 
  1133.   ''' $Log:    patch.man,v $
  1134.   ''' Revision 2.0  86/09/17  15:39:09  lwall
  1135.   ''' Baseline for netwide release.
  1136.   ''' 
  1137. --- 1,10 ----
  1138. ! .rn '' }`
  1139. ! ''' $Header: patch.man,v 2.0.1.1 88/06/03 15:12:51 lwall Locked $
  1140.   ''' 
  1141.   ''' $Log:    patch.man,v $
  1142. + ''' Revision 2.0.1.1  88/06/03  15:12:51  lwall
  1143. + ''' patch10: -B switch was contributed.
  1144. + ''' 
  1145.   ''' Revision 2.0  86/09/17  15:39:09  lwall
  1146.   ''' Baseline for netwide release.
  1147.   ''' 
  1148. ***************
  1149. *** 80,86 ****
  1150.   version.
  1151.   By default, the patched version is put in place of the original, with
  1152.   the original file backed up to the same name with the
  1153. ! extension \*(L".orig\*(R", or as specified by the
  1154.   .B -b
  1155.   switch.
  1156.   You may also specify where you want the output to go with a
  1157. --- 84,90 ----
  1158.   version.
  1159.   By default, the patched version is put in place of the original, with
  1160.   the original file backed up to the same name with the
  1161. ! extension \*(L".orig\*(R" or \*(L"~\*(R" , or as specified by the
  1162.   .B -b
  1163.   switch.
  1164.   You may also specify where you want the output to go with a
  1165. ***************
  1166. *** 137,143 ****
  1167.   .I patch
  1168.   cannot find a place to install that hunk of the patch, it will put the
  1169.   hunk out to a reject file, which normally is the name of the output file
  1170. ! plus \*(L".rej\*(R".
  1171.   (Note that the rejected hunk will come out in context diff form whether the
  1172.   input patch was a context diff or a normal diff.
  1173.   If the input was a normal diff, many of the contexts will simply be null.)
  1174. --- 141,147 ----
  1175.   .I patch
  1176.   cannot find a place to install that hunk of the patch, it will put the
  1177.   hunk out to a reject file, which normally is the name of the output file
  1178. ! plus \*(L".rej\*(R" or \*(L"#\*(R" .
  1179.   (Note that the rejected hunk will come out in context diff form whether the
  1180.   input patch was a context diff or a normal diff.
  1181.   If the input was a normal diff, many of the contexts will simply be null.)
  1182. ***************
  1183. *** 211,218 ****
  1184.   .TP 5
  1185.   .B \-b
  1186.   causes the next argument to be interpreted as the backup extension, to be
  1187. ! used in place of \*(L".orig\*(R".
  1188.   .TP 5
  1189.   .B \-c
  1190.   forces
  1191.   .I patch
  1192. --- 215,228 ----
  1193.   .TP 5
  1194.   .B \-b
  1195.   causes the next argument to be interpreted as the backup extension, to be
  1196. ! used in place of \*(L".orig\*(R" or \*(L"~\*(R".
  1197.   .TP 5
  1198. + .B \-B
  1199. + causes the next argument to be interpreted as a prefix to the backup file
  1200. + name. If this argument is specified any argument from -b will be ignored.
  1201. + This argument is an extension to Larry Wall's patch v2.0.1.4, patchlevel 8,
  1202. + made by M. Greim (greim@sbsvax.uucp).
  1203. + .TP 5
  1204.   .B \-c
  1205.   forces
  1206.   .I patch
  1207. ***************
  1208. *** 250,256 ****
  1209.   .TP 5
  1210.   .B \-F<number>
  1211.   sets the maximum fuzz factor.
  1212. ! This switch only applied to context diffs, and causes
  1213.   .I patch
  1214.   to ignore up to that many lines in looking for places to install a hunk.
  1215.   Note that a larger fuzz factor increases the odds of a faulty patch.
  1216. --- 260,266 ----
  1217.   .TP 5
  1218.   .B \-F<number>
  1219.   sets the maximum fuzz factor.
  1220. ! This switch only applies to context diffs, and causes
  1221.   .I patch
  1222.   to ignore up to that many lines in looking for places to install a hunk.
  1223.   Note that a larger fuzz factor increases the odds of a faulty patch.
  1224. ***************
  1225. *** 285,291 ****
  1226.   which controls how pathnames found in the patch file are treated, in case
  1227.   the you keep your files in a different directory than the person who sent
  1228.   out the patch.
  1229. ! The strip count specifies how many backslashes are to be stripped from
  1230.   the front of the pathname.
  1231.   (Any intervening directory names also go away.)
  1232.   For example, supposing the filename in the patch file was
  1233. --- 295,301 ----
  1234.   which controls how pathnames found in the patch file are treated, in case
  1235.   the you keep your files in a different directory than the person who sent
  1236.   out the patch.
  1237. ! The strip count specifies how many slashes are to be stripped from
  1238.   the front of the pathname.
  1239.   (Any intervening directory names also go away.)
  1240.   For example, supposing the filename in the patch file was
  1241. ***************
  1242. *** 413,418 ****
  1243. --- 423,433 ----
  1244.   .I patch
  1245.   is attempting to intuit whether there is a patch in that text and, if so,
  1246.   what kind of patch it is.
  1247. + .PP
  1248. + .I Patch
  1249. + will exit with a non-zero status if any reject files were created.
  1250. + When applying a set of patches in a loop it behooves you to check this
  1251. + exit status so you don't apply a later patch to a partially patched file.
  1252.   .SH CAVEATS
  1253.   .I Patch
  1254.   cannot tell if the line numbers are off in an ed script, and can only detect
  1255. ***************
  1256. *** 444,446 ****
  1257. --- 459,462 ----
  1258.   .I patch
  1259.   will think it is a reversed patch, and offer to un-apply the patch.
  1260.   This could be construed as a feature.
  1261. + .rn }` ''
  1262.  
  1263. Index: pch.c
  1264. Prereq: 2.0.1.6
  1265. *** pch.c.old    Fri Jun  3 15:28:08 1988
  1266. --- pch.c    Fri Jun  3 15:28:12 1988
  1267. ***************
  1268. *** 1,6 ****
  1269. ! /* $Header: pch.c,v 2.0.1.6 87/06/04 16:18:13 lwall Exp $
  1270.    *
  1271.    * $Log:    pch.c,v $
  1272.    * Revision 2.0.1.6  87/06/04  16:18:13  lwall
  1273.    * pch_swap didn't swap p_bfake and p_efake.
  1274.    * 
  1275. --- 1,10 ----
  1276. ! /* $Header: pch.c,v 2.0.1.7 88/06/03 15:13:28 lwall Locked $
  1277.    *
  1278.    * $Log:    pch.c,v $
  1279. +  * Revision 2.0.1.7  88/06/03  15:13:28  lwall
  1280. +  * patch10: Can now find patches in shar scripts.
  1281. +  * patch10: Hunks that swapped and then swapped back could core dump.
  1282. +  * 
  1283.    * Revision 2.0.1.6  87/06/04  16:18:13  lwall
  1284.    * pch_swap didn't swap p_bfake and p_efake.
  1285.    * 
  1286. ***************
  1287. *** 243,249 ****
  1288.           goto scan_exit;
  1289.           }
  1290.       }
  1291. !     for (s = buf; *s == ' ' || *s == '\t'; s++) {
  1292.           if (*s == '\t')
  1293.           indent += 8 - (indent % 8);
  1294.           else
  1295. --- 247,253 ----
  1296.           goto scan_exit;
  1297.           }
  1298.       }
  1299. !     for (s = buf; *s == ' ' || *s == '\t' || *s == 'X'; s++) {
  1300.           if (*s == '\t')
  1301.           indent += 8 - (indent % 8);
  1302.           else
  1303. ***************
  1304. *** 466,472 ****
  1305. --- 470,480 ----
  1306.           p_end++;
  1307.           assert(p_end < hunkmax);
  1308.           p_char[p_end] = *buf;
  1309. + #ifdef zilog
  1310. +         p_line[(short)p_end] = Nullch;
  1311. + #else
  1312.           p_line[p_end] = Nullch;
  1313. + #endif
  1314.           switch (*buf) {
  1315.           case '*':
  1316.           if (strnEQ(buf, "********", 8)) {
  1317. ***************
  1318. *** 494,499 ****
  1319. --- 502,509 ----
  1320.           for (s=buf; *s && !isdigit(*s); s++) ;
  1321.           if (!*s)
  1322.               goto malformed;
  1323. +         if (strnEQ(s,"0,0",3))
  1324. +             strcpy(s,s+2);
  1325.           p_first = (LINENUM) atol(s);
  1326.           while (isdigit(*s)) s++;
  1327.           if (*s == ',') {
  1328. ***************
  1329. *** 586,591 ****
  1330. --- 596,603 ----
  1331.           case '+':  case '!':
  1332.           repl_could_be_missing = FALSE;
  1333.             change_line:
  1334. +         if (buf[1] == '\n' && canonicalize)
  1335. +             strcpy(buf+1," \n");
  1336.           if (!isspace(buf[1]) && buf[1] != '>' && buf[1] != '<' &&
  1337.             repl_beginning && repl_could_be_missing) {
  1338.               repl_missing = TRUE;
  1339. ***************
  1340. *** 674,682 ****
  1341.       if (diff_type == CONTEXT_DIFF &&
  1342.         (fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) {
  1343.           if (verbose)
  1344. !         say1("\
  1345. ! (Fascinating--this is really a new-style context diff but without the telltale\n\
  1346. ! extra asterisks on the *** line that usually indicate the new style...)\n");
  1347.           diff_type = NEW_CONTEXT_DIFF;
  1348.       }
  1349.       
  1350. --- 686,695 ----
  1351.       if (diff_type == CONTEXT_DIFF &&
  1352.         (fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) {
  1353.           if (verbose)
  1354. !         say4("%s\n%s\n%s\n",
  1355. ! "(Fascinating--this is really a new-style context diff but without",
  1356. ! "the telltale extra asterisks on the *** line that usually indicate",
  1357. ! "the new style...)");
  1358.           diff_type = NEW_CONTEXT_DIFF;
  1359.       }
  1360.       
  1361. ***************
  1362. *** 844,850 ****
  1363.       Reg2 int indent = 0;
  1364.   
  1365.       if (p_indent && ret != Nullch) {
  1366. !     for (s=buf; indent < p_indent && (*s == ' ' || *s == '\t'); s++) {
  1367.           if (*s == '\t')
  1368.           indent += 8 - (indent % 7);
  1369.           else
  1370. --- 857,864 ----
  1371.       Reg2 int indent = 0;
  1372.   
  1373.       if (p_indent && ret != Nullch) {
  1374. !     for (s=buf;
  1375. !       indent < p_indent && (*s == ' ' || *s == '\t' || *s == 'X'); s++) {
  1376.           if (*s == '\t')
  1377.           indent += 8 - (indent % 7);
  1378.           else
  1379. ***************
  1380. *** 905,913 ****
  1381.       i++;
  1382.       }
  1383.       if (p_efake >= 0) {            /* fix non-freeable ptr range */
  1384. !     n = p_end - i + 1;
  1385. !     if (p_efake > i)
  1386. !         n = -n;
  1387.       p_efake += n;
  1388.       p_bfake += n;
  1389.       }
  1390. --- 919,928 ----
  1391.       i++;
  1392.       }
  1393.       if (p_efake >= 0) {            /* fix non-freeable ptr range */
  1394. !     if (p_efake <= i)
  1395. !         n = p_end - i + 1;
  1396. !     else
  1397. !         n = -i;
  1398.       p_efake += n;
  1399.       p_bfake += n;
  1400.       }
  1401. ***************
  1402. *** 1104,1108 ****
  1403.       }
  1404.       else
  1405.       chmod(outname, filemode);
  1406. !     set_signals();
  1407.   }
  1408. --- 1119,1123 ----
  1409.       }
  1410.       else
  1411.       chmod(outname, filemode);
  1412. !     set_signals(1);
  1413.   }
  1414.  
  1415. Index: util.c
  1416. *** util.c.old    Fri Jun  3 15:28:23 1988
  1417. --- util.c    Fri Jun  3 15:28:24 1988
  1418. ***************
  1419. *** 31,38 ****
  1420.       return 0;
  1421.       }
  1422.   
  1423. !     Strcpy(bakname, to);
  1424. !     Strcat(bakname, origext?origext:ORIGEXT);
  1425.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  1426.       dev_t to_device = filestat.st_dev;
  1427.       ino_t to_inode  = filestat.st_ino;
  1428. --- 31,43 ----
  1429.       return 0;
  1430.       }
  1431.   
  1432. !     if (origprae) {
  1433. !         Strcpy (bakname, origprae);
  1434. !         Strcat(bakname, to);
  1435. !     } else {
  1436. !            Strcpy(bakname, to);
  1437. !         Strcat(bakname, origext?origext:ORIGEXT);
  1438. !     }
  1439.       if (stat(to, &filestat) >= 0) {    /* output file exists */
  1440.       dev_t to_device = filestat.st_dev;
  1441.       ino_t to_inode  = filestat.st_ino;
  1442. ***************
  1443. *** 155,161 ****
  1444.   void
  1445.   say(pat,arg1,arg2,arg3)
  1446.   char *pat;
  1447. ! int arg1,arg2,arg3;
  1448.   {
  1449.       fprintf(stderr, pat, arg1, arg2, arg3);
  1450.       Fflush(stderr);
  1451. --- 160,166 ----
  1452.   void
  1453.   say(pat,arg1,arg2,arg3)
  1454.   char *pat;
  1455. ! long arg1,arg2,arg3;
  1456.   {
  1457.       fprintf(stderr, pat, arg1, arg2, arg3);
  1458.       Fflush(stderr);
  1459. ***************
  1460. *** 166,172 ****
  1461.   void                /* very void */
  1462.   fatal(pat,arg1,arg2,arg3)
  1463.   char *pat;
  1464. ! int arg1,arg2,arg3;
  1465.   {
  1466.       void my_exit();
  1467.   
  1468. --- 171,177 ----
  1469.   void                /* very void */
  1470.   fatal(pat,arg1,arg2,arg3)
  1471.   char *pat;
  1472. ! long arg1,arg2,arg3;
  1473.   {
  1474.       void my_exit();
  1475.   
  1476. ***************
  1477. *** 179,185 ****
  1478.   void
  1479.   ask(pat,arg1,arg2,arg3)
  1480.   char *pat;
  1481. ! int arg1,arg2,arg3;
  1482.   {
  1483.       int ttyfd;
  1484.       int r;
  1485. --- 184,190 ----
  1486.   void
  1487.   ask(pat,arg1,arg2,arg3)
  1488.   char *pat;
  1489. ! long arg1,arg2,arg3;
  1490.   {
  1491.       int ttyfd;
  1492.       int r;
  1493. ***************
  1494. *** 218,237 ****
  1495.       if (!tty2)
  1496.       say1(buf);
  1497.   }
  1498. ! #endif lint
  1499.   
  1500.   /* How to handle certain events when not in a critical region. */
  1501.   
  1502.   void
  1503. ! set_signals()
  1504.   {
  1505.       void my_exit();
  1506.   #ifndef lint
  1507. !     if (signal(SIGHUP, SIG_IGN) != SIG_IGN)
  1508. !     Signal(SIGHUP, my_exit);
  1509. !     if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  1510. !     Signal(SIGINT, my_exit);
  1511.   #endif
  1512.   }
  1513.   
  1514. --- 223,254 ----
  1515.       if (!tty2)
  1516.       say1(buf);
  1517.   }
  1518. ! #endif /* lint */
  1519.   
  1520.   /* How to handle certain events when not in a critical region. */
  1521.   
  1522.   void
  1523. ! set_signals(reset)
  1524. ! int reset;
  1525.   {
  1526.       void my_exit();
  1527.   #ifndef lint
  1528. ! #ifdef VOIDSIG
  1529. !     static void (*hupval)(),(*intval)();
  1530. ! #else
  1531. !     static int (*hupval)(),(*intval)();
  1532. ! #endif
  1533. !     if (!reset) {
  1534. !     hupval = signal(SIGHUP, SIG_IGN);
  1535. !     if (hupval != SIG_IGN)
  1536. !         hupval = my_exit;
  1537. !     intval = signal(SIGINT, SIG_IGN);
  1538. !     if (intval != SIG_IGN)
  1539. !         intval = my_exit;
  1540. !     }
  1541. !     Signal(SIGHUP, hupval);
  1542. !     Signal(SIGINT, intval);
  1543.   #endif
  1544.   }
  1545.   
  1546.  
  1547.  
  1548.