add directory study

This commit is contained in:
gohigh
2024-02-19 00:25:23 -05:00
parent b1306b38b1
commit f3774e2f8c
4001 changed files with 2285787 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
/* $Header: EXTERN.h,v 2.0 86/09/17 15:35:37 lwall Exp $
*
* $Log: EXTERN.h,v $
* Revision 2.0 86/09/17 15:35:37 lwall
* Baseline for netwide release.
*
*/
#undef EXT
#define EXT extern
#undef INIT
#define INIT(x)
#undef DOINIT

View File

@@ -0,0 +1,15 @@
/* $Header: INTERN.h,v 2.0 86/09/17 15:35:58 lwall Exp $
*
* $Log: INTERN.h,v $
* Revision 2.0 86/09/17 15:35:58 lwall
* Baseline for netwide release.
*
*/
#undef EXT
#define EXT
#undef INIT
#define INIT(x) = x
#define DOINIT

View File

@@ -0,0 +1,15 @@
CFLAGS=-DCHARSPRINTF # patch for old compiler
obj = patch.s pch.s inp.s util.s version.s
patch: $(obj)
cc -i -o patch $(obj)
patch.s: config.h common.h patch.c inp.h pch.h util.h version.h
pch.s: config.h common.h pch.c pch.h util.h
inp.s: config.h common.h inp.c inp.h util.h
util.s: config.h common.h util.c util.h
version.s: config.h common.h version.c version.h patchlevel.h util.h
clean:
@rm -f *.bak *.s patch

View File

@@ -0,0 +1,16 @@
CFLAGS=-DCHARSPRINTF -O # patch for old compiler
obj = patch.o pch.o inp.o util.o version.o
patch: $(obj)
cc -s -o patch $(obj)
chmem =20000 patch
patch.o: config.h common.h patch.c inp.h pch.h util.h version.h
pch.o: config.h common.h pch.c pch.h util.h
inp.o: config.h common.h inp.c inp.h util.h
util.o: config.h common.h util.c util.h
version.o: config.h common.h version.c version.h patchlevel.h util.h
clean:
@rm -f *.bak *.o patch

View File

@@ -0,0 +1,158 @@
/* $Header: common.h,v 2.0.1.2 88/06/22 20:44:53 lwall Locked $
*
* $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
#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 Mktemp (void)mktemp
#define Strcpy (void)strcpy
#define Strcat (void)strcat
#include <sys/types.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <signal.h>
#include <stdio.h>
/* constants */
#define TRUE (1)
#define FALSE (0)
#define MAXHUNKSIZE 100000 /* is this enough lines? */
#define INITHUNKMAX 125 /* initial dynamic allocation size */
#define MAXLINELEN 1024
#define BUFFERSIZE 1024
#define SCCSPREFIX "s."
#define GET "get -e %s"
#define RCSSUFFIX ",v"
#define CHECKOUT "co -l %s"
#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 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 Argc_last; /* for restarting plan_b */
EXT char **Argv_last;
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 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 *origext INIT(Nullch);
EXT char *origprae INIT(Nullch);
EXT char TMPOUTNAME[] INIT("/tmp/patchoXXXXXX");
EXT char TMPINNAME[] INIT("/tmp/patchiXXXXXX"); /* might want /usr/tmp here */
EXT char TMPREJNAME[] INIT("/tmp/patchrXXXXXX");
EXT char TMPPATNAME[] INIT("/tmp/patchpXXXXXX");
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 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
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 */
char *malloc();
char *realloc();
char *strcpy();
char *strcat();
long atol();
long lseek();
char *mktemp();
#ifdef CHARSPRINTF
char *sprintf();
#else
int sprintf();
#endif

View File

@@ -0,0 +1,33 @@
/* config.h
* This file was produced by running the Configure script.
* Feel free to modify any of this as the need arises.
*/
#/*undef EUNICE /* no file linking? */
#/*undef VMS
#/*undef index strchr /* cultural */
#/*undef rindex strrchr /* differences? */
#/*undef void int /* is void to be avoided? */
/* How many register declarations are paid attention to? */
#define Reg1 register
#define Reg2 register
#define Reg3
#define Reg4
#define Reg5
#define Reg6
#define Reg7
#define Reg8
#define Reg9
#define Reg10
#define Reg11
#define Reg12
#define Reg13
#define Reg14
#define Reg15
#define Reg16

