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

Annotation of OpenXM_contrib2/asir2000/io/ox.c, Revision 1.12

1.5       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.6       noro       26:  * e-mail at risa-admin@sec.flab.fujitsu.co.jp of the detailed specification
1.5       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.12    ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.11 2001/08/03 08:50:19 noro Exp $
1.5       noro       48: */
1.1       noro       49: #include "ca.h"
                     50: #include "parse.h"
1.3       noro       51: #include "signal.h"
1.1       noro       52: #include "wsio.h"
                     53: #include "ox.h"
                     54:
                     55: #define ISIZ sizeof(int)
                     56:
                     57: extern Obj VOIDobj;
                     58:
                     59: extern int ox_need_conv;
                     60: extern int ox_usr1_sent, ox_int_received, critical_when_signal;
                     61: unsigned int ox_serial;
                     62: int ox_flushing;
                     63: int ox_batch;
                     64: int ox_check=1;
1.2       noro       65: int ox_exchange_mathcap=1;
1.1       noro       66: jmp_buf ox_env;
                     67:
                     68: MATHCAP my_mathcap;
                     69:
                     70: struct oxcap {
                     71:        unsigned int ox;
                     72:        int ncap;
                     73:        int *cap;
                     74: };
                     75:
                     76: struct mathcap {
                     77:        LIST mc;
                     78:        unsigned int version;
                     79:        char *servername;
                     80:        int nsmcap;
                     81:        unsigned int *smcap;
                     82:        int noxcap;
                     83:        struct oxcap *oxcap;
                     84: };
                     85:
                     86: struct oxcap *my_oxcap;
                     87:
                     88: static struct mathcap my_mc;
                     89: static struct mathcap *remote_mc;
                     90: static int remote_mc_len;
                     91:
1.12    ! noro       92: void mclist_to_mc(LIST mclist,struct mathcap *mc);
        !            93:
1.9       noro       94: #if defined(VISUAL)
                     95: /* XXX : mainly used in engine2000/io.c, but declared here */
                     96: HANDLE hStreamNotify,hStreamNotify_Ack;
                     97:
                     98: void cleanup_events()
                     99: {
                    100:        /* ox_watch_stream may be waiting for hStreamNotify_Ack to be set */
                    101:
                    102:        ResetEvent(hStreamNotify);
                    103:        SetEvent(hStreamNotify_Ack);
                    104: }
                    105: #endif
                    106:
