Annotation of 42BSD/ingres/source/parser/att_fcn.c, revision 1.1

1.1     ! root        1: # include      <ingres.h>
        !             2: # include      <aux.h>
        !             3: # include      <tree.h>
        !             4: # include      <symbol.h>
        !             5: # include      "parser.h"
        !             6: # include      <sccs.h>
        !             7: 
        !             8: SCCSID(@(#)att_fcn.c   7.1     2/5/81)
        !             9: 
        !            10: /*
        !            11: ** fake attribute stash entries for tid nodes (and sid in dist version)
        !            12: **     these are provided by the system to a program only for debugging
        !            13: **     the system source and do not have well defined (over time) meanings.
        !            14: */
        !            15: struct atstash Faketid =
        !            16: {
        !            17:        0,      INT,    4,      "tid",  0
        !            18: };
        !            19: #ifdef DISTRIB
        !            20: struct atstash Fakesid
        !            21: {
        !            22:        0,      INT,    4,      "sid",  0
        !            23: };
        !            24: #endif
        !            25: 
        !            26: struct atstash         Attable[MAXATT];/* attrib stash space, turned into a list later */
        !            27: struct atstash         *Freeatt;       /* free list of attrib stash */
        !            28: 
        !            29: /*
        !            30: **  ATT_FCN.C  --  attribute list manipulation routines
        !            31: **
        !            32: **     ATT_FCN ~~ trace flags = 40, 41
        !            33: **
        !            34: **     Defines:
        !            35: **             Attable
        !            36: **             Freeatt
        !            37: **             attinit()
        !            38: **             attlookup()
        !            39: **             attadd()
        !            40: **             attfnd()
        !            41: **             attcheck()
        !            42: **             attfree()
        !            43: **             attalloc()
        !            44: **             attcount()
        !            45: **
        !            46: **     History:
        !            47: **             modified for 6.3 (jiw)
        !            48: */
        !            49: 
        !            50: /*
        !            51: **   ATTINIT -- initializes attribute table
        !            52: **
        !            53: **     Parameters:
        !            54: **             none
        !            55: **
        !            56: **     Trace Flags:
        !            57: **             attinit ~~ 40.0
        !            58: */
        !            59: 
        !            60: attinit()
        !            61: {
        !            62:        register struct atstash         *atptr;
        !            63:        register int                    i;
        !            64: 
        !            65: # ifdef        xPTR3
        !            66:        tTfp(40, 0, "attinit");
        !            67: # endif
        !            68: 
        !            69:        atptr = Attable;
        !            70: 
        !            71:        for (i = 0; i < MAXATT - 1; i++)
        !            72:        {
        !            73:                atptr->atbnext = atptr + 1;
        !            74:                atptr++;
        !            75:        }
        !            76: 
        !            77:        atptr->atbnext = NULL;
        !            78: 
        !            79:        Freeatt = Attable;              /* the first attribute in chain */
        !            80: }
        !            81: 
        !            82: /*
        !            83: **  ATTLOOKUP -- finds attribute entry
        !            84: **
        !            85: **     Attlookup looks up atribute 'attrib' in the att stash
        !            86: **     for range table entry 'slot'.  If the attrib is not
        !            87: **     in the stash it is entered.
        !            88: **
        !            89: **     Parameters:
        !            90: **             attrib -- the name of the attribute to find
        !            91: **             slot -- the number of the range variable
        !            92: **
        !            93: **     Returns:
        !            94: **             pointer to the attstash element
        !            95: **
        !            96: **     Trace Flags:
        !            97: **             attlookup ~~ 40.4, 40.5
        !            98: */
        !            99: 
        !           100: struct atstash *
        !           101: attlookup(slot, attrib)
        !           102: int            slot;
        !           103: char           *attrib;
        !           104: {
        !           105:        register PARRNG                 *rptr;
        !           106:        register struct atstash         *current;
        !           107:        int                             ik;
        !           108:        struct attribute                tuple;
        !           109:        register struct attribute       *ktuple;
        !           110:        struct attribute                ktup;
        !           111:        TID                             tid;
        !           112: 
        !           113:        extern struct atstash           *attfind();
        !           114:        extern struct atstash           *attadd();
        !           115:        extern DESC                     Attdes;
        !           116:        extern PARRNG                   Parrng[];
        !           117: 
        !           118:        rptr = &Parrng[slot];
        !           119: 
        !           120:        ktuple = &ktup;
        !           121: #      ifdef   xPTR2
        !           122:        tTfp(40, 4, "attlookup: att = %s and rel= %s\n", attrib, trim_relname(rptr->vardesc.reldum.relid));
        !           123: #      endif
        !           124: 
        !           125:        /* attribute called "tid" is phantom attribute, use fake */
        !           126:        if (sequal("tid", attrib))
        !           127:                return (&Faketid);
        !           128: #      ifdef   DISTRIB
        !           129:        if (sequal("sid", attrib))
        !           130:                return (&Fakesid);
        !           131: #      endif
        !           132: 
        !           133:        /* check to see if attrib is in stash */
        !           134:        if ((current = attfind(slot, attrib)) != NULL)
        !           135:                return (current);
        !           136: 
        !           137: #      ifdef   xPTR2
        !           138:        tTfp(40, 5, "getting att info from relation\n");
        !           139: #      endif
        !           140: 
        !           141:        /* rel name, owner, attname is unique ident */
        !           142:        clearkeys(&Attdes);
        !           143:        setkey(&Attdes, ktuple, rptr->vardesc.reldum.relid, ATTRELID);
        !           144:        setkey(&Attdes, ktuple, rptr->vardesc.reldum.relowner, ATTOWNER);
        !           145:        setkey(&Attdes, ktuple, attrib, ATTNAME);
        !           146:        if (!(ik = getequal(&Attdes, ktuple, &tuple, &tid)))
        !           147:        {
        !           148:                /* put attrib stuff into att stash */
        !           149:                current = attadd(slot, &tuple);
        !           150:                return (current);
        !           151:        }
        !           152: 
        !           153:        if (ik == 1)
        !           154:                /* attribute not in relation */
        !           155:                par_error(NOATTRIN, WARN, attrib, trim_relname(rptr->vardesc.reldum.relid), 0);
        !           156:        else
        !           157:                syserr("fatal error in getequal, ret: %d", ik);
        !           158: }
        !           159: 
        !           160: /*
        !           161: **  ATTADD -- add an attribute to the list for a particular range variable
        !           162: **
        !           163: **     Parameters:
        !           164: **             slot -- the number of the range variable to use
        !           165: **             tuple -- the attribute tuple to add
        !           166: **
        !           167: **     Returns:
        !           168: **             pointer to the attribute added
        !           169: **
        !           170: **     Trace Flags:
        !           171: **             attadd ~~ 40.8
        !           172: */
        !           173: 
        !           174: struct atstash *
        !           175: attadd(slot, tuple)
        !           176: int                    slot;
        !           177: struct attribute       *tuple;
        !           178: {
        !           179:        register struct atstash *current;
        !           180:        register struct atstash *aptr;
        !           181:        register struct atstash *bptr;
        !           182:        PARRNG                  *rptr;
        !           183:        int                     i;
        !           184: 
        !           185:        extern struct atstash   *attalloc();
        !           186:        extern PARRNG           Parrng[];
        !           187: 
        !           188: # ifdef        xPTR3
        !           189:        tTfp(40, 8, "attadd slot %d, %12s\n", slot, tuple->attname);
        !           190: # endif
        !           191: 
        !           192:        rptr = &Parrng[slot];
        !           193: 
        !           194:        current = attalloc();
        !           195:        current->atbid = tuple->attid;
        !           196:        current->atbfrmt = tuple->attfrmt;
        !           197:        current->atbfrml = tuple->attfrml;
        !           198:        bmove(tuple->attname, current->atbname, MAXNAME);
        !           199:        for (i = 0; i < MAXNAME; i++)
        !           200:                if (current->atbname[i] == ' ')
        !           201:                        current->atbname[i] = '\0';
        !           202: 
        !           203:        aptr = rptr->attlist;
        !           204:        bptr = 0;
        !           205:        while (aptr != 0)
        !           206:        {
        !           207:                if (aptr->atbid > current->atbid)
        !           208:                        break;
        !           209:                bptr = aptr;
        !           210:                aptr = aptr->atbnext;
        !           211:        }
        !           212:        if (bptr == 0)
        !           213:                rptr->attlist = current;
        !           214:        else
        !           215:                bptr->atbnext = current;
        !           216: 
        !           217:        current->atbnext = aptr;
        !           218: 
        !           219:        return (current);
        !           220: }
        !           221: 
        !           222: /*
        !           223: **  ATTFIND -- finds attribute in stash
        !           224: **
        !           225: **     Attfind looks in attribute stash to see if attrib info already there
        !           226: **     return pointer to attribute in attribute table else NULL.
        !           227: **
        !           228: **     Parameters:
        !           229: **             slot -- the number of the entry in range table
        !           230: **             attrib -- the attribute name to find
        !           231: **
        !           232: **     Returns:
        !           233: **             pointer to entry or NULL if not in stash
        !           234: **
        !           235: **     Trace Flags:
        !           236: **             attfind ~~ 40.12
        !           237: */
        !           238: 
        !           239: struct atstash *
        !           240: attfind(slot, attrib)
        !           241: int            slot;
        !           242: register char  *attrib;
        !           243: {
        !           244:        register struct atstash *aptr;
        !           245: 
        !           246:        extern PARRNG           Parrng[];
        !           247: 
        !           248: # ifdef xPTR1
        !           249:        tTfp(40, 12, "attadd\n");
        !           250: # endif
        !           251: 
        !           252:        aptr = Parrng[slot].attlist;
        !           253: 
        !           254:        while (aptr != NULL)
        !           255:        {
        !           256:                if (!scompare(attrib, MAXNAME, aptr->atbname, MAXNAME))
        !           257:                        return (aptr);
        !           258: 
        !           259:                aptr = aptr->atbnext;
        !           260:        }
        !           261:        return (NULL);
        !           262: }
        !           263: 
        !           264: /*
        !           265: **  ATTCHECK -- checks for conflicts in attributes
        !           266: **
        !           267: **     Attcheck checks for type conflicts in the current query domain and
        !           268: **     attable entry
        !           269: **
        !           270: **     Parameters:
        !           271: **             aptr -- pointer to current atttibute
        !           272: **
        !           273: **     Returns:
        !           274: **             nothing
        !           275: **
        !           276: **     Requires:
        !           277: **             Trfrmt -- for current format
        !           278: **
        !           279: **     Trace Flags:
        !           280: **             attcheck ~~ 41.0
        !           281: */
        !           282: 
        !           283: attcheck(aptr)
        !           284: register struct atstash                *aptr;
        !           285: {
        !           286:        extern char             Trfrmt;
        !           287: 
        !           288: # ifdef        xPTR1
        !           289:        tTfp(41, 0, "attcheck\n");
        !           290: # endif
        !           291: 
        !           292:        if ((Trfrmt == CHAR) != (aptr->atbfrmt == CHAR))
        !           293:                /* function type does not match attrib */
        !           294:                par_error(RESTYPE, WARN, aptr->atbname, 0);
        !           295: }
        !           296: 
        !           297: /*
        !           298: **  ATTFREE -- puts a list of attrib space back on the free list
        !           299: **
        !           300: **     Parameters:
        !           301: **             aptr -- pointer to list of attstash entries
        !           302: **
        !           303: **     Returns:
        !           304: **             nothing
        !           305: **
        !           306: **     Requires:
        !           307: **             Freeatt
        !           308: **
        !           309: **     Trace Flags:
        !           310: **             attfree ~~ 41.4
        !           311: */
        !           312: 
        !           313: attfree(aptr)
        !           314: struct atstash *aptr;
        !           315: {
        !           316:        register struct atstash *att;
        !           317: 
        !           318: # ifdef        xPTR1
        !           319:        tTfp(41, 4, "attfree\n");
        !           320: # endif
        !           321: 
        !           322:        if ((att = aptr) == NULL)
        !           323:                return;
        !           324: 
        !           325:        while (att->atbnext != NULL)
        !           326:                att = att->atbnext;
        !           327: 
        !           328:        att->atbnext = Freeatt;
        !           329:        Freeatt = aptr;
        !           330: }
        !           331: 
        !           332: /*
        !           333: **  ATTALLOC -- returns a pointer to a atstash type structure
        !           334: **
        !           335: **     Attalloc checks the freelist (Freeatt) for attstash entries,
        !           336: **     if some is there, one is removed.  If the freelist is empty,
        !           337: **     attstashes are removed from range table entries until an free
        !           338: **     element is found.
        !           339: **
        !           340: **     Parameters:
        !           341: **             none
        !           342: **
        !           343: **     Returns:
        !           344: **             a pointer to an atstash element
        !           345: **
        !           346: **     Requires:
        !           347: **             Rngback
        !           348: **             Freeatt
        !           349: **             
        !           350: **     Trace Flags:
        !           351: **             attalloc ~~ 41.8, 41.9
        !           352: */
        !           353: 
        !           354: struct atstash *
        !           355: attalloc()
        !           356: {
        !           357:        register struct atstash *aptr;
        !           358:        register PARRNG         *rptr;
        !           359: 
        !           360:        extern PARRNG           *Rngback;
        !           361: 
        !           362: # ifdef        xPTR3
        !           363:        tTfp(41, 8, "attalloc Freeatt %d\n", Freeatt);
        !           364: # endif
        !           365: 
        !           366:        /* Note: the following loop doesn't happen if Freeatt != NULL */
        !           367: 
        !           368:        for (rptr = Rngback; Freeatt == NULL; rptr = rptr->frontpt)
        !           369:        {
        !           370:                /*
        !           371:                ** search least recently used vbles for attrib stash space
        !           372:                ** until at least one entry is found
        !           373:                */
        !           374: 
        !           375: # ifdef        xPTR3
        !           376:        tTfp(41, 9, "attalloc: freeing %12s\n", rptr->vardesc.relvname);
        !           377: # endif
        !           378: 
        !           379:                if (rptr == NULL)
        !           380:                        syserr("attalloc: no att space.");
        !           381: 
        !           382:                Freeatt = rptr->attlist;
        !           383:                rptr->attlist = NULL;
        !           384:        }
        !           385:        aptr = Freeatt;
        !           386:        Freeatt = Freeatt->atbnext;
        !           387:        aptr->atbnext = NULL;
        !           388: 
        !           389:        return (aptr);
        !           390: }
        !           391: 
        !           392: /*
        !           393: **  ATTCOUNT -- counts atstash elems
        !           394: **
        !           395: **     Attcount returns a count fof the number of attributes already in the
        !           396: **     attrib stash.
        !           397: **
        !           398: **     Parameter:
        !           399: **             slot -- the range table entry to count
        !           400: **
        !           401: **     Returns:
        !           402: **             count of the attributes
        !           403: **
        !           404: **     Trace Flags:
        !           405: **             attcount ~~ 41.12
        !           406: */
        !           407: 
        !           408: int
        !           409: attcount(slot)
        !           410: int    slot;
        !           411: {
        !           412:        register int            cntr;
        !           413:        register struct atstash *aptr;
        !           414: 
        !           415:        extern PARRNG           Parrng[];
        !           416: 
        !           417: # ifdef        xPTR1
        !           418:        tTfp(41, 12, "attcount\n");
        !           419: # endif
        !           420: 
        !           421:        cntr = 0;
        !           422:        aptr = Parrng[slot].attlist;
        !           423:        while (aptr != NULL)
        !           424:        {
        !           425:                cntr++;
        !           426:                aptr = aptr->atbnext;
        !           427:        }
        !           428:        return (cntr);
        !           429: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.