Annotation of cci/usr/src/bin/cdb/main.c, revision 1.1

1.1     ! root        1: extern long    times_ndx;
        !             2: static char *sccs = "@(#)main.c        2.11";
        !             3: static char *vsbCopyright = "CDB Copyright c 1983 by Third Eye Software";
        !             4: #include <signal.h>
        !             5: #include <setjmp.h>
        !             6: #include <stdio.h>
        !             7: #define SYSTYPES 1
        !             8: #include "cdb.h"
        !             9: 
        !            10: export int     *venv;  /* This may not be portable - it SHOULD be, but ... */
        !            11: export char    **venvpParent;
        !            12: jmp_buf        venvFixer;   /* for error recovery */
        !            13: extern FILE *vfpPlayback;
        !            14: 
        !            15: void   Fixer();
        !            16: 
        !            17: /* M A I N */
        !            18: 
        !            19: export void main(argc, argv, envp)
        !            20: int    argc;
        !            21: char   *argv[];
        !            22: char   *envp[];
        !            23: {
        !            24:        int             cMainArgs, i;
        !            25:        FLAGT   fUsedArg;
        !            26:        char    *sbArg, *sbT, *sbUsage, *sbPlayback, *sbRecord;
        !            27: 
        !            28:        venv = venvFixer;
        !            29:        if (setjmp(venvFixer)) {
        !            30:                /* in case we hit an error during initialization */
        !            31:                printf("Cannot continue\n");
        !            32:                exit(1);
        !            33:        } /* if */
        !            34: 
        !            35:        venvpParent = envp;
        !            36:        sbPlayback = sbNil;
        !            37:        sbRecord = sbNil;
        !            38:        switch (**argv) {
        !            39:        default:
        !            40:        case 'c':       
        !            41:                vlc = lcC;      
        !            42:                break;
        !            43:        case 'p':       
        !            44:                vlc = lcPascal; 
        !            45:                break;
        !            46:        case 'f':       
        !            47:                vlc = lcFortran;        
        !            48:                break;
        !            49:        } /* switch */
        !            50: #ifdef BSD41
        !            51:        vcbSbCache = 0; /* unless set, this causes total read of strings */
        !            52: #endif
        !            53:        vilvMax = 26;   /* `local' variables */
        !            54:        vibpMax = 16;   /* break points */
        !            55:        viadMax = 16;   /* assertions */
        !            56: 
        !            57:        vsbSymfile = "a.out";
        !            58:        vsbCorefile = sbNil;
        !            59:        sbUsage =
        !            60:            "Usage is `cdb [-d dir] [-r file] [-p file] [-a#] [-b#] [-s#] [objfile [corfile]]\n";
        !            61: 
        !            62: 
        !            63:        cMainArgs = 0;
        !            64:        for (i=1; i<argc; ++i) {
        !            65:                if (*(sbArg=argv[i]) != '-') {
        !            66:                        switch (cMainArgs) {
        !            67:                        case 0:
        !            68:                                vsbSymfile = sbArg;
        !            69:                                break;
        !            70:                        case 1:
        !            71:                                vsbCorefile = sbArg;
        !            72:                                break;
        !            73:                        default:
        !            74:                                printf(sbUsage);
        !            75:                                exit(1);
        !            76:                        } /* switch */
        !            77:                        cMainArgs++;
        !            78:                } 
        !            79:                else {
        !            80:                        sbArg++;        /* move past the '-' */
        !            81:                        /* point to a potential argument */
        !            82:                        sbT = (sbArg[1] != chNull) ? sbArg+1 : argv[i+1];
        !            83:                        fUsedArg = true; /* set FALSE if option does NOT use arg */
        !            84:                        switch (*sbArg) {
        !            85:                        default:
        !            86:                                printf(sbUsage);
        !            87:                                exit(1);
        !            88:                        case 'a':  /* assertions */
        !            89:                                viadMax = atoi(sbT);
        !            90:                                break;
        !            91:                        case 'b': /* breakpoints */
        !            92:                                /* we use up one for temp stuff */
        !            93:                                vibpMax = 1 + atoi(sbT);
        !            94:                                break;
        !            95:                        case 'd':       /* alternate directory */
        !            96:                                AddDir(sbT);
        !            97:                                break;
        !            98:                        case 'p':       /* playback file */
        !            99:                                sbPlayback = sbT;
        !           100:                                break;
        !           101:                        case 'r':       /* record file */
        !           102:                                sbRecord = sbT;
        !           103:                                break;
        !           104:                        case 's':       /* special variables */
        !           105:                                vilvMax = atoi(sbT);
        !           106:                                break;
        !           107:                        case 'S':       /* string space */
        !           108: #ifdef BSD41
        !           109:                                vcbSbCache = atoi(sbT);
        !           110: #else
        !           111:                                printf("The -S option is only meaningful on BSD 4.X systems\n");
        !           112:                                fUsedArg = false;
        !           113:                                exit(1);
        !           114: #endif
        !           115:                                break;
        !           116:                        } /* switch */
        !           117:                        if ((fUsedArg) AND (sbArg[1] == chNull))
        !           118:                                i++;    /* eat next word - it was the arg we used */
        !           119:                } /* if */
        !           120:        } /* for */
        !           121: 
        !           122:        InitAll();      /* calls all of the initialization routines */
        !           123: 
        !           124:        if (setjmp(venvFixer) == 0) {
        !           125:                if (sbRecord != sbNil)
        !           126:                        SetRecord(sbRecord);
        !           127:                if (sbPlayback != sbNil)
        !           128:                        SetPlayback(sbPlayback, false);
        !           129:                if (vfnCore != fnNil) {
        !           130:                        FDoCommand("L", true);  /* put them at error location */
        !           131:                } 
        !           132:                else {
        !           133:                        if (vfPascal) {
        !           134:                                FDoCommand("e program", true);  /* first line to execute */
        !           135:                        } 
        !           136:                        else {
        !           137:                                FDoCommand("e main", true);     /* first line to execute */
        !           138:                        }
        !           139:                }
        !           140:        } /* if */
        !           141: 
        !           142:        vivarMac = 0; /* stack pointers might be trashed by error (see expr.c) */
        !           143:        viopMac = 0;
        !           144:        vcNest = 0; /* nesting level for printing structure indents */
        !           145: 
        !           146:        InitSignals();  /* don't dump on the customers! */
        !           147: 
        !           148:        DebugIt(true);
        !           149: } /* main */
        !           150: 
        !           151: 
        !           152: /* D E B U G   I T */
        !           153: 
        !           154: local void DebugIt(fTopLevel)
        !           155: FLAGT  fTopLevel;
        !           156: {
        !           157:        int             i, cnt;
        !           158:        FLAGT   fRet;
        !           159: #define cbCmdMax       200
        !           160:        char    sbCmd[cbCmdMax];
        !           161: 
        !           162:        fRet = true;
        !           163:        while (fRet) {
        !           164:                cnt = 1;
        !           165:                NextCmd(sbCmd, cbCmdMax, ">");
        !           166:                if (*sbCmd == chNull) {
        !           167:                        printf("\010");  /* backspace gets rid of prompt character */
        !           168:                        cnt = 10;
        !           169:                        sbCmd[0] = '~';
        !           170:                        sbCmd[1] = chNull;
        !           171:                } /* if */
        !           172:                for (i=0; i < cnt AND fRet; i++) {
        !           173:                        RecordCmd(sbCmd);
        !           174:                        fRet = FDoCommand(sbCmd, fTopLevel);
        !           175:                } /* for */
        !           176:        } /* while */
        !           177: } /* DebugIt */
        !           178: 
        !           179: 
        !           180: /* O O P S */
        !           181: 
        !           182: export void Oops(sig)
        !           183: int    sig;
        !           184: {
        !           185:        printf("Sorry, Cdb has encountered a \"");
        !           186:        PrintSig(sig);
        !           187:        UError("\" error, try a different command");
        !           188: } /* Oops */
        !           189: 
        !           190: 
        !           191: /* I N I T   S I G N A L S */
        !           192: 
        !           193: local void InitSignals()
        !           194: {
        !           195:        signal(SIGINT, Fixer);
        !           196:        signal(SIGILL, Oops);
        !           197:        signal(SIGFPE, Oops);
        !           198:        signal(SIGBUS, Oops);
        !           199:        signal(SIGSEGV, Oops);
        !           200:        signal(SIGSYS, Oops);
        !           201:        signal(SIGPIPE, Oops);
        !           202: } /* InitSignals */
        !           203: 
        !           204: 
        !           205: /* F I X E R */
        !           206: 
        !           207: export void Fixer()
        !           208: {
        !           209:        printf("\ncdb\n");
        !           210:        if ((vfpPlayback != NULL)
        !           211:            AND (vcStepPlayback == 0))
        !           212:                vcStepPlayback = 1;     /* gives them a chance to regain control */
        !           213:        longjmp(venv, 1);
        !           214: } /* Fixer */
        !           215: 
        !           216: 
        !           217: /* P A N I C */
        !           218: 
        !           219: /* VARARGS1 */
        !           220: export void Panic(msg, arg1, arg2, arg3, arg4)
        !           221: char   *msg;
        !           222: int    arg1, arg2, arg3, arg4;
        !           223: {
        !           224:        int             err;
        !           225: 
        !           226:        err = errno;
        !           227:        printf("panic - ");
        !           228:        if (msg) {
        !           229:                printf(msg, arg1, arg2, arg3, arg4);
        !           230:        } /* if */
        !           231:        if (err != 0) {
        !           232:                printf("\nerrno may not be meaningful\n");
        !           233:                errno = err;
        !           234:                perror("cdb");
        !           235:        } /* if */
        !           236:        longjmp(venv, 1);
        !           237: } /* Panic */
        !           238: 
        !           239: 
        !           240: /* U   E R R O R */
        !           241: 
        !           242: /* VARARGS1 */
        !           243: export void UError(msg, arg1, arg2, arg3, arg4)
        !           244: char   *msg;
        !           245: int    arg1, arg2, arg3, arg4;
        !           246: {
        !           247:        if (msg) {
        !           248:                printf(msg, arg1, arg2, arg3, arg4);
        !           249:        } 
        !           250:        else {
        !           251:                printf("error");
        !           252:        } /* if */
        !           253:        printf("\n");
        !           254:        longjmp(venv, 1);
        !           255: } /* UError */
        !           256: 
        !           257: 
        !           258: /* The following routines exist in System III, but not BSD41 */
        !           259: 
        !           260: /* s t r c h r */
        !           261: 
        !           262: export char * strchr(sb, ch)
        !           263: char   *sb, ch;
        !           264: {
        !           265:        /* find first instance of ch in sb, return nil if not found */
        !           266:        while (*sb != chNull AND *sb != ch)
        !           267:                sb++;
        !           268:        return((*sb == chNull) ? sbNil : sb);
        !           269: } /* strchr */
        !           270: 
        !           271: 
        !           272: /* s t r r c h r */
        !           273: 
        !           274: export char * strrchr(sb, ch)
        !           275: char   *sb, ch;
        !           276: {
        !           277:        char    *sbBack;
        !           278: 
        !           279:        sbBack = sb + strlen(sb);
        !           280:        while (*sbBack != ch AND sbBack != sb)
        !           281:                sbBack--;
        !           282:        return((*sbBack == ch) ? sbBack : sbNil);
        !           283: } /* strrchr */
        !           284: 
        !           285: 
        !           286: /* s t r c s p n */
        !           287: 
        !           288: export int strcspn(sbSpan, sbNot)
        !           289: char   *sbSpan, *sbNot;
        !           290: {
        !           291:        int             cSpan;
        !           292:        char    *sbSave;
        !           293: 
        !           294:        /* return count of chars from start of sbSpan that do NOT occur in sbNot */
        !           295:        cSpan = 0;
        !           296:        sbSave = sbNot;
        !           297:        while (*sbSpan != chNull) {
        !           298:                while (*sbNot != chNull) {
        !           299:                        if (*sbNot == *sbSpan)
        !           300:                                return(cSpan);
        !           301:                        sbNot++;
        !           302:                } /* while */
        !           303:                sbSpan++;
        !           304:                cSpan++;
        !           305:                sbNot = sbSave;
        !           306:        } /* while */
        !           307:        return(cSpan);
        !           308: } /* strcspn */
        !           309: 
        !           310: #ifdef REGULUS
        !           311: /* i s x d i g i t */
        !           312: 
        !           313: int isxdigit(ch)
        !           314: char   ch;
        !           315: {
        !           316:        return(   (ch >= '0' AND ch <= '9')
        !           317:            OR (ch >= 'a' AND ch <= 'f')
        !           318:            OR (ch >= 'A' AND ch <= 'F'));
        !           319: } /* isxdigit */
        !           320: 
        !           321: 
        !           322: /* a b s */
        !           323: 
        !           324: int abs(x)
        !           325: int    x;
        !           326: {
        !           327:        return((x < 0) ? -x : x);
        !           328: } /* abs */
        !           329: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.