BSD 4_3_Reno release
[unix-history] / usr / src / usr.bin / sccs / sccs.c
index 1a92081..41d6473 100644 (file)
@@ -1,12 +1,41 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that: (1) source distributions retain this entire copyright
+ * notice and comment, and (2) distributions including binaries display
+ * the following acknowledgement:  ``This product includes software
+ * developed by the University of California, Berkeley and its contributors''
+ * in the documentation or other materials provided with the distribution
+ * and in all advertising materials mentioning features or use of this
+ * software. Neither the name of the University nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
+ * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
+ */
+
+#ifndef lint
+char copyright[] =
+"@(#) Copyright (c) 1980 Regents of the University of California.\n\
+ All rights reserved.\n";
+#endif /* not lint */
+
+#ifndef lint
+static char sccsid[] = "@(#)sccs.c     5.9 (Berkeley) 6/1/90";
+#endif /* not lint */
+
 # include <stdio.h>
 # include <stdio.h>
-# include <sys/types.h>
+# include <sys/param.h>
 # include <sys/stat.h>
 # include <sys/dir.h>
 # include <errno.h>
 # include <signal.h>
 # include <sysexits.h>
 # include <sys/stat.h>
 # include <sys/dir.h>
 # include <errno.h>
 # include <signal.h>
 # include <sysexits.h>
-# include <whoami.h>
 # include <pwd.h>
 # include <pwd.h>
+# include "pathnames.h"
 
 /*
 **  SCCS.C -- human-oriented front end to the SCCS system.
 
 /*
 **  SCCS.C -- human-oriented front end to the SCCS system.
 **             get,
 **             delta,
 **             rmdel,
 **             get,
 **             delta,
 **             rmdel,
-**             chghist,
+**             cdc,
 **             etc.            Straight out of SCCS; only difference
 **                             is that pathnames get modified as
 **                             described above.
 **             etc.            Straight out of SCCS; only difference
 **                             is that pathnames get modified as
 **                             described above.
+**             enter           Front end doing "sccs admin -i<name> <name>"
+**             create          Macro for "enter" followed by "get".
 **             edit            Macro for "get -e".
 **             unedit          Removes a file being edited, knowing
 **                             about p-files, etc.
 **             delget          Macro for "delta" followed by "get".
 **             deledit         Macro for "delta" followed by "get -e".
 **             edit            Macro for "get -e".
 **             unedit          Removes a file being edited, knowing
 **                             about p-files, etc.
 **             delget          Macro for "delta" followed by "get".
 **             deledit         Macro for "delta" followed by "get -e".
-**             info            Tell what files being edited.
+**             branch          Macro for "get -b -e", followed by "delta
+**                             -s -n", followd by "get -e -t -g".
+**             diffs           "diff" the specified version of files
+**                             and the checked-out version.
+**             print           Macro for "prs -e" followed by "get -p -m".
+**             tell            List what files are being edited.
+**             info            Print information about files being edited.
 **             clean           Remove all files that can be
 **                             regenerated from SCCS files.
 **             check           Like info, but return exit status, for
 **             clean           Remove all files that can be
 **                             regenerated from SCCS files.
 **             check           Like info, but return exit status, for
 **             Copyright 1980 Regents of the University of California
 */
 
 **             Copyright 1980 Regents of the University of California
 */
 
-static char SccsId[] = "@(#)sccs.c     1.59 %G%";
 \f
 /*******************  Configuration Information  ********************/
 
 \f
 /*******************  Configuration Information  ********************/
 
-/* special defines for local berkeley systems */
-# include <whoami.h>
-
-# ifdef CSVAX
-# define UIDUSER
-# define PROGPATH(name)        "/usr/local/name"
-# endif CSVAX
-
-# ifdef INGVAX
-# define PROGPATH(name)        "/usr/local/name"
-# endif INGVAX
-
-# ifdef CORY
-# define PROGPATH(name)        "/usr/eecs/bin/name"
-# endif CORY
-
-/* end of berkeley systems defines */
-
 # ifndef SCCSPATH
 # define SCCSPATH      "SCCS"  /* pathname in which to find s-files */
 # endif NOT SCCSPATH
 # ifndef SCCSPATH
 # define SCCSPATH      "SCCS"  /* pathname in which to find s-files */
 # endif NOT SCCSPATH
