static char SccsId
[] = "@(#)sccs.c 1.12 %G%";
# define bitset(bit, word) ((bit) & (word))
char *sccsname
; /* name of SCCS routine */
short sccsoper
; /* opcode, see below */
short sccsflags
; /* flags, see below */
char *sccspath
; /* pathname of binary implementing */
/* values for sccsoper */
# define PROG 0 /* call a program */
# define CMACRO 1 /* command substitution macro */
# define FIX 2 /* fix a delta */
# define CLEAN 3 /* clean out recreatable files */
# define NO_SDOT 0001 /* no s. on front of args */
# define REALUSER 0002 /* protected (e.g., admin) */
# define PROGPATH(name) "/usr/local/name"
# define PROGPATH(name) "/usr/sccs/name"
struct sccsprog SccsProg
[] =
"admin", PROG
, REALUSER
, PROGPATH(admin
),
"chghist", PROG
, 0, PROGPATH(rmdel
),
"comb", PROG
, 0, PROGPATH(comb
),
"delta", PROG
, 0, PROGPATH(delta
),
"get", PROG
, 0, PROGPATH(get
),
"help", PROG
, NO_SDOT
, PROGPATH(help
),
"prt", PROG
, 0, PROGPATH(prt
),
"rmdel", PROG
, REALUSER
, PROGPATH(rmdel
),
"what", PROG
, NO_SDOT
, PROGPATH(what
),
"del", CMACRO
, 0, "delta/get",
"delt", CMACRO
, 0, "delta/get",
"clean", CLEAN
, REALUSER
, NULL
,
char *SccsPath
= "SCCS"; /* pathname of SCCS files */
bool RealUser
; /* if set, running as real user */
extern struct sccsprog
*lookup();
** Detect and decode flags intended for this program.
fprintf(stderr
, "Usage: sccs [flags] command [flags]\n");
if (lookup(argv
[0]) == NULL
)
while ((p
= *++argv
) != NULL
)
case 'r': /* run as real user */
case 'p': /* path of sccs files */
fprintf(stderr
, "Sccs: unknown option -%s\n", p
);
register struct sccsprog
*cmd
;
extern struct sccsprog
*lookup();
** At this point, argv points to the command name.
fprintf(stderr
, "Sccs: Unknown command \"%s\"\n", p
);
** Interpret operation associated with this command.
case PROG
: /* call an sccs prog */
callprog(cmd
->sccspath
, cmd
->sccsflags
, argv
, forkflag
);
case CMACRO
: /* command macro */
for (p
= cmd
->sccspath
; *p
!= '\0'; p
++)
for (q
= buf
; *p
!= '/' && *p
!= '\0'; p
++, q
++)
command(argv
, *p
!= '\0');
fprintf(stderr
, "Sccs internal error: CMACRO\n");
case FIX
: /* fix a delta */
if (strcmpn(argv
[1], "-r", 2) != 0)
fprintf(stderr
, "Sccs: -r flag needed for fix command\n");
xcommand(&argv
[1], TRUE
, "get", "-k", NULL
);
xcommand(&argv
[1], TRUE
, "rmdel", NULL
);
xcommand(&argv
[2], FALSE
, "get", "-e", "-g", NULL
);
fprintf(stderr
, "Sccs internal error: FIX\n");
fprintf(stderr
, "Sccs internal error: oper %d\n", cmd
->sccsoper
);
** LOOKUP -- look up an SCCS command name.
** name -- the name of the command to look up.
** ptr to command descriptor for this command.
** NULL if no such entry.
register struct sccsprog
*cmd
;
for (cmd
= SccsProg
; cmd
->sccsname
!= NULL
; cmd
++)
if (strcmp(cmd
->sccsname
, name
) == 0)
xcommand(argv
, forkflag
, arg0
)
for (av
= &arg0
; *av
!= NULL
; av
++)
for (av
= argv
; *av
!= NULL
; av
++)
command(newargv
, forkflag
);
callprog(progpath
, flags
, argv
, forkflag
)
fprintf(stderr
, "Sccs: cannot fork");
** Build new argument vector.
/* copy program filename arguments and flags */
while ((p
= *++av
) != NULL
)
if (!bitset(NO_SDOT
, flags
) && *p
!= '-')
** Set protection as appropriate.
if (bitset(REALUSER
, flags
))
** Call real SCCS program.
fprintf(stderr
, "Sccs: cannot execute ");
** See if this filename should be used as-is.
** There are three conditions where this can occur.
** 1. The name already begins with "s.".
** 2. The name has a "/" in it somewhere.
** 3. The name references a directory.
if (strcmpn(name
, "s.", 2) == 0)
for (p
= name
; (c
= *p
) != '\0'; p
++)
if (stat(name
, &stbuf
) >= 0 && (stbuf
.st_mode
& S_IFMT
) == S_IFDIR
)
** Prepend the path of the sccs file.
p
= malloc(strlen(buf
) + 1);
** CLEAN -- clean out recreatable files
** Any file for which an "s." file exists but no "p." file
** exists in the current directory is purged.
** removes files in the current directory.
dirfd
= fopen(SccsPath
, "r");
fprintf(stderr
, "Sccs: cannot open %s\n", SccsPath
);
** Scan the SCCS directory looking for s. files.
while (fread(&dir
, sizeof dir
, 1, dirfd
) != NULL
)
if (dir
.d_ino
== 0 || strcmpn(dir
.d_name
, "s.", 2) != 0)
/* got an s. file -- see if the p. file exists */
buf
[strlen(buf
) + sizeof dir
.d_name
- 2] = '\0';
strcatn(buf
, &dir
.d_name
[2], sizeof dir
.d_name
- 2);
if (stat(buf
, &stbuf
) >= 0)
/* the s. file exists and no p. file exists -- unlink the g-file */
buf
[sizeof dir
.d_name
- 2] = '\0';
strcpyn(buf
, &dir
.d_name
[2], sizeof dir
.d_name
- 2);