1.12    ! noro      107: void ox_resetenv(char *s)
1.1       noro      108: {
1.9       noro      109: #if defined(VISUAL)
                    110:        cleanup_events();
                    111: #endif
1.1       noro      112:        fprintf(stderr,"%s\n",s);
                    113:        longjmp(ox_env,1);
                    114: }
                    115:
                    116: static int available_cmo[] = {
                    117:        CMO_NULL, CMO_INT32, CMO_DATUM, CMO_STRING, CMO_MATHCAP,
                    118:        CMO_ERROR, CMO_ERROR2, CMO_LIST, CMO_MONOMIAL32,
                    119:        CMO_ZZ, CMO_QQ, CMO_ZERO,
                    120:        CMO_DMS_GENERIC, CMO_DMS_OF_N_VARIABLES,
                    121:        CMO_RING_BY_NAME, CMO_DISTRIBUTED_POLYNOMIAL,
                    122:        CMO_RECURSIVE_POLYNOMIAL, CMO_UNIVARIATE_POLYNOMIAL,
                    123:        CMO_INDETERMINATE,
1.11      noro      124:        CMO_TREE,
1.1       noro      125:        0
                    126: };
                    127:
                    128: static int available_sm[] = {
                    129:        SM_dupErrors, SM_getsp, SM_popSerializedLocalObject,
1.7       noro      130:        SM_popCMO, SM_popString, SM_pushCMOtag, SM_setName,
1.1       noro      131:        SM_evalName, SM_executeStringByLocalParser,
                    132:        SM_executeStringByLocalParserInBatchMode,
                    133:        SM_executeFunction, SM_shutdown, SM_pops,
                    134:        SM_mathcap, SM_setMathcap, SM_nop,
                    135:        SM_beginBlock, SM_endBlock,
                    136:        0
                    137: };
                    138:
                    139: /*
                    140:        mathcap =
                    141:                [
                    142:                        version list,
                    143:                        SMlist,
                    144:                        [
                    145:                                [OX tag,CMO tag list],
                    146:                                [OX tag,CMO tag list],
                    147:                                ...
                    148:                        ]
                    149:                ]
                    150: */
                    151:
                    152: void create_my_mathcap(char *system)
                    153: {
                    154:        NODE n,n0;
                    155:        int i,k;
                    156:        STRING str;
1.12    ! noro      157:        LIST sname,smlist,oxlist,cmolist,asirlist,oxasir,r;
1.1       noro      158:        USINT tag,t,t1;
                    159:
                    160:        if ( my_mathcap )
                    161:                return;
                    162:        /* version */
                    163:        MKSTR(str,system);
                    164:        MKUSINT(t,OX_VERSION);
                    165:        n0 = mknode(2,t,str); MKLIST(sname,n0);
                    166:
                    167:        /* cmo tag */
                    168:        for ( n0 = 0, i = 0; k = available_sm[i]; i++ ) {
                    169:                NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
                    170:        }
                    171:        NEXT(n) = 0; MKLIST(smlist,n0);
                    172:
                    173:        /* creation of [OX_DATA,CMO list] */
                    174:        /* ox tag */
                    175:        MKUSINT(tag,OX_DATA);
                    176:        /* cmo tag */
                    177:        for ( n0 = 0, i = 0; k = available_cmo[i]; i++ ) {
                    178:                NEXTNODE(n0,n); MKUSINT(t,k); BDY(n) = (pointer)t;
                    179:        }
                    180:        NEXT(n) = 0; MKLIST(cmolist,n0);
                    181:        /* [ox tag, cmo list] */
                    182:        n0 = mknode(2,tag,cmolist);
                    183:        MKLIST(oxlist,n0);
                    184:
                    185:        /* creation of [OX_LOCAL_OBJECT_ASIR,ASIR tag] */
                    186:        /* ox tag */
                    187:        MKUSINT(tag,OX_LOCAL_OBJECT_ASIR);
                    188:        /* local tag */
                    189:        MKUSINT(t,ASIR_VL);
                    190:        MKUSINT(t1,ASIR_OBJ);
                    191:        n0 = mknode(2,t,t1); MKLIST(cmolist,n0);
                    192:        /* [ox tag, local list] */
                    193:        n0 = mknode(2,tag,cmolist);
                    194:         MKLIST(asirlist,n0);
                    195:
                    196:        /* [oxlist,asirlist] */
                    197:        n0 = mknode(2,oxlist,asirlist); MKLIST(oxasir,n0);
                    198:
                    199:        /* [version,sm,oxasir] */
                    200:        n0 = mknode(3,sname,smlist,oxasir); MKLIST(r,n0);
                    201:
                    202:        MKMATHCAP(my_mathcap,r);
                    203:        mclist_to_mc(r,&my_mc);
                    204:        my_oxcap = my_mc.oxcap;
                    205: }
                    206:
                    207: void store_remote_mathcap(int s,MATHCAP mc)
                    208: {
                    209:        if ( !remote_mc ) {
                    210:                 remote_mc_len = 16;
                    211:                 remote_mc = (struct mathcap *)
                    212:                        CALLOC(remote_mc_len,sizeof(struct mathcap));
                    213:        }
                    214:        if ( s >= remote_mc_len ) {
                    215:                remote_mc_len *= 2;
                    216:                remote_mc = (struct mathcap *)REALLOC(remote_mc,
                    217:                        remote_mc_len*sizeof(struct mathcap));
                    218:        }
                    219:        mclist_to_mc(BDY(mc),&remote_mc[s]);
                    220: }
                    221:
                    222: /*
                    223:        mathcap =
                    224:                [
                    225:                        version list,
                    226:                        SMlist,
                    227:                        [
                    228:                                [OX tag,CMO tag list],
                    229:                                [OX tag,CMO tag list],
                    230:                                ...
                    231:                        ]
                    232:                ]
                    233:
                    234:     ===>
                    235:
                    236:        mathcap
                    237:                | version | &servername | nsmcap |      &smcap | noxcap | &oxcap |
                    238:        smcap
                    239:                | SM_xxx | SM_yyy | ... |
                    240:        oxcap
                    241:                | oxcap[0] | oxcap[1] | ... |
                    242:        oxcap[i]
                    243:                | ox | ncap | &cap |
                    244:        cap
                    245:                | CMO_xxx | CMO_yyy | ... |
                    246: */
                    247:
                    248: void mclist_to_mc(LIST mclist,struct mathcap *mc)
                    249: {
1.12    ! noro      250:        int l,i,j;
        !           251:        NODE n,t,oxcmo,cap;
1.1       noro      252:        int *ptr;
                    253:
                    254:        /*
                    255:                [
                    256:                        [ version,servername ]
                    257:                        [sm1,sm2,...],
                    258:                        [
                    259:                                [o1,[n11,n12,...]],
                    260:                                [o2,[n21,n22,...]],
                    261:                                ...
                    262:                        ]
                    263:                ]
                    264:        */
                    265:        n = BDY(mclist);
                    266:        mc->mc = mclist;
                    267:        mc->version = BDY((USINT)BDY(BDY((LIST)BDY(n))));
                    268:        mc->servername = BDY((STRING)BDY(NEXT(BDY((LIST)BDY(n)))));
                    269:
                    270:        /* smcap */
                    271:        n = NEXT(n);
                    272:        t = BDY((LIST)BDY(n));
                    273:        mc->nsmcap = length(t);
                    274:        mc->smcap = (int *)MALLOC_ATOMIC(mc->nsmcap*sizeof(int));
                    275:        for ( j = 0, ptr = mc->smcap; j < mc->nsmcap; j++, t = NEXT(t) )
                    276:                ptr[j] = BDY((USINT)BDY(t));
                    277:
                    278:        n = NEXT(n);
                    279:        n = BDY((LIST)BDY(n));
                    280:        /* n -> BDY([[OX1,CMOlist1], [OX2,CMOlist2], ...]) */
                    281:        mc->noxcap = length(n);
                    282:        mc->oxcap = (struct oxcap *)MALLOC(mc->noxcap*sizeof(struct oxcap));
                    283:        for ( j = 0; j < mc->noxcap; j++, n = NEXT(n) ) {
                    284:                oxcmo = BDY((LIST)BDY(n));
                    285:                /* oxcmo = BDY([OXj,CMOlistj]) */
                    286:                mc->oxcap[j].ox = BDY((USINT)BDY(oxcmo));
                    287:                cap = BDY((LIST)BDY(NEXT(oxcmo)));
                    288:                /* cap ->BDY(CMOlistj) */
                    289:                l = length(cap);
                    290:                mc->oxcap[j].ncap = l;
                    291:                mc->oxcap[j].cap = (unsigned int *)CALLOC(l+1,sizeof(unsigned int));
                    292:                for ( t = cap, ptr = mc->oxcap[j].cap, i = 0; i < l; t = NEXT(t), i++ )
                    293:                        ptr[i] = BDY((USINT)BDY(t));
                    294:        }
                    295: }
                    296:
