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

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.18    ! noro       47:  * $OpenXM: OpenXM_contrib2/asir2000/io/ox.c,v 1.17 2002/10/03 03:35:08 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.18    ! noro      403: extern FUNC registered_handler;
        !           404:
1.12      noro      405: void ox_usr1_handler(int sig)
1.1       noro      406: {
                    407: #if !defined(VISUAL)
                    408:        signal(SIGUSR1,ox_usr1_handler);
                    409: #endif
                    410:        if ( critical_when_signal ) {
                    411:                fprintf(stderr,"usr1 : critical\n");
                    412:                ox_usr1_sent = 1;
                    413:        } else {
                    414:                ox_flushing = 1;
1.18    ! noro      415:                if ( registered_handler ) {
        !           416:                        fprintf(stderr,
        !           417:                                "usr1 : calling the registered exception handler...");
        !           418:                        bevalf(registered_handler,0);
        !           419:                        fprintf(stderr, "done.\n");
        !           420:                }
1.1       noro      421:                ox_resetenv("usr1 : return to toplevel by SIGUSR1");
                    422:        }
                    423: }
                    424:
                    425: void clear_readbuffer()
                    426: {
                    427: #if defined(linux)
                    428:        iofp[0].in->_IO_read_ptr = iofp[0].in->_IO_read_end;
                    429: #elif defined(__FreeBSD__)
                    430:        fpurge(iofp[0].in);
                    431: #endif
                    432: /*
                    433:        sock = fileno(iofp[0].in);
                    434:        interval.tv_sec = (int)0;
                    435:        interval.tv_usec = (int)0;
                    436:
                    437:        FD_ZERO(&r); FD_ZERO(&w); FD_ZERO(&e);
                    438:        FD_SET(sock,&r);
                    439:        while ( 1 ) {
                    440:                n = select(FD_SETSIZE,&r,&w,&e,&interval);
                    441:                if ( !n )
                    442:                        break;
                    443:                read(sock,&c,1);
                    444:        }
                    445: */
                    446: }
                    447:
                    448: #if MPI
                    449: int ox_data_is_available(int s)
                    450: {
                    451:        return 1;
                    452: }
                    453:
                    454: void wait_for_data(int s)
                    455: {
                    456:        return;
                    457: }
                    458: #else
                    459: int ox_data_is_available(int s)
                    460: {
                    461:        return FP_DATA_IS_AVAILABLE(iofp[s].in);
                    462: }
                    463:
                    464: void wait_for_data(int s)
                    465: {
                    466:        fd_set r;
                    467:        int sock;
                    468:
                    469:        if ( !FP_DATA_IS_AVAILABLE(iofp[s].in) ) {
                    470: #if defined(VISUAL)
                    471:                sock = iofp[s].in->fildes;
                    472:                FD_ZERO(&r);
1.12      noro      473:                FD_SET((unsigned int)sock,&r);
1.1       noro      474:                select(0,&r,NULL,NULL,NULL);
                    475: #else
                    476:                sock = fileno(iofp[s].in);
                    477:                FD_ZERO(&r);
                    478:                FD_SET(sock,&r);
                    479:                select(FD_SETSIZE,&r,NULL,NULL,NULL);
                    480: #endif
                    481:        }
                    482: }
                    483: #endif
                    484:
                    485: void ox_send_data(int s,pointer p)
                    486: {
1.8       noro      487:        ERR err;
                    488:
                    489:        if ( ox_check && !ox_check_cmo(s,(Obj)p) ) {
                    490:                create_error(&err,ox_serial,"ox_send_data : Mathcap violation");
                    491:                p = (pointer)err;
                    492:        }
1.1       noro      493:        begin_critical();
                    494:        ox_write_int(s,OX_DATA);
                    495:        ox_write_int(s,ox_serial++);
                    496:        ox_write_cmo(s,p);
                    497:        ox_flush_stream(s);
                    498:        end_critical();
                    499: }
                    500:
                    501: void ox_send_cmd(int s,int id)
                    502: {
                    503:        if ( ox_check && !check_sm_by_mc(s,id) )
                    504:                error("ox_send_cmd : Mathcap violation");
                    505:        begin_critical();
                    506:        ox_write_int(s,OX_COMMAND);
                    507:        ox_write_int(s,ox_serial++);
                    508:        ox_write_int(s,id);
                    509:        ox_flush_stream(s);
                    510:        end_critical();
                    511: }
                    512:
                    513: void ox_send_sync(int s)
                    514: {
                    515:        begin_critical();
                    516:        ox_write_int(s,OX_SYNC_BALL);
                    517:        ox_write_int(s,ox_serial++);
                    518:        ox_flush_stream(s);
                    519:        end_critical();
                    520: }
                    521:
                    522: void ox_send_local_data(int s,Obj p)
                    523: {
                    524:        begin_critical();
                    525:        ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
                    526:        ox_write_int(s,ox_serial++);
                    527:        ox_write_int(s,ASIR_OBJ);
1.12      noro      528:        saveobj((FILE *)iofp[s].out,p);
1.1       noro      529:        ox_flush_stream(s);
                    530:        end_critical();
                    531: }
                    532:
                    533: void ox_send_local_ring(int s,VL vl)
                    534: {
                    535:        begin_critical();
                    536:        ox_write_int(s,OX_LOCAL_OBJECT_ASIR);
                    537:        ox_write_int(s,ox_serial++);
                    538:        ox_write_int(s,ASIR_VL);
1.12      noro      539:        savevl((FILE *)iofp[s].out,vl);
1.1       noro      540:        ox_flush_stream(s);
                    541:        end_critical();
                    542: }
                    543:
