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

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.10    ! ohara      48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/list.c,v 1.9 2004/06/29 15:06:28 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.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[] = {
                     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.10    ! ohara      69:        {"cddr",Pcddr,1},
        !            70:        {"cadr",Pcadr,1},
1.1       noro       71:        {0,0,0},
                     72: };
                     73:
                     74: void Pcar(arg,rp)
                     75: NODE arg;
                     76: pointer *rp;
                     77: {
                     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)));
                     83: }
                     84:
                     85: void Pcdr(arg,rp)
                     86: NODE arg;
                     87: LIST *rp;
                     88: {
                     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: {
                    137:        NODE t;
                    138:
                    139:        asir_assert(ARG1(arg),O_LIST,"cons");
                    140:        MKNODE(t,ARG0(arg),BDY((LIST)ARG1(arg))); MKLIST(*rp,t);
                    141: }
                    142:
                    143: void Pappend(arg,rp)
                    144: NODE arg;
                    145: LIST *rp;
                    146: {
                    147:        NODE t,t0,n;
                    148:
                    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);
1.4       saito     159:        }
                    160: }
                    161:
1.1       noro      162: void Preverse(arg,rp)
                    163: NODE arg;
                    164: LIST *rp;
                    165: {
                    166:        NODE t,t1,n;
                    167:
                    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:        }
                    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;
                    194:     default:
                    195:         error("length : invalid argument"); break;
                    196:     }
                    197:     STOQ(i,*rp);
1.8       ohara     198: }
                    199:
                    200: void Plist(NODE arg, LIST *rp)
                    201: {
                    202:     MKLIST(*rp,arg);
1.6       saito     203: }
                    204:
                    205: void Pnconc(arg,rp)
                    206: NODE arg;
                    207: LIST *rp;
                    208: {
                    209:        NODE a1,a2,n;
                    210:
                    211:        asir_assert(ARG0(arg),O_LIST,"nconc");
                    212:        asir_assert(ARG1(arg),O_LIST,"nconc");
                    213:        a1 = BDY((LIST)ARG0(arg));
                    214:        if ( !a1 )
                    215:                *rp = (LIST)ARG1(arg);
                    216:        else {
                    217:                for ( n = a1; n; n = NEXT(n) ) {
                    218:                        a2 = n;
                    219:                }
                    220:                NEXT(a2) = BDY((LIST)ARG1(arg));
                    221:                *rp = (LIST)ARG0(arg);
                    222:        }
                    223: }
                    224:
                    225: void Preplcd(arg,rp)
                    226: NODE arg;
                    227: LIST *rp;
                    228: {
                    229:        NODE a0,a1;
                    230:
                    231:        asir_assert(ARG0(arg),O_LIST,"replcd");
                    232:        asir_assert(ARG1(arg),O_LIST,"replcd");
                    233:        a0 = BDY((LIST)ARG0(arg));
                    234:        if ( !a0 )
                    235:                *rp = (LIST)ARG0(arg);
                    236:        else {
                    237:                NEXT(a0) = BDY((LIST)ARG1(arg));
                    238:                *rp = (LIST)ARG0(arg);
                    239:        }
                    240: }
                    241:
                    242: void Preplca(arg,rp)
                    243: NODE arg;
                    244: LIST *rp;
                    245: {
                    246:        NODE n;
                    247:
                    248:        asir_assert(ARG0(arg),O_LIST,"replca");
                    249:        if ( !(n = BDY((LIST)ARG0(arg)) ) )
                    250:                *rp = (LIST)ARG0(arg);
                    251:        else {
                    252:                BDY(BDY((LIST)ARG0(arg))) = (LIST)ARG1(arg);
                    253:                *rp = (LIST)ARG0(arg);
                    254:        }
1.9       ohara     255: }
                    256:
                    257: void Passoc(NODE arg, LIST *rp)
                    258: {
                    259:     NODE n,m,s1,t1,t2;
                    260:     LIST s,t;
                    261:
                    262:     asir_assert(ARG0(arg),O_LIST,"assoc");
                    263:     asir_assert(ARG1(arg),O_LIST,"assoc");
                    264:     n = BDY((LIST)ARG0(arg));
                    265:     m = BDY((LIST)ARG1(arg));
                    266:     for ( s = 0, t2 = 0; n; n = NEXT(n) ) {
                    267:         if (m) {
                    268:             MKNODE(t2,BDY(m),0);
                    269:             m = NEXT(m);
                    270:         }
                    271:         MKNODE(t1,BDY(n),t2); MKLIST(t,t1);
                    272:         NEXTNODE(s,s1); BDY(s1) = t; NEXT(s1) = 0;
                    273:     }
                    274:     MKLIST(*rp,s);
1.1       noro      275: }

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