View File

@@ -0,0 +1,319 @@
/* $Header: inp.c,v 2.0.1.1 88/06/03 15:06:13 lwall Locked $
*
* $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()
{
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(filename)
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(filename)
char *filename;
{
int ifd;
Reg1 char *s;
Reg2 LINENUM iline;
if (ok_to_create_file && stat(filename, &filestat) < 0) {
if (verbose)
say2("(Creating file %s...)\n",filename);
makedirs(filename, TRUE);
close(creat(filename, 0666));
}
if (stat(filename, &filestat) < 0) {
Sprintf(buf, "RCS/%s%s", filename, RCSSUFFIX);
if (stat(buf, &filestat) >= 0 || stat(buf+4, &filestat) >= 0) {
Sprintf(buf, CHECKOUT, filename);
if (verbose)
say2("Can't find %s--attempting to check it out from RCS.\n",
filename);
if (system(buf) || stat(filename, &filestat))
fatal2("Can't check out %s.\n", filename);
}
else {
Sprintf(buf+20, "SCCS/%s%s", SCCSPREFIX, filename);
if (stat(s=buf+20, &filestat) >= 0 ||
stat(s=buf+25, &filestat) >= 0) {
Sprintf(buf, GET, s);
if (verbose)
say2("Can't find %s--attempting to get it from SCCS.\n",
filename);
if (system(buf) || stat(filename, &filestat))
fatal2("Can't get %s.\n", filename);
}
else
fatal2("Can't find %s.\n", filename);
}
}
filemode = filestat.st_mode;
if ((filemode & S_IFMT) & ~S_IFREG)
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
i_womp = malloc((MEM)(i_size+2)); /* lint says this may alloc less than */
/* i_size, but that's okay, I think. */
#endif
if (i_womp == Nullch)
return FALSE;
if ((ifd = open(filename, 0)) < 0)
fatal2("Can't open file %s\n", filename);
#ifndef lint
if (read(ifd, i_womp, (int)i_size) != i_size) {
Close(ifd); /* probably means i_size > 15 or 16 bits worth */
free(i_womp); /* at this point it doesn't matter if i_womp was */
return FALSE; /* undersized. */
}
#endif
Close(ifd);
if (i_size && i_womp[i_size-1] != '\n')
i_womp[i_size++] = '\n';
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')
i_ptr[++iline] = s+1; /* these are NOT null terminated */
}
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 {
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(filename)
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)
fatal2("Can't open file %s\n", filename);
if ((tifd = creat(TMPINNAME, 0666)) < 0)
fatal2("Can't open file %s\n", TMPINNAME);
while (fgets(buf, sizeof buf, 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 {
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("Can't seem to get enough memory.\n");
for (i=1; ; i++) {
if (! (i % lines_per_buf)) /* new block */
if (write(tifd, tibuf[0], BUFFERSIZE) < BUFFERSIZE)
fatal1("patch: can't write temp file.\n");
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)
fatal1("patch: can't write temp file.\n");
break;
}
}
Fclose(ifp);
Close(tifd);
if ((tifd = open(TMPINNAME, 0)) < 0) {
fatal2("Can't reopen file %s\n", 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)
fatal2("Error reading tmp file %s.\n", TMPINNAME);
}
return tibuf[whichbuf] + (tireclen*offline);
}
}
/* True if the string argument contains the revision number we want. */
bool
rev_in_string(string)
char *string;
{
Reg1 char *s;
Reg2 int patlen;
if (revision == Nullch)
return TRUE;
patlen = strlen(revision);
if (strnEQ(string,revision,patlen) && isspace(s[patlen]))
return TRUE;
for (s = string; *s; s++) {
if (isspace(*s) && strnEQ(s+1, revision, patlen) &&
isspace(s[patlen+1] )) {
return TRUE;
}
}
return FALSE;
}

View File

@@ -0,0 +1,18 @@
/* $Header: inp.h,v 2.0 86/09/17 15:37:25 lwall Exp $
*
* $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 */
bool rev_in_string();
void scan_input();
bool plan_a(); /* returns false if insufficient memory */
void plan_b();
char *ifetch();

View File

