[BACK]Return to sm1sm.c CVS log [TXT][DIR] Up to [local] / OpenXM / src / k097

Annotation of OpenXM/src/k097/sm1sm.c, Revision 1.4

1.4     ! takayama    1: /* $OpenXM: OpenXM/src/k097/sm1sm.c,v 1.3 2013/11/07 07:29:47 takayama Exp $ */
1.1       takayama    2: /* This is imported from kxx/sm1stackmachine.c */
                      3: #include <stdio.h>
                      4: #include <setjmp.h>
1.3       takayama    5: #include <string.h>
1.4     ! takayama    6: #include <stdlib.h>
1.1       takayama    7: #include "../kxx/ox_kan.h"
                      8: #include "../kxx/serversm.h"
                      9: extern int OXprintMessage;
                     10:
                     11: /*  server stack machine */
                     12:
                     13:
                     14: void *Sm1_mathcap() {
                     15:   int n,i;
                     16:   struct mathCap *mathcap;
                     17:   mathcap = KSmathCapByStruct();
                     18:   return((void *)mathcap);
                     19: }
                     20:
                     21: int Sm1_setMathCap(ox_stream os) {
                     22:   /* Set the mathcap data of the client in the server. */
                     23:   /*  sm1 <====== ox_sm1  mathcap is set in ox_stream = FILE2 * */
                     24:   /* The mathcap data is on the stack. */
1.2       takayama   25:   struct object ob = OINIT;
                     26:   struct object ob2 = OINIT;
1.1       takayama   27:   int n,i;
                     28:   ob = KSpop();
                     29:   KSpush(ob);  KSexecuteString(" (mathcap data is ) message message ");
                     30:   Kan_setMathCapToStream(os,ob);
                     31:   /* set the math cap data associated to the ox_stream. */
                     32: }
                     33: void Sm1_pops(void) {
                     34:   char data[100];
                     35:   sprintf(data," 1 1 3 -1 roll { pop pop } for ");
                     36:   KSexecuteString(data);
                     37: }
                     38: int Sm1_executeStringByLocalParser(void) {
                     39:   int i;
                     40:   char *s;
                     41:   s = Sm1_popString();
                     42:   if (s == NULL) {
                     43:     printf("NULL argument for executeString.\n");
                     44:     return(-1);
                     45:   }else{
                     46:     if (OXprintMessage) fprintf(stderr,"KSexecuteString(%s)\n",s);
                     47:     i = KSexecuteString(s);
                     48:     return(i);
                     49:   }
                     50: }
                     51: char *Sm1_popString(void) {
                     52:   char *KSpopString();
                     53:   KSexecuteString(" toString ");
                     54:   return(KSpopString());
                     55: }
                     56:
                     57:
                     58: int Sm1_setName(void)
                     59: {
                     60:   char *s;
1.2       takayama   61:   struct object ob = OINIT;
1.1       takayama   62:   s = Sm1_popString();
                     63:   if (s == NULL) {
                     64:     printf("NULL argument for setName.\n");
                     65:     return(-1);
                     66:   }else{
                     67:     ob = KSpop();
                     68:     printf("/%s tag=%d def\n",s,ob.tag);
                     69:     KputUserDictionary(s,ob);
                     70:     return(0);
                     71:   }
                     72: }
                     73:
                     74: int Sm1_evalName(void)
                     75: {
                     76:   char *s;
1.2       takayama   77:   struct object ob = OINIT;
1.1       takayama   78:   s = Sm1_popString();
                     79:   if (s == NULL) {
                     80:     printf("NULL argument for evalName.\n");
                     81:     return(-1);
                     82:   }else{
                     83:     ob = KfindUserDictionary(s);
                     84:     if (ob.tag == -1) {
                     85:       printf("findUserDictionary(%s)--> tag=%d Not found.\n",s,ob.tag);
                     86:       return(-1);
                     87:     }
                     88:     printf("findUserDictionary(%s)--> tag=%d\n",s,ob.tag);
                     89:     KSpush(ob);
                     90:     return(0);
                     91:   }
                     92: }
                     93:
                     94: int Sm1_pushCMO(ox_stream fp)
                     95: {
                     96:   return(Kan_pushCMOFromStream(fp));
                     97: }
                     98: int Sm1_popCMO(ox_stream fp,int serial)
                     99: {
                    100:   return(Kan_popCMOToStream(fp,serial));
                    101: }
                    102:
                    103: int Sm1_pushError2(int serial, int no, char *s)
                    104: {
1.2       takayama  105:   struct object ob = OINIT;
1.1       takayama  106:   ob = KnewErrorPacket(serial,no,s);
                    107:   KSpush(ob);
                    108: }
                    109:
                    110: char *Sm1_popErrorMessage(char *s) {
                    111:   char *e;
                    112:   char *a;
                    113:   extern int ErrorMessageMode;
                    114:   /* Set ErrorMessageMode = 2 to use this function. */
                    115:   if (ErrorMessageMode != 2) return(s);
                    116:   e = popErrorStackByString();
                    117:   if (e == NULL ) {
                    118:     a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+80));
                    119:     if (a == NULL) {
                    120:       fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
                    121:       exit(10);
                    122:     }
                    123:     strcpy(a,s); strcat(a,"No error message on the error stack.");
                    124:     return(a);
                    125:   }else{
                    126:     a = (char *) sGC_malloc(sizeof(char)*(strlen(s)+strlen(e)+2));
                    127:     if (a == NULL) {
                    128:       fprintf(stderr,"No more memory in Sm1_popErrorMessage.\n");
                    129:       exit(10);
                    130:     }
                    131:     strcpy(a,s); strcat(a,e);
                    132:     return(a);
                    133:   }
                    134: }
                    135:
                    136: void Sm1_getsp(void) {
                    137:   KSpush(KpoInteger(KSstackPointer()));
                    138: }
                    139:
                    140: void Sm1_dupErrors(void) {
                    141:   KSpush(KSdupErrors());
                    142: }
                    143:
                    144: void Sm1_pushCMOtag(int serial) {
1.2       takayama  145:   struct object obj = OINIT;
1.1       takayama  146:   int t;
                    147:   obj = KSpeek(0);
                    148:   t = KgetCmoTagOfObject(obj);
                    149:   if (t != -1) {
                    150:     KSpush(KpoInteger(t));
                    151:   }else{
                    152:     Sm1_pushError2(serial,-1,"The top object on the server stack cannot be translated to cmo.");
                    153:   }
                    154: }
                    155:
                    156:

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