@@ -123,10 +141,6 @@ static char SccsId[] = "@(#)sccs.c 1.59 %G%";
 # define MYNAME                "sccs"  /* name used for printing errors */
 # endif NOT MYNAME
 
 # define MYNAME                "sccs"  /* name used for printing errors */
 # endif NOT MYNAME
 
-# ifndef PROGPATH
-# define PROGPATH(name)        "/usr/sccs/name"        /* place to find binaries */
-# endif PROGPATH
-
 /****************  End of Configuration Information  ****************/
 \f
 typedef char   bool;
 /****************  End of Configuration Information  ****************/
 \f
 typedef char   bool;
@@ -152,6 +166,7 @@ struct sccsprog
 # define SHELL         5       /* call a shell file (like PROG) */
 # define DIFFS         6       /* diff between sccs & file out */
 # define DODIFF                7       /* internal call to diff program */
 # define SHELL         5       /* call a shell file (like PROG) */
 # define DIFFS         6       /* diff between sccs & file out */
 # define DODIFF                7       /* internal call to diff program */
+# define ENTER         8       /* enter new files */
 
 /* bits for sccsflags */
 # define NO_SDOT       0001    /* no s. on front of args */
 
 /* bits for sccsflags */
 # define NO_SDOT       0001    /* no s. on front of args */
@@ -175,7 +190,7 @@ struct sccsprog
 struct sccsprog SccsProg[] =
 {
        "admin",        PROG,   REALUSER,               PROGPATH(admin),
 struct sccsprog SccsProg[] =
 {
        "admin",        PROG,   REALUSER,               PROGPATH(admin),
-       "chghist",      PROG,   0,                      PROGPATH(rmdel),
+       "cdc",          PROG,   0,                      PROGPATH(rmdel),
        "comb",         PROG,   0,                      PROGPATH(comb),
        "delta",        PROG,   0,                      PROGPATH(delta),
        "get",          PROG,   0,                      PROGPATH(get),
        "comb",         PROG,   0,                      PROGPATH(comb),
        "delta",        PROG,   0,                      PROGPATH(delta),
        "get",          PROG,   0,                      PROGPATH(get),
@@ -197,7 +212,11 @@ struct sccsprog SccsProg[] =
        "unedit",       UNEDIT, NO_SDOT,                NULL,
        "diffs",        DIFFS,  NO_SDOT|REALUSER,       NULL,
        "-diff",        DODIFF, NO_SDOT|REALUSER,       PROGPATH(bdiff),
        "unedit",       UNEDIT, NO_SDOT,                NULL,
        "diffs",        DIFFS,  NO_SDOT|REALUSER,       NULL,
        "-diff",        DODIFF, NO_SDOT|REALUSER,       PROGPATH(bdiff),
-       "print",        CMACRO, 0,                      "prt -e/get -p -m -s",
+       "print",        CMACRO, 0,                      "prs -e/get -p -m -s",
+       "branch",       CMACRO, NO_SDOT,
+               "get:ixrc -e -b/delta: -s -n -ybranch-place-holder/get:pl -e -t -g",
+       "enter",        ENTER,  NO_SDOT,                NULL,
+       "create",       CMACRO, NO_SDOT,                "enter/get:ixbeskcl -t",
        NULL,           -1,     0,                      NULL
 };
 
        NULL,           -1,     0,                      NULL
 };
 
@@ -227,6 +246,14 @@ bool       Debug;                  /* turn on tracing */
 # ifndef V6
 extern char    *getenv();
 # endif V6
 # ifndef V6
 extern char    *getenv();
 # endif V6
+
+extern char    *sys_siglist[];
+
+char *gstrcat(), *strcat();
+char *gstrncat(), *strncat();
+char *gstrcpy(), *strcpy();
+#define        FBUFSIZ BUFSIZ
+#define        PFILELG 120
 \f
 main(argc, argv)
        int argc;
 \f
 main(argc, argv)
        int argc;
