Annotation of researchv10no/cmd/trace/trace2.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include <errno.h>
        !             3: #include "trace.h"
        !             4: #include "trace.d"
        !             5: 
        !             6:  extern struct TBL       *tbl;
        !             7:  extern struct LBT      *lbt;
        !             8:  extern struct MBOX      *mbox;
        !             9:  extern struct MNAME     *fullname;
        !            10:  extern struct REVPOL    **expr;
        !            11:  extern struct PROCSTACK **procstack;
        !            12: 
        !            13:  extern struct VARPARS  *procpars;
        !            14:  extern struct TBLPARS  *tblpars;
        !            15: 
        !            16:  extern struct LOCVARS   *tblvars;
        !            17:  extern struct TBLPARS  *tablpars;
        !            18: 
        !            19:  extern int *reftasks, *processes, *basics;
        !            20:  extern int *globvars, *inits, *xob, *effnrstates;
        !            21: 
        !            22:  extern char qoverride;
        !            23:  extern int QMAX, msgbase, maxcol, assertbl, errortbl;
        !            24: 
        !            25: #define tell(s)        fprintf(stderr, s)
        !            26: 
        !            27: usage(str)
        !            28:        char *str;
        !            29: {      fprintf(stderr, "trace: %s\n", str);
        !            30:        tell("usage: trace [-?] [N]\n");
        !            31:        tell("\t-a show all prefixes leading into old states\n");
        !            32:        tell("\t-b `blast mode' (quick, very partial search)\n");
        !            33:        tell("\t-c  N  perform class N validation (N: 0..5) \n");
        !            34:        tell("\t-f or -F alternative formats for printing queue histories\n");
        !            35:        tell("\t-j stop at the first buffer lock found\n");
        !            36:        tell("\t-k  N  restrict the state space cache to N thousand states\n");
        !            37:        tell("\t-l show normal execution sequences and loops, but no prefixes\n");
        !            38:        tell("\t-m  N  restrict search depth to N steps\n");
        !            39:        tell("\t-n don't use timeout heuristics\n");
        !            40:        tell("\t-q  N  set bound N on maximum queue size used\n");
        !            41:        tell("\t-r  N  restrict the runtime to  N minutes\n");
        !            42:        tell("\t-R  N  report on progress every N minutes\n");
        !            43:        tell("\t-s show the transition tables (different if combined with `v')\n");
        !            44:        tell("\t-v verbose - print execution times, etc.\n");
        !            45:        tell("\t-x perform a scatter search\n");
        !            46:        tell("\tno flag: try a sensible partial search\n");
        !            47:        exit(1);
        !            48: }
        !            49: 
        !            50: /*
        !            51:  * calls on Emalloc and Realloc go straight to the library malloc
        !            52:  * it is used for data that may be realloced but is never released
        !            53:  * - Smalloc claims memory that is never realloced and never released
        !            54:  * - emalloc and efree handle memory that is never realloced but often released
        !            55:  * - talloc and tfree are direct calls on the tac-package (used via emalloc)
        !            56:  */
        !            57: 
        !            58: char *
        !            59: Stake(n)
        !            60: { char *try, *sbrk(), *Emalloc();
        !            61:   extern int errno;
        !            62: 
        !            63:        do {
        !            64:                try = sbrk(n);
        !            65:        } while ((int) try == -1 && errno == EINTR);
        !            66: 
        !            67:        if ((int) try == -1)
        !            68:                return Emalloc(n);      /* maybe some mem left here */
        !            69: 
        !            70:        return try;
        !            71: }
        !            72: 
        !            73: #define CHUNK  4096
        !            74: 
        !            75: char *have;
        !            76: long left = 0;
        !            77: 
        !            78: char *
        !            79: Smalloc(n)
        !            80:        unsigned n;
        !            81: { char *try;
        !            82: 
        !            83:        if (n == 0)
        !            84:                return (char *) NULL;
        !            85:        if (left < n)
        !            86:        {       unsigned grow = (n < CHUNK) ? CHUNK : n;
        !            87:                have = Stake(grow);
        !            88:                left = grow;
        !            89:        }
        !            90:        try = have;
        !            91:        have += n;
        !            92:        left -= n;
        !            93: 
        !            94:        return try;
        !            95: }
        !            96: 
        !            97: char *
        !            98: Emalloc(n)
        !            99:        unsigned n;
        !           100: { char *try, *malloc();
        !           101: 
        !           102:        if (n == 0)
        !           103:                return (char *) NULL;
        !           104:        if ((try = malloc(n)) == NULL)
        !           105:                whoops("malloc fault");
        !           106: 
        !           107:        return try;
        !           108: }
        !           109: 
        !           110: char *
        !           111: Realloc(a, b)
        !           112:        char *a; unsigned b;
        !           113: { char *try, *realloc();
        !           114: 
        !           115:        if (b == 0)
        !           116:                return (char *) NULL;
        !           117:        if ((try = realloc(a, b)) == NULL)
        !           118:                whoops("realloc returns 0");
        !           119: 
        !           120:        return try;
        !           121: }
        !           122: 
        !           123: char *
        !           124: emalloc(n)
        !           125:        unsigned n;
        !           126: { char *try;
        !           127:   char *talloc();
        !           128: 
        !           129:        if (n == 0)
        !           130:                return (char *) NULL;
        !           131:        if ((try = talloc(n)) == NULL)
        !           132:                whoops("talloc fault");
        !           133: 
        !           134:        return try;
        !           135: }
        !           136: 
        !           137: efree(at)
        !           138:        char *at;
        !           139: {
        !           140:        if (at) tfree(at);
        !           141: }
        !           142: 
        !           143: alloc1(x, y, z)
        !           144: { int n = x+y;
        !           145:        tbl      = (struct TBL *)
        !           146:                Smalloc(n * sizeof(struct TBL));
        !           147:        tblpars  = (struct TBLPARS *)
        !           148:                Smalloc(n * sizeof(struct TBLPARS));
        !           149:        tblvars  = (struct LOCVARS *)
        !           150:                Smalloc(n * sizeof(struct LOCVARS));
        !           151:        reftasks = (int *)
        !           152:                Smalloc(x * sizeof(int));
        !           153:        processes = (int *)
        !           154:                Smalloc(y * sizeof(int));
        !           155:        lbt       = (struct LBT *)
        !           156:                Smalloc(y * sizeof(struct LBT));
        !           157:        procpars  = (struct VARPARS *)
        !           158:                Smalloc(y * sizeof(struct VARPARS));
        !           159: 
        !           160:        tablpars  = (struct TBLPARS *)
        !           161:                Smalloc(y * sizeof(struct TBLPARS));
        !           162: 
        !           163:        basics    = (int *)
        !           164:                Smalloc(y * sizeof(int));
        !           165:        procstack = (struct PROCSTACK **)
        !           166:                Smalloc(y * sizeof(struct PROCSTACK *));
        !           167:        mbox      = (struct MBOX *)
        !           168:                Smalloc(z * sizeof(struct MBOX));
        !           169: 
        !           170:        effnrstates = (int *)
        !           171:                Smalloc(n * sizeof(int));
        !           172: }
        !           173: 
        !           174: alloc2(n, p, who)
        !           175: { char x;
        !           176: 
        !           177:        x = (qoverride && p > QMAX)? QMAX : p;
        !           178: 
        !           179:        if (x >= 256)
        !           180:                whoops("illegal queue size");
        !           181:        if (x >= 16)
        !           182:                fprintf(stderr, "warning, very large qsize (%d), queue %d\n", x, n);
        !           183: 
        !           184:        mbox[n].limit = x;
        !           185:        mbox[n].owner = (who >= 0) ? who : 0;
        !           186: }
        !           187: 
        !           188: alloc3(n)
        !           189: {      inits = (int *)
        !           190:                Smalloc(n * sizeof(int));
        !           191: }
        !           192: 
        !           193: alloc4(n)
        !           194: {      if (assertbl == NONE && errortbl == NONE)
        !           195:                globvars = (int *)
        !           196:                        Smalloc(n * sizeof(int));
        !           197:        else
        !           198:                globvars = (int *)
        !           199:                        Emalloc(n * sizeof(int));
        !           200: }
        !           201: 
        !           202: alloc45(n)
        !           203: { register int i;
        !           204:        fullname = (struct MNAME *)
        !           205:                Smalloc(n * sizeof(struct MNAME));
        !           206:        xob = (int *)
        !           207:                Smalloc((n+msgbase) * sizeof(int));
        !           208:        for (i = 0; i < n+msgbase; i++)
        !           209:                xob[i] = -1;
        !           210: }
        !           211: 
        !           212: alloc5(n)
        !           213: { register int i, j, r, c;
        !           214: 
        !           215:        r = tbl[n].nrrows;
        !           216:        if ((c = tbl[n].nrcols) > maxcol)
        !           217:                maxcol = c;
        !           218: 
        !           219:        tbl[n].endrow  = (int *) Smalloc(r * sizeof(int));
        !           220:        tbl[n].deadrow = (int *) Smalloc(r * sizeof(int));
        !           221:        tbl[n].badrow  = (int *) Smalloc(r * sizeof(int));
        !           222:        tbl[n].labrow  = (int *) Smalloc(r * sizeof(int));
        !           223:        tbl[n].colmap  = (int *) Smalloc(c * sizeof(int));
        !           224:        tbl[n].colorg  = (int *) Smalloc(c * sizeof(int));
        !           225:        tbl[n].coltyp  = (int *) Smalloc(c * sizeof(int));
        !           226:        tbl[n].ptr     = (struct IND **) Smalloc(r * sizeof(struct IND *));
        !           227:        tbl[n].rowname = (char **) Smalloc(r * sizeof(char *));
        !           228: 
        !           229:        for (i = 0; i < r; i++)
        !           230:        {       tbl[n].ptr[i] = (struct IND *)
        !           231:                        Smalloc(c * sizeof(struct IND));
        !           232:                tbl[n].rowname[i] = (char *)
        !           233:                        Smalloc(128 * sizeof(char));
        !           234: 
        !           235:                for (j = 0; j < c; j++)
        !           236:                        tbl[n].ptr[i][j].nrpils = 0;
        !           237:                tbl[n].deadrow[i] = 1;
        !           238:                tbl[n].endrow[i] = tbl[n].badrow[i] = 0;
        !           239:                tbl[n].labrow[i] = 0;
        !           240:        }
        !           241:        tbl[n].labrow[0] = 1;   /* make sure initial state is always checked */
        !           242: }
        !           243: 
        !           244: alloc6(n, m, p, q)
        !           245: {      tbl[n].ptr[m][p].one = (struct ELM *)
        !           246:                Smalloc(q * sizeof(struct ELM));
        !           247: }
        !           248: 
        !           249: alloc8(pr, p, q)
        !           250: {
        !           251:        tablpars[pr].nrms = (short) p;                  /* available */
        !           252:        tablpars[pr].nrvs = (short) q;
        !           253: 
        !           254:        procpars[pr].ms = (short *)
        !           255:                Emalloc(p * sizeof(short));
        !           256:        procpars[pr].vs = (short *)
        !           257:                Emalloc(q * sizeof(short));
        !           258: 
        !           259:        procpars[pr].nrms = 0;                          /* actually used */
        !           260:        procpars[pr].nrvs = 0;
        !           261: }
        !           262: 
        !           263: alloc9(in, p)
        !           264: {
        !           265:        tbl[in].calls = (struct CPARS *)
        !           266:                Smalloc(p * sizeof(struct CPARS));
        !           267: }
        !           268: 
        !           269: alloc10(in, cn, p, q, r)
        !           270: {
        !           271:        tbl[in].calls[cn].callwhat = (short) p;
        !           272:        tbl[in].calls[cn].nrms = (short) q;
        !           273:        tbl[in].calls[cn].nrvs = (short) r;
        !           274: 
        !           275:        tbl[in].calls[cn].ms = (short *)
        !           276:                        Smalloc(q * sizeof (short));
        !           277: 
        !           278:        tbl[in].calls[cn].vs = (short *)
        !           279:                        Smalloc(r * sizeof (short));
        !           280: }
        !           281: 
        !           282: whoops(s)
        !           283:        char *s;
        !           284: {
        !           285:        fprintf(stderr, "trace: %s\n", s);
        !           286:        postlude();
        !           287:        exit(1);
        !           288: }
        !           289: 
        !           290: badinput(s)
        !           291:        char *s;
        !           292: {      extern char fname[];
        !           293: 
        !           294:        fflush(stdout);
        !           295:        fprintf(stderr, "trace: read error `%s': %s\n", s, fname);
        !           296:        exit(1);
        !           297: }

unix.superglobalmegacorp.com

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