1: # include   <stdio.h>
   2: # include   <ingres.h>
   3: # include   <aux.h>
   4: # include   <access.h>
   5: # include   <symbol.h>
   6: # include   <sccs.h>
   7: 
   8: SCCSID(@(#)printup.c	8.3	2/8/85)
   9: 
  10: /*
  11: **  PRINTUP -- print tuple
  12: **
  13: **	Parameters:
  14: **		d -- a descriptor describing the tuple.
  15: **		tuple -- the tuple to print.
  16: **
  17: **	Returns:
  18: **		??
  19: **
  20: **	Side Effects:
  21: **		None.
  22: */
  23: 
  24: # define    PAGELGTH    56
  25: 
  26: int Printlgth;
  27: extern struct out_arg   Out_arg;
  28: int Hdr = 0;
  29: HDRINFO *Fieldwidth, *Hdrptr;
  30: 
  31: printup(d, tuple)
  32: DESC    *d;
  33: char    *tuple;
  34: {
  35:     register char   *ftype, *flen;
  36:     register short  *foff;
  37:     static  double  dbl;
  38:     auto    long    lng;
  39:     int     i, type;
  40:     extern HDRINFO  *Hdrptr;
  41:     extern HDRINFO  *Fieldwidth;
  42: 
  43:     ftype = &d->relfrmt[1];
  44:     flen = &d->relfrml[1];
  45:     foff = &d->reloff[1];
  46:     i = d->reldum.relatts;
  47: 
  48:     /* If relation is S_BINARY then print char fields escaped */
  49:     if (d->reldum.relstat & S_BINARY)
  50:     {
  51:         while (i--)
  52:             printatt((type = *ftype++) == CHAR ? BINARY : type, *flen++, &tuple[*foff++]);
  53:     }
  54:     else
  55:     {
  56:         while (i--)
  57:         {
  58:             switch ( *ftype )
  59:             {
  60:               case FLOAT:
  61:                 bmove(&tuple[*foff++],&dbl,*flen);
  62:                 printatt(*ftype++, *flen++, (ANYTYPE *)&dbl);
  63:                 break;
  64: 
  65:               case CHAR:
  66:                 printatt(*ftype++, *flen++, (ANYTYPE *)&tuple[*foff++]);
  67:                 break;
  68: 
  69:               case INT:
  70:                 if ( *flen != 4 )
  71:                     printatt(*ftype++, *flen++, (ANYTYPE *)&tuple[*foff++]);
  72:                 else
  73:                 {
  74:                     bmove(&tuple[*foff++],&lng,4);
  75:                     printatt(*ftype++, *flen++, (ANYTYPE *)&lng);
  76:                 }
  77:                 break;
  78:             }
  79:         }
  80:     }
  81:     printeol();
  82: }
  83: 
  84: printatt(type, length, value)
  85: char            type;
  86: register int        length;
  87: register ANYTYPE    *value;
  88: {
  89:     char        buf[MAXFIELD];
  90:     ANYTYPE     valbuf;
  91:     double      dbl;
  92:     float       flt;
  93:     extern char *iocv();
  94:     extern  char    *locv();
  95:     extern HDRINFO  *Hdrptr;
  96:     extern HDRINFO  *Fieldwidth;
  97:     extern int  Hdr;
  98:     register char   *p;
  99: 
 100:     putc(Out_arg.coldelim, stdout);
 101:     switch (type)
 102:     {
 103:       case INT:
 104:         switch (length)
 105:         {
 106:           case 1:
 107:             printfatt(Out_arg.i1width, iocv(value->i1type));
 108:             break;
 109: 
 110:           case 2:
 111:             printfatt(Out_arg.i2width, iocv(value->i2type));
 112:             break;
 113: 
 114:           case 4:
 115:             printfatt(Out_arg.i4width, locv(value->i4type));
 116:             break;
 117: 
 118:           default:
 119:             syserr("printatt: i%d", length);
 120:         }
 121:         return (0);
 122: 
 123:       case FLOAT:
 124:         switch (length)
 125:         {
 126:           case 4:
 127:             ftoa(value->f4type, buf, Out_arg.f4width, Out_arg.f4prec, Out_arg.f4style);
 128:             printfatt(Out_arg.f4width, buf);
 129:             break;
 130: 
 131:           case 8:
 132:             dbl = value->f8type;
 133: 
 134:             ftoa(dbl, (char *)buf, (int)Out_arg.f8width,(int) Out_arg.f8prec, (char)Out_arg.f8style);
 135:             printfatt(Out_arg.f8width, buf);
 136:             break;
 137: 
 138:           default:
 139:             syserr("printatt: f%d", length);
 140:         }
 141:         return (0);
 142: 
 143:       case CHAR:
 144:         length &= I1MASK;
 145:         if (Hdr)
 146:         {
 147:             if (length > Fieldwidth->len)
 148:                 length = Fieldwidth->len;
 149:         }
 150:         fwrite(value, 1, length, stdout);
 151:         if (Hdr)
 152:         {
 153:             if ((length = Fieldwidth->len - length) > 0)
 154:                 while (length--)
 155:                     putc(' ', stdout);
 156:             if ((length = Out_arg.c0width - Fieldwidth->len) > 0)
 157:                 while (length--)
 158:                     putc(' ', stdout);
 159:         Fieldwidth = Fieldwidth->next;
 160:         if (Fieldwidth == NULL)
 161:             Fieldwidth = Hdrptr;
 162:         }
 163:         else
 164:         {
 165:             if ((length = Out_arg.c0width - length) > 0)
 166:                 while (length--)
 167:                     putc(' ', stdout);
 168:         }
 169:         return (0);
 170: 
 171:       case BINARY:
 172:         length &= I1MASK;
 173:         p = (char *) value;
 174:         while (length--)
 175:             xputchar(*p++);
 176:         return (0);
 177: 
 178:       default:
 179:         syserr("printatt type %d", type);
 180:     }
 181: }
 182: /*
 183: **  FORMATTED ATTRIBUTE PRINT
 184: **
 185: **	Attribute 'value' is printed.  It is type 'type' and has a
 186: **	field width of 'width'.
 187: */
 188: 
 189: printfatt(width, value)
 190: int width;
 191: char    *value;
 192: {
 193:     register char   *p;
 194:     register int    w;
 195:     register int    v;
 196: 
 197:     w = width;
 198:     p = value;
 199:     v = length(p);
 200: 
 201:     if (v > w)
 202:     {
 203:         /* field overflow */
 204:         while (w--)
 205:             putc('*', stdout);
 206:         return;
 207:     }
 208: 
 209:     /* output the field */
 210:     for (w -= v; w > 0; w--)
 211:         putc(' ', stdout);
 212:     fwrite(p, 1, v, stdout);
 213: }
 214: 
 215: 
 216: printeol()
 217: {
 218:     putc(Out_arg.coldelim, stdout);
 219:     putc('\n', stdout);
 220: }
 221: 
 222: printeh()
 223: {
 224:     register int        i;
 225: 
 226:     putc(Out_arg.coldelim, stdout);
 227:     for (i = 1; i < Printlgth; i++)
 228:         putc('-', stdout);
 229:     printeol();
 230: }
 231: 
 232: printhdr(type, length, value)
 233: char        type;
 234: register int    length;
 235: register char   *value;
 236: {
 237:     register int    i;
 238:     char        c;
 239: 
 240:     switch (type)
 241:     {
 242:       case INT:
 243:         switch (length)
 244:         {
 245:           case 1:
 246:             length = Out_arg.i1width;
 247:             break;
 248: 
 249:           case 2:
 250:             length = Out_arg.i2width;
 251:             break;
 252: 
 253:           case 4:
 254:             length = Out_arg.i4width;
 255:             break;
 256: 
 257:           default:
 258:             syserr("printhdr: i%d", length);
 259:         }
 260:         break;
 261: 
 262:       case FLOAT:
 263:         switch (length)
 264:         {
 265:           case 4:
 266:             length = Out_arg.f4width;
 267:             break;
 268: 
 269:           case 8:
 270:             length = Out_arg.f8width;
 271:             break;
 272: 
 273:           default:
 274:             syserr("printhdr: f%d", length);
 275:         }
 276:         break;
 277: 
 278:       case CHAR:
 279:         length &= I1MASK;
 280:         if (length < Out_arg.c0width)
 281:             length = Out_arg.c0width;
 282:         break;
 283: 
 284:       default:
 285:         syserr("printhdr: type 0%o", type);
 286:     }
 287: 
 288:     putc(Out_arg.coldelim, stdout);
 289:     for (i = 0; i < length && i < MAXNAME; i++)
 290:         if (c = *value++)
 291:             putc(c, stdout);
 292:         else
 293:             break;
 294: 
 295:     for ( ; i < length; i++)
 296:         putc(' ', stdout);
 297: 
 298:     Printlgth += length + 1;
 299: }
 300: 
 301: beginhdr()
 302: {
 303:     Printlgth = 0;
 304:     putchar('\n');
 305: }

Defined functions

beginhdr defined in line 301; never used
printatt defined in line 84; used 9 times
printeh defined in line 222; never used
printeol defined in line 216; used 2 times
printfatt defined in line 189; used 5 times
printhdr defined in line 232; never used

Defined variables

Hdr defined in line 28; used 3 times
Printlgth defined in line 26; used 3 times

Defined macros

PAGELGTH defined in line 24; never used
Last modified: 1986-04-17
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1473
Valid CSS Valid XHTML 1.0 Strict