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

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

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

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