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

Annotation of OpenXM_contrib2/asir2000/builtin/list.c, Revision 1.12

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.12    ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/list.c,v 1.11 2006/03/16 10:08:20 noro 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.10      ohara      54: void Plist(), Passoc(), Pcadr(), Pcddr();
1.6       saito      55: void Pnconc(), Preplcd(), Preplca();
1.1       noro       56:
                     57: struct ftab list_tab[] = {
1.12    ! noro       58:   {"car",Pcar,1},
        !            59:   {"cdr",Pcdr,1},
        !            60:   {"cons",Pcons,2},
        !            61:   {"append",Pappend,2},
        !            62:   {"reverse",Preverse,1},
        !            63:   {"length",Plength,1},
        !            64:   {"nconc",Pnconc,2},
        !            65:   {"replcd",Preplcd,2},
        !            66:   {"replca",Preplca,2},
        !            67:   {"list", Plist, -99999999},
        !            68:   {"assoc",Passoc,2},
        !            69:   {"cddr",Pcddr,1},
        !            70:   {"cadr",Pcadr,1},
        !            71:   {0,0,0},
1.1       noro       72: };
                     73:
                     74: void Pcar(arg,rp)
                     75: NODE arg;
                     76: pointer *rp;
                     77: {
1.12    ! noro       78:   asir_assert(ARG0(arg),O_LIST,"car");
        !            79:   if ( !BDY((LIST)ARG0(arg)) )
        !            80:     *rp = ARG0(arg);
        !            81:   else
        !            82:     *rp = (pointer)BDY(BDY((LIST)ARG0(arg)));
1.1       noro       83: }
                     84:
                     85: void Pcdr(arg,rp)
                     86: NODE arg;
                     87: LIST *rp;
                     88: {
1.12    ! noro       89:   asir_assert(ARG0(arg),O_LIST,"cdr");
        !            90:   if ( !BDY((LIST)ARG0(arg)) )
        !            91:     *rp = (LIST)ARG0(arg);
        !            92:   else
        !            93:     MKLIST(*rp,NEXT(BDY((LIST)ARG0(arg))));
1.10      ohara      94: }
                     95:
                     96: void Pcddr(arg,rp)
                     97: NODE arg;
                     98: LIST *rp;
                     99: {
                    100:     NODE n;
                    101:     asir_assert(ARG0(arg),O_LIST,"cddr");
                    102:     if ( !BDY((LIST)ARG0(arg)) ) {
                    103:         *rp = (LIST)ARG0(arg);
                    104:     }else {
                    105:         n = NEXT(BDY((LIST)ARG0(arg)));
                    106:         if ( n ) {
                    107:             n = NEXT(n);
                    108:         }
                    109:         MKLIST(*rp,n);
                    110:     }
                    111: }
                    112:
                    113: void Pcadr(arg,rp)
                    114: NODE arg;
                    115: pointer *rp;
                    116: {
                    117:     NODE n;
                    118:     LIST t;
                    119:     asir_assert(ARG0(arg),O_LIST,"cadr");
                    120:     if ( !BDY((LIST)ARG0(arg)) ) {
                    121:         *rp = ARG0(arg);
                    122:     }else {
                    123:         n = NEXT(BDY((LIST)ARG0(arg)));
                    124:         if ( n ) {
                    125:             *rp = (pointer)BDY(n);
                    126:         }else {
                    127:             MKLIST(t,n);
                    128:             *rp = t;
                    129:         }
                    130:     }
1.1       noro      131: }
                    132:
                    133: void Pcons(arg,rp)
                    134: NODE arg;
                    135: LIST *rp;
                    136: {
1.12    ! noro      137:   NODE t;
1.1       noro      138:
1.12    ! noro      139:   asir_assert(ARG1(arg),O_LIST,"cons");
        !           140:   MKNODE(t,ARG0(arg),BDY((LIST)ARG1(arg))); MKLIST(*rp,t);
1.1       noro      141: }
                    142:
                    143: void Pappend(arg,rp)
                    144: NODE arg;
                    145: LIST *rp;
                    146: {
1.12    ! noro      147:   NODE t,t0,n;
1.1       noro      148:
1.12    ! noro      149:   asir_assert(ARG0(arg),O_LIST,"append");
        !           150:   asir_assert(ARG1(arg),O_LIST,"append");
        !           151:   if ( !(n = BDY((LIST)ARG0(arg))) )
        !           152:     *rp = (LIST)ARG1(arg);
        !           153:   else {
        !           154:     for ( t0 = 0; n; n = NEXT(n) ) {
        !           155:       NEXTNODE(t0,t); BDY(t) = BDY(n);
        !           156:     }
        !           157:     NEXT(t) = BDY((LIST)ARG1(arg));
        !           158:     MKLIST(*rp,t0);
        !           159:   }
1.4       saito     160: }
                    161:
