[BACK]Return to oxmisc2.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / kan96xx / plugin

Annotation of OpenXM/src/kan96xx/plugin/oxmisc2.c, Revision 1.5

1.5     ! takayama    1: /* $OpenXM: OpenXM/src/kan96xx/plugin/oxmisc2.c,v 1.4 1999/11/27 01:41:11 takayama Exp $ */
1.1       maekawa     2: #include <stdio.h>
                      3: #include "ox_kan.h"
                      4: #include "oxmisc2.h"   /* This file requires sm1 object description. */
                      5: #include "cmo.h"
                      6: extern FILE *MyErrorOut;
                      7: extern int SerialOX; /* defined in SerialOX */
                      8:
                      9: extern int OxVersion;
                     10:
                     11: int DebugMathCap = 1;
                     12:
                     13:
                     14:
                     15: int oxGet(oxclientp client, struct object *op,int *isObj)
                     16: /* This method should be synchronized. */
                     17: /* oxGet is a function for client. */
                     18: {
                     19:   int ans;
                     20:   ox_stream os;
                     21:   int m;
                     22:   struct object rob;
                     23:   int sss;  /* Serial number of the recieved packet. */
                     24:   *isObj = 0;
                     25:   op->tag = Snull;
                     26:   os = client->datafp2;
                     27:   switch(client->dstate) {
                     28:   case DSTATE_ANY:
                     29:     m = oxGetOXheader(os,&sss);
                     30:     switch(m) {
                     31:     case OX_DATA:
                     32:       client->dstate = DSTATE_WAIT_OX_DATA;
                     33:       return(oxGet(client,op,isObj));
                     34:     case OX_SYNC_BALL:
                     35:       client->dstate = DSTATE_ANY;
                     36:       return(OX_SYNC_BALL);
                     37:     default:
                     38:       errorOxmisc2("oxGet: cannot handle this tag.\n");
                     39:       client->dstate = DSTATE_ERROR;
                     40:       return(-1);
                     41:     }
                     42:     break;
                     43:   case DSTATE_FIRST_SYNC:  /* waiting the first sync ball */
                     44:     /* I need to clear the buffer?? */
                     45:     oxWaitSyncBall(os);
                     46:     client->dstate = DSTATE_ANY;
                     47:     oxSendSyncBall(os);
                     48:     return(OX_SYNC_BALL);
                     49:     break;
                     50:   case DSTATE_WAIT_OX_DATA:  /* waiting a cmo data. */
                     51:     *op = cmoObjectFromStream2(client->datafp2);
                     52:     client->dstate = DSTATE_ANY;
                     53:     *isObj = 1;
                     54:     return(0);
                     55:     break;
                     56:   case DSTATE_ERROR:
                     57:     client->dstate = DSTATE_ERROR;
                     58:     errorOxmisc2("oxGet: dstate == DSTATE_ERROR (error state)\n");
                     59:     return(-1);
                     60:   default:
                     61:     client->dstate = DSTATE_ERROR;
                     62:     errorOxmisc2("oxGet: Unknown state number.");
                     63:   }
                     64:
                     65:   return(-1);
                     66: }
                     67:
                     68: int oxGetFromControl(oxclientp client)
                     69: {
                     70:   int ans = -1;
                     71:   if (client->cstate != -1) {
                     72:     ans = oxGetResultOfControlInt32(client->controlfd);
                     73:     if (ans != -1) {    client->cstate = 0; }
                     74:     else {client->cstate = -1; }
                     75:   }
                     76:   return(ans);
                     77: }
                     78:
                     79: int oxReq(oxclientp client,int func,struct object ob)
                     80: {
                     81:   struct object *ob1p;
                     82:   /* request to the control channel */
                     83:   if (func == SM_control_reset_connection ||
                     84:       func == SM_control_kill) {
                     85:     switch(func) {
                     86:     case SM_control_reset_connection:
                     87:       oxReqControlResetConnection(client->controlfd);
                     88:       client->cstate = 1;
                     89:       client->dstate = DSTATE_FIRST_SYNC;
                     90:       break;
                     91:     case SM_control_kill:
                     92:       oxReqControlKill(client->controlfd);
                     93:       client->cstate = 0;
                     94:       client->dstate = DSTATE_ANY;
                     95:       break;
                     96:     }
                     97:     fflush(NULL);
                     98:     return(0);
                     99:   }
                    100:
                    101:   /* request to the data channel */
                    102:   if (client->dstate != DSTATE_ANY) {
                    103:     errorOxmisc2("oxReq: client->dstate != DSTATE_ANY, data channel is not ready to send data.\n");
                    104:     return(-1);
                    105:   }
                    106:   switch(func) {
                    107:   case SM_DUMMY_sendcmo:
                    108:     if (!cmoCheckMathCap(ob,(struct object *)client->mathcapObjp)) {
                    109:       errorOxmisc2("oxReq: your peer does not understand this cmo.\n");
                    110:       return(-1);
                    111:     }
                    112:     oxSendOXheader(client->datafp2,OX_DATA,SerialOX++);
                    113:     cmoObjectToStream2(ob,client->datafp2);
                    114:     client->dstate = DSTATE_ANY;
                    115:     break;
                    116:   case SM_sync_ball:
                    117:     oxSendSyncBall(client->datafp2);
                    118:     client->dstate = DSTATE_ANY; /*  We do not expect the sync ball.*/
                    119:     client->cstate = 0;          /* clear the cstate */
                    120:     break;
                    121:   case SM_popCMO:
                    122:     oxReqPopCMO(client->datafp2);
                    123:     client->dstate = DSTATE_ANY;
                    124:     break;
                    125:   case SM_mathcap:
                    126:     oxReqMathCap(client->datafp2);
                    127:     client->dstate = DSTATE_ANY;
                    128:     break;
                    129:   case SM_setMathCap:
                    130:     /* ob = [(mathcap-obj) [[version num, system name] [sm tags]
                    131:                              ob1                        smtags
1.4       takayama  132:                                     oxtags      [[ox numbers, [cmo numbers]]]
1.1       maekawa   133:                                                     ob3         ob2 */
1.4       takayama  134:    /*     oxtags      [[OX_DATA, [cmo numbers]],[OX_DATA_LOCAL,[opt]],...]*/
1.1       maekawa   135:     {
                    136:       struct object ob1;
                    137:       struct object ob2;
                    138:       struct object ob3;
1.4       takayama  139:       struct object obm;
1.1       maekawa   140:       struct object smtags;
1.4       takayama  141:       struct object oxtags;
                    142:       struct object ox;
1.1       maekawa   143:     int n,i;
                    144:     struct mathCap mathcap;
                    145:
                    146:     if (strcmp(KopString(getoa(ob,0)),"mathcap-object") != 0) {
                    147:       errorOxmisc2("data format error in oxReqSetMathCap");
                    148:       client->dstate = DSTATE_ANY;
                    149:       break;
                    150:     }
1.4       takayama  151:       obm = getoa(ob,1);
                    152:       ob1 = getoa(obm,0);
                    153:       smtags = getoa(obm,1);
                    154:       oxtags = getoa(obm,2);
                    155:       if (smtags.tag != Sarray || oxtags.tag != Sarray) {
                    156:        errorOxmisc2("data format error in oxReqSetMathCap");
                    157:       }
1.1       maekawa   158:       ob1p = (struct object *) sGC_malloc(sizeof(struct object));
                    159:       *ob1p = ob1;
                    160:       mathcap.infop = ob1p;
1.4       takayama  161:
                    162:       n = getoaSize(oxtags);
1.1       maekawa   163:       if (n >= MATHCAP_SIZE) errorOxmisc2("Too big mathcap of your peer.");
                    164:       mathcap.oxSize = n;
                    165:       for (i=0; i<n; i++) {
1.4       takayama  166:        ox = getoa(oxtags,i);
                    167:        if (ox.tag != Sarray) {
                    168:          errorOxmisc2("Data format error of the third argument of mathcap.");
                    169:        }
                    170:        mathcap.ox[i] = KopInteger(getoa(ox,0));
                    171:        if (mathcap.ox[i] == OX_DATA) {
                    172:          if (getoaSize(ox) < 2) {
                    173:            errorOxmisc2("Data format error in an entry of the third argument of mathcap.");
                    174:          }
                    175:          ob2 = getoa(ox,1);
                    176:          if (ob2.tag != Sarray) {
                    177:            errorOxmisc2("Data format error in an entry of the third argument of mathcap.");
                    178:          }
                    179:          mathcap.n = getoaSize(ob2);
                    180:          if (n >= MATHCAP_SIZE) errorOxmisc2("Too big mathcap of your peer.");
                    181:          for (i=0; i<mathcap.n; i++) {
                    182:            mathcap.cmo[i] = KopInteger(getoa(ob2,i));
                    183:          }
                    184:        }
1.1       maekawa   185:       }
                    186:
                    187:       n = getoaSize(smtags);
                    188:       if (n >= MATHCAP_SIZE) errorOxmisc2("Too big mathcap of your peer.");
                    189:       mathcap.smSize = n;
                    190:       for (i=0; i<n; i++) {
                    191:        mathcap.sm[i] = KopInteger(getoa(smtags,i));
                    192:       }
                    193:
                    194:       oxReqSetMathCap(client->datafp2,&mathcap);
                    195:       client->dstate = DSTATE_ANY;
                    196:     }
                    197:     break;
                    198:   case SM_pops:
                    199:     if (ob.tag != Sinteger) {
                    200:       errorOxmisc2("SM_pops : the argument must be an integer.");
                    201:       return(-1);
                    202:     }
                    203:     oxReqPops(client->datafp2, KopInteger(ob));
                    204:     client->dstate = DSTATE_ANY;
                    205:     break;
                    206:   case SM_executeStringByLocalParser:
                    207:     if (ob.tag != Sdollar) {
                    208:       errorOxmisc2("SM_executeStringByLocalParser : the argument must be a string.");
                    209:       return(-1);
                    210:     }
                    211:     oxReqExecuteStringByLocalParser(client->datafp2,KopString(ob));
                    212:     client->dstate = DSTATE_ANY;
                    213:     break;
                    214:   case SM_executeFunction:
                    215:     if (ob.tag != Sdollar) {
                    216:       errorOxmisc2("SM_executeFunction : the argument must be a string.");
                    217:       return(-1);
                    218:     }
                    219:     oxReqExecuteFunction(client->datafp2,KopString(ob));
                    220:     client->dstate = DSTATE_ANY;
                    221:     break;
                    222:   case SM_popString:
                    223:     oxReqPopString(client->datafp2);
                    224:     client->dstate = DSTATE_ANY;
                    225:     break;
                    226:   case SM_evalName:
                    227:     if (ob.tag != Sdollar) {
                    228:       errorOxmisc2("SM_evalName : the argument must be a string.");
                    229:       return(-1);
                    230:     }
                    231:     oxReqEvalName(client->datafp2,KopString(ob));
                    232:     client->dstate = DSTATE_ANY;
                    233:     break;
                    234:   case SM_setName:
                    235:     if (ob.tag != Sdollar) {
                    236:       errorOxmisc2("SM_setName : the argument must be a string.");
                    237:       return(-1);
                    238:     }
                    239:     oxReqSetName(client->datafp2,KopString(ob));
                    240:     client->dstate = DSTATE_ANY;
                    241:     break;
                    242:   case SM_getsp:
                    243:     oxReqSingleOperand(client->datafp2,SM_getsp);
                    244:     client->dstate = DSTATE_ANY;
                    245:     break;
                    246:   case SM_dupErrors:
                    247:     oxReqSingleOperand(client->datafp2,SM_dupErrors);
                    248:     client->dstate = DSTATE_ANY;
                    249:     break;
                    250:   default:
                    251:     fprintf(MyErrorOut,"func=%d ",func);
                    252:     errorOxmisc2("This function is not implemented.");
                    253:     break;
                    254:   }
                    255:   fp2fflush(client->datafp2);
                    256:   return(0);
                    257: }
                    258:
                    259: struct object KoxCreateClient(struct object ip,
                    260:                              struct object portStream,
                    261:                              struct object portControl)
                    262: {
                    263:   struct object rob;
                    264:   oxclientp client;
                    265:   rob.tag = Snull;
                    266:   if (ip.tag != Sdollar) {
                    267:     errorOxmisc2("KoxCreateClient(): The first argument must be a hostname given by a string.");
                    268:     return(rob);
                    269:   }
                    270:   if (portStream.tag == Sdollar) {
                    271:     client = oxCreateClientFile(KopString(ip),KopString(portStream),
                    272:                                "/dev/null","w");
                    273:     if (client == NULL) {
                    274:       errorOxmisc2("KoxCreateClient(): Open error.");
                    275:       return(rob);
                    276:     }
                    277:     rob = newObjectArray(N_OF_CLIENT_FIELDS);
                    278:     oxClientToObject(client,rob);
                    279:     return(rob);
                    280:   }
                    281:
                    282:   if (portStream.tag != Sinteger) {
                    283:     errorOxmisc2("KoxCreateClient(): The second argument must be a port number given in an integer.");
                    284:     return(rob);
                    285:   }
                    286:   if (portControl.tag != Sinteger) {
                    287:     errorOxmisc2("KoxCreateClient(): The third argument must be a port number given in an integer.");
                    288:     return(rob);
                    289:   }
                    290:   client = oxCreateClient(KopString(ip),KopInteger(portStream),KopInteger(portControl));
                    291:   if (client == NULL) {
                    292:     errorOxmisc2("KoxCreateClient(): Open error.");
                    293:     return(rob);
                    294:   }
                    295:   rob = newObjectArray(N_OF_CLIENT_FIELDS);
                    296:   oxClientToObject(client,rob);
                    297:   return(rob);
                    298: }
                    299:
                    300: static int isItClientObject(struct object ob)
                    301: {
                    302:   int size,i;
                    303:   struct object ee[N_OF_CLIENT_FIELDS];
                    304:   if (ob.tag != Sarray) {
                    305:     return(0);
                    306:   }
                    307:   size = getoaSize(ob);
                    308:   if (size != N_OF_CLIENT_FIELDS) return(0);
                    309:   for (i=0; i<N_OF_CLIENT_FIELDS; i++) {
                    310:     ee[i] = getoa(ob,i);
                    311:   }
                    312:
                    313:   if (ee[0].tag != Sdollar) return(0);
                    314:   if (strcmp(KopString(ee[0]),"client")!=0) return(0);
                    315:
                    316:   if (ee[1].tag != Sfile) return(0);
                    317:   if (strcmp((ee[1]).lc.str,MAGIC2) != 0) return(0);
                    318:
                    319:   for (i=2; i<=9; i++) {
                    320:     if (ee[i].tag != Sinteger) return(0);
                    321:   }
                    322:   return(1);
                    323: }
                    324:
                    325:
                    326: struct object KoxIsThereErrorClient(struct object ob)
                    327: {
                    328:   struct object rob;
                    329:   int ans;
                    330:   int size;
                    331:   oxclient cc;
                    332:   rob.tag = Snull;
                    333:   if (!isItClientObject(ob)) {
                    334:     errorOxmisc2("KoxIsThereErrorClient(): the argument must be an array for client object.");
                    335:     return(rob);
                    336:   }
                    337:   if (oxObjectToClient(ob,&cc) == -1) return(KpoInteger(-1));
                    338:   ans = oxIsThereErrorClient(&cc);
                    339:   return(KpoInteger(ans));
                    340: }
                    341:
                    342: int oxClientToObject(oxclientp client,struct object rob)
                    343: {
                    344:   struct object ob;
                    345:   if (client == NULL) return;
                    346:   /* rob = newObjectArray(N_OF_CLIENT_FIELDS); */
                    347:   if (rob.tag != Sarray) {
                    348:     errorOxmisc2("oxClientToObject(): the second argument must be an array.");
                    349:     return(-1);
                    350:   }
                    351:   if (getoaSize(rob) != N_OF_CLIENT_FIELDS) {
                    352:     errorOxmisc2("oxClientToObject(): the second argument must be an array of size N_OF_CLIENT_FIELDS.");
                    353:     return(-1);
                    354:   }
                    355:
                    356:   ob = KpoString("client");
                    357:   putoa(rob,0,ob);
                    358:
                    359:   ob.tag = Sfile; ob.lc.str = MAGIC2; ob.rc.voidp = (void *)(client->datafp2);
                    360:   putoa(rob,1,ob);
                    361:
                    362:   putoa(rob,2,KpoInteger(client->dataport));
                    363:   putoa(rob,3,KpoInteger(client->controlfd));
                    364:   putoa(rob,4,KpoInteger(client->controlport));
                    365:   putoa(rob,5,KpoInteger(client->dstate));
                    366:   putoa(rob,6,KpoInteger(client->cstate));
                    367:   putoa(rob,7,KpoInteger(client->humanio));
                    368:   putoa(rob,8,KpoInteger(client->id));
                    369:   putoa(rob,9,KpoInteger(client->type));
                    370:   if (client->mathcapObjp == NULL) {
                    371:     putoa(rob,10,NullObject);
                    372:   }else{
                    373:     putoa(rob,10,*((struct object *)(client->mathcapObjp)));
                    374:   }
                    375:   putoa(rob,11,KpoInteger(client->engineByteOrder));
                    376:   putoa(rob,12,KpoInteger(client->controlByteOrder));
                    377:   return(0);
                    378: }
                    379:
                    380: int oxObjectToClient(struct object ob,oxclientp cp)
                    381: {
                    382:   struct object ob1;
                    383:   struct object *obp;
                    384:   if (cp == NULL) {
                    385:     errorOxmisc2("oxObjectToClient(): the second argument is NULL");
                    386:     return(-1);
                    387:   }
                    388:   if (!isItClientObject(ob)) {
                    389:     errorOxmisc2("oxObjectToClient(): the first argument is not client object.");
                    390:     oxInitClient(cp);
                    391:     return(-1);
                    392:   }
                    393:
                    394:   ob1 = getoa(ob,1);
                    395:   cp->datafp2 = (FILE2 *) (ob1.rc.voidp);
                    396:
                    397:   ob1 = getoa(ob,2);
                    398:   cp->dataport = KopInteger(ob1);
                    399:
                    400:   ob1 = getoa(ob,3);
                    401:   cp->controlfd = KopInteger(ob1);
                    402:
                    403:   ob1 = getoa(ob,4);
                    404:   cp->controlport = KopInteger(ob1);
                    405:
                    406:   ob1 = getoa(ob,5);
                    407:   cp->dstate = KopInteger(ob1);
                    408:
                    409:   ob1 = getoa(ob,6);
                    410:   cp->cstate = KopInteger(ob1);
                    411:
                    412:   ob1 = getoa(ob,7);
                    413:   cp->humanio = KopInteger(ob1);
                    414:
                    415:   ob1 = getoa(ob,8);
                    416:   cp->id = KopInteger(ob1);
                    417:
                    418:   ob1 = getoa(ob,9);
                    419:   cp->type = KopInteger(ob1);
                    420:
                    421:   ob1 = getoa(ob,10);
                    422:   if (ob1.tag == Snull) {
                    423:     cp->mathcapObjp = NULL;
                    424:   }else{
                    425:     obp = (struct object *) sGC_malloc(sizeof(struct object));
                    426:     *obp = ob1;
                    427:     cp->mathcapObjp = (void *)obp;
                    428:   }
                    429:   ob1 = getoa(ob,11);
                    430:   cp->engineByteOrder = KopInteger(ob1);
                    431:   ob1 = getoa(ob,12);
                    432:   cp->controlByteOrder = KopInteger(ob1);
                    433:
                    434:
                    435:   return(0);
                    436: }
                    437:
                    438: struct object KoxReq(struct object client,
                    439:                     struct object func,
                    440:                     struct object ob1)
                    441: {
                    442:   int ans;
                    443:   static oxclientp cc1 = NULL;
                    444:   struct object rob;
                    445:   rob.tag = Snull;
                    446:   if (cc1 == NULL) {
                    447:     cc1 = (oxclientp) mymalloc(sizeof(oxclient));
                    448:     if (cc1 == NULL) {
                    449:       errorOxmisc2("KoxReq(): no more memory.");
                    450:       return(rob);
                    451:     }
                    452:     oxInitClient(cc1);
                    453:   }
                    454:
                    455:   if (oxObjectToClient(client,cc1) == -1) return(rob);
                    456:   if (cc1 == NULL) {
                    457:     errorOxmisc2("KoxReq(): the first argument must be a client object.");
                    458:     return(rob);
                    459:   }
                    460:   if (func.tag != Sinteger) {
                    461:     errorOxmisc2("KoxReq(): the second argument must be an integer.");
                    462:     return(rob);
                    463:   }
                    464:   ans = oxReq(cc1,KopInteger(func),ob1);
                    465:   /* synchronize cc1 and client. */
                    466:   oxClientToObject(cc1,client);
                    467:
                    468:   return(KpoInteger(ans));
                    469: }
                    470:
                    471: struct object KoxGet(struct object client)
                    472: {
                    473:   int ans,k;
                    474:   static oxclientp cc1 = NULL;
                    475:   struct object rob;
                    476:   rob.tag = Snull;
                    477:   if (cc1 == NULL) {
                    478:     cc1 = (oxclientp) mymalloc(sizeof(oxclient));
                    479:     if (cc1 == NULL) {
                    480:       errorOxmisc2("KoxGet(): no more memory.");
                    481:       return(rob);
                    482:     }
                    483:     oxInitClient(cc1);
                    484:   }
                    485:
                    486:   if (oxObjectToClient(client,cc1) == -1) return(rob);
                    487:   if (cc1 == NULL) {
                    488:     errorOxmisc2("KoxGet(): the first argument must be a client object.");
                    489:     return(rob);
                    490:   }
                    491:
                    492:   ans = oxGet(cc1,&rob,&k);
                    493:   /* synchronize cc1 and client. */
                    494:   oxClientToObject(cc1,client);
                    495:
                    496:   if (k) return(rob);
                    497:   else {
                    498:     return(KpoInteger(ans));
                    499:   }
                    500: }
                    501:
                    502: struct object KoxGetFromControl(struct object client)
                    503: {
                    504:   int ans;
                    505:   static oxclientp cc1 = NULL;
                    506:   struct object rob;
                    507:   rob.tag = Snull;
                    508:   if (cc1 == NULL) {
                    509:     cc1 = (oxclientp) mymalloc(sizeof(oxclient));
                    510:     if (cc1 == NULL) {
                    511:       errorOxmisc2("KoxGetFromControl(): no more memory.");
                    512:       return(rob);
                    513:     }
                    514:     oxInitClient(cc1);
                    515:   }
                    516:
                    517:   if (oxObjectToClient(client,cc1) == -1) return(rob);
                    518:   if (cc1 == NULL) {
                    519:     errorOxmisc2("KoxGetFromControl(): the first argument must be a client object.");
                    520:     return(rob);
                    521:   }
                    522:
                    523:   ans = oxGetFromControl(cc1);
                    524:   /* synchronize cc1 and client. */
                    525:   oxClientToObject(cc1,client);
                    526:
                    527:   return(KpoInteger(ans));
                    528: }
                    529:
                    530: struct object KoxMultiSelect(struct object oclients,struct object t)
                    531: {
                    532:   static int first = 1;
                    533:   static int csize = 0;
                    534:   static oxclientp *clients = NULL;
                    535:   oxclientp cc1;
                    536:   struct object rob;
                    537:   int i;
                    538:   int tt;
                    539:   struct object ob1;
                    540:   struct object ob2;
                    541:   struct object ob0;
                    542:   int size;
                    543:   int ans;
                    544:   int dataready[1024];
                    545:   int controlready[1024];
                    546:
                    547:   rob.tag = Snull;
                    548:   if (oclients.tag != Sarray) {
                    549:     errorOxmisc2("KoxMultiSelect(): the first argument must be an array.");
                    550:     return(rob);
                    551:   }
                    552:   size = getoaSize(oclients);
                    553:   if (first) {
                    554:     first = 0; csize = size;
                    555:     clients = (oxclientp *)mymalloc(sizeof(oxclientp)*(size+1));
                    556:      if (clients == NULL) {
                    557:       errorOxmisc2("KoxMultiSelect(): no more memory.");
                    558:       return(rob);
                    559:     }
                    560:     for (i=0; i<size; i++) {
                    561:       clients[i] =  (oxclientp) mymalloc(sizeof(oxclient));
                    562:       if (clients[i] == NULL) {
                    563:        errorOxmisc2("KoxMultiSelect(): no more memory.");
                    564:        return(rob);
                    565:       }
                    566:       oxInitClient(clients[i]);
                    567:     }
                    568:   }
                    569:   if (csize < size)  {
                    570:     first = 1;
                    571:     return(KoxMultiSelect(oclients,t));
                    572:   }
                    573:   for (i=0; i<size; i++) {
                    574:     ob0 = getoa(oclients,i);
                    575:     if (oxObjectToClient(ob0,clients[i]) == -1) return(rob);
                    576:   }
                    577:   if (t.tag != Sinteger) {
                    578:     errorOxmisc2("KoxMultiSelect(): the second argument must be an integer.");
                    579:   }
                    580:   tt = KopInteger(t);
                    581:   ans = oxclientMultiSelect(clients,dataready,controlready,size,tt);
                    582:   /* synchronize oclients and clients. */
                    583:   for (i=0; i<size; i++) {
                    584:     ob0 = getoa(oclients,i);
                    585:     oxClientToObject(clients[i],ob0);
                    586:     putoa(oclients,i,ob0);
                    587:   }
                    588:   rob = newObjectArray(3);
                    589:   putoa(rob,0,KpoInteger(ans));
                    590:   ob1 = newObjectArray(size);
                    591:   ob2 = newObjectArray(size);
                    592:   for (i=0; i<size; i++) {
                    593:     putoa(ob1,i,KpoInteger(dataready[i]));
                    594:     putoa(ob2,i,KpoInteger(controlready[i]));
                    595:   }
                    596:   putoa(rob,1,ob1);
                    597:   putoa(rob,2,ob2);
                    598:   return(rob);
                    599: }
                    600:
                    601: struct object KoxWatch(struct object client,struct object f)
                    602: /* f is not used for now. It should be log file. */
                    603: {
                    604:   int ans,k;
                    605:   static oxclientp cc1 = NULL;
                    606:   struct object rob;
1.3       takayama  607:   extern int WatchStream;
1.1       maekawa   608:   rob.tag = Snull;
1.3       takayama  609:   if (client.tag == Sinteger) {
                    610:        if (KopInteger(client)) {
                    611:          WatchStream = 1;
                    612:        }else{
                    613:          WatchStream = 0;
                    614:        }
                    615:        return;
                    616:   }
1.1       maekawa   617:   if (cc1 == NULL) {
                    618:     cc1 = (oxclientp) mymalloc(sizeof(oxclient));
                    619:     if (cc1 == NULL) {
                    620:       errorOxmisc2("KoxWatch(): no more memory.");
                    621:       return(rob);
                    622:     }
                    623:     oxInitClient(cc1);
                    624:   }
                    625:
                    626:   if (oxObjectToClient(client,cc1) == -1) return(rob);
                    627:   if (cc1 == NULL) {
                    628:     errorOxmisc2("KoxWatch(): the first argument must be a client object.");
                    629:     return(rob);
                    630:   }
                    631:
                    632:   k = fp2watch(cc1->datafp2,stdout);
                    633:   /* synchronize cc1 and client. */
                    634:   oxClientToObject(cc1,client);
                    635:
                    636:   return(KpoInteger(ans));
                    637: }
                    638:
                    639:
                    640: struct object KoxCloseClient(struct object client) {
                    641:   oxclientp cc1 = NULL;
                    642:   oxclient cc;
                    643:   struct object rob;
                    644:   rob.tag = Snull;
                    645:   cc1  = &cc;
                    646:   if (oxObjectToClient(client,cc1) == -1) return(rob);
                    647:   if (cc1 == NULL) {
                    648:     errorOxmisc2("KoxCloseClient(): the first argument must be a client object.");
                    649:     return(rob);
                    650:   }
                    651:
                    652:   fp2fflush(cc1->datafp2);
                    653:   if (cc1->humanio) {
                    654:     /* Do not close the file. */
                    655:     return(KpoInteger(0));
                    656:   }
                    657:   switch (cc1->type) {
                    658:   case CLIENT_SOCKET:
                    659:     fp2fclose(cc1->datafp2);
                    660:     close(cc1->controlfd);
                    661:     break;
                    662:   case CLIENT_FILE:
                    663:     fp2fclose(cc1->datafp2);
                    664:     close(cc1->controlfd);
                    665:     break;
                    666:   default:
                    667:     errorOxmisc2("Unknown client->type\n");
                    668:     break;
                    669:   }
                    670:   return(KpoInteger(0));
                    671:
                    672: }
                    673:
                    674: static int cmoCheck00(struct object obj,int cmo[], int n) {
                    675:   int i,j,m;
                    676:   int ttt;
                    677: #define CHECK00_N  4098      /* look up stackm.h and kclass.h */
                    678:   static int typeTrans[CHECK00_N];
                    679:   static int init = 0;
1.5     ! takayama  680:   /* if n == 0, report the cmo tag of the object obj.
        !           681:         If it cannot be translated to cmo, then return -1. */
        !           682:
1.1       maekawa   683:   if (!init) {
                    684:     for (i=0; i<CHECK00_N; i++) {
                    685:       typeTrans[i] = 0;  /* unknown cmo number */
                    686:     }
                    687:     typeTrans[Snull] = CMO_NULL;
                    688:     typeTrans[Sinteger] = CMO_INT32;
                    689:     typeTrans[Sdollar] = CMO_STRING;
                    690:     if (OxVersion >= 199907170) {
                    691:       typeTrans[SuniversalNumber] = CMO_ZZ;
                    692:     }else{
                    693:       typeTrans[SuniversalNumber] = CMO_ZZ_OLD;
                    694:     }
                    695:     typeTrans[Sarray] = CMO_LIST;
                    696:     /* typeTrans[Spoly] = CMO_DMS;  */
                    697:     typeTrans[Spoly] = CMO_DISTRIBUTED_POLYNOMIAL;
                    698:     typeTrans[Sdouble] = CMO_64BIT_MACHINE_DOUBLE;
                    699:     typeTrans[CLASSNAME_ERROR_PACKET]   = CMO_ERROR2;
                    700:     typeTrans[CLASSNAME_mathcap] = CMO_MATHCAP;
                    701:     typeTrans[CLASSNAME_indeterminate] = CMO_INDETERMINATE;
                    702:     typeTrans[CLASSNAME_tree] = CMO_TREE;
                    703:     typeTrans[CLASSNAME_recursivePolynomial] = CMO_RECURSIVE_POLYNOMIAL;
                    704:     typeTrans[CLASSNAME_polynomialInOneVariable] = CMO_POLYNOMIAL_IN_ONE_VARIABLE;
                    705:     init = 1;
                    706:   }
                    707:   ttt = typeTrans[obj.tag];
                    708:   if (obj.tag == Sclass) {
                    709:     ttt = typeTrans[ectag(obj)];
                    710:   }
1.5     ! takayama  711:   /* Only report the cmo tag. */
        !           712:   if (n == 0) {
        !           713:        if (ttt == 0) return(-1);
        !           714:        else return(ttt);
        !           715:   }
1.1       maekawa   716:
                    717:   for (i=0; i<n; i++) {
                    718:     if (ttt == cmo[i]) {
                    719:       if (ttt != CMO_LIST) return(1);
                    720:       else {
                    721:        m = getoaSize(obj);
                    722:        for (j=0; j<m; j++) {
                    723:          if (!cmoCheck00(getoa(obj,j),cmo,n)) return(0);
                    724:        }
                    725:        return(1);
                    726:       }
                    727:     }
                    728:   }
                    729:   if (DebugMathCap) {
                    730:     if (DebugMathCap && 1) {
                    731:       fprintf(stderr,"Type translation table (internal object tag --> CMO tag)\n");
                    732:       for (i=0; i<20; i++) {
                    733:        printf("%d ", typeTrans[i]);
                    734:       }
                    735:       printf("\n");
                    736:     }
                    737:     fprintf(stderr,"The type of the argument object in sm1 is %d.\n",obj.tag);
                    738:     fprintf(stderr,"The type of the argument object in CMO is %d.\n",ttt);
                    739:     fprintf(stderr,"Available CMO tags in mathcap= %d elements : [ ",n);
                    740:     for (i=0; i<n; i++) {
                    741:       fprintf(stderr," %d ",cmo[i]);
                    742:     }
                    743:     fprintf(stderr," ] \n");
                    744:   }
                    745:   return(0);
                    746: }
                    747:
                    748: int cmoCheckMathCap(struct object obj, struct object *obp)
                    749: {
                    750:   struct object mathcap;
                    751:   struct object cmolist;
1.2       takayama  752:   struct object mathcapMain;
1.4       takayama  753:   struct object mathcapThird;
                    754:   struct object ox;
                    755:   struct object oxtag;
1.2       takayama  756:   struct object ob0;
1.4       takayama  757:   int oxsize;
1.1       maekawa   758:   int n;
                    759:   int i;
                    760: #define CMO_CHECK_MATH_CAP_LIST_SIZE 1024
                    761:   int cmo[CMO_CHECK_MATH_CAP_LIST_SIZE];
                    762:   if (obp == NULL) return(1);
1.2       takayama  763:   /* printObject(*obp,0,stderr); for debug*/
1.1       maekawa   764:   if (obp->tag != Sarray) {
                    765:     fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    766:     printObject(*obp,0,stderr);
                    767:     fprintf(stderr,"\n");
                    768:     errorOxmisc2("cmoCheckMathCap: format error in the client->mathcapObjp field.\n");
                    769:   }
                    770:   mathcap = *obp;
1.2       takayama  771:   /* Example of mathcap
                    772:     [    $mathcap-object$ ,
                    773:        [    [    199909080 , $Ox_system=ox_sm1.plain$ , $Version=2.991106$ ,
                    774:                  $HOSTTYPE=i386$ ]  ,
                    775:             [    262 , 263 , 264 , 265 , 266 , 268 , 269 , 272 , 273 , 275 ,
                    776:                  276 ]  ,
1.4       takayama  777:             [    [    514  , [    2130706434 , 1 , 2 , 4 , 5 , 17 , 19 , 20 , 22 , 23 , 24 , 25 , 26 , 30 , 31 , 60 , 61 , 27 , 33 , 40 , 16 , 34 ] ] ]  ]  ]
1.2       takayama  778:   */
                    779:
1.1       maekawa   780:   n = getoaSize(mathcap);
                    781:   if (n < 2) {
                    782:     fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    783:     printObject(*obp,0,stderr);
                    784:     fprintf(stderr,"\n");
                    785:     errorOxmisc2("cmoCheckMathCap: length of mathcap is wrong in the client->mathcapObjp field.\n");
                    786:   }
1.2       takayama  787:   ob0 = getoa(mathcap,0);
                    788:   if (ob0.tag != Sdollar) {
                    789:     fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    790:     printObject(*obp,0,stderr);
                    791:     fprintf(stderr,"\n");
                    792:     errorOxmisc2("cmoCheckMathCap: The first field must be the string mathcap-object.\n");
                    793:   }
                    794:   if (strcmp(KopString(ob0),"mathcap-object") != 0) {
                    795:     fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    796:     printObject(*obp,0,stderr);
                    797:     fprintf(stderr,"\n");
                    798:     errorOxmisc2("cmoCheckMathCap: The mathcap must be of the form [(mathcap-object) [...]]\n");
                    799:   }
                    800:
1.1       maekawa   801:   /* I should check
1.2       takayama  802:          getoa(getoa(mathcap,1),2)
1.1       maekawa   803:      contains OX_DATA.
                    804:      It has not yet implemented.
                    805:   */
1.2       takayama  806:   mathcapMain = getoa(mathcap,1);
                    807:   if (mathcapMain.tag != Sarray) {
                    808:     fprintf(stderr,"cmoCheckMathCap: mathcap[1] is \n");
                    809:     printObject(mathcapMain,0,stderr);
                    810:     fprintf(stderr,"\n");
                    811:     errorOxmisc2("cmoCheckMathCap: format error in the (client->mathcapObjp)[1] field. It should be an array.\n");
                    812:   }
                    813:   if (getoaSize(mathcapMain) < 3) {
                    814:     fprintf(stderr,"cmoCheckMathCap: mathcap[1] is \n");
                    815:     printObject(mathcapMain,0,stderr);
                    816:     fprintf(stderr,"\n");
                    817:     errorOxmisc2("cmoCheckMathCap: format error in the (client->mathcapObjp)[1] field. It should be an array of which length is more than 2.\n");
                    818:   }
1.4       takayama  819:   mathcapThird = getoa(mathcapMain,2);
                    820:   oxsize = getoaSize(mathcapThird);
                    821:   for (i=0; i<oxsize; i++) {
                    822:     ox = getoa(mathcapThird,i);
                    823:     if (ox.tag != Sarray) {
                    824:       fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    825:       printObject(*obp,0,stderr);
                    826:       fprintf(stderr,"\n");
                    827:       errorOxmisc2("cmoCheckMathCap: the third element of mathcap is a list of lists.");
                    828:     }
                    829:     if (getoaSize(ox) != 0) {
                    830:       oxtag = getoa(ox,0);
                    831:       if (oxtag.tag != Sinteger) {
                    832:        fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    833:        printObject(*obp,0,stderr);
                    834:        fprintf(stderr,"\n");
                    835:        errorOxmisc2("cmoCheckMathCap: the third element of mathcap must be [OX_DATA_xxx, [  ]].");
                    836:       }
                    837:       if (KopInteger(oxtag) == OX_DATA) {
                    838:        if (getoaSize(ox) > 1) {
                    839:          cmolist = getoa(ox,1);
                    840:          if (cmolist.tag != Sarray) {
                    841:            fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    842:            printObject(*obp,0,stderr);
                    843:            fprintf(stderr,"\n");
                    844:            errorOxmisc2("cmoCheckMathCap: mathcap[1] must be an array of integers.\n");
                    845:          }
                    846:          n = getoaSize(cmolist);
                    847:          if (n > CMO_CHECK_MATH_CAP_LIST_SIZE) {
                    848:            errorOxmisc2("cmoCheckMathCap: Too big cmo list.\n");
                    849:          }
                    850:          for (i=0; i<n; i++) {
                    851:            cmo[i] = KopInteger(getoa(cmolist,i));
                    852:          }
                    853:        }else{
                    854:          fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
                    855:          printObject(*obp,0,stderr);
                    856:          fprintf(stderr,"\nox=");
                    857:          printObject(ox,0,stderr);
                    858:          errorOxmisc2("cmoCheckMathCap: [OX_DATA, cmolist]");
                    859:        }
                    860:       }
                    861:     }
1.1       maekawa   862:   }
                    863:   return(cmoCheck00(obj,cmo,n));
                    864: }
                    865:
                    866:
                    867: struct object KoxGenPortFile(void) {
                    868:   struct object ob;
                    869:   ob = KpoString(oxGenPortFile());
                    870:   return(ob);
                    871: }
                    872: void KoxRemovePortFile(void) {
                    873:   oxRemovePortFile();
                    874: }
                    875:
                    876: void oxPushMathCap(struct mathCap *mathcap)
                    877: {
                    878:   struct object rob;
                    879:   rob = newMathCap(mathcap);
                    880:   Kpush(rob);
                    881: }
                    882:
                    883: struct object KoxGenPass(void) {
                    884:   struct object rob;
                    885:   rob = KpoString(oxGenPass());
                    886:   return(rob);
                    887: }
                    888:
                    889: struct object KoxGetPort(struct object host)
                    890: {
                    891:   struct object rob;
                    892:   int fdStream, fdControl;
                    893:   int portStream, portControl;
                    894:   extern int OpenedSocket;
                    895:   char *sname;
                    896:   rob = NullObject;
                    897:   if (host.tag != Sdollar) {
                    898:     errorOxmisc2("KoxGetPort: argument is not a string.");
                    899:     return(rob);
                    900:   }
                    901:   sname = KopString(host);
                    902:   fdControl = socketOpen(sname,0);
                    903:   portControl = OpenedSocket;
                    904:   fdStream = socketOpen(sname,0);
                    905:   portStream = OpenedSocket;
                    906:   rob = newObjectArray(4);
                    907:   putoa(rob,0,KpoInteger(fdStream));
                    908:   putoa(rob,1,KpoInteger(portStream));
                    909:   putoa(rob,2,KpoInteger(fdControl));
                    910:   putoa(rob,3,KpoInteger(portControl));
                    911:   return(rob);
                    912: }
                    913:
                    914: struct object KoxCreateClient2(struct object peer,
                    915:                               struct object ipmask,
                    916:                               struct object pass)
                    917: {
                    918:   struct object rob;
                    919:   oxclientp client;
                    920:   int fdStream, portStream, fdControl, portControl;
                    921:   int i;
                    922:   struct object ob1;
                    923:   rob.tag = Snull;
                    924:   if (peer.tag != Sarray) {
                    925:     errorOxmisc2("KoxCreateClient2(): The first argument must be an array [fdStream, portStream, fdControl, portControl]");
                    926:     return(rob);
                    927:   }
                    928:   if (getoaSize(peer) != 4) {
                    929:     errorOxmisc2("KoxCreateClient2(): The first argument must be an array [fdStream, portStream, fdControl, portControl] of size 4.");
                    930:     return(rob);
                    931:   }
                    932:   for (i=0; i<4; i++) {
                    933:     ob1 = getoa(peer,i);
                    934:     if (ob1.tag != Sinteger) {
                    935:       errorOxmisc2("KoxCreateClient2(): The element of the first argument must be an integer.");
                    936:     }
                    937:   }
                    938:   fdStream = KopInteger(getoa(peer,0));
                    939:   portStream = KopInteger(getoa(peer,1));
                    940:   fdControl = KopInteger(getoa(peer,2));
                    941:   portControl = KopInteger(getoa(peer,3));
                    942:
                    943:   if (ipmask.tag != Sinteger) {
                    944:     errorOxmisc2("KoxCreateClient2(): ipmask must be an integer.");
                    945:   }
                    946:   if (pass.tag != Sdollar) {
                    947:     errorOxmisc2("KoxCreateClient2(): pass must be a string.");
                    948:   }
                    949:
                    950:   client = oxCreateClient2(fdStream, portStream, fdControl, portControl,
                    951:                           KopInteger(ipmask), KopString(pass));
                    952:   if (client == NULL) {
                    953:     errorOxmisc2("KoxCreateClient2(): Open error.");
                    954:     return(rob);
                    955:   }
                    956:   rob = newObjectArray(N_OF_CLIENT_FIELDS);
                    957:   oxClientToObject(client,rob);
                    958:   return(rob);
1.5     ! takayama  959: }
        !           960:
        !           961: int KgetCmoTagOfObject(struct object obj) {
        !           962:   int k;
        !           963:   k=cmoCheck00(obj,(int *)NULL,0);
        !           964:   return(k);
1.1       maekawa   965: }
                    966:
                    967: errorOxmisc2(char *s) {
                    968:   fprintf(MyErrorOut,"error in oxmisc2.c: %s\n",s);
                    969:   errorKan1("%s\n","  ");
                    970: }

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