[BACK]Return to struct.c CVS log [TXT][DIR] Up to [local] / OpenXM_contrib2 / asir2000 / parse

Annotation of OpenXM_contrib2/asir2000/parse/struct.c, Revision 1.4

1.2       noro        1: /*
                      2:  * Copyright (c) 1994-2000 FUJITSU LABORATORIES LIMITED
                      3:  * All rights reserved.
                      4:  *
                      5:  * FUJITSU LABORATORIES LIMITED ("FLL") hereby grants you a limited,
                      6:  * non-exclusive and royalty-free license to use, copy, modify and
                      7:  * redistribute, solely for non-commercial and non-profit purposes, the
                      8:  * computer program, "Risa/Asir" ("SOFTWARE"), subject to the terms and
                      9:  * conditions of this Agreement. For the avoidance of doubt, you acquire
                     10:  * only a limited right to use the SOFTWARE hereunder, and FLL or any
                     11:  * third party developer retains all rights, including but not limited to
                     12:  * copyrights, in and to the SOFTWARE.
                     13:  *
                     14:  * (1) FLL does not grant you a license in any way for commercial
                     15:  * purposes. You may use the SOFTWARE only for non-commercial and
                     16:  * non-profit purposes only, such as academic, research and internal
                     17:  * business use.
                     18:  * (2) The SOFTWARE is protected by the Copyright Law of Japan and
                     19:  * international copyright treaties. If you make copies of the SOFTWARE,
                     20:  * with or without modification, as permitted hereunder, you shall affix
                     21:  * to all such copies of the SOFTWARE the above copyright notice.
                     22:  * (3) An explicit reference to this SOFTWARE and its copyright owner
                     23:  * shall be made on your publication or presentation in any form of the
                     24:  * results obtained by use of the SOFTWARE.
                     25:  * (4) In the event that you modify the SOFTWARE, you shall notify FLL by
1.3       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.2       noro       27:  * for such modification or the source code of the modified part of the
                     28:  * SOFTWARE.
                     29:  *
                     30:  * THE SOFTWARE IS PROVIDED AS IS WITHOUT ANY WARRANTY OF ANY KIND. FLL
                     31:  * MAKES ABSOLUTELY NO WARRANTIES, EXPRESSED, IMPLIED OR STATUTORY, AND
                     32:  * EXPRESSLY DISCLAIMS ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
                     33:  * FOR A PARTICULAR PURPOSE OR NONINFRINGEMENT OF THIRD PARTIES'
                     34:  * RIGHTS. NO FLL DEALER, AGENT, EMPLOYEES IS AUTHORIZED TO MAKE ANY
                     35:  * MODIFICATIONS, EXTENSIONS, OR ADDITIONS TO THIS WARRANTY.
                     36:  * UNDER NO CIRCUMSTANCES AND UNDER NO LEGAL THEORY, TORT, CONTRACT,
                     37:  * OR OTHERWISE, SHALL FLL BE LIABLE TO YOU OR ANY OTHER PERSON FOR ANY
                     38:  * DIRECT, INDIRECT, SPECIAL, INCIDENTAL, PUNITIVE OR CONSEQUENTIAL
                     39:  * DAMAGES OF ANY CHARACTER, INCLUDING, WITHOUT LIMITATION, DAMAGES
                     40:  * ARISING OUT OF OR RELATING TO THE SOFTWARE OR THIS AGREEMENT, DAMAGES
                     41:  * FOR LOSS OF GOODWILL, WORK STOPPAGE, OR LOSS OF DATA, OR FOR ANY
                     42:  * DAMAGES, EVEN IF FLL SHALL HAVE BEEN INFORMED OF THE POSSIBILITY OF
                     43:  * SUCH DAMAGES, OR FOR ANY CLAIM BY ANY OTHER PARTY. EVEN IF A PART
                     44:  * OF THE SOFTWARE HAS BEEN DEVELOPED BY A THIRD PARTY, THE THIRD PARTY
                     45:  * DEVELOPER SHALL HAVE NO LIABILITY IN CONNECTION WITH THE USE,
                     46:  * PERFORMANCE OR NON-PERFORMANCE OF THE SOFTWARE.
                     47:  *
1.4     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/struct.c,v 1.3 2000/08/22 05:04:28 noro Exp $
1.2       noro       49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52: #include "comp.h"
                     53:
                     54: struct oSS oLSS;
                     55: SS LSS = &oLSS;
                     56:
1.4     ! noro       57: int structdef(name,member)
1.1       noro       58: char *name;
                     59: NODE member;
                     60: {
                     61:        int i,j,k,type;
                     62:        SDEF sdef,s;
                     63:        NODE n,ms;
                     64:        char *mname,*sname;
                     65:
1.4     ! noro       66:        /* search the predefined structure */
1.1       noro       67:        for ( s = LSS->sa, i = 0; i < LSS->n; i++ )
                     68:                if ( !strcmp(s[i].name,name) ) {
                     69:                        fprintf(stderr,"redeclaration of %s\n",name); break;
                     70:                }
                     71:        if ( !LSS->sa || ((i == LSS->n)&&(LSS->n==LSS->asize)) )
                     72:                reallocarray((char **)&LSS->sa,(int *)&LSS->asize,(int *)&LSS->n,(int)sizeof(struct oSDEF));
