diff options
author | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-07-18 02:00:10 +0000 |
---|---|---|
committer | Theo de Raadt <deraadt@cvs.openbsd.org> | 2003-07-18 02:00:10 +0000 |
commit | e4bf8a1e512ab57e7982f83e364018d3da2a9c03 (patch) | |
tree | 3b1c0d8b6f9afab0e6de4686ea07935df5959792 /usr.bin | |
parent | dceb612346dde755a424932844f76893db4f89a1 (diff) |
remove junk; ok otto tedu
Diffstat (limited to 'usr.bin')
-rw-r--r-- | usr.bin/patch/ChangeLog | 274 | ||||
-rw-r--r-- | usr.bin/patch/Makefile | 4 | ||||
-rw-r--r-- | usr.bin/patch/backupfile.c | 30 | ||||
-rw-r--r-- | usr.bin/patch/common.h | 47 | ||||
-rw-r--r-- | usr.bin/patch/config.h | 103 | ||||
-rw-r--r-- | usr.bin/patch/inp.c | 118 | ||||
-rw-r--r-- | usr.bin/patch/inp.h | 12 | ||||
-rw-r--r-- | usr.bin/patch/malloc.c | 468 | ||||
-rw-r--r-- | usr.bin/patch/patch.1 | 4 | ||||
-rw-r--r-- | usr.bin/patch/patch.c | 270 | ||||
-rw-r--r-- | usr.bin/patch/patchlevel.h | 3 | ||||
-rw-r--r-- | usr.bin/patch/pch.c | 190 | ||||
-rw-r--r-- | usr.bin/patch/pch.h | 48 | ||||
-rw-r--r-- | usr.bin/patch/util.c | 205 | ||||
-rw-r--r-- | usr.bin/patch/util.h | 89 | ||||
-rw-r--r-- | usr.bin/patch/version.c | 27 | ||||
-rw-r--r-- | usr.bin/patch/version.h | 3 |
17 files changed, 445 insertions, 1450 deletions
diff --git a/usr.bin/patch/ChangeLog b/usr.bin/patch/ChangeLog deleted file mode 100644 index 7e628cf8bf0..00000000000 --- a/usr.bin/patch/ChangeLog +++ /dev/null @@ -1,274 +0,0 @@ -Tue Sep 15 00:36:15 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * patchlevel.h: PATCHLEVEL 12u8. - -Mon Sep 14 22:01:23 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * Makefile.SH: Add uninstall target. Simplify install target. - - * util.c (fatal, pfatal): Add some asterisks to make fatal - messages stand out more. - -Tue Aug 25 22:13:36 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * patch.c (main, get_some_switches), common.h, inp.c (plan_a, - plan_b), pch.c (there_is_another_aptch): Add -t option, - similar to -f. - -Mon Jul 27 11:27:07 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * inp.c (plan_a, util.c (fetchname): Use a macro to simplify code. - * common.h: Define SCCSDIFF and RCSDIFF. - * inp.c (plan_a): Use them to make sure it's safe to check out - the default RCS or SCCS version. - From Paul Eggert. - -Wed Jul 22 14:37:08 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * patch.man: Use the standard comment syntax -- '\" -- instead - of '''. - -Tue Jul 21 15:26:01 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * Configure: Add /etc /usr/lib /lib to pth. - -Mon Jul 20 14:10:32 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * util.h: Declare basename. - * inp.c (plan_a), util.c (fetchname): Use it to isolate the - leading path when testing for RCS and SCCS files. - -Sat Jul 11 18:03:26 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * Configure: Use the user's PATH and build pth from it. - -Fri Jul 10 16:03:23 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * Configure: Change cc -S to cc -c and tr '[ - ]' '[\012-\012]' - to tr ' ' '\012' for AIX 3.2. - From chip@tct.com (Chip Salzenberg). - - * util.c (makedirs): Only make the directories that don't exist. - From chip@tct.com (Chip Salzenberg). - -Wed Jul 8 01:21:15 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * util.c (fatal, pfatal): Print "patch: " before message. - * pch.c, inp.c, patch.c, util.c: Remove "patch: " from the - callers that had it. - - * util.c (pfatal): New function. - * util.h: Declare it and pfatal[1-4] macros. - * various files: Use it instead of fatal where appropriate. - - * Configure: Make /usr/local/man/man1 the first choice for the - man pages. - - * patch.c (main): Open ofp after checking for ed script. - Close ofp and rejfp before trying plan B. - From epang@sfu.ca (Eugene Pang). - - * backupfile.h: Declare get_version. - - * Move decls of rindex and popen to common.h. - - * common.h (myuid): New variable. - * patch.c (main): Initialize it. - * inp.c (myuid): Function removed. - (plan_a): Use the variable, not the function. - - * patch.c: Reinstate -E option. - -Tue Jul 7 23:19:28 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * inp.c (myuid): New function. - (plan_a): Call it. Optimize stat calls. Be smarter about - detecting checked out RCS and SCCS files. - From Paul Eggert (eggert@twinsun.com). - - * inp.c, util.c, patch.c: Don't bother checking for stat() > 0. - -Mon Jul 6 13:01:52 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * version.c (version): Don't print the RCS stuff, since we're - not updating it regularly. - - * patch.c (get_some_switches): Make the usage message more accurate. - - * patchlevel.h: PATCHLEVEL 12u7. - - * Makefile.SH (dist): New target. - Makedist: File removed. - - * inp.c (plan_a): Check whether the user can write to the - file, not whether anyone can write to the file. - -Sat Jul 4 00:06:58 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * inp.c (plan_a): Try to check out read-only files from RCS or SCCS. - - * util.c (move_file): If backing up by linking fails, try copying. - From cek@sdc.boeing.com (Conrad Kimball). - - * patch.c (get_some_switches): Eliminate -E option; always - remove empty output files. - - * util.c (fetchname): Only undo slash removal for relative - paths if -p was not given. - - * Makefile.sh: Add mostlyclean target. - -Fri Jul 3 23:48:14 1992 David J. MacKenzie (djm@nutrimat.gnu.ai.mit.edu) - - * util.c (fetchname): Accept whitespace between `Index:' and filename. - Also plug a small memory leak for diffs against /dev/null. - From eggert@twinsun.com (Paul Eggert). - - * common.h: Don't define TRUE and FALSE if already defined. - From phk@data.fls.dk (Poul-Henning Kamp). - -Wed Apr 29 10:19:33 1992 David J. MacKenzie (djm@churchy.gnu.ai.mit.edu) - - * backupfile.c (get_version): Exit if given a bad backup type. - -Fri Mar 27 09:57:14 1992 Karl Berry (karl at hayley) - - * common.h (S_ISDIR, S_ISREG): define these. - * inp.c (plan_a): use S_ISREG, not S_IFREG. - * util.c (fetchname): use S_ISDIR, not S_IFDIR. - -Mon Mar 16 14:10:42 1992 David J. MacKenzie (djm@wookumz.gnu.ai.mit.edu) - - * patchlevel.h: PATCHLEVEL 12u6. - -Sat Mar 14 13:13:29 1992 David J. MacKenzie (djm at frob.eng.umd.edu) - - * Configure, config.h.SH: Check for directory header and unistd.h. - - * patch.c (main): If -E was given and output file is empty after - patching, remove it. - (get_some_switches): Recognize -E option. - - * patch.c (copy_till): Make garbled output an error, not a warning - that doesn't change the exit status. - - * common.h: Protect against system declarations of malloc and realloc. - - * Makedist: Add backupfile.[ch]. - - * Configure: Look for C library where NeXT and SVR4 put it. - Look in /usr/ucb after /bin and /usr/bin for utilities, - and look in /usr/ccs/bin, to make SVR4 happier. - Recognize m68k predefine. - - * util.c (fetchname): Test of stat return value was backward. - From csss@scheme.cs.ubc.ca. - - * version.c (version): Exit with status 0, not 1. - - * Makefile.SH: Add backupfile.[cho]. - * patch.c (main): Initialize backup file generation. - (get_some_switches): Add -V option. - * common.h, util,c, patch.c: Replace origext with simple_backup_suffix. - * util.c (move_file): Use find_backup_file_name. - -Tue Dec 3 11:27:16 1991 David J. MacKenzie (djm at wookumz.gnu.ai.mit.edu) - - * patchlevel.h: PATCHLEVEL 12u5. - - * Makefile.SH: Change clean, distclean, and realclean targets a - little so they agree with the GNU coding standards. - Add Makefile to addedbyconf, so distclean removes it. - - * Configure: Recognize Domain/OS C library in /lib/libc. - From mmuegel@mot.com (Michael S. Muegel). - - * pch.c: Fixes from Wayne Davison: - Patch now accepts no-context context diffs that are - specified with an assumed one line hunk (e.g. "*** 10 ****"). - Fixed a bug in both context and unified diff processing that would - put a zero-context hunk in the wrong place (one line too soon). - Fixed a minor problem with p_max in unified diffs where it would - set p_max to hunkmax unnecessarily (the only adverse effect was to - not supply empty lines at eof by assuming they were truncated). - -Tue Jul 2 03:25:51 1991 David J. MacKenzie (djm at geech.gnu.ai.mit.edu) - - * Configure: Check for signal declaration in - /usr/include/sys/signal.h as well as /usr/include/signal.h. - - * Configure, common.h, config.h.SH: Comment out the sprintf - declaration and tests to determine its return value type. It - conflicts with ANSI C systems' prototypes in stdio.h and the - return value of sprintf is never used anyway -- it's always cast - to void. - -Thu Jun 27 13:05:32 1991 David J. MacKenzie (djm at churchy.gnu.ai.mit.edu) - - * patchlevel.h: PATCHLEVEL 12u4. - -Thu Feb 21 15:18:14 1991 David J. MacKenzie (djm at geech.ai.mit.edu) - - * pch.c (another_hunk): Fix off by 1 error. From - iverson@xstor.com (Tim Iverson). - -Sun Jan 20 20:18:58 1991 David J. MacKenzie (djm at geech.ai.mit.edu) - - * Makefile.SH (all): Don't make a dummy `all' file. - - * patchlevel.h: PATCHLEVEL 12u3. - - * patch.c (nextarg): New function. - (get_some_switches): Use it, to prevent dereferencing a null - pointer if an option that takes an arg is not given one (is last - on the command line). From Paul Eggert. - - * pch.c (another_hunk): Fix from Wayne Davison to recognize - single-line hunks in unified diffs (with a single line number - instead of a range). - - * inp.c (rev_in_string): Don't use `s' before defining it. From - Wayne Davison. - -Mon Jan 7 06:25:11 1991 David J. MacKenzie (djm at geech.ai.mit.edu) - - * patchlevel.h: PATCHLEVEL 12u2. - - * pch.c (intuit_diff_type): Recognize `+++' in diff headers, for - unified diff format. From unidiff patch 1. - -Mon Dec 3 00:14:25 1990 David J. MacKenzie (djm at albert.ai.mit.edu) - - * patch.c (get_some_switches): Make the usage message more - informative. - -Sun Dec 2 23:20:18 1990 David J. MacKenzie (djm at albert.ai.mit.edu) - - * Configure: When checking for C preprocessor, look for 'abc.*xyz' - instead of 'abc.xyz', so ANSI C preprocessors work. - - * Apply fix for -D from ksb@mentor.cc.purdue.edu (Kevin Braunsdorf). - - * Apply unidiff patches from davison@dri.com (Wayne Davison). - -Wed Mar 7 23:47:25 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * pch.c: Call malformed instead of goto malformed - (just allows easier debugging). - -Tue Jan 23 21:27:00 1990 Jim Kingdon (kingdon at pogo.ai.mit.edu) - - * common.h (TMP*NAME): Make these char *, not char []. - patch.c (main): Use TMPDIR (if present) to set TMP*NAME. - common.h: Declare getenv. - -Sun Dec 17 17:29:48 1989 Jim Kingdon (kingdon at hobbes.ai.mit.edu) - - * patch.c (reverse_flag_specified): New variable. - (get_some_switches, reinitialize_almost_everything): Use it. - -Local Variables: -mode: indented-text -left-margin: 8 -version-control: never -end: diff --git a/usr.bin/patch/Makefile b/usr.bin/patch/Makefile index 2d47f3cb57e..9c54a925f50 100644 --- a/usr.bin/patch/Makefile +++ b/usr.bin/patch/Makefile @@ -1,6 +1,6 @@ -# $OpenBSD: Makefile,v 1.2 1996/06/10 11:21:25 niklas Exp $ +# $OpenBSD: Makefile,v 1.3 2003/07/18 02:00:09 deraadt Exp $ PROG= patch -SRCS= patch.c pch.c inp.c version.c util.c backupfile.c +SRCS= patch.c pch.c inp.c util.c backupfile.c .include <bsd.prog.mk> diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c index 58561058848..308bed34c42 100644 --- a/usr.bin/patch/backupfile.c +++ b/usr.bin/patch/backupfile.c @@ -1,4 +1,4 @@ -/* $OpenBSD: backupfile.c,v 1.9 2003/04/06 04:14:09 millert Exp $ */ +/* $OpenBSD: backupfile.c,v 1.10 2003/07/18 02:00:09 deraadt Exp $ */ /* backupfile.c -- make Emacs style backup file names Copyright (C) 1990 Free Software Foundation, Inc. @@ -14,7 +14,7 @@ Some algorithms adapted from GNU Emacs. */ #ifndef lint -static char rcsid[] = "$OpenBSD: backupfile.c,v 1.9 2003/04/06 04:14:09 millert Exp $"; +static char rcsid[] = "$OpenBSD: backupfile.c,v 1.10 2003/07/18 02:00:09 deraadt Exp $"; #endif /* not lint */ #include <stdio.h> @@ -54,9 +54,7 @@ static char rcsid[] = "$OpenBSD: backupfile.c,v 1.9 2003/04/06 04:14:09 millert #define ISDIGIT(c) (isascii (c) && isdigit (c)) #endif -#if defined (HAVE_UNISTD_H) #include <unistd.h> -#endif #if defined (_POSIX_VERSION) /* POSIX does not require that the d_ino field be present, and some @@ -73,11 +71,13 @@ enum backup_type backup_type = none; to numbered) backup file name. */ char *simple_backup_suffix = "~"; -static char *concat (); -char *find_backup_file_name (); -static char *make_version_name (); -static int max_backup_version (); -static int version_number (); +static char *concat(char *, char *); +char *find_backup_file_name(char *); +static char *make_version_name(char *, int); +static int max_backup_version(char *, char *); +static int version_number(char *, char *, int); +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, @@ -125,11 +125,11 @@ max_backup_version (file, dir) int highest_version; int this_version; int file_name_length; - + dirp = opendir (dir); if (!dirp) return 0; - + highest_version = 0; file_name_length = strlen (file); @@ -137,7 +137,7 @@ max_backup_version (file, dir) { if (!REAL_DIR_ENTRY (dp) || NLENGTH (dp) <= file_name_length) continue; - + this_version = version_number (file, dp->d_name, file_name_length); if (this_version > highest_version) highest_version = this_version; @@ -173,7 +173,7 @@ version_number (base, backup, base_length) { int version; char *p; - + version = 0; if (!strncmp (base, backup, base_length) && ISDIGIT (backup[base_length])) { @@ -213,9 +213,9 @@ argmatch (arg, optlist) int arglen; /* Length of ARG. */ int matchind = -1; /* Index of first nonexact match. */ int ambiguous = 0; /* If nonzero, multiple nonexact match(es). */ - + arglen = strlen (arg); - + /* Test all elements for either exact match or abbreviated matches. */ for (i = 0; optlist[i]; i++) { diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h index ff7b3934ab0..7da6a168f2f 100644 --- a/usr.bin/patch/common.h +++ b/usr.bin/patch/common.h @@ -1,27 +1,11 @@ -/* $OpenBSD: common.h,v 1.12 2003/04/08 01:54:56 deraadt Exp $ */ +/* $OpenBSD: common.h,v 1.13 2003/07/18 02:00:09 deraadt Exp $ */ #define DEBUGGING -#define VOIDUSED 7 #include "config.h" /* shut lint up about the following when return value ignored */ -#define Signal (void)signal -#define Unlink (void)unlink -#define Lseek (void)lseek -#define Fseek (void)fseek -#define Fstat (void)fstat -#define Pclose (void)pclose -#define Close (void)close -#define Fclose (void)fclose -#define Fflush (void)fflush -#define Snprintf (void)snprintf - -/* NeXT declares malloc and realloc incompatibly from us in some of - these files. Temporarily redefine them to prevent errors. */ -#define malloc system_malloc -#define realloc system_realloc #include <stdio.h> #include <string.h> #include <assert.h> @@ -34,9 +18,9 @@ #include <signal.h> #include <stdlib.h> #include <unistd.h> +#include <stdarg.h> #include <libgen.h> -#undef malloc -#undef realloc +#include <errno.h> /* constants */ @@ -63,13 +47,8 @@ #define CHECKOUT "co -l %s" #define RCSDIFF "rcsdiff %s > /dev/null" -#ifdef FLEXFILENAMES #define ORIGEXT ".orig" #define REJEXT ".rej" -#else -#define ORIGEXT "~" -#define REJEXT "#" -#endif /* handy definitions */ @@ -157,26 +136,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 - -FILE *popen(); -char *malloc(); -char *realloc(); -long atol(); -char *getenv(); -char *strrchr(); -int mkstemp(); -#if 0 /* This can cause a prototype conflict. */ -#ifdef CHARSPRINTF -char *snprintf(); -#else -int snprintf(); -#endif -#endif - #if !defined(S_ISDIR) && defined(S_IFDIR) #define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) #endif diff --git a/usr.bin/patch/config.h b/usr.bin/patch/config.h index 97a5510f744..764d7e04070 100644 --- a/usr.bin/patch/config.h +++ b/usr.bin/patch/config.h @@ -1,4 +1,4 @@ -/* $OpenBSD: config.h,v 1.3 1997/09/22 05:45:26 millert Exp $ */ +/* $OpenBSD: config.h,v 1.4 2003/07/18 02:00:09 deraadt Exp $ */ /* config.h * This file was produced by running the config.h.SH script, which @@ -12,20 +12,6 @@ */ -/* EUNICE: - * This symbol, if defined, indicates that the program is being compiled - * under the EUNICE package under VMS. The program will need to handle - * things like files that don't go away the first time you unlink them, - * due to version numbering. It will also need to compensate for lack - * of a respectable link() command. - */ -/* VMS: - * This symbol, if defined, indicates that the program is running under - * VMS. It is currently only set in conjunction with the EUNICE symbol. - */ -#/*undef EUNICE /**/ -#/*undef VMS /**/ - /* CPPSTDIN: * This symbol contains the first part of the string which will invoke * the C preprocessor on the standard input and produce to standard @@ -40,95 +26,8 @@ #define CPPSTDIN "/usr/bin/cpp" #define CPPMINUS "" -/* CHARSPRINTF: - * This symbol is defined if this system declares "char *sprintf()" in - * stdio.h. The trend seems to be to declare it as "int sprintf()". It - * is up to the package author to declare sprintf correctly based on the - * symbol. - */ -/* # CHARSPRINTF /**/ - -/* FLEXFILENAMES: - * This symbol, if defined, indicates that the system supports filenames - * longer than 14 characters. - */ -#define FLEXFILENAMES /**/ - -/* index: - * This preprocessor symbol is defined, along with rindex, if the system - * uses the strchr and strrchr routines instead. - */ -/* rindex: - * This preprocessor symbol is defined, along with index, if the system - * uses the strchr and strrchr routines instead. - */ -#/*undef index strchr /* cultural */ -#/*undef rindex strrchr /* differences? */ - -/* VOIDSIG: - * This symbol is defined if this system declares "void (*signal())()" in - * signal.h. The old way was to declare it as "int (*signal())()". It - * is up to the package author to declare things correctly based on the - * symbol. - */ -#define VOIDSIG /**/ - /* DIRHEADER: * This definition indicates which directory library header to use. */ #define DIRENT -/* HAVE_UNISTD_H: - * 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 51f29033b0c..a4cd46bc28b 100644 --- a/usr.bin/patch/inp.c +++ b/usr.bin/patch/inp.c @@ -1,7 +1,7 @@ -/* $OpenBSD: inp.c,v 1.10 2003/07/16 16:06:53 otto Exp $ */ +/* $OpenBSD: inp.c,v 1.11 2003/07/18 02:00:09 deraadt Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: inp.c,v 1.10 2003/07/16 16:06:53 otto Exp $"; +static char rcsid[] = "$OpenBSD: inp.c,v 1.11 2003/07/18 02:00:09 deraadt Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -25,10 +25,12 @@ 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 */ +void re_input(void); + /* New patch--prepare to edit another file. */ void -re_input() +re_input(void) { if (using_plan_a) { i_size = 0; @@ -43,7 +45,7 @@ re_input() } else { using_plan_a = TRUE; /* maybe the next one is smaller */ - Close(tifd); + close(tifd); tifd = -1; free(tibuf[0]); free(tibuf[1]); @@ -62,7 +64,7 @@ char *filename; if (!plan_a(filename)) plan_b(filename); if (verbose) { - say3("Patching file %s using Plan %s...\n", filename, + say("Patching file %s using Plan %s...\n", filename, (using_plan_a ? "A" : "B") ); } } @@ -74,8 +76,8 @@ plan_a(filename) char *filename; { int ifd, statfailed; - Reg1 char *s; - Reg2 LINENUM iline; + char *s; + LINENUM iline; char lbuf[MAXLINELEN]; if (!filename || *filename == '\0') @@ -84,19 +86,19 @@ char *filename; statfailed = stat(filename, &filestat); if (statfailed && ok_to_create_file) { if (verbose) - say2("(Creating file %s...)\n",filename); + say("(Creating file %s...)\n",filename); /* in check_patch case, we still display `Creating file' even though we're not. The rule is that -C should be as similar to normal patch behavior as possible */ - if (check_only) + if (check_only) return TRUE; makedirs(filename, TRUE); close(creat(filename, 0666)); statfailed = stat(filename, &filestat); } if (statfailed && check_only) - fatal2("%s not found, -C mode, can't probe further\n", filename); + fatal("%s not found, -C mode, can't probe further\n", filename); /* For nonexistent or read-only files, look for RCS or SCCS versions. */ if (statfailed /* No one can write to it. */ @@ -113,46 +115,46 @@ char *filename; /* Leave room in lbuf for the diff command. */ s = lbuf + 20; -#define try(f, a1, a2, a3) (Snprintf(s, sizeof lbuf - 20, f, a1, a2, a3), stat(s, &cstat) == 0) +#define try(f, a1, a2, a3) (snprintf(s, sizeof lbuf - 20, f, a1, a2, a3), stat(s, &cstat) == 0) if ( try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) || try("%s/RCS/%s%s", filedir, filebase, "") || try( "%s/%s%s", filedir, filebase, RCSSUFFIX)) { - Snprintf(buf, sizeof buf, CHECKOUT, filename); - Snprintf(lbuf, sizeof lbuf, RCSDIFF, filename); + snprintf(buf, sizeof buf, CHECKOUT, filename); + snprintf(lbuf, sizeof lbuf, RCSDIFF, filename); cs = "RCS"; } else if ( try("%s/SCCS/%s%s", filedir, SCCSPREFIX, filebase) || try( "%s/%s%s", filedir, SCCSPREFIX, filebase)) { - Snprintf(buf, sizeof buf, GET, s); - Snprintf(lbuf, sizeof lbuf, SCCSDIFF, s, filename); + snprintf(buf, sizeof buf, GET, s); + snprintf(lbuf, sizeof lbuf, SCCSDIFF, s, filename); cs = "SCCS"; } else if (statfailed) - fatal2("can't find %s\n", filename); + fatal("can't find %s\n", filename); /* else we can't write to it but it's not under a version control system, so just proceed. */ if (cs) { if (!statfailed) { if ((filestat.st_mode & 0222) != 0) /* The owner can write to it. */ - fatal3("file %s seems to be locked by somebody else under %s\n", + fatal("file %s seems to be locked by somebody else under %s\n", filename, cs); /* It might be checked out unlocked. See if it's safe to check out the default version locked. */ if (verbose) - say3("Comparing file %s to default %s version...\n", + say("Comparing file %s to default %s version...\n", filename, cs); if (system(lbuf)) - fatal3("can't check out file %s: differs from default %s version\n", + fatal("can't check out file %s: differs from default %s version\n", filename, cs); } if (verbose) - say3("Checking out file %s from %s...\n", filename, cs); + say("Checking out file %s from %s...\n", filename, cs); if (system(buf) || stat(filename, &filestat)) - fatal3("can't check out file %s from %s\n", filename, cs); + fatal("can't check out file %s from %s\n", filename, cs); } } filemode = filestat.st_mode; if (!S_ISREG(filemode)) - fatal2("%s is not a normal file--can't patch\n", filename); + fatal("%s is not a normal file--can't patch\n", filename); i_size = filestat.st_size; if (out_of_mem) { set_hunkmax(); /* make sure dynamic arrays are allocated */ @@ -168,15 +170,15 @@ char *filename; if (i_womp == Nullch) return FALSE; if ((ifd = open(filename, O_RDONLY)) < 0) - pfatal2("can't open file %s", filename); + pfatal("can't open file %s", filename); #ifndef lint if (read(ifd, i_womp, (size_t)i_size) != i_size) { - Close(ifd); /* probably means i_size > 15 or 16 bits worth */ + 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); + close(ifd); if (i_size && i_womp[i_size-1] != '\n') i_womp[i_size++] = '\n'; i_womp[i_size] = '\0'; @@ -197,7 +199,7 @@ char *filename; free((char *)i_womp); return FALSE; } - + /* now scan the buffer and build pointer array */ iline = 1; @@ -210,28 +212,28 @@ char *filename; /* now check for revision, if any */ - if (revision != Nullch) { + if (revision != Nullch) { if (!rev_in_string(i_womp)) { if (force) { if (verbose) - say2( + say( "Warning: this file doesn't appear to be the %s version--patching anyway.\n", revision); } else if (batch) { - fatal2( + fatal( "this file doesn't appear to be the %s version--aborting.\n", revision); } else { - ask2( + ask( "This file doesn't appear to be the %s version--patch anyway? [n] ", revision); if (*buf != 'y') - fatal1("aborted\n"); + fatal("aborted\n"); } } else if (verbose) - say2("Good. This file appears to be the %s version.\n", + say("Good. This file appears to be the %s version.\n", revision); } return TRUE; /* plan a will work */ @@ -243,17 +245,17 @@ void plan_b(filename) 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) - pfatal2("can't open file %s", filename); + pfatal("can't open file %s", filename); (void) unlink(TMPINNAME); if ((tifd = open(TMPINNAME, O_EXCL|O_CREAT|O_WRONLY, 0666)) < 0) - pfatal2("can't open file %s", TMPINNAME); + pfatal("can't open file %s", TMPINNAME); while (fgets(buf, sizeof buf, ifp) != Nullch) { if (revision != Nullch && !found_revision && rev_in_string(buf)) found_revision = TRUE; @@ -264,52 +266,52 @@ char *filename; if (!found_revision) { if (force) { if (verbose) - say2( + say( "Warning: this file doesn't appear to be the %s version--patching anyway.\n", revision); } else if (batch) { - fatal2( + fatal( "this file doesn't appear to be the %s version--aborting.\n", revision); } else { - ask2( + ask( "This file doesn't appear to be the %s version--patch anyway? [n] ", revision); if (*buf != 'y') - fatal1("aborted\n"); + fatal("aborted\n"); } } else if (verbose) - say2("Good. This file appears to be the %s version.\n", + say("Good. This file appears to be the %s version.\n", revision); } - Fseek(ifp, 0L, 0); /* rewind file */ + fseek(ifp, 0L, 0); /* rewind file */ lines_per_buf = BUFFERSIZE / maxlen; tireclen = maxlen; tibuf[0] = malloc((MEM)(BUFFERSIZE + 1)); if (tibuf[0] == Nullch) - fatal1("out of memory\n"); + fatal("out of memory\n"); tibuf[1] = malloc((MEM)(BUFFERSIZE + 1)); if (tibuf[1] == Nullch) - fatal1("out of memory\n"); + fatal("out of memory\n"); for (i=1; ; i++) { if (! (i % lines_per_buf)) /* new block */ if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) - pfatal1("can't write temp file"); + pfatal("can't write temp file"); if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp) == Nullch) { input_lines = i - 1; if (i % lines_per_buf) if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE) - pfatal1("can't write temp file"); + pfatal("can't write temp file"); break; } } - Fclose(ifp); - Close(tifd); + fclose(ifp); + close(tifd); if ((tifd = open(TMPINNAME, O_RDONLY)) < 0) { - pfatal2("can't reopen file %s", TMPINNAME); + pfatal("can't reopen file %s", TMPINNAME); } } @@ -317,11 +319,11 @@ char *filename; char * ifetch(line,whichbuf) -Reg1 LINENUM line; +LINENUM line; int whichbuf; /* ignored when file in memory */ { if (line < 1 || line > input_lines) { - say2("No such line %ld in input file, ignoring\n", line); + say("No such line %ld in input file, ignoring\n", line); return NULL; } if (using_plan_a) @@ -337,10 +339,10 @@ int whichbuf; /* ignored when file in memory */ else { tiline[whichbuf] = baseline; #ifndef lint /* complains of long accuracy */ - Lseek(tifd, (off_t)(baseline / lines_per_buf * BUFFERSIZE), 0); + lseek(tifd, (off_t)(baseline / lines_per_buf * BUFFERSIZE), 0); #endif if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0) - pfatal2("error reading tmp file %s", TMPINNAME); + pfatal("error reading tmp file %s", TMPINNAME); } return tibuf[whichbuf] + (tireclen*offline); } @@ -352,8 +354,8 @@ bool rev_in_string(string) char *string; { - Reg1 char *s; - Reg2 int patlen; + char *s; + int patlen; if (revision == Nullch) return TRUE; @@ -361,7 +363,7 @@ char *string; if (strnEQ(string,revision,patlen) && isspace(string[patlen])) return TRUE; for (s = string; *s; s++) { - if (isspace(*s) && strnEQ(s+1, revision, patlen) && + if (isspace(*s) && strnEQ(s+1, revision, patlen) && isspace(s[patlen+1] )) { return TRUE; } diff --git a/usr.bin/patch/inp.h b/usr.bin/patch/inp.h index 1d0ed96ba88..0b4e09d3647 100644 --- a/usr.bin/patch/inp.h +++ b/usr.bin/patch/inp.h @@ -1,12 +1,12 @@ -/* $OpenBSD: inp.h,v 1.2 1996/06/10 11:21:29 niklas Exp $ */ +/* $OpenBSD: inp.h,v 1.3 2003/07/18 02:00:09 deraadt 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 */ -bool rev_in_string(); -void scan_input(); -bool plan_a(); /* returns false if insufficient memory */ -void plan_b(); -char *ifetch(); +bool rev_in_string(char *); +void scan_input(char *); +bool plan_a(char *); /* returns false if insufficient memory */ +void plan_b(char *); +char *ifetch(LINENUM, int); diff --git a/usr.bin/patch/malloc.c b/usr.bin/patch/malloc.c deleted file mode 100644 index 352eaa04f5b..00000000000 --- a/usr.bin/patch/malloc.c +++ /dev/null @@ -1,468 +0,0 @@ -/* * $OpenBSD: malloc.c,v 1.3 2001/11/19 19:02:15 mpech Exp $*/ -/* - * from: @(#)nmalloc.c 1 (Caltech) 2/21/82 - * - * U of M Modified: 20 Jun 1983 ACT: strange hacks for Emacs - * - * Nov 1983, Mike@BRL, Added support for 4.1C/4.2 BSD. - * - * This is a very fast storage allocator. It allocates blocks of a small - * number of different sizes, and keeps free lists of each size. Blocks - * that don't exactly fit are passed up to the next larger size. In this - * implementation, the available sizes are (2^n)-4 (or -16) bytes long. - * This is designed for use in a program that uses vast quantities of - * memory, but bombs when it runs out. To make it a little better, it - * warns the user when he starts to get near the end. - * - * June 84, ACT: modified rcheck code to check the range given to malloc, - * rather than the range determined by the 2-power used. - * - * Jan 85, RMS: calls malloc_warning to issue warning on nearly full. - * No longer Emacs-specific; can serve as all-purpose malloc for GNU. - * You should call malloc_init to reinitialize after loading dumped Emacs. - * Call malloc_stats to get info on memory stats if MSTATS turned on. - * realloc knows how to return same block given, just changing its size, - * if the power of 2 is correct. - */ - -/* - * nextf[i] is the pointer to the next free block of size 2^(i+3). The - * smallest allocatable block is 8 bytes. The overhead information will - * go in the first int of the block, and the returned pointer will point - * to the second. - * -#ifdef MSTATS - * nmalloc[i] is the difference between the number of mallocs and frees - * for a given block size. -#endif /* MSTATS */ - */ - -#define ISALLOC ((char) 0xf7) /* magic byte that implies allocation */ -#define ISFREE ((char) 0x54) /* magic byte that implies free block */ - /* this is for error checking only */ - -extern char etext; - -/* end of the program; can be changed by calling init_malloc */ -static char *endofpure = &etext; - -#ifdef MSTATS -static int nmalloc[30]; -static int nmal, nfre; -#endif /* MSTATS */ - -/* If range checking is not turned on, all we have is a flag indicating - whether memory is allocated, an index in nextf[], and a size field; to - realloc() memory we copy either size bytes or 1<<(index+3) bytes depending - on whether the former can hold the exact size (given the value of - 'index'). If range checking is on, we always need to know how much space - is allocated, so the 'size' field is never used. */ - -struct mhead { - char mh_alloc; /* ISALLOC or ISFREE */ - char mh_index; /* index in nextf[] */ -/* Remainder are valid only when block is allocated */ - unsigned short mh_size; /* size, if < 0x10000 */ -#ifdef rcheck - unsigned mh_nbytes; /* number of bytes allocated */ - int mh_magic4; /* should be == MAGIC4 */ -#endif /* rcheck */ - }; - -/* Access free-list pointer of a block. - It is stored at block + 4. - This is not a field in the mhead structure - because we want sizeof (struct mhead) - to describe the overhead for when the block is in use, - and we do not want the free-list pointer to count in that. */ - -#define CHAIN(a) \ - (*(struct mhead **) (sizeof (char *) + (char *) (a))) - -#ifdef rcheck - -/* To implement range checking, we write magic values in at the beginning and - end of each allocated block, and make sure they are undisturbed whenever a - free or a realloc occurs. */ -/* Written in each of the 4 bytes following the block's real space */ -#define MAGIC1 0x55 -/* Written in the 4 bytes before the block's real space */ -#define MAGIC4 0x55555555 -#define ASSERT(p) if (!(p)) botch("p"); else -static -botch(s) - char *s; -{ - - printf("assertion botched: %s\n", s); - abort(); -} -#define EXTRA 4 /* 4 bytes extra for MAGIC1s */ -#else -#define ASSERT(p) -#define EXTRA 0 -#endif /* rcheck */ - -/* nextf[i] is free list of blocks of size 2**(i + 3) */ - -static struct mhead *nextf[30]; - -#ifdef M_WARN -/* Number of bytes of writable memory we can expect to be able to get */ -static int lim_data; -/* Level number of warnings already issued. - 0 -- no warnings issued. - 1 -- 75% warning already issued. - 2 -- 85% warning already issued. -*/ -static int warnlevel; -#endif /* M_WARN */ - -/* nonzero once initial bunch of free blocks made */ -static int gotpool; - -/* Cause reinitialization based on job parameters; - also declare where the end of pure storage is. */ -malloc_init (end) - char *end; { - endofpure = end; -#ifdef M_WARN - lim_data = 0; - warnlevel = 0; -#endif /* M_WARN */ - } - -static -morecore (nu) /* ask system for more memory */ - int nu; { /* size index to get more of */ - char *sbrk (); - char *cp; - int nblks; - int siz; - -#ifdef M_WARN -#ifndef BSD42 -#ifdef USG - extern long ulimit (); - if (lim_data == 0) /* find out how much we can get */ - lim_data = ulimit (3, 0) - TEXT_START; -#else /*HMS: was endif */ - if (lim_data == 0) /* find out how much we can get */ - lim_data = vlimit (LIM_DATA, -1); -#endif /* USG */ /HMS:* was not here */ -#else - if (lim_data == 0) { - struct rlimit XXrlimit; - - getrlimit (RLIMIT_DATA, &XXrlimit); - lim_data = XXrlimit.rlim_cur;} /* soft limit */ -#endif /* BSD42 */ -#endif /* M_WARN */ - - /* On initial startup, get two blocks of each size up to 1k bytes */ - if (!gotpool) - getpool (), getpool (), gotpool = 1; - - /* Find current end of memory and issue warning if getting near max */ - - cp = sbrk (0); - siz = cp - endofpure; -#ifdef M_WARN - switch (warnlevel) { - case 0: - if (siz > (lim_data / 4) * 3) { - warnlevel++; - malloc_warning ("Warning: past 75% of memory limit");} - break; - case 1: - if (siz > (lim_data / 20) * 17) { - warnlevel++; - malloc_warning ("Warning: past 85% of memory limit");} - break; - case 2: - if (siz > (lim_data / 20) * 19) { - warnlevel++; - malloc_warning ("Warning: past 95% of memory limit");} - break;} -#endif /* M_WARN */ - - if ((int) cp & 0x3ff) /* land on 1K boundaries */ - sbrk (1024 - ((int) cp & 0x3ff)); - - /* Take at least 2k, and figure out how many blocks of the desired size we're about to get */ - nblks = 1; - if ((siz = nu) < 8) - nblks = 1 << ((siz = 8) - nu); - - if ((cp = sbrk (1 << (siz + 3))) == (char *) -1) - return; /* no more room! */ - if ((int) cp & 7) { /* shouldn't happen, but just in case */ - cp = (char *) (((int) cp + 8) & ~7); - nblks--;} - - /* save new header and link the nblks blocks together */ - nextf[nu] = (struct mhead *) cp; - siz = 1 << (nu + 3); - while (1) { - ((struct mhead *) cp) -> mh_alloc = ISFREE; - ((struct mhead *) cp) -> mh_index = nu; - if (--nblks <= 0) break; - CHAIN ((struct mhead *) cp) = (struct mhead *) (cp + siz); - cp += siz;} -/* CHAIN ((struct mhead *) cp) = 0; /* since sbrk() returns cleared core, this is already set */ - } - -static -getpool () { - int nu; - char *cp = sbrk (0); - - if ((int) cp & 0x3ff) /* land on 1K boundaries */ - sbrk (1024 - ((int) cp & 0x3ff)); - - /* Get 2k of storage */ - - cp = sbrk (04000); - if (cp == (char *) -1) - return; - - /* Divide it into an initial 8-word block - plus one block of size 2**nu for nu = 3 ... 10. */ - - CHAIN (cp) = nextf[0]; - nextf[0] = (struct mhead *) cp; - ((struct mhead *) cp) -> mh_alloc = ISFREE; - ((struct mhead *) cp) -> mh_index = 0; - cp += 8; - - for (nu = 0; nu < 7; nu++) { - CHAIN (cp) = nextf[nu]; - nextf[nu] = (struct mhead *) cp; - ((struct mhead *) cp) -> mh_alloc = ISFREE; - ((struct mhead *) cp) -> mh_index = nu; - cp += 8 << nu;}} - -char * -malloc (n) /* get a block */ - unsigned n; { - struct mhead *p; - unsigned int nbytes; - int nunits = 0; - - /* Figure out how many bytes are required, rounding up to the nearest - multiple of 4, then figure out which nextf[] area to use */ - nbytes = (n + sizeof *p + EXTRA + 3) & ~3; - { - unsigned int shiftr = (nbytes - 1) >> 2; - - while (shiftr >>= 1) - nunits++; - } - - /* If there are no blocks of the appropriate size, go get some */ - /* COULD SPLIT UP A LARGER BLOCK HERE ... ACT */ - if (nextf[nunits] == 0) - morecore (nunits); - - /* Get one block off the list, and set the new list head */ - if ((p = nextf[nunits]) == 0) - return 0; - nextf[nunits] = CHAIN (p); - - /* Check for free block clobbered */ - /* If not for this check, we would gobble a clobbered free chain ptr */ - /* and bomb out on the NEXT allocate of this size block */ - if (p -> mh_alloc != ISFREE || p -> mh_index != nunits) -#ifdef rcheck - botch ("block on free list clobbered"); -#else - abort (); -#endif /* rcheck */ - - /* Fill in the info, and if range checking, set up the magic numbers */ - p -> mh_alloc = ISALLOC; -#ifdef rcheck - p -> mh_nbytes = n; - p -> mh_magic4 = MAGIC4; - { - char *m = (char *) (p + 1) + n; - - *m++ = MAGIC1, *m++ = MAGIC1, *m++ = MAGIC1, *m = MAGIC1; - } -#else - p -> mh_size = n; -#endif /* rcheck */ -#ifdef MSTATS - nmalloc[nunits]++; - nmal++; -#endif /* MSTATS */ - return (char *) (p + 1);} - -free (mem) - char *mem; { - struct mhead *p; - { - char *ap = mem; - - ASSERT (ap != 0); - p = (struct mhead *) ap - 1; - ASSERT (p -> mh_alloc == ISALLOC); -#ifdef rcheck - ASSERT (p -> mh_magic4 == MAGIC4); - ap += p -> mh_nbytes; - ASSERT (*ap++ == MAGIC1); ASSERT (*ap++ == MAGIC1); - ASSERT (*ap++ == MAGIC1); ASSERT (*ap == MAGIC1); -#endif /* rcheck */ - } - { - int nunits = p -> mh_index; - - ASSERT (nunits <= 29); - p -> mh_alloc = ISFREE; - CHAIN (p) = nextf[nunits]; - nextf[nunits] = p; -#ifdef MSTATS - nmalloc[nunits]--; - nfre++; -#endif /* MSTATS */ - } - } - -char * -realloc (mem, n) - char *mem; - unsigned n; { - struct mhead *p; - unsigned int tocopy; - int nbytes; - int nunits; - - if ((p = (struct mhead *) mem) == 0) - return malloc (n); - p--; - nunits = p -> mh_index; - ASSERT (p -> mh_alloc == ISALLOC); -#ifdef rcheck - ASSERT (p -> mh_magic4 == MAGIC4); - { - char *m = mem + (tocopy = p -> mh_nbytes); - ASSERT (*m++ == MAGIC1); ASSERT (*m++ == MAGIC1); - ASSERT (*m++ == MAGIC1); ASSERT (*m == MAGIC1); - } -#else - if (p -> mh_index >= 13) - tocopy = (1 << (p -> mh_index + 3)) - sizeof *p; - else - tocopy = p -> mh_size; -#endif /* rcheck */ - - /* See if desired size rounds to same power of 2 as actual size. */ - nbytes = (n + sizeof *p + EXTRA + 7) & ~7; - - /* If ok, use the same block, just marking its size as changed. */ - if (nbytes > (4 << nunits) && nbytes <= (8 << nunits)) { -#ifdef rcheck - char *m = mem + tocopy; - *m++ = 0; *m++ = 0; *m++ = 0; *m++ = 0; - p-> mh_nbytes = n; - m = mem + n; - *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1; *m++ = MAGIC1; -#else - p -> mh_size = n; -#endif /* rcheck */ - return mem;} - - if (n < tocopy) - tocopy = n; - { - char *new; - void bcopy(); /*HMS: here? */ - - if ((new = malloc (n)) == 0) - return 0; - bcopy (mem, new, tocopy); - free (mem); - return new; - } - } - -#ifdef MSTATS -/* Return statistics describing allocation of blocks of size 2**n. */ - -struct mstats_value { - int blocksize; - int nfree; - int nused; - }; - -struct mstats_value -malloc_stats (size) - int size; { - struct mstats_value v; - int i; - struct mhead *p; - - v.nfree = 0; - - if (size < 0 || size >= 30) { - v.blocksize = 0; - v.nused = 0; - return v;} - - v.blocksize = 1 << (size + 3); - v.nused = nmalloc[size]; - - for (p = nextf[size]; p; p = CHAIN (p)) - v.nfree++; - - return v;} -#endif - -/* how much space is available? */ - -unsigned freespace() { - int i, j; - struct mhead *p; - unsigned space = 0; - int local; /* address only is used */ - - space = (char *)&local - sbrk(0); /* stack space */ - - for (i = 0; i < 30; i++) { - for (j = 0, p = nextf[i]; p; p = CHAIN (p), j++) ; - space += j * (1 << (i + 3));} - - return(space);} - -/* How big is this cell? */ - -unsigned mc_size(cp) - char *cp;{ - struct mhead *p; - - if ((p = (struct mhead *) cp) == 0) { - /*HMS? */ - } - p--; -#ifdef rcheck - return p -> mh_nbytes; -#else - return (1 << (p -> mh_index + 3)) - sizeof *p; -/**/ -/* if (p -> mh_index >= 13) -/* return (1 << (p -> mh_index + 3)) - sizeof *p; -/* else -/* return p -> mh_size; -/**/ -#endif /* rcheck */ - } - -/*HMS: Really should use memcpy, if available... */ - -void bcopy(source, dest, len) - char *source, *dest; - len; { - i; - - for (i = 0; i < len; i++) - *dest++ = *source++;} diff --git a/usr.bin/patch/patch.1 b/usr.bin/patch/patch.1 index f15aa860e0b..80f332bcadb 100644 --- a/usr.bin/patch/patch.1 +++ b/usr.bin/patch/patch.1 @@ -1,4 +1,4 @@ -.\" $OpenBSD: patch.1,v 1.6 2003/02/18 07:57:49 jmc Exp $ -*- nroff -*- +.\" $OpenBSD: patch.1,v 1.7 2003/07/18 02:00:09 deraadt Exp $ -*- nroff -*- .\" Copyright 1986, Larry Wall .\" .\" Redistribution and use in source and binary forms, with or without @@ -6,7 +6,7 @@ .\" is met: .\" 1. Redistributions of source code must retain the above copyright .\" notice, this condition and the following disclaimer. -.\" +.\" .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c index eca5f1eec9d..a840825ebc1 100644 --- a/usr.bin/patch/patch.c +++ b/usr.bin/patch/patch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: patch.c,v 1.18 2003/07/16 16:06:53 otto Exp $ */ +/* $OpenBSD: patch.c,v 1.19 2003/07/18 02:00:09 deraadt Exp $ */ /* patch - a program to apply diffs to original files * @@ -9,7 +9,7 @@ * is met: * 1. Redistributions of source code must retain the above copyright * notice, this condition and the following disclaimer. - * + * * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE @@ -27,13 +27,12 @@ */ #ifndef lint -static char rcsid[] = "$OpenBSD: patch.c,v 1.18 2003/07/16 16:06:53 otto Exp $"; +static char rcsid[] = "$OpenBSD: patch.c,v 1.19 2003/07/18 02:00:09 deraadt Exp $"; #endif /* not lint */ #include "INTERN.h" #include "common.h" #include "EXTERN.h" -#include "version.h" #include "util.h" #include "pch.h" #include "inp.h" @@ -41,24 +40,22 @@ static char rcsid[] = "$OpenBSD: patch.c,v 1.18 2003/07/16 16:06:53 otto Exp $"; /* procedures */ -void reinitialize_almost_everything(); -void get_some_switches(); -LINENUM locate_hunk(); -void abort_hunk(); -void apply_hunk(); -void init_output(); -void init_reject(); -void copy_till(); -void spew_output(); -void dump_line(); -bool patch_match(); -bool similar(); -void re_input(); -#ifdef __GNUC__ -void my_exit() __attribute__((noreturn)); -#else -void my_exit(); -#endif +void reinitialize_almost_everything(void); +void get_some_switches(void); +LINENUM locate_hunk(LINENUM); +void abort_hunk(void); +void apply_hunk(LINENUM); +void init_output(char *); +void init_reject(char *); +void copy_till(LINENUM); +void spew_output(void); +void dump_line(LINENUM); +bool patch_match(LINENUM, LINENUM, LINENUM); +bool similar(char *, char *, int); +void re_input(void); +void my_exit(int) __attribute__((noreturn)); +int optcmp(const void *, const void *); +char decode_long_option(char *); /* TRUE if -E was specified on command line. */ static int remove_empty_files = FALSE; @@ -72,9 +69,7 @@ bool check_only = FALSE; /* Apply a set of diffs as appropriate. */ int -main(argc,argv) -int argc; -char **argv; +main(int argc, char *argv[]) { LINENUM where; LINENUM newwhere; @@ -103,28 +98,28 @@ char **argv; } if (asprintf(&TMPOUTNAME, "%s/patchoXXXXXXXXXX", tmpdir) == -1) - fatal1("cannot allocate memory"); + fatal("cannot allocate memory"); if ((i = mkstemp(TMPOUTNAME)) < 0) - pfatal2("can't create %s", TMPOUTNAME); - Close(i); + pfatal("can't create %s", TMPOUTNAME); + close(i); if (asprintf(&TMPINNAME, "%s/patchiXXXXXXXXXX", tmpdir) == -1) - fatal1("cannot allocate memory"); + fatal("cannot allocate memory"); if ((i = mkstemp(TMPINNAME)) < 0) - pfatal2("can't create %s", TMPINNAME); - Close(i); + pfatal("can't create %s", TMPINNAME); + close(i); if (asprintf(&TMPREJNAME, "%s/patchrXXXXXXXXXX", tmpdir) == -1) - fatal1("cannot allocate memory"); + fatal("cannot allocate memory"); if ((i = mkstemp(TMPREJNAME)) < 0) - pfatal2("can't create %s", TMPREJNAME); - Close(i); + pfatal("can't create %s", TMPREJNAME); + close(i); if (asprintf(&TMPPATNAME, "%s/patchpXXXXXXXXXX", tmpdir) == -1) - fatal1("cannot allocate memory"); + fatal("cannot allocate memory"); if ((i = mkstemp(TMPPATNAME)) < 0) - pfatal2("can't create %s", TMPPATNAME); - Close(i); + pfatal("can't create %s", TMPPATNAME); + close(i); } { @@ -145,7 +140,7 @@ char **argv; Argc = argc; Argv = argv; get_some_switches(); - + /* make sure we clean up /tmp in case of disaster */ set_signals(0); @@ -158,27 +153,27 @@ char **argv; if (outname == Nullch) outname = savestr(filearg[0]); - + /* for ed script just up and do it and exit */ if (diff_type == ED_DIFF) { do_ed_script(); continue; } - + /* initialize the patched file */ if (!skip_rest_of_patch) init_output(TMPOUTNAME); - + /* initialize reject file */ init_reject(TMPREJNAME); - + /* find out where all the lines are */ if (!skip_rest_of_patch) scan_input(filearg[0]); - + /* from here on, open no standard i/o files, because malloc */ /* might misfire and we can't catch it easily */ - + /* apply each hunk of patch */ hunk = 0; failed = 0; @@ -196,7 +191,7 @@ char **argv; /* dwim for reversed patch? */ if (!pch_swap()) { if (fuzz == Nulline) - say1( + say( "Not enough memory to try swapped hunk! Assuming unswapped.\n"); continue; } @@ -204,37 +199,37 @@ char **argv; where = locate_hunk(fuzz); /* try again */ if (where == Nulline) { /* didn't find it swapped */ if (!pch_swap()) /* put it back to normal */ - fatal1("lost hunk on alloc error!\n"); + fatal("lost hunk on alloc error!\n"); reverse = !reverse; } else if (noreverse) { if (!pch_swap()) /* put it back to normal */ - fatal1("lost hunk on alloc error!\n"); + fatal("lost hunk on alloc error!\n"); reverse = !reverse; - say1( + say( "Ignoring previously applied (or reversed) patch.\n"); skip_rest_of_patch = TRUE; } else if (batch) { if (verbose) - say3( + say( "%seversed (or previously applied) patch detected! %s -R.", reverse ? "R" : "Unr", reverse ? "Assuming" : "Ignoring"); } else { - ask3( + ask( "%seversed (or previously applied) patch detected! %s -R? [y] ", reverse ? "R" : "Unr", reverse ? "Assume" : "Ignore"); if (*buf == 'n') { - ask1("Apply anyway? [n] "); + ask("Apply anyway? [n] "); if (*buf != 'y') skip_rest_of_patch = TRUE; where = Nulline; reverse = !reverse; if (!pch_swap()) /* put it back to normal */ - fatal1("lost hunk on alloc error!\n"); + fatal("lost hunk on alloc error!\n"); } } } @@ -242,7 +237,7 @@ char **argv; ++fuzz <= mymaxfuzz); if (skip_rest_of_patch) { /* just got decided */ - Fclose(ofp); + fclose(ofp); ofp = Nullfp; } } @@ -252,24 +247,24 @@ char **argv; abort_hunk(); failed++; if (verbose) - say3("Hunk #%d ignored at %ld.\n", hunk, newwhere); + say("Hunk #%d ignored at %ld.\n", hunk, newwhere); } else if (where == Nulline) { abort_hunk(); failed++; if (verbose) - say3("Hunk #%d failed at %ld.\n", hunk, newwhere); + say("Hunk #%d failed at %ld.\n", hunk, newwhere); } else { apply_hunk(where); if (verbose) { - say3("Hunk #%d succeeded at %ld", hunk, newwhere); + say("Hunk #%d succeeded at %ld", hunk, newwhere); if (fuzz) - say2(" with fuzz %ld", fuzz); + say(" with fuzz %ld", fuzz); if (last_offset) - say3(" (offset %ld line%s)", + say(" (offset %ld line%s)", last_offset, last_offset==1L?"":"s"); - say1(".\n"); + say(".\n"); } } } @@ -277,29 +272,29 @@ char **argv; if (out_of_mem && using_plan_a) { Argc = Argc_last; Argv = Argv_last; - say1("\n\nRan out of memory using Plan A--trying again...\n\n"); + say("\n\nRan out of memory using Plan A--trying again...\n\n"); if (ofp) - Fclose(ofp); + fclose(ofp); ofp = Nullfp; if (rejfp) - Fclose(rejfp); + fclose(rejfp); rejfp = Nullfp; continue; } - + assert(hunk); - + /* finish spewing out the new file */ if (!skip_rest_of_patch) spew_output(); - + /* and put the output where desired */ ignore_signals(); if (!skip_rest_of_patch) { struct stat statbuf; char *realout = outname; - if (!check_only) { + if (!check_only) { if (move_file(TMPOUTNAME, outname) < 0) { toutkeep = TRUE; realout = TMPOUTNAME; @@ -311,40 +306,27 @@ char **argv; if (remove_empty_files && stat(realout, &statbuf) == 0 && statbuf.st_size == 0) { if (verbose) - say2("Removing %s (empty after patching).\n", realout); + say("Removing %s (empty after patching).\n", realout); while (unlink(realout) >= 0) ; /* while is for Eunice. */ } } } - Fclose(rejfp); + fclose(rejfp); rejfp = Nullfp; if (failed) { failtotal += failed; if (!*rejname) { if (strlcpy(rejname, outname, sizeof(rejname)) >= sizeof(rejname)) - fatal2("filename %s is too long\n", outname); - -#ifndef FLEXFILENAMES - { - char *s = strrchr(rejname,'/'); - - if (!s) - s = rejname; - if (strlen(s) > 13) - if (s[12] == '.') /* try to preserve difference */ - s[12] = s[13]; /* between .h, .c, .y, etc. */ - s[13] = '\0'; - } -#endif + fatal("filename %s is too long\n", outname); if (strlcat(rejname, REJEXT, sizeof(rejname)) >= sizeof(rejname)) - fatal2("filename %s is too long\n", outname); + fatal("filename %s is too long\n", outname); } if (skip_rest_of_patch) { - say4("%d out of %d hunks ignored--saving rejects to %s\n", + say("%d out of %d hunks ignored--saving rejects to %s\n", failed, hunk, rejname); } else { - say4("%d out of %d hunks failed--saving rejects to %s\n", + say("%d out of %d hunks failed--saving rejects to %s\n", failed, hunk, rejname); } if (!check_only && move_file(TMPREJNAME, rejname) < 0) @@ -353,7 +335,7 @@ char **argv; set_signals(1); } if (!patch_seen) - failtotal++; + failtotal++; my_exit(failtotal); /* NOTREACHED */ } @@ -395,14 +377,14 @@ reinitialize_almost_everything() get_some_switches(); if (filec >= 2) - fatal1("you may not change to a different patch file\n"); + fatal("you may not change to a different patch file\n"); } static char * -nextarg() +nextarg(void) { if (!--Argc) - fatal2("missing argument after `%s'\n", *Argv); + fatal("missing argument after `%s'\n", *Argv); return *++Argv; } @@ -414,17 +396,17 @@ struct option { }; int -optcmp(a, b) - struct option *a, *b; +optcmp(const void *v1, const void *v2) { + const struct option *a = v1, *b = v2; + return strcmp (a->long_opt, b->long_opt); } /* Decode Long options beginning with "--" to their short equivalents. */ char -decode_long_option(opt) - char *opt; +decode_long_option(char *opt) { /* This table must be sorted on the first field. We also decode unimplemented options as those will be handled later anyway. */ @@ -469,7 +451,7 @@ decode_long_option(opt) void get_some_switches() { - Reg1 char *s; + char *s; rejname[0] = '\0'; Argc_last = Argc; @@ -483,7 +465,7 @@ get_some_switches() } if (*s != '-' || !s[1]) { if (filec == MAXFILEC) - fatal1("too many file arguments\n"); + fatal("too many file arguments\n"); filearg[filec++] = savestr(s); } else { @@ -506,23 +488,23 @@ get_some_switches() diff_type = CONTEXT_DIFF; break; case 'C': - check_only = TRUE; + check_only = TRUE; break; case 'd': if (!*++s) s = nextarg(); if (chdir(s) < 0) - pfatal2("can't cd to %s", s); + pfatal("can't cd to %s", s); break; case 'D': - do_defines = TRUE; + do_defines = TRUE; if (!*++s) s = nextarg(); if (!isalpha(*s) && '_' != *s) - fatal1("argument to -D is not an identifier\n"); - Snprintf(if_defined, sizeof if_defined, "#ifdef %s\n", s); - Snprintf(not_defined, sizeof not_defined, "#ifndef %s\n", s); - Snprintf(end_defined, sizeof end_defined, "#endif /* %s */\n", s); + fatal("argument to -D is not an identifier\n"); + snprintf(if_defined, sizeof if_defined, "#ifdef %s\n", s); + snprintf(not_defined, sizeof not_defined, "#ifndef %s\n", s); + snprintf(end_defined, sizeof end_defined, "#endif /* %s */\n", s); break; case 'e': diff_type = ED_DIFF; @@ -561,7 +543,7 @@ get_some_switches() break; case 'r': if (strlcpy(rejname, nextarg(), sizeof(rejname)) >= sizeof(rejname)) - fatal1("argument for -r is too long\n"); + fatal("argument for -r is too long\n"); break; case 'R': reverse = TRUE; @@ -614,12 +596,12 @@ LINENUM locate_hunk(fuzz) 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 - - pat_lines + 1; - Reg4 LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + LINENUM max_pos_offset = input_lines - first_guess + - pat_lines + 1; + LINENUM max_neg_offset = first_guess - last_frozen_line - 1 + pch_context(); if (!pat_lines) /* null range matches always */ @@ -629,13 +611,13 @@ 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 if (debug & 1) - say3("Offset changing from %ld to %ld\n", last_offset, offset); + say("Offset changing from %ld to %ld\n", last_offset, offset); #endif last_offset = offset; return first_guess+offset; @@ -643,7 +625,7 @@ LINENUM fuzz; else if (check_before && patch_match(first_guess, -offset, fuzz)) { #ifdef DEBUGGING if (debug & 1) - say3("Offset changing from %ld to %ld\n", last_offset, -offset); + say("Offset changing from %ld to %ld\n", last_offset, -offset); #endif last_offset = -offset; return first_guess-offset; @@ -658,8 +640,8 @@ LINENUM fuzz; void abort_hunk() { - 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; @@ -694,7 +676,7 @@ abort_hunk() fprintf(rejfp, "%c %s", pch_char(i), pfetch(i)); break; default: - fatal1("fatal internal error in abort_hunk\n"); + fatal("fatal internal error in abort_hunk\n"); } } } @@ -705,21 +687,21 @@ void apply_hunk(where) 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') new++; - + while (old <= lastline) { if (pch_char(old) == '-') { copy_till(where + old - 1); @@ -756,11 +738,11 @@ LINENUM where; new++; } else if (pch_char(new) != pch_char(old)) { - say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n", + say("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", + say("oldchar = '%c', newchar = '%c'\n", pch_char(old), pch_char(new)); #endif my_exit(1); @@ -801,7 +783,7 @@ LINENUM where; copy_till(where + old - 1); if (R_do_defines) { if (def_state == OUTSIDE) { - fputs(if_defined, ofp); + fputs(if_defined, ofp); def_state = IN_IFDEF; } else if (def_state == IN_IFNDEF) { @@ -827,7 +809,7 @@ char *name; { ofp = fopen(name, "w"); if (ofp == Nullfp) - pfatal2("can't create %s", name); + pfatal("can't create %s", name); } /* Open a file to put hunks we can't locate. */ @@ -838,19 +820,19 @@ char *name; { rejfp = fopen(name, "w"); if (rejfp == Nullfp) - pfatal2("can't create %s", name); + pfatal("can't create %s", name); } /* Copy input file to output, up to wherever hunk is to be applied. */ void copy_till(lastline) -Reg1 LINENUM lastline; +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"); + fatal("misordered hunks! output would be garbled\n"); while (R_last_frozen_line < lastline) { dump_line(++R_last_frozen_line); } @@ -864,11 +846,11 @@ spew_output() { #ifdef DEBUGGING if (debug & 256) - say3("il=%ld lfl=%ld\n",input_lines,last_frozen_line); + say("il=%ld lfl=%ld\n",input_lines,last_frozen_line); #endif if (input_lines) copy_till(input_lines); /* dump remainder of file */ - Fclose(ofp); + fclose(ofp); ofp = Nullfp; } @@ -878,8 +860,8 @@ void dump_line(line) LINENUM line; { - Reg1 char *s; - Reg2 char R_newline = '\n'; + char *s; + char R_newline = '\n'; s = ifetch(line, 0); if (s == NULL) @@ -896,9 +878,9 @@ 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) { @@ -919,9 +901,9 @@ LINENUM fuzz; bool similar(a,b,len) -Reg1 char *a; -Reg2 char *b; -Reg3 int len; +char *a; +char *b; +int len; { if (a == NULL || b == NULL) return FALSE; @@ -951,13 +933,13 @@ void my_exit(status) int status; { - Unlink(TMPINNAME); + unlink(TMPINNAME); if (!toutkeep) { - Unlink(TMPOUTNAME); + unlink(TMPOUTNAME); } if (!trejkeep) { - Unlink(TMPREJNAME); + unlink(TMPREJNAME); } - Unlink(TMPPATNAME); + unlink(TMPPATNAME); exit(status); } diff --git a/usr.bin/patch/patchlevel.h b/usr.bin/patch/patchlevel.h deleted file mode 100644 index 43c198dede5..00000000000 --- a/usr.bin/patch/patchlevel.h +++ /dev/null @@ -1,3 +0,0 @@ -/* $OpenBSD: patchlevel.h,v 1.2 1996/06/10 11:21:32 niklas Exp $ */ - -#define PATCHLEVEL "12u8" diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c index 44228d869dd..4087daf841d 100644 --- a/usr.bin/patch/pch.c +++ b/usr.bin/patch/pch.c @@ -1,7 +1,7 @@ -/* $OpenBSD: pch.c,v 1.15 2003/07/17 19:16:31 otto Exp $ */ +/* $OpenBSD: pch.c,v 1.16 2003/07/18 02:00:09 deraadt Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: pch.c,v 1.15 2003/07/17 19:16:31 otto Exp $"; +static char rcsid[] = "$OpenBSD: pch.c,v 1.16 2003/07/18 02:00:09 deraadt Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -58,16 +58,16 @@ char *filename; if (filename == Nullch || !*filename || strEQ(filename, "-")) { pfp = fopen(TMPPATNAME, "w"); if (pfp == Nullfp) - pfatal2("can't create %s", TMPPATNAME); + pfatal("can't create %s", TMPPATNAME); while (fgets(buf, sizeof buf, stdin) != Nullch) fputs(buf, pfp); - Fclose(pfp); + fclose(pfp); filename = TMPPATNAME; } pfp = fopen(filename, "r"); if (pfp == Nullfp) - pfatal2("patch file %s not found", filename); - Fstat(fileno(pfp), &filestat); + pfatal("patch file %s not found", filename); + fstat(fileno(pfp), &filestat); p_filesize = filestat.st_size; next_intuit_at(0L,1L); /* start at the beginning */ set_hunkmax(); @@ -94,7 +94,7 @@ void grow_hunkmax() { hunkmax *= 2; - /* + /* * Note that on most systems, only the p_line array ever gets fresh memory * since p_len can move into p_line's old space, and p_char can move into * p_len's old space. Not on PDP-11's however. But it doesn't matter. @@ -108,7 +108,7 @@ grow_hunkmax() if (p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch) return; if (!using_plan_a) - fatal1("out of memory\n"); + fatal("out of memory\n"); out_of_mem = TRUE; /* whatever is null will be allocated again */ /* from within plan_a(), of all places */ } @@ -120,23 +120,23 @@ there_is_another_patch() { if (p_base != 0L && p_base >= p_filesize) { if (verbose) - say1("done\n"); + say("done\n"); return FALSE; } if (verbose) - say1("Hmm..."); + say("Hmm..."); diff_type = intuit_diff_type(); if (!diff_type) { if (p_base != 0L) { if (verbose) - say1(" Ignoring the trailing garbage.\ndone\n"); + say(" Ignoring the trailing garbage.\ndone\n"); } else - say1(" I can't seem to find a patch in there anywhere.\n"); + say(" I can't seem to find a patch in there anywhere.\n"); return FALSE; } if (verbose) - say3(" %sooks like %s to me...\n", + say(" %sooks like %s to me...\n", (p_base == 0L ? "L" : "The next patch l"), diff_type == UNI_DIFF ? "a unified diff" : diff_type == CONTEXT_DIFF ? "a context diff" : @@ -144,16 +144,16 @@ there_is_another_patch() diff_type == NORMAL_DIFF ? "a normal diff" : "an ed script" ); if (p_indent && verbose) - say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s"); + say("(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 || batch) { - say1("No file to patch. Skipping...\n"); + say("No file to patch. Skipping...\n"); filearg[0] = savestr(bestguess); skip_rest_of_patch = TRUE; return TRUE; } - ask1("File to patch: "); + ask("File to patch: "); if (*buf != '\n') { if (bestguess) free(bestguess); @@ -161,12 +161,12 @@ there_is_another_patch() filearg[0] = fetchname(buf, 0, FALSE); } if (filearg[0] == Nullch) { - ask1("No file found--skip this patch? [n] "); + ask("No file found--skip this patch? [n] "); if (*buf != 'y') { continue; } if (verbose) - say1("Skipping patch...\n"); + say("Skipping patch...\n"); filearg[0] = fetchname(bestguess, 0, TRUE); skip_rest_of_patch = TRUE; return TRUE; @@ -180,28 +180,28 @@ there_is_another_patch() int intuit_diff_type() { - 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; - 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; - Fseek(pfp, p_base, 0); + fseek(pfp, p_base, 0); p_input_line = p_bline - 1; for (;;) { previous_line = this_line; @@ -231,10 +231,10 @@ intuit_diff_type() else indent++; } - for (t=s; isdigit(*t) || *t == ','; t++) ; + for (t=s; isdigit(*t) || *t == ','; t++) ; this_is_a_command = (isdigit(*s) && (*t == 'd' || *t == 'c' || *t == 'a') ); - if (first_command_line < 0L && this_is_a_command) { + 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 */ @@ -290,7 +290,7 @@ intuit_diff_type() retval = (*(s-1) == '*' ? NEW_CONTEXT_DIFF : CONTEXT_DIFF); goto scan_exit; } - if ((!diff_type || diff_type == NORMAL_DIFF) && + if ((!diff_type || diff_type == NORMAL_DIFF) && last_line_was_command && (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) { p_start = previous_line; @@ -382,25 +382,25 @@ long file_line; assert(p_base <= file_pos); if (verbose && p_base < file_pos) { - Fseek(pfp, p_base, 0); - say1("The text leading up to this was:\n--------------------------\n"); + fseek(pfp, p_base, 0); + say("The text leading up to this was:\n--------------------------\n"); while (ftell(pfp) < file_pos) { ret = fgets(buf, sizeof buf, pfp); assert(ret != Nullch); - say2("|%s", buf); + say("|%s", buf); } - say1("--------------------------\n"); + say("--------------------------\n"); } else - Fseek(pfp, file_pos, 0); + fseek(pfp, file_pos, 0); p_input_line = file_line - 1; } /* Make this a function for better debugging. */ static void -malformed () +malformed(void) { - fatal3("malformed patch at line %ld: %s", p_input_line, buf); + fatal("malformed patch at line %ld: %s", p_input_line, buf); /* about as informative as "Syntax error" in C */ } @@ -433,9 +433,9 @@ remove_special_line(void) bool another_hunk() { - 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) @@ -452,17 +452,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; /* index of first line to copy */ - Reg6 LINENUM filldst; /* index of first missing line */ + LINENUM fillcnt = 0; /* #lines of missing ptrn or repl */ + LINENUM fillsrc; /* index of first line to copy */ + LINENUM filldst; /* 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; /* input line number for same */ - Reg7 LINENUM ptrn_copiable = 0; + LINENUM ptrn_copiable = 0; /* # of copiable lines in ptrn */ ret = pgets(buf, sizeof buf, pfp); @@ -486,7 +486,7 @@ another_hunk() repl_missing = TRUE; goto hunk_done; } - fatal1("unexpected end of file in patch\n"); + fatal("unexpected end of file in patch\n"); } } p_end++; @@ -505,7 +505,7 @@ another_hunk() goto hunk_done; } else - fatal2("unexpected end of hunk at line %ld\n", + fatal("unexpected end of hunk at line %ld\n", p_input_line); } if (p_end != 0) { @@ -513,7 +513,7 @@ another_hunk() repl_missing = TRUE; goto hunk_done; } - fatal3("unexpected *** at line %ld: %s", p_input_line, buf); + fatal("unexpected *** at line %ld: %s", p_input_line, buf); } context = 0; p_line[p_end] = savestr(buf); @@ -564,12 +564,12 @@ another_hunk() repl_missing = TRUE; goto hunk_done; } - fatal3( + fatal( "duplicate \"---\" at line %ld--check line numbers at line %ld\n", p_input_line, p_hunk_beg + repl_beginning); } else { - fatal4( + fatal( "%s \"---\" at line %ld--check line numbers at line %ld\n", (p_end <= p_ptrn_lines ? "Premature" @@ -606,7 +606,7 @@ another_hunk() } p_max = p_repl_lines + p_end; if (p_max > MAXHUNKSIZE) - fatal4("hunk too large (%ld lines) at line %ld: %s", + fatal("hunk too large (%ld lines) at line %ld: %s", p_max, p_input_line, buf); while (p_max >= hunkmax) grow_hunkmax(); @@ -693,19 +693,19 @@ another_hunk() else p_len[p_end] = 0; } - + hunk_done: if (p_end >=0 && !repl_beginning) - fatal2("no --- found in patch at line %ld\n", pch_hunk_beg()); + fatal("no --- found in patch at line %ld\n", pch_hunk_beg()); if (repl_missing) { - + /* reset state back to just after --- */ p_input_line = repl_patch_line; for (p_end--; p_end > repl_beginning; p_end--) free(p_line[p_end]); - Fseek(pfp, repl_backtrack_position, 0); - + fseek(pfp, repl_backtrack_position, 0); + /* redundant 'new' context lines were omitted - set */ /* up to fill them in from the old file context */ if (!p_context && p_repl_lines == 1) { @@ -738,13 +738,13 @@ another_hunk() if (diff_type == CONTEXT_DIFF && (fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) { if (verbose) - say4("%s\n%s\n%s\n", + say("%s\n%s\n%s\n", "(Fascinating--this is really a new-style context diff but without", "the telltale extra asterisks on the *** line that usually indicate", "the new style...)"); diff_type = NEW_CONTEXT_DIFF; } - + /* if there were omitted context lines, fill them in now */ if (fillcnt) { p_bfake = filldst; /* remember where not to free() */ @@ -753,7 +753,7 @@ another_hunk() 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", + fatal("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]; @@ -781,8 +781,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); @@ -822,7 +822,7 @@ another_hunk() fillsrc = 1; filldst = fillsrc + p_ptrn_lines; p_end = filldst + p_repl_lines; - Snprintf(buf, sizeof buf, "*** %ld,%ld ****\n", p_first, + snprintf(buf, sizeof buf, "*** %ld,%ld ****\n", p_first, p_first + p_ptrn_lines - 1); p_line[0] = savestr(buf); if (out_of_mem) { @@ -830,7 +830,7 @@ another_hunk() return FALSE; } p_char[0] = '*'; - Snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst, + snprintf(buf, sizeof buf, "--- %ld,%ld ----\n", p_newfirst, p_newfirst + p_repl_lines - 1); p_line[filldst] = savestr(buf); if (out_of_mem) { @@ -850,7 +850,7 @@ another_hunk() /* assume blank lines got chopped */ strlcpy(buf, " \n", sizeof buf); } else { - fatal1("unexpected end of file in patch\n"); + fatal("unexpected end of file in patch\n"); } } if (*buf == '\t' || *buf == '\n') { @@ -938,7 +938,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); @@ -970,13 +970,13 @@ another_hunk() min++; p_end = p_ptrn_lines + 1 + max - min + 1; if (p_end > MAXHUNKSIZE) - fatal4("hunk too large (%ld lines) at line %ld: %s", + fatal("hunk too large (%ld lines) at line %ld: %s", p_end, p_input_line, buf); while (p_end >= hunkmax) grow_hunkmax(); p_newfirst = min; p_repl_lines = max - min + 1; - Snprintf(buf, sizeof buf, "*** %ld,%ld\n", p_first, + snprintf(buf, sizeof buf, "*** %ld,%ld\n", p_first, p_first + p_ptrn_lines - 1); p_line[0] = savestr(buf); if (out_of_mem) { @@ -988,10 +988,10 @@ another_hunk() ret = pgets(buf, sizeof buf, pfp); p_input_line++; if (ret == Nullch) - fatal2("unexpected end of file in patch at line %ld\n", + fatal("unexpected end of file in patch at line %ld\n", p_input_line); if (*buf != '<') - fatal2("< expected at line %ld of patch\n", p_input_line); + fatal("< expected at line %ld of patch\n", p_input_line); p_line[i] = savestr(buf+2); if (out_of_mem) { p_end = i-1; @@ -1010,12 +1010,12 @@ another_hunk() ret = pgets(buf, sizeof buf, pfp); p_input_line++; if (ret == Nullch) - fatal2("unexpected end of file in patch at line %ld\n", + fatal("unexpected end of file in patch at line %ld\n", p_input_line); if (*buf != '-') - fatal2("--- expected at line %ld of patch\n", p_input_line); + fatal("--- expected at line %ld of patch\n", p_input_line); } - Snprintf(buf, sizeof(buf), "--- %ld,%ld\n", min, max); + snprintf(buf, sizeof(buf), "--- %ld,%ld\n", min, max); p_line[i] = savestr(buf); if (out_of_mem) { p_end = i-1; @@ -1026,10 +1026,10 @@ another_hunk() ret = pgets(buf, sizeof buf, pfp); p_input_line++; if (ret == Nullch) - fatal2("unexpected end of file in patch at line %ld\n", + fatal("unexpected end of file in patch at line %ld\n", p_input_line); if (*buf != '>') - fatal2("> expected at line %ld of patch\n", p_input_line); + fatal("> expected at line %ld of patch\n", p_input_line); p_line[i] = savestr(buf+2); if (out_of_mem) { p_end = i-1; @@ -1046,7 +1046,7 @@ another_hunk() } if (reverse) /* backwards patch? */ if (!pch_swap()) - say1("Not enough memory to swap next hunk!\n"); + say("Not enough memory to swap next hunk!\n"); #ifdef DEBUGGING if (debug & 2) { int i; @@ -1058,7 +1058,7 @@ another_hunk() else special = ' '; fprintf(stderr, "%3d %c %c %s", i, p_char[i], special, p_line[i]); - Fflush(stderr); + fflush(stderr); } } #endif @@ -1076,8 +1076,8 @@ 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; @@ -1088,7 +1088,7 @@ FILE *fp; indent++; } if (buf != s && strlcpy(buf, s, sizeof(buf)) >= sizeof(buf)) - fatal1("buffer too small in pgets()\n"); + fatal("buffer too small in pgets()\n"); } return ret; } @@ -1101,15 +1101,15 @@ pch_swap() 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; p_newfirst = i; - + /* make a scratch copy */ tp_line = p_line; @@ -1286,18 +1286,18 @@ pch_hunk_beg() void do_ed_script() { - Reg1 char *t; - Reg2 long beginning_of_this_line; - Reg3 bool this_line_is_command = FALSE; - Reg4 FILE *pipefp; + char *t; + long beginning_of_this_line; + bool this_line_is_command = FALSE; + FILE *pipefp; if (!skip_rest_of_patch) { - Unlink(TMPOUTNAME); + unlink(TMPOUTNAME); copy_file(filearg[0], TMPOUTNAME); if (verbose) - Snprintf(buf, sizeof buf, "/bin/ed %s", TMPOUTNAME); + snprintf(buf, sizeof buf, "/bin/ed %s", TMPOUTNAME); else - Snprintf(buf, sizeof buf, "/bin/ed - %s", TMPOUTNAME); + snprintf(buf, sizeof buf, "/bin/ed - %s", TMPOUTNAME); pipefp = popen(buf, "w"); } for (;;) { @@ -1332,8 +1332,8 @@ do_ed_script() return; fprintf(pipefp, "w\n"); fprintf(pipefp, "q\n"); - Fflush(pipefp); - Pclose(pipefp); + fflush(pipefp); + pclose(pipefp); ignore_signals(); if (!check_only) { if (move_file(TMPOUTNAME, outname) < 0) { diff --git a/usr.bin/patch/pch.h b/usr.bin/patch/pch.h index 712c90a415c..0e26355b67a 100644 --- a/usr.bin/patch/pch.h +++ b/usr.bin/patch/pch.h @@ -1,27 +1,27 @@ -/* $OpenBSD: pch.h,v 1.2 1996/06/10 11:21:34 niklas Exp $ */ +/* $OpenBSD: pch.h,v 1.3 2003/07/18 02:00:09 deraadt Exp $ */ EXT FILE *pfp INIT(Nullfp); /* patch file pointer */ -void re_patch(); -void open_patch_file(); -void set_hunkmax(); -void grow_hunkmax(); -bool there_is_another_patch(); -int intuit_diff_type(); -void next_intuit_at(); -void skip_to(); -bool another_hunk(); -bool pch_swap(); -char *pfetch(); -short pch_line_len(); -LINENUM pch_first(); -LINENUM pch_ptrn_lines(); -LINENUM pch_newfirst(); -LINENUM pch_repl_lines(); -LINENUM pch_end(); -LINENUM pch_context(); -LINENUM pch_hunk_beg(); -char pch_char(); -char *pfetch(); -char *pgets(); -void do_ed_script(); +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); +bool pch_swap(void); +char *pfetch(LINENUM); +short pch_line_len(LINENUM); +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); +LINENUM pch_hunk_beg(void); +char pch_char(LINENUM); +char *pfetch(LINENUM); +char *pgets(char *, int, FILE *); +void do_ed_script(void); diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c index 5cf7884909d..91cc68bbe48 100644 --- a/usr.bin/patch/util.c +++ b/usr.bin/patch/util.c @@ -1,7 +1,7 @@ -/* $OpenBSD: util.c,v 1.11 2003/04/08 00:18:31 deraadt Exp $ */ +/* $OpenBSD: util.c,v 1.12 2003/07/18 02:00:09 deraadt Exp $ */ #ifndef lint -static char rcsid[] = "$OpenBSD: util.c,v 1.11 2003/04/08 00:18:31 deraadt Exp $"; +static char rcsid[] = "$OpenBSD: util.c,v 1.12 2003/07/18 02:00:09 deraadt Exp $"; #endif /* not lint */ #include "EXTERN.h" @@ -10,11 +10,7 @@ static char rcsid[] = "$OpenBSD: util.c,v 1.11 2003/04/08 00:18:31 deraadt Exp $ #include "util.h" #include "backupfile.h" -#ifdef __GNUC__ -void my_exit() __attribute__((noreturn)); -#else -void my_exit(); -#endif +void my_exit(int) __attribute__((noreturn)); /* Rename a file, copying it if necessary. */ @@ -23,43 +19,43 @@ move_file(from,to) char *from, *to; { char bakname[MAXPATHLEN]; - Reg1 char *s; - Reg2 int i; - Reg3 int fromfd; + char *s; + int i; + int fromfd; /* to stdout? */ if (strEQ(to, "-")) { #ifdef DEBUGGING if (debug & 4) - say2("Moving %s to stdout.\n", from); + say("Moving %s to stdout.\n", from); #endif fromfd = open(from, O_RDONLY); if (fromfd < 0) - pfatal2("internal error, can't reopen %s", from); + pfatal("internal error, can't reopen %s", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(1, buf, i) != 1) - pfatal1("write failed"); - Close(fromfd); + pfatal("write failed"); + close(fromfd); return 0; } if (origprae) { if (strlcpy(bakname, origprae, sizeof(bakname)) >= sizeof(bakname) || strlcat(bakname, to, sizeof(bakname)) >= sizeof(bakname)) - fatal2("filename %s too long for buffer\n", origprae); + fatal("filename %s too long for buffer\n", origprae); } else { #ifndef NODIR char *backupname = find_backup_file_name(to); if (backupname == (char *) 0) - fatal1("out of memory\n"); + fatal("out of memory\n"); if (strlcpy(bakname, backupname, sizeof(bakname)) >= sizeof(bakname)) - fatal2("filename %s too long for buffer\n", backupname); + fatal("filename %s too long for buffer\n", backupname); free(backupname); #else /* NODIR */ if (strlcpy(bakname, to, sizeof(bakname)) >= sizeof(bakname) || strlcat(bakname, simple_backup_suffix, sizeof(bakname)) >= sizeof(bakname)) - fatal2("filename %s too long for buffer\n", to); + fatal("filename %s too long for buffer\n", to); #endif /* NODIR */ } @@ -67,7 +63,7 @@ char *from, *to; dev_t to_device = filestat.st_dev; ino_t to_inode = filestat.st_ino; char *simplename = bakname; - + for (s=bakname; *s; s++) { if (*s == '/') simplename = s+1; @@ -87,55 +83,55 @@ char *from, *to; while (unlink(bakname) >= 0) ; /* while() is for benefit of Eunice */ #ifdef DEBUGGING if (debug & 4) - say3("Moving %s to %s.\n", to, bakname); + say("Moving %s to %s.\n", to, bakname); #endif if (link(to, bakname) < 0) { /* 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) { - say4("Can't backup %s, output is in %s: %s\n", to, from, + say("Can't backup %s, output is in %s: %s\n", to, from, strerror(errno)); return -1; } tofd = open(to, O_RDONLY); if (tofd < 0) - pfatal2("internal error, can't open %s", to); + pfatal("internal error, can't open %s", to); while ((i=read(tofd, buf, sizeof buf)) > 0) if (write(bakfd, buf, i) != i) - pfatal1("write failed"); - Close(tofd); - Close(bakfd); + pfatal("write failed"); + close(tofd); + close(bakfd); } while (unlink(to) >= 0) ; } #ifdef DEBUGGING if (debug & 4) - say3("Moving %s to %s.\n", from, to); + say("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) { - say4("Can't create %s, output is in %s: %s\n", + say("Can't create %s, output is in %s: %s\n", to, from, strerror(errno)); return -1; } fromfd = open(from, O_RDONLY); if (fromfd < 0) - pfatal2("internal error, can't reopen %s", from); + pfatal("internal error, can't reopen %s", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(tofd, buf, i) != i) - pfatal1("write failed"); - Close(fromfd); - Close(tofd); + pfatal("write failed"); + close(fromfd); + close(tofd); } - Unlink(from); + unlink(from); return 0; } @@ -145,31 +141,31 @@ void copy_file(from,to) char *from, *to; { - Reg3 int tofd; - Reg2 int fromfd; - Reg1 int i; - + int tofd; + int fromfd; + int i; + tofd = creat(to, 0666); if (tofd < 0) - pfatal2("can't create %s", to); + pfatal("can't create %s", to); fromfd = open(from, O_RDONLY); if (fromfd < 0) - pfatal2("internal error, can't reopen %s", from); + pfatal("internal error, can't reopen %s", from); while ((i=read(fromfd, buf, sizeof buf)) > 0) if (write(tofd, buf, i) != i) - pfatal2("write to %s failed", to); - Close(fromfd); - Close(tofd); + pfatal("write to %s failed", to); + close(fromfd); + close(tofd); } /* Allocate a unique area for a string. */ char * savestr(s) -Reg1 char *s; +char *s; { - Reg3 char *rv; - Reg2 char *t; + char *rv; + char *t; if (!s) s = "Oops"; @@ -180,7 +176,7 @@ Reg1 char *s; if (using_plan_a) out_of_mem = TRUE; else - fatal1("out of memory\n"); + fatal("out of memory\n"); } else { t = rv; @@ -190,53 +186,45 @@ Reg1 char *s; return rv; } -#if defined(lint) && defined(CANVARARG) - -/*VARARGS ARGSUSED*/ -say(pat) char *pat; { ; } -/*VARARGS ARGSUSED*/ -fatal(pat) char *pat; { ; } -/*VARARGS ARGSUSED*/ -pfatal(pat) char *pat; { ; } -/*VARARGS ARGSUSED*/ -ask(pat) char *pat; { ; } - -#else - /* Vanilla terminal output (buffered). */ void -say(pat,arg1,arg2,arg3) -char *pat; -long arg1,arg2,arg3; +say(char *fmt, ...) { - fprintf(stderr, pat, arg1, arg2, arg3); - Fflush(stderr); + va_list ap; + + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); + fflush(stderr); } /* Terminal output, pun intended. */ -void /* very void */ -fatal(pat,arg1,arg2,arg3) -char *pat; -long arg1,arg2,arg3; +void +fatal(char *fmt, ...) { + va_list ap; + + va_start(ap, fmt); fprintf(stderr, "patch: **** "); - fprintf(stderr, pat, arg1, arg2, arg3); + vfprintf(stderr, fmt, ap); + va_end(ap); my_exit(1); } /* Say something from patch, something from the system, then silence . . . */ -void /* very void */ -pfatal(pat,arg1,arg2,arg3) -char *pat; -long arg1,arg2,arg3; +void +pfatal(char *fmt, ...) { + va_list ap; int errnum = errno; fprintf(stderr, "patch: **** "); - fprintf(stderr, pat, arg1, arg2, arg3); + va_start(ap, fmt); + vfprintf(stderr, fmt, ap); + va_end(ap); fprintf(stderr, ": %s\n", strerror(errnum)); my_exit(1); } @@ -244,37 +232,34 @@ long arg1,arg2,arg3; /* Get a response from the user, somehow or other. */ void -ask(pat,arg1,arg2,arg3) -char *pat; -long arg1,arg2,arg3; +ask(char *fmt, ...) { + va_list ap; int ttyfd; int r; bool tty2 = isatty(2); - Snprintf(buf, sizeof buf, pat, arg1, arg2, arg3); - Fflush(stderr); + va_start(ap, fmt); + vsnprintf(buf, sizeof buf, fmt, ap); + va_end(ap); + fflush(stderr); 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 */ - Fflush(stdout); + } else if (isatty(1)) { /* this may be new file output */ + fflush(stdout); write(1, buf, strlen(buf)); r = read(1, buf, sizeof buf); - } - else if ((ttyfd = open(_PATH_TTY, O_RDWR)) >= 0 && isatty(ttyfd)) { - /* might be deleted or unwriteable */ + } else if ((ttyfd = open(_PATH_TTY, O_RDWR)) >= 0 && isatty(ttyfd)) { + /* might be deleted or unwriteable */ write(ttyfd, buf, strlen(buf)); r = read(ttyfd, buf, sizeof buf); - Close(ttyfd); - } - else if (isatty(0)) { /* this is probably patch input */ - Fflush(stdin); + close(ttyfd); + } else if (isatty(0)) { /* this is probably patch input */ + fflush(stdin); write(0, buf, strlen(buf)); r = read(0, buf, sizeof buf); - } - else { /* no terminal at all--default it */ + } else { /* no terminal at all--default it */ buf[0] = '\n'; r = 1; } @@ -283,9 +268,8 @@ long arg1,arg2,arg3; else buf[r] = '\0'; if (!tty2) - say1(buf); + say(buf); } -#endif /* lint */ /* How to handle certain events when not in a critical region. */ @@ -304,8 +288,8 @@ int reset; if (intval != SIG_IGN) intval = (sig_t)my_exit; } - Signal(SIGHUP, hupval); - Signal(SIGINT, intval); + signal(SIGHUP, hupval); + signal(SIGINT, intval); #endif } @@ -315,8 +299,8 @@ void ignore_signals() { #ifndef lint - Signal(SIGHUP, SIG_IGN); - Signal(SIGINT, SIG_IGN); + signal(SIGHUP, SIG_IGN); + signal(SIGINT, SIG_IGN); #endif } @@ -325,13 +309,13 @@ ignore_signals() void makedirs(filename,striplast) -Reg1 char *filename; +char *filename; bool striplast; { char *tmpbuf; if ((tmpbuf = strdup(filename)) == NULL) - fatal1("out of memory\n"); + fatal("out of memory\n"); if (striplast) { char *s = strrchr(tmpbuf, '/'); @@ -342,10 +326,10 @@ bool striplast; strlcpy(buf, "/bin/mkdir -p ", sizeof buf); if (strlcat(buf, tmpbuf, sizeof(buf)) >= sizeof(buf)) - fatal2("buffer too small to hold %.20s...\n", tmpbuf); + fatal("buffer too small to hold %.20s...\n", tmpbuf); if (system(buf)) - pfatal2("%.40s failed", buf); + pfatal("%.40s failed", buf); } /* Make filenames more reasonable. */ @@ -358,7 +342,7 @@ int assume_exists; { char *fullname; char *name; - Reg1 char *t; + char *t; char tmpbuf[200]; int sleading = strip_leading; @@ -368,7 +352,7 @@ int assume_exists; at++; #ifdef DEBUGGING if (debug & 128) - say4("fetchname %s %d %d\n",at,strip_leading,assume_exists); + say("fetchname %s %d %d\n",at,strip_leading,assume_exists); #endif if (strnEQ(at, "/dev/null", 9)) /* so files can be created by diffing */ return Nullch; /* against /dev/null. */ @@ -400,7 +384,7 @@ int assume_exists; char *filebase = basename(name); char *filedir = dirname(name); -#define try(f, a1, a2, a3) (Snprintf(tmpbuf, sizeof tmpbuf, f, a1, a2, a3), stat(tmpbuf, &filestat) == 0) +#define try(f, a1, a2, a3) (snprintf(tmpbuf, sizeof tmpbuf, f, a1, a2, a3), stat(tmpbuf, &filestat) == 0) if ( try("%s/RCS/%s%s", filedir, filebase, RCSSUFFIX) || try("%s/RCS/%s%s", filedir, filebase, "") || try( "%s/%s%s", filedir, filebase, RCSSUFFIX) @@ -413,3 +397,10 @@ int assume_exists; return name; } + +void +version() +{ + fprintf(stderr, "Patch version 2.0-12u8-OpenBSD\n"); + my_exit(0); +} diff --git a/usr.bin/patch/util.h b/usr.bin/patch/util.h index e57966db80a..bfdb2ef8c7b 100644 --- a/usr.bin/patch/util.h +++ b/usr.bin/patch/util.h @@ -1,81 +1,18 @@ -/* $OpenBSD: util.h,v 1.3 1999/01/03 05:33:49 millert Exp $ */ +/* $OpenBSD: util.h,v 1.4 2003/07/18 02:00:09 deraadt Exp $ */ /* and for those machine that can't handle a variable argument list */ -#ifdef CANVARARG - -#define say1 say -#define say2 say -#define say3 say -#define say4 say -#define ask1 ask -#define ask2 ask -#define ask3 ask -#define ask4 ask -#define fatal1 fatal -#define fatal2 fatal -#define fatal3 fatal -#define fatal4 fatal -#define pfatal1 pfatal -#define pfatal2 pfatal -#define pfatal3 pfatal -#define pfatal4 pfatal - -#else /* hope they allow multi-line macro actual arguments */ - -#ifdef lint - -#define say1(a) say(a, 0, 0, 0) -#define say2(a,b) say(a, (b)==(b), 0, 0) -#define say3(a,b,c) say(a, (b)==(b), (c)==(c), 0) -#define say4(a,b,c,d) say(a, (b)==(b), (c)==(c), (d)==(d)) -#define ask1(a) ask(a, 0, 0, 0) -#define ask2(a,b) ask(a, (b)==(b), 0, 0) -#define ask3(a,b,c) ask(a, (b)==(b), (c)==(c), 0) -#define ask4(a,b,c,d) ask(a, (b)==(b), (c)==(c), (d)==(d)) -#define fatal1(a) fatal(a, 0, 0, 0) -#define fatal2(a,b) fatal(a, (b)==(b), 0, 0) -#define fatal3(a,b,c) fatal(a, (b)==(b), (c)==(c), 0) -#define fatal4(a,b,c,d) fatal(a, (b)==(b), (c)==(c), (d)==(d)) -#define pfatal1(a) pfatal(a, 0, 0, 0) -#define pfatal2(a,b) pfatal(a, (b)==(b), 0, 0) -#define pfatal3(a,b,c) pfatal(a, (b)==(b), (c)==(c), 0) -#define pfatal4(a,b,c,d) pfatal(a, (b)==(b), (c)==(c), (d)==(d)) - -#else /* lint */ - /* if this doesn't work, try defining CANVARARG above */ -#define say1(a) say(a, Nullch, Nullch, Nullch) -#define say2(a,b) say(a, b, Nullch, Nullch) -#define say3(a,b,c) say(a, b, c, Nullch) -#define say4 say -#define ask1(a) ask(a, Nullch, Nullch, Nullch) -#define ask2(a,b) ask(a, b, Nullch, Nullch) -#define ask3(a,b,c) ask(a, b, c, Nullch) -#define ask4 ask -#define fatal1(a) fatal(a, Nullch, Nullch, Nullch) -#define fatal2(a,b) fatal(a, b, Nullch, Nullch) -#define fatal3(a,b,c) fatal(a, b, c, Nullch) -#define fatal4 fatal -#define pfatal1(a) pfatal(a, Nullch, Nullch, Nullch) -#define pfatal2(a,b) pfatal(a, b, Nullch, Nullch) -#define pfatal3(a,b,c) pfatal(a, b, c, Nullch) -#define pfatal4 pfatal - -#endif /* lint */ - -/* if neither of the above work, join all multi-line macro calls. */ -#endif - EXT char serrbuf[BUFSIZ]; /* buffer for stderr */ -char *fetchname(); -int move_file(); -void copy_file(); -void say(); -void fatal(); -void pfatal(); -void ask(); -char *savestr(); -void set_signals(); -void ignore_signals(); -void makedirs(); +char *fetchname(char *, int, int); +int move_file(char *, char *); +void copy_file(char *, char *); +void say(char *, ...); +void fatal(char *, ...); +void pfatal(char *, ...); +void ask(char *, ...); +char *savestr(char *); +void set_signals(int); +void ignore_signals(void); +void makedirs(char *, bool); +void version(void); diff --git a/usr.bin/patch/version.c b/usr.bin/patch/version.c deleted file mode 100644 index 417956b4004..00000000000 --- a/usr.bin/patch/version.c +++ /dev/null @@ -1,27 +0,0 @@ -/* $OpenBSD: version.c,v 1.3 1997/09/22 05:45:28 millert Exp $ */ - -#ifndef lint -static char rcsid[] = "$OpenBSD: version.c,v 1.3 1997/09/22 05:45:28 millert Exp $"; -#endif /* not lint */ - -#include "EXTERN.h" -#include "common.h" -#include "util.h" -#include "INTERN.h" -#include "patchlevel.h" -#include "version.h" - -#ifdef __GNUC__ -void my_exit() __attribute__((noreturn)); -#else -void my_exit(); -#endif - -/* Print out the version number and die. */ - -void -version() -{ - fprintf(stderr, "Patch version 2.0, patch level %s\n", PATCHLEVEL); - my_exit(0); -} diff --git a/usr.bin/patch/version.h b/usr.bin/patch/version.h deleted file mode 100644 index 17fa0d5bedf..00000000000 --- a/usr.bin/patch/version.h +++ /dev/null @@ -1,3 +0,0 @@ -/* $OpenBSD: version.h,v 1.2 1996/06/10 11:21:36 niklas Exp $ */ - -void version(); |