[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.5

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.5     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/parse/pvar.c,v 1.4 2000/09/21 09:19:27 noro Exp $
1.2       noro       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:
1.5     ! noro      178: #if defined(VISUAL)
1.1       noro      179:        fclose(asir_infile->fp);
                    180:        unlink(asir_infile->tname);
                    181: #else
                    182:        PCLOSE(asir_infile->fp);
                    183: #endif
                    184:        asir_infile = NEXT(asir_infile);
                    185:        resetpvs();
                    186: }
                    187:
                    188: void resetpvs()
                    189: {
                    190:        if ( !NEXT(asir_infile) ) {
                    191:                PVSS = 0; CPVS = GPVS; nextbp = 0;
                    192:                if ( EPVS->va ) {
                    193:                        bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
                    194:                }
                    195:        }
                    196: }
                    197:
                    198: static NODE saved_PVSS;
                    199: static VS saved_CPVS;
                    200: static int saved_nextbp, saved_nextbplevel;
                    201:
                    202: void savepvs()
                    203: {
                    204:        saved_PVSS = PVSS;
                    205:        saved_CPVS = CPVS;
                    206:        saved_nextbp = nextbp;
                    207:        saved_nextbplevel = nextbplevel;
                    208: }
                    209:
                    210: void restorepvs()
                    211: {
                    212:        PVSS = saved_PVSS;
                    213:        CPVS = saved_CPVS;
                    214:        nextbp = saved_nextbp;
                    215:        nextbplevel = saved_nextbplevel;
                    216: }
                    217:
                    218: void storeans(p)
                    219: pointer p;
                    220: {
                    221:        if ( APVS->asize == APVS->n )
                    222:                reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
                    223:        APVS->va[APVS->n++].priv = p;
                    224: }
                    225:
                    226: #if 0
                    227: pointer evalpv(id,tree,f)
                    228: int id;
                    229: NODE2 tree;
                    230: pointer f;
                    231: {
                    232:        pointer a,val = 0;
                    233:        pointer *addr;
                    234:        int pv;
                    235:        NODE ind,tn;
                    236:
                    237:        switch ( id ) {
                    238:                case I_PRESELF:
                    239:                        getmemberp((FNODE)tree,(Obj **)&addr);
                    240:                        (*((ARF)f)->fp)(CO,*addr,ONE,&val); *addr = val; break;
                    241:                case I_POSTSELF:
                    242:                        getmemberp((FNODE)tree,(Obj **)&addr);
                    243:                        val = *addr; (*((ARF)f)->fp)(CO,*addr,ONE,&a); *addr = a; break;
                    244:                case I_PVAR:
                    245:                        pv = (int)BDY1(tree); ind = (NODE)BDY2(tree); GETPV(pv,a);
                    246:                        if ( !ind )
                    247:                                val = a;
                    248:                        else {
                    249:                                evalnodebody(ind,&tn); getarray(a,tn,&val);
                    250:                        }
                    251:                        break;
                    252:                case I_ASSPVAR:
                    253:                        pv = (int)BDY1(tree); ind = (NODE)BDY2(tree);
                    254:                        if ( !ind ) {
                    255:                                val = eval(f); ASSPV(pv,val);
                    256:                        } else {
                    257:                                GETPV(pv,a);
                    258:                                if ( a ) {
                    259:                                        evalnodebody(ind,&tn); putarray(a,tn,val = eval(f));
                    260:                                }
                    261:                        }
                    262:                        break;
                    263:        }
                    264:        return val;
                    265: }
                    266: #endif

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