1.12    ! noro      297: int check_sm_by_mc(int s,unsigned int smtag)
1.1       noro      298: {
                    299:        struct mathcap *rmc;
                    300:        int nsmcap,i;
                    301:        unsigned int *smcap;
                    302:
                    303:        /* XXX : return 1 if remote_mc is not available. */
                    304:        if ( !remote_mc )
                    305:                return 1;
                    306:        rmc = &remote_mc[s];
                    307:        nsmcap = rmc->nsmcap;
                    308:        smcap = rmc->smcap;
                    309:        if ( !smcap )
                    310:                return 1;
                    311:        for ( i = 0; i < nsmcap; i++ )
                    312:                if ( smcap[i] == smtag )
                    313:                        break;
                    314:        if ( i == nsmcap )
                    315:                return 0;
                    316:        else
                    317:                return 1;
                    318: }
                    319:
1.12    ! noro      320: int check_by_mc(int s,unsigned int oxtag,unsigned int cmotag)
1.1       noro      321: {
                    322:        struct mathcap *rmc;
                    323:        int noxcap,ncap,i,j;
                    324:        struct oxcap *oxcap;
                    325:        unsigned int *cap;
                    326:
                    327:        /* XXX : return 1 if remote_mc is not available. */
                    328:        if ( !remote_mc )
                    329:                return 1;
                    330:        rmc = &remote_mc[s];
                    331:        noxcap = rmc->noxcap;
                    332:        oxcap = rmc->oxcap;
                    333:        if ( !oxcap )
                    334:                return 1;
                    335:        for ( i = 0; i < noxcap; i++ )
                    336:                if ( oxcap[i].ox == oxtag )
                    337:                        break;
                    338:        if ( i == noxcap )
                    339:                return 0;
                    340:        ncap = oxcap[i].ncap;
                    341:        cap = oxcap[i].cap;
                    342:        for ( j = 0; j < ncap; j++ )
                    343:                if ( cap[j] == cmotag )
                    344:                        break;
                    345:        if ( j == ncap )
                    346:                return 0;
                    347:        else
                    348:                return 1;
                    349: }
                    350:
                    351: void begin_critical() {
                    352:        critical_when_signal = 1;
                    353: }
                    354:
                    355: void end_critical() {
                    356:        critical_when_signal = 0;
                    357:        if ( ox_usr1_sent ) {
1.12    ! noro      358:                ox_usr1_sent = 0;
        !           359: #if !defined(VISUAL)
        !           360:        ox_usr1_handler(SIGUSR1);
        !           361: #else
        !           362:        ox_usr1_handler(0);
        !           363: #endif
1.1       noro      364:        }
                    365:        if ( ox_int_received ) {
                    366:                ox_int_received = 0; int_handler(SIGINT);
                    367:        }
                    368: }
                    369:
