add ``create'' command
[unix-history] / usr / src / usr.bin / sccs / sccs.c
index 8b8cc83..8ceba1a 100644 (file)
@@ -6,6 +6,7 @@
 # include <signal.h>
 # include <sysexits.h>
 # include <whoami.h>
 # include <signal.h>
 # include <sysexits.h>
 # include <whoami.h>
+# include <pwd.h>
 
 /*
 **  SCCS.C -- human-oriented front end to the SCCS system.
 
 /*
 **  SCCS.C -- human-oriented front end to the SCCS system.
@@ -92,7 +93,7 @@
 **             Copyright 1980 Regents of the University of California
 */
 
 **             Copyright 1980 Regents of the University of California
 */
 
-static char SccsId[] = "@(#)sccs.c     1.52.1.1 %G%";
+static char SccsId[] = "@(#)sccs.c     1.63 %G%";
 \f
 /*******************  Configuration Information  ********************/
 
 \f
 /*******************  Configuration Information  ********************/
 
@@ -134,10 +135,6 @@ typedef char       bool;
 
 # define bitset(bit, word)     ((bool) ((bit) & (word)))
 
 
 # define bitset(bit, word)     ((bool) ((bit) & (word)))
 
-# ifdef UIDUSER
-# include <pwd.h>
-# endif UIDUSER
-
 struct sccsprog
 {
        char    *sccsname;      /* name of SCCS routine */
 struct sccsprog
 {
        char    *sccsname;      /* name of SCCS routine */
@@ -155,6 +152,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 CREATE                8       /* create 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 */
@@ -183,13 +181,15 @@ struct sccsprog SccsProg[] =
        "delta",        PROG,   0,                      PROGPATH(delta),
        "get",          PROG,   0,                      PROGPATH(get),
        "help",         PROG,   NO_SDOT,                PROGPATH(help),
        "delta",        PROG,   0,                      PROGPATH(delta),
        "get",          PROG,   0,                      PROGPATH(get),
        "help",         PROG,   NO_SDOT,                PROGPATH(help),
+       "prs",          PROG,   0,                      PROGPATH(prs),
        "prt",          PROG,   0,                      PROGPATH(prt),
        "rmdel",        PROG,   REALUSER,               PROGPATH(rmdel),
        "prt",          PROG,   0,                      PROGPATH(prt),
        "rmdel",        PROG,   REALUSER,               PROGPATH(rmdel),
+       "val",          PROG,   0,                      PROGPATH(val),
        "what",         PROG,   NO_SDOT,                PROGPATH(what),
        "sccsdiff",     SHELL,  REALUSER,               PROGPATH(sccsdiff),
        "edit",         CMACRO, NO_SDOT,                "get -e",
        "delget",       CMACRO, NO_SDOT,                "delta:mysrp/get:ixbeskcl -t",
        "what",         PROG,   NO_SDOT,                PROGPATH(what),
        "sccsdiff",     SHELL,  REALUSER,               PROGPATH(sccsdiff),
        "edit",         CMACRO, NO_SDOT,                "get -e",
        "delget",       CMACRO, NO_SDOT,                "delta:mysrp/get:ixbeskcl -t",
-       "deledit",      CMACRO, NO_SDOT,                "delta:mysrp/get:ixbskcl -e -t",
+       "deledit",      CMACRO, NO_SDOT,                "delta:mysrp -n/get:ixbskcl -e -t -g",
        "fix",          FIX,    NO_SDOT,                NULL,
        "clean",        CLEAN,  REALUSER|NO_SDOT,       (char *) CLEANC,
        "info",         CLEAN,  REALUSER|NO_SDOT,       (char *) INFOC,
        "fix",          FIX,    NO_SDOT,                NULL,
        "clean",        CLEAN,  REALUSER|NO_SDOT,       (char *) CLEANC,
        "info",         CLEAN,  REALUSER|NO_SDOT,       (char *) INFOC,
@@ -198,6 +198,10 @@ 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",
+       "branch",       CMACRO, NO_SDOT,
+               "get:ixrc -e -b/delta: -s -n -ybranch-place-holder/get:pl -e -t -g",
+       "create",       CREATE, NO_SDOT,                NULL,
        NULL,           -1,     0,                      NULL
 };
 
        NULL,           -1,     0,                      NULL
 };
 
@@ -209,6 +213,7 @@ struct pfile
        char    *p_user;        /* user who did edit */
        char    *p_date;        /* date of get */
        char    *p_time;        /* time of get */
        char    *p_user;        /* user who did edit */
        char    *p_date;        /* date of get */
        char    *p_time;        /* time of get */
