1: # include   "../ingres.h"
   2: # include   "../aux.h"
   3: # include   "../symbol.h"
   4: # include   "../tree.h"
   5: # include   "../pipes.h"
   6: # include   "ovqp.h"
   7: /*
   8: **	INTERP1.C
   9: **
  10: **	symbol I/O utility routines for OVQP interpreter.
  11: **
  12: */
  13: 
  14: /*
  15: ** GETSYMBOL
  16: **
  17: **	Gets (type, len, value) symbols from list
  18: **	A ptr to the list is advanced after
  19: **	call.  Symbols are moved to a target location
  20: **	(typically a slot on the interpreter's Stack).
  21: **	Legality of symbol type and length is checked.
  22: **	Returns		1  if no more symbols in list
  23: **			0 otherwise
  24: **
  25: */
  26: 
  27: getsymbol(ts, p)
  28: struct symbol   *ts;        /* target location (on stack) */
  29: struct symbol   ***p;       /* pointer to list */
  30: {
  31:     int             len;    /*length of target symbol*/
  32:     register char           *d; /* ptr to data for target symbol */
  33:     register char           *cp;    /* the item in the list */
  34:     register struct stacksym    *tops;  /* target location on stack */
  35: 
  36:     tops = (struct stacksym *) ts;  /* copy stack pointer */
  37:     cp = (char *) **p;      /* get list pointer */
  38: #	ifdef xOTR1
  39:     if(tTf(24, 0))
  40:     {
  41:         printf("GETSYM:");
  42:         prsym(cp);
  43:     }
  44: #	endif
  45: 
  46:     if (((struct stacksym *)cp)->type == VAR ||
  47:         ((struct stacksym *)cp)->type == S_VAR)
  48:     {
  49:         tops->type = ((struct qt_v *)cp)->vtype;
  50:         len = tops->len = ((struct qt_v *)cp)->vlen;
  51:         d = (char *) ((struct qt_v *)cp)->vpoint;
  52:     }
  53:     else
  54:     {
  55:         tops->type = ((struct stacksym *)cp)->type;
  56:         len = tops->len = ((struct stacksym *)cp)->len;
  57:         len &= 0377;
  58:         d = (char *) ((struct stacksym *)cp)->value;
  59:     }
  60:     /* advance Qvect sequencing pointer p */
  61:     *p += 1;
  62: 
  63:     switch(tops->type)
  64:     {
  65:       case INT:
  66:         switch (len)
  67:         {
  68:           case 1:
  69:             *tops->value = *d;
  70:             break;
  71:           case 2:
  72:           case 4:
  73:             bmove(d, tops->value, len);
  74:             break;
  75: 
  76:           default:
  77:             syserr("getsym:bad int len %d",len);
  78:         }
  79:         break;
  80: 
  81:       case FLOAT:
  82:         bmove(d, tops->value, len);
  83:         if (len == 4)
  84:             f8deref(tops->value) = f4deref(tops->value);    /* convert to double precision */
  85:         else
  86:             if (len != 8)
  87:                 syserr("getsym:bad FLOAT len %d",len);
  88:         break;
  89: 
  90:       case CHAR:
  91:         cpderef(tops->value) = d;
  92:         break;
  93: 
  94:       case AOP:
  95:       case BOP:
  96:       case UOP:
  97:       case COP:
  98:       case RESDOM:
  99:         /* all except aop are of length 1. aop is
 100: 		** length 6 but the first byte is the aop value
 101: 		*/
 102:         *tops->value = *d & 0377;
 103:         break;
 104: 
 105:       case AND:
 106:       case OR:
 107:         break;
 108: 
 109:       case AGHEAD:
 110:       case BYHEAD:
 111:       case ROOT:
 112:       case QLEND:
 113:         return (1); /* all these are delimitors between lists */
 114: 
 115:       default:
 116:         syserr("getsym:bad type %d", tops->type);
 117:     }
 118:     return(0);
 119: }
 120: 
 121: 
 122: 
 123: /*
 124: *  TOUT
 125: *
 126: *	Copies a symbol value into the Output tuple buffer.
 127: * 	Used to write target
 128: *	list elements or aggregate values into the output tuple.
 129: */
 130: 
 131: tout(sp, offp, rlen)
 132: struct symbol   *sp;
 133: char        *offp;
 134: {
 135:     register struct symbol  *s;
 136:     register int        i;
 137:     register char       *p;
 138:     int         slen;
 139:     extern char     *bmove();
 140: 
 141:     s = sp; /* copy pointer */
 142: 
 143: #	ifdef xOTR1
 144:     if (tTf(24, 3))
 145:     {
 146:         printf("TOUT: s=");
 147:         prstack(s);
 148:         printf("  offset=%d, rlen=%d\n", offp-Outtup, rlen);
 149:     }
 150: #	endif
 151:     if (s->type == CHAR)
 152:     {
 153:         slen = s->len & 0377;
 154:         rlen &= 0377;
 155:         i = rlen - slen;    /* compute difference between sizes */
 156:         if (i <= 0)
 157:             bmove(cpderef(s->value), offp, rlen);
 158:         else
 159:         {
 160:             p = bmove(cpderef(s->value), offp, slen);
 161:             while (i--)
 162:                 *p++ = ' '; /* blank out remainder */
 163:         }
 164:     }
 165:     else
 166:     {
 167:         bmove(s->value, offp, rlen);
 168:     }
 169: }
 170: 
 171: 
 172: 
 173: rcvt(tosp, restype, reslen)
 174: struct symbol   *tosp;
 175: int     restype, reslen;
 176: {
 177:     register struct symbol  *tos;
 178:     register int        rtype, rlen;
 179:     int         stype, slen;
 180: 
 181:     tos = tosp;
 182:     rtype = restype;
 183:     rlen = reslen;
 184:     stype = tos->type;
 185:     slen= tos->len;
 186: #	ifdef xOTR1
 187:     if (tTf(24, 6))
 188:     {
 189:         printf("RCVT:rt=%d, rl=%d, tos=", rtype, rlen);
 190:         prstack(tos);
 191:     }
 192: #	endif
 193: 
 194:     if (rtype != stype)
 195:     {
 196:         if (rtype == CHAR || stype == CHAR)
 197:             ov_err(BADCONV);    /* bad char to numeric conversion requested */
 198:         if (rtype == FLOAT)
 199:             itof(tos);
 200:         else
 201:         {
 202:             if (rlen == 4)
 203:                 ftoi4(tos);
 204:             else
 205:                 ftoi2(tos);
 206:         }
 207:         tos->len = rlen;    /* handles conversion to i1 or f4 */
 208:     }
 209: 
 210:     else
 211:         if (rtype != CHAR && rlen != slen)
 212:         {
 213:             if (rtype == INT)
 214:             {
 215:                 if (rlen == 4)
 216:                     i2toi4(tos);
 217:                 else
 218:                     if (slen == 4)
 219:                         i4toi2(tos);
 220:             }
 221:             tos->len = rlen;    /* handles conversion to i1 or f4 */
 222:         }
 223: }

Defined functions

getsymbol defined in line 27; used 3 times
tout defined in line 131; used 2 times
Last modified: 1995-03-02
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3325
Valid CSS Valid XHTML 1.0 Strict