Path: tut!enea!mcvax!uunet!lll-winken!lll-lcc!ames!ll-xn!mit-eddie!bbn!rochester!udel!mmdf From: frank@morgan.com (Frank Wortner) Newsgroups: comp.os.minix Subject: Patch for Minix Upgrade Message-ID: <2848@louie.udel.EDU> Date: 2 Jun 88 20:42:50 GMT Sender: mmdf@udel.EDU Lines: 1638 Here is the upgrade to the latest version of patch. You will notice that the upgrade is in the form of a context diff, so here's your chance to use patch on itself! First, compile the old patch that I posted last week. Now, clip out the diff below and place it in a file. Patch.pch might be a good name. Now type: patch testcpp.out 2>&1 if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then --- 541,547 ---- else echo $n "Nope. I can't find a C preprocessor. Name one: $c" rp='Name a C preprocessor:' ! . myread cpp="$ans" $cpp testcpp.c >testcpp.out 2>&1 if $contains 'abc.xyz' testcpp.out >/dev/null 2>&1 ; then *************** *** 658,664 **** EOM $echo $n "each routine does your C compiler pay attention to? (OK to guess) [$dflt] $c" rp="# register declarations used? [$dflt]" ! read ans case "$ans" in '') ans=$dflt;; esac --- 661,667 ---- EOM $echo $n "each routine does your C compiler pay attention to? (OK to guess) [$dflt] $c" rp="# register declarations used? [$dflt]" ! . myread case "$ans" in '') ans=$dflt;; esac *************** *** 730,736 **** $echo " " rp="Where do you want to put the public executables? [$dflt]" $echo $n "$rp $c" ! read ans bin="$ans" bin=`filexp $bin` case "$bin" in --- 733,739 ---- $echo " " rp="Where do you want to put the public executables? [$dflt]" $echo $n "$rp $c" ! . myread bin="$ans" bin=`filexp $bin` case "$bin" in *************** *** 755,761 **** $echo " " rp="Where do the manual pages (source) go? [$dflt]" $echo $n "$rp $c" ! read ans mansrc=`filexp "$ans"` case "$mansrc" in '') mansrc=$dflt ;; --- 758,764 ---- $echo " " rp="Where do the manual pages (source) go? [$dflt]" $echo $n "$rp $c" ! . myread mansrc=`filexp "$ans"` case "$mansrc" in '') mansrc=$dflt ;; *************** *** 801,807 **** EOM $echo $n "this system? [$dflt] $c" rp="Command to resolve multiple refs? [$dflt]" ! read ans cc="$ans" case "$cc" in '') cc="$dflt" ;; --- 804,810 ---- EOM $echo $n "this system? [$dflt] $c" rp="Command to resolve multiple refs? [$dflt]" ! . myread cc="$ans" case "$cc" in '') cc="$dflt" ;; *************** *** 817,823 **** if $contains '\-i' $mansrc/cc.1 >/dev/null 2>&1 ; then rp="Your system appears to have separate I and D space. Is this true? [y]" $echo $n "$rp $c" ! read ans case "$ans" in n*|f*) iandd='' ;; *) iandd='-i' ;; --- 820,826 ---- if $contains '\-i' $mansrc/cc.1 >/dev/null 2>&1 ; then rp="Your system appears to have separate I and D space. Is this true? [y]" $echo $n "$rp $c" ! . myread case "$ans" in n*|f*) iandd='' ;; *) iandd='-i' ;; *************** *** 826,832 **** $echo "Your system appears to NOT have separate I and D space." $echo $n "Is this correct? [y] $c" rp='No separate I and D. Correct? [y]' ! read ans case "$ans" in n*|f*) iandd='-i' ;; *) iandd='' ;; --- 829,835 ---- $echo "Your system appears to NOT have separate I and D space." $echo $n "Is this correct? [y] $c" rp='No separate I and D. Correct? [y]' ! . myread case "$ans" in n*|f*) iandd='-i' ;; *) iandd='' ;; *************** *** 834,840 **** fi else $echo $n "Does your machine have separate I and D space? [n] $c" ! read ans case "$ans" in y*) iandd='-i' ;; *) iandd='' ;; --- 837,843 ---- fi else $echo $n "Does your machine have separate I and D space? [n] $c" ! . myread case "$ans" in y*) iandd='-i' ;; *) iandd='' ;; *************** *** 981,987 **** $echo 'You might prefer to run it in background: "make depend > makedepend.out &"' $echo $n "Would you like me to run it for you (it takes quite a while)? [n] $c" rp="Run make depend now? [n]" ! read ans case "$ans" in y*) make depend;; esac --- 984,990 ---- $echo 'You might prefer to run it in background: "make depend > makedepend.out &"' $echo $n "Would you like me to run it for you (it takes quite a while)? [n] $c" rp="Run make depend now? [n]" ! . myread case "$ans" in y*) make depend;; esac diff -c patch_4/EXTERN.h patch_9/EXTERN.h *** patch_4/EXTERN.h Wed Feb 3 15:40:04 1988 --- patch_9/EXTERN.h Wed Dec 30 10:59:42 1987 *************** *** 1,6 **** ! /* $Header: EXTERN.h,v 2.0 86/09/17 15:35:37 lwall Exp $ * * $Log: EXTERN.h,v $ * Revision 2.0 86/09/17 15:35:37 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/EXTERN.h,v 2.7 87/02/04 11:04:55 ksb Net $ * * $Log: EXTERN.h,v $ + * Revision 2.7 87/02/04 11:04:55 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:29:30 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:35:37 lwall * Baseline for netwide release. * diff -c patch_4/INTERN.h patch_9/INTERN.h *** patch_4/INTERN.h Wed Feb 3 15:40:04 1988 --- patch_9/INTERN.h Wed Dec 30 10:59:42 1987 *************** *** 1,6 **** ! /* $Header: INTERN.h,v 2.0 86/09/17 15:35:58 lwall Exp $ * * $Log: INTERN.h,v $ * Revision 2.0 86/09/17 15:35:58 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/INTERN.h,v 2.7 87/02/04 11:05:03 ksb Net $ * * $Log: INTERN.h,v $ + * Revision 2.7 87/02/04 11:05:03 ksb + * patched to r2.ision = 7 + * + * Revision 2.0 86/12/02 14:29:37 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:35:58 lwall * Baseline for netwide release. * diff -c patch_4/MANIFEST patch_9/MANIFEST *** patch_4/MANIFEST Fri May 27 10:02:08 1988 --- patch_9/MANIFEST Wed Dec 30 10:59:43 1987 *************** *** 1,22 **** ! Configure 1 ! EXTERN.h 1 ! INTERN.h 1 ! MANIFEST 3 ! Makefile 1 ! Makefile.SH 1 ! READ-ME-FIRST 1 ! README 1 ! common.h 1 ! config.h 1 ! inp.c 1 ! inp.h 1 ! patch.c 2 ! patch.doc 1 ! patch.man 2 ! patchlevel.h 2 ! pch.c 2 ! pch.h 2 ! util.c 3 ! util.h 2 ! version.c 3 ! version.h 3 --- 1,23 ---- ! After all the patch kits are run you should have the following files: ! ! Filename Kit Description ! -------- --- ----------- ! Configure 1 A shell script that installs everything system dependent. ! EXTERN.h 1 Toggle .h files to look foreign. ! INTERN.h 3 Toggle .h files to look domestic. ! MANIFEST 3 This list of files. ! Makefile.SH 3 The makefile. ! README 3 Installation instructions. ! common.h 3 Common definitions. ! config.H 3 Sample config.h, in case Configure won't run. ! inp.c 2 Input file abstract data type routines. ! inp.h 3 Public defs for above. ! patch.c 2 The patch program. ! patch.man 2 Manual page for patch. ! patchlevel.h 3 The patch level of the patch program. ! pch.c 1 Patch abstract data type routines. ! pch.h 3 Public defs for above. ! util.c 2 Utility routines. ! util.h 1 Public defs for above. ! version.c 3 Version number routine. ! version.h 3 Public defs for above. diff -c patch_4/Makefile.SH patch_9/Makefile.SH *** patch_4/Makefile.SH Wed Feb 3 15:40:05 1988 --- patch_9/Makefile.SH Wed Dec 30 11:08:03 1987 *************** *** 3,11 **** esac echo "Extracting Makefile (with variable substitutions)" cat >Makefile <Makefile <>Makefile <<'!NO!SUBS!' *************** *** 53,71 **** # won't work with csh install: patch ! export PATH || exit 1 ! - mv $(bin)/patch $(bin)/patch.old ! - if test `pwd` != $(bin); then cp $(public) $(bin); fi ! cd $(bin); chmod 755 $(public) ! - if test `pwd` != $(mansrc); then \ ! for page in $(manpages); do \ ! cp $$page $(mansrc)/`basename $$page .man`.$(manext); \ ! done; \ ! fi clean: rm -f *.o *.orig core realclean: rm -f patch *.o *.orig core $(addedbyconf) --- 65,87 ---- # won't work with csh install: patch ! install -c -m ${MODE} -o ${OWNER} -g ${GROUP} -s $(public) $(bin) ! # export PATH || exit 1 ! # - mv $(bin)/patch $(bin)/patch.old ! # - if test `pwd` != $(bin); then cp $(public) $(bin); fi ! # cd $(bin); chmod 755 $(public) ! # - if test `pwd` != $(mansrc); then \ ! #for page in $(manpages); do \ ! #cp $$page $(mansrc)/`basename $$page .man`.$(manext); \ ! #done; \ ! #fi clean: rm -f *.o *.orig core + depend: ${c} + maketd -a ${c} + realclean: rm -f patch *.o *.orig core $(addedbyconf) *************** *** 76,87 **** lint: lint $(lintflags) $(defs) $(c) > patch.fuzz - - patch.o: config.h common.h patch.c inp.h pch.h util.h version.h - pch.o: config.h common.h pch.c pch.h util.h - inp.o: config.h common.h inp.c inp.h util.h - util.o: config.h common.h util.c util.h - version.o: config.h common.h version.c version.h patchlevel.h util.h !NO!SUBS! $eunicefix Makefile --- 92,97 ---- diff -c patch_4/common.h patch_9/common.h *** patch_4/common.h Wed May 25 17:03:11 1988 --- patch_9/common.h Wed Dec 30 10:59:48 1987 *************** *** 1,6 **** ! /* $Header: common.h,v 2.0 86/09/17 15:36:39 lwall Exp $ * * $Log: common.h,v $ * Revision 2.0 86/09/17 15:36:39 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/common.h,v 2.7 87/02/04 11:05:17 ksb Net $ * * $Log: common.h,v $ + * Revision 2.7 87/02/04 11:05:17 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:30:11 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:36:39 lwall * Baseline for netwide release. * *************** *** 29,35 **** #include #include #include ! #include #include #include --- 35,41 ---- #include #include #include ! #include #include #include *************** *** 65,71 **** /* typedefs */ typedef char bool; ! typedef int LINENUM; /* must be signed */ typedef unsigned MEM; /* what to feed malloc */ /* globals */ --- 71,77 ---- /* typedefs */ typedef char bool; ! typedef long LINENUM; /* must be signed */ typedef unsigned MEM; /* what to feed malloc */ /* globals */ diff -c patch_4/config.H patch_9/config.H *** patch_4/config.H Tue May 31 17:45:17 1988 --- patch_9/config.H Wed Dec 30 10:59:49 1987 *************** *** 0 **** --- 1,33 ---- + /* config.h + * This file was produced by running the Configure script. + * Feel free to modify any of this as the need arises. + */ + + + #/*undef EUNICE /* no file linking? */ + #/*undef VMS + + #/*undef index strchr /* cultural */ + #/*undef rindex strrchr /* differences? */ + + #/*undef void int /* is void to be avoided? */ + + /* How many register declarations are paid attention to? */ + + #define Reg1 register + #define Reg2 register + #define Reg3 register + #define Reg4 register + #define Reg5 register + #define Reg6 register + #define Reg7 + #define Reg8 + #define Reg9 + #define Reg10 + #define Reg11 + #define Reg12 + #define Reg13 + #define Reg14 + #define Reg15 + #define Reg16 + diff -c patch_4/config.h patch_9/config.h *** patch_4/config.h Wed Feb 3 16:50:42 1988 --- patch_9/config.h Tue May 31 12:59:06 1988 *************** *** 3,16 **** * Feel free to modify any of this as the need arises. */ - /*undef EUNICE /* no file linking? */ - /*undef VMS /* other assorted ickies? */ ! /*undef index strchr /* cultural */ ! /*undef rindex strrchr /* differences? */ ! /*undef void int /* is void to be avoided? */ /* How many register declarations are paid attention to? */ #define Reg1 register /**/ --- 3,17 ---- * Feel free to modify any of this as the need arises. */ ! #/*undef EUNICE /* no file linking? */ ! #/*undef VMS /* other assorted ickies? */ ! #/*undef index strchr /* cultural */ ! #/*undef rindex strrchr /* differences? */ + #/*undef void int /* is void to be avoided? */ + /* How many register declarations are paid attention to? */ #define Reg1 register /**/ *************** *** 19,32 **** #define Reg4 register /**/ #define Reg5 register /**/ #define Reg6 register /**/ ! #define Reg7 register /**/ ! #define Reg8 register /**/ ! #define Reg9 register /**/ ! #define Reg10 register /**/ ! #define Reg11 register /**/ ! #define Reg12 register /**/ ! #define Reg13 register /**/ ! #define Reg14 register /**/ ! #define Reg15 register /**/ ! #define Reg16 register /**/ --- 20,33 ---- #define Reg4 register /**/ #define Reg5 register /**/ #define Reg6 register /**/ ! #define Reg7 /**/ ! #define Reg8 /**/ ! #define Reg9 /**/ ! #define Reg10 /**/ ! #define Reg11 /**/ ! #define Reg12 /**/ ! #define Reg13 /**/ ! #define Reg14 /**/ ! #define Reg15 /**/ ! #define Reg16 /**/ Only in patch_9: config.sh Only in patch_9: filexp diff -c patch_4/global.h patch_9/global.h *** patch_4/global.h Tue May 31 13:17:04 1988 --- patch_9/global.h Wed Dec 30 10:59:50 1987 *************** *** 0 **** --- 1,3 ---- + #define check_after Acheck_after + #define this_line_is_command Athis_line_is_command + #define first_guess Afirst_guess diff -c patch_4/inp.c patch_9/inp.c *** patch_4/inp.c Wed Feb 3 15:40:08 1988 --- patch_9/inp.c Wed Dec 30 10:59:53 1987 *************** *** 1,6 **** ! /* $Header: inp.c,v 2.0 86/09/17 15:37:02 lwall Exp $ * * $Log: inp.c,v $ * Revision 2.0 86/09/17 15:37:02 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/inp.c,v 2.7 87/02/04 11:05:34 ksb Net $ * * $Log: inp.c,v $ + * Revision 2.7 87/02/04 11:05:34 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:30:25 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:37:02 lwall * Baseline for netwide release. * diff -c patch_4/inp.h patch_9/inp.h *** patch_4/inp.h Wed Feb 3 15:40:08 1988 --- patch_9/inp.h Wed Dec 30 10:59:53 1987 *************** *** 1,6 **** ! /* $Header: inp.h,v 2.0 86/09/17 15:37:25 lwall Exp $ * * $Log: inp.h,v $ * Revision 2.0 86/09/17 15:37:25 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/inp.h,v 2.7 87/02/04 11:05:41 ksb Net $ * * $Log: inp.h,v $ + * Revision 2.7 87/02/04 11:05:41 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:30:33 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:37:25 lwall * Baseline for netwide release. * diff -c patch_4/patch.c patch_9/patch.c *** patch_4/patch.c Mon Feb 15 17:08:16 1988 --- patch_9/patch.c Wed Dec 30 11:00:00 1987 *************** *** 1,5 **** char rcsid[] = ! "$Header: patch.c,v 2.0.1.1 86/10/29 13:10:22 lwall Exp $"; /* patch - a program to apply diffs to original files * --- 1,5 ---- char rcsid[] = ! "$Header: /usr/src/unsup/bin/patch/RCS/patch.c,v 2.8 87/02/17 13:57:47 doc Exp $"; /* patch - a program to apply diffs to original files * *************** *** 9,14 **** --- 9,29 ---- * money off of it, or pretend that you wrote it. * * $Log: patch.c,v $ + * Revision 2.8 87/02/17 13:57:47 doc + * Applied patch #8 from net. + * + * Revision 2.7 87/02/04 11:05:43 ksb + * patched to revision 2.7 + * + * Revision 2.2 86/12/02 15:11:09 doc + * Patch 5 applied. + * + * Revision 2.0.1.4 87/02/16 14:00:04 lwall + * Short replacement caused spurious "Out of sync" message. + * + * Revision 2.0.1.2 86/11/21 09:39:15 lwall + * Fuzz factor caused offset of installed lines. + * * Revision 2.0.1.1 86/10/29 13:10:22 lwall * Backwards search could terminate prematurely. * *************** *** 85,91 **** LINENUM locate_hunk(); void abort_hunk(); void apply_hunk(); - void do_ed_script(); void init_output(); void init_reject(); void copy_till(); --- 100,105 ---- *************** *** 542,547 **** --- 556,562 ---- #define IN_ELSE 3 Reg4 int def_state = OUTSIDE; Reg5 bool R_do_defines = do_defines; + Reg6 LINENUM pat_end = pch_end(); where--; while (pch_char(new) == '=' || pch_char(new) == '\n') *************** *** 564,569 **** --- 579,586 ---- last_frozen_line++; old++; } + else if (new > pat_end) + break; else if (pch_char(new) == '+') { copy_till(where + old - 1); if (R_do_defines) { *************** *** 581,589 **** } else { if (pch_char(new) != pch_char(old)) { ! say3("Out-of-sync patch, lines %ld,%ld\n", ! pch_hunk_beg() + old - 1, ! pch_hunk_beg() + new - 1); #ifdef DEBUGGING say3("oldchar = '%c', newchar = '%c'\n", pch_char(old), pch_char(new)); --- 598,606 ---- } else { if (pch_char(new) != pch_char(old)) { ! say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n", ! pch_hunk_beg() + old, ! pch_hunk_beg() + new); #ifdef DEBUGGING say3("oldchar = '%c', newchar = '%c'\n", pch_char(old), pch_char(new)); *************** *** 623,629 **** } } } ! if (new <= pch_end() && pch_char(new) == '+') { copy_till(where + old - 1); if (R_do_defines) { if (def_state == OUTSIDE) { --- 640,646 ---- } } } ! if (new <= pat_end && pch_char(new) == '+') { copy_till(where + old - 1); if (R_do_defines) { if (def_state == OUTSIDE) { *************** *** 635,641 **** def_state = IN_ELSE; } } ! while (new <= pch_end() && pch_char(new) == '+') { fputs(pfetch(new), ofp); new++; } --- 652,658 ---- def_state = IN_ELSE; } } ! while (new <= pat_end && pch_char(new) == '+') { fputs(pfetch(new), ofp); new++; } *************** *** 645,712 **** } } - /* Apply an ed script by feeding ed itself. */ - - void - do_ed_script() - { - Reg1 char *t; - Reg2 long beginning_of_this_line; - Reg3 bool this_line_is_command = FALSE; - Reg4 FILE *pipefp; - FILE *popen(); - - if (!skip_rest_of_patch) { - Unlink(TMPOUTNAME); - copy_file(filearg[0], TMPOUTNAME); - if (verbose) - Sprintf(buf, "/usr/bin/ed %s", TMPOUTNAME); - else - Sprintf(buf, "/usr/bin/ed - %s", TMPOUTNAME); - pipefp = popen(buf, "w"); - } - for (;;) { - beginning_of_this_line = ftell(pfp); - if (pgets(buf, sizeof buf, pfp) == Nullch) { - next_intuit_at(beginning_of_this_line); - break; - } - for (t=buf; isdigit(*t) || *t == ','; t++) ; - this_line_is_command = (isdigit(*buf) && - (*t == 'd' || *t == 'c' || *t == 'a') ); - if (this_line_is_command) { - if (!skip_rest_of_patch) - fputs(buf, pipefp); - if (*t != 'd') { - while (pgets(buf, sizeof buf, pfp) != Nullch) { - if (!skip_rest_of_patch) - fputs(buf, pipefp); - if (strEQ(buf, ".\n")) - break; - } - } - } - else { - next_intuit_at(beginning_of_this_line); - break; - } - } - if (skip_rest_of_patch) - return; - fprintf(pipefp, "w\n"); - fprintf(pipefp, "q\n"); - Fflush(pipefp); - Pclose(pipefp); - ignore_signals(); - if (move_file(TMPOUTNAME, outname) < 0) { - toutkeep = TRUE; - chmod(TMPOUTNAME, filemode); - } - else - chmod(outname, filemode); - set_signals(); - } - /* Open the new file. */ void --- 662,667 ---- *************** *** 785,791 **** Reg2 LINENUM iline; Reg3 LINENUM pat_lines = pch_ptrn_lines() - fuzz; ! for (iline=base+offset; pline <= pat_lines; pline++,iline++) { if (canonicalize) { if (!similar(ifetch(iline, (offset >= 0)), pfetch(pline), --- 740,746 ---- Reg2 LINENUM iline; Reg3 LINENUM pat_lines = pch_ptrn_lines() - fuzz; ! for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) { if (canonicalize) { if (!similar(ifetch(iline, (offset >= 0)), pfetch(pline), diff -c patch_4/patch.man patch_9/patch.man *** patch_4/patch.man Wed Feb 3 15:40:12 1988 --- patch_9/patch.man Wed Dec 30 11:00:05 1987 *************** *** 1,6 **** ! ''' $Header: patch.man,v 2.0 86/09/17 15:39:09 lwall Exp $ ''' ''' $Log: patch.man,v $ ''' Revision 2.0 86/09/17 15:39:09 lwall ''' Baseline for netwide release. ''' --- 1,9 ---- ! ''' $Header: /usr/src/unsup/bin/patch/RCS/patch.man,v 2.0 86/12/02 14:30:39 doc Exp $ ''' ''' $Log: patch.man,v $ + Revision 2.0 86/12/02 14:30:39 doc + Initial Distributed Revision + ''' Revision 2.0 86/09/17 15:39:09 lwall ''' Baseline for netwide release. ''' diff -c patch_4/patchlevel.h patch_9/patchlevel.h *** patch_4/patchlevel.h Wed Feb 3 15:40:12 1988 --- patch_9/patchlevel.h Wed Dec 30 11:00:06 1987 *************** *** 1 **** ! #define PATCHLEVEL 4 --- 1 ---- ! #define PATCHLEVEL 9 diff -c patch_4/pch.c patch_9/pch.c *** patch_4/pch.c Wed Feb 3 15:40:15 1988 --- patch_9/pch.c Wed Dec 30 11:00:20 1987 *************** *** 1,6 **** ! /* $Header: pch.c,v 2.0.1.3 86/11/14 10:08:33 lwall Exp $ * * $Log: pch.c,v $ * Revision 2.0.1.3 86/11/14 10:08:33 lwall * Fixed problem where a long pattern wouldn't grow the hunk. * Also restored p_input_line when backtracking so error messages are right. --- 1,21 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/pch.c,v 2.8 87/06/05 20:21:47 doc Exp $ * * $Log: pch.c,v $ + * Revision 2.8 87/06/05 20:21:47 doc + * Added patch # 9 + * + * Revision 2.7 87/02/04 11:06:02 ksb + * patched to revision 2.7 + * + * Revision 2.4 87/01/06 21:35:06 doc + * Patch #6 from net + * + * Revision 2.3 86/12/02 15:09:45 doc + * Patch 4 applied. + * + * Revision 2.0.1.4 87/01/05 16:59:53 lwall + * New-style context diffs caused double call to free(). + * * Revision 2.0.1.3 86/11/14 10:08:33 lwall * Fixed problem where a long pattern wouldn't grow the hunk. * Also restored p_input_line when backtracking so error messages are right. *************** *** 39,45 **** --- 54,65 ---- static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ static int p_indent; /* indent to patch */ static LINENUM p_base; /* where to intuit this time */ + static LINENUM p_bline; /* line # of p_base */ static LINENUM p_start; /* where intuit found a patch */ + static LINENUM p_sline; /* and the line number for it */ + static LINENUM p_hunk_beg; /* line number of current hunk */ + static LINENUM p_efake = -1; /* end of faked up lines--don't free */ + static LINENUM p_bfake = -1; /* beg of faked up lines */ /* Prepare to look for the next patch in the patch file. */ *************** *** 75,81 **** fatal2("patch file %s not found\n", filename); Fstat(fileno(pfp), &filestat); p_filesize = filestat.st_size; ! next_intuit_at(0L); /* start at the beginning */ set_hunkmax(); } --- 95,101 ---- fatal2("patch file %s not found\n", filename); Fstat(fileno(pfp), &filestat); p_filesize = filestat.st_size; ! next_intuit_at(0L,1L); /* start at the beginning */ set_hunkmax(); } *************** *** 150,156 **** "an ed script" ); if (p_indent && verbose) say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s"); ! skip_to(p_start); while (filearg[0] == Nullch) { if (force) { say1("No file to patch. Skipping...\n"); --- 170,176 ---- "an ed script" ); if (p_indent && verbose) say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s"); ! skip_to(p_start,p_sline); while (filearg[0] == Nullch) { if (force) { say1("No file to patch. Skipping...\n"); *************** *** 187,192 **** --- 207,213 ---- Reg4 long this_line = 0; Reg5 long previous_line; Reg6 long first_command_line = -1; + long fcl_line; Reg7 bool last_line_was_command = FALSE; Reg8 bool this_is_a_command = FALSE; Reg9 bool stars_last_line = FALSE; *************** *** 205,210 **** --- 226,232 ---- ok_to_create_file = FALSE; Fseek(pfp, p_base, 0); + p_input_line = p_bline - 1; for (;;) { previous_line = this_line; last_line_was_command = this_is_a_command; *************** *** 211,225 **** --- 233,250 ---- stars_last_line = stars_this_line; this_line = ftell(pfp); indent = 0; + p_input_line++; if (fgets(buf, sizeof buf, pfp) == Nullch) { if (first_command_line >= 0L) { /* nothing but deletes!? */ p_start = first_command_line; + p_sline = fcl_line; retval = ED_DIFF; goto scan_exit; } else { p_start = this_line; + p_sline = p_input_line; retval = 0; goto scan_exit; } *************** *** 235,240 **** --- 260,266 ---- (*t == 'd' || *t == 'c' || *t == 'a') ); if (first_command_line < 0L && this_is_a_command) { first_command_line = this_line; + fcl_line = p_input_line; p_indent = indent; /* assume this for now */ } if (!stars_last_line && strnEQ(s, "*** ", 4)) *************** *** 258,263 **** --- 284,290 ---- strEQ(s, ".\n") ) { p_indent = indent; p_start = first_command_line; + p_sline = fcl_line; retval = ED_DIFF; goto scan_exit; } *************** *** 272,277 **** --- 299,305 ---- s++; p_indent = indent; p_start = previous_line; + p_sline = p_input_line - 1; retval = (*(s-1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF); goto scan_exit; } *************** *** 279,284 **** --- 307,313 ---- last_line_was_command && (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) { p_start = previous_line; + p_sline = p_input_line - 1; p_indent = indent; retval = NORMAL_DIFF; goto scan_exit; *************** *** 347,363 **** /* Remember where this patch ends so we know where to start up again. */ void ! next_intuit_at(file_pos) long file_pos; { p_base = file_pos; } /* Basically a verbose fseek() to the actual diff listing. */ void ! skip_to(file_pos) long file_pos; { char *ret; --- 376,395 ---- /* Remember where this patch ends so we know where to start up again. */ void ! next_intuit_at(file_pos,file_line) long file_pos; + long file_line; { p_base = file_pos; + p_bline = file_line; } /* Basically a verbose fseek() to the actual diff listing. */ void ! skip_to(file_pos,file_line) long file_pos; + long file_line; { char *ret; *************** *** 374,379 **** --- 406,412 ---- } else Fseek(pfp, file_pos, 0); + p_input_line = file_line - 1; } /* True if there is more of the current diff listing to process. */ *************** *** 386,395 **** Reg2 int context = 0; while (p_end >= 0) { ! free(p_line[p_end]); /* Changed from postdecrement */ ! p_end--; /* by Keenan Ross for BSD2.9 */ } assert(p_end == -1); p_max = hunkmax; /* gets reduced when --- found */ if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) { --- 419,432 ---- Reg2 int context = 0; while (p_end >= 0) { ! if (p_end == p_efake) ! p_end = p_bfake; /* don't free twice */ ! else ! free(p_line[p_end]); ! p_end--; } assert(p_end == -1); + p_efake = -1; p_max = hunkmax; /* gets reduced when --- found */ if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) { *************** *** 410,423 **** /* # of copiable lines in ptrn */ ret = pgets(buf, sizeof buf, pfp); if (ret == Nullch || strnNE(buf, "********", 8)) { ! next_intuit_at(line_beginning); return FALSE; } p_context = 100; while (p_end < p_max) { line_beginning = ftell(pfp); ret = pgets(buf, sizeof buf, pfp); if (ret == Nullch) { if (p_max - p_end < 4) Strcpy(buf, " \n"); /* assume blank lines got chopped */ --- 447,463 ---- /* # of copiable lines in ptrn */ ret = pgets(buf, sizeof buf, pfp); + p_input_line++; if (ret == Nullch || strnNE(buf, "********", 8)) { ! next_intuit_at(line_beginning,p_input_line); return FALSE; } p_context = 100; + p_hunk_beg = p_input_line + 1; while (p_end < p_max) { line_beginning = ftell(pfp); ret = pgets(buf, sizeof buf, pfp); + p_input_line++; if (ret == Nullch) { if (p_max - p_end < 4) Strcpy(buf, " \n"); /* assume blank lines got chopped */ *************** *** 429,435 **** fatal1("Unexpected end of file in patch.\n"); } } - p_input_line++; p_end++; assert(p_end < hunkmax); p_char[p_end] = *buf; --- 469,474 ---- *************** *** 482,489 **** break; case '-': if (buf[1] == '-') { ! if (p_end != p_ptrn_lines + 1 && ! p_end != p_ptrn_lines + 2) { if (p_end == 1) { /* `old' lines were omitted - set up to fill */ /* them in from 'new' context lines. */ --- 521,529 ---- break; case '-': if (buf[1] == '-') { ! if (repl_beginning || ! (p_end != p_ptrn_lines + 1 + (p_char[p_end-1] == '\n'))) ! { if (p_end == 1) { /* `old' lines were omitted - set up to fill */ /* them in from 'new' context lines. */ *************** *** 493,504 **** fillcnt = p_ptrn_lines; } else { ! if (repl_beginning && repl_could_be_missing){ ! repl_missing = TRUE; ! goto hunk_done; } ! fatal3("Unexpected --- at line %ld: %s", ! p_input_line, buf); } } repl_beginning = p_end; --- 533,555 ---- fillcnt = p_ptrn_lines; } else { ! if (repl_beginning) { ! if (repl_could_be_missing){ ! repl_missing = TRUE; ! goto hunk_done; ! } ! fatal3( ! "Duplicate \"---\" at line %ld--check line numbers at line %ld.\n", ! p_input_line, p_hunk_beg + repl_beginning); } ! else { ! fatal4( ! "%s \"---\" at line %ld--check line numbers at line %ld.\n", ! (p_end <= p_ptrn_lines ! ? "Premature" ! : "Overdue" ), ! p_input_line, p_hunk_beg); ! } } } repl_beginning = p_end; *************** *** 637,645 **** /* if there were omitted context lines, fill them in now */ if (fillcnt) { while (fillcnt-- > 0) { ! while (p_char[fillsrc] != ' ') fillsrc++; p_line[filldst] = p_line[fillsrc]; p_char[filldst] = p_char[fillsrc]; p_len[filldst] = p_len[fillsrc]; --- 688,701 ---- /* if there were omitted context lines, fill them in now */ if (fillcnt) { + p_bfake = filldst; /* remember where not to free() */ + p_efake = filldst + fillcnt - 1; while (fillcnt-- > 0) { ! while (fillsrc <= p_end && p_char[fillsrc] != ' ') fillsrc++; + if (fillsrc > p_end) + fatal2("Replacement text or line numbers mangled in hunk at line %ld\n", + p_hunk_beg); p_line[filldst] = p_line[fillsrc]; p_char[filldst] = p_char[fillsrc]; p_len[filldst] = p_len[fillsrc]; *************** *** 667,673 **** ret = pgets(buf, sizeof buf, pfp); p_input_line++; if (ret == Nullch || !isdigit(*buf)) { ! next_intuit_at(line_beginning); return FALSE; } p_first = (LINENUM)atol(buf); --- 723,729 ---- ret = pgets(buf, sizeof buf, pfp); p_input_line++; if (ret == Nullch || !isdigit(*buf)) { ! next_intuit_at(line_beginning,p_input_line); return FALSE; } p_first = (LINENUM)atol(buf); *************** *** 854,859 **** --- 910,922 ---- blankline = TRUE; i++; } + if (p_efake >= 0) { /* fix non-freeable ptr range */ + n = p_end - i + 1; + if (p_efake > i) + n = -n; + p_efake += n; + p_bfake += n; + } for (n=0; i <= p_end; i++,n++) { p_line[n] = tp_line[i]; p_char[n] = tp_char[i]; *************** *** 983,988 **** LINENUM pch_hunk_beg() { ! return p_input_line - p_end - 1; } --- 1046,1114 ---- LINENUM pch_hunk_beg() { ! return p_hunk_beg; } + /* Apply an ed script by feeding ed itself. */ + + void + do_ed_script() + { + Reg1 char *t; + Reg2 long beginning_of_this_line; + Reg3 bool this_line_is_command = FALSE; + Reg4 FILE *pipefp; + FILE *popen(); + + if (!skip_rest_of_patch) { + Unlink(TMPOUTNAME); + copy_file(filearg[0], TMPOUTNAME); + if (verbose) + Sprintf(buf, "/usr/bin/ed %s", TMPOUTNAME); + else + Sprintf(buf, "/usr/bin/ed - %s", TMPOUTNAME); + pipefp = popen(buf, "w"); + } + for (;;) { + beginning_of_this_line = ftell(pfp); + if (pgets(buf, sizeof buf, pfp) == Nullch) { + next_intuit_at(beginning_of_this_line,p_input_line); + break; + } + p_input_line++; + for (t=buf; isdigit(*t) || *t == ','; t++) ; + this_line_is_command = (isdigit(*buf) && + (*t == 'd' || *t == 'c' || *t == 'a') ); + if (this_line_is_command) { + if (!skip_rest_of_patch) + fputs(buf, pipefp); + if (*t != 'd') { + while (pgets(buf, sizeof buf, pfp) != Nullch) { + p_input_line++; + if (!skip_rest_of_patch) + fputs(buf, pipefp); + if (strEQ(buf, ".\n")) + break; + } + } + } + else { + next_intuit_at(beginning_of_this_line,p_input_line); + break; + } + } + if (skip_rest_of_patch) + return; + fprintf(pipefp, "w\n"); + fprintf(pipefp, "q\n"); + Fflush(pipefp); + Pclose(pipefp); + ignore_signals(); + if (move_file(TMPOUTNAME, outname) < 0) { + toutkeep = TRUE; + chmod(TMPOUTNAME, filemode); + } + else + chmod(outname, filemode); + set_signals(); + } diff -c patch_4/pch.h patch_9/pch.h *** patch_4/pch.h Wed Feb 3 15:40:15 1988 --- patch_9/pch.h Wed Dec 30 11:00:21 1987 *************** *** 1,6 **** ! /* $Header: pch.h,v 2.0 86/09/17 15:39:57 lwall Exp $ * * $Log: pch.h,v $ * Revision 2.0 86/09/17 15:39:57 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/pch.h,v 2.7 87/02/04 11:06:20 ksb Net $ * * $Log: pch.h,v $ + * Revision 2.7 87/02/04 11:06:20 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:30:49 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:39:57 lwall * Baseline for netwide release. * *************** *** 30,32 **** --- 36,39 ---- char pch_char(); char *pfetch(); char *pgets(); + void do_ed_script(); diff -c patch_4/util.c patch_9/util.c *** patch_4/util.c Thu Mar 10 23:43:05 1988 --- patch_9/util.c Tue May 31 18:29:48 1988 *************** *** 139,146 **** return rv; } ! /* #if defined(lint) && defined(CANVARARG) */ ! #if 0 /*VARARGS ARGSUSED*/ say(pat) char *pat; { ; } --- 139,145 ---- return rv; } ! #if defined(lint) && defined(CANVARARG) /*VARARGS ARGSUSED*/ say(pat) char *pat; { ; } *************** *** 190,196 **** Fflush(stderr); #ifndef MINIX /* Minix can't read from fd 2 or 1 ! */ write(2, buf, strlen(buf)); ! if (tty2) { /* might be redirected to a file */ r = read(2, buf, sizeof buf); } else if (isatty(1)) { /* this may be new file output */ --- 189,195 ---- Fflush(stderr); #ifndef MINIX /* Minix can't read from fd 2 or 1 ! */ write(2, buf, strlen(buf)); ! if (tty2) { /* might be redirected to a file */ r = read(2, buf, sizeof buf); } else if (isatty(1)) { /* this may be new file output */ *************** *** 198,204 **** write(1, buf, strlen(buf)); r = read(1, buf, sizeof buf); } ! else #endif if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) { /* might be deleted or unwriteable */ --- 197,203 ---- write(1, buf, strlen(buf)); r = read(1, buf, sizeof buf); } ! else #endif if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) { /* might be deleted or unwriteable */ diff -c patch_4/util.h patch_9/util.h *** patch_4/util.h Thu Mar 10 22:11:52 1988 --- patch_9/util.h Wed Dec 30 11:00:25 1987 *************** *** 1,12 **** ! /* $Header: util.h,v 2.0 86/09/17 15:40:06 lwall Exp $ * * $Log: util.h,v $ * Revision 2.0 86/09/17 15:40:06 lwall * Baseline for netwide release. * */ - #define CANVARARG /* and for those machine that can't handle a variable argument list */ #ifdef CANVARARG --- 1,17 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/util.h,v 2.7 87/02/04 11:06:30 ksb Net $ * * $Log: util.h,v $ + * Revision 2.7 87/02/04 11:06:30 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:31:08 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:40:06 lwall * Baseline for netwide release. * */ /* and for those machine that can't handle a variable argument list */ #ifdef CANVARARG diff -c patch_4/version.c patch_9/version.c *** patch_4/version.c Wed Feb 3 15:40:17 1988 --- patch_9/version.c Wed Dec 30 11:00:26 1987 *************** *** 1,6 **** ! /* $Header: version.c,v 2.0 86/09/17 15:40:11 lwall Exp $ * * $Log: version.c,v $ * Revision 2.0 86/09/17 15:40:11 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/version.c,v 2.7 87/02/04 11:06:37 ksb Net $ * * $Log: version.c,v $ + * Revision 2.7 87/02/04 11:06:37 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:31:15 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:40:11 lwall * Baseline for netwide release. * diff -c patch_4/version.h patch_9/version.h *** patch_4/version.h Wed Feb 3 15:40:17 1988 --- patch_9/version.h Wed Dec 30 11:00:26 1987 *************** *** 1,6 **** ! /* $Header: version.h,v 2.0 86/09/17 15:40:14 lwall Exp $ * * $Log: version.h,v $ * Revision 2.0 86/09/17 15:40:14 lwall * Baseline for netwide release. * --- 1,12 ---- ! /* $Header: /usr/src/unsup/bin/patch/RCS/version.h,v 2.7 87/02/04 11:06:40 ksb Net $ * * $Log: version.h,v $ + * Revision 2.7 87/02/04 11:06:40 ksb + * patched to revision 2.7 + * + * Revision 2.0 86/12/02 14:31:23 doc + * Initial Distributed Revision + * * Revision 2.0 86/09/17 15:40:14 lwall * Baseline for netwide release. *