From a4c67efd5f829f228095cfa9ef30069364d2f824 Mon Sep 17 00:00:00 2001 From: pfg Date: Tue, 3 Sep 2013 20:03:10 +0000 Subject: Remove our hacked GNU patch. The old (2.1) GNU patch has outlived its days. The major local changes have been moved into the less restrictedly licensed patch(1) we adopted in usr.bin/ . A much newer version of GNU patch is available in the ports tree (devel/patch). Disconnect from the build and remove. --- ObsoleteFiles.inc | 3 + gnu/usr.bin/Makefile | 1 - gnu/usr.bin/patch/EXTERN.h | 21 - gnu/usr.bin/patch/INTERN.h | 19 - gnu/usr.bin/patch/Makefile | 12 - gnu/usr.bin/patch/backupfile.c | 390 ----------- gnu/usr.bin/patch/backupfile.h | 44 -- gnu/usr.bin/patch/common.h | 195 ------ gnu/usr.bin/patch/config.h | 81 --- gnu/usr.bin/patch/inp.c | 397 ----------- gnu/usr.bin/patch/inp.h | 18 - gnu/usr.bin/patch/patch.1 | 594 ---------------- gnu/usr.bin/patch/patch.c | 971 --------------------------- gnu/usr.bin/patch/patchlevel.h | 1 - gnu/usr.bin/patch/pch.c | 1449 ---------------------------------------- gnu/usr.bin/patch/pch.h | 36 - gnu/usr.bin/patch/util.c | 458 ------------- gnu/usr.bin/patch/util.h | 88 --- gnu/usr.bin/patch/version.c | 25 - gnu/usr.bin/patch/version.h | 9 - 20 files changed, 3 insertions(+), 4809 deletions(-) delete mode 100644 gnu/usr.bin/patch/EXTERN.h delete mode 100644 gnu/usr.bin/patch/INTERN.h delete mode 100644 gnu/usr.bin/patch/Makefile delete mode 100644 gnu/usr.bin/patch/backupfile.c delete mode 100644 gnu/usr.bin/patch/backupfile.h delete mode 100644 gnu/usr.bin/patch/common.h delete mode 100644 gnu/usr.bin/patch/config.h delete mode 100644 gnu/usr.bin/patch/inp.c delete mode 100644 gnu/usr.bin/patch/inp.h delete mode 100644 gnu/usr.bin/patch/patch.1 delete mode 100644 gnu/usr.bin/patch/patch.c delete mode 100644 gnu/usr.bin/patch/patchlevel.h delete mode 100644 gnu/usr.bin/patch/pch.c delete mode 100644 gnu/usr.bin/patch/pch.h delete mode 100644 gnu/usr.bin/patch/util.c delete mode 100644 gnu/usr.bin/patch/util.h delete mode 100644 gnu/usr.bin/patch/version.c delete mode 100644 gnu/usr.bin/patch/version.h diff --git a/ObsoleteFiles.inc b/ObsoleteFiles.inc index 7399a6e..30ec49b 100644 --- a/ObsoleteFiles.inc +++ b/ObsoleteFiles.inc @@ -38,6 +38,9 @@ # xargs -n1 | sort | uniq -d; # done +# 20130903: gnupatch is no more +OLD_FILES+=usr/bin/gnupatch +OLD_FILES+=usr/share/man/man1/gnupatch.1.gz # 20130829: bsdpatch is patch unconditionally OLD_FILES+=usr/bin/bsdpatch OLD_FILES+=usr/share/man/man1/bsdpatch.1.gz diff --git a/gnu/usr.bin/Makefile b/gnu/usr.bin/Makefile index cfb9a21..663107c 100644 --- a/gnu/usr.bin/Makefile +++ b/gnu/usr.bin/Makefile @@ -12,7 +12,6 @@ SUBDIR= ${_binutils} \ ${_gperf} \ grep \ ${_groff} \ - patch \ ${_rcs} \ sdiff \ send-pr \ diff --git a/gnu/usr.bin/patch/EXTERN.h b/gnu/usr.bin/patch/EXTERN.h deleted file mode 100644 index 374c94f..0000000 --- a/gnu/usr.bin/patch/EXTERN.h +++ /dev/null @@ -1,21 +0,0 @@ -/* $FreeBSD$ - * - * $Log: EXTERN.h,v $ - * Revision 2.0 86/09/17 15:35:37 lwall - * Baseline for netwide release. - * - */ - -#ifdef EXT -#undef EXT -#endif -#define EXT extern - -#ifdef INIT -#undef INIT -#endif -#define INIT(x) - -#ifdef DOINIT -#undef DOINIT -#endif diff --git a/gnu/usr.bin/patch/INTERN.h b/gnu/usr.bin/patch/INTERN.h deleted file mode 100644 index c04e722..0000000 --- a/gnu/usr.bin/patch/INTERN.h +++ /dev/null @@ -1,19 +0,0 @@ -/* $FreeBSD$ - * - * $Log: INTERN.h,v $ - * Revision 2.0 86/09/17 15:35:58 lwall - * Baseline for netwide release. - * - */ - -#ifdef EXT -#undef EXT -#endif -#define EXT - -#ifdef INIT -#undef INIT -#endif -#define INIT(x) = x - -#define DOINIT diff --git a/gnu/usr.bin/patch/Makefile b/gnu/usr.bin/patch/Makefile deleted file mode 100644 index 8d8cc7b..0000000 --- a/gnu/usr.bin/patch/Makefile +++ /dev/null @@ -1,12 +0,0 @@ -# $FreeBSD$ - -PROG= gnupatch -CLEANFILES+= gnupatch.1 - -gnupatch.1: patch.1 - cp ${.ALLSRC} ${.TARGET} - -SRCS= backupfile.c inp.c patch.c pch.c util.c version.c -CFLAGS+=-DHAVE_CONFIG_H - -.include diff --git a/gnu/usr.bin/patch/backupfile.c b/gnu/usr.bin/patch/backupfile.c deleted file mode 100644 index 94a615d..0000000 --- a/gnu/usr.bin/patch/backupfile.c +++ /dev/null @@ -1,390 +0,0 @@ -/* backupfile.c -- make Emacs style backup file names - Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* Written by David MacKenzie . - Some algorithms adapted from GNU Emacs. - */ - -#include -__FBSDID("$FreeBSD$"); - -#include "config.h" -#include -#include -#include -#include "backupfile.h" -#ifdef STDC_HEADERS -#include -#include -#else -char *malloc (); -#endif - -#if defined (HAVE_UNISTD_H) -#include -#endif - -#if defined(DIRENT) || defined(_POSIX_VERSION) -#include -#define NLENGTH(direct) (strlen((direct)->d_name)) -#else /* not (DIRENT or _POSIX_VERSION) */ -#define dirent direct -#define NLENGTH(direct) ((direct)->d_namlen) -#ifdef SYSNDIR -#include -#endif /* SYSNDIR */ -#ifdef SYSDIR -#include -#endif /* SYSDIR */ -#ifdef NDIR -#include -#endif /* NDIR */ -#endif /* DIRENT or _POSIX_VERSION */ - -#ifndef isascii -#define ISDIGIT(c) (isdigit ((unsigned char) (c))) -#else -#define ISDIGIT(c) (isascii (c) && isdigit (c)) -#endif - -#if defined (_POSIX_VERSION) -/* POSIX does not require that the d_ino field be present, and some - systems do not provide it. */ -#define REAL_DIR_ENTRY(dp) 1 -#else -#define REAL_DIR_ENTRY(dp) ((dp)->d_ino != 0) -#endif - -/* Which type of backup file names are generated. */ -enum backup_type backup_type = none; - -/* The extension added to file names to produce a simple (as opposed - to numbered) backup file name. */ -char *simple_backup_suffix = "~"; - -int argmatch(char *_arg, const char **_optlist); -const char *basename(const char *_name); -char *dirname(const char *_path); -static char *concat(const char *_str1, const char *_str2); -char *find_backup_file_name(char *_file); -static char *make_version_name (char *_file, int _version); -static int max_backup_version(char *_file, char *_dir); -static int version_number(char *base, char *backup, int base_length); -void invalid_arg(const char *_kind, char *_value, int _problem); - -/* Return NAME with any leading path stripped off. */ - -const char * -basename(const char *name) -{ - const char *r = name, *p = name; - - while (*p) - if (*p++ == '/') - r = p; - return r; -} - -#ifndef NODIR -/* Return the name of the new backup file for file FILE, - allocated with malloc. Return 0 if out of memory. - FILE must not end with a '/' unless it is the root directory. - Do not call this function if backup_type == none. */ - -char * -find_backup_file_name(char *file) -{ - char *dir; - char *base_versions; - int highest_backup; - - if (backup_type == simple) - { - char *s = malloc (strlen (file) + strlen (simple_backup_suffix) + 1); - strcpy (s, file); - addext (s, simple_backup_suffix, '~'); - return s; - } - base_versions = concat (basename (file), ".~"); - if (base_versions == 0) - return 0; - dir = dirname (file); - if (dir == 0) - { - free (base_versions); - return 0; - } - highest_backup = max_backup_version (base_versions, dir); - free (base_versions); - free (dir); - if (backup_type == numbered_existing && highest_backup == 0) - return concat (file, simple_backup_suffix); - return make_version_name (file, highest_backup + 1); -} - -/* Return the number of the highest-numbered backup file for file - FILE in directory DIR. If there are no numbered backups - of FILE in DIR, or an error occurs reading DIR, return 0. - FILE should already have ".~" appended to it. */ - -static int -max_backup_version(char *file, char *dir) -{ - DIR *dirp; - struct dirent *dp; - 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); - - while ((dp = readdir (dirp)) != 0) - { - 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; - } - closedir (dirp); - return highest_version; -} - -/* Return a string, allocated with malloc, containing - "FILE.~VERSION~". Return 0 if out of memory. */ - -static char * -make_version_name(char *file, int version) -{ - char *backup_name; - - backup_name = malloc (strlen (file) + 16); - if (backup_name == 0) - return 0; - sprintf (backup_name, "%s.~%d~", file, version); - return backup_name; -} - -/* If BACKUP is a numbered backup of BASE, return its version number; - otherwise return 0. BASE_LENGTH is the length of BASE. - BASE should already have ".~" appended to it. */ - -static int -version_number(char *base, char *backup, int base_length) -{ - int version; - char *p; - - version = 0; - if (!strncmp (base, backup, base_length) && ISDIGIT (backup[base_length])) - { - for (p = &backup[base_length]; ISDIGIT (*p); ++p) - version = version * 10 + *p - '0'; - if (p[0] != '~' || p[1]) - version = 0; - } - return version; -} - -/* Return the newly-allocated concatenation of STR1 and STR2. - If out of memory, return 0. */ - -static char * -concat(const char *str1, const char *str2) -{ - char *newstr; - int str1_length = strlen (str1); - - newstr = malloc (str1_length + strlen (str2) + 1); - if (newstr == 0) - return 0; - strcpy (newstr, str1); - strcpy (newstr + str1_length, str2); - return newstr; -} - -/* Return the leading directories part of PATH, - allocated with malloc. If out of memory, return 0. - Assumes that trailing slashes have already been - removed. */ - -char * -dirname(const char *path) -{ - char *newpath; - const char *slash; - int length; /* Length of result, not including NUL. */ - - slash = basename (path); - if (slash == path) - { - /* File is in the current directory. */ - path = "."; - length = 1; - } - else - { - /* Remove any trailing slashes from result. */ - while (*--slash == '/' && slash > path) - ; - - length = slash - path + 1; - } - newpath = malloc (length + 1); - if (newpath == 0) - return 0; - strncpy (newpath, path, length); - newpath[length] = 0; - return newpath; -} - -/* If ARG is an unambiguous match for an element of the - null-terminated array OPTLIST, return the index in OPTLIST - 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(char *arg, const char **optlist) -{ - int i; /* Temporary index in 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++) - { - if (!strncmp (optlist[i], arg, arglen)) - { - if (strlen (optlist[i]) == arglen) - /* Exact match found. */ - return i; - else if (matchind == -1) - /* First nonexact match found. */ - matchind = i; - else - /* Second nonexact match found. */ - ambiguous = 1; - } - } - if (ambiguous) - return -2; - else - return matchind; -} - -/* Error reporting for argmatch. - KIND is a description of the type of entity that was being matched. - VALUE is the invalid value that was given. - PROBLEM is the return value from argmatch. */ - -void -invalid_arg(const char *kind, char *value, int problem) -{ - fprintf (stderr, "patch: "); - if (problem == -1) - fprintf (stderr, "invalid"); - else /* Assume -2. */ - fprintf (stderr, "ambiguous"); - fprintf (stderr, " %s `%s'\n", kind, value); -} - -static const char *backup_args[] = -{ - "never", "simple", "nil", "existing", "t", "numbered", 0 -}; - -static enum backup_type backup_types[] = -{ - simple, simple, numbered_existing, numbered_existing, numbered, numbered -}; - -/* Return the type of backup indicated by VERSION. - Unique abbreviations are accepted. */ - -enum backup_type -get_version(char *version) -{ - int i; - - if (version == 0 || *version == 0) - return numbered_existing; - i = argmatch (version, backup_args); - if (i >= 0) - return backup_types[i]; - invalid_arg ("version control type", version, i); - exit (1); -} -#endif /* NODIR */ - -/* Append to FILENAME the extension EXT, unless the result would be too long, - in which case just append the character E. */ - -void -addext(char *filename, char *ext, int e) -{ - char *s = (char *)(uintptr_t)(const void *)basename (filename); - int slen = strlen (s), extlen = strlen (ext); - long slen_max = -1; - -#if HAVE_PATHCONF && defined (_PC_NAME_MAX) -#ifndef _POSIX_NAME_MAX -#define _POSIX_NAME_MAX 14 -#endif - if (slen + extlen <= _POSIX_NAME_MAX) - /* The file name is so short there's no need to call pathconf. */ - slen_max = _POSIX_NAME_MAX; - else if (s == filename) - slen_max = pathconf (".", _PC_NAME_MAX); - else - { - char c = *s; - *s = 0; - slen_max = pathconf (filename, _PC_NAME_MAX); - *s = c; - } -#endif - if (slen_max == -1) { -#ifdef HAVE_LONG_FILE_NAMES - slen_max = 255; -#else - slen_max = 14; -#endif - } - if (slen + extlen <= slen_max) - strcpy (s + slen, ext); - else - { - if (slen_max <= slen) { - /* Try to preserve difference between .h .c etc. */ - if (slen == slen_max && s[slen - 2] == '.') - s[slen - 2] = s[slen - 1]; - - slen = slen_max - 1; - } - s[slen] = e; - s[slen + 1] = 0; - } -} diff --git a/gnu/usr.bin/patch/backupfile.h b/gnu/usr.bin/patch/backupfile.h deleted file mode 100644 index 7600714..0000000 --- a/gnu/usr.bin/patch/backupfile.h +++ /dev/null @@ -1,44 +0,0 @@ -/* backupfile.h -- declarations for making Emacs style backup file names - Copyright (C) 1990, 1991, 1992 Free Software Foundation, Inc. - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2, or (at your option) - any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ - -/* - * $FreeBSD$ - */ - -/* When to make backup files. */ -enum backup_type -{ - /* Never make backups. */ - none, - - /* Make simple backups of every file. */ - simple, - - /* Make numbered backups of files that already have numbered backups, - and simple backups of the others. */ - numbered_existing, - - /* Make numbered backups of every file. */ - numbered -}; - -extern enum backup_type backup_type; -extern char *simple_backup_suffix; - -char *find_backup_file_name (char *_file); -enum backup_type get_version(char *_version); -void addext(char *_filename, char *_ext, int _e); diff --git a/gnu/usr.bin/patch/common.h b/gnu/usr.bin/patch/common.h deleted file mode 100644 index aa19105..0000000 --- a/gnu/usr.bin/patch/common.h +++ /dev/null @@ -1,195 +0,0 @@ -/* $FreeBSD$ - * - * $Log: common.h,v $ - * Revision 2.0.1.2 88/06/22 20:44:53 lwall - * patch12: sprintf was declared wrong - * - * Revision 2.0.1.1 88/06/03 15:01:56 lwall - * patch10: support for shorter extensions. - * - * Revision 2.0 86/09/17 15:36:39 lwall - * Baseline for netwide release. - * - */ - -#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 Sprintf (void)sprintf -#define Snprintf (void)snprintf -#define Mktemp (void)mktemp -#define Strcpy (void)strcpy -#define Strcat (void)strcat -#define Strlcpy (void)strlcpy -#define Strncpy (void)strncpy -#define Strlcat (void)strlcat - -/* 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 -#include -#include -#include -#include -#include -#undef malloc -#undef realloc - -/* constants */ - -/* AIX predefines these. */ -#ifdef TRUE -#undef TRUE -#endif -#ifdef FALSE -#undef FALSE -#endif -#define TRUE (1) -#define FALSE (0) - -#define MAXHUNKSIZE 200000 /* is this enough lines? */ -#define INITHUNKMAX 125 /* initial dynamic allocation size */ -#define INITLINELEN 4096 -#define BUFFERSIZE 4096 - -#define SCCSPREFIX "s." -#define GET "get %s" -#define GET_LOCKED "get -e %s" -#define SCCSDIFF "get -p %s | diff - %s >/dev/null" - -#define RCSSUFFIX ",v" -#define CHECKOUT "co %s" -#define CHECKOUT_LOCKED "co -l %s" -#define RCSDIFF "rcsdiff %s > /dev/null" - -/* handy definitions */ - -#define Null(t) ((t)0) -#define Nullch Null(char *) -#define Nullfp Null(FILE *) -#define Nulline Null(LINENUM) - -#define Ctl(ch) ((ch) & 037) - -#define strNE(s1,s2) (strcmp(s1, s2)) -#define strEQ(s1,s2) (!strcmp(s1, s2)) -#define strnNE(s1,s2,l) (strncmp(s1, s2, l)) -#define strnEQ(s1,s2,l) (!strncmp(s1, s2, l)) - -/* typedefs */ - -typedef char bool; -typedef long LINENUM; /* must be signed */ -typedef unsigned MEM; /* what to feed malloc */ - -/* globals */ - -EXT int Argc; /* guess */ -EXT char **Argv; -EXT int optind_last; /* for restarting plan_b */ - -EXT struct stat filestat; /* file statistics area */ -EXT int filemode INIT(0644); - -EXT char *buf; /* general purpose buffer */ -EXT size_t buf_size; /* size of the general purpose buffer */ -EXT FILE *ofp INIT(Nullfp); /* output file pointer */ -EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */ - -EXT int myuid; /* cache getuid return value */ - -EXT bool using_plan_a INIT(TRUE); /* try to keep everything in memory */ -EXT bool out_of_mem INIT(FALSE); /* ran out of memory in plan a */ - -#define MAXFILEC 2 -EXT int filec INIT(0); /* how many file arguments? */ -EXT char *filearg[MAXFILEC]; -EXT bool ok_to_create_file INIT(FALSE); -EXT char *bestguess INIT(Nullch); /* guess at correct filename */ - -EXT char *outname INIT(Nullch); -EXT char rejname[128]; - -EXT char *origprae INIT(Nullch); - -EXT char *TMPOUTNAME; -EXT char *TMPINNAME; -EXT char *TMPREJNAME; -EXT char *TMPPATNAME; -EXT bool toutkeep INIT(FALSE); -EXT bool trejkeep INIT(FALSE); - -EXT LINENUM last_offset INIT(0); -#ifdef DEBUGGING -EXT int debug INIT(0); -#endif -EXT LINENUM maxfuzz INIT(2); -EXT bool force INIT(FALSE); -EXT bool batch INIT(FALSE); -EXT bool verbose INIT(TRUE); -EXT bool reverse INIT(FALSE); -EXT bool noreverse INIT(FALSE); -EXT bool skip_rest_of_patch INIT(FALSE); -EXT int strippath INIT(957); -EXT bool canonicalize INIT(FALSE); - -#define CONTEXT_DIFF 1 -#define NORMAL_DIFF 2 -#define ED_DIFF 3 -#define NEW_CONTEXT_DIFF 4 -#define UNI_DIFF 5 -EXT int diff_type INIT(0); - -EXT bool do_defines INIT(FALSE); /* patch using ifdef, ifndef, etc. */ -EXT char if_defined[128]; /* #ifdef xyzzy */ -EXT char not_defined[128]; /* #ifndef xyzzy */ -EXT char else_defined[] INIT("#else\n");/* #else */ -EXT char end_defined[128]; /* #endif xyzzy */ - -EXT char *revision INIT(Nullch); /* prerequisite revision, if any */ - -#include -#ifdef STDC_HEADERS -#include -#include -#else -extern int errno; -FILE *popen(); -char *malloc(); -char *realloc(); -long atol(); -char *getenv(); -char *strcpy(); -char *strcat(); -#endif -char *mktemp(char *); -#ifdef HAVE_UNISTD_H -#include -#else -long lseek(); -#endif -#if defined(_POSIX_VERSION) || defined(HAVE_FCNTL_H) -#include -#endif - -#if !defined(S_ISDIR) && defined(S_IFDIR) -#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) -#endif -#if !defined(S_ISREG) && defined(S_IFREG) -#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) -#endif diff --git a/gnu/usr.bin/patch/config.h b/gnu/usr.bin/patch/config.h deleted file mode 100644 index 177a8c5..0000000 --- a/gnu/usr.bin/patch/config.h +++ /dev/null @@ -1,81 +0,0 @@ -/* config.h. Generated automatically by configure. */ -/* Portability variables. -*- C -*- */ - -/* Define if the system does not support the `const' keyword. */ -/* #undef const */ - -/* Define if the system supports file names longer than 14 characters. */ -#define HAVE_LONG_FILE_NAMES - -/* Define if the system has pathconf(). */ -/* #undef HAVE_PATHCONF */ - -/* Define if the system has strerror(). */ -#define HAVE_STRERROR 1 - -/* Define if the system has ANSI C header files and library functions. */ -#define STDC_HEADERS - -/* Define if the system uses strchr instead of index - and strrchr instead of rindex. */ -#define HAVE_STRING_H 1 - -#if defined(STDC_HEADERS) || defined(HAVE_STRING_H) -#define index strchr -#define rindex strrchr -#endif - -/* Define if the system has unistd.h. */ -#define HAVE_UNISTD_H 1 - -/* Define if the system has fcntl.h. */ -#define HAVE_FCNTL_H 1 - -/* Define as either int or void -- the type that signal handlers return. */ -#define RETSIGTYPE void - -#ifndef RETSIGTYPE -#define RETSIGTYPE void -#endif - -/* Which directory library header to use. */ -#define DIRENT 1 /* dirent.h */ -/* #undef SYSNDIR */ /* sys/ndir.h */ -/* #undef SYSDIR */ /* sys/dir.h */ -/* #undef NDIR */ /* ndir.h */ -/* #undef NODIR */ /* none -- don't make numbered backup files */ - -/* Define if the system lets you pass fewer arguments to a function - than the function actually accepts (in the absence of a prototype). - Defining it makes I/O calls slightly more efficient. - You need not bother defining it unless your C preprocessor chokes on - multi-line arguments to macros. */ -/* #undef CANVARARG */ - -/* Define Reg* as either `register' or nothing, 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 more than once per routine. - - These don't really matter a lot, since most modern C compilers ignore - register declarations and often do a better job of allocating - registers than people do. */ - -#define Reg1 register -#define Reg2 register -#define Reg3 register -#define Reg4 register -#define Reg5 register -#define Reg6 register -#define Reg7 -#define Reg8 -#define Reg9 -#define Reg10 -#define Reg11 -#define Reg12 -#define Reg13 -#define Reg14 -#define Reg15 -#define Reg16 diff --git a/gnu/usr.bin/patch/inp.c b/gnu/usr.bin/patch/inp.c deleted file mode 100644 index 17f8adb..0000000 --- a/gnu/usr.bin/patch/inp.c +++ /dev/null @@ -1,397 +0,0 @@ -/* $FreeBSD$ - * - * $Log: inp.c,v $ - * Revision 2.0.1.1 88/06/03 15:06:13 lwall - * patch10: made a little smarter about sccs files - * - * Revision 2.0 86/09/17 15:37:02 lwall - * Baseline for netwide release. - * - */ - -#include "EXTERN.h" -#include "common.h" -#include "util.h" -#include "pch.h" -#include "INTERN.h" -#include "inp.h" - -/* Input-file-with-indexable-lines abstract type. */ - -static long i_size; /* Size of the input file */ -static char *i_womp; /* Plan a buffer for entire file */ -static char **i_ptr; /* Pointers to lines in i_womp */ - -static int tifd = -1; /* Plan b virtual string array */ -static char *tibuf[2]; /* Plan b buffers */ -static LINENUM tiline[2] = {-1, -1}; /* 1st line in each buffer */ -static LINENUM lines_per_buf; /* How many lines per buffer */ -static int tireclen; /* Length of records in tmp file */ - -/* - * New patch--prepare to edit another file. - */ -void -re_input(void) -{ - if (using_plan_a) { - i_size = 0; -#ifndef lint - if (i_ptr != Null(char**)) - free((char *)i_ptr); -#endif - if (i_womp != Nullch) - free(i_womp); - i_womp = Nullch; - i_ptr = Null(char **); - } else { - using_plan_a = TRUE; /* maybe the next one is smaller */ - Close(tifd); - tifd = -1; - free(tibuf[0]); - free(tibuf[1]); - tibuf[0] = tibuf[1] = Nullch; - tiline[0] = tiline[1] = -1; - tireclen = 0; - } -} - -/* - * Constuct the line index, somehow or other. - */ -void -scan_input(char *filename) -{ - if (!plan_a(filename)) - plan_b(filename); - if (verbose) { - say3("Patching file %s using Plan %s...\n", filename, - (using_plan_a ? "A" : "B") ); - } -} - -/* - * Try keeping everything in memory. - */ -bool -plan_a(char *filename) -{ - int ifd, statfailed; - Reg1 char *s; - Reg2 LINENUM iline; - char lbuf[INITLINELEN]; - int output_elsewhere = strcmp(filename, outname); - extern int check_patch; - - statfailed = stat(filename, &filestat); - if (statfailed && ok_to_create_file) { - if (verbose) - say2("(Creating file %s...)\n",filename); - if (check_patch) - return TRUE; - makedirs(filename, TRUE); - close(creat(filename, 0666)); - statfailed = stat(filename, &filestat); - } - if (statfailed && check_patch) { - fatal2("%s not found and in check_patch mode.", filename); - } - /* - * For nonexistent or read-only files, look for RCS or SCCS - * versions. - */ - if (statfailed || - (! output_elsewhere && - (/* No one can write to it. */ - (filestat.st_mode & 0222) == 0 || - /* I can't write to it. */ - ((filestat.st_mode & 0022) == 0 && filestat.st_uid != myuid)))) { - struct stat cstat; - char *cs = Nullch; - char *filebase; - int pathlen; - - filebase = basename(filename); - pathlen = filebase - filename; - - /* - * Put any leading path into `s'. - * Leave room in lbuf for the diff command. - */ - s = lbuf + 20; - strncpy(s, filename, pathlen); - -#define try(f,a1,a2) (Sprintf(s + pathlen, f, a1, a2), stat(s, &cstat) == 0) - if ((try("RCS/%s%s", filebase, RCSSUFFIX) || - try("RCS/%s%s", filebase, "") || - try("%s%s", filebase, RCSSUFFIX)) && - /* - * Check that RCS file is not working file. - * Some hosts don't report file name length errors. - */ - (statfailed || - ((filestat.st_dev ^ cstat.st_dev) | - (filestat.st_ino ^ cstat.st_ino)))) { - Sprintf(buf, output_elsewhere?CHECKOUT:CHECKOUT_LOCKED, filename); - Sprintf(lbuf, RCSDIFF, filename); - cs = "RCS"; - } else if (try("SCCS/%s%s", SCCSPREFIX, filebase) || - try("%s%s", SCCSPREFIX, filebase)) { - Sprintf(buf, output_elsewhere?GET:GET_LOCKED, s); - Sprintf(lbuf, SCCSDIFF, s, filename); - cs = "SCCS"; - } else if (statfailed) - fatal2("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", - 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", - filename, cs); - if (system(lbuf)) - fatal3( -"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); - if (system(buf) || stat(filename, &filestat)) - fatal3("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); - i_size = filestat.st_size; - if (out_of_mem) { - set_hunkmax(); /* make sure dynamic arrays are allocated */ - out_of_mem = FALSE; - return FALSE; /* force plan b because plan a bombed */ - } -#ifdef lint - i_womp = Nullch; -#else - /* - * Lint says this may alloc less than i_size, - * but that's okay, I think. - */ - i_womp = malloc((MEM)(i_size + 2)); -#endif - 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) { - /* - * This probably means i_size > 15 or 16 bits worth. At - * this point it doesn't matter if i_womp was undersized. - */ - Close(ifd); - free(i_womp); - return FALSE; - } -#endif - Close(ifd); - if (i_size && i_womp[i_size - 1] != '\n') - i_womp[i_size++] = '\n'; - i_womp[i_size] = '\0'; - - /* - * Count the lines in the buffer so we know how many pointers we - * need. - */ - iline = 0; - for (s = i_womp; *s; s++) { - 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; - } - - /* Now scan the buffer and build pointer array. */ - iline = 1; - i_ptr[iline] = i_womp; - for (s = i_womp; *s; s++) { - if (*s == '\n') { - /* These are NOT null terminated. */ - i_ptr[++iline] = s + 1; - } - } - input_lines = iline - 1; - - /* Now check for revision, if any. */ - if (revision != Nullch) { - if (!rev_in_string(i_womp)) { - if (force) { - if (verbose) - say2( -"Warning: this file doesn't appear to be the %s version--patching anyway.\n", - revision); - } else if (batch) { - fatal2( -"this file doesn't appear to be the %s version--aborting.\n", revision); - } else { - (void) ask2( -"This file doesn't appear to be the %s version--patch anyway? [n] ", - revision); - if (*buf != 'y') - fatal1("aborted\n"); - } - } else if (verbose) - say2("Good. This file appears to be the %s version.\n", - revision); - } - - return TRUE; /* Plan a will work. */ -} - -/* - * Keep (virtually) nothing in memory. - */ -void -plan_b(char *filename) -{ - Reg3 FILE *ifp; - Reg1 int i = 0; - Reg2 int maxlen = 1; - Reg4 bool found_revision = (revision == Nullch); - - using_plan_a = FALSE; - if ((ifp = fopen(filename, "r")) == Nullfp) - pfatal2("can't open file %s", filename); - if ((tifd = creat(TMPINNAME, 0666)) < 0) - pfatal2("can't open file %s", TMPINNAME); - while (fgets(buf, buf_size, ifp) != Nullch) { - if (revision != Nullch && !found_revision && rev_in_string(buf)) - found_revision = TRUE; - if ((i = strlen(buf)) > maxlen) - maxlen = i; /* Find longest line. */ - } - if (revision != Nullch) { - if (!found_revision) { - if (force) { - if (verbose) - say2( -"Warning: this file doesn't appear to be the %s version--patching anyway.\n", - revision); - } else if (batch) { - fatal2( -"this file doesn't appear to be the %s version--aborting.\n", revision); - } else { - (void) ask2( -"This file doesn't appear to be the %s version--patch anyway? [n] ", - revision); - if (*buf != 'y') - fatal1("aborted\n"); - } - } else if (verbose) - say2("Good. This file appears to be the %s version.\n", - revision); - } - Fseek(ifp, 0L, 0); /* Rewind file. */ - lines_per_buf = BUFFERSIZE / maxlen; - tireclen = maxlen; - tibuf[0] = malloc((MEM)(BUFFERSIZE + 1)); - tibuf[1] = malloc((MEM)(BUFFERSIZE + 1)); - if (tibuf[1] == Nullch) - fatal1("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"); - 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"); - break; - } - } - Fclose(ifp); - Close(tifd); - if ((tifd = open(TMPINNAME, 0)) < 0) { - pfatal2("can't reopen file %s", TMPINNAME); - } -} - -/* - * 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 */ -{ - if (line < 1 || line > input_lines) - return ""; - if (using_plan_a) - return i_ptr[line]; - else { - LINENUM offline = line % lines_per_buf; - LINENUM baseline = line - offline; - - if (tiline[0] == baseline) - whichbuf = 0; - else if (tiline[1] == baseline) - whichbuf = 1; - else { - tiline[whichbuf] = baseline; -#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); - } - return tibuf[whichbuf] + (tireclen * offline); - } -} - -/* - * True if the string argument contains the revision number we want. - */ -bool -rev_in_string(char *string) -{ - Reg1 char *s; - Reg2 int patlen; - - if (revision == Nullch) - return TRUE; - patlen = strlen(revision); - if (strnEQ(string,revision,patlen) && - isspace((unsigned char)string[patlen])) - return TRUE; - for (s = string; *s; s++) { - if (isspace((unsigned char)*s) && - strnEQ(s + 1, revision, patlen) && - isspace((unsigned char)s[patlen + 1] )) { - return TRUE; - } - } - return FALSE; -} diff --git a/gnu/usr.bin/patch/inp.h b/gnu/usr.bin/patch/inp.h deleted file mode 100644 index f1f0386..0000000 --- a/gnu/usr.bin/patch/inp.h +++ /dev/null @@ -1,18 +0,0 @@ -/* $FreeBSD$ - * - * $Log: inp.h,v $ - * Revision 2.0 86/09/17 15:37:25 lwall - * Baseline for netwide release. - * - */ - -EXT LINENUM input_lines INIT(0); /* how long is input file in lines */ -EXT LINENUM last_frozen_line INIT(0); /* how many input lines have been */ - /* irretractibly output */ -void re_input(void); -void scan_input(char *_filename); -bool plan_a(char *_filename); -void plan_b(char *_filename); -bool rev_in_string(char *_string); -char *ifetch(LINENUM _line, int _whichbuf); - diff --git a/gnu/usr.bin/patch/patch.1 b/gnu/usr.bin/patch/patch.1 deleted file mode 100644 index 3cc7957..0000000 --- a/gnu/usr.bin/patch/patch.1 +++ /dev/null @@ -1,594 +0,0 @@ -.\" -*- nroff -*- -.rn '' }` -'\" $Header: patch.man,v 2.0.1.2 88/06/22 20:47:18 lwall Locked $ -'\" $FreeBSD$ -'\" -'\" $Log: patch.man,v $ -'\" Revision 2.0.1.2 88/06/22 20:47:18 lwall -'\" patch12: now avoids Bell System Logo -'\" -'\" Revision 2.0.1.1 88/06/03 15:12:51 lwall -'\" patch10: -B switch was contributed. -'\" -'\" Revision 2.0 86/09/17 15:39:09 lwall -'\" Baseline for netwide release. -'\" -'\" Revision 1.4 86/08/01 19:23:22 lwall -'\" Documented -v, -p, -F. -'\" Added notes to patch senders. -'\" -'\" Revision 1.3 85/03/26 15:11:06 lwall -'\" Frozen. -'\" -'\" Revision 1.2.1.4 85/03/12 16:14:27 lwall -'\" Documented -p. -'\" -'\" Revision 1.2.1.3 85/03/12 16:09:41 lwall -'\" Documented -D. -'\" -'\" Revision 1.2.1.2 84/12/05 11:06:55 lwall -'\" Added -l switch, and noted bistability bug. -'\" -'\" Revision 1.2.1.1 84/12/04 17:23:39 lwall -'\" Branch for sdcrdcf changes. -'\" -'\" Revision 1.2 84/12/04 17:22:02 lwall -'\" Baseline version. -'\" -.de Sh -.br -.ne 5 -.PP -\fB\\$1\fR -.PP -.. -.de Sp -.if t .sp .5v -.if n .sp -.. -'\" -'\" Set up \*(-- to give an unbreakable dash; -'\" string Tr holds user defined translation string. -'\" Bell System Logo is used as a dummy character. -'\" -.if !d Tr .ds Tr -.ie n \{\ -.tr \(*W-\*(Tr -.ds -- \(*W- -.if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch -.if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch -.ds L" "" -.ds R" "" -.ds L' ' -.ds R' ' -'br \} -.el \{\ -.ds -- \(em\| -.tr \*(Tr -.ds L" `` -.ds R" '' -.ds L' ` -.ds R' ' -'br\} -.TH PATCH 1 LOCAL -.SH NAME -patch - apply a diff file to an original -.SH SYNOPSIS -.B patch -[options] [origfile [patchfile]] [+ [options] [origfile]]... -.sp -but usually just -.sp -.B patch - -.br -with many other contributors. -.SH ENVIRONMENT -.TP -.B TMPDIR -Directory to put temporary files in; default is /tmp. -.TP -.B SIMPLE_BACKUP_SUFFIX -Extension to use for backup file names instead of \*(L".orig\*(R" or -\*(L"~\*(R". -.TP -.B VERSION_CONTROL -Selects when numbered backup files are made. -.SH FILES -$TMPDIR/patch* -.SH SEE ALSO -diff(1) -.SH NOTES FOR PATCH SENDERS -There are several things you should bear in mind if you are going to -be sending out patches. -First, you can save people a lot of grief by keeping a patchlevel.h file -which is patched to increment the patch level as the first diff in the -patch file you send out. -If you put a Prereq: line in with the patch, it won't let them apply -patches out of order without some warning. -Second, make sure you've specified the file names right, either in a -context diff header, or with an Index: line. -If you are patching something in a subdirectory, be sure to tell the patch -user to specify a -.B \-p -option as needed. -Third, you can create a file by sending out a diff that compares a -null file to the file you want to create. -This will only work if the file you want to create doesn't exist already in -the target directory. -Fourth, take care not to send out reversed patches, since it makes people wonder -whether they already applied the patch. -Fifth, while you may be able to get away with putting 582 diff listings into -one file, it is probably wiser to group related patches into separate files in -case something goes haywire. -.SH DIAGNOSTICS -Too many to list here, but generally indicative that -.I patch -couldn't parse your patch file. -.PP -The message \*(L"Hmm...\*(R" indicates that there is unprocessed text in -the patch file and that -.I patch -is attempting to intuit whether there is a patch in that text and, if so, -what kind of patch it is. -.PP -.I Patch -will exit with a non-zero status if any reject files were created. -When applying a set of patches in a loop it behooves you to check this -exit status so you don't apply a later patch to a partially patched file. -.SH CAVEATS -.I Patch -cannot tell if the line numbers are off in an -.I ed -script, and can only detect -bad line numbers in a normal diff when it finds a \*(L"change\*(R" or -a \*(L"delete\*(R" command. -A context diff using fuzz factor 3 may have the same problem. -Until a suitable interactive interface is added, you should probably do -a context diff in these cases to see if the changes made sense. -Of course, compiling without errors is a pretty good indication that the patch -worked, but not always. -.PP -.I Patch -usually produces the correct results, even when it has to do a lot of -guessing. -However, the results are guaranteed to be correct only when the patch is -applied to exactly the same version of the file that the patch was -generated from. -.SH BUGS -Could be smarter about partial matches, excessively \&deviant offsets and -swapped code, but that would take an extra pass. -.PP -If code has been duplicated (for instance with #ifdef OLDCODE ... #else ... -#endif), -.I patch -is incapable of patching both versions, and, if it works at all, will likely -patch the wrong one, and tell you that it succeeded to boot. -.PP -If you apply a patch you've already applied, -.I patch -will think it is a reversed patch, and offer to un-apply the patch. -This could be construed as a feature. -.rn }` '' diff --git a/gnu/usr.bin/patch/patch.c b/gnu/usr.bin/patch/patch.c deleted file mode 100644 index fbf7e70..0000000 --- a/gnu/usr.bin/patch/patch.c +++ /dev/null @@ -1,971 +0,0 @@ -char rcsid[] = - "$FreeBSD$"; - -/* patch - a program to apply diffs to original files - * - * Copyright 1986, Larry Wall - * - * This program may be copied as long as you don't try to make any - * money off of it, or pretend that you wrote it. - * - * $Log: patch.c,v $ - * Revision 2.0.2.0 90/05/01 22:17:50 davison - * patch12u: unidiff support added - * - * Revision 2.0.1.6 88/06/22 20:46:39 lwall - * patch12: rindex() wasn't declared - * - * Revision 2.0.1.5 88/06/03 15:09:37 lwall - * patch10: exit code improved. - * patch10: better support for non-flexfilenames. - * - * Revision 2.0.1.4 87/02/16 14:00:04 lwall - * Short replacement caused spurious "Out of sync" message. - * - * Revision 2.0.1.3 87/01/30 22:45:50 lwall - * Improved diagnostic on sync error. - * Moved do_ed_script() to pch.c. - * - * Revision 2.0.1.2 86/11/21 09:39:15 lwall - * Fuzz factor caused offset of installed lines. - * - * Revision 2.0.1.1 86/10/29 13:10:22 lwall - * Backwards search could terminate prematurely. - * - * Revision 2.0 86/09/17 15:37:32 lwall - * Baseline for netwide release. - * - * Revision 1.5 86/08/01 20:53:24 lwall - * Changed some %d's to %ld's. - * Linted. - * - * Revision 1.4 86/08/01 19:17:29 lwall - * Fixes for machines that can't vararg. - * Added fuzz factor. - * Generalized -p. - * General cleanup. - * - * 85/08/15 van%ucbmonet@berkeley - * Changes for 4.3bsd diff -c. - * - * Revision 1.3 85/03/26 15:07:43 lwall - * Frozen. - * - * Revision 1.2.1.9 85/03/12 17:03:35 lwall - * Changed pfp->_file to fileno(pfp). - * - * Revision 1.2.1.8 85/03/12 16:30:43 lwall - * Check i_ptr and i_womp to make sure they aren't null before freeing. - * Also allow ed output to be suppressed. - * - * Revision 1.2.1.7 85/03/12 15:56:13 lwall - * Added -p option from jromine@uci-750a. - * - * Revision 1.2.1.6 85/03/12 12:12:51 lwall - * Now checks for normalness of file to patch. - * - * Revision 1.2.1.5 85/03/12 11:52:12 lwall - * Added -D (#ifdef) option from joe@fluke. - * - * Revision 1.2.1.4 84/12/06 11:14:15 lwall - * Made smarter about SCCS subdirectories. - * - * Revision 1.2.1.3 84/12/05 11:18:43 lwall - * Added -l switch to do loose string comparison. - * - * Revision 1.2.1.2 84/12/04 09:47:13 lwall - * Failed hunk count not reset on multiple patch file. - * - * Revision 1.2.1.1 84/12/04 09:42:37 lwall - * Branch for sdcrdcf changes. - * - * Revision 1.2 84/11/29 13:29:51 lwall - * Linted. Identifiers uniqified. Fixed i_ptr malloc() bug. Fixed - * multiple calls to mktemp(). Will now work on machines that can only - * read 32767 chars. Added -R option for diffs with new and old swapped. - * Various cosmetic changes. - * - * Revision 1.1 84/11/09 17:03:58 lwall - * Initial revision - * - */ - -#include -#include "INTERN.h" -#include "common.h" -#include "EXTERN.h" -#include "version.h" -#include "util.h" -#include "pch.h" -#include "inp.h" -#include "backupfile.h" -#include "getopt.h" - -/* procedures */ - -void reinitialize_almost_everything(void); -void get_some_switches(void); -LINENUM locate_hunk(LINENUM _fuzz); -void abort_hunk(void); -void apply_hunk(LINENUM _where); -void init_output(char *_name); -void init_reject(char *_name); -void copy_till(LINENUM _lastline); -void spew_output(void); -void dump_line(LINENUM _line); -bool patch_match(LINENUM _base, LINENUM _offset, LINENUM _fuzz); -bool similar(char *_a, char *_b, int _len); -void my_exit(int _status); - - -/* TRUE if -E was specified on command line. */ -static int remove_empty_files = FALSE; - -/* TRUE if -R was specified on command line. */ -static int reverse_flag_specified = FALSE; - -/* TRUE if -C was specified on command line. */ -int check_patch = FALSE; - -/* TRUE if -I was specified on command line */ -/* or PATCH_INDEX_FIRST env. variable is set */ -int index_first; - -/* TRUE if -S was specified on command line. */ -int skip_flag_specified = FALSE; - -/* Apply a set of diffs as appropriate. */ - -int -main(argc,argv) -int argc; -char **argv; -{ - LINENUM where; - LINENUM newwhere; - LINENUM fuzz; - LINENUM mymaxfuzz; - int hunk = 0; - int failed = 0; - int failtotal = 0; - bool rev_okayed = 0; - int i; - - setbuf(stderr, serrbuf); - for (i = 0; i= 0) ; /* while is for Eunice. */ - } - } - Fclose(rejfp); - rejfp = Nullfp; - if (failed) { - failtotal += failed; - if (!*rejname) { - Strlcpy(rejname, outname, sizeof(rejname)); - addext(rejname, ".rej", '#'); - } - if (skip_rest_of_patch) { - say4("%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", - failed, hunk, rejname); - } - if (check_patch) { - ; - } else if (move_file(TMPREJNAME, rejname) < 0) - trejkeep = TRUE; - } - set_signals(1); - } - my_exit(failtotal); - return (failtotal); -} - -/* Prepare to find the next patch to do in the patch file. */ - -void -reinitialize_almost_everything(void) -{ - re_patch(); - re_input(); - - input_lines = 0; - last_frozen_line = 0; - - filec = 0; - if (filearg[0] != Nullch && !out_of_mem) { - free(filearg[0]); - filearg[0] = Nullch; - } - - if (outname != Nullch) { - free(outname); - outname = Nullch; - } - - last_offset = 0; - - diff_type = 0; - - if (revision != Nullch) { - free(revision); - revision = Nullch; - } - - reverse = reverse_flag_specified; - skip_rest_of_patch = FALSE; - skip_flag_specified = FALSE; - - get_some_switches(); - - if (filec >= 2) - fatal1("you may not change to a different patch file\n"); -} - -static char *shortopts = "-b:B:cCd:D:eEfF:i:IlnNo:p::r:RsStuvV:x:"; -static struct option longopts[] = -{ - {"suffix", 1, NULL, 'b'}, - {"prefix", 1, NULL, 'B'}, - {"check", 0, NULL, 'C'}, - {"context", 0, NULL, 'c'}, - {"directory", 1, NULL, 'd'}, - {"ifdef", 1, NULL, 'D'}, - {"ed", 0, NULL, 'e'}, - {"remove-empty-files", 0, NULL, 'E'}, - {"force", 0, NULL, 'f'}, - {"fuzz", 1, NULL, 'F'}, - {"index-first", 0, NULL, 'I'}, - {"ignore-whitespace", 0, NULL, 'l'}, - {"normal", 0, NULL, 'n'}, - {"forward", 0, NULL, 'N'}, - {"output", 1, NULL, 'o'}, - {"strip", 2, NULL, 'p'}, - {"reject-file", 1, NULL, 'r'}, - {"reverse", 0, NULL, 'R'}, - {"quiet", 0, NULL, 's'}, - {"silent", 0, NULL, 's'}, - {"skip", 0, NULL, 'S'}, - {"batch", 0, NULL, 't'}, - {"unified", 0, NULL, 'u'}, - {"version", 0, NULL, 'v'}, - {"version-control", 1, NULL, 'V'}, - {"debug", 1, NULL, 'x'}, - {0, 0, 0, 0} -}; - -/* Process switches and filenames up to next '+' or end of list. */ - -void -get_some_switches(void) -{ - Reg1 int optc; - - rejname[0] = '\0'; - optind_last = optind; - if (optind == Argc) - return; - while ((optc = getopt_long (Argc, Argv, shortopts, longopts, (int *) 0)) - != -1) { - if (optc == 1) { - if (strEQ(optarg, "+")) - return; - if (filec == MAXFILEC) - fatal1("too many file arguments\n"); - filearg[filec++] = savestr(optarg); - } - else { - switch (optc) { - case 'b': - simple_backup_suffix = savestr(optarg); - break; - case 'B': - origprae = savestr(optarg); - break; - case 'c': - diff_type = CONTEXT_DIFF; - break; - case 'C': - check_patch = TRUE; - break; - case 'd': - if (chdir(optarg) < 0) - pfatal2("can't cd to %s", optarg); - break; - case 'D': - do_defines = TRUE; - if (!isalpha((unsigned char)*optarg) && '_' != *optarg) - fatal1("argument to -D is not an identifier\n"); - Snprintf(if_defined, sizeof(if_defined), "#ifdef %s\n", optarg); - Snprintf(not_defined, sizeof(not_defined), "#ifndef %s\n", optarg); - Snprintf(end_defined, sizeof(end_defined), "#endif /* %s */\n", optarg); - break; - case 'e': - diff_type = ED_DIFF; - break; - case 'E': - remove_empty_files = TRUE; - break; - case 'f': - force = TRUE; - break; - case 'F': - maxfuzz = atoi(optarg); - break; - case 'i': - filearg[1] = savestr(optarg); - break; - case 'I': - index_first = TRUE; - break; - case 'l': - canonicalize = TRUE; - break; - case 'n': - diff_type = NORMAL_DIFF; - break; - case 'N': - noreverse = TRUE; - break; - case 'o': - outname = savestr(optarg); - break; - case 'p': - if (optarg) - strippath = atoi(optarg); - else - strippath = 0; - break; - case 'r': - Strlcpy(rejname, optarg, sizeof(rejname)); - break; - case 'R': - reverse = TRUE; - reverse_flag_specified = TRUE; - break; - case 's': - verbose = FALSE; - break; - case 'S': - skip_rest_of_patch = TRUE; - skip_flag_specified = TRUE; - break; - case 't': - batch = TRUE; - break; - case 'u': - diff_type = UNI_DIFF; - break; - case 'v': - version(); - break; - case 'V': -#ifndef NODIR - backup_type = get_version (optarg); -#endif - break; -#ifdef DEBUGGING - case 'x': - debug = atoi(optarg); - break; -#endif - default: - fprintf(stderr, "\ -Usage: %s [options] [origfile [patchfile]] [+ [options] [origfile]]...\n", - Argv[0]); - fprintf(stderr, "\ -Options:\n\ - [-cCeEflnNRsStuv] [-b backup-ext] [-B backup-prefix] [-d directory]\n\ - [-D symbol] [-F max-fuzz] [-i patchfile] [-o out-file] [-p[strip-count]]\n\ - [-r rej-name] [-V {numbered,existing,simple}] [--check] [--context]\n\ - [--prefix=backup-prefix] [--suffix=backup-ext] [--ifdef=symbol]\n\ - [--directory=directory] [--ed] [--fuzz=max-fuzz] [--force] [--batch]\n\ - [--ignore-whitespace] [--forward] [--reverse] [--output=out-file]\n"); - fprintf(stderr, "\ - [--strip[=strip-count]] [--normal] [--reject-file=rej-name] [--skip]\n\ - [--remove-empty-files] [--quiet] [--silent] [--unified] [--version]\n\ - [--version-control={numbered,existing,simple}] [--index-first]\n"); - my_exit(1); - } - } - } - - /* Process any filename args given after "--". */ - for (; optind < Argc; ++optind) { - if (filec == MAXFILEC) - fatal1("too many file arguments\n"); - filearg[filec++] = savestr(Argv[optind]); - } -} - -/* - * Attempt to find the right place to apply this hunk of patch. - */ -LINENUM -locate_hunk(LINENUM fuzz) -{ - Reg1 LINENUM first_guess = pch_first() + last_offset; - Reg2 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 - + pch_context(); - - if (!pat_lines) /* null range matches always */ - return first_guess; - if (max_neg_offset >= first_guess) /* do not try lines < 0 */ - max_neg_offset = first_guess - 1; - 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); - - 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); -#endif - last_offset = offset; - return first_guess+offset; - } - 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); -#endif - last_offset = -offset; - return first_guess-offset; - } - else if (!check_before && !check_after) - return Nulline; - } -} - -/* We did not find the pattern, dump out the hunk so they can handle it. */ - -void -abort_hunk(void) -{ - Reg1 LINENUM i; - Reg2 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; - LINENUM oldlast = oldfirst + pch_ptrn_lines() - 1; - LINENUM newlast = newfirst + pch_repl_lines() - 1; - char *stars = (diff_type >= NEW_CONTEXT_DIFF ? " ****" : ""); - char *minuses = (diff_type >= NEW_CONTEXT_DIFF ? " ----" : " -----"); - - fprintf(rejfp, "***************\n"); - for (i=0; i<=pat_end; i++) { - switch (pch_char(i)) { - case '*': - if (oldlast < oldfirst) - fprintf(rejfp, "*** 0%s\n", stars); - else if (oldlast == oldfirst) - fprintf(rejfp, "*** %ld%s\n", oldfirst, stars); - else - fprintf(rejfp, "*** %ld,%ld%s\n", oldfirst, oldlast, stars); - break; - case '=': - if (newlast < newfirst) - fprintf(rejfp, "--- 0%s\n", minuses); - else if (newlast == newfirst) - fprintf(rejfp, "--- %ld%s\n", newfirst, minuses); - else - fprintf(rejfp, "--- %ld,%ld%s\n", newfirst, newlast, minuses); - break; - case '\n': - fprintf(rejfp, "%s", pfetch(i)); - break; - case ' ': case '-': case '+': case '!': - fprintf(rejfp, "%c %s", pch_char(i), pfetch(i)); - break; - default: - fatal1("fatal internal error in abort_hunk\n"); - } - } -} - -/* - * We found where to apply it (we hope), so do it. - */ -void -apply_hunk(LINENUM where) -{ - Reg1 LINENUM old = 1; - Reg2 LINENUM lastline = pch_ptrn_lines(); - Reg3 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(); - - where--; - while (pch_char(new) == '=' || pch_char(new) == '\n') - new++; - - while (old <= lastline) { - if (pch_char(old) == '-') { - copy_till(where + old - 1); - if (R_do_defines) { - if (def_state == OUTSIDE) { - fputs(not_defined, ofp); - def_state = IN_IFNDEF; - } - else if (def_state == IN_IFDEF) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } - fputs(pfetch(old), ofp); - } - last_frozen_line++; - old++; - } - else if (new > pat_end) { - break; - } - else if (pch_char(new) == '+') { - copy_till(where + old - 1); - if (R_do_defines) { - if (def_state == IN_IFNDEF) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } - else if (def_state == OUTSIDE) { - fputs(if_defined, ofp); - def_state = IN_IFDEF; - } - } - fputs(pfetch(new), ofp); - new++; - } - else if (pch_char(new) != pch_char(old)) { - say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n", - pch_hunk_beg() + old, - pch_hunk_beg() + new); -#ifdef DEBUGGING - say3("oldchar = '%c', newchar = '%c'\n", - pch_char(old), pch_char(new)); -#endif - my_exit(1); - } - else if (pch_char(new) == '!') { - copy_till(where + old - 1); - if (R_do_defines) { - fputs(not_defined, ofp); - def_state = IN_IFNDEF; - } - while (pch_char(old) == '!') { - if (R_do_defines) { - fputs(pfetch(old), ofp); - } - last_frozen_line++; - old++; - } - if (R_do_defines) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } - while (pch_char(new) == '!') { - fputs(pfetch(new), ofp); - new++; - } - } - else { - assert(pch_char(new) == ' '); - old++; - new++; - if (R_do_defines && def_state != OUTSIDE) { - fputs(end_defined, ofp); - def_state = OUTSIDE; - } - } - } - if (new <= pat_end && pch_char(new) == '+') { - copy_till(where + old - 1); - if (R_do_defines) { - if (def_state == OUTSIDE) { - fputs(if_defined, ofp); - def_state = IN_IFDEF; - } - else if (def_state == IN_IFNDEF) { - fputs(else_defined, ofp); - def_state = IN_ELSE; - } - } - while (new <= pat_end && pch_char(new) == '+') { - fputs(pfetch(new), ofp); - new++; - } - } - if (R_do_defines && def_state != OUTSIDE) { - fputs(end_defined, ofp); - } -} - -/* Open the new file. */ - -void -init_output(char *name) -{ - ofp = fopen(name, "w"); - if (ofp == Nullfp) - pfatal2("can't create %s", name); -} - -/* Open a file to put hunks we can't locate. */ - -void -init_reject(char *name) -{ - rejfp = fopen(name, "w"); - if (rejfp == Nullfp) - pfatal2("can't create %s", name); -} - -/* Copy input file to output, up to wherever hunk is to be applied. */ - -void -copy_till(LINENUM lastline) -{ - Reg2 LINENUM R_last_frozen_line = last_frozen_line; - - if (R_last_frozen_line > lastline) - fatal1("misordered hunks! output would be garbled\n"); - while (R_last_frozen_line < lastline) { - dump_line(++R_last_frozen_line); - } - last_frozen_line = R_last_frozen_line; -} - -/* Finish copying the input file to the output file. */ - -void -spew_output(void) -{ -#ifdef DEBUGGING - if (debug & 256) - say3("il=%ld lfl=%ld\n",input_lines,last_frozen_line); -#endif - if (input_lines) - copy_till(input_lines); /* dump remainder of file */ - Fclose(ofp); - ofp = Nullfp; -} - -/* Copy one line from input to output. */ - -void -dump_line(LINENUM line) -{ - Reg1 char *s; - Reg2 char R_newline = '\n'; - - /* Note: string is not null terminated. */ - for (s=ifetch(line, 0); putc(*s, ofp) != R_newline; s++) ; -} - -/* Does the patch pattern match at line base+offset? */ - -bool -patch_match(LINENUM base, LINENUM offset, LINENUM fuzz) -{ - Reg1 LINENUM pline = 1 + fuzz; - Reg2 LINENUM iline; - Reg3 LINENUM pat_lines = pch_ptrn_lines() - fuzz; - - for (iline=base+offset+fuzz; pline <= pat_lines; pline++,iline++) { - if (canonicalize) { - if (!similar(ifetch(iline, (offset >= 0)), - pfetch(pline), - pch_line_len(pline) )) - return FALSE; - } - else if (strnNE(ifetch(iline, (offset >= 0)), - pfetch(pline), - pch_line_len(pline) )) - return FALSE; - } - return TRUE; -} - -/* Do two lines match with canonicalized white space? */ - -bool -similar(char *a, char *b, int len) -{ - while (len) { - if (isspace((unsigned char)*b)) { /* whitespace (or \n) to match? */ - if (!isspace((unsigned char)*a)) /* no corresponding whitespace? */ - return FALSE; - while (len && isspace((unsigned char)*b) && *b != '\n') - b++,len--; /* skip pattern whitespace */ - while (isspace((unsigned char)*a) && *a != '\n') - a++; /* skip target whitespace */ - if (*a == '\n' || *b == '\n') - return (*a == *b); /* should end in sync */ - } - else if (*a++ != *b++) /* match non-whitespace chars */ - return FALSE; - else - len--; /* probably not necessary */ - } - return TRUE; /* actually, this is not reached */ - /* since there is always a \n */ -} - -/* Exit with cleanup. */ - -void -my_exit(int status) -{ - Unlink(TMPINNAME); - if (!toutkeep) { - Unlink(TMPOUTNAME); - } - if (!trejkeep) { - Unlink(TMPREJNAME); - } - Unlink(TMPPATNAME); - exit(status); -} diff --git a/gnu/usr.bin/patch/patchlevel.h b/gnu/usr.bin/patch/patchlevel.h deleted file mode 100644 index d5de3a9..0000000 --- a/gnu/usr.bin/patch/patchlevel.h +++ /dev/null @@ -1 +0,0 @@ -#define PATCH_VERSION "2.1" diff --git a/gnu/usr.bin/patch/pch.c b/gnu/usr.bin/patch/pch.c deleted file mode 100644 index 37bbe56..0000000 --- a/gnu/usr.bin/patch/pch.c +++ /dev/null @@ -1,1449 +0,0 @@ -/* $FreeBSD$ - * - * $Log: pch.c,v $ - * Revision 2.0.2.0 90/05/01 22:17:51 davison - * patch12u: unidiff support added - * - * Revision 2.0.1.7 88/06/03 15:13:28 lwall - * patch10: Can now find patches in shar scripts. - * patch10: Hunks that swapped and then swapped back could core dump. - * - * Revision 2.0.1.6 87/06/04 16:18:13 lwall - * pch_swap didn't swap p_bfake and p_efake. - * - * Revision 2.0.1.5 87/01/30 22:47:42 lwall - * Improved responses to mangled patches. - * - * Revision 2.0.1.4 87/01/05 16:59:53 lwall - * New-style context diffs caused double call to free(). - * - * Revision 2.0.1.3 86/11/14 10:08:33 lwall - * Fixed problem where a long pattern wouldn't grow the hunk. - * Also restored p_input_line when backtracking so error messages are right. - * - * Revision 2.0.1.2 86/11/03 17:49:52 lwall - * New-style delete triggers spurious assertion error. - * - * Revision 2.0.1.1 86/10/29 15:52:08 lwall - * Could falsely report new-style context diff. - * - * Revision 2.0 86/09/17 15:39:37 lwall - * Baseline for netwide release. - * - */ - -#include "EXTERN.h" -#include "common.h" -#include "util.h" -#include "INTERN.h" -#include "pch.h" - -/* Patch (diff listing) abstract type. */ - -static long p_filesize; /* size of the patch file */ -static LINENUM p_first; /* 1st line number */ -static LINENUM p_newfirst; /* 1st line number of replacement */ -static LINENUM p_ptrn_lines; /* # lines in pattern */ -static LINENUM p_repl_lines; /* # lines in replacement text */ -static LINENUM p_end = -1; /* last line in hunk */ -static LINENUM p_max; /* max allowed value of p_end */ -static LINENUM p_context = 3; /* # of context lines */ -static LINENUM p_input_line = 0; /* current line # from patch file */ -static char **p_line = Null(char**); /* the text of the hunk */ -static short *p_len = Null(short*); /* length of each line */ -static char *p_Char = Nullch; /* +, -, and ! */ -static int hunkmax = INITHUNKMAX; /* size of above arrays to begin with */ -static int p_indent; /* indent to patch */ -static LINENUM p_base; /* where to intuit this time */ -static LINENUM p_bline; /* line # of p_base */ -static LINENUM p_start; /* where intuit found a patch */ -static LINENUM p_sline; /* and the line number for it */ -static LINENUM p_hunk_beg; /* line number of current hunk */ -static LINENUM p_efake = -1; /* end of faked up lines--don't free */ -static LINENUM p_bfake = -1; /* beg of faked up lines */ - -/* - * Prepare to look for the next patch in the patch file. - */ -void -re_patch(void) -{ - p_first = Nulline; - p_newfirst = Nulline; - p_ptrn_lines = Nulline; - p_repl_lines = Nulline; - p_end = (LINENUM)-1; - p_max = Nulline; - p_indent = 0; -} - -/* - * Open the patch file at the beginning of time. - */ -void -open_patch_file(char *filename) -{ - int nr, nw; - - if (filename == Nullch || !*filename || strEQ(filename, "-")) { - pfp = fopen(TMPPATNAME, "w"); - if (pfp == Nullfp) - pfatal2("can't create %s", TMPPATNAME); - while ((nr = fread(buf, 1, buf_size, stdin)) > 0) { - nw = fwrite(buf, 1, nr, pfp); - if (nr != nw) - pfatal2("write error to %s", TMPPATNAME); - } - Fclose(pfp); - filename = TMPPATNAME; - } - pfp = fopen(filename, "r"); - if (pfp == Nullfp) - pfatal2("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(); -} - -/* - * Make sure our dynamically realloced tables are malloced to begin with. - */ -void -set_hunkmax(void) -{ -#ifndef lint - if (p_line == Null(char**)) - p_line = (char**) malloc((MEM)hunkmax * sizeof(char *)); - if (p_len == Null(short*)) - p_len = (short*) malloc((MEM)hunkmax * sizeof(short)); -#endif - if (p_Char == Nullch) - p_Char = (char*) malloc((MEM)hunkmax * sizeof(char)); -} - -/* - * Enlarge the arrays containing the current hunk of patch. - */ -void -grow_hunkmax(void) -{ - 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. - */ - 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 - if (p_line != Null(char**) && p_len != Null(short*) && p_Char != Nullch) - return; - if (!using_plan_a) - fatal1("out of memory\n"); - out_of_mem = TRUE; /* whatever is null will be allocated again */ - /* from within plan_a(), of all places */ -} - -/* - * True if the remainder of the patch file contains a diff of some sort. - */ -bool -there_is_another_patch(void) -{ - if (p_base != 0L && p_base >= p_filesize) { - if (verbose) - say1("done\n"); - return FALSE; - } - if (verbose) - say1("Hmm..."); - diff_type = intuit_diff_type(); - if (!diff_type) { - if (p_base != 0L) { - if (verbose) - say1(" Ignoring the trailing garbage.\ndone\n"); - } - else - say1(" I can't seem to find a patch in there anywhere.\n"); - return FALSE; - } - if (verbose) - say3(" %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" : - diff_type == NEW_CONTEXT_DIFF ? - "a new-style context diff" : - 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"); - skip_to(p_start,p_sline); - while (filearg[0] == Nullch) { - if (force || batch || skip_rest_of_patch) { - say1("No file to patch. Skipping...\n"); - filearg[0] = savestr(bestguess); - skip_rest_of_patch = TRUE; - return TRUE; - } - (void) ask1("File to patch: "); - if (*buf != '\n') { - if (bestguess) - free(bestguess); - bestguess = savestr(buf); - filearg[0] = fetchname(buf, 0, FALSE); - } - if (filearg[0] == Nullch) { - if (ask1("No file found--skip this patch? [n] ")) { - if (*buf != 'y') { - continue; - } - } - if (verbose) - say1("Skipping patch...\n"); - filearg[0] = fetchname(bestguess, 0, TRUE); - skip_rest_of_patch = TRUE; - return TRUE; - } - } - return TRUE; -} - -static char * -p4_savestr(char *str) -{ - char *t, *h; - - /* Leading whitespace. */ - while (isspace((unsigned char)*str)) - str++; - - /* Remove the file revision number. */ - for (t = str, h = NULL; *t != '\0' && !isspace((unsigned char)*t); t++) - if (*t == '#') - h = t; - if (h != NULL) - *h = '\0'; - - return savestr(str); -} - -/* - * Determine what kind of diff is in the remaining part of the patch file. - */ -int -intuit_diff_type(void) -{ - Reg4 long this_line = 0; - Reg5 long previous_line; - Reg6 long first_command_line = -1; - long fcl_line; - Reg7 bool last_line_was_command = FALSE; - Reg8 bool this_is_a_command = FALSE; - Reg9 bool stars_last_line = FALSE; - Reg10 bool stars_this_line = FALSE; - Reg3 int indent; - Reg1 char *s; - Reg2 char *t; - char *indtmp = Nullch; - char *oldtmp = Nullch; - char *newtmp = Nullch; - char *indname = Nullch; - char *oldname = Nullch; - char *newname = Nullch; - Reg11 int retval; - bool no_filearg = (filearg[0] == Nullch); - extern int index_first; - - ok_to_create_file = FALSE; - Fseek(pfp, p_base, 0); - p_input_line = p_bline - 1; - for (;;) { - previous_line = this_line; - last_line_was_command = this_is_a_command; - stars_last_line = stars_this_line; - this_line = ftell(pfp); - indent = 0; - p_input_line++; - if (pgets(FALSE) == 0) { - if (first_command_line >= 0L) { - /* nothing but deletes!? */ - p_start = first_command_line; - p_sline = fcl_line; - retval = ED_DIFF; - goto scan_exit; - } - else { - p_start = this_line; - p_sline = p_input_line; - retval = 0; - goto scan_exit; - } - } - for (s = buf; *s == ' ' || *s == '\t' || *s == 'X'; s++) { - if (*s == '\t') - indent += 8 - (indent % 8); - else - indent++; - } - for (t=s; isdigit((unsigned char)*t) || *t == ','; t++) - ; - this_is_a_command = (isdigit((unsigned char)*s) && - (*t == 'd' || *t == 'c' || *t == 'a') ); - if (first_command_line < 0L && this_is_a_command) { - first_command_line = this_line; - fcl_line = p_input_line; - p_indent = indent; /* assume this for now */ - } - if (!stars_last_line && strnEQ(s, "*** ", 4)) - oldtmp = savestr(s+4); - else if (strnEQ(s, "--- ", 4)) - newtmp = savestr(s+4); - else if (strnEQ(s, "+++ ", 4)) - oldtmp = savestr(s+4); /* pretend it is the old name */ - else if (strnEQ(s, "Index:", 6)) - indtmp = savestr(s+6); - else if (strnEQ(s, "Prereq:", 7)) { - for (t = s + 7; isspace((unsigned char)*t); t++) - ; - revision = savestr(t); - for (t = revision; *t && !isspace((unsigned char)*t); - t++) - ; - *t = '\0'; - if (!*revision) { - free(revision); - revision = Nullch; - } - } else if (strnEQ(s, "==== ", 5)) { - /* Perforce-style diffs. */ - if ((t = strstr(s + 5, " - ")) != NULL) - newtmp = p4_savestr(t + 3); - oldtmp = p4_savestr(s + 5); - } - if ((!diff_type || diff_type == ED_DIFF) && - first_command_line >= 0L && - strEQ(s, ".\n") ) { - p_indent = indent; - p_start = first_command_line; - p_sline = fcl_line; - retval = ED_DIFF; - goto scan_exit; - } - if ((!diff_type || diff_type == UNI_DIFF) && - strnEQ(s, "@@ -", 4)) { - if (!atol(s+3)) - ok_to_create_file = TRUE; - p_indent = indent; - p_start = this_line; - p_sline = p_input_line; - retval = UNI_DIFF; - goto scan_exit; - } - stars_this_line = strnEQ(s, "********", 8); - if ((!diff_type || diff_type == CONTEXT_DIFF) && - stars_last_line && - strnEQ(s, "*** ", 4)) { - if (!atol(s+4)) - ok_to_create_file = TRUE; - /* - * If this is a new context diff the character just - * before the newline is a '*'. - */ - while (*s != '\n') - s++; - p_indent = indent; - p_start = previous_line; - p_sline = p_input_line - 1; - retval = (*(s-1) == '*' ? - NEW_CONTEXT_DIFF : CONTEXT_DIFF); - goto scan_exit; - } - if ((!diff_type || diff_type == NORMAL_DIFF) && - last_line_was_command && - (strnEQ(s, "< ", 2) || strnEQ(s, "> ", 2)) ) { - p_start = previous_line; - p_sline = p_input_line - 1; - p_indent = indent; - retval = NORMAL_DIFF; - goto scan_exit; - } - } - scan_exit: - if (no_filearg) { - if (indtmp != Nullch) - indname = fetchname(indtmp, strippath, - ok_to_create_file); - if (oldtmp != Nullch) - oldname = fetchname(oldtmp, strippath, - ok_to_create_file); - if (newtmp != Nullch) - newname = fetchname(newtmp, strippath, - ok_to_create_file); - if (index_first && indname) - filearg[0] = savestr(indname); - else if (oldname && newname) { - if (strlen(oldname) < strlen(newname)) - filearg[0] = savestr(oldname); - else - filearg[0] = savestr(newname); - } else if (indname) - filearg[0] = savestr(indname); - else if (oldname) - filearg[0] = savestr(oldname); - else if (newname) - filearg[0] = savestr(newname); - } - if (bestguess) { - free(bestguess); - bestguess = Nullch; - } - if (filearg[0] != Nullch) - bestguess = savestr(filearg[0]); - else if (indtmp != Nullch) - bestguess = fetchname(indtmp, strippath, TRUE); - else { - if (oldtmp != Nullch) - oldname = fetchname(oldtmp, strippath, TRUE); - if (newtmp != Nullch) - newname = fetchname(newtmp, strippath, TRUE); - if (oldname && newname) { - if (strlen(oldname) < strlen(newname)) - bestguess = savestr(oldname); - else - bestguess = savestr(newname); - } - else if (oldname) - bestguess = savestr(oldname); - else if (newname) - bestguess = savestr(newname); - } - if (indtmp != Nullch) - free(indtmp); - if (oldtmp != Nullch) - free(oldtmp); - if (newtmp != Nullch) - free(newtmp); - if (indname != Nullch) - free(indname); - if (oldname != Nullch) - free(oldname); - if (newname != Nullch) - free(newname); - return retval; -} - -/* - * Remember where this patch ends so we know where to start up again. - */ -void -next_intuit_at(long file_pos, long file_line) -{ - p_base = file_pos; - p_bline = file_line; -} - -/* - * Basically a verbose fseek() to the actual diff listing. - */ -void -skip_to(long file_pos, long file_line) -{ - size_t len; - - 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"); - while (ftell(pfp) < file_pos) { - len = pgets(FALSE); - assert(len != 0); - say2("|%s", buf); - } - say1("--------------------------\n"); - } - else - Fseek(pfp, file_pos, 0); - p_input_line = file_line - 1; -} - -/* - * Make this a function for better debugging. - */ -static void -malformed(void) -{ - fatal3("malformed patch at line %ld: %s", p_input_line, buf); - /* about as informative as "Syntax error" in C */ -} - -/* - * True if the line has been discarded (i.e. it is a line saying - * "\ No newline at end of file".) - */ -static bool -remove_special_line(void) -{ - int c; - - c = fgetc(pfp); - if (c == '\\') { - do { - c = fgetc(pfp); - } while (c != EOF && c != '\n'); - - return TRUE; - } - - if (c != EOF) - fseek(pfp, -1, SEEK_CUR); - - return FALSE; -} - -/* - * True if there is more of the current diff listing to process. - */ -bool -another_hunk(void) -{ - Reg1 char *s; - size_t len; - Reg2 int context = 0; - - while (p_end >= 0) { - if (p_end == p_efake) - p_end = p_bfake; /* don't free twice */ - else - free(p_line[p_end]); - p_end--; - } - assert(p_end == -1); - p_efake = -1; - - p_max = hunkmax; /* gets reduced when --- found */ - if (diff_type == CONTEXT_DIFF || diff_type == NEW_CONTEXT_DIFF) { - 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 */ - bool ptrn_spaces_eaten = FALSE; /* ptrn was slightly misformed */ - Reg9 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; - /* # of copiable lines in ptrn */ - - len = pgets(TRUE); - p_input_line++; - if (len == 0 || strnNE(buf, "********", 8)) { - next_intuit_at(line_beginning,p_input_line); - return FALSE; - } - p_context = 100; - p_hunk_beg = p_input_line + 1; - while (p_end < p_max) { - line_beginning = ftell(pfp); - len = pgets(TRUE); - p_input_line++; - if (len == 0) { - if (p_max - p_end < 4) - Strcpy(buf, " \n"); /* assume blank lines got chopped */ - else { - if (repl_beginning && repl_could_be_missing) { - repl_missing = TRUE; - goto hunk_done; - } - fatal1("unexpected end of file in patch\n"); - } - } - p_end++; - assert(p_end < hunkmax); - p_Char[p_end] = *buf; -#ifdef zilog - p_line[(short)p_end] = Nullch; -#else - p_line[p_end] = Nullch; -#endif - switch (*buf) { - case '*': - if (strnEQ(buf, "********", 8)) { - if (repl_beginning && repl_could_be_missing) { - repl_missing = TRUE; - goto hunk_done; - } - else - fatal2("unexpected end of hunk at line %ld\n", - p_input_line); - } - if (p_end != 0) { - if (repl_beginning && repl_could_be_missing) { - repl_missing = TRUE; - goto hunk_done; - } - fatal3("unexpected *** at line %ld: %s", p_input_line, buf); - } - context = 0; - p_line[p_end] = savestr(buf); - if (out_of_mem) { - p_end--; - return FALSE; - } - for (s=buf; *s && !isdigit((unsigned char)*s); s++) ; - if (!*s) - malformed (); - if (strnEQ(s,"0,0",3)) - strcpy(s,s+2); - p_first = (LINENUM) atol(s); - while (isdigit((unsigned char)*s)) s++; - if (*s == ',') { - for (; *s && !isdigit((unsigned char)*s); s++) ; - if (!*s) - malformed (); - p_ptrn_lines = ((LINENUM)atol(s)) - p_first + 1; - } - else if (p_first) - p_ptrn_lines = 1; - else { - p_ptrn_lines = 0; - p_first = 1; - } - p_max = p_ptrn_lines + 6; /* we need this much at least */ - while (p_max >= hunkmax) - grow_hunkmax(); - p_max = hunkmax; - break; - case '-': - if (buf[1] == '-') { - if (repl_beginning || - (p_end != p_ptrn_lines + 1 + (p_Char[p_end-1] == '\n'))) - { - if (p_end == 1) { - /* `old' lines were omitted - set up to fill */ - /* them in from 'new' context lines. */ - p_end = p_ptrn_lines + 1; - fillsrc = p_end + 1; - filldst = 1; - fillcnt = p_ptrn_lines; - } - else { - if (repl_beginning) { - if (repl_could_be_missing){ - repl_missing = TRUE; - goto hunk_done; - } - fatal3( -"duplicate \"---\" at line %ld--check line numbers at line %ld\n", - p_input_line, p_hunk_beg + repl_beginning); - } - else { - fatal4( -"%s \"---\" at line %ld--check line numbers at line %ld\n", - (p_end <= p_ptrn_lines - ? "Premature" - : "Overdue" ), - p_input_line, p_hunk_beg); - } - } - } - repl_beginning = p_end; - repl_backtrack_position = ftell(pfp); - repl_patch_line = p_input_line; - p_line[p_end] = savestr(buf); - if (out_of_mem) { - p_end--; - return FALSE; - } - p_Char[p_end] = '='; - for (s=buf; *s && !isdigit((unsigned char)*s); s++) ; - if (!*s) - malformed (); - p_newfirst = (LINENUM) atol(s); - while (isdigit((unsigned char)*s)) s++; - if (*s == ',') { - for (; *s && !isdigit((unsigned char)*s); s++) ; - if (!*s) - malformed (); - p_repl_lines = ((LINENUM)atol(s)) - p_newfirst + 1; - } - else if (p_newfirst) - p_repl_lines = 1; - else { - p_repl_lines = 0; - p_newfirst = 1; - } - p_max = p_repl_lines + p_end; - if (p_max > MAXHUNKSIZE) - fatal4("hunk too large (%ld lines) at line %ld: %s", - p_max, p_input_line, buf); - while (p_max >= hunkmax) - grow_hunkmax(); - if (p_repl_lines != ptrn_copiable - && (p_context != 0 || p_repl_lines != 1)) - repl_could_be_missing = FALSE; - break; - } - goto change_line; - case '+': case '!': - repl_could_be_missing = FALSE; - change_line: - if (buf[1] == '\n' && canonicalize) - strcpy(buf+1," \n"); - if (!isspace((unsigned char)buf[1]) && buf[1] != '>' && buf[1] != '<' && - repl_beginning && repl_could_be_missing) { - repl_missing = TRUE; - goto hunk_done; - } - if (context >= 0) { - if (context < p_context) - p_context = context; - context = -1000; - } - p_line[p_end] = savestr(buf+2); - if (out_of_mem) { - p_end--; - return FALSE; - } - if (p_end == p_ptrn_lines) - { - if (remove_special_line()) { - int len; - - len = strlen(p_line[p_end]) - 1; - (p_line[p_end])[len] = 0; - } - } - break; - case '\t': case '\n': /* assume the 2 spaces got eaten */ - if (repl_beginning && repl_could_be_missing && - (!ptrn_spaces_eaten || diff_type == NEW_CONTEXT_DIFF) ) { - repl_missing = TRUE; - goto hunk_done; - } - p_line[p_end] = savestr(buf); - if (out_of_mem) { - p_end--; - return FALSE; - } - if (p_end != p_ptrn_lines + 1) { - ptrn_spaces_eaten |= (repl_beginning != 0); - context++; - if (!repl_beginning) - ptrn_copiable++; - p_Char[p_end] = ' '; - } - break; - case ' ': - if (!isspace((unsigned char)buf[1]) && - repl_beginning && repl_could_be_missing) { - repl_missing = TRUE; - goto hunk_done; - } - context++; - if (!repl_beginning) - ptrn_copiable++; - p_line[p_end] = savestr(buf+2); - if (out_of_mem) { - p_end--; - return FALSE; - } - break; - default: - if (repl_beginning && repl_could_be_missing) { - repl_missing = TRUE; - goto hunk_done; - } - malformed (); - } - /* set up p_len for strncmp() so we don't have to */ - /* assume null termination */ - if (p_line[p_end]) - p_len[p_end] = strlen(p_line[p_end]); - 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()); - - 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); - - /* redundant 'new' context lines were omitted - set */ - /* up to fill them in from the old file context */ - if (!p_context && p_repl_lines == 1) { - p_repl_lines = 0; - p_max--; - } - fillsrc = 1; - filldst = repl_beginning+1; - fillcnt = p_repl_lines; - p_end = p_max; - } - else if (!p_context && fillcnt == 1) { - /* the first hunk was a null hunk with no context */ - /* and we were expecting one line -- fix it up. */ - while (filldst < p_end) { - p_line[filldst] = p_line[filldst+1]; - p_Char[filldst] = p_Char[filldst+1]; - p_len[filldst] = p_len[filldst+1]; - filldst++; - } -#if 0 - repl_beginning--; /* this doesn't need to be fixed */ -#endif - p_end--; - p_first++; /* do append rather than insert */ - fillcnt = 0; - p_ptrn_lines = 0; - } - - if (diff_type == CONTEXT_DIFF && - (fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) { - if (verbose) - say4("%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() */ - p_efake = filldst + fillcnt - 1; - while (fillcnt-- > 0) { - while (fillsrc <= p_end && p_Char[fillsrc] != ' ') - fillsrc++; - if (fillsrc > p_end) - fatal2("replacement text or line numbers mangled in hunk at line %ld\n", - p_hunk_beg); - p_line[filldst] = p_line[fillsrc]; - p_Char[filldst] = p_Char[fillsrc]; - p_len[filldst] = p_len[fillsrc]; - fillsrc++; filldst++; - } - while (fillsrc <= p_end && fillsrc != repl_beginning && - p_Char[fillsrc] != ' ') - fillsrc++; -#ifdef DEBUGGING - if (debug & 64) - printf("fillsrc %ld, filldst %ld, rb %ld, e+1 %ld\n", - fillsrc,filldst,repl_beginning,p_end+1); -#endif - assert(fillsrc==p_end+1 || fillsrc==repl_beginning); - assert(filldst==p_end+1 || filldst==repl_beginning); - } - - if (p_line[p_end] != NULL) - { - if (remove_special_line()) { - p_len[p_end] -= 1; - (p_line[p_end])[p_len[p_end]] = 0; - } - } - } - 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 */ - char ch; - - len = pgets(TRUE); - p_input_line++; - if (len == 0 || strnNE(buf, "@@ -", 4)) { - next_intuit_at(line_beginning,p_input_line); - return FALSE; - } - s = buf+4; - if (!*s) - malformed (); - p_first = (LINENUM) atol(s); - while (isdigit((unsigned char)*s)) s++; - if (*s == ',') { - p_ptrn_lines = (LINENUM) atol(++s); - while (isdigit((unsigned char)*s)) s++; - } else - p_ptrn_lines = 1; - if (*s == ' ') s++; - if (*s != '+' || !*++s) - malformed (); - p_newfirst = (LINENUM) atol(s); - while (isdigit((unsigned char)*s)) s++; - if (*s == ',') { - p_repl_lines = (LINENUM) atol(++s); - while (isdigit((unsigned char)*s)) s++; - } else - p_repl_lines = 1; - if (*s == ' ') s++; - if (*s != '@') - malformed (); - if (!p_ptrn_lines) - p_first++; /* do append rather than insert */ - p_max = p_ptrn_lines + p_repl_lines + 1; - while (p_max >= hunkmax) - grow_hunkmax(); - fillsrc = 1; - filldst = fillsrc + p_ptrn_lines; - p_end = filldst + p_repl_lines; - Sprintf(buf,"*** %ld,%ld ****\n",p_first,p_first + p_ptrn_lines - 1); - p_line[0] = savestr(buf); - if (out_of_mem) { - p_end = -1; - return FALSE; - } - p_Char[0] = '*'; - Sprintf(buf,"--- %ld,%ld ----\n",p_newfirst,p_newfirst+p_repl_lines-1); - p_line[filldst] = savestr(buf); - if (out_of_mem) { - p_end = 0; - return FALSE; - } - p_Char[filldst++] = '='; - p_context = 100; - context = 0; - p_hunk_beg = p_input_line + 1; - while (fillsrc <= p_ptrn_lines || filldst <= p_end) { - line_beginning = ftell(pfp); - len = pgets(TRUE); - p_input_line++; - if (len == 0) { - if (p_max - filldst < 3) - Strcpy(buf, " \n"); /* assume blank lines got chopped */ - else { - fatal1("unexpected end of file in patch\n"); - } - } - if (*buf == '\t' || *buf == '\n') { - ch = ' '; /* assume the space got eaten */ - s = savestr(buf); - } - else { - ch = *buf; - s = savestr(buf+1); - } - if (out_of_mem) { - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc-1; - return FALSE; - } - switch (ch) { - case '-': - if (fillsrc > p_ptrn_lines) { - free(s); - p_end = filldst-1; - malformed (); - } - p_Char[fillsrc] = ch; - p_line[fillsrc] = s; - p_len[fillsrc++] = strlen(s); - if (fillsrc > p_ptrn_lines) { - if (remove_special_line()) { - p_len[fillsrc - 1] -= 1; - s[p_len[fillsrc - 1]] = 0; - } - } - break; - case '=': - ch = ' '; - /* FALLTHROUGH */ - case ' ': - if (fillsrc > p_ptrn_lines) { - free(s); - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc-1; - malformed (); - } - context++; - p_Char[fillsrc] = ch; - p_line[fillsrc] = s; - p_len[fillsrc++] = strlen(s); - s = savestr(s); - if (out_of_mem) { - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc-1; - return FALSE; - } - /* FALLTHROUGH */ - case '+': - if (filldst > p_end) { - free(s); - while (--filldst > p_ptrn_lines) - free(p_line[filldst]); - p_end = fillsrc-1; - malformed (); - } - p_Char[filldst] = ch; - p_line[filldst] = s; - p_len[filldst++] = strlen(s); - if (fillsrc > p_ptrn_lines) { - if (remove_special_line()) { - p_len[filldst - 1] -= 1; - s[p_len[filldst - 1]] = 0; - } - } - break; - default: - p_end = filldst; - malformed (); - } - if (ch != ' ' && context > 0) { - if (context < p_context) - p_context = context; - context = -1000; - } - }/* while */ - } - else { /* normal diff--fake it up */ - char hunk_type; - Reg3 int i; - LINENUM min, max; - long line_beginning = ftell(pfp); - - p_context = 0; - len = pgets(TRUE); - p_input_line++; - if (len == 0 || !isdigit((unsigned char)*buf)) { - next_intuit_at(line_beginning,p_input_line); - return FALSE; - } - p_first = (LINENUM)atol(buf); - for (s=buf; isdigit((unsigned char)*s); s++) ; - if (*s == ',') { - p_ptrn_lines = (LINENUM)atol(++s) - p_first + 1; - while (isdigit((unsigned char)*s)) s++; - } - else - p_ptrn_lines = (*s != 'a'); - hunk_type = *s; - if (hunk_type == 'a') - p_first++; /* do append rather than insert */ - min = (LINENUM)atol(++s); - for (; isdigit((unsigned char)*s); s++) ; - if (*s == ',') - max = (LINENUM)atol(++s); - else - max = min; - if (hunk_type == 'd') - min++; - p_end = p_ptrn_lines + 1 + max - min + 1; - if (p_end > MAXHUNKSIZE) - fatal4("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; - Sprintf(buf, "*** %ld,%ld\n", p_first, p_first + p_ptrn_lines - 1); - p_line[0] = savestr(buf); - if (out_of_mem) { - p_end = -1; - return FALSE; - } - p_Char[0] = '*'; - for (i=1; i<=p_ptrn_lines; i++) { - len = pgets(TRUE); - p_input_line++; - if (len == 0) - fatal2("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); - p_line[i] = savestr(buf+2); - if (out_of_mem) { - p_end = i-1; - return FALSE; - } - p_len[i] = strlen(p_line[i]); - p_Char[i] = '-'; - } - - if (remove_special_line()) { - p_len[i-1] -= 1; - (p_line[i-1])[p_len[i-1]] = 0; - } - - if (hunk_type == 'c') { - len = pgets(TRUE); - p_input_line++; - if (len == 0) - fatal2("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); - } - Sprintf(buf, "--- %ld,%ld\n", min, max); - p_line[i] = savestr(buf); - if (out_of_mem) { - p_end = i-1; - return FALSE; - } - p_Char[i] = '='; - for (i++; i<=p_end; i++) { - len = pgets(TRUE); - p_input_line++; - if (len == 0) - fatal2("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); - p_line[i] = savestr(buf+2); - if (out_of_mem) { - p_end = i-1; - return FALSE; - } - p_len[i] = strlen(p_line[i]); - p_Char[i] = '+'; - } - - if (remove_special_line()) { - p_len[i-1] -= 1; - (p_line[i-1])[p_len[i-1]] = 0; - } - } - if (reverse) /* backwards patch? */ - if (!pch_swap()) - say1("Not enough memory to swap next hunk!\n"); -#ifdef DEBUGGING - if (debug & 2) { - int i; - char special; - - for (i=0; i <= p_end; i++) { - if (i == p_ptrn_lines) - special = '^'; - else - special = ' '; - fprintf(stderr, "%3d %c %c %s", i, p_Char[i], special, p_line[i]); - Fflush(stderr); - } - } -#endif - if (p_end+1 < hunkmax) /* paranoia reigns supreme... */ - p_Char[p_end+1] = '^'; /* add a stopper for apply_hunk */ - return TRUE; -} - -/* - * Input a line from the patch file. - * Worry about indentation if do_indent is true. - * The line is read directly into the buf global variable which - * is resized if necessary in order to hold the complete line. - * Returns the number of characters read including the terminating - * '\n', if any. - */ -size_t -pgets(bool do_indent) -{ - char *line; - size_t len; - int indent = 0, skipped = 0; - - line = fgetln(pfp, &len); - if (line != Nullch) { - if (len + 1 > buf_size) { - while (len + 1 > buf_size) - buf_size *= 2; - free(buf); - buf = malloc(buf_size); - if (buf == Nullch) - fatal1("out of memory\n"); - } - if (do_indent == TRUE && p_indent) { - for (; - indent < p_indent && (*line == ' ' || *line == '\t' || *line == 'X'); - line++, skipped++) { - if (*line == '\t') - indent += 8 - (indent %7); - else - indent++; - } - } - memcpy(buf, line, len - skipped); - buf[len - skipped] = '\0'; - } - return len; -} - -/* - * Reverse the old and new portions of the current hunk. - */ -bool -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; - bool blankline = FALSE; - Reg3 char *s; - - i = p_first; - p_first = p_newfirst; - p_newfirst = i; - - /* make a scratch copy */ - - tp_line = p_line; - tp_len = p_len; - tp_char = p_Char; - p_line = Null(char**); /* force set_hunkmax to allocate again */ - p_len = Null(short*); - 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); - p_line = tp_line; - if (p_len == Null(short*)) - free((char*)p_len); - p_len = tp_len; -#endif - if (p_Char == Nullch) - free((char*)p_Char); - p_Char = tp_char; - return FALSE; /* not enough memory to swap hunk! */ - } - - /* now turn the new into the old */ - - i = p_ptrn_lines + 1; - if (tp_char[i] == '\n') { /* account for possible blank line */ - blankline = TRUE; - i++; - } - if (p_efake >= 0) { /* fix non-freeable ptr range */ - if (p_efake <= i) - n = p_end - i + 1; - else - n = -i; - p_efake += n; - p_bfake += n; - } - for (n=0; i <= p_end; i++,n++) { - p_line[n] = tp_line[i]; - p_Char[n] = tp_char[i]; - if (p_Char[n] == '+') - p_Char[n] = '-'; - p_len[n] = tp_len[i]; - } - if (blankline) { - i = p_ptrn_lines + 1; - p_line[n] = tp_line[i]; - p_Char[n] = tp_char[i]; - p_len[n] = tp_len[i]; - n++; - } - assert(p_Char[0] == '='); - p_Char[0] = '*'; - for (s=p_line[0]; *s; s++) - if (*s == '-') - *s = '*'; - - /* now turn the old into the new */ - - assert(tp_char[0] == '*'); - tp_char[0] = '='; - for (s=tp_line[0]; *s; s++) - if (*s == '*') - *s = '-'; - for (i=0; n <= p_end; i++,n++) { - p_line[n] = tp_line[i]; - p_Char[n] = tp_char[i]; - if (p_Char[n] == '-') - p_Char[n] = '+'; - p_len[n] = tp_len[i]; - } - assert(i == p_ptrn_lines + 1); - 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); - if (tp_len == Null(short*)) - free((char*)tp_len); -#endif - if (tp_char == Nullch) - free((char*)tp_char); - return TRUE; -} - -/* - * Return the specified line position in the old file of the old context. - */ -LINENUM -pch_first(void) -{ - return p_first; -} - -/* - * Return the number of lines of old context. - */ -LINENUM -pch_ptrn_lines(void) -{ - return p_ptrn_lines; -} - -/* - * Return the probable line position in the new file of the first line. - */ -LINENUM -pch_newfirst(void) -{ - return p_newfirst; -} - -/* - * Return the number of lines in the replacement text including context. - */ -LINENUM -pch_repl_lines(void) -{ - return p_repl_lines; -} - -/* - * Return the number of lines in the whole hunk. - */ -LINENUM -pch_end(void) -{ - return p_end; -} - -/* - * Return the number of context lines before the first changed line. - */ -LINENUM -pch_context(void) -{ - return p_context; -} - -/* - * Return the length of a particular patch line. - */ -short -pch_line_len(LINENUM line) -{ - return p_len[line]; -} - -/* - * Return the control character (+, -, *, !, etc) for a patch line. - */ -char -pch_char(LINENUM line) -{ - return p_Char[line]; -} - -/* - * Return a pointer to a particular patch line. - */ -char * -pfetch(LINENUM line) -{ - return p_line[line]; -} - -/* - * Return where in the patch file this hunk began, for error messages. - */ -LINENUM -pch_hunk_beg(void) -{ - return p_hunk_beg; -} - -/* - * Apply an ed script by feeding ed itself. - */ -void -do_ed_script(void) -{ - Reg1 char *t; - Reg2 long beginning_of_this_line; - Reg3 bool this_line_is_command = FALSE; - Reg4 FILE *pipefp; - - if (!skip_rest_of_patch) { - Unlink(TMPOUTNAME); - copy_file(filearg[0], TMPOUTNAME); - if (verbose) - Sprintf(buf, "/bin/ed %s", TMPOUTNAME); - else - Sprintf(buf, "/bin/ed - %s", TMPOUTNAME); - pipefp = popen(buf, "w"); - } - for (;;) { - beginning_of_this_line = ftell(pfp); - if (pgets(TRUE) == 0) { - next_intuit_at(beginning_of_this_line, p_input_line); - break; - } - p_input_line++; - for (t=buf; isdigit((unsigned char)*t) || *t == ','; t++) - ; - this_line_is_command = (isdigit((unsigned char)*buf) && - (*t == 'd' || *t == 'c' || *t == 'a') ); - if (this_line_is_command) { - if (!skip_rest_of_patch) - fputs(buf, pipefp); - if (*t != 'd') { - while (pgets(TRUE) != 0) { - p_input_line++; - if (!skip_rest_of_patch) - fputs(buf, pipefp); - if (strEQ(buf, ".\n")) - break; - } - } - } - else { - next_intuit_at(beginning_of_this_line,p_input_line); - break; - } - } - if (skip_rest_of_patch) - return; - fprintf(pipefp, "w\n"); - fprintf(pipefp, "q\n"); - Fflush(pipefp); - Pclose(pipefp); - ignore_signals(); - if (move_file(TMPOUTNAME, outname) < 0) { - toutkeep = TRUE; - chmod(TMPOUTNAME, filemode); - } - else - chmod(outname, filemode); - set_signals(1); -} diff --git a/gnu/usr.bin/patch/pch.h b/gnu/usr.bin/patch/pch.h deleted file mode 100644 index 0393dea..0000000 --- a/gnu/usr.bin/patch/pch.h +++ /dev/null @@ -1,36 +0,0 @@ -/* $FreeBSD$ - * - * $Log: pch.h,v $ - * Revision 2.0.1.1 87/01/30 22:47:16 lwall - * Added do_ed_script(). - * - * Revision 2.0 86/09/17 15:39:57 lwall - * Baseline for netwide release. - * - */ - -EXT FILE *pfp INIT(Nullfp); /* patch file pointer */ - -void re_patch(void); -void open_patch_file(char *_filename); -void set_hunkmax(void); -void grow_hunkmax(void); -bool there_is_another_patch(void); -int intuit_diff_type(void); -void next_intuit_at(long _file_pos, long _file_line); -void skip_to(long _file_pos, long _file_line); -bool another_hunk(void); -bool pch_swap(void); -char *pfetch(LINENUM _line); -short pch_line_len(LINENUM _line); -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 _line); -char *pfetch(LINENUM _line); -size_t pgets(bool _do_indent); -void do_ed_script(void); diff --git a/gnu/usr.bin/patch/util.c b/gnu/usr.bin/patch/util.c deleted file mode 100644 index 5a76a03..0000000 --- a/gnu/usr.bin/patch/util.c +++ /dev/null @@ -1,458 +0,0 @@ -/* $FreeBSD$ */ - -#include - -#include "EXTERN.h" -#include "common.h" -#include "INTERN.h" -#include "util.h" -#include "backupfile.h" - -void my_exit(int _status); /* in patch.c */ - -#ifndef HAVE_STRERROR -static char * -private_strerror (errnum) - int errnum; -{ - extern char *sys_errlist[]; - extern int sys_nerr; - - if (errnum > 0 && errnum <= sys_nerr) - return sys_errlist[errnum]; - return "Unknown system error"; -} -#define strerror private_strerror -#endif /* !HAVE_STRERROR */ - -/* - * Rename a file, copying it if necessary. - */ -int -move_file(char *from, char *to) -{ - char bakname[512]; - Reg1 char *s; - Reg2 int i; - Reg3 int fromfd; - - /* to stdout? */ - - if (strEQ(to, "-")) { -#ifdef DEBUGGING - if (debug & 4) - say2("Moving %s to stdout.\n", from); -#endif - fromfd = open(from, 0); - if (fromfd < 0) - pfatal2("internal error, can't reopen %s", from); - while ((i = read(fromfd, buf, buf_size)) > 0) - if (write(1, buf, i) != 1) - pfatal1("write failed"); - Close(fromfd); - return 0; - } - - if (origprae) { - Strcpy(bakname, origprae); - Strcat(bakname, to); - } else { -#ifndef NODIR - char *backupname = find_backup_file_name(to); - if (backupname == (char *) 0) - fatal1("out of memory\n"); - Strcpy(bakname, backupname); - free(backupname); -#else /* NODIR */ - Strcpy(bakname, to); - Strcat(bakname, simple_backup_suffix); -#endif /* NODIR */ - } - - if (stat(to, &filestat) == 0) { /* output file exists */ - 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; - } - /* - * Find a backup name that is not the same file. - * Change the first lowercase char into uppercase; - * if that isn't sufficient, chop off the first char - * and try again. - */ - while (stat(bakname, &filestat) == 0 && - to_device == filestat.st_dev && - to_inode == filestat.st_ino) { - /* Skip initial non-lowercase chars. */ - for (s=simplename; *s && !islower((unsigned char)*s); - s++) - ; - if (*s) - *s = toupper((unsigned char)*s); - else - Strcpy(simplename, simplename + 1); - } - while (unlink(bakname) >= 0) - ; /* while() is for benefit of Eunice */ -#ifdef DEBUGGING - if (debug & 4) - say3("Moving %s to %s.\n", to, bakname); -#endif - if (rename(to, bakname) < 0) { - say4("Can't backup %s, output is in %s: %s\n", to, from, - strerror(errno)); - return -1; - } - while (unlink(to) >= 0) - ; - } -#ifdef DEBUGGING - if (debug & 4) - say3("Moving %s to %s.\n", from, to); -#endif - if (rename(from, to) < 0) { /* different file system? */ - Reg4 int tofd; - - tofd = creat(to, 0666); - if (tofd < 0) { - say4("Can't create %s, output is in %s: %s\n", - to, from, strerror(errno)); - return -1; - } - fromfd = open(from, 0); - if (fromfd < 0) - pfatal2("internal error, can't reopen %s", from); - while ((i = read(fromfd, buf, buf_size)) > 0) - if (write(tofd, buf, i) != i) - pfatal1("write failed"); - Close(fromfd); - Close(tofd); - } - Unlink(from); - return 0; -} - -/* - * Copy a file. - */ -void -copy_file(char *from, char *to) -{ - Reg3 int tofd; - Reg2 int fromfd; - Reg1 int i; - - tofd = creat(to, 0666); - if (tofd < 0) - pfatal2("can't create %s", to); - fromfd = open(from, 0); - if (fromfd < 0) - pfatal2("internal error, can't reopen %s", from); - while ((i = read(fromfd, buf, buf_size)) > 0) - if (write(tofd, buf, i) != i) - pfatal2("write to %s failed", to); - Close(fromfd); - Close(tofd); -} - -/* - * Allocate a unique area for a string. - */ -char * -savestr(char *s) -{ - Reg3 char *rv; - Reg2 char *t; - - if (!s) - s = "Oops"; - t = s; - while (*t++) - ; - rv = malloc((MEM) (t - s)); - if (rv == Nullch) { - if (using_plan_a) - out_of_mem = TRUE; - else - fatal1("out of memory\n"); - } else { - t = rv; - while ((*t++ = *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; -{ - fprintf(stderr, pat, arg1, arg2, arg3); - Fflush(stderr); -} - -/* - * Terminal output, pun intended. - */ -void /* very void */ -fatal(pat,arg1,arg2,arg3) -char *pat; -long arg1,arg2,arg3; -{ - fprintf(stderr, "patch: **** "); - fprintf(stderr, pat, arg1, arg2, arg3); - 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; -{ - int errnum = errno; - - fprintf(stderr, "patch: **** "); - fprintf(stderr, pat, arg1, arg2, arg3); - fprintf(stderr, ": %s\n", strerror(errnum)); - my_exit(1); -} - -/* - * Get a response from the user, somehow or other. - */ -int -ask(pat,arg1,arg2,arg3) -char *pat; -long arg1,arg2,arg3; -{ - int ttyfd; - int r; - bool tty2 = isatty(2); - - Sprintf(buf, pat, arg1, arg2, arg3); - Fflush(stderr); - write(2, buf, strlen(buf)); - if (tty2) { /* might be redirected to a file */ - r = read(2, buf, buf_size); - } else if (isatty(1)) { /* this may be new file output */ - Fflush(stdout); - write(1, buf, strlen(buf)); - r = read(1, buf, buf_size); - } else if ((ttyfd = open(_PATH_TTY, 2)) >= 0 && isatty(ttyfd)) { - /* might be deleted or unwriteable */ - write(ttyfd, buf, strlen(buf)); - r = read(ttyfd, buf, buf_size); - Close(ttyfd); - } else if (isatty(0)) { /* this is probably patch input */ - Fflush(stdin); - write(0, buf, strlen(buf)); - r = read(0, buf, buf_size); - } else { /* no terminal at all--default it */ - buf[0] = '\n'; - buf[1] = 0; - say1(buf); - return 0; /* signal possible error */ - } - if (r <= 0) - buf[0] = 0; - else - buf[r] = '\0'; - if (!tty2) - say1(buf); - - if (r <= 0) - return 0; /* if there was an error, return it */ - else - return 1; -} -#endif /* lint */ - -/* - * How to handle certain events when not in a critical region. - */ -void -set_signals(int reset) -{ -#ifndef lint - static RETSIGTYPE (*hupval)(),(*intval)(); - - if (!reset) { - hupval = signal(SIGHUP, SIG_IGN); - if (hupval != SIG_IGN) - hupval = (RETSIGTYPE(*)())my_exit; - intval = signal(SIGINT, SIG_IGN); - if (intval != SIG_IGN) - intval = (RETSIGTYPE(*)())my_exit; - } - Signal(SIGHUP, hupval); - Signal(SIGINT, intval); -#endif -} - -/* - * How to handle certain events when in a critical region. - */ -void -ignore_signals(void) -{ -#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; -{ - char tmpbuf[256]; - Reg2 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. */ - - /* - * Copy `filename' into `tmpbuf' with a NUL instead of a slash - * between the directories. - */ - while (*filename) { - if (*filename == '/') { - filename++; - dirv[dirvp++] = s; - *s++ = '\0'; - } else { - *s++ = *filename++; - } - } - *s = '\0'; - dirv[dirvp] = s; - if (striplast) - dirvp--; - if (dirvp < 0) - return; - - strcpy(buf, "mkdir"); - s = buf; - for (i = 0; i <= dirvp; i++) { - struct stat sbuf; - - if (stat(tmpbuf, &sbuf) && errno == ENOENT) { - while (*s) - s++; - *s++ = ' '; - strcpy(s, tmpbuf); - } - *dirv[i] = '/'; - } - if (s != buf) - system(buf); -} - -/* - * Make filenames more reasonable. - */ -char * -fetchname(char *at, int strip_leading, int assume_exists) -{ - char *fullname; - char *name; - Reg1 char *t; - char tmpbuf[200]; - int sleading = strip_leading; - - if (!at) - return Nullch; - while (isspace((unsigned char)*at)) - at++; -#ifdef DEBUGGING - if (debug & 128) - say4("fetchname %s %d %d\n",at,strip_leading,assume_exists); -#endif - if (strnEQ(at, _PATH_DEVNULL, sizeof _PATH_DEVNULL - 1)) - /* So files can be created by diffing against /dev/null. */ - return Nullch; - name = fullname = t = savestr(at); - - /* Strip off up to `sleading' leading slashes and null terminate. */ - for (; *t && !isspace((unsigned char)*t); t++) - if (*t == '/') - if (--sleading >= 0) - name = t + 1; - *t = '\0'; - - /* - * If no -p option was given (957 is the default value!), - * we were given a relative pathname, - * and the leading directories that we just stripped off all exist, - * put them back on. - */ - if (strip_leading == 957 && name != fullname && *fullname != '/') { - name[-1] = '\0'; - if (stat(fullname, &filestat) == 0 && - S_ISDIR(filestat.st_mode)) { - name[-1] = '/'; - name = fullname; - } - } - - name = savestr(name); - free(fullname); - - if (stat(name, &filestat) && !assume_exists) { - char *filebase = basename(name); - int pathlen = filebase - name; - - /* Put any leading path into `tmpbuf'. */ - strncpy(tmpbuf, name, pathlen); - -#define try(f, a1, a2) \ - (Sprintf(tmpbuf + pathlen, f, a1, a2), stat(tmpbuf, &filestat) == 0) - if (try("RCS/%s%s", filebase, RCSSUFFIX) || - try("RCS/%s%s", filebase, "") || - try( "%s%s", filebase, RCSSUFFIX) || - try("SCCS/%s%s", SCCSPREFIX, filebase) || - try( "%s%s", SCCSPREFIX, filebase)) - return name; - free(name); - name = Nullch; - } - - return name; -} - -char * -xmalloc(unsigned int size) -{ - register char *p = (char *) malloc (size); - if (!p) - fatal("out of memory"); - return p; -} diff --git a/gnu/usr.bin/patch/util.h b/gnu/usr.bin/patch/util.h deleted file mode 100644 index f31f2e2..0000000 --- a/gnu/usr.bin/patch/util.h +++ /dev/null @@ -1,88 +0,0 @@ -/* $FreeBSD$ - * - * $Log: util.h,v $ - * Revision 2.0 86/09/17 15:40:06 lwall - * Baseline for netwide release. - * - */ - -/* and for those machine that can't handle a variable argument list */ - -#ifdef CANVARARG - -#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(char *_at, int _strip_leading, int _assume_exists); -int move_file(char *_from, char *_to); -void copy_file(char *_from, char *_to); -void say(/*const char *pat, long _arg1, long _arg2, long _arg3*/); -void fatal(); -void pfatal(); -int ask(/*const char *pat, long _arg1, long _arg2, long _arg3*/); -char *savestr(char *_s); -void set_signals(int _reset); -void ignore_signals(void); -void makedirs(/*char *_filename, bool _striplast*/); -char *basename(); diff --git a/gnu/usr.bin/patch/version.c b/gnu/usr.bin/patch/version.c deleted file mode 100644 index 753dbfb..0000000 --- a/gnu/usr.bin/patch/version.c +++ /dev/null @@ -1,25 +0,0 @@ -/* $FreeBSD$ - * - * $Log: version.c,v $ - * Revision 2.0 86/09/17 15:40:11 lwall - * Baseline for netwide release. - * - */ - -#include "EXTERN.h" -#include "common.h" -#include "util.h" -#include "INTERN.h" -#include "patchlevel.h" -#include "version.h" - -void my_exit(int _status); /* in patch.c */ - -/* Print out the version number and die. */ - -void -version(void) -{ - fprintf(stderr, "Patch version %s\n", PATCH_VERSION); - my_exit(0); -} diff --git a/gnu/usr.bin/patch/version.h b/gnu/usr.bin/patch/version.h deleted file mode 100644 index faddf7c..0000000 --- a/gnu/usr.bin/patch/version.h +++ /dev/null @@ -1,9 +0,0 @@ -/* $FreeBSD$ - * - * $Log: version.h,v $ - * Revision 2.0 86/09/17 15:40:14 lwall - * Baseline for netwide release. - * - */ - -void version(void); -- cgit v1.1