Annotation of researchv10no/cmd/pret/pret6.c, revision 1.1

1.1     ! root        1: #include <stdio.h>
        !             2: #include "pret.h"
        !             3: 
        !             4: struct {
        !             5:        char name[MAXNAME];
        !             6:        char mbox;
        !             7:        char status;
        !             8:        int  qind;              /* index!=NONE if q addressed is array */
        !             9:        int  equa;              /* basename match */
        !            10:        int  code;
        !            11: } mesgtable[MANY];
        !            12: 
        !            13: struct QTABLE qtable[NQUEUES];
        !            14: 
        !            15: int msize[NQUEUES];            /* mailbox sizes per queue */
        !            16: 
        !            17: int msgval = BASEVAL;
        !            18: int nrmesgs = 0;
        !            19: int nrqs = 0;
        !            20: 
        !            21: int initable[MANY];
        !            22: int nrinits = 0;               /* number initial messages */
        !            23: 
        !            24: extern anyerror, pid, rid;
        !            25: 
        !            26: newqname(str, mask, lim, qind)
        !            27:        char *str;
        !            28: {
        !            29:        register int i;
        !            30: 
        !            31:        if (rid != NONE)
        !            32:        {       if ((i = Fparname(str, rid, ISQ, NONE, mask, qind)) != -1)
        !            33:                        return (MANY + i);      /* id of qset + offset */
        !            34:        }
        !            35:        for (i = 0; i < nrqs; i++)
        !            36:                if (strcmp(str, qtable[i].name) == 0)
        !            37:                        break;
        !            38:        if (i == nrqs)
        !            39:        {       if (nrqs >= NQUEUES)
        !            40:                        whoops("too many queues");
        !            41: 
        !            42:                qtable[i].owner = (mask == DCL || mask == RFR) ? pid : NONE;
        !            43:                qtable[i].limit  = (lim == NONE) ? 2 : lim;
        !            44:                qtable[i].status = mask;
        !            45:                qtable[i].magic  = 0;
        !            46:                qtable[i].multiple  = qind;
        !            47:                strcpy(qtable[nrqs++].name, str);
        !            48:        } else
        !            49:        {       if (mask == DCL)
        !            50:                {       if (qtable[i].status & DCL)
        !            51:                                yyerror("queue redeclared, %s", str);
        !            52: 
        !            53:                        if (qtable[i].owner == NONE)
        !            54:                                qtable[i].owner = pid;
        !            55:                        else if (qtable[i].owner != pid && pid != NONE)
        !            56:                                warning("queue read by 2 processes", str);
        !            57:                        qtable[i].limit = lim;
        !            58:                        qtable[i].multiple = qind;
        !            59:                } else if (mask & RFR)
        !            60:                {       if (qtable[i].owner == NONE)
        !            61:                                qtable[i].owner = pid;
        !            62: 
        !            63:                        else if (qtable[i].owner != pid)
        !            64:                                warning("queue read by 2 processes", str);
        !            65:                }
        !            66:                if ((mask & RFR) || (mask & ADR))
        !            67:                {       if (qind != qtable[i].multiple
        !            68:                        &&  (qind == NONE || qtable[i].multiple == NONE))
        !            69:                                yyerror("queue indexing error, mesg name, %s", str);
        !            70:                }
        !            71:                qtable[i].status |= mask;
        !            72:        }
        !            73:        return i;
        !            74: }
        !            75: 
        !            76: addmsg(what, hit, mask, tpp, qind)
        !            77:        char *what; char mask;
        !            78: { register int i, j;
        !            79:   char str[MAXNAME];
        !            80: 
        !            81:        if (rid != NONE)
        !            82:        {       if ((i = Fparname(what, rid, ISM, hit - MANY, mask, qind)) != -1)
        !            83:                        return (MANY + i);
        !            84:                if (hit >= MANY)
        !            85:                {       yyerror("undeclared message, %s", what);
        !            86:                        return -1;
        !            87:        }       }
        !            88: 
        !            89:        strcpy(str, qtable[hit].name);
        !            90:        strcat(str, ":"); strcat(str, what);
        !            91: 
        !            92:        for (j = 0; j < nrmesgs; j++)
        !            93:        {       if (strcmp(str, mesgtable[j].name) == 0)
        !            94:                        break;
        !            95:        }
        !            96:        for (i = j; i < nrmesgs; i++)
        !            97:                if (strcmp(str, mesgtable[i].name) == 0
        !            98:                &&  mesgtable[i].qind == qind)
        !            99:                        break;
        !           100:        if (i == nrmesgs)
        !           101:        {       if (nrmesgs >= MANY)
        !           102:                        whoops("too many messages");
        !           103:                if (qtable[hit].multiple != qind
        !           104:                &&  (qind == NONE || qtable[hit].multiple == NONE))
        !           105:                        yyerror("Queue indexing error, qname, %s", str);
        !           106: 
        !           107:                mesgtable[i].mbox = hit;
        !           108:                mesgtable[i].qind = qind;
        !           109:                mesgtable[i].status = mask;
        !           110:                strcpy(mesgtable[nrmesgs++].name, str);
        !           111:                mesgtable[i].code = msgval++;
        !           112:                mesgtable[i].equa = mesgtable[j].code;
        !           113:        } else
        !           114:                mesgtable[i].status |= mask;
        !           115: 
        !           116:        if (tpp == INITM)
        !           117:                initable[nrinits++] = mesgtable[i].code;
        !           118: 
        !           119:        if (strcmp(what, " any") == 0 && mask == SAR)
        !           120:                qtable[hit].magic = 1;
        !           121: 
        !           122:        return mesgtable[i].code;
        !           123: }
        !           124: 
        !           125: isoqs()
        !           126: { int i;
        !           127:        for (i = 0; i < nrqs; i++)
        !           128:        {       if (!(qtable[i].status & DCL))
        !           129:                printf("warning: queue `%s' undeclared\n", qtable[i].name);
        !           130:                if (qtable[i].owner == NONE)
        !           131:                printf("warning: queue `%s' unknown owner\n", qtable[i].name);
        !           132:                switch (qtable[i].status) {
        !           133:                case 0:         /* used to check name existence in qsets */
        !           134:                case DCL:       printf("%s: isolated queue\n", qtable[i].name);
        !           135:                                break;
        !           136:                case DCL+RFR:   printf("%s: queue not addressed\n", qtable[i].name);
        !           137:                                break;
        !           138:                case DCL+ADR:   printf("%s: queue is never read\n", qtable[i].name);
        !           139:                default:        break;
        !           140:                }
        !           141:        }
        !           142: }
        !           143: 
        !           144: silentcheck()
        !           145: { int i, j, k, p;
        !           146:        for (i = 0; i < nrqs; i++)
        !           147:        {       if (msize[i] == 0)
        !           148:                        continue;
        !           149:                k = strlen(qtable[i].name) + 1;
        !           150:                for (j = 0; j < nrmesgs; j++)
        !           151:                if (mesgtable[j].mbox == i && (p = mesgtable[j].status) != SAR)
        !           152:                {       switch (p) {
        !           153:                        case RCV: if (qtable[i].multiple) break;
        !           154:                                  printf("queue %s: ", qtable[i].name);
        !           155:                                  printf("mesg '%s' ", &mesgtable[j].name[k]);
        !           156:                                  printf("is received but not sent\n");
        !           157:                                  anyerror++;
        !           158:                                  break;
        !           159:                        case SND: if (qtable[i].magic != 0
        !           160:                                  ||  qtable[i].multiple
        !           161:                                  ||  strcmp(&mesgtable[j].name[k], " any") == 0)
        !           162:                                        break;
        !           163:                                  printf("queue %s: ", qtable[i].name);
        !           164:                                  printf("mesg '%s' ", &mesgtable[j].name[k]);
        !           165:                                  printf("is sent but not received\n");
        !           166:                                  anyerror++;
        !           167:                                  break;
        !           168:                        case 0:   printf("queue %s: ", qtable[i].name);
        !           169:                                  printf("mesg '%s' ", &mesgtable[j].name[k]);
        !           170:                                  printf("is never used\n");
        !           171:                                  break;
        !           172:                        }
        !           173:        }       }       
        !           174: }
        !           175: 
        !           176: checkqs()
        !           177: {      isoqs();
        !           178:        silentcheck();
        !           179: }
        !           180: 
        !           181: numsorts(fd)
        !           182:        FILE *fd;
        !           183: { int i, j;
        !           184: 
        !           185:        for (i = j = 0; i < nrqs; i++)
        !           186:        {       if (qtable[i].multiple == NONE)
        !           187:                        j++;
        !           188:                else
        !           189:                        j += qtable[i].multiple;
        !           190:        }
        !           191:        fprintf(fd, "%d queues:\n", j);
        !           192:        numesgs(fd);
        !           193:        for (i = 0; i < nrqs; i++)
        !           194:        {       fprintf(fd, "%s\t%d/",
        !           195:                                qtable[i].name, qtable[i].owner);
        !           196:                fprintf(fd, "%d/%d/%d: ",
        !           197:                                qtable[i].limit, msize[i], qtable[i].multiple);
        !           198:                for (j = 0; j < nrmesgs; j++)
        !           199:                        if (mesgtable[j].mbox == i)
        !           200:                                fprintf(fd, "%d[%d,%d],", mesgtable[j].code,
        !           201:                                        mesgtable[j].qind,
        !           202:                                        mesgtable[j].equa);
        !           203:                putc('\n', fd);
        !           204: }      }
        !           205: 
        !           206: numinits(fd)
        !           207:        FILE *fd;
        !           208: { int i;
        !           209:        fprintf(fd, "%d inits:\n", nrinits);
        !           210:        for (i = 0; i < nrinits; i++)
        !           211:                fprintf(fd, "%d,", initable[i]);
        !           212:        if (nrinits > 0)
        !           213:                putc('\n', fd);
        !           214: }
        !           215: 
        !           216: numesgs(fd)
        !           217:        FILE *fd;
        !           218: { int i, j;
        !           219:   char c;
        !           220: 
        !           221:        fprintf(fd, "%d messages, base %d:\n", nrmesgs, BASEVAL);
        !           222:        for (i = 0; i < nrmesgs; i++)
        !           223:        {       for (j = 0; (c = mesgtable[i].name[j]) != '\0'; j++)
        !           224:                        if (c == ':')
        !           225:                        {       j++;
        !           226:                                break;
        !           227:                        }
        !           228:                if (c == '\0')
        !           229:                        j = 0;
        !           230: 
        !           231:                fprintf(fd, "%s ", &mesgtable[i].name[j]);
        !           232:        }
        !           233:        if (nrmesgs > 0)
        !           234:                putc('\n', fd);
        !           235: }
        !           236: 
        !           237: prepsorts()
        !           238: { int i, j;
        !           239:        for (i = 0; i < nrqs; i++)
        !           240:        {       msize[i] = 0;
        !           241:                for (j = 0; j < nrmesgs; j++)
        !           242:                        if (mesgtable[j].mbox == i)
        !           243:                                msize[i]++;
        !           244:        }
        !           245: }
        !           246: 
        !           247: listqs()
        !           248: {      int i, j, k, l, a;
        !           249: 
        !           250:        for (i = 0; i < nrqs; i++)
        !           251:        {
        !           252:                if (qtable[i].status & DCL == 0)        /* formal q-parameter */
        !           253:                        continue;
        !           254: 
        !           255:                printf("\t%2d\t%s", i+1, qtable[i].name);
        !           256:                k = strlen(qtable[i].name) + 1;
        !           257:                if (qtable[i].multiple != NONE)
        !           258:                {       printf("[%d], ", qtable[i].multiple);
        !           259:                        a = (qtable[i].multiple>9)?4:3;
        !           260:                } else
        !           261:                {       printf(", ");
        !           262:                        a = 0;
        !           263:                }
        !           264:                for (j = 10; j > k+a; j--) putchar(' ');
        !           265:                printf("sort: ");
        !           266: 
        !           267:                for (j = l = 0; j < nrmesgs; j++)
        !           268:                if (mesgtable[j].mbox == i &&
        !           269:                        strcmp(&mesgtable[j].name[k], " tau") != 0 &&
        !           270:                        strcmp(&mesgtable[j].name[k], " any") != 0)
        !           271:                {       if (l++ > 0)
        !           272:                                printf(", ");
        !           273:                        printf("%s", &mesgtable[j].name[k]);
        !           274:                        if ((a = mesgtable[j].qind) != NONE)
        !           275:                        {       if (a < -1)
        !           276:                                        printf("/*%d", -(a+2));
        !           277:                                else
        !           278:                                        printf("/%d", a);
        !           279:                }       }
        !           280:                printf("\n");
        !           281:        }
        !           282: }

unix.superglobalmegacorp.com

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