Annotation of 43BSD/ingres/source/dbu/print.c, revision 1.1

1.1     ! root        1: # include      <pv.h>
        !             2: # include      <ingres.h>
        !             3: # include      <access.h>
        !             4: # include      <aux.h>
        !             5: # include      <lock.h>
        !             6: # include      <func.h>
        !             7: # include      <catalog.h>
        !             8: # include      <btree.h>
        !             9: # include      <sccs.h>
        !            10: # include      <errors.h>
        !            11: 
        !            12: SCCSID(@(#)print.c     8.6     3/20/85)
        !            13: 
        !            14: extern short   tTdbu[];
        !            15: extern int     print();
        !            16: extern int     null_fn();
        !            17: 
        !            18: struct fn_def PrintFn =
        !            19: {
        !            20:        "PRINT",
        !            21:        print,
        !            22:        null_fn,                /* initialization function */
        !            23:        null_fn,
        !            24:        NULL,
        !            25:        0,
        !            26:        tTdbu,
        !            27:        100,
        !            28:        'Z',
        !            29:        0
        !            30: };
        !            31: 
        !            32: 
        !            33: 
        !            34: 
        !            35: /*
        !            36: **  PRINT -- print relation
        !            37: **
        !            38: **     Parameters:
        !            39: **             parmv[0] through parmv[parmc -2] contain names
        !            40: **             of relations to be printed on the standard output.
        !            41: **             Note that this calls printatt, so all the output formatting 
        !            42: **             features associated with printatt are available here.
        !            43: **
        !            44: **             parmv[parmc - 1].pv_type is PV_INT for other than a "normal"
        !            45: **             print.  In this case parmv[parmc - 1] is 0 for headers on
        !            46: **             every page, and 1 for all headers and footers suppressed.
        !            47: **             err_array is set to 0 for a good relation, 1 for no
        !            48: **             relation by that name, and -1 for a view.
        !            49: **
        !            50: **     Returns:
        !            51: **             0 if no errors else the last error number
        !            52: **
        !            53: **     Trace Flags:
        !            54: **             40
        !            55: */
        !            56: 
        !            57: print(parmc, parmv)
        !            58: int    parmc;
        !            59: PARM   parmv[];
        !            60: {
        !            61:        DESC                    d;
        !            62:        extern DESC             Attdes;
        !            63:        struct attribute        att, katt;
        !            64:        char                    tuple[MAXTUP];
        !            65:        TID                     tid, limtid;
        !            66:        TID                     stid;
        !            67:        register int            i;
        !            68:        register int            ern;
        !            69:        register char           *name;
        !            70:        extern struct out_arg   Out_arg;
        !            71:        int                     mode;
        !            72:        int                     lineno;
        !            73:        int                     pc;
        !            74:        int                     err_array[PV_MAXPC];
        !            75:        char                    btree[MAXNAME + 4];
        !            76:        struct locator          tidpos;
        !            77:        long                    page, mtid, t, next;
        !            78:        extern DESC             Btreesec;
        !            79:        extern int              Btree_fd;
        !            80:        extern HDRINFO          *Hdrptr;
        !            81:        extern HDRINFO          *Fieldwidth;
        !            82:        extern int              Hdr;
        !            83:        HDRINFO                 *hptr;
        !            84:        HDRINFO                 *tptr;
        !            85:        int                     start;
        !            86: 
        !            87: #      ifdef xZTR1
        !            88:        if (tTf(40, -1))
        !            89:        {
        !            90:                printf("entering print\n");
        !            91:                prvect(parmc, parmv);
        !            92:        }
        !            93: #      endif
        !            94: 
        !            95:        if (parmv[parmc - 1].pv_type == PV_INT)
        !            96:                mode = parmv[parmc - 1].pv_val.pv_int;
        !            97:        else
        !            98:                mode = -1;
        !            99: 
        !           100:        opencatalog("attribute", OR_READ);
        !           101: 
        !           102:        for (pc = 0; pc <= parmc - 1; pc++)
        !           103:        {
        !           104:                name = parmv[pc].pv_val.pv_str;
        !           105: 
        !           106:                ern = openr(&d, OR_READ, name);
        !           107:                if (d.reldum.reldim > 0)
        !           108:                {
        !           109:                        bmove(d.relbtree, &Btreesec, sizeof(Btreesec));
        !           110:                        Btree_fd = d.btree_fd;
        !           111:                }
        !           112:                if (ern == AMOPNVIEW_ERR)
        !           113:                {
        !           114:                        err_array[pc] = NOPRINTVIEW;    /* can't print a view */
        !           115:                        continue;
        !           116:                }
        !           117:                if (ern > 0)
        !           118:                {       
        !           119:                        err_array[pc] = BADRELNAME;     /* cannot open relation */
        !           120:                        continue;
        !           121:                }
        !           122:                if (ern < 0)
        !           123:                        syserr("printr:openr target %s, %d",
        !           124:                        name, ern);
        !           125:                if ((d.reldum.relstat & S_PROTALL) && (d.reldum.relstat & S_PROTRET) &&
        !           126:                        !bequal(Usercode, d.reldum.relowner, UCODE_SZ))
        !           127:                {
        !           128:                        err_array[pc] = PROTVIOL;       /* protection violation */
        !           129:                        closer(&d);
        !           130:                        continue;
        !           131:                }
        !           132: 
        !           133: 
        !           134:                /* a printable relation */
        !           135:                err_array[pc] = 0;
        !           136: #              ifdef xZTR2
        !           137:                if (tTf(40, 1))
        !           138:                        printdesc(&d);
        !           139: #              endif
        !           140:                lineno = Out_arg.linesperpage - 6;
        !           141:                if (mode <= 0)
        !           142:                {
        !           143:                        if (mode == 0)
        !           144:                                putchar('\014');        /* form feed */
        !           145:                        printf("\n%s relation\n", name);
        !           146:                        lineno -= 2;
        !           147:                }
        !           148:        
        !           149:                if (!d.reldum.reldim)
        !           150:                        find(&d, NOKEY, &tid, &limtid);
        !           151:        
        !           152:                if (Lockrel)
        !           153:                        setrll(A_SLP, d.reltid.ltid, M_SHARE);  /* set shared lock on relation*/
        !           154:                for (;;)
        !           155:                {
        !           156:                        if (mode <= 0)
        !           157:                        {
        !           158:                                Hdr = TRUE;
        !           159:                                beginhdr();
        !           160:                                seq_init(&Attdes, &d);
        !           161:                                start = 1;
        !           162:                                for (i = 1; seq_attributes(&Attdes, &d, &att); i++)
        !           163:                                {
        !           164:                                        if (d.relfrmt[i] == 'c')
        !           165:                                        {
        !           166:                                                tptr = (HDRINFO *) malloc(sizeof(HDRINFO));
        !           167:                                                if (start)
        !           168:                                                {
        !           169:                                                        Hdrptr = tptr;
        !           170:                                                        Fieldwidth = Hdrptr;
        !           171:                                                        start = 0;
        !           172:                                                }
        !           173:                                                else 
        !           174:                                                        hptr->next = tptr;
        !           175:                                                hptr = tptr;
        !           176:                                        }
        !           177: 
        !           178:                                        printhdr(d.relfrmt[i], d.relfrml[i], att.attname);
        !           179:                                        if (d.relfrmt[i] == 'c')
        !           180:                                        {
        !           181:                                                tptr->len = d.relfrml[i];
        !           182:                                                tptr->len &= 0377;
        !           183:                                                tptr->next = NULL;
        !           184:                                        }
        !           185:                                }
        !           186:                                printeol();
        !           187:                                printeh();
        !           188:                                lineno -= 3;
        !           189:                        }
        !           190:        
        !           191:                        if (d.reldum.reldim > 0)
        !           192:                        {
        !           193:                                btreename(d.reldum.relid, btree);
        !           194:                                page = RT;
        !           195:                                for (i = 0; i < d.reldum.reldim -1 ; ++i)
        !           196:                                {
        !           197:                                        t = get_tid(page, 1, &tidpos);
        !           198:                                        if (t < 0)
        !           199:                                                break;  /* lid value doesn't exist */
        !           200:                                        bmove(&t, &page, LIDSIZE);
        !           201:                                }
        !           202:                                ern = 1;
        !           203:                                if (t >= 0)
        !           204:                                {
        !           205:                                        do
        !           206:                                        {
        !           207:                                                get_node(page, &tidpos.page);
        !           208:                                                next = tidpos.page.nexttree;
        !           209:                                                get_tid(page, 1, &tidpos);
        !           210:                                                page = tidpos.pageno;
        !           211:                                                ern = 0;
        !           212:                                                while (ern == 0)
        !           213:                                                {
        !           214:                                                        for (i = 0; i < tidpos.page.nelmts && ern == 0; ++i)
        !           215:                                                        {
        !           216:                                                                mtid = tidpos.page.node.leafnode.tid_pos[tidpos.page.node.leafnode.tid_loc[i]];
        !           217:                                                                ern = get(&d, &mtid, &mtid, tuple, FALSE);
        !           218:                                                                printup(&d, tuple);
        !           219:                
        !           220:                                                                if (mode == 0 && --lineno <= 0)
        !           221:                                                                {
        !           222:                                                                        printf("\n\n\n\n\n\n");
        !           223:                                                                        lineno = Out_arg.linesperpage - 6;
        !           224:                                                                        ern = 1;
        !           225:                                                                        break;
        !           226:                                                                }
        !           227:                                                        }
        !           228:                                                        page = tidpos.page.node.leafnode.nextleaf;
        !           229:                                                        if (page == NULL)
        !           230:                                                                ern = 1;
        !           231:                                                        else
        !           232:                                                                get_node(page, &tidpos.page);
        !           233:                                                }
        !           234:                                        } while (page = next);
        !           235:                                }
        !           236:                        }
        !           237:                        else
        !           238:                        {
        !           239:                                while ((ern = get(&d, &tid, &limtid, tuple, TRUE)) == 0)
        !           240:                                {
        !           241:                                        printup(&d, tuple);
        !           242:        
        !           243:                                        if (mode == 0 && --lineno <= 0)
        !           244:                                        {
        !           245:                                                printf("\n\n\n\n\n\n");
        !           246:                                                lineno = Out_arg.linesperpage - 6;
        !           247:                                                break;
        !           248:                                        }
        !           249:                                }
        !           250:                        }
        !           251:                        if (ern > 0)
        !           252:                                break;
        !           253:        
        !           254:                        if (ern < 0)
        !           255:                                syserr("print: get %d", ern);
        !           256:                }
        !           257:        
        !           258:                if (mode <= 0)
        !           259:                {
        !           260:                        printeh();
        !           261:                        Hdr = FALSE;
        !           262:                }
        !           263:                if (Lockrel)
        !           264:                        unlrl(d.reltid.ltid);   /* release relation lock */
        !           265:        
        !           266:                closer(&d);
        !           267:        }
        !           268:        /* check for any error messages that should be printed */
        !           269:        ern = 0;
        !           270:        for (pc = 0; pc <= parmc - 1; pc++)
        !           271:        {
        !           272:                if (i = err_array[pc])
        !           273:                {
        !           274:                        ern = nferror(i, parmv[pc].pv_val.pv_str, 0);
        !           275:                }
        !           276:        }
        !           277:        return (ern);
        !           278: }

unix.superglobalmegacorp.com

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