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

Annotation of OpenXM_contrib2/asir2000/io/cio.c, Revision 1.9

1.3       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.4       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.3       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.
1.9     ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/cio.c,v 1.8 2001/08/06 01:48:33 noro Exp $
1.3       noro       48: */
1.1       noro       49: #include "ca.h"
                     50: #include "parse.h"
                     51: #include "ox.h"
                     52:
                     53: #define ISIZ sizeof(int)
                     54:
                     55: int write_cmo_zz(FILE *,int,N);
                     56: int read_cmo_zz(FILE *,int *,N *);
                     57:
                     58: int valid_as_cmo(obj)
                     59: Obj obj;
                     60: {
                     61:        NODE m;
                     62:
                     63:        if ( !obj )
                     64:                return 1;
                     65:        switch ( OID(obj) ) {
                     66:                case O_MATHCAP: case O_P: case O_R: case O_DP: case O_STR:
1.6       noro       67:                case O_ERR: case O_USINT: case O_BYTEARRAY: case O_VOID:
1.1       noro       68:                        return 1;
                     69:                case O_N:
1.2       noro       70:                        if ( NID((Num)obj) == N_Q || NID((Num)obj) == N_R )
1.1       noro       71:                                return 1;
                     72:                        else
                     73:                                return 0;
                     74:                case O_LIST:
                     75:                        for ( m = BDY((LIST)obj); m; m = NEXT(m) )
                     76:                                if ( !valid_as_cmo(BDY(m)) )
                     77:                                        return 0;
                     78:                        return 1;
1.7       noro       79:                case O_QUOTE:
                     80:                        return 1;
1.1       noro       81:                default:
                     82:                        return 0;
                     83:        }
                     84: }
                     85:
                     86: write_cmo(s,obj)
                     87: FILE *s;
                     88: Obj obj;
                     89: {
                     90:        int r;
                     91:        char errmsg[BUFSIZ];
                     92:
                     93:        if ( !obj ) {
                     94:                r = CMO_NULL; write_int(s,&r);
                     95:                return;
                     96:        }
                     97:        switch ( OID(obj) ) {
                     98:                case O_N:
1.2       noro       99:                        switch ( NID((Num)obj) ) {
                    100:                                case N_Q:
                    101:                                        write_cmo_q(s,(Q)obj);
                    102:                                        break;
                    103:                                case N_R:
                    104:                                        write_cmo_real(s,(Real)obj);
                    105:                                        break;
                    106:                                default:
                    107:                                        sprintf(errmsg, "write_cmo : number id=%d not implemented.",
                    108:                                                NID((Num)obj));
                    109:                                        error(errmsg);
                    110:                                        break;
                    111:                        }
1.1       noro      112:                        break;
                    113:                case O_P:
                    114:                        write_cmo_p(s,obj);
                    115:                        break;
                    116:                case O_R:
                    117:                        write_cmo_r(s,obj);
                    118:                        break;
                    119:                case O_DP:
                    120:                        write_cmo_dp(s,obj);
                    121:                        break;
                    122:                case O_LIST:
                    123:                        write_cmo_list(s,obj);
                    124:                        break;
                    125:                case O_STR:
                    126:                        write_cmo_string(s,obj);
                    127:                        break;
                    128:                case O_USINT:
                    129:                        write_cmo_uint(s,obj);
                    130:                        break;
                    131:                case O_MATHCAP:
                    132:                        write_cmo_mathcap(s,obj);
                    133:                        break;
                    134:                case O_ERR:
                    135:                        write_cmo_error(s,obj);
                    136:                        break;
1.6       noro      137:                case O_BYTEARRAY:
                    138:                        write_cmo_bytearray(s,obj);
                    139:                        break;
1.1       noro      140:                case O_VOID:
                    141:                        r = ((USINT)obj)->body; write_int(s,&r);
                    142:                        break;
1.7       noro      143:                case O_QUOTE:
                    144:                        write_cmo_tree(s,(FNODE)(((QUOTE)obj)->body));
                    145:                        break;
1.1       noro      146:                default:
                    147:                        sprintf(errmsg, "write_cmo : id=%d not implemented.",OID(obj));
                    148:                        error(errmsg);
                    149:                        break;
                    150:        }
1.5       noro      151: }
                    152:
                    153: int cmo_tag(obj,tag)
                    154: Obj obj;
                    155: int *tag;
                    156: {
                    157:        if ( !valid_as_cmo(obj) )
                    158:                return 0;
                    159:        if ( !obj ) {
                    160:                *tag = CMO_NULL;
                    161:                return 1;
                    162:        }
                    163:        switch ( OID(obj) ) {
                    164:                case O_N:
                    165:                        switch ( NID((Num)obj) ) {
                    166:                                case N_Q:
                    167:                                        *tag = DN((Q)obj) ? CMO_QQ : CMO_ZZ; break;
                    168:                                case N_R:
                    169:                                        *tag = CMO_IEEE_DOUBLE_FLOAT; break;
                    170:                                default:
                    171:                                        return 0;
                    172:                        }
                    173:                        break;
                    174:                case O_P:
                    175:                        *tag = CMO_RECURSIVE_POLYNOMIAL; break;
                    176:                case O_R:
                    177:                        *tag = CMO_RATIONAL; break;
                    178:                case O_DP:
                    179:                        *tag = CMO_DISTRIBUTED_POLYNOMIAL; break;
                    180:                case O_LIST:
                    181:                        *tag = CMO_LIST; break;
                    182:                case O_STR:
                    183:                        *tag = CMO_STRING; break;
                    184:                case O_USINT:
                    185:                        *tag = CMO_INT32; break;
                    186:                case O_MATHCAP:
                    187:                        *tag = CMO_MATHCAP; break;
                    188:                case O_ERR:
                    189:                        *tag = CMO_ERROR2; break;
1.7       noro      190:                case O_QUOTE:
                    191:                        *tag = CMO_TREE; break; break;
1.5       noro      192:                default:
                    193:                        return 0;
                    194:        }
                    195:        return 1;
1.1       noro      196: }
                    197:
                    198: write_cmo_mathcap(s,mc)
                    199: FILE *s;
                    200: MATHCAP mc;
                    201: {
                    202:        unsigned int r;
                    203:
                    204:        r = CMO_MATHCAP; write_int(s,&r);
                    205:        write_cmo(s,BDY(mc));
                    206: }
                    207:
                    208: write_cmo_uint(s,ui)
                    209: FILE *s;
                    210: USINT ui;
                    211: {
                    212:        unsigned int r;
                    213:
                    214:        r = CMO_INT32; write_int(s,&r);
                    215:        r = ui->body; write_int(s,&r);
                    216: }
                    217:
                    218: write_cmo_q(s,q)
                    219: FILE *s;
                    220: Q q;
                    221: {
                    222:        int r;
                    223:
                    224:        if ( q && DN(q) ) {
                    225:                r = CMO_QQ; write_int(s,&r);
                    226:                write_cmo_zz(s,SGN(q),NM(q));
                    227:                write_cmo_zz(s,1,DN(q));
                    228:        } else {
                    229:                r = CMO_ZZ; write_int(s,&r);
                    230:                write_cmo_zz(s,SGN(q),NM(q));
                    231:        }
                    232: }
                    233:
1.2       noro      234: write_cmo_real(s,real)
                    235: FILE *s;
                    236: Real real;
                    237: {
                    238:        unsigned int r;
                    239:        double dbl;
                    240:
                    241:        r = CMO_IEEE_DOUBLE_FLOAT; write_int(s,&r);
                    242:        dbl = real->body; write_double(s,&dbl);
                    243: }
                    244:
1.1       noro      245: write_cmo_zz(s,sgn,n)
                    246: FILE *s;
                    247: int sgn;
                    248: N n;
                    249: {
                    250:        int i,l,bytes;
                    251:        unsigned int t;
                    252:        unsigned int *b;
                    253:        unsigned char c;
                    254:
                    255: #if 1
                    256:        l = PL(n);
                    257:        bytes = sgn*l;
                    258:        write_int(s,&bytes);
                    259:        write_intarray(s,BD(n),l);
                    260: #else
                    261:        l = PL(n); b = (unsigned int *)BD(n);
                    262:        bytes = sgn*4*l;
                    263:        write_int(s,&bytes);
                    264:        for ( i = l-1; i >= 0; i-- ) {
                    265:                t = b[i];
                    266:                c = t>>24; write_char(s,&c);
                    267:                c = (t>>16)&0xff; write_char(s,&c);
                    268:                c = (t>>8)&0xff; write_char(s,&c);
                    269:                c = t&0xff; write_char(s,&c);
                    270:        }
                    271: #endif
                    272: }
                    273:
                    274: write_cmo_p(s,p)
                    275: FILE *s;
                    276: P p;
                    277: {
                    278:        int r,i;
                    279:        VL t,vl;
                    280:        char *namestr;
                    281:        STRING name;
                    282:        NODE n0,n;
                    283:
                    284:        r = CMO_RECURSIVE_POLYNOMIAL; write_int(s,&r);
                    285:        get_vars((Obj)p,&vl);
                    286:
                    287:        /* indeterminate list */
                    288:        r = CMO_LIST; write_int(s,&r);
                    289:        for ( t = vl, i = 0; t; t = NEXT(t), i++ );
                    290:        write_int(s,&i);
                    291:        r = CMO_INDETERMINATE;
                    292:        for ( t = vl; t; t = NEXT(t) ) {
                    293:                write_int(s,&r);
                    294: /*             localname_to_cmoname(NAME(t->v),&namestr); */
                    295:                namestr = NAME(t->v);
                    296:                MKSTR(name,namestr);
                    297:                write_cmo(s,name);
                    298:        }
                    299:
                    300:        /* body */
                    301:        write_cmo_upoly(s,vl,p);
                    302: }
                    303:
                    304: write_cmo_upoly(s,vl,p)
                    305: FILE *s;
                    306: VL vl;
                    307: P p;
                    308: {
                    309:        int r,i;
                    310:        V v;
                    311:        DCP dc,dct;
                    312:        VL vlt;
                    313:
                    314:        if ( NUM(p) )
                    315:                write_cmo(s,p);
                    316:        else {
                    317:                r = CMO_UNIVARIATE_POLYNOMIAL; write_int(s,&r);
                    318:                v = VR(p);
                    319:                dc = DC(p);
                    320:                for ( i = 0, dct = dc; dct; dct = NEXT(dct), i++ );
                    321:                write_int(s,&i);
                    322:                for ( i = 0, vlt = vl; vlt->v != v; vlt = NEXT(vlt), i++ );
                    323:                write_int(s,&i);
                    324:                for ( dct = dc; dct; dct = NEXT(dct) ) {
                    325:                        i = QTOS(DEG(dct)); write_int(s,&i);
                    326:                        write_cmo_upoly(s,vl,COEF(dct));
                    327:                }
                    328:        }
                    329: }
                    330:
                    331: write_cmo_r(s,f)
                    332: FILE *s;
                    333: R f;
                    334: {
                    335:        int r;
                    336:
                    337:        r = CMO_RATIONAL; write_int(s,&r);
                    338:        write_cmo(s,NM(f));
                    339:        write_cmo(s,DN(f));
                    340: }
                    341:
                    342: write_cmo_dp(s,dp)
                    343: FILE *s;
                    344: DP dp;
                    345: {
                    346:        int i,n,nv,r;
                    347:        MP m;
                    348:
                    349:        for ( n = 0, m = BDY(dp); m; m = NEXT(m), n++ );
                    350:        r = CMO_DISTRIBUTED_POLYNOMIAL; write_int(s,&r);
                    351:        r = n; write_int(s,&r);
                    352:        r = CMO_DMS_GENERIC; write_int(s,&r);
                    353:        nv = dp->nv;
                    354:        for ( i = 0, m = BDY(dp); i < n; i++, m = NEXT(m) )
                    355:                write_cmo_monomial(s,m,nv);
                    356: }
                    357:
                    358: write_cmo_monomial(s,m,n)
                    359: FILE *s;
                    360: MP m;
                    361: int n;
                    362: {
                    363:        int i,r;
                    364:        int *p;
                    365:
                    366:        r = CMO_MONOMIAL32; write_int(s,&r);
                    367:        write_int(s,&n);
                    368:        for ( i = 0, p = m->dl->d; i < n; i++ ) {
                    369:                write_int(s,p++);
                    370:        }
                    371:        write_cmo_q(s,m->c);
                    372: }
                    373:
                    374: write_cmo_list(s,list)
                    375: FILE *s;
                    376: LIST list;
                    377: {
                    378:        NODE m;
                    379:        int i,n,r;
                    380:
                    381:        for ( n = 0, m = BDY(list); m; m = NEXT(m), n++ );
                    382:        r = CMO_LIST; write_int(s,&r);
                    383:        write_int(s,&n);
                    384:        for ( i = 0, m = BDY(list); i < n; i++, m = NEXT(m) )
                    385:                write_cmo(s,BDY(m));
                    386: }
                    387:
                    388: write_cmo_string(s,str)
                    389: FILE *s;
                    390: STRING str;
                    391: {
                    392:        int r;
                    393:
                    394:        r = CMO_STRING; write_int(s,&r);
                    395:        savestr(s,BDY(str));
                    396: }
                    397:
1.6       noro      398: write_cmo_bytearray(s,array)
                    399: FILE *s;
                    400: BYTEARRAY array;
                    401: {
                    402:        int r;
                    403:
                    404:        r = CMO_DATUM; write_int(s,&r);
                    405:        write_int(s,&array->len);
                    406:        write_string(s,array->body,array->len);
                    407: }
                    408:
1.1       noro      409: write_cmo_error(s,e)
                    410: FILE *s;
                    411: ERR e;
                    412: {
                    413:        int r;
                    414:
                    415:        r = CMO_ERROR2; write_int(s,&r);
                    416:        write_cmo(s,BDY(e));
                    417: }
                    418:
1.7       noro      419: /* XXX */
                    420:
                    421: write_cmo_tree(s,f)
                    422: FILE *s;
                    423: FNODE f;
                    424: {
                    425:        int r,i,n;
                    426:        char opname[BUFSIZ];
                    427:        NODE args,t;
                    428:        FUNC fspec;
                    429:        struct oSTRING str,nullstr;
                    430:
1.8       noro      431:        /* zero */
                    432:        if ( !f ) {
                    433:                r = CMO_NULL; write_int(s,&r);
                    434:                return;
                    435:        }
                    436:
1.7       noro      437:        /* null string */
                    438:        nullstr.id = O_STR;
                    439:        nullstr.body = 0;
                    440:
                    441:        /* name string */
                    442:        str.id = O_STR;
                    443:        str.body = opname;
                    444:
                    445:        switch ( f->id ) {
                    446:                case I_BOP: case I_COP:
                    447:                case I_AND: case I_OR:
                    448:                        /*
                    449:                         * (CMO_TREE (CMO_STRING,op),(CMO_STRING,0)(CMO_LIST,2,arg1,arg2))
                    450:                         */
                    451:                        switch ( f->id ) {
                    452:                                case I_BOP:
                    453:                                        strcpy(opname,((ARF)FA0(f))->name); break;
                    454:                                case I_COP:
                    455:                                        switch( (cid)FA0(f) ) {
                    456:                                                case C_EQ: strcpy(opname,"=="); break;
                    457:                                                case C_NE: strcpy(opname,"!="); break;
                    458:                                                case C_GT: strcpy(opname,">"); break;
                    459:                                                case C_LT: strcpy(opname,"<"); break;
                    460:                                                case C_GE: strcpy(opname,">="); break;
                    461:                                                case C_LE: strcpy(opname,"<="); break;
                    462:                                        }
                    463:                                        break;
                    464:                                case I_AND:
                    465:                                        strcpy(opname,"&&"); break;
                    466:                                case I_OR:
                    467:                                        strcpy(opname,"||"); break;
                    468:                        }
                    469:                        r = CMO_TREE; write_int(s,&r);
                    470:                        write_cmo_string(s,&str);
                    471:                        write_cmo_string(s,&nullstr);
                    472:                        r = CMO_LIST; write_int(s,&r);
                    473:                        n = 2; write_int(s,&n);
                    474:                        write_cmo_tree(s,(FNODE)FA1(f));
                    475:                        write_cmo_tree(s,(FNODE)FA2(f));
                    476:                        break;
                    477:                case I_NOT:
                    478:                        r = CMO_TREE; write_int(s,&r);
                    479:                        strcpy(opname,"!");
                    480:                        write_cmo_string(s,&str);;
                    481:                        write_cmo_string(s,&nullstr);
                    482:                        r = CMO_LIST; write_int(s,&r);
                    483:                        n = 1; write_int(s,&n);
                    484:                        write_cmo_tree(s,(FNODE)FA1(f));
                    485:                        break;
                    486:                case I_FUNC:
1.8       noro      487:                        r = CMO_TREE; write_int(s,&r);
1.7       noro      488:                        fspec = (FUNC)FA0(f);
                    489:                        strcpy(opname,fspec->name);
                    490:                        write_cmo_string(s,&str);
                    491:                        write_cmo_string(s,&nullstr);
                    492:                        args = (NODE)FA0((FNODE)FA1(f));
                    493:                        r = CMO_LIST; write_int(s,&r);
                    494:                        for ( n = 0, t = args; t; t = NEXT(t), n++ );
                    495:                        write_int(s,&n);
                    496:                        for ( i = 0, t = args; i < n; t = NEXT(t), i++ )
1.9     ! noro      497:                                write_cmo_tree(s,BDY(t));
        !           498:                        break;
        !           499:                case I_LIST:
        !           500:                        r = CMO_LIST; write_int(s,&r);
        !           501:                        args = (NODE)FA0(f);
        !           502:                        for ( n = 0, t = args; t; t = NEXT(t), n++ );
        !           503:                        write_int(s,&n);
        !           504:                        for ( i = 0, t = args; i < n; i++, t = NEXT(t) )
1.7       noro      505:                                write_cmo_tree(s,BDY(t));
                    506:                        break;
                    507:                case I_FORMULA:
                    508:                        write_cmo(s,FA0(f));
                    509:                        break;
                    510:                default:
                    511:                        break; /* XXX */
                    512:        }
                    513: }
                    514:
1.1       noro      515: read_cmo(s,rp)
                    516: FILE *s;
                    517: Obj *rp;
                    518: {
                    519:        int id;
                    520:        int n,sgn,dummy;
                    521:        Q q,qnm,qdn;
                    522:        N nm,dn;
                    523:        P p,pnm,pdn;
                    524:        R r;
1.2       noro      525:        Real real;
                    526:        double dbl;
1.1       noro      527:        STRING str;
                    528:        USINT t;
                    529:        DP dp;
                    530:        char *b;
                    531:        Obj obj;
                    532:        ERR e;
                    533:        MATHCAP mc;
1.6       noro      534:        BYTEARRAY array;
1.8       noro      535:        QUOTE quote;
                    536:        FNODE fn;
1.1       noro      537:
                    538:        read_int(s,&id);
                    539:        switch ( id ) {
                    540:        /* level 0 objects */
                    541:                case CMO_NULL:
                    542:                        *rp = 0;
                    543:                        break;
                    544:                case CMO_INT32:
                    545:                        read_cmo_uint(s,rp);
                    546:                        break;
                    547:                case CMO_DATUM:
1.6       noro      548:                        loadbytearray(s,&array); *rp = (Obj)array;
                    549:                        break;
1.1       noro      550:                case CMO_STRING:
                    551:                        loadstring(s,&str); *rp = (Obj)str;
                    552:                        break;
                    553:                case CMO_MATHCAP:
                    554:                        read_cmo(s,&obj); MKMATHCAP(mc,(LIST)obj);
                    555:                        *rp = (Obj)mc;
                    556:                        break;
                    557:                case CMO_ERROR:
                    558:                        MKERR(e,0); *rp = (Obj)e;
                    559:                        break;
                    560:                case CMO_ERROR2:
                    561:                        read_cmo(s,&obj); MKERR(e,obj); *rp = (Obj)e;
                    562:                        break;
                    563:        /* level 1 objects */
                    564:                case CMO_LIST:
                    565:                        read_cmo_list(s,rp);
                    566:                        break;
                    567:                case CMO_MONOMIAL32:
                    568:                        read_cmo_monomial(s,rp);
                    569:                        break;
                    570:                case CMO_ZZ:
                    571:                        read_cmo_zz(s,&sgn,&nm);
                    572:                        NTOQ(nm,sgn,q); *rp = (Obj)q;
                    573:                        break;
                    574:                case CMO_QQ:
                    575:                        read_cmo_zz(s,&sgn,&nm);
                    576:                        read_cmo_zz(s,&dummy,&dn);
                    577:                        NDTOQ(nm,dn,sgn,q); *rp = (Obj)q;
1.2       noro      578:                        break;
                    579:                case CMO_IEEE_DOUBLE_FLOAT:
                    580:                        read_double(s,&dbl); MKReal(dbl,real); *rp = (Obj)real;
1.1       noro      581:                        break;
                    582:                case CMO_DISTRIBUTED_POLYNOMIAL:
                    583:                        read_cmo_dp(s,&dp); *rp = (Obj)dp;
                    584:                        break;
                    585:                case CMO_RECURSIVE_POLYNOMIAL:
                    586:                        read_cmo_p(s,&p); *rp = (Obj)p;
                    587:                        break;
                    588:                case CMO_UNIVARIATE_POLYNOMIAL:
                    589:                        read_cmo_upoly(s,&p); *rp = (Obj)p;
                    590:                        break;
                    591:                case CMO_INDETERMINATE:
                    592:                        read_cmo(s,&str); *rp = (Obj)str;
                    593:                        break;
                    594:                case CMO_RATIONAL:
                    595:                        read_cmo(s,&pnm); read_cmo(s,&pdn);
                    596:                        divr(CO,(Obj)pnm,(Obj)pdn,rp);
                    597:                        break;
                    598:                case CMO_ZERO:
                    599:                        *rp = 0;
                    600:                        break;
                    601:                case CMO_DMS_OF_N_VARIABLES:
                    602:                        read_cmo(s,rp);
                    603:                        break;
                    604:                case CMO_RING_BY_NAME:
                    605:                        read_cmo(s,rp);
                    606:                        break;
1.7       noro      607:                case CMO_TREE:
1.8       noro      608:                        read_cmo_tree(s,&fn);
                    609:                        MKQUOTE(quote,fn);
                    610:                        *rp = (Obj)quote;
1.7       noro      611:                        break;
1.1       noro      612:                default:
                    613:                        MKUSINT(t,id);
                    614:                        t->id = O_VOID;
                    615:                        *rp = (Obj)t;
                    616:                        break;
                    617:        }
                    618: }
                    619:
                    620: read_cmo_uint(s,rp)
                    621: FILE *s;
                    622: USINT *rp;
                    623: {
                    624:        unsigned int body;
                    625:
                    626:        read_int(s,&body);
                    627:        MKUSINT(*rp,body);
                    628: }
                    629:
                    630: read_cmo_zz(s,sgn,rp)
                    631: FILE *s;
                    632: int *sgn;
                    633: N *rp;
                    634: {
                    635:        int l,i,words;
                    636:        N n;
                    637:        unsigned int *b;
                    638:        unsigned int h;
                    639:        unsigned char c;
                    640:
                    641:        read_int(s,&l);
                    642:        if ( l == 0 ) {
                    643:                *sgn = 0;
                    644:                *rp = 0;
                    645:                return;
                    646:        }
                    647:        if ( l < 0 ) {
                    648:                *sgn = -1; l = -l;
                    649:        } else
                    650:                *sgn = 1;
                    651: #if 1
                    652:        *rp = n = NALLOC(l); PL(n) = l;
                    653:        read_intarray(s,BD(n),l);
                    654: #else
                    655:        words = (l+3)/4;
                    656:        *rp = n = NALLOC(words); PL(n) = words; b = BD(n);
                    657:        h = 0;
                    658:        switch ( l % 4 ) {
                    659:                case 0:
                    660:                        read_char(s,&c); h = c;
                    661:                case 3:
                    662:                        read_char(s,&c); h = (h<<8)|c;
                    663:                case 2:
                    664:                        read_char(s,&c); h = (h<<8)|c;
                    665:                case 1:
                    666:                        read_char(s,&c); h = (h<<8)|c;
                    667:        }
                    668:        b[words-1] = h;
                    669:        for ( i = words-2; i >= 0; i-- ) {
                    670:                read_char(s,&c); h = c;
                    671:                read_char(s,&c); h = (h<<8)|c;
                    672:                read_char(s,&c); h = (h<<8)|c;
                    673:                read_char(s,&c); h = (h<<8)|c;
                    674:                b[i] = h;
                    675:        }
                    676: #endif
                    677: }
                    678:
                    679: read_cmo_list(s,rp)
                    680: FILE *s;
                    681: Obj *rp;
                    682: {
                    683:        int len;
                    684:        Obj *w;
                    685:        int i;
                    686:        Obj r,r1;
                    687:        NODE n0,n1;
                    688:        LIST list;
                    689:
                    690:        read_int(s,&len);
                    691:        w = (Obj *)ALLOCA(len*sizeof(Obj));
                    692:        for ( i = 0; i < len; i++ )
                    693:                read_cmo(s,&w[i]);
                    694:        for ( i = len-1, n0 = 0; i >= 0; i-- ) {
                    695:                MKNODE(n1,w[i],n0); n0 = n1;
                    696:        }
                    697:        MKLIST(list,n0);
                    698:        *rp = (Obj)list;
                    699: }
                    700:
                    701: read_cmo_dp(s,rp)
                    702: FILE *s;
                    703: DP *rp;
                    704: {
                    705:        int len;
                    706:        int i;
                    707:        NODE n0,n1;
                    708:        MP mp0,mp;
                    709:        int nv,d;
                    710:        DP dp;
                    711:        Obj obj;
                    712:
                    713:        read_int(s,&len);
                    714:        /* skip the ring definition */
                    715:        read_cmo(s,&obj);
                    716:        for ( mp0 = 0, i = 0, d = 0; i < len; i++ ) {
                    717:                read_cmo(s,&dp);
                    718:                if ( !mp0 ) {
                    719:                        nv = dp->nv;
                    720:                        mp0 = dp->body;
                    721:                        mp = mp0;
                    722:                } else {
                    723:                        NEXT(mp) = dp->body;
                    724:                        mp = NEXT(mp);
                    725:                }
                    726:                d = MAX(d,dp->sugar);
                    727:        }
                    728:        MKDP(nv,mp0,dp);
                    729:        dp->sugar = d; *rp = dp;
                    730: }
                    731:
                    732: read_cmo_monomial(s,rp)
                    733: FILE *s;
                    734: DP *rp;
                    735: {
                    736:        MP m;
                    737:        DP dp;
                    738:        int i,sugar,n;
                    739:        DL dl;
                    740:
                    741:        read_int(s,&n);
                    742:        NEWMP(m); NEWDL(dl,n); m->dl = dl;
                    743:        read_intarray(s,dl->d,n);
                    744:        for ( sugar = 0, i = 0; i < n; i++ )
                    745:                sugar += dl->d[i];
                    746:        dl->td = sugar;
                    747:        read_cmo(s,&m->c);
                    748:        NEXT(m) = 0; MKDP(n,m,dp); dp->sugar = sugar; *rp = dp;
                    749: }
                    750:
                    751: static V *remote_vtab;
                    752:
                    753: read_cmo_p(s,rp)
                    754: FILE *s;
                    755: P *rp;
                    756: {
                    757:        LIST vlist;
                    758:        int nv,i;
                    759:        V *vtab;
                    760:        V v1,v2;
                    761:        NODE t;
                    762:        P v,p;
                    763:        VL tvl,rvl;
                    764:        char *name;
                    765:
                    766:        read_cmo(s,&vlist);
                    767:        nv = length(BDY(vlist));
                    768:        vtab = (V *)ALLOCA(nv*sizeof(V));
                    769:        for ( i = 0, t = BDY(vlist); i < nv; t = NEXT(t), i++ ) {
                    770: /*             cmoname_to_localname(BDY((STRING)BDY(t)),&name); */
                    771:                name = BDY((STRING)BDY(t));
                    772:                makevar(name,&v); vtab[i] = VR(v);
                    773:        }
                    774:        remote_vtab = vtab;
                    775:        read_cmo(s,&p);
                    776:        for ( i = 0; i < nv-1; i++ ) {
                    777:                v1 = vtab[i]; v2 = vtab[i+1];
                    778:                for ( tvl = CO; tvl->v != v1 && tvl->v != v2; tvl = NEXT(tvl) );
                    779:                if ( tvl->v == v2 )
                    780:                        break;
                    781:        }
                    782:        if ( i < nv-1 ) {
                    783:                 for ( i = nv-1, rvl = 0; i >= 0; i-- ) {
                    784:                        NEWVL(tvl); tvl->v = vtab[i]; NEXT(tvl) = rvl; rvl = tvl;
                    785:                 }
                    786:                 reorderp(CO,rvl,p,rp);
                    787:        } else
                    788:                *rp = p;
                    789: }
                    790:
                    791: read_cmo_upoly(s,rp)
                    792: FILE *s;
                    793: P *rp;
                    794: {
                    795:        int n,ind,i,d;
                    796:        P c;
                    797:        Q q;
                    798:        DCP dc0,dc;
                    799:
                    800:        read_int(s,&n);
                    801:        read_int(s,&ind);
                    802:        for ( i = 0, dc0 = 0; i < n; i++ ) {
                    803:                read_int(s,&d);
                    804:                read_cmo(s,&c);
                    805:                if ( c ) {
                    806:                        if ( OID(c) == O_USINT ) {
                    807:                                UTOQ(((USINT)c)->body,q); c = (P)q;
                    808:                        }
                    809:                        NEXTDC(dc0,dc);
                    810:                        STOQ(d,q);
                    811:                        dc->c = c; dc->d = q;
                    812:                }
                    813:        }
                    814:        if ( dc0 )
                    815:                NEXT(dc) = 0;
                    816:        MKP(remote_vtab[ind],dc0,*rp);
1.7       noro      817: }
                    818:
                    819: /* XXX */
                    820:
                    821: extern struct oARF arf[];
                    822:
                    823: struct operator_tab {
                    824:        char *name;
                    825:        fid id;
                    826:        ARF arf;
                    827:        cid cid;
                    828: };
                    829:
                    830: static struct operator_tab optab[] = {
                    831:        {"+",I_BOP,&arf[0],0}, /* XXX */
                    832:        {"-",I_BOP,&arf[1],0},
                    833:        {"*",I_BOP,&arf[2],0},
                    834:        {"/",I_BOP,&arf[3],0},
                    835:        {"%",I_BOP,&arf[4],0},
                    836:        {"^",I_BOP,&arf[5],0},
                    837:        {"==",I_COP,0,C_EQ},
                    838:        {"!=",I_COP,0,C_NE},
                    839:        {"<",I_COP,0,C_LT},
                    840:        {"<=",I_COP,0,C_LE},
                    841:        {">",I_COP,0,C_GT},
                    842:        {">=",I_COP,0,C_GE},
                    843:        {"&&",I_AND,0,0},
                    844:        {"||",I_OR,0,0},
                    845:        {"!",I_NOT,0,0},
                    846: };
                    847:
                    848: static int optab_len = sizeof(optab)/sizeof(struct operator_tab);
                    849:
                    850: read_cmo_tree(s,rp)
                    851: FILE *s;
