BSD 4_3_Tahoe release
[unix-history] / usr / src / ucb / sccs.c
index a630fd7..11b75bd 100644 (file)
@@ -1,7 +1,34 @@
+/*
+ * Copyright (c) 1980 Regents of the University of California.
+ * All rights reserved.
+ *
+ * Redistribution and use in source and binary forms are permitted
+ * provided that the above copyright notice and this paragraph are
+ * duplicated in all such forms and that any documentation,
+ * advertising materials, and other materials related to such
+ * distribution and use acknowledge that the software was developed
+ * by the University of California, Berkeley.  The name of the
+ * University may not 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 MERCHANTIBILITY 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.6 (Berkeley) 6/29/88";
+#endif /* not lint */
+
 # include <stdio.h>
 # include <sys/param.h>
 # include <sys/stat.h>
 # include <stdio.h>
 # include <sys/param.h>
 # include <sys/stat.h>
-# include <dir.h>
+# include <sys/dir.h>
 # include <errno.h>
 # include <signal.h>
 # include <sysexits.h>
 # include <errno.h>
 # include <signal.h>
 # include <sysexits.h>
 **             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.69 1/13/83";
 \f
 /*******************  Configuration Information  ********************/
 
 \f
 /*******************  Configuration Information  ********************/
 
@@ -157,7 +191,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),
@@ -179,7 +213,7 @@ 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,
        "branch",       CMACRO, NO_SDOT,
                "get:ixrc -e -b/delta: -s -n -ybranch-place-holder/get:pl -e -t -g",
        "enter",        ENTER,  NO_SDOT,                NULL,
@@ -214,6 +248,8 @@ bool        Debug;                  /* turn on tracing */
 extern char    *getenv();
 # endif V6
 
 extern char    *getenv();
 # endif V6
 
+extern char    *sys_siglist[];
+
 char *gstrcat(), *strcat();
 char *gstrncat(), *strncat();
 char *gstrcpy(), *strcpy();
 char *gstrcat(), *strcat();
 char *gstrncat(), *strncat();
 char *gstrcpy(), *strcpy();
@@ -467,7 +503,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;
@@ -639,7 +675,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)
@@ -671,9 +712,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);
@@ -898,7 +960,7 @@ clean(mode, argv)
        struct direct *dir;
        char buf[FBUFSIZ];
        char *bufend;
        struct direct *dir;
        char buf[FBUFSIZ];
        char *bufend;
-       register DIR *dirfd;
+       register DIR *dirp;
        register char *basefile;
        bool gotedit;
        bool gotpfent;
        register char *basefile;
        bool gotedit;
        bool gotpfent;
@@ -962,8 +1024,8 @@ clean(mode, argv)
        gstrcat(buf, SccsPath, sizeof(buf));
        bufend = &buf[strlen(buf)];
 
        gstrcat(buf, SccsPath, sizeof(buf));
        bufend = &buf[strlen(buf)];
 
-       dirfd = opendir(buf);
-       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);
@@ -976,7 +1038,7 @@ clean(mode, argv)
        */
 
        gotedit = FALSE;
        */
 
        gotedit = FALSE;
-       while (dir = readdir(dirfd)) {
+       while (dir = readdir(dirp)) {
                if (strncmp(dir->d_name, "s.", 2) != 0)
                        continue;
                
                if (strncmp(dir->d_name, "s.", 2) != 0)
                        continue;
                
@@ -1025,7 +1087,7 @@ clean(mode, argv)
        }
 
        /* cleanup & report results */
        }
 
        /* cleanup & report results */
-       closedir(dirfd);
+       closedir(dirp);
        if (!gotedit && mode == INFOC)
        {
                printf("Nothing being edited");
        if (!gotedit && mode == INFOC)
        {
                printf("Nothing being edited");
@@ -1096,7 +1158,7 @@ unedit(fn)
        char *fn;
 {
        register FILE *pfp;
        char *fn;
 {
        register FILE *pfp;
-       char *pfn;
+       char *cp, *pfn;
        static char tfn[] = "/tmp/sccsXXXXX";
        FILE *tfp;
        register char *q;
        static char tfn[] = "/tmp/sccsXXXXX";
        FILE *tfp;
        register char *q;
@@ -1107,7 +1169,7 @@ unedit(fn)
        struct pfile *pent;
        extern struct pfile *getpfent();
        char buf[PFILELG];
        struct pfile *pent;
        extern struct pfile *getpfent();
        char buf[PFILELG];
-       extern char *makefile();
+       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);
@@ -1163,6 +1225,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)
        {
@@ -1192,8 +1280,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
@@ -1459,7 +1552,6 @@ username()
        return (pw->pw_name);
 # else
        extern char *getlogin();
        return (pw->pw_name);
 # else
        extern char *getlogin();
-       extern char *getenv();
        register char *p;
 
        p = getenv("USER");
        register char *p;
 
        p = getenv("USER");