[net.sources] Preprocessor to simplify usage of sccs files.

lars@myab.UUCP (Lars Pensj|) (12/28/84)

A preprocessor to simplify editing of sccs files. The files are supposed to
be in a subdirectory '.sc'. Automatic 'get', 'admin', 'delta' and 'unget'
are done when needed.

#--------CUT---------CUT---------CUT---------CUT--------#
#########################################################
#                                                       #
# This is a shell archive file.  To extract files:      #
#                                                       #
#    1)	Make a directory for the files.                 #
#    2) Write a file, such as "file.shar", containing   #
#       this archive file into the directory.           #
#    3) Type "sh file.shar".  Do not use csh.           #
#                                                       #
#########################################################
#
#
echo Extracting README:
sed 's/^Z//' >README <<\STUNKYFLUFF
ZThis directory contains a preprocessor for editing sccs files.
Z
Z1.	Source files are put in '.sc/s.filename'.
Z2.	Directorys and files are created if nonexisting.
Z3.	Pretty file headers are made for new files.
Z4.	Delta is automatically done when exiting v.
Z5.	A read only file is created when exiting v.
Z6.	Dates are only modified when files are modified.
Z7.	Vi is used as editor.
Z
ZFiles:
Z
ZREADME		This file.
Zmakefhead.c	Program to make a file head template.
Zmakefile	Building description for v and makefhead.
Zv.1		Manual page for v.
Zv.c		Preprocessor for manipulating sccs files.
STUNKYFLUFF
set `sum README`
if test 56592 != $1
then
echo README: Checksum error. Is: $1, should be: 56592.
fi
#
#
echo Extracting makefhead.c:
sed 's/^Z//' >makefhead.c <<\STUNKYFLUFF
Zstatic char *makefhead_c = "@(#)makefhead.c	1.17 84/11/12";
Z
Z/*
Z * File name:		makefhead.c 1.17
Z * Created:		841021
Z * By:			Lars Pensj|
Z * Latest change:	84/11/12 16:18:37
Z * Purpose of this file:
Z *	A program that makes a nice file header.
Z * 
Z * Definitions	Description
Z * PER		character value for percent.
Z */
Z
Z# include <stdio.h>
Z# include <time.h>
Z
Z# define PER	045
Z
Zchar *getlogin();
Zstruct tm *localtime();
Zlong tloc;
Zstruct tm *tm;
Zchar name2[14];
Z
Zmain(argc, argv)
Zchar **argv;
Z{
Z    FILE *fd;
Z    char *name = argv[1];
Z    char *p;
Z
Z    if (argc != 2) {
Z	fprintf(stderr, "Usage: makefhead file\n");
Z	exit(1);
Z    }
Z    strncpy(name2, name, 14);
Z    for (p = name2; *p; p++) {
Z	if ((*p <= 'z' && *p >= 'a') ||
Z	    (*p <= 'Z' && *p >= 'A') ||
Z	    (*p <= '9' && *p >= '0')) continue;
Z	*p = '_';
Z    }
Z    fd = fopen(name, "w");
Z    if (fd == NULL) {
Z	fprintf(stderr, "Couldn't open %s for write.\n", name);
Z	exit(1);
Z    }
Z    time(&tloc);
Z    tm = localtime(&tloc);
Z    fprintf(fd,"\nstatic char *%s = \"%cW%c %cE%c\";\n", name2,
Z        PER, PER, PER, PER);
Z    fprintf(fd,"\n/*\n");
Z    fprintf(fd," * File name:		%s %cI%c\n", name, PER, PER);
Z    fprintf(fd," * Created:		%02d%02d%02d\n", tm->tm_year,
Z	tm->tm_mon+1, tm->tm_mday);
Z    fprintf(fd," * By:			%s\n", getlogin());
Z    fprintf(fd," * Latest change:	%cE%c %cU%c\n", PER, PER, PER, PER);
Z    fprintf(fd," * Purpose of this file:\n");
Z    fprintf(fd," * \n");
Z    fprintf(fd," * Definitions	Description\n");
Z    fprintf(fd," * \n");
Z    fprintf(fd," * (ELABORATE FUNCTIONAL DESCRIPTION)\n");
Z    fprintf(fd," */\n");
Z}
STUNKYFLUFF
set `sum makefhead.c`
if test 48167 != $1
then
echo makefhead.c: Checksum error. Is: $1, should be: 48167.
fi
#
#
echo Extracting makefile:
sed 's/^Z//' >makefile <<\STUNKYFLUFF
Zall:		makefhead v
Z
Zmakefhead:	makefhead.c
Z		cc makefhead.c -o makefhead
Z
Zv:		v.c
Z		cc v.c -o v -ljobs
STUNKYFLUFF
set `sum makefile`
if test 40460 != $1
then
echo makefile: Checksum error. Is: $1, should be: 40460.
fi
#
#
echo Extracting v.1:
sed 's/^Z//' >v.1 <<\STUNKYFLUFF
Z.TH V 1L Local
Z.SH "NAME"
Zv \- a preprocessor for sccs files.
Z.SH "SYNOPSIS"
Zv [-rSID] file
Z.SH "DESCRIPTION"
Z.I
ZV
Zdoes an atutomatic check out (get -e) on the file that is wanted for
Zmanipulation.
ZIf the file is missing or something is wrong, questions are
Zasked and proper precautions are done.
ZVi is started on the specified file.
ZIf the 'r' flag is present, it will be passed on to the 'get' command.
ZThe sccs files are taken from subdirectory '.sc'.
ZIf the program 'makefhead' exists, it will be run when creating new files.
ZOtherwise a template is looked for at /usr/src/filehead.
Z.SH "FILES"
Z .sc/s.file /usr/src/filehead
Z.SH "SEE ALSO"
Zvi admin delta get unget
Z.SH "BUGS"
ZA read only file is created in background immediately after exiting v.
Z.SH "AUTHOR"
ZLars Pensj|
STUNKYFLUFF
set `sum v.1`
if test 40114 != $1
then
echo v.1: Checksum error. Is: $1, should be: 40114.
fi
#
#
echo Extracting v.c:
sed 's/^Z//' >v.c <<\STUNKYFLUFF
Z#include <stdio.h>
Z#include <sys/types.h>
Z#include <sys/stat.h>
Z#include <signal.h>
Z
Zchar *v_c = "@(#)v.c	2.2 84/12/21";
Z
Z/*
Z * v.c 2.2 created 841020 by Lars Pensj|.
Z * Copyright (c) 1984 By Lars Pensj|.
Z * The file may be copied if it is not used for commercial purposes.
Z * The author takes no responsibility whatsover for the usage of the program.
Z *
Z * A preprocessor for manipulating sccs files from a subdirectory .sc.
Z * V checks out a file from directory .sc for editing and starts
Z * 'vi' on it. After editing is done, the file is reentered into
Z * its sccs file, and a read only copy is left.
Z * The read only copy is created after exiting this program (in background).
Z */
Z
Z/* Path to program makefhead. */
Z
Z#define MAKEFHEAD "makefhead"
Z#define FILEHEAD "/usr/src/filehead"
Z
Zint retstatus;
Zstruct stat statbuff;
Ztime_t timep[2];
Z
Zmain(argc, argv)
Zchar **argv;
Z{
Z    char file[100];
Z    char buff[50];
Z    register char *name = NULL, *sid = NULL;
Z    register int status;
Z
Z    argv++;
Z    while (*argv) {
Z	if (**argv == '-') {
Z	    switch((*argv)[1]) {
Z	    case 'r':
Z		sid = *argv;
Z		break;
Z	    default:
Z		fprintf(stderr, "Illegal flag %s\n", *argv);
Z		break;
Z	    }
Z	} else {
Z	    if (name) usage();
Z	    name = *argv;
Z	}
Z	argv++;
Z    }
Z    if (!name) usage(); 	/* Are there a file name given ? */
Z    strcpy(file, ".sc/s.");	/* Make sccs file name */
Z    strcat(file, name);
Z    if (!access(name, 6)) {	/* Check if file exists */
Z	fprintf(stderr, "File exists. Edit it ? ");
Z	gets(buff);
Z	if (buff[0] != 'y') exit(0);
Z	if (access(file, 4)) {		/* Check if sccs file exists */
Z	    fprintf(stderr, "No sccs file %s. Create ? ", file);
Z	    gets(buff);
Z	    if (buff[0] != 'y') {
Z		fprintf(stderr, "Nothing done\n");
Z		exit(0);
Z	    }
Z	    /* Do an 'admin' to create sccs file */
Z	    checkdir();
Z	    strcpy(buff, "-i");
Z	    strcat(buff, name);
Z	    fprintf(stderr, "Giv descriptive text ended with EOF:\n");
Z	    status = mexec("admin", "admin", buff, file, "-t/dev/tty", 0);
Z	    if (status || access(file, 4)) {
Z		fprintf(stderr, "Error creating %s\n", file);
Z		exit(1);
Z	    }
Z	    /* Get date of old file */
Z	    copydate(name, file);
Z	    /* Take away old file */
Z	    status = mexec("rm", "rm", name, 0);
Z	    if (status) {
Z		fprintf(stderr, "v(84) Couldn't remove old %s\n", name);
Z		exit(1);
Z	    }
Z	    /* Check out file */
Z	    status = mexec("get", "get", "-e", file, sid, 0);
Z	    if (status || access(name, 6)) {
Z		fprintf(stderr, "v(90) Couldn't check out file %s\n", name);
Z		exit(1);
Z	    }
Z	    /* Restore date */
Z	    copydate(file, name);
Z	}
Z    } else {
Z	/* Check if sccs file exists */
Z	if (access(file, 4)) {
Z	    if (!access(name, 4)) {
Z		fprintf(stderr, "%s exists as read only but no %s !\n",
Z		    name, file);
Z		exit(1);
Z	    }
Z	    fprintf(stderr, "No sccs file %s. Create ? ", file);
Z	    gets(buff);
Z	    if (buff[0] != 'y') {
Z		fprintf(stderr, "Nothing done\n");
Z		exit(0);
Z	    }
Z	    checkdir();
Z	    fprintf(stderr, "Giv descriptive text ended with EOF:\n");
Z	    status = mexec("admin", "admin", "-n", file, "-t/dev/tty", 0);
Z	    if (status) {
Z		fprintf(stderr, "Error creating %s\n", file);
Z		exit(1);
Z	    }
Z	    /* Check out empty file */
Z	    status = mexec("get", "get", "-e", file, sid, 0);
Z	    if (status || access(name, 6)) {
Z		fprintf(stderr, "v(120) Couldn't check out file %s\n", name);
Z		exit(1);
Z	    }
Z	    /* Fix a starting file */
Z	    status = mexec(MAKEFHEAD, "makefhead", name, 0);
Z	    if (status) {	/* Did it work ? */
Z		status = mexec("cp", "cp", FILEHEAD, name, 0);
Z		if (status) {	/* Did this work ?? */
Z		    fprintf(stderr, "v(128) Couldn't create template file\n");
Z		}
Z	    }
Z	} else {
Z	    /* Sccs file did exist. Check out file */
Z	    status = mexec("get", "get", "-e", file, sid, 0);
Z	    if (status || access(name, 6)) {
Z		fprintf(stderr, "v(135) Couldn't check out file %s\n", name);
Z		exit(1);
Z	    }
Z	    copydate(file, name);
Z	}
Z    }
Zedit:
Z    status = mexec("vi", "vi", name, 0);
Z    if (status) {
Z	fprintf(stderr, "v(144) Couldn't start 'vi %s'\n", name);
Z	exit(1);
Z    }
Z    while (1) {
Z	fprintf(stderr, "make delta (y/n/e/q/?): ");
Z	gets(buff);
Z	switch(buff[0]) {
Z	case 'y':
Z	    status = mexec("delta", "delta", file, 0);
Z	    if (status) {
Z		printf("Couldn't make delta\n");
Z		exit(1);
Z	    }
Z	    background();
Z	    status = mexec("get", "get", "-s", file, 0);
Z	    if (!status) {
Z		copydate(file, name);
Z	    }
Z	    exit(0);
Z	case 'q':
Z	    fprintf(stderr, "Leaving file %s for editing\n", name);
Z	    exit(0);
Z	case 'e':
Z	    goto edit;
Z	case 'n':
Z	    fprintf(stderr, "Undo latest version %s ? ", name);
Z	    gets(buff);
Z	    if (buff[0] == 'y') {
Z		status = mexec("unget", "unget", file, 0);
Z		if (status) {
Z		    fprintf(stderr, "v(174) Couldn't unget file %s\n", name);
Z		    break;
Z		}
Z		background();
Z		status = mexec("get", "get", "-s", file, 0);
Z		if (!status) {
Z		    copydate(file, name);
Z		}
Z		exit(0);
Z	    }
Z	    break;
Z	}
Z	fprintf(stderr, "Valid responses are:\n");
Z	fprintf(stderr, "y:	yes\nn:	no\nq:	quit\ne:	re-edit\n");
Z    }
Z}
Z
Z/*VARARGS0*/
Zmexec(a1, a2, a3, a4, a5, a6, a7, a8, a9)
Z{
Z    int s;
Z
Z    s = vfork();
Z    if (s) {
Z	if (s == -1) {
Z	    fprintf(stderr, "v(199) Couldn't vfork\n");
Z	    exit(1);
Z	}
Z	sighold(SIGINT);
Z	if (wait(&retstatus) != s) fprintf(stderr, "v(203) Wait gave wrong child\n");
Z	sigrelse(SIGINT);
Z	return retstatus;
Z    }
Z    execlp(a1, a2, a3, a4, a5, a6, a7, a8, a9);
Z    /* Normally no return */
Z    exit(1);
Z}
Z
Zcopydate(f1, f2)
Zchar *f1, *f2;
Z{
Z    if (stat(f1, &statbuff) == -1) {
Z	fprintf(stderr, "v(216) Couldn't stat %s\n", f1);
Z	exit(1);
Z    }
Z    timep[0] = statbuff.st_atime;
Z    timep[1] = statbuff.st_mtime;
Z    utime(f2, timep);
Z}
Z
Zbackground() {
Z    int s;
Z
Z    s = fork();
Z    if (s == -1) {
Z	fprintf(stderr, "v(229) Couldn't move to background\n");
Z	return;
Z    }
Z    if (s) exit(0);
Z}
Z
Zusage() {
Z    fprintf(stderr, "Usage: v [-rSID] file\n");
Z    exit(1);
Z}
Z
Zcheckdir() {
Z    char buff[50];
Z
Z    if (!access(".sc/.", 0)) return;
Z    fprintf(stderr, "No directory '.sc'. Create ? ");
Z    gets(buff);
Z    if (buff[0] != 'y') exit(1);
Z    if (mexec("mkdir", "mkdir", ".sc", 0)) {
Z	fprintf(stderr, "Couldn't create directory '.sc'\n");
Z	exit(1);
Z    }
Z}
STUNKYFLUFF
set `sum v.c`
if test 13502 != $1
then
echo v.c: Checksum error. Is: $1, should be: 13502.
fi
echo All done
exit 0