1.4     ! noro       73:        /* sdef = room for new structure definition */
1.1       noro       74:        sdef = &LSS->sa[i];
                     75:        if ( i == LSS->n )
                     76:                LSS->n++;
1.4     ! noro       77:        /* set the name of structure */
1.1       noro       78:        sdef->name = (char *)MALLOC(strlen(name)+1);
                     79:        bcopy(name,sdef->name,strlen(name)+1);
1.4     ! noro       80:        /* count the total number of members */
        !            81:        for ( j = 0, n = member; n; n = NEXT(n), j++ );
1.1       noro       82:        sdef->n = j;
1.4     ! noro       83:        sdef->member = (char **)MALLOC(sdef->n*sizeof(char *));
        !            84:        /* set the names of members */
        !            85:        for ( j = 0, n = member; n; n = NEXT(n), j++ ) {
        !            86:                mname = (char *)MALLOC(strlen((char *)BDY(n))+1);
        !            87:                bcopy((char *)BDY(n),mname,strlen((char *)BDY(n))+1);
        !            88:                sdef->member[j] = mname;
1.1       noro       89:        }
1.4     ! noro       90:        return i;
1.1       noro       91: }
                     92:
                     93: void newstruct(type,rp)
                     94: int type;
                     95: COMP *rp;
                     96: {
                     97:        NEWCOMP(*rp,LSS->sa[type].n); (*rp)->type = type;
                     98: }
                     99:
                    100: int structtoindex(name)
                    101: char *name;
                    102: {
                    103:        SDEF s;
                    104:        int i;
                    105:
                    106:        for ( s = LSS->sa, i = 0; i < LSS->n; i++ )
                    107:                if ( !strcmp(s[i].name,name) )
                    108:                        break;
                    109:        if ( i == LSS->n ) {
                    110:                fprintf(stderr,"%s: undefined structure\n",name); return -1; /* XXX */
                    111:        } else
                    112:                return i;
                    113: }
                    114:
                    115: int membertoindex(type,name)
                    116: int type;
                    117: char *name;
                    118: {
                    119:        SDEF s;
1.4     ! noro      120:        char **member;
1.1       noro      121:        int i;
                    122:
                    123:        s = &LSS->sa[type];
1.4     ! noro      124:        for ( member = s->member, i = 0; i < s->n; i++ )
        !           125:                if ( !strcmp(member[i],name) )
1.1       noro      126:                        break;
1.4     ! noro      127:        if ( i == s->n )
1.1       noro      128:                return -1;
1.4     ! noro      129:        else
1.1       noro      130:                return i;
                    131: }
                    132:
                    133: int getcompsize(type)
                    134: int type;
                    135: {
                    136:        return LSS->sa[type].n;
                    137: }
                    138:
