Annotation of 41BSD/cmd/pxp/pp.c, revision 1.1

1.1     ! root        1: /* Copyright (c) 1979 Regents of the University of California */
        !             2: #
        !             3: /*
        !             4:  * pxp - Pascal execution profiler
        !             5:  *
        !             6:  * Bill Joy UCB
        !             7:  * Version 1.2 January 1979
        !             8:  */
        !             9: 
        !            10: #include "0.h"
        !            11: 
        !            12: #define noprint() nopflg
        !            13: 
        !            14: int    pplev[3];       /* STAT, DECL, PRFN */
        !            15: int    nopflg;
        !            16: 
        !            17: setprint()
        !            18: {
        !            19: 
        !            20:        if (profile == 0) {
        !            21:                if (table)
        !            22:                        nopflg = 1;
        !            23:                else
        !            24:                        nopflg = 0;
        !            25:                return;
        !            26:        }
        !            27:        nopflg = !all && nowcnt() == 0 || !opt('z');
        !            28: }
        !            29: 
        !            30: printon()
        !            31: {
        !            32: 
        !            33:        if (profile == 0) {
        !            34:                if (table)
        !            35:                        nopflg = 1;
        !            36:                return;
        !            37:        }
        !            38:        nopflg = 0;
        !            39: }
        !            40: 
        !            41: printoff()
        !            42: {
        !            43: 
        !            44:        nopflg = 1;
        !            45: }
        !            46: 
        !            47: ppkw(s)
        !            48:        register char *s;
        !            49: {
        !            50:        register char *cp, i;
        !            51: 
        !            52:        if (noprint())
        !            53:                return;
        !            54:        /*
        !            55:         * First real thing printed
        !            56:         * is always a keyword
        !            57:         * or includes an "id" (if a comment)
        !            58:         * (See ppnl below)
        !            59:         */
        !            60:        hadsome = 1;
        !            61:        if (underline) {
        !            62:                for (cp = s; *cp; cp++)
        !            63:                        putchar('_');
        !            64:                for (cp = s; *cp; cp++)
        !            65:                        putchar('\b');
        !            66:        }
        !            67:        printf(s);
        !            68: }
        !            69: 
        !            70: ppid(s)
        !            71:        register char *s;
        !            72: {
        !            73: 
        !            74:        if (noprint())
        !            75:                return;
        !            76:        hadsome = 1;
        !            77:        if (s == NIL)
        !            78:                s = "{identifier}";
        !            79:        printf(s);
        !            80: }
        !            81: 
        !            82: ppbra(s)
        !            83:        char *s;
        !            84: {
        !            85: 
        !            86:        if (noprint())
        !            87:                return;
        !            88:        if (s != NIL)
        !            89:                printf(s);
        !            90: }
        !            91: 
        !            92: ppsep(s)
        !            93:        char *s;
        !            94: {
        !            95: 
        !            96:        if (noprint())
        !            97:                return;
        !            98:        printf(s);
        !            99: }
        !           100: 
        !           101: ppket(s)
        !           102:        char *s;
        !           103: {
        !           104: 
        !           105:        if (noprint())
        !           106:                return;
        !           107:        if (s != NIL)
        !           108:                printf(s);
        !           109: }
        !           110: 
        !           111: char   killsp;
        !           112: 
        !           113: ppunspac()
        !           114: {
        !           115: 
        !           116:        killsp = 1;
        !           117: }
        !           118: 
        !           119: ppspac()
        !           120: {
        !           121: 
        !           122:        if (killsp) {
        !           123:                killsp = 0;
        !           124:                return;
        !           125:        }
        !           126:        if (noprint())
        !           127:                return;
        !           128:        putchar(' ');
        !           129: }
        !           130: 
        !           131: ppitem()
        !           132: {
        !           133: 
        !           134:        if (noprint())
        !           135:                return;
        !           136:        ppnl();
        !           137:        indent();
        !           138: }
        !           139: 
        !           140: int    owenl, owenlb;
        !           141: 
        !           142: ppsnlb()
        !           143: {
        !           144: 
        !           145:        if (nopflg)
        !           146:                return;
        !           147:        owenlb++;
        !           148: }
        !           149: 
        !           150: ppsnl()
        !           151: {
        !           152: 
        !           153:        if (nopflg)
        !           154:                return;
        !           155:        owenl++;
        !           156: }
        !           157: 
        !           158: pppay()
        !           159: {
        !           160: 
        !           161:        while (owenl || owenlb) {
        !           162:                putchar('\n');
        !           163:                if (owenlb) {
        !           164:                        putchar(' ');
        !           165:                        owenlb--;
        !           166:                } else
        !           167:                        owenl--;
        !           168:        }
        !           169: }
        !           170: 
        !           171: ppnl()
        !           172: {
        !           173: 
        !           174:        if (noprint())
        !           175:                return;
        !           176:        if (hadsome == 0)
        !           177:                return;
        !           178:        pppay();
        !           179:        putchar('\n');
        !           180: }
        !           181: 
        !           182: indent()
        !           183: {
        !           184:        register i;
        !           185: 
        !           186:        if (noprint())
        !           187:                return;
        !           188:        linopr();
        !           189:        if (profile == 0) {
        !           190:                indent1(pplev[PRFN] + pplev[DECL] + pplev[STAT]);
        !           191:                return;
        !           192:        }
        !           193:        indent1(pplev[PRFN] + pplev[STAT]);
        !           194:        switch (i = shudpcnt()) {
        !           195:                case 1:
        !           196:                        printf("%7.7ld.", nowcnt());
        !           197:                        dashes('-');
        !           198:                        putchar('|');
        !           199:                        break;
        !           200:                case 0:
        !           201:                case -1:
        !           202:                        printf("        ");
        !           203:                        dashes(' ');
        !           204:                        putchar(i == 0 ? '|' : ' ');
        !           205:                        break;
        !           206:        }
        !           207:        indent1(pplev[DECL]);
        !           208: }
        !           209: 
        !           210: dashes(c)
        !           211:        char c;
        !           212: {
        !           213:        register i;
        !           214: 
        !           215:        for (i = unit - 1; i != 0; i--)
        !           216:                putchar(c);
        !           217: }
        !           218: 
        !           219: indent1(in)
        !           220:        int in;
        !           221: {
        !           222:        register i;
        !           223: 
        !           224:        if (noprint())
        !           225:                return;
        !           226:        i = in;
        !           227:        if (profile == 0)
        !           228:                while (i >= 8) {
        !           229:                        putchar('\t');
        !           230:                        i =- 8;
        !           231:                }
        !           232:        while (i > 0) {
        !           233:                putchar(' ');
        !           234:                i--;
        !           235:        }
        !           236: }
        !           237: 
        !           238: linopr()
        !           239: {
        !           240: 
        !           241:        if (noprint())
        !           242:                return;
        !           243:        if (profile) {
        !           244:                if (line < 0)
        !           245:                        line = -line;
        !           246:                printf("%6d  ", line);
        !           247:        }
        !           248: }
        !           249: 
        !           250: indentlab()
        !           251: {
        !           252: 
        !           253:        indent1(pplev[PRFN]);
        !           254: }
        !           255: 
        !           256: ppop(s)
        !           257:        char *s;
        !           258: {
        !           259: 
        !           260:        if (noprint())
        !           261:                return;
        !           262:        printf(s);
        !           263: }
        !           264: 
        !           265: ppnumb(s)
        !           266:        char *s;
        !           267: {
        !           268: 
        !           269:        if (noprint())
        !           270:                return;
        !           271:        if (s == NIL)
        !           272:                s = "{number}";
        !           273:        printf(s);
        !           274: }
        !           275: 
        !           276: ppgoin(lv)
        !           277: {
        !           278: 
        !           279:        pplev[lv] =+ unit;
        !           280: }
        !           281: 
        !           282: ppgoout(lv)
        !           283: {
        !           284: 
        !           285:        pplev[lv] =- unit;
        !           286:        if (pplev[lv] < 0)
        !           287:                panic("pplev");
        !           288: }
        !           289: 
        !           290: ppstr(s)
        !           291:        char *s;
        !           292: {
        !           293:        register char *cp;
        !           294: 
        !           295:        if (noprint())
        !           296:                return;
        !           297:        if (s == NIL) {
        !           298:                printf("{string}");
        !           299:                return;
        !           300:        }
        !           301:        putchar('\'');
        !           302:        cp = s;
        !           303:        while (*cp) {
        !           304:                putchar(*cp);
        !           305:                if (*cp == '\'')
        !           306:                        putchar('\'');
        !           307:                cp++;
        !           308:        }
        !           309:        putchar('\'');
        !           310: }
        !           311: 
        !           312: pplab(s)
        !           313:        char *s;
        !           314: {
        !           315: 
        !           316:        if (noprint())
        !           317:                return;
        !           318:        if (s == NIL)
        !           319:                s = "{integer label}";
        !           320:        printf(s);
        !           321: }
        !           322: 
        !           323: int    outcol;
        !           324: 
        !           325: 
        !           326: putchar(c)
        !           327:        char c;
        !           328: {
        !           329: 
        !           330:        putc(c, stdout);
        !           331:        if (ferror(stdout))
        !           332:                outerr();
        !           333:        switch (c) {
        !           334:                case '\n':
        !           335:                        outcol = 0;
        !           336:                        flush();
        !           337:                        break;
        !           338:                case '\t':
        !           339:                        outcol =+ 8;
        !           340:                        outcol =& ~07;
        !           341:                        break;
        !           342:                case '\b':
        !           343:                        if (outcol)
        !           344:                                outcol--;
        !           345:                        break;
        !           346:                default:
        !           347:                        outcol++;
        !           348:                case '\f':
        !           349:                        break;
        !           350:        }
        !           351: }
        !           352: 
        !           353: flush()
        !           354: {
        !           355: 
        !           356:        fflush(stdout);
        !           357:        if (ferror(stdout))
        !           358:                outerr();
        !           359: }
        !           360: 
        !           361: pptab()
        !           362: {
        !           363:        register int i;
        !           364: 
        !           365:        if (noprint())
        !           366:                return;
        !           367:        i = pplev[PRFN] + profile ? 44 + unit : 28;
        !           368: /*
        !           369:        if (outcol > i + 8) {
        !           370:                ppnl();
        !           371:                i =+ 8;
        !           372:        }
        !           373: */
        !           374:        do
        !           375:                putchar('\t');
        !           376:        while (outcol < i);
        !           377: }
        !           378: 
        !           379: outerr()
        !           380: {
        !           381: 
        !           382:        perror(stdoutn);
        !           383:        pexit(DIED);
        !           384: }

unix.superglobalmegacorp.com

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