1.12      noro      544: unsigned int ox_recv(int s, int *id, Obj *p)
1.1       noro      545: {
                    546:        unsigned int cmd,serial;
                    547:        USINT ui;
                    548:
                    549:        wait_for_data(s);
                    550:        begin_critical();
                    551:        ox_read_int(s,id);
                    552:        ox_read_int(s,&serial);
                    553:        switch ( *id ) {
                    554:                case OX_COMMAND:
                    555:                        ox_read_int(s,&cmd);
                    556:                        MKUSINT(ui,cmd);
1.12      noro      557:                        *p = (Obj)ui;
1.1       noro      558:                        break;
                    559:                case OX_DATA:
                    560:                        ox_read_cmo(s,p);
                    561:                        break;
                    562:                case OX_LOCAL_OBJECT_ASIR:
                    563:                        ox_read_local(s,p);
                    564:                        break;
                    565:                default:
                    566:                        *p = 0;
                    567:                        break;
                    568:        }
                    569:        end_critical();
                    570:        return serial;
                    571: }
                    572:
1.12      noro      573: void ox_get_result(int s,Obj *rp)
1.1       noro      574: {
                    575:        int id;
                    576:        Obj obj,r;
                    577:        int level;
                    578:
                    579:        level = 0;
                    580:        r = 0;
                    581:        do {
1.12      noro      582:                ox_recv(s,&id,&obj);
1.1       noro      583:                if ( id == OX_COMMAND ) {
                    584:                        switch ( ((USINT)obj)->body ) {
                    585:                                case SM_beginBlock:
                    586:                                        level++;
                    587:                                        break;
                    588:                                case SM_endBlock:
                    589:                                        level--;
                    590:                        }
                    591:                } else
                    592:                        r = obj;
                    593:        } while ( level );
                    594:        *rp = r;
                    595: }
                    596:
                    597: void ox_read_int(int s, int *n)
                    598: {
                    599:        ox_need_conv = iofp[s].conv;
1.12      noro      600:        read_int((FILE *)iofp[s].in,n);
1.1       noro      601: }
                    602:
                    603: void ox_read_cmo(int s, Obj *rp)
                    604: {
                    605:        ox_need_conv = iofp[s].conv;
1.12      noro      606:        read_cmo((FILE *)iofp[s].in,rp);
1.1       noro      607: }
                    608:
                    609: void ox_read_local(int s, Obj *rp)
                    610: {
                    611:        int id;
                    612:
                    613:        ox_need_conv = iofp[s].conv;
1.12      noro      614:        read_int((FILE *)iofp[s].in,&id);
1.1       noro      615:        switch ( id ) {
                    616:                case ASIR_VL:
1.12      noro      617:                        loadvl((FILE *)iofp[s].in);
1.1       noro      618:                        *rp = VOIDobj;
                    619:                        break;
                    620:                case ASIR_OBJ:
1.12      noro      621:                        loadobj((FILE *)iofp[s].in,rp);
1.1       noro      622:                        break;
                    623:                default:
                    624:                        error("ox_read_local : unsupported id");
                    625:                        break;
                    626:        }
                    627: }
                    628:
                    629: void ox_write_int(int s, int n)
                    630: {
                    631:        ox_need_conv = iofp[s].conv;
1.12      noro      632:        write_int((FILE *)iofp[s].out,&n);
1.1       noro      633: }
                    634:
                    635: void ox_write_cmo(int s, Obj obj)
                    636: {
                    637:        ox_need_conv = iofp[s].conv;
1.12      noro      638:        write_cmo((FILE *)iofp[s].out,obj);
1.1       noro      639: }
                    640:
                    641: int ox_check_cmo(int s, Obj obj)
                    642: {
                    643:        NODE m;
                    644:
                    645:        if ( !obj )
                    646:                return 1;
                    647:        switch ( OID(obj) ) {
                    648:                case O_MATHCAP: case O_STR: case O_ERR: case O_USINT: case O_VOID:
1.10      noro      649:                case O_BYTEARRAY:
1.1       noro      650:                        return 1;
                    651:                case O_P:
                    652:                        if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
                    653:                                return 0;
                    654:                        else
                    655:                                return ox_check_cmo_p(s,(P)obj);
                    656:                case O_R:
                    657:                        if ( !check_by_mc(s,OX_DATA,CMO_RATIONAL) )
                    658:                                return 0;
                    659:                        else if ( !check_by_mc(s,OX_DATA,CMO_RECURSIVE_POLYNOMIAL) )
                    660:                                return 0;
                    661:                        else
                    662:                                return ox_check_cmo_p(s,NM((R)obj)) && ox_check_cmo_p(s,DN((R)obj));
                    663:                case O_DP:
                    664:                        return ox_check_cmo_dp(s,(DP)obj);
                    665:                case O_N:
1.4       noro      666:                        switch ( NID((Num)obj) ) {
                    667:                                case N_Q:
                    668:                                        if ( INT((Q)obj) )
                    669:                                                return check_by_mc(s,OX_DATA,CMO_ZZ);
                    670:                                        else
                    671:                                                return check_by_mc(s,OX_DATA,CMO_QQ);
                    672:                                case N_R:
                    673:                                        return 1;
                    674:                                default:
                    675:                                        return 0;
                    676:                        }
                    677:                        break;
1.1       noro      678:                case O_LIST:
                    679:                        for ( m = BDY((LIST)obj); m; m = NEXT(m) )
                    680:                                if ( !ox_check_cmo(s,(BDY(m))) )
                    681:                                        return 0;
1.11      noro      682:                        return 1;
                    683:                case O_QUOTE: /* XXX */
1.1       noro      684:                        return 1;
                    685:                default:
                    686:                        return 0;
                    687:        }
                    688: }
                    689:
                    690: void ox_get_serverinfo(int s, LIST *rp)
                    691: {
                    692:        if ( remote_mc )
                    693:                *rp = remote_mc[s].mc;
                    694:        else {
                    695:                MKLIST(*rp,0);
                    696:        }
                    697: }
