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

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.8     ! ohara      48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/list.c,v 1.7 2003/07/29 01:50:56 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.8     ! ohara      54: void Plist();
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.1       noro       68:        {0,0,0},
                     69: };
                     70:
                     71: void Pcar(arg,rp)
                     72: NODE arg;
                     73: pointer *rp;
                     74: {
                     75:        asir_assert(ARG0(arg),O_LIST,"car");
                     76:        if ( !BDY((LIST)ARG0(arg)) )
                     77:                *rp = ARG0(arg);
                     78:        else
                     79:                *rp = (pointer)BDY(BDY((LIST)ARG0(arg)));
                     80: }
                     81:
                     82: void Pcdr(arg,rp)
                     83: NODE arg;
                     84: LIST *rp;
                     85: {
                     86:        asir_assert(ARG0(arg),O_LIST,"cdr");
                     87:        if ( !BDY((LIST)ARG0(arg)) )
                     88:                *rp = (LIST)ARG0(arg);
                     89:        else
                     90:                MKLIST(*rp,NEXT(BDY((LIST)ARG0(arg))));
                     91: }
                     92:
                     93: void Pcons(arg,rp)
                     94: NODE arg;
                     95: LIST *rp;
                     96: {
                     97:        NODE t;
                     98:
                     99:        asir_assert(ARG1(arg),O_LIST,"cons");
                    100:        MKNODE(t,ARG0(arg),BDY((LIST)ARG1(arg))); MKLIST(*rp,t);
                    101: }
                    102:
                    103: void Pappend(arg,rp)
                    104: NODE arg;
                    105: LIST *rp;
                    106: {
                    107:        NODE t,t0,n;
                    108:
                    109:        asir_assert(ARG0(arg),O_LIST,"append");
                    110:        asir_assert(ARG1(arg),O_LIST,"append");
                    111:        if ( !(n = BDY((LIST)ARG0(arg))) )
                    112:                *rp = (LIST)ARG1(arg);
                    113:        else {
                    114:                for ( t0 = 0; n; n = NEXT(n) ) {
                    115:                        NEXTNODE(t0,t); BDY(t) = BDY(n);
                    116:                }
                    117:                NEXT(t) = BDY((LIST)ARG1(arg));
                    118:                MKLIST(*rp,t0);
1.4       saito     119:        }
                    120: }
                    121:
1.1       noro      122: void Preverse(arg,rp)
                    123: NODE arg;
                    124: LIST *rp;
                    125: {
                    126:        NODE t,t1,n;
                    127:
                    128:        asir_assert(ARG0(arg),O_LIST,"reverse");
                    129:        if ( !(n = BDY((LIST)ARG0(arg))) )
                    130:                *rp = (LIST)ARG0(arg);
                    131:        else {
                    132:                for ( t = 0; n; n = NEXT(n) ) {
                    133:                        MKNODE(t1,BDY(n),t); t = t1;
                    134:                }
                    135:                MKLIST(*rp,t);
                    136:        }
                    137: }
                    138:
1.7       ohara     139: void Plength(arg,rp)
                    140: NODE arg;
                    141: Q *rp;
                    142: {
                    143:     NODE n;
                    144:     int i;
                    145:
                    146:     switch (OID(ARG0(arg))) {
                    147:     case O_VECT:
                    148:         i = ((VECT)ARG0(arg))->len;
                    149:         break;
                    150:     case O_LIST:
                    151:         n = BDY((LIST)ARG0(arg));
                    152:         for ( i = 0; n; i++, n = NEXT(n) );
                    153:         break;
                    154:     default:
                    155:         error("length : invalid argument"); break;
                    156:     }
                    157:     STOQ(i,*rp);
1.8     ! ohara     158: }
        !           159:
        !           160: void Plist(NODE arg, LIST *rp)
        !           161: {
        !           162:     MKLIST(*rp,arg);
1.6       saito     163: }
                    164:
                    165: void Pnconc(arg,rp)
                    166: NODE arg;
                    167: LIST *rp;
                    168: {
                    169:        NODE a1,a2,n;
                    170:
                    171:        asir_assert(ARG0(arg),O_LIST,"nconc");
                    172:        asir_assert(ARG1(arg),O_LIST,"nconc");
                    173:        a1 = BDY((LIST)ARG0(arg));
                    174:        if ( !a1 )
                    175:                *rp = (LIST)ARG1(arg);
                    176:        else {
                    177:                for ( n = a1; n; n = NEXT(n) ) {
                    178:                        a2 = n;
                    179:                }
                    180:                NEXT(a2) = BDY((LIST)ARG1(arg));
                    181:                *rp = (LIST)ARG0(arg);
                    182:        }
                    183: }
                    184:
                    185: void Preplcd(arg,rp)
                    186: NODE arg;
                    187: LIST *rp;
                    188: {
                    189:        NODE a0,a1;
                    190:
                    191:        asir_assert(ARG0(arg),O_LIST,"replcd");
                    192:        asir_assert(ARG1(arg),O_LIST,"replcd");
                    193:        a0 = BDY((LIST)ARG0(arg));
                    194:        if ( !a0 )
                    195:                *rp = (LIST)ARG0(arg);
                    196:        else {
                    197:                NEXT(a0) = BDY((LIST)ARG1(arg));
                    198:                *rp = (LIST)ARG0(arg);
                    199:        }
                    200: }
                    201:
                    202: void Preplca(arg,rp)
                    203: NODE arg;
                    204: LIST *rp;
                    205: {
                    206:        NODE n;
                    207:
                    208:        asir_assert(ARG0(arg),O_LIST,"replca");
                    209:        if ( !(n = BDY((LIST)ARG0(arg)) ) )
                    210:                *rp = (LIST)ARG0(arg);
                    211:        else {
                    212:                BDY(BDY((LIST)ARG0(arg))) = (LIST)ARG1(arg);
                    213:                *rp = (LIST)ARG0(arg);
                    214:        }
1.1       noro      215: }

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