Annotation of OpenXM_contrib2/asir2000/builtin/subst.c, Revision 1.7
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.7 ! noro 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/subst.c,v 1.6 2003/11/27 08:28:40 noro Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52:
1.4 noro 53: void Psubst(), Ppsubst(), Psubstf(), Psubst_quote();
1.1 noro 54:
55: struct ftab subst_tab[] = {
56: {"subst",Psubst,-99999999},
1.4 noro 57: {"subst_quote",Psubst_quote,-99999999},
1.1 noro 58: {"psubst",Ppsubst,-99999999},
59: {"substf",Psubstf,-99999999},
60: {0,0,0},
61: };
62:
63: void Psubst(arg,rp)
64: NODE arg;
65: Obj *rp;
66: {
67: Obj a,b,t;
68: LIST l;
69: V v;
1.6 noro 70: int row,col,len;
71: VECT vect;
72: MAT mat;
73: int i,j;
74: NODE n0,n,nd;
75: struct oNODE arg0;
76: MP m,mp,mp0;
77: DP d;
1.1 noro 78:
79: if ( !arg ) {
80: *rp = 0; return;
81: }
1.6 noro 82: a = (Obj)ARG0(arg);
83: if ( !a ) {
84: *rp = 0;
85: return;
86: }
87: switch ( OID(a) ) {
88: case O_N: case O_P: case O_R:
89: reductr(CO,(Obj)ARG0(arg),&a);
90: arg = NEXT(arg);
91: if ( arg && (l = (LIST)ARG0(arg)) && OID(l) == O_LIST )
92: arg = BDY(l);
93: while ( arg ) {
1.7 ! noro 94: if ( !BDY(arg) || OID((Obj)BDY(arg)) != O_P )
! 95: error("subst : invalid argument");
1.6 noro 96: v = VR((P)BDY(arg)); arg = NEXT(arg);
97: if ( !arg )
98: error("subst : invalid argument");
99: asir_assert(ARG0(arg),O_R,"subst");
100: reductr(CO,(Obj)BDY(arg),&b); arg = NEXT(arg);
101: /* b = (Obj)BDY(arg); arg = NEXT(arg); */
102: substr(CO,0,a,v,b,&t); a = t;
103: }
104: *rp = a;
105: break;
106: case O_LIST:
107: n0 = 0;
108: for ( nd = BDY((LIST)a); nd; nd = NEXT(nd) ) {
109: NEXTNODE(n0,n);
110: arg0.body = (pointer)BDY(nd);
111: arg0.next = NEXT(arg);
112: Psubst(&arg0,&b);
113: BDY(n) = (pointer)b;
114: }
115: if ( n0 )
116: NEXT(n) = 0;
117: MKLIST(l,n0);
118: *rp = (Obj)l;
119: break;
120: case O_VECT:
121: len = ((VECT)a)->len;
122: MKVECT(vect,len);
123: for ( i = 0; i < len; i++ ) {
124: arg0.body = (pointer)BDY((VECT)a)[i];
125: arg0.next = NEXT(arg);
126: Psubst(&arg0,&b);
127: BDY(vect)[i] = (pointer)b;
128: }
129: *rp = (Obj)vect;
130: break;
131: case O_MAT:
132: row = ((MAT)a)->row;
133: col = ((MAT)a)->col;
134: MKMAT(mat,row,col);
135: for ( i = 0; i < row; i++ )
136: for ( j = 0; j < col; j++ ) {
137: arg0.body = (pointer)BDY((MAT)a)[i][j];
138: arg0.next = NEXT(arg);
139: Psubst(&arg0,&b);
140: BDY(mat)[i][j] = (pointer)b;
141: }
142: *rp = (Obj)mat;
143: break;
144: case O_DP:
145: mp0 = 0;
146: for ( m = BDY((DP)a); m; m = NEXT(m) ) {
147: arg0.body = (pointer)C(m);
148: arg0.next = NEXT(arg);
149: Psubst(&arg0,&b);
150: if ( b ) {
151: NEXTMP(mp0,mp);
152: C(mp) = (P)b;
153: mp->dl = m->dl;
154: }
155: }
156: if ( mp0 ) {
157: MKDP(NV((DP)a),mp0,d);
158: d->sugar = ((DP)a)->sugar;
159: *rp = (Obj)d;
160: } else
161: *rp = 0;
162:
163: break;
164: default:
165: error("subst invalid argument");
1.1 noro 166: }
1.4 noro 167: }
168:
169: FNODE subst_in_fnode();
170:
171: void Psubst_quote(arg,rp)
172: NODE arg;
173: QUOTE *rp;
174: {
1.5 noro 175: QUOTE h;
1.4 noro 176: FNODE fn;
177: Obj g;
178: LIST l;
179: V v;
180:
181: if ( !arg ) {
182: *rp = 0; return;
183: }
184: asir_assert(ARG0(arg),O_QUOTE,"subst_quote");
185: fn = BDY((QUOTE)ARG0(arg)); arg = NEXT(arg);
186: if ( arg && (l = (LIST)ARG0(arg)) && OID(l) == O_LIST )
187: arg = BDY(l);
188: while ( arg ) {
189: asir_assert(BDY(arg),O_P,"subst_quote");
190: v = VR((P)BDY(arg)); arg = NEXT(arg);
191: if ( !arg )
192: error("subst_quote : invalid argument");
193: g = (Obj)ARG0(arg); arg = NEXT(arg);
194: if ( !g || OID(g) != O_QUOTE )
195: objtoquote(g,&h);
196: else
197: h = (QUOTE)g;
198: fn = subst_in_fnode(fn,v,BDY(h));
199: }
200: MKQUOTE(*rp,fn);
1.1 noro 201: }
202:
203: void Ppsubst(arg,rp)
204: NODE arg;
205: Obj *rp;
206: {
207: Obj a,b,t;
208: LIST l;
209: V v;
210:
211: if ( !arg ) {
212: *rp = 0; return;
213: }
214: asir_assert(ARG0(arg),O_R,"psubst");
215: reductr(CO,(Obj)ARG0(arg),&a);
216: /* a = (Obj)ARG0(arg); */
217: arg = NEXT(arg);
218: if ( arg && (l = (LIST)ARG0(arg)) && OID(l) == O_LIST )
219: arg = BDY(l);
220: while ( arg ) {
221: asir_assert(BDY(arg),O_P,"psubst");
222: v = VR((P)BDY(arg)); arg = NEXT(arg);
223: if ( !arg )
224: error("psubst : invalid argument");
225: asir_assert(ARG0(arg),O_R,"psubst");
226: reductr(CO,(Obj)BDY(arg),&b); arg = NEXT(arg);
227: /* b = (Obj)BDY(arg); arg = NEXT(arg); */
228: substr(CO,1,a,v,b,&t); a = t;
229: }
230: *rp = a;
231: }
232:
233: void Psubstf(arg,rp)
234: NODE arg;
235: Obj *rp;
236: {
237: Obj a,t;
238: LIST l;
239: V v,f;
240:
241: if ( !arg ) {
242: *rp = 0; return;
243: }
244: asir_assert(ARG0(arg),O_R,"substf");
245: reductr(CO,(Obj)ARG0(arg),&a);
246: /* a = (Obj)ARG0(arg); */
247: arg = NEXT(arg);
248: if ( arg && (l = (LIST)ARG0(arg)) && OID(l) == O_LIST )
249: arg = BDY(l);
250: while ( arg ) {
251: asir_assert(BDY(arg),O_P,"substf");
252: v = VR((P)BDY(arg)); arg = NEXT(arg);
253: if ( !arg || (int)v->attr != V_SR )
254: error("substf : invalid argument");
255: f = VR((P)BDY(arg)); arg = NEXT(arg);
256: if ( (int)f->attr != V_SR )
257: error("substf : invalid argument\n");
258: substfr(CO,a,((FUNC)v->priv)->f.puref,((FUNC)f->priv)->f.puref,&t);
259: a = t;
260: }
261: *rp = a;
262: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>