Annotation of OpenXM/src/kan96xx/plugin/oxmisc2.c, Revision 1.4
1.4 ! takayama 1: /* $OpenXM: OpenXM/src/kan96xx/plugin/oxmisc2.c,v 1.3 1999/11/18 00:54:17 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;
680: if (n == 0) return(1); /* For null cmolist, OK. */
681: if (!init) {
682: for (i=0; i<CHECK00_N; i++) {
683: typeTrans[i] = 0; /* unknown cmo number */
684: }
685: typeTrans[Snull] = CMO_NULL;
686: typeTrans[Sinteger] = CMO_INT32;
687: typeTrans[Sdollar] = CMO_STRING;
688: if (OxVersion >= 199907170) {
689: typeTrans[SuniversalNumber] = CMO_ZZ;
690: }else{
691: typeTrans[SuniversalNumber] = CMO_ZZ_OLD;
692: }
693: typeTrans[Sarray] = CMO_LIST;
694: /* typeTrans[Spoly] = CMO_DMS; */
695: typeTrans[Spoly] = CMO_DISTRIBUTED_POLYNOMIAL;
696: typeTrans[Sdouble] = CMO_64BIT_MACHINE_DOUBLE;
697: typeTrans[CLASSNAME_ERROR_PACKET] = CMO_ERROR2;
698: typeTrans[CLASSNAME_mathcap] = CMO_MATHCAP;
699: typeTrans[CLASSNAME_indeterminate] = CMO_INDETERMINATE;
700: typeTrans[CLASSNAME_tree] = CMO_TREE;
701: typeTrans[CLASSNAME_recursivePolynomial] = CMO_RECURSIVE_POLYNOMIAL;
702: typeTrans[CLASSNAME_polynomialInOneVariable] = CMO_POLYNOMIAL_IN_ONE_VARIABLE;
703: init = 1;
704: }
705: ttt = typeTrans[obj.tag];
706: if (obj.tag == Sclass) {
707: ttt = typeTrans[ectag(obj)];
708: }
709:
710: for (i=0; i<n; i++) {
711: if (ttt == cmo[i]) {
712: if (ttt != CMO_LIST) return(1);
713: else {
714: m = getoaSize(obj);
715: for (j=0; j<m; j++) {
716: if (!cmoCheck00(getoa(obj,j),cmo,n)) return(0);
717: }
718: return(1);
719: }
720: }
721: }
722: if (DebugMathCap) {
723: if (DebugMathCap && 1) {
724: fprintf(stderr,"Type translation table (internal object tag --> CMO tag)\n");
725: for (i=0; i<20; i++) {
726: printf("%d ", typeTrans[i]);
727: }
728: printf("\n");
729: }
730: fprintf(stderr,"The type of the argument object in sm1 is %d.\n",obj.tag);
731: fprintf(stderr,"The type of the argument object in CMO is %d.\n",ttt);
732: fprintf(stderr,"Available CMO tags in mathcap= %d elements : [ ",n);
733: for (i=0; i<n; i++) {
734: fprintf(stderr," %d ",cmo[i]);
735: }
736: fprintf(stderr," ] \n");
737: }
738: return(0);
739: }
740:
741: int cmoCheckMathCap(struct object obj, struct object *obp)
742: {
743: struct object mathcap;
744: struct object cmolist;
1.2 takayama 745: struct object mathcapMain;
1.4 ! takayama 746: struct object mathcapThird;
! 747: struct object ox;
! 748: struct object oxtag;
1.2 takayama 749: struct object ob0;
1.4 ! takayama 750: int oxsize;
1.1 maekawa 751: int n;
752: int i;
753: #define CMO_CHECK_MATH_CAP_LIST_SIZE 1024
754: int cmo[CMO_CHECK_MATH_CAP_LIST_SIZE];
755: if (obp == NULL) return(1);
1.2 takayama 756: /* printObject(*obp,0,stderr); for debug*/
1.1 maekawa 757: if (obp->tag != Sarray) {
758: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
759: printObject(*obp,0,stderr);
760: fprintf(stderr,"\n");
761: errorOxmisc2("cmoCheckMathCap: format error in the client->mathcapObjp field.\n");
762: }
763: mathcap = *obp;
1.2 takayama 764: /* Example of mathcap
765: [ $mathcap-object$ ,
766: [ [ 199909080 , $Ox_system=ox_sm1.plain$ , $Version=2.991106$ ,
767: $HOSTTYPE=i386$ ] ,
768: [ 262 , 263 , 264 , 265 , 266 , 268 , 269 , 272 , 273 , 275 ,
769: 276 ] ,
1.4 ! takayama 770: [ [ 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 771: */
772:
1.1 maekawa 773: n = getoaSize(mathcap);
774: if (n < 2) {
775: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
776: printObject(*obp,0,stderr);
777: fprintf(stderr,"\n");
778: errorOxmisc2("cmoCheckMathCap: length of mathcap is wrong in the client->mathcapObjp field.\n");
779: }
1.2 takayama 780: ob0 = getoa(mathcap,0);
781: if (ob0.tag != Sdollar) {
782: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
783: printObject(*obp,0,stderr);
784: fprintf(stderr,"\n");
785: errorOxmisc2("cmoCheckMathCap: The first field must be the string mathcap-object.\n");
786: }
787: if (strcmp(KopString(ob0),"mathcap-object") != 0) {
788: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
789: printObject(*obp,0,stderr);
790: fprintf(stderr,"\n");
791: errorOxmisc2("cmoCheckMathCap: The mathcap must be of the form [(mathcap-object) [...]]\n");
792: }
793:
1.1 maekawa 794: /* I should check
1.2 takayama 795: getoa(getoa(mathcap,1),2)
1.1 maekawa 796: contains OX_DATA.
797: It has not yet implemented.
798: */
1.2 takayama 799: mathcapMain = getoa(mathcap,1);
800: if (mathcapMain.tag != Sarray) {
801: fprintf(stderr,"cmoCheckMathCap: mathcap[1] is \n");
802: printObject(mathcapMain,0,stderr);
803: fprintf(stderr,"\n");
804: errorOxmisc2("cmoCheckMathCap: format error in the (client->mathcapObjp)[1] field. It should be an array.\n");
805: }
806: if (getoaSize(mathcapMain) < 3) {
807: fprintf(stderr,"cmoCheckMathCap: mathcap[1] is \n");
808: printObject(mathcapMain,0,stderr);
809: fprintf(stderr,"\n");
810: errorOxmisc2("cmoCheckMathCap: format error in the (client->mathcapObjp)[1] field. It should be an array of which length is more than 2.\n");
811: }
1.4 ! takayama 812: mathcapThird = getoa(mathcapMain,2);
! 813: oxsize = getoaSize(mathcapThird);
! 814: for (i=0; i<oxsize; i++) {
! 815: ox = getoa(mathcapThird,i);
! 816: if (ox.tag != Sarray) {
! 817: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
! 818: printObject(*obp,0,stderr);
! 819: fprintf(stderr,"\n");
! 820: errorOxmisc2("cmoCheckMathCap: the third element of mathcap is a list of lists.");
! 821: }
! 822: if (getoaSize(ox) != 0) {
! 823: oxtag = getoa(ox,0);
! 824: if (oxtag.tag != Sinteger) {
! 825: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
! 826: printObject(*obp,0,stderr);
! 827: fprintf(stderr,"\n");
! 828: errorOxmisc2("cmoCheckMathCap: the third element of mathcap must be [OX_DATA_xxx, [ ]].");
! 829: }
! 830: if (KopInteger(oxtag) == OX_DATA) {
! 831: if (getoaSize(ox) > 1) {
! 832: cmolist = getoa(ox,1);
! 833: if (cmolist.tag != Sarray) {
! 834: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
! 835: printObject(*obp,0,stderr);
! 836: fprintf(stderr,"\n");
! 837: errorOxmisc2("cmoCheckMathCap: mathcap[1] must be an array of integers.\n");
! 838: }
! 839: n = getoaSize(cmolist);
! 840: if (n > CMO_CHECK_MATH_CAP_LIST_SIZE) {
! 841: errorOxmisc2("cmoCheckMathCap: Too big cmo list.\n");
! 842: }
! 843: for (i=0; i<n; i++) {
! 844: cmo[i] = KopInteger(getoa(cmolist,i));
! 845: }
! 846: }else{
! 847: fprintf(stderr,"cmoCheckMathCap: the mathcap obj is \n");
! 848: printObject(*obp,0,stderr);
! 849: fprintf(stderr,"\nox=");
! 850: printObject(ox,0,stderr);
! 851: errorOxmisc2("cmoCheckMathCap: [OX_DATA, cmolist]");
! 852: }
! 853: }
! 854: }
1.1 maekawa 855: }
856: return(cmoCheck00(obj,cmo,n));
857: }
858:
859:
860: struct object KoxGenPortFile(void) {
861: struct object ob;
862: ob = KpoString(oxGenPortFile());
863: return(ob);
864: }
865: void KoxRemovePortFile(void) {
866: oxRemovePortFile();
867: }
868:
869: void oxPushMathCap(struct mathCap *mathcap)
870: {
871: struct object rob;
872: rob = newMathCap(mathcap);
873: Kpush(rob);
874: }
875:
876: struct object KoxGenPass(void) {
877: struct object rob;
878: rob = KpoString(oxGenPass());
879: return(rob);
880: }
881:
882: struct object KoxGetPort(struct object host)
883: {
884: struct object rob;
885: int fdStream, fdControl;
886: int portStream, portControl;
887: extern int OpenedSocket;
888: char *sname;
889: rob = NullObject;
890: if (host.tag != Sdollar) {
891: errorOxmisc2("KoxGetPort: argument is not a string.");
892: return(rob);
893: }
894: sname = KopString(host);
895: fdControl = socketOpen(sname,0);
896: portControl = OpenedSocket;
897: fdStream = socketOpen(sname,0);
898: portStream = OpenedSocket;
899: rob = newObjectArray(4);
900: putoa(rob,0,KpoInteger(fdStream));
901: putoa(rob,1,KpoInteger(portStream));
902: putoa(rob,2,KpoInteger(fdControl));
903: putoa(rob,3,KpoInteger(portControl));
904: return(rob);
905: }
906:
907: struct object KoxCreateClient2(struct object peer,
908: struct object ipmask,
909: struct object pass)
910: {
911: struct object rob;
912: oxclientp client;
913: int fdStream, portStream, fdControl, portControl;
914: int i;
915: struct object ob1;
916: rob.tag = Snull;
917: if (peer.tag != Sarray) {
918: errorOxmisc2("KoxCreateClient2(): The first argument must be an array [fdStream, portStream, fdControl, portControl]");
919: return(rob);
920: }
921: if (getoaSize(peer) != 4) {
922: errorOxmisc2("KoxCreateClient2(): The first argument must be an array [fdStream, portStream, fdControl, portControl] of size 4.");
923: return(rob);
924: }
925: for (i=0; i<4; i++) {
926: ob1 = getoa(peer,i);
927: if (ob1.tag != Sinteger) {
928: errorOxmisc2("KoxCreateClient2(): The element of the first argument must be an integer.");
929: }
930: }
931: fdStream = KopInteger(getoa(peer,0));
932: portStream = KopInteger(getoa(peer,1));
933: fdControl = KopInteger(getoa(peer,2));
934: portControl = KopInteger(getoa(peer,3));
935:
936: if (ipmask.tag != Sinteger) {
937: errorOxmisc2("KoxCreateClient2(): ipmask must be an integer.");
938: }
939: if (pass.tag != Sdollar) {
940: errorOxmisc2("KoxCreateClient2(): pass must be a string.");
941: }
942:
943: client = oxCreateClient2(fdStream, portStream, fdControl, portControl,
944: KopInteger(ipmask), KopString(pass));
945: if (client == NULL) {
946: errorOxmisc2("KoxCreateClient2(): Open error.");
947: return(rob);
948: }
949: rob = newObjectArray(N_OF_CLIENT_FIELDS);
950: oxClientToObject(client,rob);
951: return(rob);
952: }
953:
954: errorOxmisc2(char *s) {
955: fprintf(MyErrorOut,"error in oxmisc2.c: %s\n",s);
956: errorKan1("%s\n"," ");
957: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>