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

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.6     ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/cio.c,v 1.5 2000/09/07 23:59:54 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;
                     79:                default:
                     80:                        return 0;
                     81:        }
                     82: }
                     83:
                     84: write_cmo(s,obj)
                     85: FILE *s;
                     86: Obj obj;
                     87: {
                     88:        int r;
                     89:        char errmsg[BUFSIZ];
                     90:
                     91:        if ( !obj ) {
                     92:                r = CMO_NULL; write_int(s,&r);
                     93:                return;
                     94:        }
                     95:        switch ( OID(obj) ) {
                     96:                case O_N:
1.2       noro       97:                        switch ( NID((Num)obj) ) {
                     98:                                case N_Q:
                     99:                                        write_cmo_q(s,(Q)obj);
                    100:                                        break;
                    101:                                case N_R:
                    102:                                        write_cmo_real(s,(Real)obj);
                    103:                                        break;
                    104:                                default:
                    105:                                        sprintf(errmsg, "write_cmo : number id=%d not implemented.",
                    106:                                                NID((Num)obj));
                    107:                                        error(errmsg);
                    108:                                        break;
                    109:                        }
1.1       noro      110:                        break;
                    111:                case O_P:
                    112:                        write_cmo_p(s,obj);
                    113:                        break;
                    114:                case O_R:
                    115:                        write_cmo_r(s,obj);
                    116:                        break;
                    117:                case O_DP:
                    118:                        write_cmo_dp(s,obj);
                    119:                        break;
                    120:                case O_LIST:
                    121:                        write_cmo_list(s,obj);
                    122:                        break;
                    123:                case O_STR:
                    124:                        write_cmo_string(s,obj);
                    125:                        break;
                    126:                case O_USINT:
                    127:                        write_cmo_uint(s,obj);
                    128:                        break;
                    129:                case O_MATHCAP:
                    130:                        write_cmo_mathcap(s,obj);
                    131:                        break;
                    132:                case O_ERR:
                    133:                        write_cmo_error(s,obj);
                    134:                        break;
1.6     ! noro      135:                case O_BYTEARRAY:
        !           136:                        write_cmo_bytearray(s,obj);
        !           137:                        break;
1.1       noro      138:                case O_VOID:
                    139:                        r = ((USINT)obj)->body; write_int(s,&r);
                    140:                        break;
                    141:                default:
                    142:                        sprintf(errmsg, "write_cmo : id=%d not implemented.",OID(obj));
                    143:                        error(errmsg);
                    144:                        break;
                    145:        }
1.5       noro      146: }
                    147:
                    148: int cmo_tag(obj,tag)
                    149: Obj obj;
                    150: int *tag;
                    151: {
                    152:        if ( !valid_as_cmo(obj) )
                    153:                return 0;
                    154:        if ( !obj ) {
                    155:                *tag = CMO_NULL;
                    156:                return 1;
                    157:        }
                    158:        switch ( OID(obj) ) {
                    159:                case O_N:
                    160:                        switch ( NID((Num)obj) ) {
                    161:                                case N_Q:
                    162:                                        *tag = DN((Q)obj) ? CMO_QQ : CMO_ZZ; break;
                    163:                                case N_R:
                    164:                                        *tag = CMO_IEEE_DOUBLE_FLOAT; break;
                    165:                                default:
                    166:                                        return 0;
                    167:                        }
                    168:                        break;
                    169:                case O_P:
                    170:                        *tag = CMO_RECURSIVE_POLYNOMIAL; break;
                    171:                case O_R:
                    172:                        *tag = CMO_RATIONAL; break;
                    173:                case O_DP:
                    174:                        *tag = CMO_DISTRIBUTED_POLYNOMIAL; break;
                    175:                case O_LIST:
                    176:                        *tag = CMO_LIST; break;
                    177:                case O_STR:
                    178:                        *tag = CMO_STRING; break;
                    179:                case O_USINT:
                    180:                        *tag = CMO_INT32; break;
                    181:                case O_MATHCAP:
                    182:                        *tag = CMO_MATHCAP; break;
                    183:                case O_ERR:
                    184:                        *tag = CMO_ERROR2; break;
                    185:                default:
                    186:                        return 0;
                    187:        }
                    188:        return 1;
1.1       noro      189: }
                    190:
                    191: write_cmo_mathcap(s,mc)
                    192: FILE *s;
                    193: MATHCAP mc;
                    194: {
                    195:        unsigned int r;
                    196:
                    197:        r = CMO_MATHCAP; write_int(s,&r);
                    198:        write_cmo(s,BDY(mc));
                    199: }
                    200:
                    201: write_cmo_uint(s,ui)
                    202: FILE *s;
                    203: USINT ui;
                    204: {
                    205:        unsigned int r;
                    206:
                    207:        r = CMO_INT32; write_int(s,&r);
                    208:        r = ui->body; write_int(s,&r);
                    209: }
                    210:
                    211: write_cmo_q(s,q)
                    212: FILE *s;
                    213: Q q;
                    214: {
                    215:        int r;
                    216:
                    217:        if ( q && DN(q) ) {
                    218:                r = CMO_QQ; write_int(s,&r);
                    219:                write_cmo_zz(s,SGN(q),NM(q));
                    220:                write_cmo_zz(s,1,DN(q));
                    221:        } else {
                    222:                r = CMO_ZZ; write_int(s,&r);
                    223:                write_cmo_zz(s,SGN(q),NM(q));
                    224:        }
                    225: }
                    226:
1.2       noro      227: write_cmo_real(s,real)
                    228: FILE *s;
                    229: Real real;
                    230: {
                    231:        unsigned int r;
                    232:        double dbl;
                    233:
                    234:        r = CMO_IEEE_DOUBLE_FLOAT; write_int(s,&r);
                    235:        dbl = real->body; write_double(s,&dbl);
                    236: }
                    237:
1.1       noro      238: write_cmo_zz(s,sgn,n)
                    239: FILE *s;
                    240: int sgn;
                    241: N n;
                    242: {
                    243:        int i,l,bytes;
                    244:        unsigned int t;
                    245:        unsigned int *b;
                    246:        unsigned char c;
                    247:
                    248: #if 1
                    249:        l = PL(n);
                    250:        bytes = sgn*l;
                    251:        write_int(s,&bytes);
                    252:        write_intarray(s,BD(n),l);
                    253: #else
                    254:        l = PL(n); b = (unsigned int *)BD(n);
                    255:        bytes = sgn*4*l;
                    256:        write_int(s,&bytes);
                    257:        for ( i = l-1; i >= 0; i-- ) {
                    258:                t = b[i];
                    259:                c = t>>24; write_char(s,&c);
                    260:                c = (t>>16)&0xff; write_char(s,&c);
                    261:                c = (t>>8)&0xff; write_char(s,&c);
                    262:                c = t&0xff; write_char(s,&c);
                    263:        }
                    264: #endif
                    265: }
                    266:
                    267: write_cmo_p(s,p)
                    268: FILE *s;
                    269: P p;
                    270: {
                    271:        int r,i;
                    272:        VL t,vl;
                    273:        char *namestr;
                    274:        STRING name;
                    275:        NODE n0,n;
                    276:
                    277:        r = CMO_RECURSIVE_POLYNOMIAL; write_int(s,&r);
                    278:        get_vars((Obj)p,&vl);
                    279:
                    280:        /* indeterminate list */
                    281:        r = CMO_LIST; write_int(s,&r);
                    282:        for ( t = vl, i = 0; t; t = NEXT(t), i++ );
                    283:        write_int(s,&i);
                    284:        r = CMO_INDETERMINATE;
                    285:        for ( t = vl; t; t = NEXT(t) ) {
                    286:                write_int(s,&r);
                    287: /*             localname_to_cmoname(NAME(t->v),&namestr); */
                    288:                namestr = NAME(t->v);
                    289:                MKSTR(name,namestr);
                    290:                write_cmo(s,name);
                    291:        }
                    292:
                    293:        /* body */
                    294:        write_cmo_upoly(s,vl,p);
                    295: }
                    296:
                    297: write_cmo_upoly(s,vl,p)
                    298: FILE *s;
                    299: VL vl;
                    300: P p;
                    301: {
                    302:        int r,i;
                    303:        V v;
                    304:        DCP dc,dct;
                    305:        VL vlt;
                    306:
                    307:        if ( NUM(p) )
                    308:                write_cmo(s,p);
                    309:        else {
                    310:                r = CMO_UNIVARIATE_POLYNOMIAL; write_int(s,&r);
                    311:                v = VR(p);
                    312:                dc = DC(p);
                    313:                for ( i = 0, dct = dc; dct; dct = NEXT(dct), i++ );
                    314:                write_int(s,&i);
                    315:                for ( i = 0, vlt = vl; vlt->v != v; vlt = NEXT(vlt), i++ );
                    316:                write_int(s,&i);
                    317:                for ( dct = dc; dct; dct = NEXT(dct) ) {
                    318:                        i = QTOS(DEG(dct)); write_int(s,&i);
                    319:                        write_cmo_upoly(s,vl,COEF(dct));
                    320:                }
                    321:        }
                    322: }
                    323:
                    324: write_cmo_r(s,f)
                    325: FILE *s;
                    326: R f;
                    327: {
                    328:        int r;
                    329:
                    330:        r = CMO_RATIONAL; write_int(s,&r);
                    331:        write_cmo(s,NM(f));
                    332:        write_cmo(s,DN(f));
                    333: }
                    334:
                    335: write_cmo_dp(s,dp)
                    336: FILE *s;
                    337: DP dp;
                    338: {
                    339:        int i,n,nv,r;
                    340:        MP m;
                    341:
                    342:        for ( n = 0, m = BDY(dp); m; m = NEXT(m), n++ );
                    343:        r = CMO_DISTRIBUTED_POLYNOMIAL; write_int(s,&r);
                    344:        r = n; write_int(s,&r);
                    345:        r = CMO_DMS_GENERIC; write_int(s,&r);
                    346:        nv = dp->nv;
                    347:        for ( i = 0, m = BDY(dp); i < n; i++, m = NEXT(m) )
                    348:                write_cmo_monomial(s,m,nv);
                    349: }
                    350:
                    351: write_cmo_monomial(s,m,n)
                    352: FILE *s;
                    353: MP m;
                    354: int n;
                    355: {
                    356:        int i,r;
                    357:        int *p;
                    358:
                    359:        r = CMO_MONOMIAL32; write_int(s,&r);
                    360:        write_int(s,&n);
                    361:        for ( i = 0, p = m->dl->d; i < n; i++ ) {
                    362:                write_int(s,p++);
                    363:        }
                    364:        write_cmo_q(s,m->c);
                    365: }
                    366:
                    367: write_cmo_list(s,list)
                    368: FILE *s;
                    369: LIST list;
                    370: {
                    371:        NODE m;
                    372:        int i,n,r;
                    373:
                    374:        for ( n = 0, m = BDY(list); m; m = NEXT(m), n++ );
                    375:        r = CMO_LIST; write_int(s,&r);
                    376:        write_int(s,&n);
                    377:        for ( i = 0, m = BDY(list); i < n; i++, m = NEXT(m) )
                    378:                write_cmo(s,BDY(m));
                    379: }
                    380:
                    381: write_cmo_string(s,str)
                    382: FILE *s;
                    383: STRING str;
                    384: {
                    385:        int r;
                    386:
                    387:        r = CMO_STRING; write_int(s,&r);
                    388:        savestr(s,BDY(str));
                    389: }
                    390:
1.6     ! noro      391: write_cmo_bytearray(s,array)
        !           392: FILE *s;
        !           393: BYTEARRAY array;
        !           394: {
        !           395:        int r;
        !           396:
        !           397:        r = CMO_DATUM; write_int(s,&r);
        !           398:        write_int(s,&array->len);
        !           399:        write_string(s,array->body,array->len);
        !           400: }
        !           401:
1.1       noro      402: write_cmo_error(s,e)
                    403: FILE *s;
                    404: ERR e;
                    405: {
                    406:        int r;
                    407:
                    408:        r = CMO_ERROR2; write_int(s,&r);
                    409:        write_cmo(s,BDY(e));
                    410: }
                    411:
                    412: read_cmo(s,rp)
                    413: FILE *s;
                    414: Obj *rp;
                    415: {
                    416:        int id;
                    417:        int n,sgn,dummy;
                    418:        Q q,qnm,qdn;
                    419:        N nm,dn;
                    420:        P p,pnm,pdn;
                    421:        R r;
1.2       noro      422:        Real real;
                    423:        double dbl;
1.1       noro      424:        STRING str;
                    425:        USINT t;
                    426:        DP dp;
                    427:        char *b;
                    428:        Obj obj;
                    429:        ERR e;
                    430:        MATHCAP mc;
1.6     ! noro      431:        BYTEARRAY array;
1.1       noro      432:
                    433:        read_int(s,&id);
                    434:        switch ( id ) {
                    435:        /* level 0 objects */
                    436:                case CMO_NULL:
                    437:                        *rp = 0;
                    438:                        break;
                    439:                case CMO_INT32:
                    440:                        read_cmo_uint(s,rp);
                    441:                        break;
                    442:                case CMO_DATUM:
1.6     ! noro      443:                        loadbytearray(s,&array); *rp = (Obj)array;
        !           444:                        break;
1.1       noro      445:                case CMO_STRING:
                    446:                        loadstring(s,&str); *rp = (Obj)str;
                    447:                        break;
                    448:                case CMO_MATHCAP:
                    449:                        read_cmo(s,&obj); MKMATHCAP(mc,(LIST)obj);
                    450:                        *rp = (Obj)mc;
                    451:                        break;
                    452:                case CMO_ERROR:
                    453:                        MKERR(e,0); *rp = (Obj)e;
                    454:                        break;
                    455:                case CMO_ERROR2:
                    456:                        read_cmo(s,&obj); MKERR(e,obj); *rp = (Obj)e;
                    457:                        break;
                    458:        /* level 1 objects */
                    459:                case CMO_LIST:
                    460:                        read_cmo_list(s,rp);
                    461:                        break;
                    462:                case CMO_MONOMIAL32:
                    463:                        read_cmo_monomial(s,rp);
                    464:                        break;
                    465:                case CMO_ZZ:
                    466:                        read_cmo_zz(s,&sgn,&nm);
                    467:                        NTOQ(nm,sgn,q); *rp = (Obj)q;
                    468:                        break;
                    469:                case CMO_QQ:
                    470:                        read_cmo_zz(s,&sgn,&nm);
                    471:                        read_cmo_zz(s,&dummy,&dn);
                    472:                        NDTOQ(nm,dn,sgn,q); *rp = (Obj)q;
1.2       noro      473:                        break;
                    474:                case CMO_IEEE_DOUBLE_FLOAT:
                    475:                        read_double(s,&dbl); MKReal(dbl,real); *rp = (Obj)real;
1.1       noro      476:                        break;
                    477:                case CMO_DISTRIBUTED_POLYNOMIAL:
                    478:                        read_cmo_dp(s,&dp); *rp = (Obj)dp;
                    479:                        break;
                    480:                case CMO_RECURSIVE_POLYNOMIAL:
                    481:                        read_cmo_p(s,&p); *rp = (Obj)p;
                    482:                        break;
                    483:                case CMO_UNIVARIATE_POLYNOMIAL:
                    484:                        read_cmo_upoly(s,&p); *rp = (Obj)p;
                    485:                        break;
                    486:                case CMO_INDETERMINATE:
                    487:                        read_cmo(s,&str); *rp = (Obj)str;
                    488:                        break;
                    489:                case CMO_RATIONAL:
                    490:                        read_cmo(s,&pnm); read_cmo(s,&pdn);
                    491:                        divr(CO,(Obj)pnm,(Obj)pdn,rp);
                    492:                        break;
                    493:                case CMO_ZERO:
                    494:                        *rp = 0;
                    495:                        break;
                    496:                case CMO_DMS_OF_N_VARIABLES:
                    497:                        read_cmo(s,rp);
                    498:                        break;
                    499:                case CMO_RING_BY_NAME:
                    500:                        read_cmo(s,rp);
                    501:                        break;
                    502:                default:
                    503:                        MKUSINT(t,id);
                    504:                        t->id = O_VOID;
                    505:                        *rp = (Obj)t;
                    506:                        break;
                    507:        }
                    508: }
                    509:
                    510: read_cmo_uint(s,rp)
                    511: FILE *s;
                    512: USINT *rp;
                    513: {
                    514:        unsigned int body;
                    515:
                    516:        read_int(s,&body);
                    517:        MKUSINT(*rp,body);
                    518: }
                    519:
                    520: read_cmo_zz(s,sgn,rp)
                    521: FILE *s;
                    522: int *sgn;
                    523: N *rp;
                    524: {
                    525:        int l,i,words;
                    526:        N n;
                    527:        unsigned int *b;
                    528:        unsigned int h;
                    529:        unsigned char c;
                    530:
                    531:        read_int(s,&l);
                    532:        if ( l == 0 ) {
                    533:                *sgn = 0;
                    534:                *rp = 0;
                    535:                return;
                    536:        }
                    537:        if ( l < 0 ) {
                    538:                *sgn = -1; l = -l;
                    539:        } else
                    540:                *sgn = 1;
                    541: #if 1
                    542:        *rp = n = NALLOC(l); PL(n) = l;
                    543:        read_intarray(s,BD(n),l);
                    544: #else
                    545:        words = (l+3)/4;
                    546:        *rp = n = NALLOC(words); PL(n) = words; b = BD(n);
                    547:        h = 0;
                    548:        switch ( l % 4 ) {
                    549:                case 0:
                    550:                        read_char(s,&c); h = c;
                    551:                case 3:
                    552:                        read_char(s,&c); h = (h<<8)|c;
                    553:                case 2:
                    554:                        read_char(s,&c); h = (h<<8)|c;
                    555:                case 1:
                    556:                        read_char(s,&c); h = (h<<8)|c;
                    557:        }
                    558:        b[words-1] = h;
                    559:        for ( i = words-2; i >= 0; i-- ) {
                    560:                read_char(s,&c); h = c;
                    561:                read_char(s,&c); h = (h<<8)|c;
                    562:                read_char(s,&c); h = (h<<8)|c;
                    563:                read_char(s,&c); h = (h<<8)|c;
                    564:                b[i] = h;
                    565:        }
                    566: #endif
                    567: }
                    568:
                    569: read_cmo_list(s,rp)
                    570: FILE *s;
                    571: Obj *rp;
                    572: {
                    573:        int len;
                    574:        Obj *w;
                    575:        int i;
                    576:        Obj r,r1;
                    577:        NODE n0,n1;
                    578:        LIST list;
                    579:
                    580:        read_int(s,&len);
                    581:        w = (Obj *)ALLOCA(len*sizeof(Obj));
                    582:        for ( i = 0; i < len; i++ )
                    583:                read_cmo(s,&w[i]);
                    584:        for ( i = len-1, n0 = 0; i >= 0; i-- ) {
                    585:                MKNODE(n1,w[i],n0); n0 = n1;
                    586:        }
                    587:        MKLIST(list,n0);
                    588:        *rp = (Obj)list;
                    589: }
                    590:
                    591: read_cmo_dp(s,rp)
                    592: FILE *s;
                    593: DP *rp;
                    594: {
                    595:        int len;
                    596:        int i;
                    597:        NODE n0,n1;
                    598:        MP mp0,mp;
                    599:        int nv,d;
                    600:        DP dp;
                    601:        Obj obj;
                    602:
                    603:        read_int(s,&len);
                    604:        /* skip the ring definition */
                    605:        read_cmo(s,&obj);
                    606:        for ( mp0 = 0, i = 0, d = 0; i < len; i++ ) {
                    607:                read_cmo(s,&dp);
                    608:                if ( !mp0 ) {
                    609:                        nv = dp->nv;
                    610:                        mp0 = dp->body;
                    611:                        mp = mp0;
                    612:                } else {
                    613:                        NEXT(mp) = dp->body;
                    614:                        mp = NEXT(mp);
                    615:                }
                    616:                d = MAX(d,dp->sugar);
                    617:        }
                    618:        MKDP(nv,mp0,dp);
                    619:        dp->sugar = d; *rp = dp;
                    620: }
                    621:
                    622: read_cmo_monomial(s,rp)
                    623: FILE *s;
                    624: DP *rp;
                    625: {
                    626:        MP m;
                    627:        DP dp;
                    628:        int i,sugar,n;
                    629:        DL dl;
                    630:
                    631:        read_int(s,&n);
                    632:        NEWMP(m); NEWDL(dl,n); m->dl = dl;
                    633:        read_intarray(s,dl->d,n);
                    634:        for ( sugar = 0, i = 0; i < n; i++ )
                    635:                sugar += dl->d[i];
                    636:        dl->td = sugar;
                    637:        read_cmo(s,&m->c);
                    638:        NEXT(m) = 0; MKDP(n,m,dp); dp->sugar = sugar; *rp = dp;
                    639: }
                    640:
                    641: static V *remote_vtab;
                    642:
                    643: read_cmo_p(s,rp)
                    644: FILE *s;
                    645: P *rp;
                    646: {
                    647:        LIST vlist;
                    648:        int nv,i;
                    649:        V *vtab;
                    650:        V v1,v2;
                    651:        NODE t;
                    652:        P v,p;
                    653:        VL tvl,rvl;
                    654:        char *name;
                    655:
                    656:        read_cmo(s,&vlist);
                    657:        nv = length(BDY(vlist));
                    658:        vtab = (V *)ALLOCA(nv*sizeof(V));
                    659:        for ( i = 0, t = BDY(vlist); i < nv; t = NEXT(t), i++ ) {
                    660: /*             cmoname_to_localname(BDY((STRING)BDY(t)),&name); */
                    661:                name = BDY((STRING)BDY(t));
                    662:                makevar(name,&v); vtab[i] = VR(v);
                    663:        }
                    664:        remote_vtab = vtab;
                    665:        read_cmo(s,&p);
                    666:        for ( i = 0; i < nv-1; i++ ) {
                    667:                v1 = vtab[i]; v2 = vtab[i+1];
                    668:                for ( tvl = CO; tvl->v != v1 && tvl->v != v2; tvl = NEXT(tvl) );
                    669:                if ( tvl->v == v2 )
                    670:                        break;
                    671:        }
                    672:        if ( i < nv-1 ) {
                    673:                 for ( i = nv-1, rvl = 0; i >= 0; i-- ) {
                    674:                        NEWVL(tvl); tvl->v = vtab[i]; NEXT(tvl) = rvl; rvl = tvl;
                    675:                 }
                    676:                 reorderp(CO,rvl,p,rp);
                    677:        } else
                    678:                *rp = p;
                    679: }
                    680:
                    681: read_cmo_upoly(s,rp)
                    682: FILE *s;
                    683: P *rp;
                    684: {
                    685:        int n,ind,i,d;
                    686:        P c;
                    687:        Q q;
                    688:        DCP dc0,dc;
                    689:
                    690:        read_int(s,&n);
                    691:        read_int(s,&ind);
                    692:        for ( i = 0, dc0 = 0; i < n; i++ ) {
                    693:                read_int(s,&d);
                    694:                read_cmo(s,&c);
                    695:                if ( c ) {
                    696:                        if ( OID(c) == O_USINT ) {
                    697:                                UTOQ(((USINT)c)->body,q); c = (P)q;
                    698:                        }
                    699:                        NEXTDC(dc0,dc);
                    700:                        STOQ(d,q);
                    701:                        dc->c = c; dc->d = q;
                    702:                }
                    703:        }
                    704:        if ( dc0 )
                    705:                NEXT(dc) = 0;
                    706:        MKP(remote_vtab[ind],dc0,*rp);
                    707: }
                    708:
                    709: localname_to_cmoname(a,b)
                    710: char *a;
                    711: char **b;
                    712: {
                    713:        int l;
                    714:        char *t;
                    715:
                    716:        l = strlen(a);
                    717:        if ( l >= 2 && a[0] == '@' && isupper(a[1]) ) {
                    718:                t = *b = (char *)MALLOC_ATOMIC(l);
                    719:                strcpy(t,a+1);
                    720:        } else {
                    721:                t = *b = (char *)MALLOC_ATOMIC(l+1);
                    722:                strcpy(t,a);
                    723:        }
                    724: }
                    725:
                    726: cmoname_to_localname(a,b)
                    727: char *a;
                    728: char **b;
                    729: {
                    730:        int l;
                    731:        char *t;
                    732:
                    733:        l = strlen(a);
                    734:        if ( isupper(a[0]) ) {
                    735:                t = *b = (char *)MALLOC_ATOMIC(l+2);
                    736:                strcpy(t+1,a);
                    737:                t[0] = '@';
                    738:        } else {
                    739:                t = *b = (char *)MALLOC_ATOMIC(l+1);
                    740:                strcpy(t,a);
                    741:        }
                    742: }

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