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