1.12    ! noro      370: void ox_usr1_handler(int sig)
1.1       noro      371: {
                    372:        extern jmp_buf env;
                    373:
                    374: #if !defined(VISUAL)
                    375:        signal(SIGUSR1,ox_usr1_handler);
                    376: #endif
                    377:        if ( critical_when_signal ) {
                    378:                fprintf(stderr,"usr1 : critical\n");
                    379:                ox_usr1_sent = 1;
                    380:        } else {
                    381:                ox_flushing = 1;
                    382:                ox_resetenv("usr1 : return to toplevel by SIGUSR1");
                    383:        }
                    384: }
                    385:
                    386: void clear_readbuffer()
                    387: {
                    388: #if defined(linux)
                    389:        iofp[0].in->_IO_read_ptr = iofp[0].in->_IO_read_end;
                    390: #elif defined(__FreeBSD__)
                    391:        fpurge(iofp[0].in);
                    392: #endif
                    393: /*
                    394:        sock = fileno(iofp[0].in);
                    395:        interval.tv_sec = (int)0;
                    396:        interval.tv_usec = (int)0;
                    397:
                    398:        FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
                    399:        FD_SET(sock,&r);
                    400:        while ( 1 ) {
                    401:                n = select(FD_SETSIZE,&r,&w,&e,&interval);
                    402:                if ( !n )
                    403:                        break;
                    404:                read(sock,&c,1);
                    405:        }
                    406: */
                    407: }
                    408:
                    409: #if MPI
                    410: int ox_data_is_available(int s)
                    411: {
                    412:        return 1;
                    413: }
                    414:
                    415: void wait_for_data(int s)
                    416: {
                    417:        return;
                    418: }
                    419: #else
                    420: int ox_data_is_available(int s)
                    421: {
                    422:        return FP_DATA_IS_AVAILABLE(iofp[s].in);
                    423: }
                    424:
                    425: void wait_for_data(int s)
                    426: {
                    427:        fd_set r;
                    428:        int sock;
                    429:
                    430:        if ( !FP_DATA_IS_AVAILABLE(iofp[s].in) ) {
                    431: #if defined(VISUAL)
                    432:                sock = iofp[s].in->fildes;
                    433:                FD_ZERO(&r);
1.12    ! noro      434:                FD_SET((unsigned int)sock,&r);
1.1       noro      435:                select(0,&r,NULL,NULL,NULL);
                    436: #else
                    437:                sock = fileno(iofp[s].in);
                    438:                FD_ZERO(&r);
                    439:                FD_SET(sock,&r);
                    440:                select(FD_SETSIZE,&r,NULL,NULL,NULL);
                    441: #endif
                    442:        }
                    443: }
                    444: #endif
                    445:
                    446: void ox_send_data(int s,pointer p)
                    447: {
1.8       noro      448:        ERR err;
                    449:
                    450:        if ( ox_check && !ox_check_cmo(s,(Obj)p) ) {
                    451:                create_error(&err,ox_serial,"ox_send_data : Mathcap violation");
                    452:                p = (pointer)err;
                    453:        }
1.1       noro      454:        begin_critical();
                    455:        ox_write_int(s,OX_DATA);
                    456:        ox_write_int(s,ox_serial++);
                    457:        ox_write_cmo(s,p);
                    458:        ox_flush_stream(s);
                    459:        end_critical();
                    460: }
                    461:
                    462: void ox_send_cmd(int s,int id)
                    463: {
                    464:        if ( ox_check && !check_sm_by_mc(s,id) )
                    465:                error("ox_send_cmd : Mathcap violation");
                    466:        begin_critical();
                    467:        ox_write_int(s,OX_COMMAND);
                    468:        ox_write_int(s,ox_serial++);
                    469:        ox_write_int(s,id);
                    470:        ox_flush_stream(s);
                    471:        end_critical();
                    472: }
                    473:
                    474: void ox_send_sync(int s)
                    475: {
                    476:        begin_critical();
                    477:        ox_write_int(s,OX_SYNC_BALL);
                    478:        ox_write_int(s,ox_serial++);
                    479:        ox_flush_stream(s);
                    480:        end_critical();
                    481: }
                    482:
                    483: void ox_send_local_data(int s,Obj p)
                    484: {
                    485:        begin_critical();
                    486:        ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
                    487:        ox_write_int(s,ox_serial++);
                    488:        ox_write_int(s,ASIR_OBJ);
1.12    ! noro      489:        saveobj((FILE *)iofp[s].out,p);
1.1       noro      490:        ox_flush_stream(s);
                    491:        end_critical();
                    492: }
                    493:
                    494: void ox_send_local_ring(int s,VL vl)
                    495: {
                    496:        begin_critical();
                    497:        ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
                    498:        ox_write_int(s,ox_serial++);
                    499:        ox_write_int(s,ASIR_VL);
1.12    ! noro      500:        savevl((FILE *)iofp[s].out,vl);
1.1       noro      501:        ox_flush_stream(s);
                    502:        end_critical();
                    503: }
                    504:
1.12    ! noro      505: unsigned int ox_recv(int s, int *id, Obj *p)
1.1       noro      506: {
                    507:        unsigned int cmd,serial;
                    508:        USINT ui;
                    509:
                    510:        wait_for_data(s);
                    511:        begin_critical();
                    512:        ox_read_int(s,id);
                    513:        ox_read_int(s,&serial);
                    514:        switch ( *id ) {
                    515:                case OX_COMMAND:
                    516:                        ox_read_int(s,&cmd);
                    517:                        MKUSINT(ui,cmd);
1.12    ! noro      518:                        *p = (Obj)ui;
1.1       noro      519:                        break;
                    520:                case OX_DATA:
                    521:                        ox_read_cmo(s,p);
                    522:                        break;
                    523:                case OX_LOCAL_OBJECT_ASIR:
                    524:                        ox_read_local(s,p);
                    525:                        break;
                    526:                default:
                    527:                        *p = 0;
                    528:                        break;
                    529:        }
                    530:        end_critical();
                    531:        return serial;
                    532: }
                    533:
1.12    ! noro      534: void ox_get_result(int s,Obj *rp)
1.1       noro      535: {
                    536:        int id;
                    537:        Obj obj,r;
                    538:        int level;
                    539:
                    540:        level = 0;
                    541:        r = 0;
                    542:        do {
1.12    ! noro      543:                ox_recv(s,&id,&obj);
1.1       noro      544:                if ( id == OX_COMMAND ) {
                    545:                        switch ( ((USINT)obj)->body ) {
                    546:                                case SM_beginBlock:
                    547:                                        level++;
                    548:                                        break;
                    549:                                case SM_endBlock:
                    550:                                        level--;
                    551:                        }
                    552:                } else
                    553:                        r = obj;
                    554:        } while ( level );
                    555:        *rp = r;
                    556: }
                    557:
                    558: void ox_read_int(int s, int *n)
                    559: {
                    560:        ox_need_conv = iofp[s].conv;
1.12    ! noro      561:        read_int((FILE *)iofp[s].in,n);
1.1       noro      562: }
                    563:
                    564: void ox_read_cmo(int s, Obj *rp)
                    565: {
                    566:        ox_need_conv = iofp[s].conv;
1.12    ! noro      567:        read_cmo((FILE *)iofp[s].in,rp);
1.1       noro      568: }
                    569:
                    570: void ox_read_local(int s, Obj *rp)
                    571: {
                    572:        int id;
                    573:
                    574:        ox_need_conv = iofp[s].conv;
1.12    ! noro      575:        read_int((FILE *)iofp[s].in,&id);
1.1       noro      576:        switch ( id ) {
                    577:                case ASIR_VL:
1.12    ! noro      578:                        loadvl((FILE *)iofp[s].in);
1.1       noro      579:                        *rp = VOIDobj;
                    580:                        break;
                    581:                case ASIR_OBJ:
1.12    ! noro      582:                        loadobj((FILE *)iofp[s].in,rp);
1.1       noro      583:                        break;
                    584:                default:
                    585:                        error("ox_read_local : unsupported id");
                    586:                        break;
                    587:        }
                    588: }
                    589:
                    590: void ox_write_int(int s, int n)
                    591: {
                    592:        ox_need_conv = iofp[s].conv;
1.12    ! noro      593:        write_int((FILE *)iofp[s].out,&n);
1.1       noro      594: }
                    595:
                    596: void ox_write_cmo(int s, Obj obj)
                    597: {
                    598:        ox_need_conv = iofp[s].conv;
1.12    ! noro      599:        write_cmo((FILE *)iofp[s].out,obj);
1.1       noro      600: }
                    601:
                    602: int ox_check_cmo(int s, Obj obj)
                    603: {
                    604:        NODE m;
                    605:
                    606:        if ( !obj )
                    607:                return 1;
                    608:        switch ( OID(obj) ) {
                    609:                case O_MATHCAP: case O_STR: case O_ERR: case O_USINT: case O_VOID:
1.10      noro      610:                case O_BYTEARRAY:
1.1       noro      611:                        return 1;
                    612:                case O_P:
                    613:                        if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
                    614:                                return 0;
                    615:                        else
                    616:                                return ox_check_cmo_p(s,(P)obj);
                    617:                case O_R:
                    618:                        if ( !check_by_mc(s,OX_DATA,CMO_RATIONAL) )
                    619:                                return 0;
                    620:                        else if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
                    621:                                return 0;
                    622:                        else
                    623:                                return ox_check_cmo_p(s,NM((R)obj)) && ox_check_cmo_p(s,DN((R)obj));
                    624:                case O_DP:
                    625:                        return ox_check_cmo_dp(s,(DP)obj);
                    626:                case O_N:
1.4       noro      627:                        switch ( NID((Num)obj) ) {
                    628:                                case N_Q:
                    629:                                        if ( INT((Q)obj) )
                    630:                                                return check_by_mc(s,OX_DATA,CMO_ZZ);
                    631:                                        else
                    632:                                                return check_by_mc(s,OX_DATA,CMO_QQ);
                    633:                                case N_R:
                    634:                                        return 1;
                    635:                                default:
                    636:                                        return 0;
                    637:                        }
                    638:                        break;
1.1       noro      639:                case O_LIST:
                    640:                        for ( m = BDY((LIST)obj); m; m = NEXT(m) )
                    641:                                if ( !ox_check_cmo(s,(BDY(m))) )
                    642:                                        return 0;
1.11      noro      643:                        return 1;
                    644:                case O_QUOTE: /* XXX */
1.1       noro      645:                        return 1;
                    646:                default:
                    647:                        return 0;
                    648:        }
                    649: }
                    650:
                    651: void ox_get_serverinfo(int s, LIST *rp)
                    652: {
                    653:        if ( remote_mc )
                    654:                *rp = remote_mc[s].mc;
                    655:        else {
                    656:                MKLIST(*rp,0);
                    657:        }
                    658: }
                    659:
                    660: int ox_check_cmo_p(int s, P p)
                    661: {
                    662:        DCP dc;
                    663:
                    664:        if ( NUM(p) )
                    665:                return ox_check_cmo(s,(Obj)p);
                    666:        else {
                    667:                for ( dc = DC(p); dc; dc = NEXT(dc) )
                    668:                        if ( !ox_check_cmo_p(s,COEF(dc)) )
                    669:                                return 0;
                    670:                return 1;
                    671:        }
                    672: }
                    673:
                    674: int ox_check_cmo_dp(int s, DP p)
                    675: {
                    676:        MP m;
                    677:
                    678:        for ( m = BDY(p); m; m = NEXT(m) )
                    679:                if ( !ox_check_cmo(s,(Obj)m->c) )
                    680:                        return 0;
                    681:        return 1;
                    682: }
                    683:
1.12    ! noro      684: void ox_flush_stream(int s)
1.1       noro      685: {
                    686:        if ( ox_batch )
                    687:                return;
                    688: #if defined(VISUAL)
                    689:        if ( _fileno(&iofp[s].out->fp) < 0 )
                    690:                cflush(iofp[s].out);
                    691:        else
                    692: #elif MPI
                    693:        if ( (char)fileno(&iofp[s].out->fp) < 0 )
                    694:                cflush(iofp[s].out);
                    695:        else
                    696: #endif
1.12    ! noro      697:        fflush((FILE *)iofp[s].out);
1.1       noro      698: }
                    699:
1.12    ! noro      700: void ox_flush_stream_force(int s)
1.1       noro      701: {
                    702: #if defined(VISUAL)
                    703:        if ( _fileno(&iofp[s].out->fp) < 0 )
                    704:                cflush(iofp[s].out);
                    705:        else
                    706: #elif MPI
                    707:        if ( (char)fileno(&iofp[s].out->fp) < 0 )
                    708:                cflush(iofp[s].out);
                    709:        else
                    710: #endif
1.12    ! noro      711:        fflush((FILE *)iofp[s].out);
1.1       noro      712: }

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