diff options
| author | kristerw <kristerw@NetBSD.org> | 2002-03-08 21:57:33 +0000 |
|---|---|---|
| committer | kristerw <kristerw@NetBSD.org> | 2002-03-08 21:57:33 +0000 |
| commit | 8bcbaa7bc893540be6bf045238abd546a41d67c3 (patch) | |
| tree | 9c48b11d768ceb2ed03d7360fcf1a806e805c3f7 /usr.bin/patch | |
| parent | ce635a702a6fd5a7f7759cb6d3ae578dc63c9dbc (diff) | |
Ansify
Remove 'register'
Make local functions static.
Remove most '#ifndef lint'
Diffstat (limited to 'usr.bin/patch')
| -rw-r--r-- | usr.bin/patch/backupfile.c | 63 | ||||
| -rw-r--r-- | usr.bin/patch/backupfile.h | 12 | ||||
| -rw-r--r-- | usr.bin/patch/common.h | 27 | ||||
| -rw-r--r-- | usr.bin/patch/config.h | 52 | ||||
| -rw-r--r-- | usr.bin/patch/inp.c | 64 | ||||
| -rw-r--r-- | usr.bin/patch/inp.h | 14 | ||||
| -rw-r--r-- | usr.bin/patch/patch.c | 131 | ||||
| -rw-r--r-- | usr.bin/patch/pch.c | 158 | ||||
| -rw-r--r-- | usr.bin/patch/pch.h | 46 | ||||
| -rw-r--r-- | usr.bin/patch/util.c | 57 | ||||
| -rw-r--r-- | usr.bin/patch/util.h | 24 |
11 files changed, 242 insertions, 406 deletions
diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c index a8528a2d5fe..6017d3e94bc 100644 --- a/usr.bin/patch/backupfile.c +++ b/usr.bin/patch/backupfile.c @@ -1,4 +1,4 @@ -/* $NetBSD: backupfile.c,v 1.6 1998/11/06 22:40:13 christos Exp $ */ +/* $NetBSD: backupfile.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $ */ /* backupfile.c -- make Emacs style backup file names Copyright (C) 1990 Free Software Foundation, Inc. @@ -15,7 +15,7 @@ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: backupfile.c,v 1.6 1998/11/06 22:40:13 christos Exp $"); +__RCSID("$NetBSD: backupfile.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $"); #endif /* not lint */ #include <stdio.h> @@ -74,16 +74,13 @@ enum backup_type backup_type = none; char *simple_backup_suffix = "~"; /* backupfile.c */ -char *find_backup_file_name __P((char *)); -static int max_backup_version __P((char *, char *)); -static char *make_version_name __P((char *, int)); -static int version_number __P((char *, char *, int)); -static char *concat __P((char *, char *)); -char *basename __P((char *)); -char *dirname __P((char *)); -int argmatch __P((char *, char **)); -void invalid_arg __P((char *, char *, int)); -enum backup_type get_version __P((char *)); +static int max_backup_version(char *, char *); +static char *make_version_name(char *, int); +static int version_number(char *, char *, int); +static char *concat(char *, char *); +static char *dirname(char *); +static int argmatch(char *, char **); +static void invalid_arg(char *, char *, int); #ifndef NODIR /* Return the name of the new backup file for file FILE, @@ -92,8 +89,7 @@ enum backup_type get_version __P((char *)); Do not call this function if backup_type == none. */ char * -find_backup_file_name (file) - char *file; +find_backup_file_name(char *file) { char *dir; char *base_versions; @@ -124,8 +120,7 @@ find_backup_file_name (file) FILE should already have ".~" appended to it. */ static int -max_backup_version (file, dir) - char *file, *dir; +max_backup_version(char *file, char *dir) { DIR *dirp; struct direct *dp; @@ -157,9 +152,7 @@ max_backup_version (file, dir) "FILE.~VERSION~". Return 0 if out of memory. */ static char * -make_version_name (file, version) - char *file; - int version; +make_version_name(char *file, int version) { char *backup_name; @@ -175,10 +168,7 @@ make_version_name (file, version) BASE should already have ".~" appended to it. */ static int -version_number (base, backup, base_length) - char *base; - char *backup; - int base_length; +version_number(char *base, char *backup, int base_length) { int version; char *p; @@ -198,8 +188,7 @@ version_number (base, backup, base_length) If out of memory, return 0. */ static char * -concat (str1, str2) - char *str1, *str2; +concat(char *str1, char *str2) { char *newstr; char str1_length = strlen (str1); @@ -215,8 +204,7 @@ concat (str1, str2) /* Return NAME with any leading path stripped off. */ char * -basename (name) - char *name; +basename(char *name) { char *base; @@ -229,9 +217,8 @@ basename (name) Assumes that trailing slashes have already been removed. */ -char * -dirname (path) - char *path; +static char * +dirname(char *path) { char *newpath; char *slash; @@ -265,10 +252,8 @@ dirname (path) of the matched element, else -1 if it does not match any element or -2 if it is ambiguous (is a prefix of more than one element). */ -int -argmatch (arg, optlist) - char *arg; - char **optlist; +static int +argmatch(char *arg, char **optlist) { int i; /* Temporary index in OPTLIST. */ int arglen; /* Length of ARG. */ @@ -304,11 +289,8 @@ argmatch (arg, optlist) VALUE is the invalid value that was given. PROBLEM is the return value from argmatch. */ -void -invalid_arg (kind, value, problem) - char *kind; - char *value; - int problem; +static void +invalid_arg(char *kind, char *value, int problem) { fprintf (stderr, "patch: "); if (problem == -1) @@ -332,8 +314,7 @@ static enum backup_type backup_types[] = Unique abbreviations are accepted. */ enum backup_type -get_version (version) - char *version; +get_version(char *version) { int i; diff --git a/usr.bin/patch/backupfile.h b/usr.bin/patch/backupfile.h index 72ea4c6ddd1..ed31061a186 100644 --- a/usr.bin/patch/backupfile.h +++ b/usr.bin/patch/backupfile.h @@ -1,4 +1,4 @@ -/* $NetBSD: backupfile.h,v 1.3 1996/09/19 06:27:08 thorpej Exp $ */ +/* $NetBSD: backupfile.h,v 1.4 2002/03/08 21:57:33 kristerw Exp $ */ /* backupfile.h -- declarations for making Emacs style backup file names Copyright (C) 1990 Free Software Foundation, Inc. @@ -31,10 +31,6 @@ enum backup_type extern enum backup_type backup_type; extern char *simple_backup_suffix; -#ifdef __STDC__ -char *find_backup_file_name (char *file); -enum backup_type get_version (char *version); -#else -char *find_backup_file_name (); -enum backup_type get_version (); -#endif +char *find_backup_file_name(char *); +enum backup_type get_version(char *); +char *basename(char *); diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h index 9b1cfaa371c..f7573fc64dc 100644 --- a/usr.bin/patch/common.h +++ b/usr.bin/patch/common.h @@ -1,8 +1,7 @@ -/* $NetBSD: common.h,v 1.9 1999/02/09 05:15:45 sommerfe Exp $ */ +/* $NetBSD: common.h,v 1.10 2002/03/08 21:57:33 kristerw Exp $ */ #define DEBUGGING -#define VOIDUSED 7 #include "config.h" /* shut lint up about the following when return value ignored */ @@ -156,27 +155,6 @@ EXT char end_defined[128]; /* #endif xyzzy */ EXT char *revision INIT(Nullch); /* prerequisite revision, if any */ #include <errno.h> -#ifndef errno -extern int errno; -#endif - -#ifndef __STDC__ -FILE *popen(); -char *malloc(); -char *realloc(); -long atol(); -char *getenv(); -char *strcpy(); -char *strcat(); -char *rindex(); -#if 0 /* This can cause a prototype conflict. */ -#ifdef CHARSPRINTF -char *sprintf(); -#else -int sprintf(); -#endif -#endif -#endif #if !defined(S_ISDIR) && defined(S_IFDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) @@ -185,5 +163,4 @@ int sprintf(); #define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) #endif -void my_exit __P((int)) __attribute__((__noreturn__)); -char *basename __P((char *)); +void my_exit(int) __attribute__((__noreturn__)); diff --git a/usr.bin/patch/config.h b/usr.bin/patch/config.h index 8a84f97fe88..f66e4c048ca 100644 --- a/usr.bin/patch/config.h +++ b/usr.bin/patch/config.h @@ -1,4 +1,4 @@ -/* $NetBSD: config.h,v 1.4 1998/02/22 13:33:49 christos Exp $ */ +/* $NetBSD: config.h,v 1.5 2002/03/08 21:57:33 kristerw Exp $ */ /* config.h * This file was produced by running the config.h.SH script, which @@ -83,53 +83,3 @@ * This is defined if the system has unistd.h. */ #define HAVE_UNISTD_H /**/ - -/* Reg1: - * This symbol, along with Reg2, Reg3, etc. is either the word "register" - * or null, depending on whether the C compiler pays attention to this - * many register declarations. The intent is that you don't have to - * order your register declarations in the order of importance, so you - * can freely declare register variables in sub-blocks of code and as - * function parameters. Do not use Reg<n> more than once per routine. - */ - -#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 /**/ - -/* VOIDFLAGS: - * This symbol indicates how much support of the void type is given by this - * compiler. What various bits mean: - * - * 1 = supports declaration of void - * 2 = supports arrays of pointers to functions returning void - * 4 = supports comparisons between pointers to void functions and - * addresses of void functions - * - * The package designer should define VOIDUSED to indicate the requirements - * of the package. This can be done either by #defining VOIDUSED before - * including config.h, or by defining defvoidused in Myinit.U. If the - * level of void support necessary is not present, defines void to int. - */ -#ifndef VOIDUSED -#define VOIDUSED 7 -#endif -#define VOIDFLAGS 7 -#if (VOIDFLAGS & VOIDUSED) != VOIDUSED -#define void int /* is void to be avoided? */ -#define M_VOID /* Xenix strikes again */ -#endif - diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c index 2273b3b6e8d..01190ccb048 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,10 +1,11 @@ -/* $NetBSD: inp.c,v 1.6 1999/02/09 05:15:45 sommerfe Exp $ */ +/* $NetBSD: inp.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $ */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: inp.c,v 1.6 1999/02/09 05:15:45 sommerfe Exp $"); +__RCSID("$NetBSD: inp.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $"); #endif /* not lint */ #include "EXTERN.h" +#include "backupfile.h" #include "common.h" #include "util.h" #include "pch.h" @@ -30,14 +31,13 @@ static int tireclen; /* length of records in tmp file */ /* New patch--prepare to edit another file. */ void -re_input() +re_input(void) { if (using_plan_a) { i_size = 0; -#ifndef lint - if (i_ptr != Null(char**)) - free((char *)i_ptr); -#endif + + if (i_ptr != NULL) + free(i_ptr); if (i_womp != Nullch) free(i_womp); i_womp = Nullch; @@ -58,8 +58,7 @@ re_input() /* Constuct the line index, somehow or other. */ void -scan_input(filename) -char *filename; +scan_input(char *filename) { if (!plan_a(filename)) plan_b(filename); @@ -72,12 +71,11 @@ char *filename; /* Try keeping everything in memory. */ bool -plan_a(filename) -char *filename; +plan_a(char *filename) { int ifd, statfailed; - Reg1 char *s; - Reg2 LINENUM iline; + char *s; + LINENUM iline; char lbuf[MAXLINELEN]; statfailed = stat(filename, &filestat); @@ -159,23 +157,17 @@ char *filename; out_of_mem = FALSE; return FALSE; /* force plan b because plan a bombed */ } -#ifdef lint - i_womp = Nullch; -#else - i_womp = malloc((MEM)(i_size+2)); /* lint says this may alloc less than */ - /* i_size, but that's okay, I think. */ -#endif + + i_womp = malloc((MEM)(i_size+2)); if (i_womp == Nullch) return FALSE; if ((ifd = open(filename, 0)) < 0) pfatal2("can't open file %s", filename); -#ifndef lint - if (read(ifd, i_womp, (int)i_size) != i_size) { + if (read(ifd, i_womp, i_size) != i_size) { Close(ifd); /* probably means i_size > 15 or 16 bits worth */ free(i_womp); /* at this point it doesn't matter if i_womp was */ return FALSE; /* undersized. */ } -#endif Close(ifd); if (i_size && i_womp[i_size-1] != '\n') i_womp[i_size++] = '\n'; @@ -188,11 +180,7 @@ char *filename; if (*s == '\n') iline++; } -#ifdef lint - i_ptr = Null(char**); -#else i_ptr = (char **)malloc((MEM)((iline + 2) * sizeof(char *))); -#endif if (i_ptr == Null(char **)) { /* shucks, it was a near thing */ free((char *)i_womp); return FALSE; @@ -240,13 +228,12 @@ char *filename; /* Keep (virtually) nothing in memory. */ void -plan_b(filename) -char *filename; +plan_b(char *filename) { - Reg3 FILE *ifp; - Reg1 int i = 0; - Reg2 int maxlen = 1; - Reg4 bool found_revision = (revision == Nullch); + FILE *ifp; + int i = 0; + int maxlen = 1; + bool found_revision = (revision == Nullch); using_plan_a = FALSE; if ((ifp = fopen(filename, "r")) == Nullfp) @@ -313,9 +300,7 @@ char *filename; /* Fetch a line from the input file, \n terminated, not necessarily \0. */ char * -ifetch(line,whichbuf) -Reg1 LINENUM line; -int whichbuf; /* ignored when file in memory */ +ifetch(LINENUM line, int whichbuf) { if (line < 1 || line > input_lines) return ""; @@ -331,9 +316,7 @@ int whichbuf; /* ignored when file in memory */ whichbuf = 1; else { tiline[whichbuf] = baseline; -#ifndef lint /* complains of long accuracy */ Lseek(tifd, (long)baseline / lines_per_buf * BUFFERSIZE, 0); -#endif if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0) pfatal2("error reading tmp file %s", TMPINNAME); } @@ -344,11 +327,10 @@ int whichbuf; /* ignored when file in memory */ /* True if the string argument contains the revision number we want. */ bool -rev_in_string(string) -char *string; +rev_in_string(char *string) { - Reg1 char *s; - Reg2 int patlen; + char *s; + int patlen; if (revision == Nullch) return TRUE; diff --git a/usr.bin/patch/inp.h b/usr.bin/patch/inp.h index 597421c5b82..46aec2b5770 100644 --- a/usr.bin/patch/inp.h +++ b/usr.bin/patch/inp.h @@ -1,11 +1,11 @@ -/* $NetBSD: inp.h,v 1.4 1998/02/22 13:33:49 christos Exp $ */ +/* $NetBSD: inp.h,v 1.5 2002/03/08 21:57:33 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 __P((void)); -void scan_input __P((char *)); -bool plan_a __P((char *)); -void plan_b __P((char *)); -char *ifetch __P((Reg1 LINENUM, int)); -bool rev_in_string __P((char *)); +void re_input(void); +void scan_input(char *); +bool plan_a(char *); +void plan_b(char *); +char *ifetch(LINENUM, int); +bool rev_in_string(char *); diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index 5332cd0acb4..19e4446714f 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -1,4 +1,4 @@ -/* $NetBSD: patch.c,v 1.9 2002/03/06 12:01:04 ragge Exp $ */ +/* $NetBSD: patch.c,v 1.10 2002/03/08 21:57:33 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.9 2002/03/06 12:01:04 ragge Exp $"); +__RCSID("$NetBSD: patch.c,v 1.10 2002/03/08 21:57:33 kristerw Exp $"); #endif /* not lint */ #include "INTERN.h" @@ -40,25 +40,23 @@ __RCSID("$NetBSD: patch.c,v 1.9 2002/03/06 12:01:04 ragge Exp $"); #include <stdlib.h> #include <unistd.h> -int main __P((int, char **)); - /* procedures */ -static void reinitialize_almost_everything __P((void)); -static char *nextarg __P((void)); -struct option; -static int optcmp __P((const void *, const void *)); -static char decode_long_option __P((char *)); -static void get_some_switches __P((void)); -static LINENUM locate_hunk __P((LINENUM)); -static void abort_hunk __P((void)); -static void apply_hunk __P((LINENUM)); -static void init_output __P((char *)); -static void init_reject __P((char *)); -static void copy_till __P((Reg1 LINENUM)); -static void spew_output __P((void)); -static void dump_line __P((LINENUM)); -static bool patch_match __P((LINENUM, LINENUM, LINENUM)); -static bool similar __P((Reg1 char *, Reg2 char *, Reg3 int)); +static void reinitialize_almost_everything(void); +static char *nextarg(void); +static int optcmp(const void *, const void *); +static char decode_long_option(char *); +static void get_some_switches(void); +static LINENUM locate_hunk(LINENUM); +static void abort_hunk(void); +static void apply_hunk(LINENUM); +static void init_output(char *); +static void init_reject(char *); +static void copy_till(LINENUM); +static void spew_output(void); +static void dump_line(LINENUM); +static bool patch_match(LINENUM, LINENUM, LINENUM); +static bool similar(char *, char *, int); +int main(int, char *[]); /* TRUE if -E was specified on command line. */ static int remove_empty_files = FALSE; @@ -69,9 +67,7 @@ static int reverse_flag_specified = FALSE; /* Apply a set of diffs as appropriate. */ int -main(argc,argv) -int argc; -char **argv; +main(int argc, char *argv[]) { LINENUM where = 0; LINENUM newwhere; @@ -354,7 +350,7 @@ char **argv; /* Prepare to find the next patch to do in the patch file. */ static void -reinitialize_almost_everything() +reinitialize_almost_everything(void) { re_patch(); re_input(); @@ -392,7 +388,7 @@ reinitialize_almost_everything() } static char * -nextarg() +nextarg(void) { if (!--Argc) fatal2("missing argument after `%s'\n", *Argv); @@ -407,8 +403,7 @@ struct option { }; static int -optcmp(va, vb) - const void *va, *vb; +optcmp(const void *va, const void *vb) { const struct option *a = va, *b = vb; return strcmp (a->long_opt, b->long_opt); @@ -417,8 +412,7 @@ optcmp(va, vb) /* Decode Long options beginning with "--" to their short equivalents. */ static char -decode_long_option(opt) - char *opt; +decode_long_option(char *opt) { /* * This table must be sorted on the first field. We also decode @@ -465,9 +459,9 @@ decode_long_option(opt) /* Process switches and filenames up to next '+' or end of list. */ static void -get_some_switches() +get_some_switches(void) { - Reg1 char *s; + char *s; rejname[0] = '\0'; Argc_last = Argc; @@ -608,15 +602,14 @@ Options:\n\ /* Attempt to find the right place to apply this hunk of patch. */ static LINENUM -locate_hunk(fuzz) -LINENUM fuzz; +locate_hunk(LINENUM fuzz) { - Reg1 LINENUM first_guess = pch_first() + last_offset; - Reg2 LINENUM offset; + LINENUM first_guess = pch_first() + last_offset; + LINENUM offset; LINENUM pat_lines = pch_ptrn_lines(); - Reg3 LINENUM max_pos_offset = input_lines - first_guess + LINENUM max_pos_offset = input_lines - first_guess - pat_lines + 1; - Reg4 LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context(); if (!pat_lines) /* null range matches always */ @@ -626,8 +619,8 @@ LINENUM fuzz; if (first_guess <= input_lines && patch_match(first_guess, Nulline, fuzz)) return first_guess; for (offset = 1; ; offset++) { - Reg5 bool check_after = (offset <= max_pos_offset); - Reg6 bool check_before = (offset <= max_neg_offset); + bool check_after = (offset <= max_pos_offset); + bool check_before = (offset <= max_neg_offset); if (check_after && patch_match(first_guess, offset, fuzz)) { #ifdef DEBUGGING @@ -653,10 +646,10 @@ LINENUM fuzz; /* We did not find the pattern, dump out the hunk so they can handle it. */ static void -abort_hunk() +abort_hunk(void) { - Reg1 LINENUM i; - Reg2 LINENUM pat_end = pch_end(); + LINENUM i; + LINENUM pat_end = pch_end(); /* add in last_offset to guess the same as the previous successful hunk */ LINENUM oldfirst = pch_first() + last_offset; LINENUM newfirst = pch_newfirst() + last_offset; @@ -699,19 +692,18 @@ abort_hunk() /* We found where to apply it (we hope), so do it. */ static void -apply_hunk(where) -LINENUM where; +apply_hunk(LINENUM where) { - Reg1 LINENUM old = 1; - Reg2 LINENUM lastline = pch_ptrn_lines(); - Reg3 LINENUM new = lastline+1; + LINENUM old = 1; + LINENUM lastline = pch_ptrn_lines(); + LINENUM new = lastline+1; #define OUTSIDE 0 #define IN_IFNDEF 1 #define IN_IFDEF 2 #define IN_ELSE 3 - Reg4 int def_state = OUTSIDE; - Reg5 bool R_do_defines = do_defines; - Reg6 LINENUM pat_end = pch_end(); + int def_state = OUTSIDE; + bool R_do_defines = do_defines; + LINENUM pat_end = pch_end(); where--; while (pch_char(new) == '=' || pch_char(new) == '\n') @@ -819,8 +811,7 @@ LINENUM where; /* Open the new file. */ static void -init_output(name) -char *name; +init_output(char *name) { ofp = fopen(name, "w"); if (ofp == Nullfp) @@ -830,8 +821,7 @@ char *name; /* Open a file to put hunks we can't locate. */ static void -init_reject(name) -char *name; +init_reject(char *name) { rejfp = fopen(name, "w"); if (rejfp == Nullfp) @@ -841,10 +831,9 @@ char *name; /* Copy input file to output, up to wherever hunk is to be applied. */ static void -copy_till(lastline) -Reg1 LINENUM lastline; +copy_till(LINENUM lastline) { - Reg2 LINENUM R_last_frozen_line = last_frozen_line; + LINENUM R_last_frozen_line = last_frozen_line; if (R_last_frozen_line > lastline) fatal1("misordered hunks! output would be garbled\n"); @@ -857,7 +846,7 @@ Reg1 LINENUM lastline; /* Finish copying the input file to the output file. */ static void -spew_output() +spew_output(void) { #ifdef DEBUGGING if (debug & 256) @@ -872,11 +861,10 @@ spew_output() /* Copy one line from input to output. */ static void -dump_line(line) -LINENUM line; +dump_line(LINENUM line) { - Reg1 char *s; - Reg2 char R_newline = '\n'; + char *s; + char R_newline = '\n'; /* Note: string is not null terminated. */ for (s=ifetch(line, 0); putc(*s, ofp) != R_newline; s++) ; @@ -885,14 +873,11 @@ LINENUM line; /* Does the patch pattern match at line base+offset? */ static bool -patch_match(base, offset, fuzz) -LINENUM base; -LINENUM offset; -LINENUM fuzz; +patch_match(LINENUM base, LINENUM offset, LINENUM fuzz) { - Reg1 LINENUM pline = 1 + fuzz; - Reg2 LINENUM iline; - Reg3 LINENUM pat_lines = pch_ptrn_lines() - fuzz; + LINENUM pline = 1 + fuzz; + LINENUM iline; + LINENUM pat_lines = pch_ptrn_lines() - fuzz; for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) { if (canonicalize) { @@ -912,10 +897,7 @@ LINENUM fuzz; /* Do two lines match with canonicalized white space? */ static bool -similar(a,b,len) -Reg1 char *a; -Reg2 char *b; -Reg3 int len; +similar(char *a, char *b, int len) { while (len) { if (isspace((unsigned char)*b)) {/* whitespace (or \n) to match? */ @@ -940,8 +922,7 @@ Reg3 int len; /* Exit with cleanup. */ void -my_exit(status) -int status; +my_exit(int status) { Unlink(TMPINNAME); if (!toutkeep) { diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index ebec9a0708e..b1eb6ee9b56 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1,7 +1,7 @@ -/* $NetBSD: pch.c,v 1.7 1999/02/09 05:15:45 sommerfe Exp $ */ +/* $NetBSD: pch.c,v 1.8 2002/03/08 21:57:33 kristerw Exp $ */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: pch.c,v 1.7 1999/02/09 05:15:45 sommerfe Exp $"); +__RCSID("$NetBSD: pch.c,v 1.8 2002/03/08 21:57:33 kristerw Exp $"); #endif /* not lint */ #include "EXTERN.h" @@ -38,10 +38,10 @@ 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. */ -static void malformed __P((void)); +static void malformed(void); void -re_patch() +re_patch(void) { p_first = Nulline; p_newfirst = Nulline; @@ -55,8 +55,7 @@ re_patch() /* Open the patch file at the beginning of time. */ void -open_patch_file(filename) -char *filename; +open_patch_file(char *filename) { if (filename == Nullch || !*filename || strEQ(filename, "-")) { pfp = fopen(TMPPATNAME, "w"); @@ -79,22 +78,20 @@ char *filename; /* Make sure our dynamically realloced tables are malloced to begin with. */ void -set_hunkmax() +set_hunkmax(void) { -#ifndef lint - if (p_line == Null(char**)) + if (p_line == NULL) p_line = (char**) malloc((MEM)hunkmax * sizeof(char *)); - if (p_len == Null(short*)) + if (p_len == NULL) p_len = (short*) malloc((MEM)hunkmax * sizeof(short)); -#endif - if (p_char == Nullch) + if (p_char == NULL) p_char = (char*) malloc((MEM)hunkmax * sizeof(char)); } /* Enlarge the arrays containing the current hunk of patch. */ void -grow_hunkmax() +grow_hunkmax(void) { hunkmax *= 2; /* @@ -103,11 +100,9 @@ grow_hunkmax() * p_len's old space. Not on PDP-11's however. But it doesn't matter. */ assert(p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch); -#ifndef lint - p_line = (char**) realloc((char*)p_line, (MEM)hunkmax * sizeof(char *)); - p_len = (short*) realloc((char*)p_len, (MEM)hunkmax * sizeof(short)); - p_char = (char*) realloc((char*)p_char, (MEM)hunkmax * sizeof(char)); -#endif + p_line = (char**) realloc(p_line, (MEM)hunkmax * sizeof(char *)); + p_len = (short*) realloc(p_len, (MEM)hunkmax * sizeof(short)); + p_char = (char*) realloc(p_char, (MEM)hunkmax * sizeof(char)); if (p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch) return; if (!using_plan_a) @@ -119,7 +114,7 @@ grow_hunkmax() /* True if the remainder of the patch file contains a diff of some sort. */ bool -there_is_another_patch() +there_is_another_patch(void) { if (p_base != 0L && p_base >= p_filesize) { if (verbose) @@ -181,26 +176,26 @@ there_is_another_patch() /* Determine what kind of diff is in the remaining part of the patch file. */ int -intuit_diff_type() +intuit_diff_type(void) { - Reg4 long this_line = 0; - Reg5 long previous_line; - Reg6 long first_command_line = -1; + long this_line = 0; + long previous_line; + long first_command_line = -1; long fcl_line = -1; - Reg7 bool last_line_was_command = FALSE; - Reg8 bool this_is_a_command = FALSE; - Reg9 bool stars_last_line = FALSE; - Reg10 bool stars_this_line = FALSE; - Reg3 int indent; - Reg1 char *s; - Reg2 char *t; + bool last_line_was_command = FALSE; + bool this_is_a_command = FALSE; + bool stars_last_line = FALSE; + bool stars_this_line = FALSE; + int indent; + char *s; + char *t; char *indtmp = Nullch; char *oldtmp = Nullch; char *newtmp = Nullch; char *indname = Nullch; char *oldname = Nullch; char *newname = Nullch; - Reg11 int retval; + int retval; bool no_filearg = (filearg[0] == Nullch); ok_to_create_file = FALSE; @@ -371,9 +366,7 @@ intuit_diff_type() /* 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; +next_intuit_at(long file_pos, long file_line) { p_base = file_pos; p_bline = file_line; @@ -382,9 +375,7 @@ long file_line; /* Basically a verbose fseek() to the actual diff listing. */ void -skip_to(file_pos,file_line) -long file_pos; -long file_line; +skip_to(long file_pos, long file_line) { char *ret; @@ -406,7 +397,7 @@ long file_line; /* Make this a function for better debugging. */ static void -malformed () +malformed(void) { fatal3("malformed patch at line %ld: %s", p_input_line, buf); /* about as informative as "Syntax error" in C */ @@ -415,11 +406,11 @@ malformed () /* True if there is more of the current diff listing to process. */ bool -another_hunk() +another_hunk(void) { - Reg1 char *s; - Reg8 char *ret; - Reg2 int context = 0; + char *s; + char *ret; + int context = 0; while (p_end >= 0) { if (p_end == p_efake) @@ -436,18 +427,17 @@ another_hunk() long line_beginning = ftell(pfp); /* file pos of the current line */ LINENUM repl_beginning = 0; /* index of --- line */ - Reg4 LINENUM fillcnt = 0; /* #lines of missing ptrn or repl */ - Reg5 LINENUM fillsrc = 0; /* index of first line to copy */ - Reg6 LINENUM filldst = 0; /* index of first missing line */ + LINENUM fillcnt = 0; /* #lines of missing ptrn or repl */ + LINENUM fillsrc = 0; /* index of first line to copy */ + LINENUM filldst = 0; /* index of first missing line */ bool ptrn_spaces_eaten = FALSE; /* ptrn was slightly misformed */ - Reg9 bool repl_could_be_missing = TRUE; + bool repl_could_be_missing = TRUE; /* no + or ! lines in this hunk */ bool repl_missing = FALSE; /* we are now backtracking */ long repl_backtrack_position = 0; /* file pos of first repl line */ LINENUM repl_patch_line = 0; /* input line number for same */ - Reg7 LINENUM ptrn_copiable = 0; - /* # of copiable lines in ptrn */ + LINENUM ptrn_copiable = 0; /* # of copiable lines in ptrn */ ret = pgets(buf, sizeof buf, pfp); p_input_line++; @@ -750,8 +740,8 @@ another_hunk() else if (diff_type == UNI_DIFF) { long line_beginning = ftell(pfp); /* file pos of the current line */ - Reg4 LINENUM fillsrc; /* index of old lines */ - Reg5 LINENUM filldst; /* index of new lines */ + LINENUM fillsrc; /* index of old lines */ + LINENUM filldst; /* index of new lines */ char ch; ret = pgets(buf, sizeof buf, pfp); @@ -892,7 +882,7 @@ another_hunk() } else { /* normal diff--fake it up */ char hunk_type; - Reg3 int i; + int i; LINENUM min, max; long line_beginning = ftell(pfp); @@ -1012,14 +1002,11 @@ another_hunk() /* Input a line from the patch file, worrying about indentation. */ char * -pgets(bf,sz,fp) -char *bf; -int sz; -FILE *fp; +pgets(char *bf, int sz, FILE *fp) { char *ret = fgets(bf, sz, fp); - Reg1 char *s; - Reg2 int indent = 0; + char *s; + int indent = 0; if (p_indent && ret != Nullch) { for (s=buf; @@ -1038,15 +1025,15 @@ FILE *fp; /* Reverse the old and new portions of the current hunk. */ bool -pch_swap() +pch_swap(void) { char **tp_line; /* the text of the hunk */ short *tp_len; /* length of each line */ char *tp_char; /* +, -, and ! */ - Reg1 LINENUM i; - Reg2 LINENUM n; + LINENUM i; + LINENUM n; bool blankline = FALSE; - Reg3 char *s; + char *s; i = p_first; p_first = p_newfirst; @@ -1062,16 +1049,14 @@ pch_swap() p_char = Nullch; set_hunkmax(); if (p_line == Null(char**) || p_len == Null(short*) || p_char == Nullch) { -#ifndef lint if (p_line == Null(char**)) - free((char*)p_line); + free(p_line); p_line = tp_line; if (p_len == Null(short*)) - free((char*)p_len); + free(p_len); p_len = tp_len; -#endif if (p_char == Nullch) - free((char*)p_char); + free(p_char); p_char = tp_char; return FALSE; /* not enough memory to swap hunk! */ } @@ -1129,21 +1114,19 @@ pch_swap() i = p_ptrn_lines; p_ptrn_lines = p_repl_lines; p_repl_lines = i; -#ifndef lint if (tp_line == Null(char**)) - free((char*)tp_line); + free(tp_line); if (tp_len == Null(short*)) - free((char*)tp_len); -#endif + free(tp_len); if (tp_char == Nullch) - free((char*)tp_char); + free(tp_char); return TRUE; } /* Return the specified line position in the old file of the old context. */ LINENUM -pch_first() +pch_first(void) { return p_first; } @@ -1151,7 +1134,7 @@ pch_first() /* Return the number of lines of old context. */ LINENUM -pch_ptrn_lines() +pch_ptrn_lines(void) { return p_ptrn_lines; } @@ -1159,7 +1142,7 @@ pch_ptrn_lines() /* Return the probable line position in the new file of the first line. */ LINENUM -pch_newfirst() +pch_newfirst(void) { return p_newfirst; } @@ -1167,7 +1150,7 @@ pch_newfirst() /* Return the number of lines in the replacement text including context. */ LINENUM -pch_repl_lines() +pch_repl_lines(void) { return p_repl_lines; } @@ -1175,7 +1158,7 @@ pch_repl_lines() /* Return the number of lines in the whole hunk. */ LINENUM -pch_end() +pch_end(void) { return p_end; } @@ -1183,7 +1166,7 @@ pch_end() /* Return the number of context lines before the first changed line. */ LINENUM -pch_context() +pch_context(void) { return p_context; } @@ -1191,8 +1174,7 @@ pch_context() /* Return the length of a particular patch line. */ short -pch_line_len(line) -LINENUM line; +pch_line_len(LINENUM line) { return p_len[line]; } @@ -1200,8 +1182,7 @@ LINENUM line; /* Return the control character (+, -, *, !, etc) for a patch line. */ char -pch_char(line) -LINENUM line; +pch_char(LINENUM line) { return p_char[line]; } @@ -1209,8 +1190,7 @@ LINENUM line; /* Return a pointer to a particular patch line. */ char * -pfetch(line) -LINENUM line; +pfetch(LINENUM line) { return p_line[line]; } @@ -1218,7 +1198,7 @@ LINENUM line; /* Return where in the patch file this hunk began, for error messages. */ LINENUM -pch_hunk_beg() +pch_hunk_beg(void) { return p_hunk_beg; } @@ -1226,12 +1206,12 @@ pch_hunk_beg() /* Apply an ed script by feeding ed itself. */ void -do_ed_script() +do_ed_script(void) { - Reg1 char *t; - Reg2 long beginning_of_this_line; - Reg3 bool this_line_is_command = FALSE; - Reg4 FILE *pipefp = NULL; + char *t; + long beginning_of_this_line; + bool this_line_is_command = FALSE; + FILE *pipefp = NULL; if (!skip_rest_of_patch) { Unlink(TMPOUTNAME); diff --git a/usr.bin/patch/pch.h b/usr.bin/patch/pch.h index b457c9bbd51..f71a5b63ae9 100644 --- a/usr.bin/patch/pch.h +++ b/usr.bin/patch/pch.h @@ -1,26 +1,26 @@ -/* $NetBSD: pch.h,v 1.4 1998/02/22 13:33:50 christos Exp $ */ +/* $NetBSD: pch.h,v 1.5 2002/03/08 21:57:33 kristerw Exp $ */ EXT FILE *pfp INIT(Nullfp); /* patch file pointer */ -void re_patch __P((void)); -void open_patch_file __P((char *)); -void set_hunkmax __P((void)); -void grow_hunkmax __P((void)); -bool there_is_another_patch __P((void)); -int intuit_diff_type __P((void)); -void next_intuit_at __P((long, long)); -void skip_to __P((long, long)); -bool another_hunk __P((void)); -char *pgets __P((char *, int, FILE *)); -bool pch_swap __P((void)); -LINENUM pch_first __P((void)); -LINENUM pch_ptrn_lines __P((void)); -LINENUM pch_newfirst __P((void)); -LINENUM pch_repl_lines __P((void)); -LINENUM pch_end __P((void)); -LINENUM pch_context __P((void)); -short pch_line_len __P((LINENUM)); -char pch_char __P((LINENUM)); -char *pfetch __P((LINENUM)); -LINENUM pch_hunk_beg __P((void)); -void do_ed_script __P((void)); +void re_patch(void); +void open_patch_file(char *); +void set_hunkmax(void); +void grow_hunkmax(void); +bool there_is_another_patch(void); +int intuit_diff_type(void); +void next_intuit_at(long, long); +void skip_to(long, long); +bool another_hunk(void); +char *pgets(char *, int, FILE *); +bool pch_swap(void); +LINENUM pch_first(void); +LINENUM pch_ptrn_lines(void); +LINENUM pch_newfirst(void); +LINENUM pch_repl_lines(void); +LINENUM pch_end(void); +LINENUM pch_context(void); +short pch_line_len(LINENUM); +char pch_char(LINENUM); +char *pfetch(LINENUM); +LINENUM pch_hunk_beg(void); +void do_ed_script(void); diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c index df1214f9522..8925406308a 100644 --- a/usr.bin/patch/util.c +++ b/usr.bin/patch/util.c @@ -1,7 +1,7 @@ -/* $NetBSD: util.c,v 1.8 2000/10/11 14:46:15 is Exp $ */ +/* $NetBSD: util.c,v 1.9 2002/03/08 21:57:33 kristerw Exp $ */ #include <sys/cdefs.h> #ifndef lint -__RCSID("$NetBSD: util.c,v 1.8 2000/10/11 14:46:15 is Exp $"); +__RCSID("$NetBSD: util.c,v 1.9 2002/03/08 21:57:33 kristerw Exp $"); #endif /* not lint */ #include "EXTERN.h" @@ -22,13 +22,12 @@ __RCSID("$NetBSD: util.c,v 1.8 2000/10/11 14:46:15 is Exp $"); /* Rename a file, copying it if necessary. */ int -move_file(from,to) -char *from, *to; +move_file(char *from, char *to) { char bakname[512]; - Reg1 char *s; - Reg2 int i; - Reg3 int fromfd; + char *s; + int i; + int fromfd; /* to stdout? */ @@ -93,8 +92,8 @@ char *from, *to; /* Maybe `to' is a symlink into a different file system. Copying replaces the symlink with a file; using rename would be better. */ - Reg4 int tofd; - Reg5 int bakfd; + int tofd; + int bakfd; bakfd = creat(bakname, 0666); if (bakfd < 0) { @@ -118,7 +117,7 @@ char *from, *to; say3("Moving %s to %s.\n", from, to); #endif if (link(from, to) < 0) { /* different file system? */ - Reg4 int tofd; + int tofd; tofd = creat(to, 0666); if (tofd < 0) { @@ -142,12 +141,11 @@ char *from, *to; /* Copy a file. */ void -copy_file(from,to) -char *from, *to; +copy_file(char *from, char *to) { - Reg3 int tofd; - Reg2 int fromfd; - Reg1 int i; + int tofd; + int fromfd; + int i; tofd = creat(to, 0666); if (tofd < 0) @@ -165,11 +163,10 @@ char *from, *to; /* Allocate a unique area for a string. */ char * -savestr(s) -Reg1 char *s; +savestr(char *s) { - Reg3 char *rv; - Reg2 char *t; + char *rv; + char *t; if (!s) s = "Oops"; @@ -342,8 +339,7 @@ ask(va_alist) /* How to handle certain events when not in a critical region. */ void -set_signals(reset) -int reset; +set_signals(int reset) { #ifndef lint #ifdef VOIDSIG @@ -378,25 +374,21 @@ int reset; void ignore_signals() { -#ifndef lint Signal(SIGHUP, SIG_IGN); Signal(SIGINT, SIG_IGN); -#endif } /* Make sure we'll have the directories to create a file. If `striplast' is TRUE, ignore the last element of `filename'. */ void -makedirs(filename,striplast) -Reg1 char *filename; -bool striplast; +makedirs(char *filename, bool striplast) { char tmpbuf[256]; - Reg2 char *s = tmpbuf; + char *s = tmpbuf; char *dirv[20]; /* Point to the NULs between elements. */ - Reg3 int i; - Reg4 int dirvp = 0; /* Number of finished entries in dirv. */ + int i; + int dirvp = 0; /* Number of finished entries in dirv. */ /* Copy `filename' into `tmpbuf' with a NUL instead of a slash between the directories. */ @@ -436,14 +428,11 @@ bool striplast; /* Make filenames more reasonable. */ char * -fetchname(at,strip_leading,assume_exists) -char *at; -int strip_leading; -int assume_exists; +fetchname(char *at, int strip_leading, int assume_exists) { char *fullname; char *name; - Reg1 char *t; + char *t; char tmpbuf[200]; int sleading = strip_leading; diff --git a/usr.bin/patch/util.h b/usr.bin/patch/util.h index 4a2ec4c2e71..11bc0fc6e68 100644 --- a/usr.bin/patch/util.h +++ b/usr.bin/patch/util.h @@ -1,4 +1,4 @@ -/* $NetBSD: util.h,v 1.5 2000/10/11 14:46:15 is Exp $ */ +/* $NetBSD: util.h,v 1.6 2002/03/08 21:57:33 kristerw Exp $ */ /* and for those machine that can't handle a variable argument list */ @@ -68,18 +68,18 @@ EXT char serrbuf[BUFSIZ]; /* buffer for stderr */ -int move_file __P((char *, char *)); -void copy_file __P((char *, char *)); -char *savestr __P((Reg1 char *)); -void say __P((const char *, ...)) +int move_file(char *, char *); +void copy_file(char *, char *); +char *savestr(char *); +void say(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); -void fatal __P((const char *, ...)) +void fatal(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); -void pfatal __P((const char *, ...)) +void pfatal(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); -void ask __P((const char *, ...)) +void ask(const char *, ...) __attribute__((__format__(__printf__, 1, 2))); -void set_signals __P((int)); -void ignore_signals __P((void)); -void makedirs __P((Reg1 char *, bool)); -char *fetchname __P((char *, int, int)); +void set_signals(int); +void ignore_signals(void); +void makedirs(char *, bool); +char *fetchname(char *, int, int); |