+       char    *p_aux;         /* extra info at end */
 };
 
 char   *SccsPath = SCCSPATH;   /* pathname of SCCS files */
 };
 
 char   *SccsPath = SCCSPATH;   /* pathname of SCCS files */
@@ -223,6 +228,9 @@ bool        RealUser;               /* if set, running as real user */
 # ifdef DEBUG
 bool   Debug;                  /* turn on tracing */
 # endif
 # ifdef DEBUG
 bool   Debug;                  /* turn on tracing */
 # endif
+# ifndef V6
+extern char    *getenv();
+# endif V6
 \f
 main(argc, argv)
        int argc;
 \f
 main(argc, argv)
        int argc;
@@ -231,6 +239,43 @@ main(argc, argv)
        register char *p;
        extern struct sccsprog *lookup();
        register int i;
        register char *p;
        extern struct sccsprog *lookup();
        register int i;
+# ifndef V6
+# ifndef SCCSDIR
+       register struct passwd *pw;
+       extern struct passwd *getpwnam();
+       char buf[100];
+
+       /* pull "SccsDir" out of the environment (possibly) */
+       p = getenv("PROJECT");
+       if (p != NULL && p[0] != '\0')
+       {
+               if (p[0] == '/')
+                       SccsDir = p;
+               else
+               {
+                       pw = getpwnam(p);
+                       if (pw == NULL)
+                       {
+                               usrerr("user %s does not exist", p);
+                               exit(EX_USAGE);
+                       }
+                       strcpy(buf, pw->pw_dir);
+                       strcat(buf, "/src");
+                       if (access(buf, 0) < 0)
+                       {
+                               strcpy(buf, pw->pw_dir);
+                               strcat(buf, "/source");
+                               if (access(buf, 0) < 0)
+                               {
+                                       usrerr("project %s has no source!", p);
+                                       exit(EX_USAGE);
+                               }
+                       }
+                       SccsDir = buf;
+               }
+       }
+# endif SCCSDIR
+# endif V6
 
        /*
        **  Detect and decode flags intended for this program.
 
        /*
        **  Detect and decode flags intended for this program.
@@ -259,10 +304,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
 
@@ -315,7 +364,7 @@ command(argv, forkflag, arg0)
 {
        register struct sccsprog *cmd;
        register char *p;
 {
        register struct sccsprog *cmd;
        register char *p;
-       char buf[40];
+       char buf[100];
        extern struct sccsprog *lookup();
        char *nav[1000];
        char **np;
        extern struct sccsprog *lookup();
        char *nav[1000];
        char **np;
@@ -507,6 +556,32 @@ command(argv, forkflag, arg0)
                syserr("cannot exec %s", cmd->sccspath);
                exit(EX_OSERR);
 
                syserr("cannot exec %s", cmd->sccspath);
                exit(EX_OSERR);
 
+         case CREATE:          /* create 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)
+               {
+                       sprintf(buf, "-i%s", *np);
+                       ap[0] = buf;
+                       argv[0] = tail(*np);
+                       argv[1] = NULL;
+                       rval = command(ap, TRUE, "admin");
+                       argv[1] = p;
+                       if (rval == 0)
+                       {
+                               sprintf(buf, ",%s", tail(*np));
+                               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);
@@ -816,6 +891,7 @@ clean(mode, argv)
 {
        struct direct dir;
        char buf[100];
 {
        struct direct dir;
        char buf[100];
+       char *bufend;
        register FILE *dirfd;
        register char *basefile;
        bool gotedit;
        register FILE *dirfd;
        register char *basefile;
        bool gotedit;
@@ -827,12 +903,15 @@ clean(mode, argv)
        register char **ap;
        extern char *username();
        char *usernm = NULL;
        register char **ap;
        extern char *username();
        char *usernm = NULL;
+       char *subdir = NULL;
+       char *cmdname;
 
        /*
        **  Process the argv
        */
 
 
        /*
        **  Process the argv
        */
 
-       for (ap = argv; *ap != NULL; ap++)
+       cmdname = *argv;
+       for (ap = argv; *++ap != NULL; )
        {
                if (**ap == '-')
                {
        {
                if (**ap == '-')
                {
@@ -853,6 +932,13 @@ clean(mode, argv)
                                break;
                        }
                }
                                break;
                        }
                }