1.15      noro      698:
                    699: char *ox_get_servername(int s)
                    700: {
                    701:        return (remote_mc && remote_mc[s].servername)?remote_mc[s].servername:0;
                    702: }
                    703:
1.1       noro      704:
                    705: int ox_check_cmo_p(int s, P p)
                    706: {
                    707:        DCP dc;
                    708:
                    709:        if ( NUM(p) )
                    710:                return ox_check_cmo(s,(Obj)p);
                    711:        else {
                    712:                for ( dc = DC(p); dc; dc = NEXT(dc) )
                    713:                        if ( !ox_check_cmo_p(s,COEF(dc)) )
                    714:                                return 0;
                    715:                return 1;
                    716:        }
                    717: }
                    718:
                    719: int ox_check_cmo_dp(int s, DP p)
                    720: {
                    721:        MP m;
                    722:
                    723:        for ( m = BDY(p); m; m = NEXT(m) )
                    724:                if ( !ox_check_cmo(s,(Obj)m->c) )
                    725:                        return 0;
                    726:        return 1;
                    727: }
                    728:
1.12      noro      729: void ox_flush_stream(int s)
1.1       noro      730: {
                    731:        if ( ox_batch )
                    732:                return;
                    733: #if defined(VISUAL)
                    734:        if ( _fileno(&iofp[s].out->fp) < 0 )
                    735:                cflush(iofp[s].out);
                    736:        else
                    737: #elif MPI
                    738:        if ( (char)fileno(&iofp[s].out->fp) < 0 )
                    739:                cflush(iofp[s].out);
                    740:        else
                    741: #endif
1.12      noro      742:        fflush((FILE *)iofp[s].out);
1.1       noro      743: }
                    744:
1.12      noro      745: void ox_flush_stream_force(int s)
1.1       noro      746: {
                    747: #if defined(VISUAL)
                    748:        if ( _fileno(&iofp[s].out->fp) < 0 )
                    749:                cflush(iofp[s].out);
                    750:        else
                    751: #elif MPI
                    752:        if ( (char)fileno(&iofp[s].out->fp) < 0 )
                    753:                cflush(iofp[s].out);
                    754:        else
                    755: #endif
1.12      noro      756:        fflush((FILE *)iofp[s].out);
1.1       noro      757: }

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