1: # include <ingres.h> 2: # include <symbol.h> 3: # include <range.h> 4: # include <tree.h> 5: # include <sccs.h> 6: # include <errors.h> 7: 8: SCCSID(@(#)range.c 8.2 2/8/85) 9: 10: 11: 12: /* 13: ** CLRRANGE -- clear range table(s) 14: ** 15: ** Parameters: 16: ** none. 17: ** 18: ** Returns: 19: ** none. 20: ** 21: ** Side Effects: 22: ** The range table (Qt.qt_rangev) is cleared. 23: */ 24: 25: clrrange() 26: { 27: register int i; 28: register DESC *d; 29: 30: for (i = 0; i < MAXRANGE; i++) 31: { 32: Qt.qt_rangev[i].rngvmark = FALSE; 33: Qt.qt_remap[i] = i; 34: d = Qt.qt_rangev[i].rngvdesc; 35: if (d != NULL) 36: { 37: xfree(d); 38: Qt.qt_rangev[i].rngvdesc = NULL; 39: } 40: } 41: } 42: /* 43: ** DECLARE -- declare a range variable 44: ** 45: ** A range variable is declared. If possible, the preferred varno 46: ** stated is used (this is the one already in the tree). This 47: ** should always be possible when reading the original tree (and 48: ** should probably stay this way to make debugging easier). When 49: ** not possible, a new varno is chosen and the tree can later 50: ** be patched up by 'mapvars'. 51: ** 52: ** Parameters: 53: ** varno -- the preferred varno. 54: ** desc -- the descriptor for this range variable. 55: ** 56: ** Returns: 57: ** The actual varno assigned. 58: ** 59: ** Side Effects: 60: ** Qt.qt_rangev is updated. 61: ** 62: ** Trace Flags: 63: ** 7.0-3 64: */ 65: 66: declare(varno, desc) 67: int varno; 68: DESC *desc; 69: { 70: register int i; 71: register int vn; 72: extern char *trim_relname(); 73: 74: vn = varno; 75: 76: /* check for preferred slot in range table available */ 77: if (desc != NULL && Qt.qt_rangev[vn].rngvdesc != NULL) 78: { 79: /* try to find another slot */ 80: for (i = 0; i < MAXRANGE; i++) 81: if (Qt.qt_rangev[i].rngvdesc == NULL) 82: break; 83: 84: if (i >= MAXRANGE) 85: { 86: /* too many variables */ 87: error(TOOMANYVARS, trim_relname(desc->reldum.relid), 0); 88: } 89: 90: vn = i; 91: } 92: 93: /* if clearing, make sure something to clear */ 94: if (desc == NULL && Qt.qt_rangev[vn].rngvdesc == NULL) 95: syserr("declare: null clr %d", vn); 96: 97: /* declare variable in the slot */ 98: Qt.qt_rangev[vn].rngvdesc = desc; 99: Qt.qt_rangev[vn].rngvmark = (desc != NULL); 100: 101: # ifdef xQTR2 102: if (tTf(7, 0)) 103: lprintf("declare(%d, %.14s) into slot %d\n", varno, 104: desc != NULL ? desc->reldum.relid : "(NULL)", vn); 105: # endif 106: 107: return (vn); 108: }