1.4     ! noro      139: #if 0
1.1       noro      140: void getmember(expr,memp)
                    141: FNODE expr;
                    142: Obj *memp;
                    143: {
                    144:        int i;
                    145:        FNODE root;
                    146:        COMP t;
                    147:        PV v0;
                    148:        NODE2 mchain;
                    149:
                    150:        root = (FNODE)FA1(expr); mchain = (NODE2)FA2(expr);
                    151:        if ( ID(root) == I_PVAR ) {
                    152:                i = (int)FA0(root);
                    153:                v0 = i>=0?&CPVS->va[(unsigned int)i]:&GPVS->va[((unsigned int)i)&~MSB];
                    154:                t = (COMP)v0->priv;
                    155:        } else
                    156:                t = (COMP)eval(root);
                    157:        for ( ; mchain; mchain = NEXT(mchain) )
                    158:                t = (COMP)(t->member[(int)BDY1(mchain)]);
                    159:        *memp = (Obj)t;
                    160: }
                    161:
                    162: void getmemberp(expr,addrp)
                    163: FNODE expr;
                    164: Obj **addrp;
                    165: {
                    166:        int i;
                    167:        FNODE root;
                    168:        COMP t;
                    169:        PV v0;
                    170:        COMP *addr;
                    171:        NODE2 mchain;
                    172:
                    173:        root = (FNODE)FA1(expr); mchain = (NODE2)FA2(expr);
                    174:        if ( ID(root) == I_PVAR ) {
                    175:                i = (int)FA0(root);
                    176:                v0 = i>=0?&CPVS->va[(unsigned int)i]:&GPVS->va[((unsigned int)i)&~MSB];
                    177:                addr = (COMP *)&v0->priv;
                    178:        } else {
                    179:                t = (COMP)eval(root);
                    180:                addr = (COMP *)&t;
                    181:        }
                    182:        for ( ; mchain; mchain = NEXT(mchain) )
                    183:                addr = (COMP *)&((*addr)->member[(int)BDY1(mchain)]);
                    184:        *addrp = (Obj *)addr;
                    185: }
                    186:
                    187: void getarrayp(a,ind,addrp)
                    188: Obj a;
                    189: NODE ind;
                    190: Obj **addrp;
                    191: {
                    192:        Obj len,row,col;
                    193:        Obj *addr;
                    194:
                    195:        switch ( OID(a) ) {
                    196:                case O_VECT:
                    197:                        len = (Obj)BDY(ind);
                    198:                        if ( !rangecheck(len,((VECT)a)->len) )
                    199:                                error("getarrayp : Out of range");
                    200:                        else
                    201:                                addr = (Obj *)&(BDY((VECT)a)[QTOS((Q)len)]);
                    202:                        break;
                    203:                case O_MAT:
                    204:                        row = (Obj)BDY(ind); col = (Obj)BDY(NEXT(ind));
                    205:                        if ( !rangecheck(row,((MAT)a)->row)
                    206:                                || !rangecheck(col,((MAT)a)->col) )
                    207:                                error("getarrayp : Out of range");
                    208:                        else
                    209:                                addr = (Obj *)&(BDY((MAT)a)[QTOS((Q)row)][QTOS((Q)col)]);
                    210:                        break;
                    211:                default:
                    212:                                addr = 0;
                    213:                        break;
                    214:        }
                    215:        *addrp = addr;
                    216: }
1.4     ! noro      217: #endif
1.1       noro      218:
1.4     ! noro      219: Obj memberofstruct(a,name)
        !           220: COMP a;
1.1       noro      221: char *name;
                    222: {
                    223:        NODE2 n,*np;
                    224:        int type,ind;
1.4     ! noro      225:        char buf[BUFSIZ];
1.1       noro      226:
1.4     ! noro      227:        if ( !a || OID(a) != O_COMP )
        !           228:                error("object is not a structure");
        !           229:        type = a->type;
        !           230:        ind = membertoindex(type,name);
        !           231:        if ( ind < 0 ) {
        !           232:                sprintf(buf,"structure has no member named `%s'",name);
        !           233:                error(buf);
1.1       noro      234:        }
1.4     ! noro      235:        return (Obj)a->member[ind];
        !           236: }
        !           237:
        !           238: void assign_to_member(a,name,obj)
        !           239: COMP a;
        !           240: char *name;
        !           241: Obj obj;
        !           242: {
        !           243:        NODE2 n,*np;
        !           244:        int type,ind;
        !           245:        char buf[BUFSIZ];
        !           246:
        !           247:        if ( !a || OID(a) != O_COMP )
        !           248:                error("object is not a structure");
        !           249:        type = a->type;
1.1       noro      250:        ind = membertoindex(type,name);
1.4     ! noro      251:        if ( ind < 0 ) {
        !           252:                sprintf(buf,"structure has no member named `%s'",name);
        !           253:                error(buf);
        !           254:        }
        !           255:        a->member[ind] = obj;
1.1       noro      256: }

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>