Annotation of OpenXM_contrib2/asir2000/builtin/list.c, Revision 1.9
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.9 ! ohara 48: * $OpenXM: OpenXM_contrib2/asir2000/builtin/list.c,v 1.8 2004/06/22 13:40:44 ohara Exp $
1.2 noro 49: */
1.1 noro 50: #include "ca.h"
51: #include "parse.h"
52:
1.6 saito 53: void Pcar(), Pcdr(), Pcons(), Pappend(), Preverse(), Plength();
1.9 ! ohara 54: void Plist(), Passoc();
1.6 saito 55: void Pnconc(), Preplcd(), Preplca();
1.1 noro 56:
57: struct ftab list_tab[] = {
58: {"car",Pcar,1},
59: {"cdr",Pcdr,1},
60: {"cons",Pcons,2},
61: {"append",Pappend,2},
62: {"reverse",Preverse,1},
63: {"length",Plength,1},
1.6 saito 64: {"nconc",Pnconc,2},
65: {"replcd",Preplcd,2},
66: {"replca",Preplca,2},
1.8 ohara 67: {"list", Plist, -99999999},
1.9 ! ohara 68: {"assoc",Passoc,2},
1.1 noro 69: {0,0,0},
70: };
71:
72: void Pcar(arg,rp)
73: NODE arg;
74: pointer *rp;
75: {
76: asir_assert(ARG0(arg),O_LIST,"car");
77: if ( !BDY((LIST)ARG0(arg)) )
78: *rp = ARG0(arg);
79: else
80: *rp = (pointer)BDY(BDY((LIST)ARG0(arg)));
81: }
82:
83: void Pcdr(arg,rp)
84: NODE arg;
85: LIST *rp;
86: {
87: asir_assert(ARG0(arg),O_LIST,"cdr");
88: if ( !BDY((LIST)ARG0(arg)) )
89: *rp = (LIST)ARG0(arg);
90: else
91: MKLIST(*rp,NEXT(BDY((LIST)ARG0(arg))));
92: }
93:
94: void Pcons(arg,rp)
95: NODE arg;
96: LIST *rp;
97: {
98: NODE t;
99:
100: asir_assert(ARG1(arg),O_LIST,"cons");
101: MKNODE(t,ARG0(arg),BDY((LIST)ARG1(arg))); MKLIST(*rp,t);
102: }
103:
104: void Pappend(arg,rp)
105: NODE arg;
106: LIST *rp;
107: {
108: NODE t,t0,n;
109:
110: asir_assert(ARG0(arg),O_LIST,"append");
111: asir_assert(ARG1(arg),O_LIST,"append");
112: if ( !(n = BDY((LIST)ARG0(arg))) )
113: *rp = (LIST)ARG1(arg);
114: else {
115: for ( t0 = 0; n; n = NEXT(n) ) {
116: NEXTNODE(t0,t); BDY(t) = BDY(n);
117: }
118: NEXT(t) = BDY((LIST)ARG1(arg));
119: MKLIST(*rp,t0);
1.4 saito 120: }
121: }
122:
1.1 noro 123: void Preverse(arg,rp)
124: NODE arg;
125: LIST *rp;
126: {
127: NODE t,t1,n;
128:
129: asir_assert(ARG0(arg),O_LIST,"reverse");
130: if ( !(n = BDY((LIST)ARG0(arg))) )
131: *rp = (LIST)ARG0(arg);
132: else {
133: for ( t = 0; n; n = NEXT(n) ) {
134: MKNODE(t1,BDY(n),t); t = t1;
135: }
136: MKLIST(*rp,t);
137: }
138: }
139:
1.7 ohara 140: void Plength(arg,rp)
141: NODE arg;
142: Q *rp;
143: {
144: NODE n;
145: int i;
146:
147: switch (OID(ARG0(arg))) {
148: case O_VECT:
149: i = ((VECT)ARG0(arg))->len;
150: break;
151: case O_LIST:
152: n = BDY((LIST)ARG0(arg));
153: for ( i = 0; n; i++, n = NEXT(n) );
154: break;
155: default:
156: error("length : invalid argument"); break;
157: }
158: STOQ(i,*rp);
1.8 ohara 159: }
160:
161: void Plist(NODE arg, LIST *rp)
162: {
163: MKLIST(*rp,arg);
1.6 saito 164: }
165:
166: void Pnconc(arg,rp)
167: NODE arg;
168: LIST *rp;
169: {
170: NODE a1,a2,n;
171:
172: asir_assert(ARG0(arg),O_LIST,"nconc");
173: asir_assert(ARG1(arg),O_LIST,"nconc");
174: a1 = BDY((LIST)ARG0(arg));
175: if ( !a1 )
176: *rp = (LIST)ARG1(arg);
177: else {
178: for ( n = a1; n; n = NEXT(n) ) {
179: a2 = n;
180: }
181: NEXT(a2) = BDY((LIST)ARG1(arg));
182: *rp = (LIST)ARG0(arg);
183: }
184: }
185:
186: void Preplcd(arg,rp)
187: NODE arg;
188: LIST *rp;
189: {
190: NODE a0,a1;
191:
192: asir_assert(ARG0(arg),O_LIST,"replcd");
193: asir_assert(ARG1(arg),O_LIST,"replcd");
194: a0 = BDY((LIST)ARG0(arg));
195: if ( !a0 )
196: *rp = (LIST)ARG0(arg);
197: else {
198: NEXT(a0) = BDY((LIST)ARG1(arg));
199: *rp = (LIST)ARG0(arg);
200: }
201: }
202:
203: void Preplca(arg,rp)
204: NODE arg;
205: LIST *rp;
206: {
207: NODE n;
208:
209: asir_assert(ARG0(arg),O_LIST,"replca");
210: if ( !(n = BDY((LIST)ARG0(arg)) ) )
211: *rp = (LIST)ARG0(arg);
212: else {
213: BDY(BDY((LIST)ARG0(arg))) = (LIST)ARG1(arg);
214: *rp = (LIST)ARG0(arg);
215: }
1.9 ! ohara 216: }
! 217:
! 218: void Passoc(NODE arg, LIST *rp)
! 219: {
! 220: NODE n,m,s1,t1,t2;
! 221: LIST s,t;
! 222:
! 223: asir_assert(ARG0(arg),O_LIST,"assoc");
! 224: asir_assert(ARG1(arg),O_LIST,"assoc");
! 225: n = BDY((LIST)ARG0(arg));
! 226: m = BDY((LIST)ARG1(arg));
! 227: for ( s = 0, t2 = 0; n; n = NEXT(n) ) {
! 228: if (m) {
! 229: MKNODE(t2,BDY(m),0);
! 230: m = NEXT(m);
! 231: }
! 232: MKNODE(t1,BDY(n),t2); MKLIST(t,t1);
! 233: NEXTNODE(s,s1); BDY(s1) = t; NEXT(s1) = 0;
! 234: }
! 235: MKLIST(*rp,s);
1.1 noro 236: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>