Annotation of OpenXM_contrib2/asir2000/parse/pvar.c, Revision 1.6
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.6 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/parse/pvar.c,v 1.5 2000/12/05 01:24:57 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()
1.6 ! noro 56: {
1.1 noro 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:
1.6 ! noro 66: void pushpvs(FUNC f)
1.1 noro 67: {
68: VS pvs;
69: NODE node;
70: int level;
71: extern int evalstatline;
72:
73: pvs = f->f.usrf->pvs;
74: if ( PVSS ) {
75: ((VS)BDY(PVSS))->at = evalstatline;
76: level = ((VS)BDY(PVSS))->level+1;
77: } else
78: level = 1;
79: MKNODE(node,pvs,PVSS);
80: PVSS = node;
81: CPVS = (VS)MALLOC(sizeof(struct oVS)); BDY(PVSS) = (pointer)CPVS;
82: CPVS->usrf = f;
83: CPVS->n = CPVS->asize = pvs->n;
84: CPVS->level = level;
85: if ( CPVS->n ) {
86: CPVS->va = (struct oPV *)MALLOC(CPVS->n*sizeof(struct oPV));
87: bcopy((char *)pvs->va,(char *)CPVS->va,(int)(pvs->n*sizeof(struct oPV)));
88: }
89: if ( nextbp )
90: nextbplevel++;
91: }
92:
93: void poppvs() {
94: PVSS = NEXT(PVSS);
95: if ( PVSS )
96: CPVS = (VS)BDY(PVSS);
97: else
98: CPVS = GPVS;
99: if ( nextbp )
100: nextbplevel--;
101: }
102:
103: int gdef;
104:
1.6 ! noro 105: int makepvar(char *str)
1.1 noro 106: {
107: int c;
108:
109: c = getpvar(CPVS,str,0);
110: if ( gdef ) {
111: getpvar(EPVS,str,0);
112: if ( CPVS != GPVS ) {
113: getpvar(GPVS,str,0);
114: CPVS->va[c].attr = 1;
115: }
116: } else if ( (CPVS != GPVS) &&
117: (CPVS->va[c].attr || (getpvar(EPVS,str,1) >= 0)) ) {
118: CPVS->va[c].attr = 1;
119: c = (getpvar(GPVS,str,1)|MSB);
120: }
121: return c;
122: }
123:
124: extern FUNC parse_targetf;
125:
1.6 ! noro 126: int searchpvar(char *str)
1.1 noro 127: {
128: VS pvs;
129: int i;
130:
131: if ( parse_targetf && parse_targetf->id != A_USR )
132: return -1;
133: pvs = parse_targetf ? parse_targetf->f.usrf->pvs : GPVS;
134: i = getpvar(pvs,str,1);
135: if ( ((i>=0)&&pvs->va[i].attr) || (i<0) )
136: return getpvar(GPVS,str,1)|MSB;
137: else
138: return i;
139: }
140:
1.6 ! noro 141: int getpvar(VS pvs,char *str,int searchonly)
1.1 noro 142: {
143: struct oPV *va;
144: PV v;
145: int i;
146:
147: for ( va = pvs->va, i = 0; i < (int)pvs->n; i++ )
148: if ( va[i].name && !strcmp(va[i].name,str) )
149: return i;
150: if ( searchonly )
151: return -1;
152: if ( pvs->asize == pvs->n )
153: reallocarray((char **)&pvs->va,(int *)&pvs->asize,(int *)&pvs->n,(int)sizeof(struct oPV));
154: v = &pvs->va[pvs->n];
155: NAME(v) = (char *)CALLOC(strlen(str)+1,sizeof(char));
156: strcpy(NAME(v),str); v->priv = 0;
157: v->attr= 0; v->type = -1; i = pvs->n; pvs->n++;
158: return i;
159: }
160:
161: #if defined(VISUAL)
162: #define PCLOSE _pclose
163: #else
164: #define PCLOSE pclose
165: #endif
166:
167: void closecurrentinput()
168: {
169: if ( asir_infile && !asir_infile->fp )
170: return;
171:
1.5 noro 172: #if defined(VISUAL)
1.1 noro 173: fclose(asir_infile->fp);
174: unlink(asir_infile->tname);
175: #else
176: PCLOSE(asir_infile->fp);
177: #endif
178: asir_infile = NEXT(asir_infile);
179: resetpvs();
180: }
181:
182: void resetpvs()
183: {
184: if ( !NEXT(asir_infile) ) {
185: PVSS = 0; CPVS = GPVS; nextbp = 0;
186: if ( EPVS->va ) {
187: bzero((char *)EPVS->va,(int)(EPVS->asize*sizeof(struct oPV))); EPVS->n = 0;
188: }
189: }
190: }
191:
192: static NODE saved_PVSS;
193: static VS saved_CPVS;
194: static int saved_nextbp, saved_nextbplevel;
195:
196: void savepvs()
197: {
198: saved_PVSS = PVSS;
199: saved_CPVS = CPVS;
200: saved_nextbp = nextbp;
201: saved_nextbplevel = nextbplevel;
202: }
203:
204: void restorepvs()
205: {
206: PVSS = saved_PVSS;
207: CPVS = saved_CPVS;
208: nextbp = saved_nextbp;
209: nextbplevel = saved_nextbplevel;
210: }
211:
1.6 ! noro 212: void storeans(pointer p)
1.1 noro 213: {
214: if ( APVS->asize == APVS->n )
215: reallocarray((char **)&APVS->va,(int *)&APVS->asize,(int *)&APVS->n,(int)sizeof(struct oPV));
216: APVS->va[APVS->n++].priv = p;
217: }
218:
219: #if 0
1.6 ! noro 220: pointer evalpv(int id,NODE2 tree,pointer f)
1.1 noro 221: {
222: pointer a,val = 0;
223: pointer *addr;
224: int pv;
225: NODE ind,tn;
226:
227: switch ( id ) {
228: case I_PRESELF:
229: getmemberp((FNODE)tree,(Obj **)&addr);
230: (*((ARF)f)->fp)(CO,*addr,ONE,&val); *addr = val; break;
231: case I_POSTSELF:
232: getmemberp((FNODE)tree,(Obj **)&addr);
233: val = *addr; (*((ARF)f)->fp)(CO,*addr,ONE,&a); *addr = a; break;
234: case I_PVAR:
235: pv = (int)BDY1(tree); ind = (NODE)BDY2(tree); GETPV(pv,a);
236: if ( !ind )
237: val = a;
238: else {
239: evalnodebody(ind,&tn); getarray(a,tn,&val);
240: }
241: break;
242: case I_ASSPVAR:
243: pv = (int)BDY1(tree); ind = (NODE)BDY2(tree);
244: if ( !ind ) {
245: val = eval(f); ASSPV(pv,val);
246: } else {
247: GETPV(pv,a);
248: if ( a ) {
249: evalnodebody(ind,&tn); putarray(a,tn,val = eval(f));
250: }
251: }
252: break;
253: }
254: return val;
255: }
256: #endif
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>