From d31142de3e4e91bdd5a4c8e42f260d075a0c30a9 Mon Sep 17 00:00:00 2001 From: "Robert R. Henry" Date: Tue, 4 May 1982 19:34:15 -0800 Subject: [PATCH] Preserves links by writing to /tmp and copying. Removed #ifdef ERNIE SCCS-vsn: usr.bin/error/Makefile 1.4 SCCS-vsn: usr.bin/error/input.c 1.6 SCCS-vsn: usr.bin/error/main.c 1.4 SCCS-vsn: usr.bin/error/touch.c 1.4 --- usr/src/usr.bin/error/Makefile | 4 +- usr/src/usr.bin/error/input.c | 7 +--- usr/src/usr.bin/error/main.c | 11 +----- usr/src/usr.bin/error/touch.c | 70 ++++++++++++++++++++++++++++------ 4 files changed, 63 insertions(+), 29 deletions(-) diff --git a/usr/src/usr.bin/error/Makefile b/usr/src/usr.bin/error/Makefile index db3f300182..e640de442d 100644 --- a/usr/src/usr.bin/error/Makefile +++ b/usr/src/usr.bin/error/Makefile @@ -1,5 +1,5 @@ # -# @(#)Makefile 1.3 (Berkeley) %G% +# @(#)Makefile 1.4 (Berkeley) %G% # # error.h error header file # errorinput.c does all of the input, and canonicalizes errors @@ -16,7 +16,7 @@ SRCS = errormain.c errorinput.c errorpi.c errorsubr.c errorfilter.c errortouch.c PSRCS = $(SRCS) OBJS = errormain.o errorinput.o errorpi.o errorsubr.o errorfilter.o errortouch.o -DFLAGS = -DDEBUG -DERNIE +DFLAGS = -DDEBUG CFLAGS = -O $(DFLAGS) LINTFLAGS = $(DFLAGS) diff --git a/usr/src/usr.bin/error/input.c b/usr/src/usr.bin/error/input.c index 775ba58721..2f983a7b00 100644 --- a/usr/src/usr.bin/error/input.c +++ b/usr/src/usr.bin/error/input.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)input.c 1.5 (Berkeley) 82/05/04"; +static char *sccsid = "@(#)input.c 1.6 (Berkeley) 82/05/04"; #include #include #include "error.h" @@ -44,9 +44,6 @@ eaterrors(r_errorc, r_errorv) */ wordv -= 1; if ( 0 -#ifndef ERNIE - || (piflag && ( (errorclass = pi() ) != C_UNKNOWN)) -#endif || (( errorclass = onelong() ) != C_UNKNOWN) || (( errorclass = cpp() ) != C_UNKNOWN) || (( errorclass = pccccom() ) != C_UNKNOWN) @@ -57,10 +54,8 @@ eaterrors(r_errorc, r_errorv) || (( errorclass = lint3() ) != C_UNKNOWN) || (( errorclass = make() ) != C_UNKNOWN) || (( errorclass = f77() ) != C_UNKNOWN) -#ifdef ERNIE || ((errorclass = pi() ) != C_UNKNOWN) || (( errorclass = ri() )!= C_UNKNOWN) -#endif ) ; else errorclass = catchall(); diff --git a/usr/src/usr.bin/error/main.c b/usr/src/usr.bin/error/main.c index 36ec9e6a28..3c65fa3d15 100644 --- a/usr/src/usr.bin/error/main.c +++ b/usr/src/usr.bin/error/main.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)main.c 1.3 (Berkeley) %G%"; +static char *sccsid = "@(#)main.c 1.4 (Berkeley) %G%"; #include #include #include @@ -97,15 +97,6 @@ main(argc, argv) case 's': pr_summary = TRUE; break; case 'v': edit_files = TRUE; break; case 'T': terse = TRUE; break; -#ifndef ERNIE - case 'p': - *cp-- = 0; argv++; argc--; - if (argc > 1){ - currentfilename = argv[1]; - piflag = TRUE; - } - break; -#endif case 't': *cp-- = 0; argv++; argc--; if (argc > 1){ diff --git a/usr/src/usr.bin/error/touch.c b/usr/src/usr.bin/error/touch.c index 89ff10051c..1ff215115a 100644 --- a/usr/src/usr.bin/error/touch.c +++ b/usr/src/usr.bin/error/touch.c @@ -1,4 +1,4 @@ -static char *sccsid = "@(#)touch.c 1.3 (Berkeley) %G%"; +static char *sccsid = "@(#)touch.c 1.4 (Berkeley) %G%"; #include #include #include @@ -253,8 +253,12 @@ hackfile(name, files, ix, nerrors) diverterrors(name, errordest, files, ix, previewed, nerrors); - if (errordest == TOTHEFILE) - writetouched(); + if (errordest == TOTHEFILE){ + /* + * overwrite the original file + */ + writetouched(1); + } } boolean preview(name, nerrors, files, ix) @@ -468,8 +472,8 @@ execvarg(n_pissed_on, r_argc, r_argv) FILE *o_touchedfile; /* the old file */ FILE *n_touchedfile; /* the new file */ char *o_name; -char n_name[32]; -char *canon_name = "ErrorXXXXXX"; +char n_name[64]; +char *canon_name = "/tmp/ErrorXXXXXX"; int o_lineno; int n_lineno; boolean tempfileopen = FALSE; @@ -528,19 +532,59 @@ text(p, use_all) n_lineno++; } -writetouched() +/* + * write the touched file to its temporary copy, + * then bring the temporary in over the local file + */ +writetouched(overwrite) + int overwrite; { - int nread; + reg int nread; + reg FILE *localfile; + reg FILE *tmpfile; + int botch; while((nread = fread(edbuf, 1, sizeof(edbuf), o_touchedfile)) != NULL){ fwrite(edbuf, 1, nread, n_touchedfile); } fclose(n_touchedfile); fclose(o_touchedfile); - unlink(o_name); - link(n_name, o_name); + /* + * Now, copy the temp file back over the original + * file, thus preserving links, etc + */ + if (overwrite){ + botch = 0; + localfile = NULL; + tmpfile = NULL; + if ((localfile = fopen(o_name, "w")) == NULL){ + fprintf(stderr, + "%s: Can't open file \"%s\" to overwrite.\n", + processname, o_name); + botch++; + } + if ((tmpfile = fopen(n_name, "r")) == NULL){ + fprintf(stderr, "%s: Can't open file \"%s\" to read.\n", + processname, n_name); + botch++; + } + if (!botch){ + while((nread=fread(edbuf, 1, sizeof(edbuf), tmpfile)) + != NULL){ + fwrite(edbuf, 1, nread, localfile); + } + } + if (localfile != NULL) + fclose(localfile); + if (tmpfile != NULL) + fclose(tmpfile); + } + /* + * Kiss the temp file good bye + */ unlink(n_name); tempfileopen = FALSE; + return(TRUE); } onintr() @@ -553,8 +597,12 @@ onintr() signal(SIGINT, onintr); return; default: - if (tempfileopen) - writetouched(); + if (tempfileopen){ + /* + * Don't overwrite the original file! + */ + writetouched(0); + } exit(1); } /*NOTREACHED*/ -- 2.20.1