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

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

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