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

Annotation of OpenXM_contrib2/asir2000/builtin/subst.c, Revision 1.6

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.6     ! noro       48:  * $OpenXM: OpenXM_contrib2/asir2000/builtin/subst.c,v 1.5 2001/10/09 01:36:07 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 ) {
        !            94:                                asir_assert(BDY(arg),O_P,"subst");
        !            95:                                v = VR((P)BDY(arg)); arg = NEXT(arg);
        !            96:                                if ( !arg )
        !            97:                                        error("subst : invalid argument");
        !            98:                                asir_assert(ARG0(arg),O_R,"subst");
        !            99:                                reductr(CO,(Obj)BDY(arg),&b); arg = NEXT(arg);
        !           100:                /*              b = (Obj)BDY(arg); arg = NEXT(arg); */
        !           101:                                substr(CO,0,a,v,b,&t); a = t;
        !           102:                        }
        !           103:                        *rp = a;
        !           104:                        break;
        !           105:                case O_LIST:
        !           106:                        n0 = 0;
        !           107:                        for ( nd = BDY((LIST)a); nd; nd = NEXT(nd) ) {
        !           108:                                NEXTNODE(n0,n);
        !           109:                                arg0.body = (pointer)BDY(nd);
        !           110:                                arg0.next = NEXT(arg);
        !           111:                                Psubst(&arg0,&b);
        !           112:                                BDY(n) = (pointer)b;
        !           113:                        }
        !           114:                        if ( n0 )
        !           115:                                NEXT(n) = 0;
        !           116:                        MKLIST(l,n0);
        !           117:                        *rp = (Obj)l;
        !           118:                        break;
        !           119:                case O_VECT:
        !           120:                        len = ((VECT)a)->len;
        !           121:                        MKVECT(vect,len);
        !           122:                        for ( i = 0; i < len; i++ ) {
        !           123:                                arg0.body = (pointer)BDY((VECT)a)[i];
        !           124:                                arg0.next = NEXT(arg);
        !           125:                                Psubst(&arg0,&b);
        !           126:                                BDY(vect)[i] = (pointer)b;
        !           127:                        }
        !           128:                        *rp = (Obj)vect;
        !           129:                        break;
        !           130:                case O_MAT:
        !           131:                        row = ((MAT)a)->row;
        !           132:                        col = ((MAT)a)->col;
        !           133:                        MKMAT(mat,row,col);
        !           134:                        for ( i = 0; i < row; i++ )
        !           135:                                for ( j = 0; j < col; j++ ) {
        !           136:                                        arg0.body = (pointer)BDY((MAT)a)[i][j];
        !           137:                                        arg0.next = NEXT(arg);
        !           138:                                        Psubst(&arg0,&b);
        !           139:                                        BDY(mat)[i][j] = (pointer)b;
        !           140:                                }
        !           141:                        *rp = (Obj)mat;
        !           142:                        break;
        !           143:                case O_DP:
        !           144:                        mp0 = 0;
        !           145:                        for ( m = BDY((DP)a); m; m = NEXT(m) ) {
        !           146:                                arg0.body = (pointer)C(m);
        !           147:                                arg0.next = NEXT(arg);
        !           148:                                Psubst(&arg0,&b);
        !           149:                                if ( b ) {
        !           150:                                        NEXTMP(mp0,mp);
        !           151:                                        C(mp) = (P)b;
        !           152:                                        mp->dl = m->dl;
        !           153:                                }
        !           154:                        }
        !           155:                        if ( mp0 ) {
        !           156:                                MKDP(NV((DP)a),mp0,d);
        !           157:                                d->sugar = ((DP)a)->sugar;
        !           158:                                *rp = (Obj)d;
        !           159:                        } else
        !           160:                                *rp = 0;
        !           161:
        !           162:                        break;
        !           163:                default:
        !           164:                        error("subst invalid argument");
