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

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

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