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

Annotation of OpenXM_contrib2/asir2000/parse/pvar.c, Revision 1.2

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
        !            26:  * e-mail at risa-admin@flab.fujitsu.co.jp of the detailed specification
        !            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:  *
        !            48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/pvar.c,v 1.1.1.1 1999/12/03 07:39:12 noro Exp $
        !            49: */
1.1       noro       50: #include "ca.h"
                     51: #include "parse.h"
                     52:
                     53: NODE PVSS;
                     54:
                     55: void mkpvs()
                     56:  {
                     57:        VS pvs;
                     58:
                     59:        pvs = (VS)MALLOC(sizeof(struct oVS));
                     60:        pvs->va = (struct oPV *)MALLOC(DEFSIZE*sizeof(struct oPV));
                     61:        pvs->n = 0;
                     62:        pvs->asize=DEFSIZE;
                     63:        CPVS = pvs;
                     64: }
                     65:
                     66: void pushpvs(f)
                     67: FUNC f;
                     68: {
                     69:        VS pvs;
                     70:        NODE node;
                     71:        int level;
                     72:        extern int evalstatline;
                     73:
                     74:        pvs = f->f.usrf->pvs;
                     75:        if ( PVSS ) {
                     76:                ((VS)BDY(PVSS))->at = evalstatline;
                     77:                level = ((VS)BDY(PVSS))->level+1;
                     78:        } else
                     79:                level = 1;
                     80:        MKNODE(node,pvs,PVSS);
                     81:        PVSS = node;
                     82:        CPVS = (VS)MALLOC(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS;
                     83:        CPVS->usrf = f;
                     84:        CPVS->n = CPVS->asize = pvs->n;
                     85:        CPVS->level = level;
                     86:        if ( CPVS->n ) {
                     87:                CPVS->va = (struct oPV *)MALLOC(CPVS->n*sizeof(struct oPV));
                     88:                bcopy((char *)pvs->va,(char *)CPVS->va,(int)(pvs->n*sizeof(struct oPV)));
                     89:        }
                     90:        if ( nextbp )
                     91:                nextbplevel++;
                     92: }
                     93:
                     94: void poppvs() {
                     95:        PVSS = NEXT(PVSS);
                     96:        if ( PVSS )
                     97:                CPVS = (VS)BDY(PVSS);
                     98:        else
                     99:                CPVS = GPVS;
                    100:        if ( nextbp )
                    101:                nextbplevel--;
                    102: }
                    103:
                    104: int gdef;
                    105:
                    106: int makepvar(str)
                    107: char *str;
                    108: {
                    109:        int c;
                    110:
                    111:        c = getpvar(CPVS,str,0);
                    112:        if ( gdef ) {
                    113:                getpvar(EPVS,str,0);
                    114:                if ( CPVS != GPVS ) {
                    115:                        getpvar(GPVS,str,0);
                    116:                        CPVS->va[c].attr = 1;
                    117:                }
                    118:        } else if ( (CPVS != GPVS) &&
                    119:                (CPVS->va[c].attr || (getpvar(EPVS,str,1) >= 0)) ) {
                    120:                CPVS->va[c].attr = 1;
                    121:                c = (getpvar(GPVS,str,1)|MSB);
                    122:        }
                    123:        return c;
                    124: }
                    125:
                    126: extern FUNC parse_targetf;
                    127:
                    128: int searchpvar(str)
                    129: char *str;
                    130: {
                    131:        VS pvs;
                    132:        int i;
                    133:
                    134:        if ( parse_targetf && parse_targetf->id != A_USR )
                    135:                return -1;
                    136:        pvs = parse_targetf ? parse_targetf->f.usrf->pvs : GPVS;
                    137:        i = getpvar(pvs,str,1);
                    138:        if ( ((i>=0)&&pvs->va[i].attr) || (i<0) )
                    139:                return getpvar(GPVS,str,1)|MSB;
                    140:        else
                    141:                return i;
                    142: }
                    143:
                    144: int getpvar(pvs,str,searchonly)
                    145: VS pvs;
                    146: char *str;
                    147: int searchonly;
                    148: {
                    149:        struct oPV *va;
                    150:        PV v;
                    151:        int i;
                    152:
                    153:        for ( va = pvs->va, i = 0; i < (int)pvs->n; i++ )
                    154:                if ( va[i].name && !strcmp(va[i].name,str) )
                    155:                        return i;
                    156:        if ( searchonly )
                    157:                return -1;
                    158:        if ( pvs->asize == pvs->n )
                    159:                reallocarray((char **)&pvs->va,(int *)&pvs->asize,(int *)&pvs->n,(int)sizeof(struct oPV));
                    160:        v = &pvs->va[pvs->n];
                    161:        NAME(v) = (char *)CALLOC(strlen(str)+1,sizeof(char));
                    162:        strcpy(NAME(v),str); v->priv = 0;
                    163:        v->attr= 0; v->type = -1; i = pvs->n; pvs->n++;
                    164:        return i;
                    165: }
                    166:
                    167: #if defined(VISUAL)
                    168: #define PCLOSE _pclose
                    169: #else
                    170: #define PCLOSE pclose
                    171: #endif
                    172:
                    173: void closecurrentinput()
                    174: {
                    175:        if ( asir_infile && !asir_infile->fp )
                    176:                return;
                    177:
                    178: #if defined(THINK_C) || defined(VISUAL)
                    179: #if defined(THINK_C)
                    180:        void setDir(short);
                    181:
                    182:        fclose(asir_infile->fp);
                    183:        setDir(asir_infile->vol);
                    184:        unlink(asir_infile->tname);
                    185:        resetDir();
                    186: #else
                    187:        fclose(asir_infile->fp);
                    188:        unlink(asir_infile->tname);
                    189: #endif
                    190: #else
                    191:        PCLOSE(asir_infile->fp);
                    192: #endif
                    193:        asir_infile = NEXT(asir_infile);
                    194:        resetpvs();
                    195: }
                    196:
                    197: void resetpvs()
                    198: {
                    199:        if ( !NEXT(asir_infile) ) {
                    200:                PVSS = 0; CPVS = GPVS; nextbp = 0;
                    201:                if ( EPVS->va ) {
                    202:                        bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
                    203:                }
                    204:        }
                    205: }
                    206:
                    207: static NODE saved_PVSS;
                    208: static VS saved_CPVS;
                    209: static int saved_nextbp, saved_nextbplevel;
                    210:
                    211: void savepvs()
                    212: {
                    213:        saved_PVSS = PVSS;
                    214:        saved_CPVS = CPVS;
                    215:        saved_nextbp = nextbp;
                    216:        saved_nextbplevel = nextbplevel;
                    217: }
                    218:
                    219: void restorepvs()
                    220: {
                    221:        PVSS = saved_PVSS;
                    222:        CPVS = saved_CPVS;
                    223:        nextbp = saved_nextbp;
                    224:        nextbplevel = saved_nextbplevel;
                    225: }
                    226:
                    227: void storeans(p)
                    228: pointer p;
                    229: {
                    230:        if ( APVS->asize == APVS->n )
                    231:                reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
                    232:        APVS->va[APVS->n++].priv = p;
                    233: }
                    234:
                    235: #if 1
                    236: pointer evalpv(id,expr,f)
                    237: int id;
                    238: FNODE expr;
                    239: pointer f;
                    240: {
                    241:        pointer a,val = 0;
                    242:        pointer *addr;
                    243:
                    244:        if ( expr->id != I_PVAR && expr->id != I_CAST )
                    245:                error("evalpv : invalid assignment");
                    246:        switch ( id ) {
                    247:                case I_PRESELF:
                    248:                        getmemberp((FNODE)expr,(Obj **)&addr);
                    249:                        (*((ARF)f)->fp)(CO,*addr,ONE,&val); *addr = val; break;
                    250:                case I_POSTSELF:
                    251:                        getmemberp((FNODE)expr,(Obj **)&addr);
                    252:                        val = *addr; (*((ARF)f)->fp)(CO,*addr,ONE,&a); *addr = a; break;
                    253:                case I_PVAR:
                    254:                        getmember((FNODE)expr,(Obj *)&val); break;
                    255:                case I_ASSPVAR:
                    256:                        getmemberp((FNODE)expr,(Obj **)&addr); *addr = val = eval((FNODE)f); break;
                    257:        }
                    258:        return val;
                    259: }
                    260: #endif
                    261:
                    262: #if 0
                    263: pointer evalpv(id,tree,f)
                    264: int id;
                    265: NODE2 tree;
                    266: pointer f;
                    267: {
                    268:        pointer a,val = 0;
                    269:        pointer *addr;
                    270:        int pv;
                    271:        NODE ind,tn;
                    272:
                    273:        switch ( id ) {
                    274:                case I_PRESELF:
                    275:                        getmemberp((FNODE)tree,(Obj **)&addr);
                    276:                        (*((ARF)f)->fp)(CO,*addr,ONE,&val); *addr = val; break;
                    277:                case I_POSTSELF:
                    278:                        getmemberp((FNODE)tree,(Obj **)&addr);
                    279:                        val = *addr; (*((ARF)f)->fp)(CO,*addr,ONE,&a); *addr = a; break;
                    280:                case I_PVAR:
                    281:                        pv = (int)BDY1(tree); ind = (NODE)BDY2(tree); GETPV(pv,a);
                    282:                        if ( !ind )
                    283:                                val = a;
                    284:                        else {
                    285:                                evalnodebody(ind,&tn); getarray(a,tn,&val);
                    286:                        }
                    287:                        break;
                    288:                case I_ASSPVAR:
                    289:                        pv = (int)BDY1(tree); ind = (NODE)BDY2(tree);
                    290:                        if ( !ind ) {
                    291:                                val = eval(f); ASSPV(pv,val);
                    292:                        } else {
                    293:                                GETPV(pv,a);
                    294:                                if ( a ) {
                    295:                                        evalnodebody(ind,&tn); putarray(a,tn,val = eval(f));
                    296:                                }
                    297:                        }
                    298:                        break;
                    299:        }
                    300:        return val;
                    301: }
                    302: #endif

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