1: # include   "../ingres.h"
   2: # include   "decomp.h"
   3: 
   4: # define    FIRSTNUM    MAXRANGE + 3
   5: # define    LASTNUM     100
   6: 
   7: /*
   8: **	Internal numbers are used in decomp to
   9: **	represent relation names. The numbers
  10: **	from 0 to FIRSTNUM-1 refer to the names
  11: **	stored in Name_table[].
  12: **
  13: **	The number from FIRSTNUM to LASTNUM have
  14: **	names which are computed from aa, ab, etc.
  15: */
  16: char    Name_table[FIRSTNUM-1][MAXNAME];
  17: 
  18: char    Num_used[LASTNUM+1];
  19: 
  20: 
  21: rnum_assign(name)
  22: char    *name;
  23: 
  24: /*
  25: **	Assign an internal number rnum to name.
  26: */
  27: 
  28: {
  29:     register int    i;
  30: 
  31:     for (i = 0; i < FIRSTNUM; i++)
  32:         if (Num_used[i] == 0)
  33:         {
  34:             bmove(name, Name_table[i], MAXNAME);
  35:             Num_used[i]++;
  36:             return (i);
  37:         }
  38:     syserr("rnum_assign:no room");
  39: }
  40: 
  41: rnum_alloc()
  42: 
  43: /*
  44: **	Allocate the next available name
  45: */
  46: 
  47: {
  48:     register int    i;
  49:     register char   *cp;
  50: 
  51:     cp = &Num_used[FIRSTNUM];
  52:     for (i = FIRSTNUM; i < LASTNUM; i++)
  53:         if (*cp++ == 0)
  54:         {
  55:             --cp;
  56:             (*cp)++;
  57:             return (i);
  58:         }
  59:     syserr("no free names");
  60: }
  61: 
  62: 
  63: char *rnum_convert(num)
  64: int num;
  65: 
  66: /*
  67: **	Convert internal relation number
  68: **	to its real name. Guarantee '\0' at end.
  69: */
  70: 
  71: {
  72:     register int    i;
  73:     register char   *ret, *cp;
  74:     static char temp[MAXNAME+1];
  75:     extern char *Fileset;
  76:     extern char *concat();
  77: 
  78:     i = num;
  79:     if (i > LASTNUM || Num_used[i] == 0)
  80:         syserr("no name for %d", i);
  81: 
  82:     ret = temp;
  83: 
  84:     if (i < FIRSTNUM)
  85:     {
  86:         bmove(Name_table[i], ret, MAXNAME);
  87:     }
  88:     else
  89:     {
  90:         /* compute temp name */
  91:         cp = concat("_SYS", Fileset, ret);
  92:         pad(ret, MAXNAME);
  93:         i -= FIRSTNUM;
  94:         *cp++ = i/26 + 'a';
  95:         *cp = i%26 + 'a';
  96:     }
  97:     return (ret);
  98: }
  99: 
 100: rnum_remove(num)
 101: int num;
 102: 
 103: /*
 104: **	Remove a num from the used list
 105: */
 106: 
 107: {
 108:     register int    i;
 109:     register char   *cp;
 110: 
 111:     cp = &Num_used[num];
 112: 
 113:     if (*cp == 0)
 114:         syserr("cant remove %d", num);
 115:     *cp = 0;
 116: }
 117: 
 118: 
 119: rnum_last()
 120: 
 121: /*
 122: **	returns number of largest assigned temp number.
 123: **	zero if none
 124: */
 125: 
 126: {
 127:     register int    i;
 128:     register char   *cp;
 129: 
 130:     for (i = LASTNUM; i >= FIRSTNUM; i--)
 131:         if (Num_used[i])
 132:             return (i);
 133: 
 134:     return (0);
 135: }
 136: 
 137: 
 138: rnum_temp(rnum)
 139: int rnum;
 140: 
 141: /*
 142: **	Predicate to check whether rnum is a temporary relation or not
 143: */
 144: 
 145: {
 146:     register int    i;
 147: 
 148:     i = rnum;
 149: 
 150:     return (i >= FIRSTNUM || bequal("_SYS", rnum_convert(i), 4));
 151: }
 152: 
 153: rnum_init()
 154: 
 155: /*
 156: **	Clear tag fields from previous query
 157: */
 158: 
 159: {
 160:     register char   *cp;
 161:     register int    i;
 162: 
 163:     cp = Num_used;
 164:     i = FIRSTNUM;
 165:     while (--i)
 166:         *cp++ = 0;
 167: }

Defined functions

rnum_last defined in line 119; used 1 times
rnum_remove defined in line 100; used 1 times

Defined variables

Name_table defined in line 16; used 2 times
Num_used defined in line 18; used 7 times

Defined macros

FIRSTNUM defined in line 4; used 9 times
LASTNUM defined in line 5; used 4 times
Last modified: 1995-04-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3278
Valid CSS Valid XHTML 1.0 Strict