@@ -0,0 +1 @@
#define PATCHLEVEL 12

View File

@@ -0,0 +1,36 @@
/* $Header: pch.h,v 2.0.1.1 87/01/30 22:47:16 lwall Exp $
*
* $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 open_patch_file();
void set_hunkmax();
void grow_hunkmax();
bool there_is_another_patch();
int intuit_diff_type();
void next_intuit_at();
void skip_to();
bool another_hunk();
bool pch_swap();
char *pfetch();
short pch_line_len();
LINENUM pch_first();
LINENUM pch_ptrn_lines();
LINENUM pch_newfirst();
LINENUM pch_repl_lines();
LINENUM pch_end();
LINENUM pch_context();
LINENUM pch_hunk_beg();
char pch_char();
char *pfetch();
char *pgets();
void do_ed_script();

View File

@@ -0,0 +1,364 @@
#include "EXTERN.h"
#include "common.h"
#include "INTERN.h"
#include "util.h"
/* Rename a file, copying it if necessary. */
int
move_file(from,to)
char *from, *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)
fatal2("patch: internal error, can't reopen %s\n", from);
while ((i=read(fromfd, buf, sizeof buf)) > 0)
if (write(1, buf, i) != 1)
fatal1("patch: write failed\n");
Close(fromfd);
return 0;
}
if (origprae) {
Strcpy (bakname, origprae);
Strcat(bakname, to);
} else {
Strcpy(bakname, to);
Strcat(bakname, origext?origext:ORIGEXT);
}
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 */
while (stat(bakname, &filestat) >= 0 &&
to_device == filestat.st_dev && to_inode == filestat.st_ino) {
for (s=simplename; *s && !islower(*s); s++) ;
if (*s)
*s = toupper(*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 (link(to, bakname) < 0) {
say3("patch: can't backup %s, output is in %s\n",
to, from);
return -1;
}
while (unlink(to) >= 0) ;
}
#ifdef DEBUGGING
if (debug & 4)
say3("Moving %s to %s.\n", from, to);
#endif
if (link(from, to) < 0) { /* different file system? */
Reg4 int tofd;
tofd = creat(to, 0666);
if (tofd < 0) {
say3("patch: can't create %s, output is in %s.\n",
to, from);
return -1;
}
fromfd = open(from, 0);
if (fromfd < 0)
fatal2("patch: internal error, can't reopen %s\n", from);
while ((i=read(fromfd, buf, sizeof buf)) > 0)
if (write(tofd, buf, i) != i)
fatal1("patch: write failed\n");
Close(fromfd);
Close(tofd);
}
Unlink(from);
return 0;
}
/* Copy a file. */
void
copy_file(from,to)
char *from, *to;
{
Reg3 int tofd;
Reg2 int fromfd;
Reg1 int i;
tofd = creat(to, 0666);
if (tofd < 0)
fatal2("patch: can't create %s.\n", to);
fromfd = open(from, 0);
if (fromfd < 0)
fatal2("patch: internal error, can't reopen %s\n", from);
while ((i=read(fromfd, buf, sizeof buf)) > 0)
if (write(tofd, buf, i) != i)
fatal2("patch: write (%s) failed\n", to);
Close(fromfd);
Close(tofd);
}
/* Allocate a unique area for a string. */
char *
savestr(s)
Reg1 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("patch: out of memory (savestr)\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*/
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;
{
void my_exit();
say(pat, arg1, arg2, arg3);
my_exit(1);
}
/* Get a response from the user, somehow or other. */
void
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, sizeof buf);
}
else if (isatty(1)) { /* this may be new file output */
Fflush(stdout);
write(1, buf, strlen(buf));
r = read(1, buf, sizeof buf);
}
else if ((ttyfd = open("/dev/tty", 2)) >= 0 && isatty(ttyfd)) {
/* might be deleted or unwriteable */
write(ttyfd, buf, strlen(buf));
r = read(ttyfd, buf, sizeof buf);
Close(ttyfd);
}
else if (isatty(0)) { /* this is probably patch input */
Fflush(stdin);
write(0, buf, strlen(buf));
r = read(0, buf, sizeof buf);
}
else { /* no terminal at all--default it */
buf[0] = '\n';
r = 1;
}
if (r <= 0)
buf[0] = 0;
else
buf[r] = '\0';
if (!tty2)
say1(buf);
}
#endif /* lint */
/* How to handle certain events when not in a critical region. */
void
set_signals(reset)
int reset;
{
void my_exit();
#ifndef lint
#ifdef VOIDSIG
static void (*hupval)(),(*intval)();
#else
static int (*hupval)(),(*intval)();
#endif
if (!reset) {
hupval = signal(SIGHUP, SIG_IGN);
if (hupval != SIG_IGN)
#ifdef VOIDSIG
hupval = my_exit;
#else
hupval = (int(*)())my_exit;
#endif
intval = signal(SIGINT, SIG_IGN);
if (intval != SIG_IGN)
#ifdef VOIDSIG
intval = my_exit;
#else
intval = (int(*)())my_exit;
#endif
}
Signal(SIGHUP, hupval);
Signal(SIGINT, intval);
#endif
}
/* How to handle certain events when in a critical region. */
void
ignore_signals()
{
#ifndef lint
Signal(SIGHUP, SIG_IGN);
Signal(SIGINT, SIG_IGN);
#endif
}
/* Make sure we'll have the directories to create a file. */
void
makedirs(filename,striplast)
Reg1 char *filename;
bool striplast;
{
char tmpbuf[256];
Reg2 char *s = tmpbuf;
char *dirv[20];
Reg3 int i;
Reg4 int dirvp = 0;
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++) {
while (*s) s++;
*s++ = ' ';
strcpy(s, tmpbuf);
*dirv[i] = '/';
}
system(buf);
}
/* Make filenames more reasonable. */
char *
fetchname(at,strip_leading,assume_exists)
char *at;
int strip_leading;
int assume_exists;
{
char *s;
char *name;
Reg1 char *t;
char tmpbuf[200];
if (!at)
return Nullch;
s = savestr(at);
for (t=s; isspace(*t); t++) ;
name = t;
#ifdef DEBUGGING
if (debug & 128)
say4("fetchname %s %d %d\n",name,strip_leading,assume_exists);
#endif
if (strnEQ(name, "/dev/null", 9)) /* so files can be created by diffing */
return Nullch; /* against /dev/null. */
for (; *t && !isspace(*t); t++)
if (*t == '/')
if (--strip_leading >= 0)
name = t+1;
*t = '\0';
if (name != s && *s != '/') {
name[-1] = '\0';
if (stat(s, &filestat) && filestat.st_mode & S_IFDIR) {
name[-1] = '/';
name=s;
}
}
name = savestr(name);
Sprintf(tmpbuf, "RCS/%s", name);
free(s);
if (stat(name, &filestat) < 0 && !assume_exists) {
Strcat(tmpbuf, RCSSUFFIX);
if (stat(tmpbuf, &filestat) < 0 && stat(tmpbuf+4, &filestat) < 0) {
Sprintf(tmpbuf, "SCCS/%s%s", SCCSPREFIX, name);
if (stat(tmpbuf, &filestat) < 0 && stat(tmpbuf+5, &filestat) < 0) {
free(name);
name = Nullch;
}
}
}
return name;
}

View File

@@ -0,0 +1,74 @@
/* $Header: util.h,v 2.0 86/09/17 15:40:06 lwall Exp $
*
* $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
#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))
#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
#endif /* lint */
/* if neither of the above work, join all multi-line macro calls. */
#endif
EXT char serrbuf[BUFSIZ]; /* buffer for stderr */
char *fetchname();
int move_file();
void copy_file();
void say();
void fatal();
void ask();
char *savestr();
void set_signals();
void ignore_signals();
void makedirs();

View File

@@ -0,0 +1,28 @@
/* $Header: version.c,v 2.0 86/09/17 15:40:11 lwall Exp $
*
* $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"
/* Print out the version number and die. */
void
version()
{
extern char rcsid[];
#ifdef lint
rcsid[0] = rcsid[0];
#else
fatal3("%s\nPatch level: %d\n", rcsid, PATCHLEVEL);
#endif
}

View File

@@ -0,0 +1,9 @@
/* $Header: version.h,v 2.0 86/09/17 15:40:14 lwall Exp $
*
* $Log: version.h,v $
* Revision 2.0 86/09/17 15:40:14 lwall
* Baseline for netwide release.
*
*/
void version();