diff options
| author | kristerw <kristerw@NetBSD.org> | 2003-05-30 22:33:58 +0000 |
|---|---|---|
| committer | kristerw <kristerw@NetBSD.org> | 2003-05-30 22:33:58 +0000 |
| commit | 7e5434fe39eaa35edcc4ddc84b4a481f621ee0bd (patch) | |
| tree | 8298c96a73ac229726400609ad4efaae4fb197ac /usr.bin/patch | |
| parent | b62cbc21e98a57d6fb8d8a98f0b71747df46906b (diff) | |
Remove stuff that are not needed any longer.
Diffstat (limited to 'usr.bin/patch')
| -rw-r--r-- | usr.bin/patch/common.h | 9 | ||||
| -rw-r--r-- | usr.bin/patch/inp.c | 157 | ||||
| -rw-r--r-- | usr.bin/patch/inp.h | 4 | ||||
| -rw-r--r-- | usr.bin/patch/patch.c | 12 |
4 files changed, 29 insertions, 153 deletions
diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h index f14f145c020..6bd8c85b10d 100644 --- a/usr.bin/patch/common.h +++ b/usr.bin/patch/common.h @@ -1,4 +1,4 @@ -/* $NetBSD: common.h,v 1.13 2003/05/30 18:14:13 kristerw Exp $ */ +/* $NetBSD: common.h,v 1.14 2003/05/30 22:33:58 kristerw Exp $ */ #define DEBUGGING @@ -40,7 +40,6 @@ #define MAXHUNKSIZE 100000 /* is this enough lines? */ #define INITHUNKMAX 125 /* initial dynamic allocation size */ #define MAXLINELEN 10240 -#define BUFFERSIZE 1024 #define SCCSPREFIX "s." #define GET "get -e %s" @@ -57,8 +56,6 @@ #define Nulline 0 -#define Ctl(ch) ((ch) & 037) - #define strNE(s1,s2) (strcmp(s1, s2)) #define strEQ(s1,s2) (!strcmp(s1, s2)) #define strnNE(s1,s2,l) (strncmp(s1, s2, l)) @@ -73,8 +70,6 @@ typedef int LINENUM; /* must be signed */ EXT int Argc; /* guess */ EXT char **Argv; -EXT int Argc_last; /* for restarting plan_b */ -EXT char **Argv_last; EXT struct stat filestat; /* file statistics area */ EXT mode_t filemode INIT(0644); @@ -85,8 +80,6 @@ EXT FILE *rejfp INIT(NULL); /* reject file pointer */ EXT int myuid; /* cache getuid return value */ -EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */ - #define MAXFILEC 2 EXT int filec INIT(0); /* how many file arguments? */ EXT char *filearg[MAXFILEC]; diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index f5cf277f703..c3b17123247 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,7 +1,7 @@ -/* $NetBSD: inp.c,v 1.12 2003/05/30 18:14:13 kristerw Exp $ */ +/* $NetBSD: inp.c,v 1.13 2003/05/30 22:33:58 kristerw Exp $ */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: inp.c,v 1.12 2003/05/30 18:14:13 kristerw Exp $"); +__RCSID("$NetBSD: inp.c,v 1.13 2003/05/30 22:33:58 kristerw Exp $"); #endif /* not lint */ #include "EXTERN.h" @@ -16,8 +16,7 @@ __RCSID("$NetBSD: inp.c,v 1.12 2003/05/30 18:14:13 kristerw Exp $"); #include <unistd.h> #include <fcntl.h> -static bool plan_a(char *); -static void plan_b(char *); +static void plan_a(char *); static bool rev_in_string(char *); /* Input-file-with-indexable-lines abstract type. */ @@ -26,57 +25,37 @@ static size_t i_size; /* Size of the input file */ static char *i_womp; /* Plan a buffer for entire file */ static char **i_ptr; /* Pointers to lines in i_womp */ -static int tifd = -1; /* Plan b virtual string array */ -static char *tibuf[2]; /* Plan b buffers */ -static LINENUM tiline[2] = {-1, -1}; /* 1st line in each buffer */ -static LINENUM lines_per_buf; /* How many lines per buffer */ -static int tireclen; /* Length of records in tmp file */ - /* - * New patch--prepare to edit another file. + * New patch -- prepare to edit another file. */ void re_input(void) { - if (using_plan_a) { - i_size = 0; + i_size = 0; - if (i_ptr != NULL) - free(i_ptr); - if (i_womp != NULL) - free(i_womp); - i_womp = NULL; - i_ptr = NULL; - } else { - using_plan_a = TRUE; /* maybe the next one is smaller */ - Close(tifd); - tifd = -1; - free(tibuf[0]); - free(tibuf[1]); - tibuf[0] = tibuf[1] = NULL; - tiline[0] = tiline[1] = -1; - tireclen = 0; - } + if (i_ptr != NULL) + free(i_ptr); + if (i_womp != NULL) + free(i_womp); + i_womp = NULL; + i_ptr = NULL; } /* - * Constuct the line index, somehow or other. + * Construct the line index, somehow or other. */ void scan_input(char *filename) { - if (!plan_a(filename)) - plan_b(filename); - if (verbose) { - say("Patching file %s using Plan %s...\n", filename, - (using_plan_a ? "A" : "B") ); - } + plan_a(filename); + if (verbose) + say("Patching file %s using Plan A...\n", filename); } /* * Try keeping everything in memory. */ -static bool +static void plan_a(char *filename) { int ifd, statfailed; @@ -180,15 +159,8 @@ plan_a(char *filename) i_womp = xmalloc(i_size + 2); if ((ifd = open(filename, 0)) < 0) pfatal("can't open file %s", filename); - if (read(ifd, i_womp, i_size) != i_size) { - /* - * This probably means i_size > 15 or 16 bits worth at this - * point it doesn't matter if i_womp was undersized. - */ - Close(ifd); - free(i_womp); - return FALSE; - } + if (read(ifd, i_womp, i_size) != i_size) + pfatal("read error"); Close(ifd); if (i_size && i_womp[i_size - 1] != '\n') i_womp[i_size++] = '\n'; @@ -238,105 +210,18 @@ plan_a(char *filename) say("Good. This file appears to be the %s version.\n", revision); } - - return TRUE; /* Plan a will work. */ -} - -/* - * Keep (virtually) nothing in memory. - */ -static void -plan_b(char *filename) -{ - FILE *ifp; - int i = 0; - int maxlen = 1; - bool found_revision = (revision == NULL); - - using_plan_a = FALSE; - if ((ifp = fopen(filename, "r")) == NULL) - pfatal("can't open file %s", filename); - if ((tifd = creat(TMPINNAME, 0666)) < 0) - pfatal("can't open file %s", TMPINNAME); - while (fgets(buf, sizeof buf, ifp) != NULL) { - if (revision != NULL && !found_revision && rev_in_string(buf)) - found_revision = TRUE; - if ((i = strlen(buf)) > maxlen) - maxlen = i; /* Find longest line. */ - } - if (revision != NULL) { - if (!found_revision) { - if (force) { - if (verbose) - say( -"Warning: this file doesn't appear to be the %s version--patching anyway.\n", - revision); - } else if (batch) { - fatal( -"this file doesn't appear to be the %s version--aborting.\n", revision); - } else { - ask( -"This file doesn't appear to be the %s version--patch anyway? [n] ", - revision); - if (*buf != 'y') - fatal("aborted\n"); - } - } else if (verbose) - say("Good. This file appears to be the %s version.\n", - revision); - } - Fseek(ifp, 0L, 0); /* Rewind file. */ - lines_per_buf = BUFFERSIZE / maxlen; - tireclen = maxlen; - tibuf[0] = xmalloc(BUFFERSIZE + 1); - tibuf[1] = xmalloc(BUFFERSIZE + 1); - for (i = 1; ; i++) { - if (! (i % lines_per_buf)) /* New block. */ - if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) - pfatal("can't write temp file"); - if (fgets(tibuf[0] + maxlen * (i % lines_per_buf), - maxlen + 1, ifp) == NULL) { - input_lines = i - 1; - if (i % lines_per_buf) - if (write(tifd, tibuf[0], BUFFERSIZE) - < BUFFERSIZE) - pfatal("can't write temp file"); - break; - } - } - Fclose(ifp); - Close(tifd); - if ((tifd = open(TMPINNAME, 0)) < 0) { - pfatal("can't reopen file %s", TMPINNAME); - } } /* * Fetch a line from the input file, \n terminated, not necessarily \0. */ char * -ifetch(LINENUM line, int whichbuf) +ifetch(LINENUM line) { if (line < 1 || line > input_lines) return ""; - if (using_plan_a) - return i_ptr[line]; - else { - LINENUM offline = line % lines_per_buf; - LINENUM baseline = line - offline; - if (tiline[0] == baseline) - whichbuf = 0; - else if (tiline[1] == baseline) - whichbuf = 1; - else { - tiline[whichbuf] = baseline; - Lseek(tifd, baseline / lines_per_buf * BUFFERSIZE, 0); - if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0) - pfatal("error reading tmp file %s", TMPINNAME); - } - return tibuf[whichbuf] + (tireclen * offline); - } + return i_ptr[line]; } /* @@ -361,5 +246,5 @@ rev_in_string(char *string) return TRUE; } } - return FALSE; + return FALSE; } diff --git a/usr.bin/patch/inp.h b/usr.bin/patch/inp.h index 98da6c72071..031365ff8ef 100644 --- a/usr.bin/patch/inp.h +++ b/usr.bin/patch/inp.h @@ -1,9 +1,9 @@ -/* $NetBSD: inp.h,v 1.6 2002/03/16 22:36:42 kristerw Exp $ */ +/* $NetBSD: inp.h,v 1.7 2003/05/30 22:33:58 kristerw Exp $ */ EXT LINENUM input_lines INIT(0); /* how long is input file in lines */ EXT LINENUM last_frozen_line INIT(0); /* how many input lines have been */ /* irretractibly output */ void re_input(void); void scan_input(char *); -char *ifetch(LINENUM, int); +char *ifetch(LINENUM); diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index efabee91aa1..cdb9aa8ee1f 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -1,4 +1,4 @@ -/* $NetBSD: patch.c,v 1.15 2003/05/30 18:14:13 kristerw Exp $ */ +/* $NetBSD: patch.c,v 1.16 2003/05/30 22:33:58 kristerw Exp $ */ /* patch - a program to apply diffs to original files * @@ -25,7 +25,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: patch.c,v 1.15 2003/05/30 18:14:13 kristerw Exp $"); +__RCSID("$NetBSD: patch.c,v 1.16 2003/05/30 22:33:58 kristerw Exp $"); #endif /* not lint */ #include "INTERN.h" @@ -440,8 +440,6 @@ get_some_switches(void) char *s; rejname[0] = '\0'; - Argc_last = Argc; - Argv_last = Argv; if (!Argc) return; for (Argc--,Argv++; Argc; Argc--,Argv++) { @@ -843,7 +841,7 @@ dump_line(LINENUM line) char R_newline = '\n'; /* Note: string is not null terminated. */ - for (s=ifetch(line, 0); putc(*s, ofp) != R_newline; s++) ; + for (s=ifetch(line); putc(*s, ofp) != R_newline; s++) ; } /* Does the patch pattern match at line base+offset? */ @@ -857,12 +855,12 @@ patch_match(LINENUM base, LINENUM offset, LINENUM fuzz) for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) { if (canonicalize) { - if (!similar(ifetch(iline, (offset >= 0)), + if (!similar(ifetch(iline), pfetch(pline), pch_line_len(pline) )) return FALSE; } - else if (strnNE(ifetch(iline, (offset >= 0)), + else if (strnNE(ifetch(iline), pfetch(pline), pch_line_len(pline) )) return FALSE; |
