|
|
Power 6/32 Unix version 1.2b
extern long times_ndx;
static char *sccs = "@(#)main.c 2.11";
static char *vsbCopyright = "CDB Copyright c 1983 by Third Eye Software";
#include <signal.h>
#include <setjmp.h>
#include <stdio.h>
#define SYSTYPES 1
#include "cdb.h"
export int *venv; /* This may not be portable - it SHOULD be, but ... */
export char **venvpParent;
jmp_buf venvFixer; /* for error recovery */
extern FILE *vfpPlayback;
void Fixer();
/* M A I N */
export void main(argc, argv, envp)
int argc;
char *argv[];
char *envp[];
{
int cMainArgs, i;
FLAGT fUsedArg;
char *sbArg, *sbT, *sbUsage, *sbPlayback, *sbRecord;
venv = venvFixer;
if (setjmp(venvFixer)) {
/* in case we hit an error during initialization */
printf("Cannot continue\n");
exit(1);
} /* if */
venvpParent = envp;
sbPlayback = sbNil;
sbRecord = sbNil;
switch (**argv) {
default:
case 'c':
vlc = lcC;
break;
case 'p':
vlc = lcPascal;
break;
case 'f':
vlc = lcFortran;
break;
} /* switch */
#ifdef BSD41
vcbSbCache = 0; /* unless set, this causes total read of strings */
#endif
vilvMax = 26; /* `local' variables */
vibpMax = 16; /* break points */
viadMax = 16; /* assertions */
vsbSymfile = "a.out";
vsbCorefile = sbNil;
sbUsage =
"Usage is `cdb [-d dir] [-r file] [-p file] [-a#] [-b#] [-s#] [objfile [corfile]]\n";
cMainArgs = 0;
for (i=1; i<argc; ++i) {
if (*(sbArg=argv[i]) != '-') {
switch (cMainArgs) {
case 0:
vsbSymfile = sbArg;
break;
case 1:
vsbCorefile = sbArg;
break;
default:
printf(sbUsage);
exit(1);
} /* switch */
cMainArgs++;
}
else {
sbArg++; /* move past the '-' */
/* point to a potential argument */
sbT = (sbArg[1] != chNull) ? sbArg+1 : argv[i+1];
fUsedArg = true; /* set FALSE if option does NOT use arg */
switch (*sbArg) {
default:
printf(sbUsage);
exit(1);
case 'a': /* assertions */
viadMax = atoi(sbT);
break;
case 'b': /* breakpoints */
/* we use up one for temp stuff */
vibpMax = 1 + atoi(sbT);
break;
case 'd': /* alternate directory */
AddDir(sbT);
break;
case 'p': /* playback file */
sbPlayback = sbT;
break;
case 'r': /* record file */
sbRecord = sbT;
break;
case 's': /* special variables */
vilvMax = atoi(sbT);
break;
case 'S': /* string space */
#ifdef BSD41
vcbSbCache = atoi(sbT);
#else
printf("The -S option is only meaningful on BSD 4.X systems\n");
fUsedArg = false;
exit(1);
#endif
break;
} /* switch */
if ((fUsedArg) AND (sbArg[1] == chNull))
i++; /* eat next word - it was the arg we used */
} /* if */
} /* for */
InitAll(); /* calls all of the initialization routines */
if (setjmp(venvFixer) == 0) {
if (sbRecord != sbNil)
SetRecord(sbRecord);
if (sbPlayback != sbNil)
SetPlayback(sbPlayback, false);
if (vfnCore != fnNil) {
FDoCommand("L", true); /* put them at error location */
}
else {
if (vfPascal) {
FDoCommand("e program", true); /* first line to execute */
}
else {
FDoCommand("e main", true); /* first line to execute */
}
}
} /* if */
vivarMac = 0; /* stack pointers might be trashed by error (see expr.c) */
viopMac = 0;
vcNest = 0; /* nesting level for printing structure indents */
InitSignals(); /* don't dump on the customers! */
DebugIt(true);
} /* main */
/* D E B U G I T */
local void DebugIt(fTopLevel)
FLAGT fTopLevel;
{
int i, cnt;
FLAGT fRet;
#define cbCmdMax 200
char sbCmd[cbCmdMax];
fRet = true;
while (fRet) {
cnt = 1;
NextCmd(sbCmd, cbCmdMax, ">");
if (*sbCmd == chNull) {
printf("\010"); /* backspace gets rid of prompt character */
cnt = 10;
sbCmd[0] = '~';
sbCmd[1] = chNull;
} /* if */
for (i=0; i < cnt AND fRet; i++) {
RecordCmd(sbCmd);
fRet = FDoCommand(sbCmd, fTopLevel);
} /* for */
} /* while */
} /* DebugIt */
/* O O P S */
export void Oops(sig)
int sig;
{
printf("Sorry, Cdb has encountered a \"");
PrintSig(sig);
UError("\" error, try a different command");
} /* Oops */
/* I N I T S I G N A L S */
local void InitSignals()
{
signal(SIGINT, Fixer);
signal(SIGILL, Oops);
signal(SIGFPE, Oops);
signal(SIGBUS, Oops);
signal(SIGSEGV, Oops);
signal(SIGSYS, Oops);
signal(SIGPIPE, Oops);
} /* InitSignals */
/* F I X E R */
export void Fixer()
{
printf("\ncdb\n");
if ((vfpPlayback != NULL)
AND (vcStepPlayback == 0))
vcStepPlayback = 1; /* gives them a chance to regain control */
longjmp(venv, 1);
} /* Fixer */
/* P A N I C */
/* VARARGS1 */
export void Panic(msg, arg1, arg2, arg3, arg4)
char *msg;
int arg1, arg2, arg3, arg4;
{
int err;
err = errno;
printf("panic - ");
if (msg) {
printf(msg, arg1, arg2, arg3, arg4);
} /* if */
if (err != 0) {
printf("\nerrno may not be meaningful\n");
errno = err;
perror("cdb");
} /* if */
longjmp(venv, 1);
} /* Panic */
/* U E R R O R */
/* VARARGS1 */
export void UError(msg, arg1, arg2, arg3, arg4)
char *msg;
int arg1, arg2, arg3, arg4;
{
if (msg) {
printf(msg, arg1, arg2, arg3, arg4);
}
else {
printf("error");
} /* if */
printf("\n");
longjmp(venv, 1);
} /* UError */
/* The following routines exist in System III, but not BSD41 */
/* s t r c h r */
export char * strchr(sb, ch)
char *sb, ch;
{
/* find first instance of ch in sb, return nil if not found */
while (*sb != chNull AND *sb != ch)
sb++;
return((*sb == chNull) ? sbNil : sb);
} /* strchr */
/* s t r r c h r */
export char * strrchr(sb, ch)
char *sb, ch;
{
char *sbBack;
sbBack = sb + strlen(sb);
while (*sbBack != ch AND sbBack != sb)
sbBack--;
return((*sbBack == ch) ? sbBack : sbNil);
} /* strrchr */
/* s t r c s p n */
export int strcspn(sbSpan, sbNot)
char *sbSpan, *sbNot;
{
int cSpan;
char *sbSave;
/* return count of chars from start of sbSpan that do NOT occur in sbNot */
cSpan = 0;
sbSave = sbNot;
while (*sbSpan != chNull) {
while (*sbNot != chNull) {
if (*sbNot == *sbSpan)
return(cSpan);
sbNot++;
} /* while */
sbSpan++;
cSpan++;
sbNot = sbSave;
} /* while */
return(cSpan);
} /* strcspn */
#ifdef REGULUS
/* i s x d i g i t */
int isxdigit(ch)
char ch;
{
return( (ch >= '0' AND ch <= '9')
OR (ch >= 'a' AND ch <= 'f')
OR (ch >= 'A' AND ch <= 'F'));
} /* isxdigit */
/* a b s */
int abs(x)
int x;
{
return((x < 0) ? -x : x);
} /* abs */
#endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.