Annotation of 3BSD/cmd/awk/dump.c, revision 1.1

1.1     ! root        1: #include "awk.def"
        !             2: #include "stdio.h"
        !             3: #include "awk.h"
        !             4: #define printit(n) printf(printname[n-FIRSTTOKEN]);
        !             5: extern char *printname[];
        !             6: extern cell fldtab[];
        !             7: 
        !             8: dump(a,b) node *a, *b;
        !             9: {
        !            10: #ifdef DEBUG
        !            11:        node *x;
        !            12:        if(a==nullstat) return;
        !            13:        for(x=a;x!=NULL;x=x->nnext)
        !            14:        {
        !            15:        if(x==b) printf(" *** ");
        !            16:                if(x->ntype==NVALUE)
        !            17:                {       switch(x->subtype)
        !            18:                        {
        !            19:                        default: runerror();
        !            20:                        case CCON: case CVAR:
        !            21:                                printf("%s",x->nobj->nval);
        !            22:                                continue;
        !            23:                        case CFLD:
        !            24:                                if(x->nobj->nval==0) printf("$%d",x->nobj - fldtab);
        !            25:                                else printf("$0");
        !            26:                                continue;
        !            27:                        }
        !            28:                }
        !            29:                else if(x->ntype==PASTAT2)
        !            30:                {       pa2dump(x,b);
        !            31:                        continue;
        !            32:                }
        !            33:                switch(x->nobj)
        !            34:                {
        !            35:                default: runerror();
        !            36:                case LE: case LT: case EQ:
        !            37:                case NE: case GT: case GE:
        !            38:                case MATCH: case NOTMATCH:
        !            39:                case ADD: case MINUS: case MULT:
        !            40:                case DIVIDE: case MOD: case ASGNOP:
        !            41:                case BOR: case AND: case CAT:
        !            42:                        dump(x->narg[0], b);
        !            43:                        printit(x->nobj);
        !            44:                        if(x->nobj!=MATCH && x->nobj!=NOTMATCH)
        !            45:                                dump(x->narg[1]);
        !            46:                        else    printf("regex");
        !            47:                        break;
        !            48:                case UMINUS: case FNCN: case INCR:
        !            49:                case DECR: case INDIRECT:
        !            50:                        printit(x->nobj);
        !            51:                        dump(x->narg[0], b);
        !            52:                        break;
        !            53:                case PRINT: case PRINTF: case SPRINTF:
        !            54:                case SPLIT:
        !            55:                        printit(x->nobj);
        !            56:                        dump(x->narg[0], b);
        !            57:                        if(x->nobj==SPLIT || x->nobj==SPRINTF) break;
        !            58:                        if(x->narg[1]==0) break;
        !            59:                        printit((int)x->narg[1]);
        !            60:                        dump(x->narg[2], b);
        !            61:                        break;
        !            62:                case IF: case WHILE:
        !            63:                        printit(x->nobj);
        !            64:                        dump(x->narg[0], b);
        !            65:                        printf(") ");
        !            66:                        dump(x->narg[1], b);
        !            67:                        if(x->narg[2]==NULL) break;
        !            68:                        printit(ELSE);
        !            69:                        dump(x->narg[2], b);
        !            70:                        break;
        !            71:                case FOR:
        !            72:                        printit(x->nobj);
        !            73:                        dump(x->narg[0], b);
        !            74:                        putchar(';');
        !            75:                        dump(x->narg[1], b);
        !            76:                        putchar(';');
        !            77:                        dump(x->narg[2], b);
        !            78:                        printf(") ");
        !            79:                        dump(x->narg[3], b);
        !            80:                        break;
        !            81:                case NEXT: case EXIT: case BREAK: case CONTINUE:
        !            82:                        printit(x->nobj);
        !            83:                        break;
        !            84:                case PROGRAM:
        !            85:                        if(x->narg[0]!=NULL)
        !            86:                        {       printf("BEGIN {");
        !            87:                                dump(x->narg[0], b);
        !            88:                                printf("}\n");
        !            89:                        }
        !            90:                        dump(x->narg[1], b);
        !            91:                        if(x->narg[2]!=NULL)
        !            92:                        {       printf("END {");
        !            93:                                dump(x->narg[2], b);
        !            94:                                printf("}\n");
        !            95:                        }
        !            96:                        break;
        !            97:                case PASTAT:
        !            98:                        dump(x->narg[0], b);
        !            99:                        printf("{");
        !           100:                        dump(x->narg[1], b);
        !           101:                        printf("}\n");
        !           102:                        break;
        !           103:                case ARRAY:
        !           104:                        printf(x->nval);
        !           105:                        printf("[");
        !           106:                        dump(x->narg[1], b);
        !           107:                        printf("]");
        !           108:                        break;
        !           109:                case SUBSTR:
        !           110:                        printit(x->nobj);
        !           111:                        dump(x->narg[0], b);
        !           112:                        putchar(',');
        !           113:                        dump(x->narg[1], b);
        !           114:                        if(x->narg[2]!=NULL)
        !           115:                        {       putchar(',');
        !           116:                                dump(x->narg[2], b);
        !           117:                        }
        !           118:                        putchar(')');
        !           119:                        break;
        !           120:                }
        !           121:                if(x->ntype == NSTAT) putchar('\n');
        !           122:        }
        !           123: #endif
        !           124: }
        !           125: pa2dump(a, b) node *a, *b;
        !           126: {
        !           127: #ifdef DEBUG
        !           128:        dump(a->narg[0], b);
        !           129:        printf(", ");
        !           130:        dump(a->narg[1], b);
        !           131:        printf(" {");
        !           132:        dump(a->narg[2], b);
        !           133:        printf("}\n");
        !           134: #endif
        !           135: }

unix.superglobalmegacorp.com

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