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