|
|
1.1 ! root 1: # include <ingres.h> ! 2: # include <catalog.h> ! 3: # include <tree.h> ! 4: # include <symbol.h> ! 5: # include <sccs.h> ! 6: ! 7: SCCSID(@(#)gettree.c 7.1 2/5/81) ! 8: ! 9: ! 10: /* ! 11: ** GETTREE -- get tree from 'tree' catalog ! 12: ** ! 13: ** This function, given an internal treeid, fetches and builds ! 14: ** that tree from the 'tree' catalog. There is nothing exciting ! 15: ** except the mapping of variables, done by mapvars(). ! 16: ** ! 17: ** Parameters: ! 18: ** treeid -- internal id of tree to fetch and build. ! 19: ** init -- passed to 'readqry' to tell whether or not ! 20: ** to initialize the query buffer. ! 21: ** ! 22: ** Returns: ! 23: ** Pointer to root of tree. ! 24: ** ! 25: ** Side Effects: ! 26: ** file activity. Space in Qbuf is used up. ! 27: ** ! 28: ** Trace Flags: ! 29: ** 13 ! 30: */ ! 31: ! 32: QTREE * ! 33: gettree(treerelid, treeowner, treetype, treeid, init) ! 34: char *treerelid; ! 35: char *treeowner; ! 36: char treetype; ! 37: int treeid; ! 38: int init; ! 39: { ! 40: register QTREE *t; ! 41: extern int relntrrd(); ! 42: register int i; ! 43: extern QTREE *readqry(); ! 44: ! 45: /* initialize relntrrd() for this treeid */ ! 46: relntrrd(0, NULL, 0, treerelid, treeowner, treetype, treeid); ! 47: ! 48: /* read and build query tree */ ! 49: t = readqry(relntrrd, 0, init); ! 50: ! 51: /* remap varno's to be unique */ ! 52: if (!init) ! 53: mapvars(t); ! 54: ! 55: return (t); ! 56: } ! 57: /* ! 58: ** RELNTRRD -- read tree from 'tree' relation ! 59: ** ! 60: ** This looks exactly like the 'pipetrrd' call, except that info ! 61: ** comes from the 'tree' talolog instead of from the pipe. It ! 62: ** must be initialized by calling it with a NULL pointer and ! 63: ** the segment name wanted as 'treeid'. ! 64: ** ! 65: ** Parameters: ! 66: ** dummyx -- a placeholder parameter to make this ! 67: ** routine compatible with pb_get. ! 68: ** ptr -- NULL -- "initialize". ! 69: ** else -- pointer to read area. ! 70: ** cnt -- count of number of bytes to read. ! 71: ** treerelid -- if ptr == NULL, the relation name ! 72: ** associated with the tree; ignored otherwise. ! 73: ** treeowner -- if ptr == NULL, the owner of the relation ! 74: ** associated with the tree; ignored otherwise. ! 75: ** treetype -- if ptr == NULL, the type of the tree ! 76: ** (view, prot, etc.); ignored otherwise. ! 77: ** treeid -- if ptr == NULL, this is the tree id, ! 78: ** otherwise this parameter is not supplied. ! 79: ** ! 80: ** Returns: ! 81: ** count of actual number of bytes read. ! 82: ** ! 83: ** Side Effects: ! 84: ** activity in database. ! 85: ** static variables are adjusted correctly. Note that ! 86: ** this routine can be used on only one tree ! 87: ** at one time. ! 88: */ ! 89: ! 90: relntrrd(dummyx, ptr, cnt, treerelid, treeowner, treetype, treeid) ! 91: char *ptr; ! 92: int cnt; ! 93: char *treerelid; ! 94: char *treeowner; ! 95: char treetype; ! 96: int treeid; ! 97: { ! 98: static struct tree trseg; ! 99: static char *trp; ! 100: static int seqno; ! 101: register char *p; ! 102: register int n; ! 103: register int i; ! 104: struct tree trkey; ! 105: TID tid; ! 106: extern DESC Treedes; ! 107: ! 108: p = ptr; ! 109: n = cnt; ! 110: ! 111: if (p == NULL) ! 112: { ! 113: /* initialize -- make buffer appear empty */ ! 114: trp = &trseg.treetree[sizeof trseg.treetree]; ! 115: bmove(treerelid, trseg.treerelid, MAXNAME); ! 116: bmove(treeowner, trseg.treeowner, 2); ! 117: trseg.treetype = treetype; ! 118: trseg.treeid = treeid; ! 119: seqno = 0; ! 120: opencatalog("tree", 0); ! 121: ! 122: # ifdef xQTR2 ! 123: if (tTf(13, 6)) ! 124: printf("relntrrd: n=%.12s o=%.2s t=%d i=%d\n", ! 125: treerelid, treeowner, treetype, treeid); ! 126: # endif ! 127: ! 128: return (0); ! 129: } ! 130: ! 131: /* fetch characters */ ! 132: while (n-- > 0) ! 133: { ! 134: /* check for segment empty */ ! 135: if (trp >= &trseg.treetree[sizeof trseg.treetree]) ! 136: { ! 137: /* then read new segment */ ! 138: clearkeys(&Treedes); ! 139: setkey(&Treedes, &trkey, trseg.treerelid, TREERELID); ! 140: setkey(&Treedes, &trkey, trseg.treeowner, TREEOWNER); ! 141: setkey(&Treedes, &trkey, &trseg.treetype, TREETYPE); ! 142: setkey(&Treedes, &trkey, &trseg.treeid, TREEID); ! 143: setkey(&Treedes, &trkey, &seqno, TREESEQ); ! 144: seqno++; ! 145: if ((i = getequal(&Treedes, &trkey, &trseg, &tid)) != 0) ! 146: syserr("relnrdtr: getequal %d", i); ! 147: trp = &trseg.treetree[0]; ! 148: } ! 149: ! 150: /* do actual character fetch */ ! 151: *p++ = *trp++; ! 152: } ! 153: ! 154: return (cnt); ! 155: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.