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

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

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