|
|
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 <sccs.h> ! 8: ! 9: SCCSID(@(#)print.c 7.1 2/5/81) ! 10: ! 11: extern short tTdbu[]; ! 12: extern int print(); ! 13: extern int null_fn(); ! 14: ! 15: struct fn_def PrintFn = ! 16: { ! 17: "PRINT", ! 18: print, ! 19: null_fn, /* initialization function */ ! 20: null_fn, ! 21: NULL, ! 22: 0, ! 23: tTdbu, ! 24: 100, ! 25: 'Z', ! 26: 0 ! 27: }; ! 28: ! 29: ! 30: ! 31: ! 32: /* ! 33: ** PRINT -- print relation ! 34: ** ! 35: ** Parameters: ! 36: ** parmv[0] through parmv[parmc -2] contain names ! 37: ** of relations to be printed on the standard output. ! 38: ** Note that this calls printatt, so all the output formatting ! 39: ** features associated with printatt are available here. ! 40: ** ! 41: ** parmv[parmc - 1].pv_type is PV_INT for other than a "normal" ! 42: ** print. In this case parmv[parmc - 1] is 0 for headers on ! 43: ** every page, and 1 for all headers and footers suppressed. ! 44: ** err_array is set to 0 for a good relation, 1 for no ! 45: ** relation by that name, and -1 for a view. ! 46: ** ! 47: ** Returns: ! 48: ** 0 if no errors else the last error number ! 49: ** ! 50: ** Trace Flags: ! 51: ** 40 ! 52: */ ! 53: ! 54: print(parmc, parmv) ! 55: int parmc; ! 56: PARM parmv[]; ! 57: { ! 58: DESC d; ! 59: extern DESC Attdes; ! 60: struct attribute att, katt; ! 61: char tuple[MAXTUP]; ! 62: TID tid, limtid; ! 63: TID stid; ! 64: register int i; ! 65: register int ern; ! 66: register char *name; ! 67: extern struct out_arg Out_arg; ! 68: int mode; ! 69: int lineno; ! 70: int pc; ! 71: int err_array[PV_MAXPC]; ! 72: ! 73: # ifdef xZTR1 ! 74: if (tTf(40, -1)) ! 75: { ! 76: printf("entering print\n"); ! 77: prvect(parmc, parmv); ! 78: } ! 79: # endif ! 80: ! 81: if (parmv[parmc - 1].pv_type == PV_INT) ! 82: mode = parmv[parmc - 1].pv_val.pv_int; ! 83: else ! 84: mode = -1; ! 85: ! 86: opencatalog("attribute", 0); ! 87: ! 88: for (pc = 0; pc <= parmc - 1; pc++) ! 89: { ! 90: name = parmv[pc].pv_val.pv_str; ! 91: ! 92: ern = openr(&d, 0, name); ! 93: if (ern == AMOPNVIEW_ERR) ! 94: { ! 95: err_array[pc] = 5002; /* can't print a view */ ! 96: continue; ! 97: } ! 98: if (ern > 0) ! 99: { ! 100: err_array[pc] = 5001; /* cannot open relation */ ! 101: continue; ! 102: } ! 103: if (ern < 0) ! 104: syserr("printr:openr target %s, %d", ! 105: name, ern); ! 106: if ((d.reldum.relstat & S_PROTALL) && (d.reldum.relstat & S_PROTRET) && ! 107: !bequal(Usercode, d.reldum.relowner, 2)) ! 108: { ! 109: err_array[pc] = 5003; /* protection violation */ ! 110: closer(&d); ! 111: continue; ! 112: } ! 113: ! 114: ! 115: /* a printable relation */ ! 116: err_array[pc] = 0; ! 117: # ifdef xZTR2 ! 118: if (tTf(40, 1)) ! 119: printdesc(&d); ! 120: # endif ! 121: lineno = Out_arg.linesperpage - 6; ! 122: if (mode <= 0) ! 123: { ! 124: if (mode == 0) ! 125: putchar('\014'); /* form feed */ ! 126: printf("\n%s relation\n", name); ! 127: lineno -= 2; ! 128: } ! 129: ! 130: find(&d, NOKEY, &tid, &limtid); ! 131: ! 132: if (Lockrel) ! 133: setrll(A_SLP, d.reltid.ltid, M_SHARE); /* set shared lock on relation*/ ! 134: for (;;) ! 135: { ! 136: if (mode <= 0) ! 137: { ! 138: beginhdr(); ! 139: seq_init(&Attdes, &d); ! 140: for (i = 1; seq_attributes(&Attdes, &d, &att); i++) ! 141: { ! 142: printhdr(d.relfrmt[i], d.relfrml[i], att.attname); ! 143: } ! 144: printeol(); ! 145: printeh(); ! 146: lineno -= 3; ! 147: } ! 148: ! 149: # ifdef xZTM ! 150: if(tTf(99, 1)) ! 151: timtrace(29, 0); ! 152: # endif ! 153: while ((ern = get(&d, &tid, &limtid, tuple, TRUE)) == 0) ! 154: { ! 155: printup(&d, tuple); ! 156: ! 157: if (mode == 0 && --lineno <= 0) ! 158: { ! 159: printf("\n\n\n\n\n\n"); ! 160: lineno = Out_arg.linesperpage - 6; ! 161: break; ! 162: } ! 163: } ! 164: # ifdef xZTM ! 165: if(tTf(99, 1)) ! 166: timtrace(30, 0); ! 167: # endif ! 168: if (ern > 0) ! 169: break; ! 170: ! 171: if (ern < 0) ! 172: syserr("print: get %d", ern); ! 173: } ! 174: ! 175: if (mode <= 0) ! 176: printeh(); ! 177: if (Lockrel) ! 178: unlrl(d.reltid.ltid); /* release relation lock */ ! 179: ! 180: closer(&d); ! 181: } ! 182: /* check for any error messages that should be printed */ ! 183: ern = 0; ! 184: for (pc = 0; pc <= parmc - 1; pc++) ! 185: { ! 186: if (i = err_array[pc]) ! 187: { ! 188: ern = nferror(i, parmv[pc].pv_val.pv_str, 0); ! 189: } ! 190: } ! 191: return (ern); ! 192: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.