1.1       noro      162: void Preverse(arg,rp)
                    163: NODE arg;
                    164: LIST *rp;
                    165: {
1.12    ! noro      166:   NODE t,t1,n;
1.1       noro      167:
1.12    ! noro      168:   asir_assert(ARG0(arg),O_LIST,"reverse");
        !           169:   if ( !(n = BDY((LIST)ARG0(arg))) )
        !           170:     *rp = (LIST)ARG0(arg);
        !           171:   else {
        !           172:     for ( t = 0; n; n = NEXT(n) ) {
        !           173:       MKNODE(t1,BDY(n),t); t = t1;
        !           174:     }
        !           175:     MKLIST(*rp,t);
        !           176:   }
1.1       noro      177: }
                    178:
1.7       ohara     179: void Plength(arg,rp)
                    180: NODE arg;
                    181: Q *rp;
                    182: {
                    183:     NODE n;
                    184:     int i;
                    185:
                    186:     switch (OID(ARG0(arg))) {
                    187:     case O_VECT:
                    188:         i = ((VECT)ARG0(arg))->len;
                    189:         break;
                    190:     case O_LIST:
                    191:         n = BDY((LIST)ARG0(arg));
                    192:         for ( i = 0; n; i++, n = NEXT(n) );
                    193:         break;
1.12    ! noro      194:   case O_BYTEARRAY:
        !           195:     i = ((BYTEARRAY)ARG0(arg))->len;
        !           196:     break;
1.7       ohara     197:     default:
                    198:         error("length : invalid argument"); break;
                    199:     }
                    200:     STOQ(i,*rp);
1.8       ohara     201: }
                    202:
                    203: void Plist(NODE arg, LIST *rp)
                    204: {
                    205:     MKLIST(*rp,arg);
1.6       saito     206: }
                    207:
                    208: void Pnconc(arg,rp)
                    209: NODE arg;
                    210: LIST *rp;
                    211: {
1.12    ! noro      212:   NODE a1,a2,n;
1.6       saito     213:
1.12    ! noro      214:   asir_assert(ARG0(arg),O_LIST,"nconc");
        !           215:   asir_assert(ARG1(arg),O_LIST,"nconc");
        !           216:   a1 = BDY((LIST)ARG0(arg));
        !           217:   if ( !a1 )
        !           218:     *rp = (LIST)ARG1(arg);
        !           219:   else {
        !           220:     for ( n = a1; n; n = NEXT(n) ) {
        !           221:       a2 = n;
        !           222:     }
        !           223:     NEXT(a2) = BDY((LIST)ARG1(arg));
        !           224:     *rp = (LIST)ARG0(arg);
        !           225:   }
1.6       saito     226: }
                    227:
                    228: void Preplcd(arg,rp)
                    229: NODE arg;
                    230: LIST *rp;
                    231: {
1.12    ! noro      232:   NODE a0,a1;
        !           233:
        !           234:   asir_assert(ARG0(arg),O_LIST,"replcd");
        !           235:   asir_assert(ARG1(arg),O_LIST,"replcd");
        !           236:   a0 = BDY((LIST)ARG0(arg));
        !           237:   if ( !a0 )
        !           238:     *rp = (LIST)ARG0(arg);
        !           239:   else {
        !           240:     NEXT(a0) = BDY((LIST)ARG1(arg));
        !           241:     *rp = (LIST)ARG0(arg);
        !           242:   }
1.6       saito     243: }
                    244:
                    245: void Preplca(arg,rp)
                    246: NODE arg;
                    247: LIST *rp;
                    248: {
1.12    ! noro      249:   NODE n;
        !           250:
        !           251:   asir_assert(ARG0(arg),O_LIST,"replca");
        !           252:   if ( !(n = BDY((LIST)ARG0(arg)) ) )
        !           253:     *rp = (LIST)ARG0(arg);
        !           254:   else {
        !           255:     BDY(BDY((LIST)ARG0(arg))) = (LIST)ARG1(arg);
        !           256:     *rp = (LIST)ARG0(arg);
        !           257:   }
1.9       ohara     258: }
                    259:
                    260: void Passoc(NODE arg, LIST *rp)
                    261: {
                    262:     NODE n,m,s1,t1,t2;
                    263:     LIST s,t;
                    264:
                    265:     asir_assert(ARG0(arg),O_LIST,"assoc");
                    266:     asir_assert(ARG1(arg),O_LIST,"assoc");
                    267:     n = BDY((LIST)ARG0(arg));
                    268:     m = BDY((LIST)ARG1(arg));
                    269:     for ( s = 0, t2 = 0; n; n = NEXT(n) ) {
                    270:         if (m) {
                    271:             MKNODE(t2,BDY(m),0);
                    272:             m = NEXT(m);
                    273:         }
                    274:         MKNODE(t1,BDY(n),t2); MKLIST(t,t1);
                    275:         NEXTNODE(s,s1); BDY(s1) = t; NEXT(s1) = 0;
                    276:     }
                    277:     MKLIST(*rp,s);
1.1       noro      278: }

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