1.8       noro      852: FNODE *rp;
1.7       noro      853: {
                    854:        int r,i,n;
                    855:        char *opname;
                    856:        STRING name,cd;
                    857:        int op;
1.8       noro      858:        pointer *arg;
1.7       noro      859:        QUOTE quote;
                    860:        FNODE fn;
1.8       noro      861:        NODE t,t1;
1.7       noro      862:        fid id;
1.8       noro      863:        Obj expr;
                    864:        FUNC func;
1.7       noro      865:
                    866:        read_cmo(s,&name);
                    867:        read_cmo(s,&cd); /* XXX: currently not used */
                    868:        for ( i = 0; i < optab_len; i++ )
                    869:                if ( !strcmp(optab[i].name,BDY(name)) )
                    870:                        break;
                    871:        if ( i == optab_len ) {
                    872:                /* may be a function name */
1.8       noro      873:                n = read_cmo_tree_arg(s,&arg);
                    874:                for ( i = n-1, t = 0; i >= 0; i-- ) {
                    875:                        MKNODE(t1,arg[i],t); t = t1;
                    876:                }
                    877:                searchf(sysf,BDY(name),&func);
                    878:                if ( !func )
                    879:                        searchf(ubinf,BDY(name),&func);
                    880:                if ( !func )
                    881:                        searchpf(BDY(name),&func);
                    882:                if ( !func )
                    883:                        searchf(usrf,BDY(name),&func);
                    884:                if ( !func )
                    885:                        appenduf(BDY(name),&func);
                    886:                *rp = mkfnode(2,I_FUNC,func,mkfnode(1,I_LIST,t));
1.7       noro      887:        } else {
                    888:                opname = optab[i].name;
                    889:                id = optab[i].id;
                    890:                switch ( id ) {
                    891:                        case I_BOP:
1.8       noro      892:                                read_cmo_tree_arg(s,&arg);
                    893:                                *rp = mkfnode(3,I_BOP,optab[i].arf,arg[0],arg[1]);
                    894:                                return;
1.7       noro      895:                        case I_COP:
1.8       noro      896:                                read_cmo_tree_arg(s,&arg);
                    897:                                *rp = mkfnode(3,I_COP,optab[i].cid,arg[0],arg[0]);
                    898:                                return;
1.7       noro      899:                        case I_AND:
1.8       noro      900:                                read_cmo_tree_arg(s,&arg);
                    901:                                *rp = mkfnode(2,I_AND,arg[0],arg[1]);
                    902:                                return;
1.7       noro      903:                        case I_OR:
1.8       noro      904:                                read_cmo_tree_arg(s,&arg);
                    905:                                *rp = mkfnode(2,I_OR,arg[0],arg[1]);
                    906:                                return;
1.7       noro      907:                        case I_NOT:
1.8       noro      908:                                read_cmo_tree_arg(s,&arg);
                    909:                                *rp = mkfnode(1,I_OR,arg[0]);
                    910:                                return;
1.7       noro      911:                }
                    912:        }
1.8       noro      913: }
                    914:
                    915: int read_cmo_tree_arg(s,argp)
                    916: FILE *s;
                    917: pointer **argp;
                    918: {
                    919:        int id,n,i;
                    920:        pointer *ap;
                    921:        Obj t;
                    922:
                    923:        read_int(s,&id); /* id = CMO_LIST */
                    924:        read_int(s,&n); /* n = the number of args */
                    925:        *argp = ap = (pointer *) MALLOC(n*sizeof(pointer));
                    926:        for ( i = 0; i < n; i++ ) {
                    927:                read_cmo(s,&t);
                    928:                if ( !t || (OID(t) != O_QUOTE) )
                    929:                        ap[i] = mkfnode(1,I_FORMULA,t);
                    930:                else
                    931:                        ap[i] = BDY((QUOTE)t);
                    932:        }
                    933:        return n;
1.1       noro      934: }
                    935:
                    936: localname_to_cmoname(a,b)
                    937: char *a;
                    938: char **b;
                    939: {
                    940:        int l;
                    941:        char *t;
                    942:
                    943:        l = strlen(a);
                    944:        if ( l >= 2 && a[0] == '@' && isupper(a[1]) ) {
                    945:                t = *b = (char *)MALLOC_ATOMIC(l);
                    946:                strcpy(t,a+1);
                    947:        } else {
                    948:                t = *b = (char *)MALLOC_ATOMIC(l+1);
                    949:                strcpy(t,a);
                    950:        }
                    951: }
                    952:
                    953: cmoname_to_localname(a,b)
                    954: char *a;
                    955: char **b;
                    956: {
                    957:        int l;
                    958:        char *t;
                    959:
                    960:        l = strlen(a);
                    961:        if ( isupper(a[0]) ) {
                    962:                t = *b = (char *)MALLOC_ATOMIC(l+2);
                    963:                strcpy(t+1,a);
                    964:                t[0] = '@';
                    965:        } else {
                    966:                t = *b = (char *)MALLOC_ATOMIC(l+1);
                    967:                strcpy(t,a);
                    968:        }
                    969: }

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