1.1       noro      165:        }
1.4       noro      166: }
                    167:
                    168: FNODE subst_in_fnode();
                    169:
                    170: void Psubst_quote(arg,rp)
                    171: NODE arg;
                    172: QUOTE *rp;
                    173: {
1.5       noro      174:        QUOTE h;
1.4       noro      175:        FNODE fn;
                    176:        Obj g;
                    177:        LIST l;
                    178:        V v;
                    179:
                    180:        if ( !arg ) {
                    181:                *rp = 0; return;
                    182:        }
                    183:        asir_assert(ARG0(arg),O_QUOTE,"subst_quote");
                    184:        fn = BDY((QUOTE)ARG0(arg)); arg = NEXT(arg);
                    185:        if ( arg && (l = (LIST)ARG0(arg)) && OID(l) == O_LIST )
                    186:                arg = BDY(l);
                    187:        while ( arg ) {
                    188:                asir_assert(BDY(arg),O_P,"subst_quote");
                    189:                v = VR((P)BDY(arg)); arg = NEXT(arg);
                    190:                if ( !arg )
                    191:                        error("subst_quote : invalid argument");
                    192:                g = (Obj)ARG0(arg); arg = NEXT(arg);
                    193:                if ( !g || OID(g) != O_QUOTE )
                    194:                        objtoquote(g,&h);
                    195:                else
                    196:                        h = (QUOTE)g;
                    197:                fn = subst_in_fnode(fn,v,BDY(h));
                    198:        }
                    199:        MKQUOTE(*rp,fn);
1.1       noro      200: }
                    201:
                    202: void Ppsubst(arg,rp)
                    203: NODE arg;
                    204: Obj *rp;
                    205: {
                    206:        Obj a,b,t;
                    207:        LIST l;
                    208:        V v;
                    209:
                    210:        if ( !arg ) {
                    211:                *rp = 0; return;
                    212:        }
                    213:        asir_assert(ARG0(arg),O_R,"psubst");
                    214:        reductr(CO,(Obj)ARG0(arg),&a);
                    215: /*     a = (Obj)ARG0(arg); */
                    216:        arg = NEXT(arg);
                    217:        if ( arg && (l = (LIST)ARG0(arg)) && OID(l) == O_LIST )
                    218:                arg = BDY(l);
                    219:        while ( arg ) {
                    220:                asir_assert(BDY(arg),O_P,"psubst");
                    221:                v = VR((P)BDY(arg)); arg = NEXT(arg);
                    222:                if ( !arg )
                    223:                        error("psubst : invalid argument");
                    224:                asir_assert(ARG0(arg),O_R,"psubst");
                    225:                reductr(CO,(Obj)BDY(arg),&b); arg = NEXT(arg);
                    226: /*             b = (Obj)BDY(arg); arg = NEXT(arg); */
                    227:                substr(CO,1,a,v,b,&t); a = t;
                    228:        }
                    229:        *rp = a;
                    230: }
                    231:
                    232: void Psubstf(arg,rp)
                    233: NODE arg;
                    234: Obj *rp;
                    235: {
                    236:        Obj a,t;
                    237:        LIST l;
                    238:        V v,f;
                    239:
                    240:        if ( !arg ) {
                    241:                *rp = 0; return;
                    242:        }
                    243:        asir_assert(ARG0(arg),O_R,"substf");
                    244:        reductr(CO,(Obj)ARG0(arg),&a);
                    245: /*     a = (Obj)ARG0(arg); */
                    246:        arg = NEXT(arg);
                    247:        if ( arg && (l = (LIST)ARG0(arg)) && OID(l) == O_LIST )
                    248:                arg = BDY(l);
                    249:        while ( arg ) {
                    250:                asir_assert(BDY(arg),O_P,"substf");
                    251:                v = VR((P)BDY(arg)); arg = NEXT(arg);
                    252:                if ( !arg || (int)v->attr != V_SR )
                    253:                        error("substf : invalid argument");
                    254:                f = VR((P)BDY(arg)); arg = NEXT(arg);
                    255:                if ( (int)f->attr != V_SR )
                    256:                        error("substf : invalid argument\n");
                    257:                substfr(CO,a,((FUNC)v->priv)->f.puref,((FUNC)f->priv)->f.puref,&t);
                    258:                a = t;
                    259:        }
                    260:        *rp = a;
                    261: }

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