summaryrefslogtreecommitdiff
path: root/usr.bin/patch
diff options
context:
space:
mode:
authorkristerw <kristerw@NetBSD.org>2002-03-11 18:47:51 +0000
committerkristerw <kristerw@NetBSD.org>2002-03-11 18:47:51 +0000
commit175b5054de4ae8dafb16275db2a41227efd2c467 (patch)
treea7caf89b76af931efff8bb1e8dd0598f90acbade /usr.bin/patch
parent552fdb7e1b31b00ea44cdcd623637d22199c0acd (diff)
Ansify
Remove unused defines Remove #ifndef lint Remove redundant and incorrect casts.
Diffstat (limited to 'usr.bin/patch')
-rw-r--r--usr.bin/patch/Makefile3
-rw-r--r--usr.bin/patch/backupfile.c22
-rw-r--r--usr.bin/patch/common.h33
-rw-r--r--usr.bin/patch/inp.c108
-rw-r--r--usr.bin/patch/patch.c136
-rw-r--r--usr.bin/patch/pch.c230
-rw-r--r--usr.bin/patch/pch.h4
-rw-r--r--usr.bin/patch/util.c136
-rw-r--r--usr.bin/patch/util.h68
-rw-r--r--usr.bin/patch/version.c6
-rw-r--r--usr.bin/patch/version.h4
11 files changed, 276 insertions, 474 deletions
diff --git a/usr.bin/patch/Makefile b/usr.bin/patch/Makefile
index c53bddb9d9c..36dd50cb0cc 100644
--- a/usr.bin/patch/Makefile
+++ b/usr.bin/patch/Makefile
@@ -1,7 +1,6 @@
-# $NetBSD: Makefile,v 1.6 2000/10/11 14:46:15 is Exp $
+# $NetBSD: Makefile,v 1.7 2002/03/11 18:47:51 kristerw Exp $
PROG= patch
SRCS= patch.c pch.c inp.c version.c util.c backupfile.c
-CFLAGS+= -DCANVARARG
.include <bsd.prog.mk>
diff --git a/usr.bin/patch/backupfile.c b/usr.bin/patch/backupfile.c
index 6017d3e94bc..90c504486a2 100644
--- a/usr.bin/patch/backupfile.c
+++ b/usr.bin/patch/backupfile.c
@@ -1,4 +1,4 @@
-/* $NetBSD: backupfile.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $ */
+/* $NetBSD: backupfile.c,v 1.8 2002/03/11 18:47:51 kristerw Exp $ */
/* backupfile.c -- make Emacs style backup file names
Copyright (C) 1990 Free Software Foundation, Inc.
@@ -15,7 +15,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: backupfile.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $");
+__RCSID("$NetBSD: backupfile.c,v 1.8 2002/03/11 18:47:51 kristerw Exp $");
#endif /* not lint */
#include <stdio.h>
@@ -24,29 +24,13 @@ __RCSID("$NetBSD: backupfile.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $");
#include <ctype.h>
#include <sys/types.h>
#include "backupfile.h"
-#include "config.h"
-#ifdef DIRENT
#include <dirent.h>
#ifdef direct
#undef direct
#endif
#define direct dirent
#define NLENGTH(direct) (strlen((direct)->d_name))
-#else /* !DIRENT */
-#define NLENGTH(direct) ((direct)->d_namlen)
-#ifdef USG
-#ifdef SYSNDIR
-#include <sys/ndir.h>
-#else /* !SYSNDIR */
-#include <ndir.h>
-#endif /* !SYSNDIR */
-#else /* !USG */
-#ifdef SYSDIR
-#include <sys/dir.h>
-#endif /* SYSDIR */
-#endif /* !USG */
-#endif /* !DIRENT */
#ifndef isascii
#define ISDIGIT(c) (isdigit ((unsigned char) (c)))
@@ -54,9 +38,7 @@ __RCSID("$NetBSD: backupfile.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $");
#define ISDIGIT(c) (isascii (c) && isdigit ((unsigned char)c))
#endif
-#if defined (HAVE_UNISTD_H)
#include <unistd.h>
-#endif
#if defined (_POSIX_VERSION)
/* POSIX does not require that the d_ino field be present, and some
diff --git a/usr.bin/patch/common.h b/usr.bin/patch/common.h
index f7573fc64dc..174fa1a8a27 100644
--- a/usr.bin/patch/common.h
+++ b/usr.bin/patch/common.h
@@ -1,9 +1,7 @@
-/* $NetBSD: common.h,v 1.10 2002/03/08 21:57:33 kristerw Exp $ */
+/* $NetBSD: common.h,v 1.11 2002/03/11 18:47:51 kristerw Exp $ */
#define DEBUGGING
-#include "config.h"
-
/* shut lint up about the following when return value ignored */
#define Signal (void)signal
@@ -19,10 +17,6 @@
#define Strcpy (void)strcpy
#define Strcat (void)strcat
-/* NeXT declares malloc and realloc incompatibly from us in some of
- these files. Temporarily redefine them to prevent errors. */
-#define malloc system_malloc
-#define realloc system_realloc
#include <stdio.h>
#include <string.h>
#include <assert.h>
@@ -30,8 +24,6 @@
#include <sys/stat.h>
#include <ctype.h>
#include <signal.h>
-#undef malloc
-#undef realloc
/* constants */
@@ -58,20 +50,12 @@
#define CHECKOUT "co -l %s"
#define RCSDIFF "rcsdiff %s > /dev/null"
-#ifdef FLEXFILENAMES
#define ORIGEXT ".orig"
#define REJEXT ".rej"
-#else
-#define ORIGEXT "~"
-#define REJEXT "#"
-#endif
/* handy definitions */
-#define Null(t) ((t)0)
-#define Nullch Null(char *)
-#define Nullfp Null(FILE *)
-#define Nulline Null(LINENUM)
+#define Nulline 0
#define Ctl(ch) ((ch) & 037)
@@ -84,7 +68,6 @@
typedef char bool;
typedef long LINENUM; /* must be signed */
-typedef unsigned MEM; /* what to feed malloc */
/* globals */
@@ -97,8 +80,8 @@ EXT struct stat filestat; /* file statistics area */
EXT int filemode INIT(0644);
EXT char buf[MAXLINELEN]; /* general purpose buffer */
-EXT FILE *ofp INIT(Nullfp); /* output file pointer */
-EXT FILE *rejfp INIT(Nullfp); /* reject file pointer */
+EXT FILE *ofp INIT(NULL); /* output file pointer */
+EXT FILE *rejfp INIT(NULL); /* reject file pointer */
EXT int myuid; /* cache getuid return value */
@@ -111,12 +94,12 @@ EXT char *filearg[MAXFILEC];
EXT bool ok_to_create_file INIT(FALSE);
EXT bool filename_is_dev_null INIT(FALSE);
EXT bool old_file_is_dev_null INIT(FALSE);
-EXT char *bestguess INIT(Nullch); /* guess at correct filename */
+EXT char *bestguess INIT(NULL); /* guess at correct filename */
-EXT char *outname INIT(Nullch);
+EXT char *outname INIT(NULL);
EXT char rejname[128];
-EXT char *origprae INIT(Nullch);
+EXT char *origprae INIT(NULL);
EXT char *TMPOUTNAME;
EXT char *TMPINNAME;
@@ -152,7 +135,7 @@ 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 */
+EXT char *revision INIT(NULL); /* prerequisite revision, if any */
#include <errno.h>
diff --git a/usr.bin/patch/inp.c b/usr.bin/patch/inp.c
index 01190ccb048..0697eb5503e 100644
--- a/usr.bin/patch/inp.c
+++ b/usr.bin/patch/inp.c
@@ -1,7 +1,7 @@
-/* $NetBSD: inp.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $ */
+/* $NetBSD: inp.c,v 1.8 2002/03/11 18:47:51 kristerw Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: inp.c,v 1.7 2002/03/08 21:57:33 kristerw Exp $");
+__RCSID("$NetBSD: inp.c,v 1.8 2002/03/11 18:47:51 kristerw Exp $");
#endif /* not lint */
#include "EXTERN.h"
@@ -38,10 +38,10 @@ re_input(void)
if (i_ptr != NULL)
free(i_ptr);
- if (i_womp != Nullch)
+ if (i_womp != NULL)
free(i_womp);
- i_womp = Nullch;
- i_ptr = Null(char **);
+ i_womp = NULL;
+ i_ptr = NULL;
}
else {
using_plan_a = TRUE; /* maybe the next one is smaller */
@@ -49,7 +49,7 @@ re_input(void)
tifd = -1;
free(tibuf[0]);
free(tibuf[1]);
- tibuf[0] = tibuf[1] = Nullch;
+ tibuf[0] = tibuf[1] = NULL;
tiline[0] = tiline[1] = -1;
tireclen = 0;
}
@@ -63,7 +63,7 @@ scan_input(char *filename)
if (!plan_a(filename))
plan_b(filename);
if (verbose) {
- say3("Patching file %s using Plan %s...\n", filename,
+ say("Patching file %s using Plan %s...\n", filename,
(using_plan_a ? "A" : "B") );
}
}
@@ -81,7 +81,7 @@ plan_a(char *filename)
statfailed = stat(filename, &filestat);
if (statfailed && ok_to_create_file) {
if (verbose)
- say2("(Creating file %s...)\n",filename);
+ say("(Creating file %s...)\n",filename);
makedirs(filename, TRUE);
close(creat(filename, 0666));
statfailed = stat(filename, &filestat);
@@ -93,7 +93,7 @@ plan_a(char *filename)
/* I can't write to it. */
|| ((filestat.st_mode & 0022) == 0 && filestat.st_uid != myuid)) {
struct stat cstat;
- char *cs = Nullch;
+ char *cs = NULL;
char *filebase;
int pathlen;
@@ -119,38 +119,38 @@ plan_a(char *filename)
Sprintf(lbuf, SCCSDIFF, s, filename);
cs = "SCCS";
} else if (statfailed)
- fatal2("can't find %s\n", filename);
+ fatal("can't find %s\n", filename);
/* else we can't write to it but it's not under a version
control system, so just proceed. */
if (cs) {
if (!statfailed) {
if ((filestat.st_mode & 0222) != 0)
/* The owner can write to it. */
- fatal3("file %s seems to be locked by somebody else under %s\n",
+ fatal("file %s seems to be locked by somebody else under %s\n",
filename, cs);
/* It might be checked out unlocked. See if it's safe to
check out the default version locked. */
if (verbose)
- say3("Comparing file %s to default %s version...\n",
- filename, cs);
+ say("Comparing file %s to default %s version...\n",
+ filename, cs);
if (system(lbuf))
- fatal3("can't check out file %s: differs from default %s version\n",
+ fatal("can't check out file %s: differs from default %s version\n",
filename, cs);
}
if (verbose)
- say3("Checking out file %s from %s...\n", filename, cs);
+ say("Checking out file %s from %s...\n", filename, cs);
if (system(buf) || stat(filename, &filestat))
- fatal3("can't check out file %s from %s\n", filename, cs);
+ fatal("can't check out file %s from %s\n", filename, cs);
}
}
if (old_file_is_dev_null && ok_to_create_file && (filestat.st_size != 0)) {
- fatal2("patch creates new file but existing file %s not empty\n",
- filename);
+ fatal("patch creates new file but existing file %s not empty\n",
+ filename);
}
filemode = filestat.st_mode;
if (!S_ISREG(filemode))
- fatal2("%s is not a normal file--can't patch\n", filename);
+ fatal("%s is not a normal file--can't patch\n", filename);
i_size = filestat.st_size;
if (out_of_mem) {
set_hunkmax(); /* make sure dynamic arrays are allocated */
@@ -158,11 +158,11 @@ plan_a(char *filename)
return FALSE; /* force plan b because plan a bombed */
}
- i_womp = malloc((MEM)(i_size+2));
- if (i_womp == Nullch)
+ i_womp = malloc(i_size+2);
+ if (i_womp == NULL)
return FALSE;
if ((ifd = open(filename, 0)) < 0)
- pfatal2("can't open file %s", filename);
+ pfatal("can't open file %s", filename);
if (read(ifd, i_womp, i_size) != i_size) {
Close(ifd); /* probably means i_size > 15 or 16 bits worth */
free(i_womp); /* at this point it doesn't matter if i_womp was */
@@ -180,9 +180,9 @@ plan_a(char *filename)
if (*s == '\n')
iline++;
}
- i_ptr = (char **)malloc((MEM)((iline + 2) * sizeof(char *)));
- if (i_ptr == Null(char **)) { /* shucks, it was a near thing */
- free((char *)i_womp);
+ i_ptr = malloc((iline + 2) * sizeof(char *));
+ if (i_ptr == NULL) { /* shucks, it was a near thing */
+ free(i_womp);
return FALSE;
}
@@ -198,28 +198,28 @@ plan_a(char *filename)
/* now check for revision, if any */
- if (revision != Nullch) {
+ if (revision != NULL) {
if (!rev_in_string(i_womp)) {
if (force) {
if (verbose)
- say2(
+ say(
"Warning: this file doesn't appear to be the %s version--patching anyway.\n",
revision);
}
else if (batch) {
- fatal2(
+ fatal(
"this file doesn't appear to be the %s version--aborting.\n", revision);
}
else {
- ask2(
+ ask(
"This file doesn't appear to be the %s version--patch anyway? [n] ",
revision);
if (*buf != 'y')
- fatal1("aborted\n");
+ fatal("aborted\n");
}
}
else if (verbose)
- say2("Good. This file appears to be the %s version.\n",
+ say("Good. This file appears to be the %s version.\n",
revision);
}
return TRUE; /* plan a will work */
@@ -233,67 +233,67 @@ plan_b(char *filename)
FILE *ifp;
int i = 0;
int maxlen = 1;
- bool found_revision = (revision == Nullch);
+ bool found_revision = (revision == NULL);
using_plan_a = FALSE;
- if ((ifp = fopen(filename, "r")) == Nullfp)
- pfatal2("can't open file %s", filename);
+ if ((ifp = fopen(filename, "r")) == NULL)
+ pfatal("can't open file %s", filename);
if ((tifd = creat(TMPINNAME, 0666)) < 0)
- pfatal2("can't open file %s", TMPINNAME);
- while (fgets(buf, sizeof buf, ifp) != Nullch) {
- if (revision != Nullch && !found_revision && rev_in_string(buf))
+ pfatal("can't open file %s", TMPINNAME);
+ while (fgets(buf, sizeof buf, ifp) != NULL) {
+ if (revision != NULL && !found_revision && rev_in_string(buf))
found_revision = TRUE;
if ((i = strlen(buf)) > maxlen)
maxlen = i; /* find longest line */
}
- if (revision != Nullch) {
+ if (revision != NULL) {
if (!found_revision) {
if (force) {
if (verbose)
- say2(
+ say(
"Warning: this file doesn't appear to be the %s version--patching anyway.\n",
revision);
}
else if (batch) {
- fatal2(
+ fatal(
"this file doesn't appear to be the %s version--aborting.\n", revision);
}
else {
- ask2(
+ ask(
"This file doesn't appear to be the %s version--patch anyway? [n] ",
revision);
if (*buf != 'y')
- fatal1("aborted\n");
+ fatal("aborted\n");
}
}
else if (verbose)
- say2("Good. This file appears to be the %s version.\n",
+ say("Good. This file appears to be the %s version.\n",
revision);
}
Fseek(ifp, 0L, 0); /* rewind file */
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");
+ tibuf[0] = malloc(BUFFERSIZE + 1);
+ tibuf[1] = malloc(BUFFERSIZE + 1);
+ if (tibuf[1] == NULL)
+ fatal("out of memory\n");
for (i=1; ; i++) {
if (! (i % lines_per_buf)) /* new block */
if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
- pfatal1("can't write temp file");
+ pfatal("can't write temp file");
if (fgets(tibuf[0] + maxlen * (i%lines_per_buf), maxlen + 1, ifp)
- == Nullch) {
+ == NULL) {
input_lines = i - 1;
if (i % lines_per_buf)
if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
- pfatal1("can't write temp file");
+ pfatal("can't write temp file");
break;
}
}
Fclose(ifp);
Close(tifd);
if ((tifd = open(TMPINNAME, 0)) < 0) {
- pfatal2("can't reopen file %s", TMPINNAME);
+ pfatal("can't reopen file %s", TMPINNAME);
}
}
@@ -316,9 +316,9 @@ ifetch(LINENUM line, int whichbuf)
whichbuf = 1;
else {
tiline[whichbuf] = baseline;
- Lseek(tifd, (long)baseline / lines_per_buf * BUFFERSIZE, 0);
+ Lseek(tifd, baseline / lines_per_buf * BUFFERSIZE, 0);
if (read(tifd, tibuf[whichbuf], BUFFERSIZE) < 0)
- pfatal2("error reading tmp file %s", TMPINNAME);
+ pfatal("error reading tmp file %s", TMPINNAME);
}
return tibuf[whichbuf] + (tireclen*offline);
}
@@ -332,7 +332,7 @@ rev_in_string(char *string)
char *s;
int patlen;
- if (revision == Nullch)
+ if (revision == NULL)
return TRUE;
patlen = strlen(revision);
if (strnEQ(string,revision,patlen) && isspace((unsigned char)string[patlen]))
diff --git a/usr.bin/patch/patch.c b/usr.bin/patch/patch.c
index 19e4446714f..f2a2db3057d 100644
--- a/usr.bin/patch/patch.c
+++ b/usr.bin/patch/patch.c
@@ -1,4 +1,4 @@
-/* $NetBSD: patch.c,v 1.10 2002/03/08 21:57:33 kristerw Exp $ */
+/* $NetBSD: patch.c,v 1.11 2002/03/11 18:47:51 kristerw Exp $ */
/* patch - a program to apply diffs to original files
*
@@ -25,7 +25,7 @@
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: patch.c,v 1.10 2002/03/08 21:57:33 kristerw Exp $");
+__RCSID("$NetBSD: patch.c,v 1.11 2002/03/11 18:47:51 kristerw Exp $");
#endif /* not lint */
#include "INTERN.h"
@@ -80,7 +80,7 @@ main(int argc, char *argv[])
setbuf(stderr, serrbuf);
for (i = 0; i<MAXFILEC; i++)
- filearg[i] = Nullch;
+ filearg[i] = NULL;
myuid = getuid();
@@ -88,7 +88,7 @@ main(int argc, char *argv[])
{
/* Directory for temporary files. */
char *tmpdir;
- int tmpname_len;
+ size_t tmpname_len;
tmpdir = getenv ("TMPDIR");
if (tmpdir == NULL) {
@@ -96,32 +96,32 @@ main(int argc, char *argv[])
}
tmpname_len = strlen (tmpdir) + 20;
- TMPOUTNAME = (char *) malloc (tmpname_len);
+ TMPOUTNAME = malloc (tmpname_len);
strcpy (TMPOUTNAME, tmpdir);
strcat (TMPOUTNAME, "/patchoXXXXXX");
if ((i = mkstemp(TMPOUTNAME)) < 0)
- pfatal2("can't create %s", TMPOUTNAME);
+ pfatal("can't create %s", TMPOUTNAME);
Close(i);
- TMPINNAME = (char *) malloc (tmpname_len);
+ TMPINNAME = malloc (tmpname_len);
strcpy (TMPINNAME, tmpdir);
strcat (TMPINNAME, "/patchiXXXXXX");
if ((i = mkstemp(TMPINNAME)) < 0)
- pfatal2("can't create %s", TMPINNAME);
+ pfatal("can't create %s", TMPINNAME);
Close(i);
- TMPREJNAME = (char *) malloc (tmpname_len);
+ TMPREJNAME = malloc (tmpname_len);
strcpy (TMPREJNAME, tmpdir);
strcat (TMPREJNAME, "/patchrXXXXXX");
if ((i = mkstemp(TMPREJNAME)) < 0)
- pfatal2("can't create %s", TMPREJNAME);
+ pfatal("can't create %s", TMPREJNAME);
Close(i);
- TMPPATNAME = (char *) malloc (tmpname_len);
+ TMPPATNAME = malloc (tmpname_len);
strcpy (TMPPATNAME, tmpdir);
strcat (TMPPATNAME, "/patchpXXXXXX");
if ((i = mkstemp(TMPPATNAME)) < 0)
- pfatal2("can't create %s", TMPPATNAME);
+ pfatal("can't create %s", TMPPATNAME);
Close(i);
}
@@ -153,7 +153,7 @@ main(int argc, char *argv[])
reinitialize_almost_everything()
) { /* for each patch in patch file */
- if (outname == Nullch)
+ if (outname == NULL)
outname = savestr(filearg[0]);
/* for ed script just up and do it and exit */
@@ -193,7 +193,7 @@ main(int argc, char *argv[])
/* dwim for reversed patch? */
if (!pch_swap()) {
if (fuzz == Nulline)
- say1(
+ say(
"Not enough memory to try swapped hunk! Assuming unswapped.\n");
continue;
}
@@ -201,37 +201,37 @@ main(int argc, char *argv[])
where = locate_hunk(fuzz); /* try again */
if (where == Nulline) { /* didn't find it swapped */
if (!pch_swap()) /* put it back to normal */
- fatal1("lost hunk on alloc error!\n");
+ fatal("lost hunk on alloc error!\n");
reverse = !reverse;
}
else if (noreverse) {
if (!pch_swap()) /* put it back to normal */
- fatal1("lost hunk on alloc error!\n");
+ fatal("lost hunk on alloc error!\n");
reverse = !reverse;
- say1(
+ say(
"Ignoring previously applied (or reversed) patch.\n");
skip_rest_of_patch = TRUE;
}
else if (batch) {
if (verbose)
- say3(
+ say(
"%seversed (or previously applied) patch detected! %s -R.",
reverse ? "R" : "Unr",
reverse ? "Assuming" : "Ignoring");
}
else {
- ask3(
+ ask(
"%seversed (or previously applied) patch detected! %s -R? [y] ",
reverse ? "R" : "Unr",
reverse ? "Assume" : "Ignore");
if (*buf == 'n') {
- ask1("Apply anyway? [n] ");
+ ask("Apply anyway? [n] ");
if (*buf != 'y')
skip_rest_of_patch = TRUE;
where = Nulline;
reverse = !reverse;
if (!pch_swap()) /* put it back to normal */
- fatal1("lost hunk on alloc error!\n");
+ fatal("lost hunk on alloc error!\n");
}
}
}
@@ -240,7 +240,7 @@ main(int argc, char *argv[])
if (skip_rest_of_patch) { /* just got decided */
Fclose(ofp);
- ofp = Nullfp;
+ ofp = NULL;
}
}
@@ -249,24 +249,24 @@ main(int argc, char *argv[])
abort_hunk();
failed++;
if (verbose)
- say3("Hunk #%d ignored at %ld.\n", hunk, newwhere);
+ say("Hunk #%d ignored at %ld.\n", hunk, newwhere);
}
else if (where == Nulline) {
abort_hunk();
failed++;
if (verbose)
- say3("Hunk #%d failed at %ld.\n", hunk, newwhere);
+ say("Hunk #%d failed at %ld.\n", hunk, newwhere);
}
else {
apply_hunk(where);
if (verbose) {
- say3("Hunk #%d succeeded at %ld", hunk, newwhere);
+ say("Hunk #%d succeeded at %ld", hunk, newwhere);
if (fuzz)
- say2(" with fuzz %ld", fuzz);
+ say(" with fuzz %ld", fuzz);
if (last_offset)
- say3(" (offset %ld line%s)",
+ say(" (offset %ld line%s)",
last_offset, last_offset==1L?"":"s");
- say1(".\n");
+ say(".\n");
}
}
}
@@ -274,13 +274,13 @@ main(int argc, char *argv[])
if (out_of_mem && using_plan_a) {
Argc = Argc_last;
Argv = Argv_last;
- say1("\n\nRan out of memory using Plan A--trying again...\n\n");
+ say("\n\nRan out of memory using Plan A--trying again...\n\n");
if (ofp)
Fclose(ofp);
- ofp = Nullfp;
+ ofp = NULL;
if (rejfp)
Fclose(rejfp);
- rejfp = Nullfp;
+ rejfp = NULL;
continue;
}
@@ -307,36 +307,24 @@ main(int argc, char *argv[])
if (remove_empty_files && stat(realout, &statbuf) == 0
&& statbuf.st_size == 0) {
if (verbose)
- say2("Removing %s (empty after patching).\n", realout);
+ say("Removing %s (empty after patching).\n", realout);
while (unlink(realout) >= 0) ; /* while is for Eunice. */
}
}
Fclose(rejfp);
- rejfp = Nullfp;
+ rejfp = NULL;
if (failed) {
failtotal += failed;
if (!*rejname) {
Strcpy(rejname, outname);
-#ifndef FLEXFILENAMES
- {
- char *s = strrchr(rejname,'/');
-
- if (!s)
- s = rejname;
- if (strlen(s) > 13)
- if (s[12] == '.') /* try to preserve difference */
- s[12] = s[13]; /* between .h, .c, .y, etc. */
- s[13] = '\0';
- }
-#endif
Strcat(rejname, REJEXT);
}
if (skip_rest_of_patch) {
- say4("%d out of %d hunks ignored--saving rejects to %s\n",
+ say("%d out of %d hunks ignored--saving rejects to %s\n",
failed, hunk, rejname);
}
else {
- say4("%d out of %d hunks failed--saving rejects to %s\n",
+ say("%d out of %d hunks failed--saving rejects to %s\n",
failed, hunk, rejname);
}
if (move_file(TMPREJNAME, rejname) < 0)
@@ -359,23 +347,23 @@ reinitialize_almost_everything(void)
last_frozen_line = 0;
filec = 0;
- if (filearg[0] != Nullch && !out_of_mem) {
+ if (filearg[0] != NULL && !out_of_mem) {
free(filearg[0]);
- filearg[0] = Nullch;
+ filearg[0] = NULL;
}
- if (outname != Nullch) {
+ if (outname != NULL) {
free(outname);
- outname = Nullch;
+ outname = NULL;
}
last_offset = 0;
diff_type = 0;
- if (revision != Nullch) {
+ if (revision != NULL) {
free(revision);
- revision = Nullch;
+ revision = NULL;
}
reverse = reverse_flag_specified;
@@ -384,14 +372,14 @@ reinitialize_almost_everything(void)
get_some_switches();
if (filec >= 2)
- fatal1("you may not change to a different patch file\n");
+ fatal("you may not change to a different patch file\n");
}
static char *
nextarg(void)
{
if (!--Argc)
- fatal2("missing argument after `%s'\n", *Argv);
+ fatal("missing argument after `%s'\n", *Argv);
return *++Argv;
}
@@ -450,7 +438,7 @@ decode_long_option(char *opt)
struct option key, *found;
key.long_opt = opt;
- found = (struct option *)bsearch(&key, options,
+ found = bsearch(&key, options,
sizeof(options) / sizeof(options[0]), sizeof(options[0]), optcmp);
return found ? found->short_opt : '\0';
@@ -475,9 +463,9 @@ get_some_switches(void)
}
if (*s != '-' || !s[1]) {
if (filec == MAXFILEC)
- fatal1("too many file arguments\n");
- if (filec == 1 && filearg[filec] != Nullch)
- fatal1("-i option and patchfile argument are mutually\
+ fatal("too many file arguments\n");
+ if (filec == 1 && filearg[filec] != NULL)
+ fatal("-i option and patchfile argument are mutually\
exclusive\n");
filearg[filec++] = savestr(s);
}
@@ -505,14 +493,14 @@ exclusive\n");
if (!*++s)
s = nextarg();
if (chdir(s) < 0)
- pfatal2("can't cd to %s", s);
+ pfatal("can't cd to %s", s);
break;
case 'D':
do_defines = TRUE;
if (!*++s)
s = nextarg();
if (!isalpha((unsigned char)*s) && '_' != *s)
- fatal1("argument to -D is not an identifier\n");
+ fatal("argument to -D is not an identifier\n");
Sprintf(if_defined, "#ifdef %s\n", s);
Sprintf(not_defined, "#ifndef %s\n", s);
Sprintf(end_defined, "#endif /* %s */\n", s);
@@ -532,7 +520,7 @@ exclusive\n");
maxfuzz = atoi(s);
break;
case 'i':
- if (filearg[1] != Nullch)
+ if (filearg[1] != NULL)
free(filearg[1]);
filearg[1] = savestr(nextarg());
break;
@@ -625,7 +613,7 @@ locate_hunk(LINENUM fuzz)
if (check_after && patch_match(first_guess, offset, fuzz)) {
#ifdef DEBUGGING
if (debug & 1)
- say3("Offset changing from %ld to %ld\n", last_offset, offset);
+ say("Offset changing from %ld to %ld\n", last_offset, offset);
#endif
last_offset = offset;
return first_guess+offset;
@@ -633,7 +621,7 @@ locate_hunk(LINENUM fuzz)
else if (check_before && patch_match(first_guess, -offset, fuzz)) {
#ifdef DEBUGGING
if (debug & 1)
- say3("Offset changing from %ld to %ld\n", last_offset, -offset);
+ say("Offset changing from %ld to %ld\n", last_offset, -offset);
#endif
last_offset = -offset;
return first_guess-offset;
@@ -684,7 +672,7 @@ abort_hunk(void)
fprintf(rejfp, "%c %s", pch_char(i), pfetch(i));
break;
default:
- fatal1("fatal internal error in abort_hunk\n");
+ fatal("fatal internal error in abort_hunk\n");
}
}
}
@@ -745,11 +733,11 @@ apply_hunk(LINENUM where)
new++;
}
else if (pch_char(new) != pch_char(old)) {
- say3("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
+ say("Out-of-sync patch, lines %ld,%ld--mangled text or line numbers, maybe?\n",
pch_hunk_beg() + old,
pch_hunk_beg() + new);
#ifdef DEBUGGING
- say3("oldchar = '%c', newchar = '%c'\n",
+ say("oldchar = '%c', newchar = '%c'\n",
pch_char(old), pch_char(new));
#endif
my_exit(1);
@@ -814,8 +802,8 @@ static void
init_output(char *name)
{
ofp = fopen(name, "w");
- if (ofp == Nullfp)
- pfatal2("can't create %s", name);
+ if (ofp == NULL)
+ pfatal("can't create %s", name);
}
/* Open a file to put hunks we can't locate. */
@@ -824,8 +812,8 @@ static void
init_reject(char *name)
{
rejfp = fopen(name, "w");
- if (rejfp == Nullfp)
- pfatal2("can't create %s", name);
+ if (rejfp == NULL)
+ pfatal("can't create %s", name);
}
/* Copy input file to output, up to wherever hunk is to be applied. */
@@ -836,7 +824,7 @@ copy_till(LINENUM lastline)
LINENUM R_last_frozen_line = last_frozen_line;
if (R_last_frozen_line > lastline)
- fatal1("misordered hunks! output would be garbled\n");
+ fatal("misordered hunks! output would be garbled\n");
while (R_last_frozen_line < lastline) {
dump_line(++R_last_frozen_line);
}
@@ -850,12 +838,12 @@ spew_output(void)
{
#ifdef DEBUGGING
if (debug & 256)
- say3("il=%ld lfl=%ld\n",input_lines,last_frozen_line);
+ say("il=%ld lfl=%ld\n",input_lines,last_frozen_line);
#endif
if (input_lines)
copy_till(input_lines); /* dump remainder of file */
Fclose(ofp);
- ofp = Nullfp;
+ ofp = NULL;
}
/* Copy one line from input to output. */
diff --git a/usr.bin/patch/pch.c b/usr.bin/patch/pch.c
index b1eb6ee9b56..a9391120a14 100644
--- a/usr.bin/patch/pch.c
+++ b/usr.bin/patch/pch.c
@@ -1,7 +1,7 @@
-/* $NetBSD: pch.c,v 1.8 2002/03/08 21:57:33 kristerw Exp $ */
+/* $NetBSD: pch.c,v 1.9 2002/03/11 18:47:51 kristerw Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: pch.c,v 1.8 2002/03/08 21:57:33 kristerw Exp $");
+__RCSID("$NetBSD: pch.c,v 1.9 2002/03/11 18:47:51 kristerw Exp $");
#endif /* not lint */
#include "EXTERN.h"
@@ -24,9 +24,9 @@ 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 char **p_line = NULL; /* the text of the hunk */
+static short *p_len = NULL; /* length of each line */
+static char *p_char = NULL; /* +, -, 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 */
@@ -47,7 +47,7 @@ re_patch(void)
p_newfirst = Nulline;
p_ptrn_lines = Nulline;
p_repl_lines = Nulline;
- p_end = (LINENUM)-1;
+ p_end = -1;
p_max = Nulline;
p_indent = 0;
}
@@ -57,18 +57,18 @@ re_patch(void)
void
open_patch_file(char *filename)
{
- if (filename == Nullch || !*filename || strEQ(filename, "-")) {
+ if (filename == NULL || !*filename || strEQ(filename, "-")) {
pfp = fopen(TMPPATNAME, "w");
- if (pfp == Nullfp)
- pfatal2("can't create %s", TMPPATNAME);
- while (fgets(buf, sizeof buf, stdin) != Nullch)
+ if (pfp == NULL)
+ pfatal("can't create %s", TMPPATNAME);
+ while (fgets(buf, sizeof buf, stdin) != NULL)
fputs(buf, pfp);
Fclose(pfp);
filename = TMPPATNAME;
}
pfp = fopen(filename, "r");
- if (pfp == Nullfp)
- pfatal2("patch file %s not found", filename);
+ if (pfp == NULL)
+ pfatal("patch file %s not found", filename);
Fstat(fileno(pfp), &filestat);
p_filesize = filestat.st_size;
next_intuit_at(0L,1L); /* start at the beginning */
@@ -81,11 +81,11 @@ void
set_hunkmax(void)
{
if (p_line == NULL)
- p_line = (char**) malloc((MEM)hunkmax * sizeof(char *));
+ p_line = malloc(hunkmax * sizeof(char *));
if (p_len == NULL)
- p_len = (short*) malloc((MEM)hunkmax * sizeof(short));
+ p_len = malloc(hunkmax * sizeof(short));
if (p_char == NULL)
- p_char = (char*) malloc((MEM)hunkmax * sizeof(char));
+ p_char = malloc(hunkmax * sizeof(char));
}
/* Enlarge the arrays containing the current hunk of patch. */
@@ -99,14 +99,14 @@ grow_hunkmax(void)
* 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);
- p_line = (char**) realloc(p_line, (MEM)hunkmax * sizeof(char *));
- p_len = (short*) realloc(p_len, (MEM)hunkmax * sizeof(short));
- p_char = (char*) realloc(p_char, (MEM)hunkmax * sizeof(char));
- if (p_line != Null(char**) && p_len != Null(short*) && p_char != Nullch)
+ assert(p_line != NULL && p_len != NULL && p_char != NULL);
+ p_line = realloc(p_line, hunkmax * sizeof(char *));
+ p_len = realloc(p_len, hunkmax * sizeof(short));
+ p_char = realloc(p_char, hunkmax * sizeof(char));
+ if (p_line != NULL && p_len != NULL && p_char != NULL)
return;
if (!using_plan_a)
- fatal1("out of memory\n");
+ fatal("out of memory\n");
out_of_mem = TRUE; /* whatever is null will be allocated again */
/* from within plan_a(), of all places */
}
@@ -118,23 +118,23 @@ there_is_another_patch(void)
{
if (p_base != 0L && p_base >= p_filesize) {
if (verbose)
- say1("done\n");
+ say("done\n");
return FALSE;
}
if (verbose)
- say1("Hmm...");
+ say("Hmm...");
diff_type = intuit_diff_type();
if (!diff_type) {
if (p_base != 0L) {
if (verbose)
- say1(" Ignoring the trailing garbage.\ndone\n");
+ say(" Ignoring the trailing garbage.\ndone\n");
}
else
- say1(" I can't seem to find a patch in there anywhere.\n");
+ say(" I can't seem to find a patch in there anywhere.\n");
return FALSE;
}
if (verbose)
- say3(" %sooks like %s to me...\n",
+ say(" %sooks like %s to me...\n",
(p_base == 0L ? "L" : "The next patch l"),
diff_type == UNI_DIFF ? "a unified diff" :
diff_type == CONTEXT_DIFF ? "a context diff" :
@@ -142,29 +142,29 @@ there_is_another_patch(void)
diff_type == NORMAL_DIFF ? "a normal diff" :
"an ed script" );
if (p_indent && verbose)
- say3("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
+ say("(Patch is indented %d space%s.)\n", p_indent, p_indent==1?"":"s");
skip_to(p_start,p_sline);
- while (filearg[0] == Nullch) {
+ while (filearg[0] == NULL) {
if (force || batch) {
- say1("No file to patch. Skipping...\n");
+ say("No file to patch. Skipping...\n");
filearg[0] = savestr(bestguess);
skip_rest_of_patch = TRUE;
return TRUE;
}
- ask1("File to patch: ");
+ ask("File to patch: ");
if (*buf != '\n') {
if (bestguess)
free(bestguess);
bestguess = savestr(buf);
filearg[0] = fetchname(buf, 0, FALSE);
}
- if (filearg[0] == Nullch) {
- ask1("No file found--skip this patch? [n] ");
+ if (filearg[0] == NULL) {
+ ask("No file found--skip this patch? [n] ");
if (*buf != 'y') {
continue;
}
if (verbose)
- say1("Skipping patch...\n");
+ say("Skipping patch...\n");
filearg[0] = fetchname(bestguess, 0, TRUE);
skip_rest_of_patch = TRUE;
return TRUE;
@@ -189,14 +189,14 @@ intuit_diff_type(void)
int indent;
char *s;
char *t;
- char *indtmp = Nullch;
- char *oldtmp = Nullch;
- char *newtmp = Nullch;
- char *indname = Nullch;
- char *oldname = Nullch;
- char *newname = Nullch;
+ char *indtmp = NULL;
+ char *oldtmp = NULL;
+ char *newtmp = NULL;
+ char *indname = NULL;
+ char *oldname = NULL;
+ char *newname = NULL;
int retval;
- bool no_filearg = (filearg[0] == Nullch);
+ bool no_filearg = (filearg[0] == NULL);
ok_to_create_file = FALSE;
old_file_is_dev_null = FALSE;
@@ -209,7 +209,7 @@ intuit_diff_type(void)
this_line = ftell(pfp);
indent = 0;
p_input_line++;
- if (fgets(buf, sizeof buf, pfp) == Nullch) {
+ if (fgets(buf, sizeof buf, pfp) == NULL) {
if (first_command_line >= 0L) {
/* nothing but deletes!? */
p_start = first_command_line;
@@ -253,7 +253,7 @@ intuit_diff_type(void)
*t = '\0';
if (!*revision) {
free(revision);
- revision = Nullch;
+ revision = NULL;
}
}
if ((!diff_type || diff_type == ED_DIFF) &&
@@ -301,13 +301,13 @@ intuit_diff_type(void)
}
scan_exit:
if (no_filearg) {
- if (indtmp != Nullch)
+ if (indtmp != NULL)
indname = fetchname(indtmp, strippath, ok_to_create_file);
- if (oldtmp != Nullch) {
+ if (oldtmp != NULL) {
oldname = fetchname(oldtmp, strippath, ok_to_create_file);
old_file_is_dev_null = filename_is_dev_null;
}
- if (newtmp != Nullch)
+ if (newtmp != NULL)
newname = fetchname(newtmp, strippath, ok_to_create_file);
if (oldname && newname) {
if (strlen(oldname) < strlen(newname))
@@ -324,18 +324,18 @@ intuit_diff_type(void)
}
if (bestguess) {
free(bestguess);
- bestguess = Nullch;
+ bestguess = NULL;
}
- if (filearg[0] != Nullch)
+ if (filearg[0] != NULL)
bestguess = savestr(filearg[0]);
- else if (indtmp != Nullch)
+ else if (indtmp != NULL)
bestguess = fetchname(indtmp, strippath, TRUE);
else {
- if (oldtmp != Nullch) {
+ if (oldtmp != NULL) {
oldname = fetchname(oldtmp, strippath, TRUE);
old_file_is_dev_null = filename_is_dev_null;
}
- if (newtmp != Nullch)
+ if (newtmp != NULL)
newname = fetchname(newtmp, strippath, TRUE);
if (oldname && newname) {
if (strlen(oldname) < strlen(newname))
@@ -348,17 +348,17 @@ intuit_diff_type(void)
else if (newname)
bestguess = savestr(newname);
}
- if (indtmp != Nullch)
+ if (indtmp != NULL)
free(indtmp);
- if (oldtmp != Nullch)
+ if (oldtmp != NULL)
free(oldtmp);
- if (newtmp != Nullch)
+ if (newtmp != NULL)
free(newtmp);
- if (indname != Nullch)
+ if (indname != NULL)
free(indname);
- if (oldname != Nullch)
+ if (oldname != NULL)
free(oldname);
- if (newname != Nullch)
+ if (newname != NULL)
free(newname);
return retval;
}
@@ -382,13 +382,13 @@ skip_to(long file_pos, long file_line)
assert(p_base <= file_pos);
if (verbose && p_base < file_pos) {
Fseek(pfp, p_base, 0);
- say1("The text leading up to this was:\n--------------------------\n");
+ say("The text leading up to this was:\n--------------------------\n");
while (ftell(pfp) < file_pos) {
ret = fgets(buf, sizeof buf, pfp);
- assert(ret != Nullch);
- say2("|%s", buf);
+ assert(ret != NULL);
+ say("|%s", buf);
}
- say1("--------------------------\n");
+ say("--------------------------\n");
}
else
Fseek(pfp, file_pos, 0);
@@ -399,7 +399,7 @@ skip_to(long file_pos, long file_line)
static void
malformed(void)
{
- fatal3("malformed patch at line %ld: %s", p_input_line, buf);
+ fatal("malformed patch at line %ld: %s", p_input_line, buf);
/* about as informative as "Syntax error" in C */
}
@@ -441,7 +441,7 @@ another_hunk(void)
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch || strnNE(buf, "********", 8)) {
+ if (ret == NULL || strnNE(buf, "********", 8)) {
next_intuit_at(line_beginning,p_input_line);
return FALSE;
}
@@ -451,7 +451,7 @@ another_hunk(void)
line_beginning = ftell(pfp);
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch) {
+ if (ret == NULL) {
if (p_max - p_end < 4)
Strcpy(buf, " \n"); /* assume blank lines got chopped */
else {
@@ -459,17 +459,13 @@ another_hunk(void)
repl_missing = TRUE;
goto hunk_done;
}
- fatal1("unexpected end of file in patch\n");
+ fatal("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
+ p_line[p_end] = NULL;
switch (*buf) {
case '*':
if (strnEQ(buf, "********", 8)) {
@@ -478,7 +474,7 @@ another_hunk(void)
goto hunk_done;
}
else
- fatal2("unexpected end of hunk at line %ld\n",
+ fatal("unexpected end of hunk at line %ld\n",
p_input_line);
}
if (p_end != 0) {
@@ -486,7 +482,7 @@ another_hunk(void)
repl_missing = TRUE;
goto hunk_done;
}
- fatal3("unexpected *** at line %ld: %s", p_input_line, buf);
+ fatal("unexpected *** at line %ld: %s", p_input_line, buf);
}
context = 0;
p_line[p_end] = savestr(buf);
@@ -499,13 +495,13 @@ another_hunk(void)
malformed ();
if (strnEQ(s,"0,0",3))
strcpy(s,s+2);
- p_first = (LINENUM) atol(s);
+ p_first = 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;
+ p_ptrn_lines = atol(s) - p_first + 1;
}
else if (p_first)
p_ptrn_lines = 1;
@@ -537,12 +533,12 @@ another_hunk(void)
repl_missing = TRUE;
goto hunk_done;
}
- fatal3(
+ fatal(
"duplicate \"---\" at line %ld--check line numbers at line %ld\n",
p_input_line, p_hunk_beg + repl_beginning);
}
else {
- fatal4(
+ fatal(
"%s \"---\" at line %ld--check line numbers at line %ld\n",
(p_end <= p_ptrn_lines
? "Premature"
@@ -563,13 +559,13 @@ another_hunk(void)
for (s=buf; *s && !isdigit((unsigned char)*s); s++) ;
if (!*s)
malformed ();
- p_newfirst = (LINENUM) atol(s);
+ p_newfirst = 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;
+ p_repl_lines = atol(s) - p_newfirst + 1;
}
else if (p_newfirst)
p_repl_lines = 1;
@@ -579,7 +575,7 @@ another_hunk(void)
}
p_max = p_repl_lines + p_end;
if (p_max > MAXHUNKSIZE)
- fatal4("hunk too large (%ld lines) at line %ld: %s",
+ fatal("hunk too large (%ld lines) at line %ld: %s",
p_max, p_input_line, buf);
while (p_max >= hunkmax)
grow_hunkmax();
@@ -661,7 +657,7 @@ another_hunk(void)
hunk_done:
if (p_end >=0 && !repl_beginning)
- fatal2("no --- found in patch at line %ld\n", pch_hunk_beg());
+ fatal("no --- found in patch at line %ld\n", pch_hunk_beg());
if (repl_missing) {
@@ -703,7 +699,7 @@ another_hunk(void)
if (diff_type == CONTEXT_DIFF &&
(fillcnt || (p_first > 1 && ptrn_copiable > 2*p_context)) ) {
if (verbose)
- say4("%s\n%s\n%s\n",
+ say("%s\n%s\n%s\n",
"(Fascinating--this is really a new-style context diff but without",
"the telltale extra asterisks on the *** line that usually indicate",
"the new style...)");
@@ -718,7 +714,7 @@ another_hunk(void)
while (fillsrc <= p_end && p_char[fillsrc] != ' ')
fillsrc++;
if (fillsrc > p_end)
- fatal2("replacement text or line numbers mangled in hunk at line %ld\n",
+ fatal("replacement text or line numbers mangled in hunk at line %ld\n",
p_hunk_beg);
p_line[filldst] = p_line[fillsrc];
p_char[filldst] = p_char[fillsrc];
@@ -746,27 +742,27 @@ another_hunk(void)
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch || strnNE(buf, "@@ -", 4)) {
+ if (ret == NULL || strnNE(buf, "@@ -", 4)) {
next_intuit_at(line_beginning,p_input_line);
return FALSE;
}
s = buf+4;
if (!*s)
malformed ();
- p_first = (LINENUM) atol(s);
+ p_first = atol(s);
while (isdigit((unsigned char)*s)) s++;
if (*s == ',') {
- p_ptrn_lines = (LINENUM) atol(++s);
+ p_ptrn_lines = 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);
+ p_newfirst = atol(s);
while (isdigit((unsigned char)*s)) s++;
if (*s == ',') {
- p_repl_lines = (LINENUM) atol(++s);
+ p_repl_lines = atol(++s);
while (isdigit((unsigned char)*s)) s++;
} else
p_repl_lines = 1;
@@ -802,11 +798,11 @@ another_hunk(void)
line_beginning = ftell(pfp);
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch) {
+ if (ret == NULL) {
if (p_max - filldst < 3)
Strcpy(buf, " \n"); /* assume blank lines got chopped */
else {
- fatal1("unexpected end of file in patch\n");
+ fatal("unexpected end of file in patch\n");
}
}
if (*buf == '\t' || *buf == '\n') {
@@ -889,14 +885,14 @@ another_hunk(void)
p_context = 0;
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch || !isdigit((unsigned char)*buf)) {
+ if (ret == NULL || !isdigit((unsigned char)*buf)) {
next_intuit_at(line_beginning,p_input_line);
return FALSE;
}
- p_first = (LINENUM)atol(buf);
+ p_first = atol(buf);
for (s=buf; isdigit((unsigned char)*s); s++) ;
if (*s == ',') {
- p_ptrn_lines = (LINENUM)atol(++s) - p_first + 1;
+ p_ptrn_lines = atol(++s) - p_first + 1;
while (isdigit((unsigned char)*s)) s++;
}
else
@@ -904,17 +900,17 @@ another_hunk(void)
hunk_type = *s;
if (hunk_type == 'a')
p_first++; /* do append rather than insert */
- min = (LINENUM)atol(++s);
+ min = atol(++s);
for (; isdigit((unsigned char)*s); s++) ;
if (*s == ',')
- max = (LINENUM)atol(++s);
+ max = 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",
+ fatal("hunk too large (%ld lines) at line %ld: %s",
p_end, p_input_line, buf);
while (p_end >= hunkmax)
grow_hunkmax();
@@ -930,11 +926,11 @@ another_hunk(void)
for (i=1; i<=p_ptrn_lines; i++) {
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch)
- fatal2("unexpected end of file in patch at line %ld\n",
+ if (ret == NULL)
+ fatal("unexpected end of file in patch at line %ld\n",
p_input_line);
if (*buf != '<')
- fatal2("< expected at line %ld of patch\n", p_input_line);
+ fatal("< expected at line %ld of patch\n", p_input_line);
p_line[i] = savestr(buf+2);
if (out_of_mem) {
p_end = i-1;
@@ -946,11 +942,11 @@ another_hunk(void)
if (hunk_type == 'c') {
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch)
- fatal2("unexpected end of file in patch at line %ld\n",
+ if (ret == NULL)
+ fatal("unexpected end of file in patch at line %ld\n",
p_input_line);
if (*buf != '-')
- fatal2("--- expected at line %ld of patch\n", p_input_line);
+ fatal("--- expected at line %ld of patch\n", p_input_line);
}
Sprintf(buf, "--- %ld,%ld\n", min, max);
p_line[i] = savestr(buf);
@@ -962,11 +958,11 @@ another_hunk(void)
for (i++; i<=p_end; i++) {
ret = pgets(buf, sizeof buf, pfp);
p_input_line++;
- if (ret == Nullch)
- fatal2("unexpected end of file in patch at line %ld\n",
+ if (ret == NULL)
+ fatal("unexpected end of file in patch at line %ld\n",
p_input_line);
if (*buf != '>')
- fatal2("> expected at line %ld of patch\n", p_input_line);
+ fatal("> expected at line %ld of patch\n", p_input_line);
p_line[i] = savestr(buf+2);
if (out_of_mem) {
p_end = i-1;
@@ -978,7 +974,7 @@ another_hunk(void)
}
if (reverse) /* backwards patch? */
if (!pch_swap())
- say1("Not enough memory to swap next hunk!\n");
+ say("Not enough memory to swap next hunk!\n");
#ifdef DEBUGGING
if (debug & 2) {
int i;
@@ -1008,7 +1004,7 @@ pgets(char *bf, int sz, FILE *fp)
char *s;
int indent = 0;
- if (p_indent && ret != Nullch) {
+ if (p_indent && ret != NULL) {
for (s=buf;
indent < p_indent && (*s == ' ' || *s == '\t' || *s == 'X'); s++) {
if (*s == '\t')
@@ -1044,18 +1040,18 @@ pch_swap(void)
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;
+ p_line = NULL; /* force set_hunkmax to allocate again */
+ p_len = NULL;
+ p_char = NULL;
set_hunkmax();
- if (p_line == Null(char**) || p_len == Null(short*) || p_char == Nullch) {
- if (p_line == Null(char**))
+ if (p_line == NULL || p_len == NULL || p_char == NULL) {
+ if (p_line == NULL)
free(p_line);
p_line = tp_line;
- if (p_len == Null(short*))
+ if (p_len == NULL)
free(p_len);
p_len = tp_len;
- if (p_char == Nullch)
+ if (p_char == NULL)
free(p_char);
p_char = tp_char;
return FALSE; /* not enough memory to swap hunk! */
@@ -1114,11 +1110,11 @@ pch_swap(void)
i = p_ptrn_lines;
p_ptrn_lines = p_repl_lines;
p_repl_lines = i;
- if (tp_line == Null(char**))
+ if (tp_line == NULL)
free(tp_line);
- if (tp_len == Null(short*))
+ if (tp_len == NULL)
free(tp_len);
- if (tp_char == Nullch)
+ if (tp_char == NULL)
free(tp_char);
return TRUE;
}
@@ -1224,7 +1220,7 @@ do_ed_script(void)
}
for (;;) {
beginning_of_this_line = ftell(pfp);
- if (pgets(buf, sizeof buf, pfp) == Nullch) {
+ if (pgets(buf, sizeof buf, pfp) == NULL) {
next_intuit_at(beginning_of_this_line,p_input_line);
break;
}
@@ -1236,7 +1232,7 @@ do_ed_script(void)
if (!skip_rest_of_patch)
fputs(buf, pipefp);
if (*t != 'd') {
- while (pgets(buf, sizeof buf, pfp) != Nullch) {
+ while (pgets(buf, sizeof buf, pfp) != NULL) {
p_input_line++;
if (!skip_rest_of_patch)
fputs(buf, pipefp);
diff --git a/usr.bin/patch/pch.h b/usr.bin/patch/pch.h
index f71a5b63ae9..87f0912cdc0 100644
--- a/usr.bin/patch/pch.h
+++ b/usr.bin/patch/pch.h
@@ -1,6 +1,6 @@
-/* $NetBSD: pch.h,v 1.5 2002/03/08 21:57:33 kristerw Exp $ */
+/* $NetBSD: pch.h,v 1.6 2002/03/11 18:47:51 kristerw Exp $ */
-EXT FILE *pfp INIT(Nullfp); /* patch file pointer */
+EXT FILE *pfp INIT(NULL); /* patch file pointer */
void re_patch(void);
void open_patch_file(char *);
diff --git a/usr.bin/patch/util.c b/usr.bin/patch/util.c
index 8925406308a..8bc688fde27 100644
--- a/usr.bin/patch/util.c
+++ b/usr.bin/patch/util.c
@@ -1,7 +1,7 @@
-/* $NetBSD: util.c,v 1.9 2002/03/08 21:57:33 kristerw Exp $ */
+/* $NetBSD: util.c,v 1.10 2002/03/11 18:47:51 kristerw Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: util.c,v 1.9 2002/03/08 21:57:33 kristerw Exp $");
+__RCSID("$NetBSD: util.c,v 1.10 2002/03/11 18:47:51 kristerw Exp $");
#endif /* not lint */
#include "EXTERN.h"
@@ -9,12 +9,8 @@ __RCSID("$NetBSD: util.c,v 1.9 2002/03/08 21:57:33 kristerw Exp $");
#include "INTERN.h"
#include "util.h"
#include "backupfile.h"
-#ifdef __STDC__
-#include <stdarg.h>
-#else
-#include <varargs.h>
-#endif
+#include <stdarg.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
@@ -34,14 +30,14 @@ move_file(char *from, char *to)
if (strEQ(to, "-")) {
#ifdef DEBUGGING
if (debug & 4)
- say2("Moving %s to stdout.\n", from);
+ say("Moving %s to stdout.\n", from);
#endif
fromfd = open(from, 0);
if (fromfd < 0)
- pfatal2("internal error, can't reopen %s", from);
+ pfatal("internal error, can't reopen %s", from);
while ((i=read(fromfd, buf, sizeof buf)) > 0)
if (write(1, buf, i) != 1)
- pfatal1("write failed");
+ pfatal("write failed");
Close(fromfd);
return 0;
}
@@ -53,7 +49,7 @@ move_file(char *from, char *to)
#ifndef NODIR
char *backupname = find_backup_file_name(to);
if (backupname == (char *) 0)
- fatal1("out of memory\n");
+ fatal("out of memory\n");
Strcpy(bakname, backupname);
free(backupname);
#else /* NODIR */
@@ -86,7 +82,7 @@ move_file(char *from, char *to)
while (unlink(bakname) >= 0) ; /* while() is for benefit of Eunice */
#ifdef DEBUGGING
if (debug & 4)
- say3("Moving %s to %s.\n", to, bakname);
+ say("Moving %s to %s.\n", to, bakname);
#endif
if (link(to, bakname) < 0) {
/* Maybe `to' is a symlink into a different file system.
@@ -97,16 +93,16 @@ move_file(char *from, char *to)
bakfd = creat(bakname, 0666);
if (bakfd < 0) {
- say4("Can't backup %s, output is in %s: %s\n", to, from,
- strerror(errno));
+ say("Can't backup %s, output is in %s: %s\n", to, from,
+ strerror(errno));
return -1;
}
tofd = open(to, 0);
if (tofd < 0)
- pfatal2("internal error, can't open %s", to);
+ pfatal("internal error, can't open %s", to);
while ((i=read(tofd, buf, sizeof buf)) > 0)
if (write(bakfd, buf, i) != i)
- pfatal1("write failed");
+ pfatal("write failed");
Close(tofd);
Close(bakfd);
}
@@ -114,23 +110,23 @@ move_file(char *from, char *to)
}
#ifdef DEBUGGING
if (debug & 4)
- say3("Moving %s to %s.\n", from, to);
+ say("Moving %s to %s.\n", from, to);
#endif
if (link(from, to) < 0) { /* different file system? */
int tofd;
tofd = creat(to, 0666);
if (tofd < 0) {
- say4("Can't create %s, output is in %s: %s\n",
+ say("Can't create %s, output is in %s: %s\n",
to, from, strerror(errno));
return -1;
}
fromfd = open(from, 0);
if (fromfd < 0)
- pfatal2("internal error, can't reopen %s", from);
+ pfatal("internal error, can't reopen %s", from);
while ((i=read(fromfd, buf, sizeof buf)) > 0)
if (write(tofd, buf, i) != i)
- pfatal1("write failed");
+ pfatal("write failed");
Close(fromfd);
Close(tofd);
}
@@ -149,13 +145,13 @@ copy_file(char *from, char *to)
tofd = creat(to, 0666);
if (tofd < 0)
- pfatal2("can't create %s", to);
+ pfatal("can't create %s", to);
fromfd = open(from, 0);
if (fromfd < 0)
- pfatal2("internal error, can't reopen %s", from);
+ pfatal("internal error, can't reopen %s", from);
while ((i=read(fromfd, buf, sizeof buf)) > 0)
if (write(tofd, buf, i) != i)
- pfatal2("write to %s failed", to);
+ pfatal("write to %s failed", to);
Close(fromfd);
Close(tofd);
}
@@ -172,12 +168,12 @@ savestr(char *s)
s = "Oops";
t = s;
while (*t++);
- rv = malloc((MEM) (t - s));
- if (rv == Nullch) {
+ rv = malloc(t - s);
+ if (rv == NULL) {
if (using_plan_a)
out_of_mem = TRUE;
else
- fatal1("out of memory\n");
+ fatal("out of memory\n");
}
else {
t = rv;
@@ -186,38 +182,13 @@ savestr(char *s)
return rv;
}
-#if defined(lint) && defined(CANVARARG)
-
-/*VARARGS ARGSUSED*/
-say(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-fatal(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-pfatal(pat) char *pat; { ; }
-/*VARARGS ARGSUSED*/
-ask(pat) char *pat; { ; }
-
-#else
-
/* Vanilla terminal output (buffered). */
void
-#ifdef __STDC__
say(const char *pat, ...)
-#else
-say(va_alist)
- va_dcl
-#endif
{
va_list ap;
-#ifdef __STDC__
va_start(ap, pat);
-#else
- const char *pat;
-
- va_start(ap);
- pat = va_arg(ap, const char *);
-#endif
vfprintf(stderr, pat, ap);
va_end(ap);
@@ -227,22 +198,10 @@ say(va_alist)
/* Terminal output, pun intended. */
void /* very void */
-#ifdef __STDC__
fatal(const char *pat, ...)
-#else
-fatal(va_alist)
- va_dcl
-#endif
{
va_list ap;
-#ifdef __STDC__
va_start(ap, pat);
-#else
- const char *pat;
-
- va_start(ap);
- pat = va_arg(ap, const char *);
-#endif
fprintf(stderr, "patch: **** ");
vfprintf(stderr, pat, ap);
@@ -253,23 +212,11 @@ fatal(va_alist)
/* Say something from patch, something from the system, then silence . . . */
void /* very void */
-#ifdef __STDC__
pfatal(const char *pat, ...)
-#else
-pfatal(va_alist)
- va_dcl
-#endif
{
va_list ap;
int errnum = errno;
-#ifdef __STDC__
va_start(ap, pat);
-#else
- const char *pat;
-
- va_start(ap);
- pat = va_arg(ap, const char *);
-#endif
fprintf(stderr, "patch: **** ");
vfprintf(stderr, pat, ap);
@@ -280,25 +227,13 @@ pfatal(va_alist)
/* Get a response from the user, somehow or other. */
void
-#ifdef __STDC__
ask(const char *pat, ...)
-#else
-ask(va_alist)
- va_dcl
-#endif
{
int ttyfd;
int r;
bool tty2 = isatty(2);
va_list ap;
-#ifdef __STDC__
va_start(ap, pat);
-#else
- const char *pat;
-
- va_start(ap);
- pat = va_arg(ap, const char *);
-#endif
(void) vsprintf(buf, pat, ap);
va_end(ap);
@@ -332,41 +267,26 @@ ask(va_alist)
else
buf[r] = '\0';
if (!tty2)
- say2("%s",buf);
+ say("%s",buf);
}
-#endif /* lint */
/* How to handle certain events when not in a critical region. */
void
set_signals(int reset)
{
-#ifndef lint
-#ifdef VOIDSIG
- static void (*hupval) __P((int)),(*intval) __P((int));
-#else
- static int (*hupval) __P((int)),(*intval)__P((int));
-#endif
+ static void (*hupval)(int),(*intval)(int);
if (!reset) {
hupval = signal(SIGHUP, SIG_IGN);
if (hupval != SIG_IGN)
-#ifdef VOIDSIG
hupval = my_exit;
-#else
- hupval = (int(*) __P((int)))my_exit;
-#endif
intval = signal(SIGINT, SIG_IGN);
if (intval != SIG_IGN)
-#ifdef VOIDSIG
intval = my_exit;
-#else
- intval = (int(*) __P((int)))my_exit;
-#endif
}
Signal(SIGHUP, hupval);
Signal(SIGINT, intval);
-#endif
}
/* How to handle certain events when in a critical region. */
@@ -437,17 +357,17 @@ fetchname(char *at, int strip_leading, int assume_exists)
int sleading = strip_leading;
if (!at)
- return Nullch;
+ return NULL;
while (isspace((unsigned char)*at))
at++;
#ifdef DEBUGGING
if (debug & 128)
- say4("fetchname %s %d %d\n",at,strip_leading,assume_exists);
+ say("fetchname %s %d %d\n",at,strip_leading,assume_exists);
#endif
filename_is_dev_null = FALSE;
if (strnEQ(at, "/dev/null", 9)) { /* so files can be created by diffing */
filename_is_dev_null = TRUE;
- return Nullch; /* against /dev/null. */
+ return NULL; /* against /dev/null. */
}
name = fullname = t = savestr(at);
@@ -489,7 +409,7 @@ fetchname(char *at, int strip_leading, int assume_exists)
|| try( "%s%s", SCCSPREFIX, filebase))
return name;
free(name);
- name = Nullch;
+ name = NULL;
}
return name;
diff --git a/usr.bin/patch/util.h b/usr.bin/patch/util.h
index 11bc0fc6e68..adbecc63c3d 100644
--- a/usr.bin/patch/util.h
+++ b/usr.bin/patch/util.h
@@ -1,70 +1,4 @@
-/* $NetBSD: util.h,v 1.6 2002/03/08 21:57:33 kristerw Exp $ */
-
-/* and for those machine that can't handle a variable argument list */
-
-#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
+/* $NetBSD: util.h,v 1.7 2002/03/11 18:47:51 kristerw Exp $ */
EXT char serrbuf[BUFSIZ]; /* buffer for stderr */
diff --git a/usr.bin/patch/version.c b/usr.bin/patch/version.c
index f8b4cc65354..92b62929281 100644
--- a/usr.bin/patch/version.c
+++ b/usr.bin/patch/version.c
@@ -1,7 +1,7 @@
-/* $NetBSD: version.c,v 1.4 1998/02/22 13:33:51 christos Exp $ */
+/* $NetBSD: version.c,v 1.5 2002/03/11 18:47:51 kristerw Exp $ */
#include <sys/cdefs.h>
#ifndef lint
-__RCSID("$NetBSD: version.c,v 1.4 1998/02/22 13:33:51 christos Exp $");
+__RCSID("$NetBSD: version.c,v 1.5 2002/03/11 18:47:51 kristerw Exp $");
#endif /* not lint */
#include "EXTERN.h"
@@ -14,7 +14,7 @@ __RCSID("$NetBSD: version.c,v 1.4 1998/02/22 13:33:51 christos Exp $");
/* Print out the version number and die. */
void
-version()
+version(void)
{
fprintf(stderr, "Patch version 2.0, patch level %s\n", PATCHLEVEL);
my_exit(0);
diff --git a/usr.bin/patch/version.h b/usr.bin/patch/version.h
index b3e8a6d6652..5ac2516011f 100644
--- a/usr.bin/patch/version.h
+++ b/usr.bin/patch/version.h
@@ -1,3 +1,3 @@
-/* $NetBSD: version.h,v 1.4 1998/02/22 13:33:51 christos Exp $ */
+/* $NetBSD: version.h,v 1.5 2002/03/11 18:47:51 kristerw Exp $ */
-void version __P((void));
+void version(void);