1: # include <stdio.h> 2: 3: # include "../ingres.h" 4: # include "../aux.h" 5: # include "../access.h" 6: # include "../symbol.h" 7: 8: # define PAGELGTH 56 9: 10: int Printlgth; 11: extern struct out_arg Out_arg; 12: 13: printup(d, tuple) 14: struct descriptor *d; 15: char *tuple; 16: { 17: register char *ftype, *flen; 18: register int *foff; 19: int i, type; 20: 21: ftype = &d->relfrmt[1]; 22: flen = &d->relfrml[1]; 23: foff = &d->reloff[1]; 24: i = d->relatts; 25: 26: /* If relation is S_BINARY then print char fields escaped */ 27: if (d->relstat & S_BINARY) 28: { 29: while (i--) 30: printatt((type = *ftype++) == CHAR ? BINARY : type, *flen++, &tuple[*foff++]); 31: } 32: else 33: { 34: while (i--) 35: printatt(*ftype++, *flen++, &tuple[*foff++]); 36: } 37: printeol(); 38: } 39: 40: printatt(type, length1, value1) 41: char type; 42: int length1; 43: char *value1; 44: { 45: register int length; 46: register char *value; 47: char buf[MAXFIELD]; 48: extern char *locv(); 49: int valbuf[4]; 50: 51: putc(Out_arg.coldelim, stdout); 52: length = length1; 53: switch (type) 54: { 55: 56: case INT: 57: value = (char *) valbuf; 58: bmove(value1, value, length); 59: switch (length) 60: { 61: 62: case 1: 63: printfatt(Out_arg.i1width, iocv(i1deref(value))); 64: break; 65: 66: case 2: 67: printfatt(Out_arg.i2width, iocv(i2deref(value))); 68: break; 69: 70: case 4: 71: printfatt(Out_arg.i4width, locv(i4deref(value))); 72: break; 73: 74: default: 75: syserr("printatt: i%d", length); 76: 77: } 78: return (0); 79: 80: case FLOAT: 81: value = (char *) valbuf; 82: bmove(value1, value, length); 83: switch (length) 84: { 85: 86: case 4: 87: ftoa(f4deref(value), buf, Out_arg.f4width, Out_arg.f4prec, Out_arg.f4style); 88: printfatt(Out_arg.f4width, buf); 89: break; 90: 91: case 8: 92: ftoa(f8deref(value), buf, Out_arg.f8width, Out_arg.f8prec, Out_arg.f8style); 93: printfatt(Out_arg.f8width, buf); 94: break; 95: 96: default: 97: syserr("printatt: f%d", length); 98: 99: } 100: return (0); 101: 102: case CHAR: 103: length &= 0377; 104: fwrite(value1, 1, length, stdout); 105: if ((length = Out_arg.c0width - length) > 0) 106: while (length--) 107: putc(' ', stdout); 108: return (0); 109: 110: case BINARY: 111: length &= 0377; 112: value = value1; 113: while (length--) 114: xputchar(*value++); 115: return (0); 116: 117: default: 118: syserr("printatt type %d", type); 119: } 120: } 121: 122: 123: /* 124: ** FORMATTED ATTRIBUTE PRINT 125: ** 126: ** Attribute 'value' is printed. It is type 'type' and has a 127: ** field width of 'width'. 128: */ 129: 130: printfatt(width, value) 131: int width; 132: int value; 133: { 134: register char *p; 135: register int w; 136: register int v; 137: 138: w = width; 139: p = (char *) value; 140: v = length(p); 141: 142: if (v > w) 143: { 144: /* field overflow */ 145: while (w--) 146: putc('*', stdout); 147: return; 148: } 149: 150: /* output the field */ 151: for (w -= v; w > 0; w--) 152: putc(' ', stdout); 153: fwrite(p, 1, v, stdout); 154: } 155: 156: 157: printeol() 158: { 159: putc(Out_arg.coldelim, stdout); 160: putc('\n', stdout); 161: } 162: 163: printeh() 164: { 165: register int i; 166: 167: putc(Out_arg.coldelim, stdout); 168: for (i = 1; i < Printlgth; i++) 169: putc('-', stdout); 170: printeol(); 171: } 172: 173: printhdr(type, length1, value1) 174: char type; 175: int length1; 176: char *value1; 177: { 178: register int length, i; 179: register char *value; 180: char c; 181: 182: value = value1; 183: length = length1 & 0377; 184: 185: switch (type) 186: { 187: case INT: 188: switch (length) 189: { 190: 191: case 1: 192: length = Out_arg.i1width; 193: break; 194: 195: case 2: 196: length = Out_arg.i2width; 197: break; 198: 199: case 4: 200: length = Out_arg.i4width; 201: break; 202: 203: default: 204: syserr("printhdr: i%d", length); 205: 206: } 207: break; 208: 209: case FLOAT: 210: switch (length) 211: { 212: 213: case 4: 214: length = Out_arg.f4width; 215: break; 216: 217: case 8: 218: length = Out_arg.f8width; 219: break; 220: 221: default: 222: syserr("printhdr: f%d", length); 223: 224: } 225: break; 226: 227: case CHAR: 228: if (length < Out_arg.c0width) 229: length = Out_arg.c0width; 230: break; 231: 232: default: 233: syserr("printhdr: type 0%o", type); 234: } 235: 236: putc(Out_arg.coldelim, stdout); 237: for (i = 0; i < length && i < MAXNAME; i++) 238: if (c = *value++) 239: putc(c, stdout); 240: else 241: break; 242: 243: for ( ; i < length; i++) 244: putc(' ', stdout); 245: 246: Printlgth += length + 1; 247: } 248: 249: beginhdr() 250: { 251: Printlgth = 0; 252: putchar('\n'); 253: }