+               else
+               {
+                       if (subdir != NULL)
+                               usrerr("too many args");
+                       else
+                               subdir = *ap;
+               }
        }
 
        /*
        }
 
        /*
@@ -862,7 +948,13 @@ clean(mode, argv)
        strcpy(buf, SccsDir);
        if (buf[0] != '\0')
                strcat(buf, "/");
        strcpy(buf, SccsDir);
        if (buf[0] != '\0')
                strcat(buf, "/");
+       if (subdir != NULL)
+       {
+               strcat(buf, subdir);
+               strcat(buf, "/");
+       }
        strcat(buf, SccsPath);
        strcat(buf, SccsPath);
+       bufend = &buf[strlen(buf)];
 
        dirfd = fopen(buf, "r");
        if (dirfd == NULL)
 
        dirfd = fopen(buf, "r");
        if (dirfd == NULL)
@@ -884,12 +976,8 @@ clean(mode, argv)
                        continue;
                
                /* got an s. file -- see if the p. file exists */
                        continue;
                
                /* got an s. file -- see if the p. file exists */
-               strcpy(buf, SccsDir);
-               if (buf[0] != '\0')
-                       strcat(buf, "/");
-               strcat(buf, SccsPath);
-               strcat(buf, "/p.");
-               basefile = &buf[strlen(buf)];
+               strcpy(bufend, "/p.");
+               basefile = bufend + 3;
                strncpy(basefile, &dir.d_name[2], sizeof dir.d_name - 2);
                basefile[sizeof dir.d_name - 2] = '\0';
 
                strncpy(basefile, &dir.d_name[2], sizeof dir.d_name - 2);
                basefile[sizeof dir.d_name - 2] = '\0';
 
@@ -917,9 +1005,8 @@ clean(mode, argv)
                                        printf("%s\n", basefile);
                                        break;
                                }
                                        printf("%s\n", basefile);
                                        break;
                                }
-                               printf("%12s: being edited: %s %s %s %s %s\n",
-                                      basefile, pf->p_osid, pf->p_nsid,
-                                      pf->p_user, pf->p_date, pf->p_time);
+                               printf("%12s: being edited: ", basefile);
+                               putpfent(pf, stdout);
                        }
                        fclose(pfp);
                }
                        }
                        fclose(pfp);
                }
@@ -1067,9 +1154,7 @@ unedit(fn)
                else
                {
                        /* output it again */
                else
                {
                        /* output it again */
-                       fprintf(tfp, "%s %s %s %s %s\n", pent->p_osid,
-                           pent->p_nsid, pent->p_user, pent->p_date,
-                           pent->p_time);
+                       putpfent(pent, tfp);
                        others++;
                }
        }
                        others++;
                }
        }
@@ -1270,8 +1355,7 @@ getpfent(pfp)
        ent.p_user = p = nextfield(p);
        ent.p_date = p = nextfield(p);
        ent.p_time = p = nextfield(p);
        ent.p_user = p = nextfield(p);
        ent.p_date = p = nextfield(p);
        ent.p_time = p = nextfield(p);
-       if (p == NULL || nextfield(p) != NULL)
-               return (NULL);
+       ent.p_aux = p = nextfield(p);
 
        return (&ent);
 }
 
        return (&ent);
 }
@@ -1293,6 +1377,31 @@ nextfield(p)
        *p++ = '\0';
        return (p);
 }
        *p++ = '\0';
        return (p);
 }
+\f/*
+**  PUTPFENT -- output a p-file entry to a file
+**
+**     Parameters:
+**             pf -- the p-file entry
+**             f -- the file to put it on.
+**
+**     Returns:
+**             none.
+**
+**     Side Effects:
+**             pf is written onto file f.
+*/
+
+putpfent(pf, f)
+       register struct pfile *pf;
+       register FILE *f;
+{
+       fprintf(f, "%s %s %s %s %s", pf->p_osid, pf->p_nsid,
+               pf->p_user, pf->p_date, pf->p_time);
+       if (pf->p_aux != NULL)
+               fprintf(f, " %s", pf->p_aux);
+       else
+               fprintf(f, "\n");
+}
 \f
 /*
 **  USRERR -- issue user-level error
 \f
 /*
 **  USRERR -- issue user-level error
@@ -1378,6 +1487,13 @@ username()
        }
        return (pw->pw_name);
 # else
        }
        return (pw->pw_name);
 # else
-       return (getlogin());
+       extern char *getlogin();
+       extern char *getenv();
+       register char *p;
+
+       p = getenv("USER");
+       if (p == NULL || p[0] == '\0')
+               p = getlogin();
+       return (p);
 # endif UIDUSER
 }
 # endif UIDUSER
 }