Annotation of researchv10no/cmd/cflow/lpfx.c, revision 1.1.1.1

1.1       root        1: /*     @(#)lpfx.c      1.5     83/08/05        */
                      2: #include <stdio.h>
                      3: #include <ctype.h>
                      4: /*#include "lerror.h"*/
                      5: #include "manifest"
                      6: #define        FMTARGS
                      7: #include "lint.h"
                      8: /*#include "lmanifest"*/
                      9: /*#include "lpass2.h"*/
                     10: #define FNSIZE LFNM
                     11: #define NSIZE LCHNM
                     12: #define LDS 0
                     13: char *tstrbuf[1];
                     14: 
                     15: typedef struct {
                     16:        union rec r;
                     17: #ifdef FLEXNAMES
                     18:        char *fname;
                     19: #else
                     20:        char fname[FNSIZE + 1];
                     21: #endif
                     22:        } funct;
                     23: 
                     24: typedef struct LI {
                     25:        struct LI *next;
                     26:        funct fun;
                     27:        } li;
                     28: 
                     29: /*
                     30:  * lpfx - read lint1 output, sort and format for dag
                     31:  *
                     32:  *     options -i_ -ix (inclusion)
                     33:  *
                     34:  *     while (read lint1 output into "funct" structures)
                     35:  *             if (this is a filename record)
                     36:  *                     save filename
                     37:  *             else
                     38:  *                     read arg records and throw on floor
                     39:  *                     if (this is to be included)
                     40:  *                             copy filename into "funct"
                     41:  *                             insert into list
                     42:  *     format and print
                     43:  */
                     44: 
                     45: 
                     46: main(argc, argv)
                     47:        int argc;
                     48:        char **argv;
                     49:        {
                     50:        extern int optind;
                     51:        extern char *optarg;
                     52:        funct fu;
                     53:        int uscore, fmask, c;
                     54:        void rdargs(), insert(), putout();
                     55: #ifdef FLEXNAMES
                     56:        char *filename, *funcname, *getstr();
                     57: #else
                     58:        char filename[FNSIZE + 1], *strncpy();
                     59: #endif
                     60: 
                     61:        fmask = LDS | LDX | LRV;
                     62:        uscore = 0;
                     63:        while ((c = getopt(argc, argv, "i:")) != EOF)
                     64:                if (c == 'i')
                     65:                        if (*optarg == '_')
                     66:                                uscore = 1;
                     67:                        else if (*optarg == 'x')
                     68:                                fmask &= ~(LDS | LDX);
                     69:                        else
                     70:                                goto argerr;
                     71:                else
                     72:                argerr:
                     73:                        (void)fprintf(stderr, "lpfx: bad option %c ignored\n", c);
                     74:        while (0 < fread((char *)&fu.r, sizeof(fu.r), 1, stdin))
                     75:                if (fu.r.l.decflag & LFN)
                     76:                        {
                     77: #ifdef FLEXNAMES
                     78:                        filename = fu.r.f.fn = getstr();
                     79: fprintf(stderr, "file <%s>\n", filename);
                     80: #else
                     81:                        (void)strncpy(filename, fu.r.f.fn, FNSIZE);
                     82:                        filename[FNSIZE] = '\0';
                     83: #endif
                     84:                        }
                     85:                else
                     86:                        {
                     87: #ifdef FLEXNAMES
                     88:                        funcname = fu.r.l.name = getstr();
                     89: #endif
                     90:                        rdargs(&fu);
                     91:                        if (((fmask & LDS) ? ISFTN(fu.r.l.type.aty) :
                     92:                              !(fu.r.l.decflag & fmask)) &&
                     93:                            ((uscore) ? 1 : (*fu.r.l.name != '_')))
                     94:                                {
                     95: #ifdef FLEXNAMES
                     96:                                fu.fname = filename;
                     97: #else
                     98:                                (void)strncpy(fu.fname, filename, FNSIZE);
                     99:                                fu.fname[FNSIZE] = '\0';
                    100: #endif
                    101:                                insert(&fu);
                    102:                                }
                    103:                        }
                    104:        putout();
                    105:        }
                    106: 
                    107: /* getstr - get strings from intermediate file
                    108:  *
                    109:  * simple while loop reading into static buffer
                    110:  * transfer into malloc'ed buffer
                    111:  * panic and die if format or malloc error
                    112:  *
                    113:  */
                    114: 
                    115: char *getstr()
                    116:        {
                    117:        static char buf[BUFSIZ];
                    118:        char *malloc(), *strcat();
                    119:        register int c;
                    120:        register char *p = buf;
                    121: 
                    122:        while ((c = getchar()) != EOF)
                    123:                {
                    124:                *p++ = c;
                    125:                if (c == '\0' || !isascii(c))
                    126:                        break;
                    127:                }
                    128:        if (c != '\0')
                    129:                {
                    130:                fputs("lpfx: PANIC! Intermediate file string format error\n",
                    131:                    stderr);
                    132:                exit(1);
                    133:                /*NOTREACHED*/
                    134:                }
                    135:        if (!(p = malloc(strlen(buf) + 1)))
                    136:                {
                    137:                fputs("lpfx: out of heap space\n", stderr);
                    138:                exit(1);
                    139:                /*NOTREACHED*/
                    140:                }
                    141:        return (strcat(p, buf));
                    142:        }
                    143: 
                    144: /*
                    145:  * rdargs - read arg records and throw on floor
                    146:  *
                    147:  *     if ("funct" has args)
                    148:  *             get absolute value of nargs
                    149:  *             if (too many args)
                    150:  *                     panic and die
                    151:  *             read args into temp array
                    152:  */
                    153: 
                    154: void rdargs(pf)
                    155:        register funct *pf;
                    156:        {
                    157:        struct ty atype[50];
                    158: 
                    159:        if (pf->r.l.nargs)
                    160:                {
                    161:                if (pf->r.l.nargs < 0)
                    162:                        pf->r.l.nargs = -pf->r.l.nargs - 1;
                    163:                if (pf->r.l.nargs > 50)
                    164:                        {
                    165:                        (void) fprintf(stderr, "lpfx: PANIC! nargs=%d\n",
                    166:                            pf->r.l.nargs);
                    167:                        exit(1);
                    168:                        }
                    169:                if (fread((char *)atype, sizeof(ATYPE), pf->r.l.nargs, stdin) <= 0)
                    170:                        {
                    171:                        (void)perror("lpfx.rdargs");
                    172:                        exit(1);
                    173:                        }
                    174:                }
                    175:        }
                    176: 
                    177: /*
                    178:  * insert - insertion sort into (singly) linked list
                    179:  *
                    180:  *     stupid linear list insertion
                    181:  */
                    182: 
                    183: static li *head = NULL;
                    184: 
                    185: void insert(pfin)
                    186:        register funct *pfin;
                    187:        {
                    188:        register li *list_item, *newf;
                    189:        char *malloc();
                    190: 
                    191:        if ((newf = (li *)malloc(sizeof(li))) == NULL)
                    192:                {
                    193:                (void)fprintf(stderr, "lpfx: out of heap space\n");
                    194:                exit(1);
                    195:                }
                    196:        newf->fun = *pfin;
                    197:        if (list_item = head)
                    198:                if (newf->fun.r.l.fline < list_item->fun.r.l.fline)
                    199:                        {
                    200:                        newf->next = head;
                    201:                        head = newf;
                    202:                        }
                    203:                else
                    204:                        {
                    205:                        while (list_item->next &&
                    206:                          list_item->next->fun.r.l.fline < newf->fun.r.l.fline)
                    207:                                list_item = list_item->next;
                    208:                        while (list_item->next &&
                    209:                          list_item->next->fun.r.l.fline == newf->fun.r.l.fline &&
                    210:                          list_item->next->fun.r.l.decflag < newf->fun.r.l.decflag)
                    211:                                        list_item = list_item->next;
                    212:                        newf->next = list_item->next;
                    213:                        list_item->next = newf;
                    214:                        }
                    215:        else
                    216:                {
                    217:                head = newf;
                    218:                newf->next = NULL;
                    219:                }
                    220:        }
                    221: 
                    222: /*
                    223:  * putout - format and print sorted records
                    224:  *
                    225:  *     while (there are records left)
                    226:  *             copy name and null terminate
                    227:  *             if (this is a definition)
                    228:  *                     if (this is a function**)
                    229:  *                             save name for reference formatting
                    230:  *                     print definition format
                    231:  *             else if (this is a reference)
                    232:  *                     print reference format
                    233:  *
                    234:  *     ** as opposed to external/static variable
                    235:  */
                    236: 
                    237: void putout()
                    238:        {
                    239:        register li *pli;
                    240: #ifdef FLEXNAMES
                    241:        char lname[BUFSIZ], name[BUFSIZ];
                    242: #else
                    243:        char lname[NSIZE+1], name[NSIZE+1];
                    244: #endif
                    245:        char *prtype(), *strncpy(), *strcpy();
                    246:        
                    247:        pli = head;
                    248:        name[0] = lname[0] = '\0';
                    249:        while (pli != NULL)
                    250:                {
                    251: #ifdef FLEXNAMES
                    252:                (void) strcpy(name, pli->fun.r.l.name);
                    253: #else
                    254:                (void)strncpy(name, pli->fun.r.l.name, NSIZE);
                    255:                name[NSIZE] = '\0';
                    256: #endif
                    257:                if (pli->fun.r.l.decflag & (LDI | LDC | LDS))
                    258:                        {
                    259:                        if (ISFTN(pli->fun.r.l.type.aty))
                    260:                                (void)strcpy(lname, name);
                    261:                        (void)printf("%s = %s, <%s %d>\n", name, prtype(pli),
                    262:                            pli->fun.fname, pli->fun.r.l.fline);
                    263:                        }
                    264:                else if (pli->fun.r.l.decflag & (LUV | LUE | LUM))
                    265:                        (void)printf("%s : %s\n", lname, name);
                    266:                pli = pli->next;
                    267:                }
                    268:        }
                    269: 
                    270: static char *types[] = {
                    271:        "void", "???", "char", "short", "int", "long", "float",
                    272:        "double", "struct", "union", "enum", "???", "unsigned char",
                    273:        "unsigned short", "unsigned int", "unsigned long"};
                    274: 
                    275: /*
                    276:  * prtype - decode type fields
                    277:  *
                    278:  *     strictly arcana
                    279:  */
                    280: 
                    281: char *prtype(pli)
                    282:        register li *pli;
                    283:        {
                    284:        static char bigbuf[64];
                    285:        char buf[32], *shift(), *strcpy(), *strcat();
                    286:        register char *bp;
                    287:        register int typ;
                    288: 
                    289:        typ = pli->fun.r.l.type.aty;
                    290:        (void)strcpy(bigbuf, types[typ & 017]);
                    291:        *(bp = buf) = '\0';
                    292:        for (typ >>= 4; typ > 0; typ >>= 2)
                    293:                switch (typ & 03)
                    294:                        {
                    295:                        case 1:
                    296:                                bp = shift(buf);
                    297:                                buf[0] = '*';
                    298:                                break;
                    299:                        case 2:
                    300:                                *bp++ = '(';
                    301:                                *bp++ = ')';
                    302:                                *bp = '\0';
                    303:                                break;
                    304:                        case 3:
                    305:                                *bp++ = '[';
                    306:                                *bp++ = ']';
                    307:                                *bp = '\0';
                    308:                                break;
                    309:                        }
                    310:        (void)strcat(bigbuf, buf);
                    311:        return(bigbuf);
                    312:        }
                    313: 
                    314: char *shift(s)
                    315:        register char *s;
                    316:        {
                    317:        register char *p1, *p2;
                    318:        char *rp;
                    319: 
                    320:        for (p1 = s; *p1; ++p1)
                    321:                ;
                    322:        rp = p2 = p1++;
                    323:        while (p2 >= s)
                    324:                *p1-- = *p2--;
                    325:        return(++rp);
                    326:        }

unix.superglobalmegacorp.com

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