home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
rtsi.com
/
2014.01.www.rtsi.com.tar
/
www.rtsi.com
/
OS9
/
OS9000
/
APPS
/
rcs.lzh
/
rcs1
/
puttot.c
< prev
next >
Wrap
C/C++ Source or Header
|
1996-04-22
|
8KB
|
302 lines
static char RCSid[]="$Header: puttot.c_v 1.4 96/04/23 02:01:48 hiro Exp $";
/********************************************************************
Copyright (c) 1993 ARK Systems USA
All rights reserved.
Program: puttot - put symbolic label at top of RCS trunk
File: puttot.c
$Date: 96/04/23 02:01:48 $
$Revision: 1.4 $
$Log: puttot.c_v $
* Revision 1.4 96/04/23 02:01:48 hiro
* Excluded inclusion of <stdlib.h> for OS-9.
*
* Revision 1.3 96/04/21 01:21:44 hiro
* Ported to OS-9000.
*
* Revision 1.2 93/04/04 01:46:41 hiro
* Prototype
* ================================================================
* Made work!
* ================================================================
*
********************************************************************/
#ifdef _UCC
_asm("_sysedit: equ 1");
#else
@_sysedit: equ 1
#endif
#include <stdio.h>
#if defined(__STDC__) || defined(_OS9000)
#include <stdlib.h>
#else
extern void *malloc();
#endif
#include <strings.h>
#include <time.h>
#include <errno.h>
#include <ctype.h>
#include <module.h>
#ifdef _OS9000
#include <io.h>
#else
#include <sysio.h>
#endif
#include <modes.h>
#include <rbf.h>
#ifdef _OS9000
#define environ _environ
#define mod_exec mh_com
extern int _os_fork();
#else
extern int os9forkc();
#endif
FILE *namefile;
char **files;
char *nextfile();
extern char *_prgname();
extern mod_exec *modlink(), *modloadp();
extern char *environ;
#define RCPROG "rcs"
#define RLPROG "rlog"
#define REVSTRLEN 20
char *rcsopt, *revstr, *nopt;
mod_exec *rcmp, *rlmp;
int stop;
void cleanup(err, cstr, a)
int err;
char *cstr, *a;
{
if (rcmp)
munlink(rcmp);
if (rlmp)
munlink(rlmp);
if (cstr)
exit(_errmsg(err, cstr, a));
else exit(err);
}
/*---------------------------------------------------------
! fork and wait a program
*/
int runprog(args, waitit)
char *args[];
{
int status;
#ifdef _OS9000
process_id pid;
if (errno = os9kexec(_os_fork, 0, 3, *args, args, environ,
0, &pid, mktypelang(MT_PROGRAM, ML_OBJECT), 0))
#else
int pid;
if ((pid = os9exec(os9forkc, *args, args, environ, 0, 0, 3)) == -1)
#endif
cleanup(errno, "can't fork \"%s\". ", *args);
if (waitit)
{
while (wait(&status) != pid)
;
return status;
}
else return 0;
}
/*---------------------------------------------------------
! process each file
*/
void process(file)
register char *file;
{
static char *rlargs[] = {RLPROG, "-b%h", NULL, NULL};
static char *rcargs[] = {RCPROG, NULL, NULL, NULL};
register char *p;
int savepn, n, skipthis = 0;
unsigned int status;
rlargs[2] = rcargs[2] = file;
rcargs[1] = rcsopt;
/* redirect STDOUT to pipe */
savepn = dup(1);
close(1);
errno = 0;
if (creat("/pipe", S_IREAD+S_IWRITE) != 1)
cleanup(errno, "can't redirect STDIN to pipe. ", NULL);
/* get top-of-trunk revision number */
runprog(rlargs, 0);
if ((n = readln(1, revstr, REVSTRLEN)) <= 0)
skipthis = _errmsg(1, "can't read %s's output; file \"%s\" skipped.\n");
wait(&status);
if (status)
skipthis = _errmsg(1, "%s exited with error; file \"%s\" skipped.\n");
/* restore redirected STDOUT */
close(1);
dup(savepn);
close(savepn);
if (!skipthis)
{
revstr[n] = '\0';
if (revstr[--n] == '\n')
revstr[n] = '\0';
fprintf(stderr, "%s: \"%s\" assigned to revision %s.\n", file, nopt+2, revstr);
runprog(rcargs, 1);
}
if (stop)
cleanup(stop, "Stopped by signal.\n", NULL);
}
mod_exec *mlinkload(mod)
char *mod;
{
mod_exec *mp;
if ((int)(mp = modlink(mod, mktypelang(MT_PROGRAM, ML_OBJECT))) == -1 &&
(int)(mp = modloadp(mod, S_IEXEC, NULL)) == -1 &&
(int)(mp = modloadp(mod, S_IREAD, NULL)) == -1)
cleanup(errno, "can't find \"%s\". ", mod);
}
void intcpt(sig)
{
stop = sig;
}
main(argc, argv)
int argc;
char *argv[];
{
register char *file;
register char *p, **fpp;
register int ch, waseq = 0;
long tfsize;
files = fpp = argv;
while (--argc)
{
if (*(p = *++argv) == '-')
{
++p;
while (ch = *p++)
{
waseq = *p == '=';
if (waseq)
++p;
switch (ch)
{
case 'n':
case 'N':
if (nopt)
exit(_errmsg(1, "only one symbolica label can be specified.\n"));
else if (waseq)
exit(_errmsg(1, "can't have '=' in -n/N options.\n"));
else if (!isalpha(*p))
exit(_errmsg(1, "illegal symbolic label \"%s\".\n", p));
nopt = p - 2;
break;
case 'z':
if (namefile)
exit(_errmsg(
1,"only one file of names allowed.\n"));
if (waseq)
{
if ((namefile = fopen(p,"r")) == NULL)
exit(_errmsg(errno,
"can't open \"%s\". ",p));
}
else
{
namefile = stdin;
continue;
}
break;
default:
prtuse(_errmsg(1,"unknown option '%c'.\n\n",ch));
case '?':
prtuse(0);
}
break;
}
}
else *fpp++ = p;
}
*fpp = NULL;
if (fpp == files && namefile == NULL)
exit(_errmsg(1, "no files.\n"));
else if (!nopt)
exit(_errmsg(1, "no symbolic label.\n"));
else if (!(rcsopt = malloc(strlen(nopt) + REVSTRLEN + 5)))
exit(_errmsg(errno, "can't allocate string buffer. "));
sprintf(rcsopt, "%s:", nopt);
revstr = rcsopt + strlen(rcsopt);
rcmp = mlinkload(RCPROG);
rlmp = mlinkload(RLPROG);
while (file = nextfile())
process(file);
cleanup(0, NULL, NULL);
}
/**--------------------------------------------------------------*/
char *nextfile()
{
register char *file = NULL;
static char nambuf[120];
if (file = *files)
++files;
else if (namefile)
{
if ((file = fgets(nambuf,sizeof nambuf,namefile)) == NULL)
{
if (ferror(namefile))
exit(_errmsg(errno,"can't read name file.\n"));
fclose(namefile);
namefile = NULL;
}
else *(file + strlen(file) - 1) = '\0';
}
return file;
}
/**--------------------------------------------------------------
! cmds[] - array of pointers to strings of help text
!*/
static char *cmds[] = {
"Function: put symbolic lable at top of RCS trunk\n",
"Options:\n",
" -n=<lable> specify symbolic label\n",
" -N=<lable> specify symbolic label (overwrite current)\n",
" -z[=<file>] read list of files from standard input or <file>\n"
};
/**--------------------------------------------------------------
! printuse - print the help text to standard error.
!*/
static prtuse(stat)
int stat;
{
register char **p = cmds,
**e = cmds + sizeof cmds / sizeof (char *);
fprintf(stderr,"Syntax: %s {<opts>} [<file>] {<opts>}\n", _prgname());
while (p < e)
fputs(*p++,stderr);
exit(stat);
}