@@ -239,10 +266,10 @@ main(argc, argv)
 # ifndef SCCSDIR
        register struct passwd *pw;
        extern struct passwd *getpwnam();
 # ifndef SCCSDIR
        register struct passwd *pw;
        extern struct passwd *getpwnam();
-       char buf[100];
+       char buf[FBUFSIZ];
 
        /* pull "SccsDir" out of the environment (possibly) */
 
        /* pull "SccsDir" out of the environment (possibly) */
-       p = getenv("PROJECT");
+       p = getenv("PROJECTDIR");
        if (p != NULL && p[0] != '\0')
        {
                if (p[0] == '/')
        if (p != NULL && p[0] != '\0')
        {
                if (p[0] == '/')
@@ -255,12 +282,12 @@ main(argc, argv)
                                usrerr("user %s does not exist", p);
                                exit(EX_USAGE);
                        }
                                usrerr("user %s does not exist", p);
                                exit(EX_USAGE);
                        }
-                       strcpy(buf, pw->pw_dir);
-                       strcat(buf, "/src");
+                       gstrcpy(buf, pw->pw_dir, sizeof(buf));
+                       gstrcat(buf, "/src", sizeof(buf));
                        if (access(buf, 0) < 0)
                        {
                        if (access(buf, 0) < 0)
                        {
-                               strcpy(buf, pw->pw_dir);
-                               strcat(buf, "/source");
+                               gstrcpy(buf, pw->pw_dir, sizeof(buf));
+                               gstrcat(buf, "/source", sizeof(buf));
                                if (access(buf, 0) < 0)
                                {
                                        usrerr("project %s has no source!", p);
                                if (access(buf, 0) < 0)
                                {
                                        usrerr("project %s has no source!", p);
@@ -300,10 +327,14 @@ main(argc, argv)
 # ifndef SCCSDIR
                          case 'p':             /* path of sccs files */
                                SccsPath = ++p;
 # ifndef SCCSDIR
                          case 'p':             /* path of sccs files */
                                SccsPath = ++p;
+                               if (SccsPath[0] == '\0' && argv[1] != NULL)
+                                       SccsPath = *++argv;
                                break;
 
                          case 'd':             /* directory to search from */
                                SccsDir = ++p;
                                break;
 
                          case 'd':             /* directory to search from */
                                SccsDir = ++p;
+                               if (SccsDir[0] == '\0' && argv[1] != NULL)
+                                       SccsDir = *++argv;
                                break;
 # endif
 
                                break;
 # endif
 
@@ -356,7 +387,7 @@ command(argv, forkflag, arg0)
 {
        register struct sccsprog *cmd;
        register char *p;
 {
        register struct sccsprog *cmd;
        register char *p;
-       char buf[40];
+       char buf[FBUFSIZ];
        extern struct sccsprog *lookup();
        char *nav[1000];
        char **np;
        extern struct sccsprog *lookup();
        char *nav[1000];
        char **np;
@@ -450,7 +481,7 @@ command(argv, forkflag, arg0)
          case SHELL:           /* call a shell file */
                *ap = cmd->sccspath;
                *--ap = "sh";
          case SHELL:           /* call a shell file */
                *ap = cmd->sccspath;
                *--ap = "sh";
-               rval = callprog("/bin/sh", cmd->sccsflags, ap, forkflag);
+               rval = callprog(_PATH_BSHELL, cmd->sccsflags, ap, forkflag);
                break;
 
          case PROG:            /* call an sccs prog */
                break;
 
          case PROG:            /* call an sccs prog */
@@ -471,7 +502,7 @@ command(argv, forkflag, arg0)
                break;
 
          case FIX:             /* fix a delta */
                break;
 
          case FIX:             /* fix a delta */
-               if (strncmp(ap[1], "-r", 2) != 0)
+               if (ap[1]==0 || strncmp(ap[1], "-r", 2)!=0)
                {
                        usrerr("-r flag needed for fix command");
                        rval = EX_USAGE;
                {
                        usrerr("-r flag needed for fix command");
                        rval = EX_USAGE;
@@ -548,6 +579,35 @@ command(argv, forkflag, arg0)
                syserr("cannot exec %s", cmd->sccspath);
                exit(EX_OSERR);
 
                syserr("cannot exec %s", cmd->sccspath);
                exit(EX_OSERR);
 
+         case ENTER:           /* enter new sccs files */
+               /* skip over flag arguments */
+               for (np = &ap[1]; *np != NULL && **np == '-'; np++)
+                       continue;
+               argv = np;
+
+               /* do an admin for each file */
+               p = argv[1];
+               while (*np != NULL)
+               {
+                       printf("\n%s:\n", *np);
+                       strcpy(buf, "-i");
+                       gstrcat(buf, *np, sizeof(buf));
+                       ap[0] = buf;
+                       argv[0] = tail(*np);
+                       argv[1] = NULL;
+                       rval = command(ap, TRUE, "admin");
+                       argv[1] = p;
+                       if (rval == 0)
+                       {
+                               strcpy(buf, ",");
+                               gstrcat(buf, tail(*np), sizeof(buf));
+                               if (link(*np, buf) >= 0)
+                                       unlink(*np);
+                       }
+                       np++;
+               }
+               break;
+
          default:
                syserr("oper %d", cmd->sccsoper);
                exit(EX_SOFTWARE);
          default:
                syserr("oper %d", cmd->sccsoper);
                exit(EX_SOFTWARE);
@@ -614,7 +674,12 @@ callprog(progpath, flags, argv, forkflag)
        bool forkflag;
 {
        register int i;
        bool forkflag;
 {
        register int i;
+       register int wpid;
        auto int st;
        auto int st;
+       register int sigcode;
+       register int coredumped;
+       register char *sigmsg;
+       auto char sigmsgbuf[10+1];      /* "Signal 127" + terminating '\0' */
 
 # ifdef DEBUG
        if (Debug)
 
 # ifdef DEBUG
        if (Debug)
@@ -646,9 +711,30 @@ callprog(progpath, flags, argv, forkflag)
                }
                else if (i > 0)
                {
                }
                else if (i > 0)
                {
-                       wait(&st);
-                       if ((st & 0377) == 0)
+                       while ((wpid = wait(&st)) != -1 && wpid != i)
+                               ;
+                       if ((sigcode = st & 0377) == 0)
                                st = (st >> 8) & 0377;
                                st = (st >> 8) & 0377;
+                       else
+                       {
+                               coredumped = sigcode & 0200;
+                               sigcode &= 0177;
+                               if (sigcode != SIGINT && sigcode != SIGPIPE)
+                               {
+                                       if (sigcode < NSIG)
+                                               sigmsg = sys_siglist[sigcode];
+                                       else
+                                       {
+                                               sprintf(sigmsgbuf, "Signal %d",
+                                                   sigcode);
+                                               sigmsg = sigmsgbuf;
+                                       }
+                                       fprintf(stderr, "sccs: %s: %s%s", argv[0],
+                                           sigmsg,
+                                           coredumped ? " - core dumped": "");
+                               }
+                               st = EX_SOFTWARE;
+                       }
                        if (OutFile >= 0)
                        {
                                close(OutFile);
                        if (OutFile >= 0)
                        {
                                close(OutFile);
@@ -713,9 +799,10 @@ makefile(name)
        char *name;
 {
        register char *p;
        char *name;
 {
        register char *p;
-       char buf[512];
+       char buf[3*FBUFSIZ];
        extern char *malloc();
        extern char *rindex();
        extern char *malloc();
        extern char *rindex();
+       extern bool safepath();
        extern bool isdir();
        register char *q;
 
        extern bool isdir();
        register char *q;
 
@@ -726,51 +813,65 @@ makefile(name)
                p++;
 
        /*
                p++;
 
        /*
-       **  See if the name can be used as-is.
+       **  Check to see that the path is "safe", i.e., that we
+       **  are not letting some nasty person use the setuid part
+       **  of this program to look at or munge some presumably
+       **  hidden files.
        */
 
        */
 
-       if (SccsPath[0] != '/' || name[0] == '/' || strncmp(name, "./", 2) == 0)
-       {
-               if (strncmp(p, "s.", 2) == 0)
-                       return (name);
-               if (isdir(name))
-                       return (name);
-       }
+       if (SccsDir[0] == '/' && !safepath(name))
+               return (NULL);
 
        /*
 
        /*
-       **  Create the actual pathname.
+       **  Create the base pathname.
        */
 
        /* first the directory part */
        */
 
        /* first the directory part */
-       if (name[0] != '/')
+       if (SccsDir[0] != '\0' && name[0] != '/' && strncmp(name, "./", 2) != 0)
        {
        {
-               strcpy(buf, SccsDir);
-               strcat(buf, "/");
+               gstrcpy(buf, SccsDir, sizeof(buf));
+               gstrcat(buf, "/", sizeof(buf));
        }
        else
        }
        else
-               strcpy(buf, "");
+               gstrcpy(buf, "", sizeof(buf));
        
        /* then the head of the pathname */
        
        /* then the head of the pathname */
-       strncat(buf, name, p - name);
+       gstrncat(buf, name, p - name, sizeof(buf));
        q = &buf[strlen(buf)];
        q = &buf[strlen(buf)];
-       strcpy(q, p);
+
+       /* now copy the final part of the name, in case useful */
+       gstrcpy(q, p, sizeof(buf));
+
+       /* so is it useful? */
        if (strncmp(p, "s.", 2) != 0 && !isdir(buf))
        {
                /* sorry, no; copy the SCCS pathname & the "s." */
        if (strncmp(p, "s.", 2) != 0 && !isdir(buf))
        {
                /* sorry, no; copy the SCCS pathname & the "s." */
-               strcpy(q, SccsPath);
-               strcat(buf, "/s.");
+               gstrcpy(q, SccsPath, sizeof(buf));
+               gstrcat(buf, "/s.", sizeof(buf));
 
                /* and now the end of the name */
 
                /* and now the end of the name */
-               strcat(buf, p);
+               gstrcat(buf, p, sizeof(buf));
        }
 
        /* if i haven't changed it, why did I do all this? */
        if (strcmp(buf, name) == 0)
                p = name;
        }
 
        /* if i haven't changed it, why did I do all this? */
        if (strcmp(buf, name) == 0)
                p = name;
+       else
+       {
+               /* but if I have, squirrel it away */
+               p = malloc(strlen(buf) + 1);
+               if (p == NULL)
+               {
+                       perror("Sccs: no mem");
+                       exit(EX_OSERR);
+               }
+               strcpy(p, buf);
+       }
 
 
-       return (stat(name, &stbuf) >= 0 && (stbuf.st_mode & S_IFMT) == S_IFDIR);
+       return (p);
 }
 }
-\f/*
+\f
+/*
 **  ISDIR -- return true if the argument is a directory.
 **
 **     Parameters:
 **  ISDIR -- return true if the argument is a directory.
 **
 **     Parameters:
@@ -855,10 +956,10 @@ clean(mode, argv)
        int mode;
        char **argv;
 {
        int mode;
        char **argv;
 {
-       struct direct dir;
-       char buf[100];
+       struct direct *dir;
+       char buf[FBUFSIZ];
        char *bufend;
        char *bufend;
-       register FILE *dirfd;
+       register DIR *dirp;
        register char *basefile;
        bool gotedit;
        bool gotpfent;
        register char *basefile;
        bool gotedit;
        bool gotpfent;
@@ -911,19 +1012,19 @@ clean(mode, argv)
        **  Find and open the SCCS directory.
        */
 
        **  Find and open the SCCS directory.
        */
 
-       strcpy(buf, SccsDir);
+       gstrcpy(buf, SccsDir, sizeof(buf));
        if (buf[0] != '\0')
        if (buf[0] != '\0')
-               strcat(buf, "/");
+               gstrcat(buf, "/", sizeof(buf));
        if (subdir != NULL)
        {
        if (subdir != NULL)
        {
-               strcat(buf, subdir);
-               strcat(buf, "/");
+               gstrcat(buf, subdir, sizeof(buf));
+               gstrcat(buf, "/", sizeof(buf));
        }
        }
-       strcat(buf, SccsPath);
+       gstrcat(buf, SccsPath, sizeof(buf));
        bufend = &buf[strlen(buf)];
 
        bufend = &buf[strlen(buf)];
 
-       dirfd = fopen(buf, "r");
-       if (dirfd == NULL)
+       dirp = opendir(buf);
+       if (dirp == NULL)
        {
                usrerr("cannot open %s", buf);
                return (EX_NOINPUT);
        {
                usrerr("cannot open %s", buf);
                return (EX_NOINPUT);
@@ -936,16 +1037,14 @@ clean(mode, argv)
        */
 
        gotedit = FALSE;
        */
 
        gotedit = FALSE;
-       while (fread((char *)&dir, sizeof dir, 1, dirfd) != NULL)
-       {
-               if (dir.d_ino == 0 || strncmp(dir.d_name, "s.", 2) != 0)
+       while (dir = readdir(dirp)) {
+               if (strncmp(dir->d_name, "s.", 2) != 0)
                        continue;
                
                /* got an s. file -- see if the p. file exists */
                        continue;
                
                /* got an s. file -- see if the p. file exists */
-               strcpy(bufend, "/p.");
+               gstrcpy(bufend, "/p.", sizeof(buf));
                basefile = bufend + 3;
                basefile = bufend + 3;
-               strncpy(basefile, &dir.d_name[2], sizeof dir.d_name - 2);
-               basefile[sizeof dir.d_name - 2] = '\0';
+               gstrcpy(basefile, &dir->d_name[2], sizeof(buf));
 
                /*
                **  open and scan the p-file.
 
                /*
                **  open and scan the p-file.
@@ -980,14 +1079,14 @@ clean(mode, argv)
                /* the s. file exists and no p. file exists -- unlink the g-file */
                if (mode == CLEANC && !gotpfent)
                {
                /* the s. file exists and no p. file exists -- unlink the g-file */
                if (mode == CLEANC && !gotpfent)
                {
-                       strncpy(buf, &dir.d_name[2], sizeof dir.d_name - 2);
-                       buf[sizeof dir.d_name - 2] = '\0';
-                       unlink(buf);
+                       char    unlinkbuf[FBUFSIZ];
+                       gstrcpy(unlinkbuf, &dir->d_name[2], sizeof(unlinkbuf));
+                       unlink(unlinkbuf);
                }
        }
 
        /* cleanup & report results */
                }
        }
 
        /* cleanup & report results */
-       fclose(dirfd);
+       closedir(dirp);
        if (!gotedit && mode == INFOC)
        {
                printf("Nothing being edited");
        if (!gotedit && mode == INFOC)
        {
                printf("Nothing being edited");
@@ -1058,8 +1157,8 @@ unedit(fn)
        char *fn;
 {
        register FILE *pfp;
        char *fn;
 {
        register FILE *pfp;
-       char *pfn;
-       static char tfn[] = "/tmp/sccsXXXXX";
+       char *cp, *pfn;
+       static char tfn[] = _PATH_TMP;
        FILE *tfp;
        register char *q;
        bool delete = FALSE;
        FILE *tfp;
        register char *q;
        bool delete = FALSE;
@@ -1068,8 +1167,8 @@ unedit(fn)
        extern char *username();
        struct pfile *pent;
        extern struct pfile *getpfent();
        extern char *username();
        struct pfile *pent;
        extern struct pfile *getpfent();
-       char buf[120];
-       extern char *makefile();
+       char buf[PFILELG];
+       extern char *makefile(), *rindex(), *tail();
 
        /* make "s." filename & find the trailing component */
        pfn = makefile(fn);
 
        /* make "s." filename & find the trailing component */
        pfn = makefile(fn);
@@ -1125,6 +1224,32 @@ unedit(fn)
                }
        }
 
                }
        }
 
+       /*
+        * Before changing anything, make sure we can remove
+        * the file in question (assuming it exists).
+        */
+       if (delete) {
+               extern int errno;
+
+               cp = tail(fn);
+               errno = 0;
+               if (access(cp, 0) < 0 && errno != ENOENT)
+                       goto bad;
+               if (errno == 0)
+                       /*
+                        * This is wrong, but the rest of the program
+                        * has built in assumptions about "." as well,
+                        * so why make unedit a special case?
+                        */
+                       if (access(".", 2) < 0) {
+       bad:
+                               printf("%12s: can't remove\n", cp);
+                               fclose(tfp);
+                               fclose(pfp);
+                               unlink(tfn);
+                               return (FALSE);
+                       }
+       }
        /* do final cleanup */
        if (others)
        {
        /* do final cleanup */
        if (others)
        {
@@ -1154,8 +1279,13 @@ unedit(fn)
        /* actually remove the g-file */
        if (delete)
        {
        /* actually remove the g-file */
        if (delete)
        {
-               unlink(tail(fn));
-               printf("%12s: removed\n", tail(fn));
+               /*
+                * Since we've checked above, we can
+                * use the return from unlink to
+                * determine if the file existed or not.
+                */
+               if (unlink(cp) >= 0)
+                       printf("%12s: removed\n", cp);
                return (TRUE);
        }
        else
                return (TRUE);
        }
        else
@@ -1189,33 +1319,9 @@ dodiff(getv, gfile)
        register int pid;
        auto int st;
        extern int errno;
        register int pid;
        auto int st;
        extern int errno;
-       int (*osig)();
-       register char *p;
-       register char **ap;
-       bool makescript = FALSE;
-
-       for (ap = getv; *ap != NULL; ap++)
-       {
-               p = *ap;
-               if (p[0] == '-')
-               {
-                       switch (p[1])
-                       {
-                         case 'E':
-                               p[1] = 'e';
-                               makescript = TRUE;
-                               break;
-                       }
-               }
-       }
+       sig_t osig;
 
 
-       if (makescript)
-       {
-               printf("sccs edit %s\n", gfile);
-               printf("ed - %s << 'xxEOFxx'\n", gfile);
-       }
-       else
-               printf("\n------- %s -------\n", gfile);
+       printf("\n------- %s -------\n", gfile);
        fflush(stdout);
 
        /* create context for diff to run in */
        fflush(stdout);
 
        /* create context for diff to run in */
@@ -1252,15 +1358,6 @@ dodiff(getv, gfile)
                }
                command(&getv[1], FALSE, "-diff:elsfhbC");
        }
                }
                command(&getv[1], FALSE, "-diff:elsfhbC");
        }
-
-       if (makescript)
-       {
-               printf("w\n");
-               printf("q\n");
-               printf("'xxEOFxx'\n");
-               printf("sccs delta %s\n", gfile);
-       }
-
        return (rval);
 }
 \f
        return (rval);
 }
 \f
@@ -1309,7 +1406,7 @@ getpfent(pfp)
        FILE *pfp;
 {
        static struct pfile ent;
        FILE *pfp;
 {
        static struct pfile ent;
-       static char buf[120];
+       static char buf[PFILELG];
        register char *p;
        extern char *nextfield();
 
        register char *p;
        extern char *nextfield();
 
@@ -1454,7 +1551,52 @@ username()
        return (pw->pw_name);
 # else
        extern char *getlogin();
        return (pw->pw_name);
 # else
        extern char *getlogin();
+       register char *p;
 
 
-       return (getlogin());
+       p = getenv("USER");
+       if (p == NULL || p[0] == '\0')
+               p = getlogin();
+       return (p);
 # endif UIDUSER
 }
 # endif UIDUSER
 }
+\f
+/*
+**     Guarded string manipulation routines; the last argument
+**     is the length of the buffer into which the strcpy or strcat
+**     is to be done.
+*/
+char *gstrcat(to, from, length)
+       char    *to, *from;
+       int     length;
+{
+       if (strlen(from) + strlen(to) >= length) {
+               gstrbotch(to, from);
+       }
+       return(strcat(to, from));
+}
+
+char *gstrncat(to, from, n, length)
+       char    *to, *from;
+       int     n;
+       int     length;
+{
+       if (n + strlen(to) >= length) {
+               gstrbotch(to, from);
+       }
+       return(strncat(to, from, n));
+}
+
+char *gstrcpy(to, from, length)
+       char    *to, *from;
+       int     length;
+{
+       if (strlen(from) >= length) {
+               gstrbotch(from, (char *)0);
+       }
+       return(strcpy(to, from));
+}
+gstrbotch(str1, str2)
+       char    *str1, *str2;
+{
+       usrerr("Filename(s) too long: %s %s", str1, str2);
+}