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

Annotation of OpenXM/src/kxx/ox_texmacs.c, Revision 1.29

1.29    ! takayama    1: /* $OpenXM: OpenXM/src/kxx/ox_texmacs.c,v 1.28 2006/02/02 07:07:22 takayama Exp $ */
1.1       takayama    2:
                      3: #include <stdio.h>
1.23      takayama    4: #include <stdlib.h>
                      5: #include <string.h>
1.1       takayama    6: #include <setjmp.h>
                      7: #include <signal.h>
                      8: #include "ox_kan.h"
                      9: #include "serversm.h"
                     10:
                     11: #if defined(__CYGWIN__)
                     12: #define JMP_BUF sigjmp_buf
                     13: #define SETJMP(env)  sigsetjmp(env,1)
                     14: #define LONGJMP(env,p)  siglongjmp(env,p)
                     15: #else
                     16: #define JMP_BUF jmp_buf
                     17: #define SETJMP(env)  setjmp(env)
                     18: #define LONGJMP(env,p)  longjmp(env,p)
                     19: #endif
                     20:
1.3       takayama   21: /*
                     22: #define DEBUG
                     23: */
1.7       takayama   24: /* #define DEBUG2 */
1.3       takayama   25:
1.23      takayama   26: /* Type of View part (user interface engine) */
                     27: #define  GENERIC      0   /* DEBUG, xml */
                     28: #define  V_TEXMACS    1
                     29: #define  V_CFEP       2
                     30: int View       = V_TEXMACS ;
                     31:
                     32: char *Data_begin_v[] = {
                     33:   "<S type=verbatim>",
                     34:   "\002verbatim:",
                     35:   "\002",
                     36: };
                     37: char *Data_begin_l[] = {
                     38:   "<S type=latex>",
                     39:   "\002latex:",
                     40:   "\002latex:"
                     41: };
                     42: char *Data_begin_p[] = {
                     43:   "<S type=prompt>",
                     44:   "\002prompt:",
                     45:   "\002prompt:"
                     46: };
                     47: char *Data_begin_ps[] = {
                     48:   "<S type=postscript>",
                     49:   "\002ps:",
                     50:   "\002ps:"
                     51: };
                     52: char *Data_end[] = {
                     53:   "</S>",
                     54:   "\005",
1.25      takayama   55:   "\n\005"    /* \n is not a part of the protocol. */
1.23      takayama   56: };
                     57:
1.25      takayama   58: /* todo:  start_of_input */
1.2       takayama   59:
1.25      takayama   60: char End_of_input[] = {
                     61:   0x5,              /* Use ^E and Return to end the input. */
                     62:   '\n',  /* TEXMACS_END_OF_INPUT. 0xd should be used for multiple lines. */
                     63:   0x5    /* CFEP_END_OF_INPUT    */
                     64: };
1.1       takayama   65:
1.5       takayama   66: /* Table for the engine type. */
                     67: #define ASIR          1
                     68: #define SM1           2
                     69: #define K0            3
                     70:
1.1       takayama   71: extern int Quiet;
                     72: extern JMP_BUF EnvOfStackMachine;
1.19      takayama   73: extern int Calling_ctrlC_hook;
1.20      takayama   74: extern int RestrictedMode, RestrictedMode_saved;
1.3       takayama   75: int Format=1;  /* 1 : latex mode */
                     76: int OutputLimit_for_TeXmacs = (1024*10);
1.1       takayama   77:
1.22      takayama   78:
1.5       takayama   79: int TM_Engine  = ASIR ;
                     80: int TM_asirStarted = 0;
                     81: int TM_sm1Started  = 0;
                     82: int TM_k0Started  = 0;
1.7       takayama   83: int TM_do_not_print = 0;
1.5       takayama   84:
1.15      takayama   85: int Xm_noX = 0;
                     86: int NoCopyright = 0;
1.25      takayama   87: int Cpp = 0;                 /* Use cpp before sending to the engine. */
                     88: int EngineLogToStdout = 0;   /* Do not run the ox engine inside xterm. */
1.15      takayama   89:
1.29    ! takayama   90: char *LanguageResource = NULL;
        !            91:
1.1       takayama   92: void ctrlC();
                     93: struct object KpoString(char *s);
                     94: char *KSpopString(void);
                     95:
1.2       takayama   96: static char *readString(FILE *fp,char *prolog, char *eplog);
1.1       takayama   97: static void printv(char *s);
                     98: static void printl(char *s);
                     99: static void printp(char *s);
1.17      takayama  100: static void printps(char *s);
1.2       takayama  101: static void printCopyright(char *s);
1.5       takayama  102: static int startEngine(int type,char *msg);
1.17      takayama  103: static int isPS(char *s);
1.22      takayama  104: static int end_of_input(int c);
                    105: static void setDefaultParameterForCfep();
1.2       takayama  106:
1.27      takayama  107: static void myEncoder(int c);
                    108: static void myEncoderS(unsigned char *s);
                    109: static void myEncoderSn(unsigned char *s,int n);
                    110: static void outputStringToTunnel0(int channel, unsigned char *s, int size, int view);
                    111: static void outputStringToTunnel(int channel, unsigned char *s,  int view);
                    112:
1.2       takayama  113: /* tail -f /tmp/debug-texmacs.txt
                    114:    Debug output to understand the timing problem of pipe interface.
                    115: */
1.3       takayama  116: FILE *Dfp;
1.1       takayama  117:
1.10      takayama  118: main(int argc,char *argv[]) {
1.1       takayama  119:   char *s;
                    120:   char *r;
                    121:   char *sys;
1.21      takayama  122:   struct object ob = OINIT;
1.3       takayama  123:   int irt=0;
1.4       takayama  124:   int vmode=1;
1.7       takayama  125:   char *openxm_home;
                    126:   char *asir_config;
1.10      takayama  127:   int i;
1.1       takayama  128:
1.7       takayama  129:
                    130:
1.3       takayama  131: #ifdef DEBUG2
                    132:   Dfp = fopen("/tmp/debug-texmacs.txt","w");
                    133: #endif
1.2       takayama  134:
1.1       takayama  135:   /* Set consts */
                    136:   Quiet = 1;
1.10      takayama  137:   for (i=1; i<argc; i++) {
1.22      takayama  138:     if (strcmp(argv[i],"--view") == 0) {
                    139:       i++;
                    140:       if (strcmp(argv[i],"texmacs") == 0) {
                    141:         View = V_TEXMACS;
                    142:       }else if (strcmp(argv[i],"cfep")==0) {
                    143:         View = V_CFEP; setDefaultParameterForCfep();
                    144:       }else{
1.25      takayama  145:         View = GENERIC;
1.22      takayama  146:         /* printv("Unknown view type.\n"); */
                    147:       }
                    148:     } else if (strcmp(argv[i],"--sm1") == 0) {
                    149:       TM_Engine = SM1;
                    150:     }else if (strcmp(argv[i],"--asir") == 0) {
                    151:       TM_Engine = ASIR;
                    152:     }else if (strcmp(argv[i],"--k0") == 0) {
                    153:       TM_Engine = K0;
1.14      takayama  154:     }else if (strcmp(argv[i],"--outputLimit") == 0) {
                    155:       i++;
                    156:       sscanf(argv[i],"%d",&OutputLimit_for_TeXmacs);
1.15      takayama  157:     }else if (strcmp(argv[i],"--noLogWindow") == 0) {
1.22      takayama  158:       Xm_noX = 1;
1.15      takayama  159:     }else if (strcmp(argv[i],"--noCopyright") == 0) {
1.22      takayama  160:       NoCopyright = 1;
1.25      takayama  161:     }else if (strcmp(argv[i],"--cpp") == 0) {
                    162:       Cpp = 1;
                    163:     }else if (strcmp(argv[i],"--engineLogToStdout") == 0) {
                    164:       EngineLogToStdout = 1;
1.29    ! takayama  165:     }else if (strcmp(argv[i],"--languageResource") == 0) {
        !           166:       i++;
        !           167:       LanguageResource = (char *)sGC_malloc(strlen(argv[i])+80);
        !           168:       sprintf(LanguageResource,
        !           169:                          " /localizedString.file (%s) def localizedString.load ",argv[i]);
1.22      takayama  170:     }else{
                    171:       /* printv("Unknown option\n"); */
                    172:     }
1.10      takayama  173:   }
1.1       takayama  174:
1.23      takayama  175:   openxm_home = (char *) getenv("OpenXM_HOME");
                    176:   asir_config = (char *) getenv("ASIR_CONFIG");
                    177:   if (openxm_home == NULL)  {
                    178:     printv("Error. The environmental variable OpenXM_HOME is not set.\nStart the texmacs with openxm texmacs or ox_texmacs by openxm ox_texmacs\nBye...");
                    179:     exit(10);
                    180:   }
                    181:
1.1       takayama  182:   /* Initialize kanlib (gc is also initialized) */
                    183:   KSstart();
                    184:
1.3       takayama  185:   /* Main loop */
1.23      takayama  186:   printf("%s",Data_begin_v[View]);
                    187:   if ((asir_config == NULL) && (View == V_TEXMACS)) {
                    188:     printf("Warning. The environmental variable ASIR_CONFIG is not set.\nStart the texmacs with openxm texmacs or ox_texmacs by openxm ox_texmacs.\nOtherwise, tex translation will not be performed\n");
                    189:
                    190:   }
                    191:
1.3       takayama  192:   printCopyright("");
                    193:
1.23      takayama  194:
1.1       takayama  195:   /* Load ox engine here */
                    196:   /* engine id should be set to ox.engine */
                    197:   KSexecuteString(" [(parse) (ox.sm1) pushfile] extension ");
1.15      takayama  198:   if (Xm_noX) KSexecuteString(" /Xm_noX 1 def ");
1.26      takayama  199:   if (EngineLogToStdout) KSexecuteString(" /Xm_engineLogToStdout 1 def ");
1.29    ! takayama  200:   if (LanguageResource != NULL) KSexecuteString(LanguageResource);
1.5       takayama  201:   startEngine(TM_Engine," ");
1.1       takayama  202:
                    203:   if (signal(SIGINT,SIG_IGN) != SIG_IGN) {
1.8       takayama  204:     signal(SIGINT,ctrlC);
1.1       takayama  205:   }
1.3       takayama  206:
                    207:   irt = 0;
1.1       takayama  208:   while(1) {
1.8       takayama  209:     /* printp(sys);  no prompt */
                    210:     if (SETJMP(EnvOfStackMachine)) {
1.19      takayama  211:       if (!Calling_ctrlC_hook) {
1.20      takayama  212:         Calling_ctrlC_hook = 1; RestrictedMode = 0;
1.19      takayama  213:         KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */
1.20      takayama  214:         RestrictedMode = RestrictedMode_saved;
1.19      takayama  215:       }
                    216:       Calling_ctrlC_hook = 0;
1.8       takayama  217:       if (signal(SIGINT,SIG_IGN) != SIG_IGN) {
                    218:         signal(SIGINT,ctrlC);
                    219:       }
                    220:       irt = 1;
                    221:       continue;
                    222:     } else {  }
                    223:     if (!irt) {
1.23      takayama  224:       printf("%s",Data_end[View]); fflush(stdout);
1.8       takayama  225:     }
                    226:     irt = 0;
1.7       takayama  227:
                    228:     /* Reading the input. */
1.8       takayama  229:     if (TM_Engine == K0) {
                    230:       s=readString(stdin, " ", " "); /* see test data */
                    231:     }else if (TM_Engine == SM1) {
                    232:       s=readString(stdin, " ", " "); /* see test data */
                    233:     }else{
                    234:       s=readString(stdin, "if (1) { ", " ; }else{ }"); /* see test data */
                    235:     }
1.5       takayama  236:
1.8       takayama  237:     if (s == NULL) { irt = 1; continue; }
1.23      takayama  238:     if (!irt) printf("%s",Data_begin_v[View]);
1.7       takayama  239:     /* Evaluate the input on the engine */
1.27      takayama  240:     KSexecuteString(" ox.engine oxclearstack ");
1.1       takayama  241:     KSexecuteString(" ox.engine ");
1.7       takayama  242:     ob = KpoString(s);
1.8       takayama  243:     KSpush(ob);
                    244:     KSexecuteString(" oxsubmit ");
                    245:
1.27      takayama  246:     /* Get the result in string for cfep. */
                    247:     if (View != V_TEXMACS) {
                    248:       KSexecuteString(" ox.engine oxgeterrors ");
                    249:       ob = KSpop();
                    250:       if (ob.tag == Sarray) {
                    251:         if (getoaSize(ob) > 0) {
                    252:           ob = getoa(ob,0);
                    253:           KSpush(ob);
                    254:           KSexecuteString(" translateErrorForCfep ");
                    255:           r = KSpopString();
                    256:           outputStringToTunnel(0,(unsigned char *)r,View);
                    257:         }
                    258:       }
                    259:       if (!TM_do_not_print) {
                    260:         KSexecuteString(" ox.engine oxpopstring ");
                    261:         r = KSpopString();
                    262:         printv(r);
                    263:       }else{
                    264:         KSexecuteString(" ox.engine 1 oxpops ");
                    265:         KSexecuteString(" ox.engine 0 oxpushcmo ox.engine oxpopcmo ");
                    266:         ob = KSpop();
                    267:         printv("");
                    268:       }
                    269:       continue;
                    270:     }
                    271:     /* Get the result in string for texmacs  */
1.8       takayama  272:     if (Format == 1 && (! TM_do_not_print)) {
                    273:       /* translate to latex form */
                    274:       KSexecuteString(" ox.engine oxpushcmotag ox.engine oxpopcmo ");
                    275:       ob = KSpop();
                    276:       vmode = 0;
                    277:       /* printf("id=%d\n",ob.tag); bug: matrix return 17 instead of Sinteger
                    278:        or error. */
                    279:       if (ob.tag == Sinteger) {
                    280:         /* printf("cmotag=%d\n",ob.lc.ival);*/
                    281:         if (ob.lc.ival == CMO_ERROR2) {
                    282:           vmode = 1;
                    283:         }
                    284:         if (ob.lc.ival == CMO_STRING) {
                    285:           vmode = 1;
                    286:         }
                    287:       }
                    288:       if (vmode) {
                    289:         KSexecuteString(" ox.engine oxpopstring ");
                    290:         r = KSpopString();
                    291:       }else{
                    292:         KSexecuteString(" ox.engine 1 oxpushcmo ox.engine (print_tex_form) oxexec  ");
                    293:         KSexecuteString(" ox.engine oxpopstring ");
                    294:         r = KSpopString();
                    295:       }
1.17      takayama  296:       if (isPS(r)) {
                    297:         printps(r);
                    298:       }else{
                    299:         if (vmode) printv(r);
                    300:         else{
                    301:           if (strlen(r) < OutputLimit_for_TeXmacs) {
                    302:             printl(r);
                    303:           } else printv("Output is too large.\n");
                    304:         }
                    305:       }
1.8       takayama  306:     }else{
                    307:       if (!TM_do_not_print) {
                    308:         KSexecuteString(" ox.engine oxpopstring ");
                    309:         r = KSpopString();
1.17      takayama  310:         printv(r);
1.8       takayama  311:       }else{
                    312:         KSexecuteString(" ox.engine 1 oxpops "); /* Discard the result. */
1.12      takayama  313:         /* Push and pop dummy data to wait until the computation finishes. */
                    314:         KSexecuteString(" ox.engine 0 oxpushcmo ox.engine oxpopcmo ");
                    315:         ob = KSpop();
1.8       takayama  316:         printv("");
                    317:       }
                    318:     }
1.27      takayama  319:     /* note that there is continue above. */
1.1       takayama  320:   }
                    321: }
                    322:
                    323: #define SB_SIZE 1024
1.8       takayama  324: #define INC_BUF     if (n >= limit-3) { \
                    325:       tmp = s; \
                    326:       limit *= 2;  \
                    327:       s = (char *) sGC_malloc(limit); \
                    328:       if (s == NULL) { \
                    329:         fprintf(stderr,"No more memory.\n"); \
                    330:         exit(10); \
                    331:       } \
                    332:       strcpy(s,tmp); \
                    333:     }
1.2       takayama  334: /*   */
                    335: static char *readString(FILE *fp, char *prolog, char *epilog) {
1.1       takayama  336:   int n = 0;
                    337:   static int limit = 0;
                    338:   static char *s;
                    339:   int c;
                    340:   char *tmp;
1.2       takayama  341:   int i;
1.3       takayama  342:   int m;
                    343:   int start;
1.21      takayama  344:   struct object ob = OINIT;
1.1       takayama  345:   if (limit == 0) {
1.8       takayama  346:     limit = 1024;
                    347:     s = (char *)sGC_malloc(limit);
                    348:     if (s == NULL) {
                    349:       fprintf(stderr,"No more memory.\n");
                    350:       exit(10);
                    351:     }
1.1       takayama  352:   }
1.2       takayama  353:   s[0] = 0; n = 0; m = 0;
                    354:   for (i=0; i < strlen(prolog); i++) {
1.8       takayama  355:     s[n++] = prolog[i];  s[n] = 0;
1.2       takayama  356:     INC_BUF ;
                    357:   }
1.3       takayama  358:   start = n;
1.1       takayama  359:   while ((c = fgetc(fp)) != EOF) {
1.3       takayama  360: #ifdef DEBUG2
1.8       takayama  361:     fprintf(Dfp,"[%x] ",c); fflush(Dfp);
1.3       takayama  362: #endif
1.22      takayama  363:     if (end_of_input(c)) {
1.18      takayama  364:       /* If there remains data in the stream,
1.25      takayama  365:          read the remaining data. (for debug) */
1.18      takayama  366:          /*
1.8       takayama  367:       if (oxSocketSelect0(0,1)) {
                    368:         if (c == '\n') c=' ';
                    369:         s[n++] = c; s[n] = 0;  m++;
                    370:         INC_BUF ;
                    371:         continue;
                    372:       }
1.18      takayama  373:       */
1.8       takayama  374:       break;
                    375:     }
1.18      takayama  376:     if ( c == '\v') c=' ';
1.8       takayama  377:     s[n++] = c; s[n] = 0;  m++;
1.2       takayama  378:     INC_BUF ;
                    379:   }
1.5       takayama  380:   /* Check the escape sequence */
                    381:   if (strcmp(&(s[start]),"!quit;") == 0) {
1.8       takayama  382:     printv("Terminated the process ox_texmacs.\n");
                    383:     exit(0);
1.3       takayama  384:   }
1.11      takayama  385:   /* Check the escape sequence to change the global env. */
1.5       takayama  386:   if (strcmp(&(s[start]),"!verbatim;") == 0) {
1.8       takayama  387:     printv("Output mode is changed to verbatim mode.");
                    388:     Format=0;
                    389:     return NULL;
1.5       takayama  390:   }
                    391:   if (strcmp(&(s[start]),"!latex;") == 0) {
1.8       takayama  392:     printv("Output mode is changed to latex/verbose.");
                    393:     Format = 1;
                    394:     return NULL;
1.5       takayama  395:   }
                    396:   if (strcmp(&(s[start]),"!asir;") == 0) {
1.8       takayama  397:     Format=1;
                    398:     TM_Engine=ASIR; startEngine(TM_Engine,"Asir");
                    399:     return NULL;
1.5       takayama  400:   }
                    401:   if (strcmp(&(s[start]),"!sm1;") == 0) {
1.8       takayama  402:     Format=0;
                    403:     TM_Engine=SM1; startEngine(TM_Engine,"sm1");
                    404:     return NULL;
1.5       takayama  405:   }
                    406:   if (strcmp(&(s[start]),"!k0;") == 0) {
1.8       takayama  407:     Format=0;
                    408:     TM_Engine=K0; startEngine(TM_Engine,"k0");
                    409:     return NULL;
1.5       takayama  410:   }
1.13      takayama  411:   if (strcmp(&(s[start]),"!reset;") == 0) {
1.23      takayama  412:        printf("%s",Data_begin_v[View]);
1.13      takayama  413:     KSexecuteString(" ox.engine oxreset ox.engine oxpopcmo ");
                    414:        ob = KSpop();
1.23      takayama  415:        printf("%s",Data_end[View]); fflush(stdout);
1.13      takayama  416:     return NULL;
                    417:   }
1.11      takayama  418:
                    419:   /* Set TM_do_no_print */
                    420:   if (s[n-1] == '$' && TM_Engine == ASIR) {
                    421:        TM_do_not_print = 1; s[n-1] = ' ';
                    422:   } else if (s[n-1] == ';' && TM_Engine == SM1) {
                    423:        TM_do_not_print = 1; s[n-1] = ' ';
                    424:   } else TM_do_not_print = 0;
1.5       takayama  425:
1.2       takayama  426:   for (i=0; i < strlen(epilog); i++) {
1.8       takayama  427:     s[n++] = epilog[i];  s[n] = 0;
1.2       takayama  428:     INC_BUF ;
1.1       takayama  429:   }
                    430:   return s;
1.22      takayama  431: }
                    432:
                    433: static int end_of_input(int c) {
1.25      takayama  434:   if (c == End_of_input[View]) return 1;
                    435:   else return 0;
1.22      takayama  436: }
1.25      takayama  437:
1.22      takayama  438: static void setDefaultParameterForCfep() {
                    439:   Format = 0;
1.1       takayama  440: }
                    441:
                    442: static void printv(char *s) {
                    443:   int i;
1.23      takayama  444:   printf("%s",Data_begin_v[View]);
1.1       takayama  445:   printf("%s",s);
1.23      takayama  446:   printf("%s",Data_end[View]);
1.3       takayama  447: #ifdef DEBUG2
                    448:   fprintf(Dfp,"<%s>",s); fflush(Dfp);
                    449: #endif
1.1       takayama  450:   fflush(NULL);
                    451: }
                    452: static void printl(char *s) {
1.23      takayama  453:   printf("%s",Data_begin_l[View]);
1.4       takayama  454:   printf(" $ %s $ ",s);
1.23      takayama  455:   printf("%s",Data_end[View]);
1.17      takayama  456:   fflush(NULL);
                    457: }
                    458: static int isPS(char *s) {
                    459:   if (s[0] != '%') return 0;
                    460:   if (s[1] != '%') return 0;
                    461:   if (s[2] != '!') return 0;
                    462:   if (s[3] != 'P') return 0;
                    463:   if (s[4] != 'S') return 0;
                    464:   return 1;
                    465: }
                    466: static void printps(char *s) {
1.23      takayama  467:   printf("%s",Data_begin_ps[View]);
1.17      takayama  468:   printf("%s",s);
1.23      takayama  469:   printf("%s",Data_end[View]);
1.1       takayama  470:   fflush(NULL);
                    471: }
                    472: static void printp(char *s) {
1.23      takayama  473:   printf("%s",Data_begin_p[View]);
                    474:   printf("%s",Data_end[View]);
1.2       takayama  475:   printf("%s] ",s);
                    476:   fflush(NULL);
                    477: }
                    478: static void printCopyright(char *s) {
1.23      takayama  479:   printf("%s",Data_begin_v[View]);
1.15      takayama  480:   if (! NoCopyright) {
1.24      takayama  481:     printf("OpenXM engine (ox engine) interface with TeXmacs protocol.\n2004 (C) openxm.org");
                    482:     printf(" under the BSD license.  !asir; !sm1; !k0; !verbatim; !quit;\n");
1.15      takayama  483:     printf("Type in      !reset;     when the engine gets confused. ");
                    484:     printf("%s",s);
                    485:   }
1.23      takayama  486:   printf("%s",Data_end[View]);
1.5       takayama  487:   fflush(NULL);
                    488: }
                    489:
                    490: static int startEngine(int type,char *msg) {
1.21      takayama  491:   struct object ob = OINIT;
1.23      takayama  492:   printf("%s",Data_begin_v[View]);
1.5       takayama  493:   if (type == SM1) {
                    494:     if (!TM_sm1Started) KSexecuteString(" sm1connectr ");
1.8       takayama  495:     KSexecuteString(" /ox.engine oxsm1.ccc def ");
1.10      takayama  496:     /* Initialize the setting of sm1. */
                    497:     KSexecuteString("  oxsm1.ccc ( [(cmoLispLike) 0] extension ) oxsubmit ");
                    498:     KSexecuteString("  oxsm1.ccc ( ox_server_mode ) oxsubmit ");
                    499:     KSexecuteString("  oxsm1.ccc ( ( ) message (------------- Message from sm1 ----------------)message ) oxsubmit ");
1.8       takayama  500:     TM_sm1Started = 1;
1.10      takayama  501:        /* Welcome message.  BUG. Copyright should be returned by a function. */
1.15      takayama  502:     if (! NoCopyright) {
                    503:       printf("Kan/StackMachine1                         1991 April --- 2004.\n");
                    504:       printf("This software may be freely distributed as is with no warranty expressed. \n");
                    505:       printf("See OpenXM/Copyright/Copyright.generic\n");
                    506:       printf("Info: http://www.math.kobe-u.ac.jp/KAN, kan@math.kobe-u.ac.jp.\n");
                    507:       printf("0 usages to show a list of functions. \n(keyword) usages to see a short description\n");
                    508:     }
1.8       takayama  509:     printf("%s\n",msg);
1.5       takayama  510:   }else if (type == K0) {
                    511:     if (!TM_k0Started) KSexecuteString(" k0connectr ");
1.8       takayama  512:     KSexecuteString(" /ox.engine oxk0.ccc def ");
                    513:     TM_k0Started = 1;
                    514:     printf("%s\n",msg);
1.5       takayama  515:   }else{
                    516:     if (!TM_asirStarted) KSexecuteString(" asirconnectr ");
1.8       takayama  517:     KSexecuteString(" /ox.engine oxasir.ccc def ");
                    518:     TM_asirStarted = 1;
                    519:     printf("%s\n",msg);
1.24      takayama  520:     if ((!NoCopyright) && ((char *)getenv("ASIR_CONFIG") != NULL)) {
1.15      takayama  521:       KSexecuteString(" oxasir.ccc (copyright()+asir_contrib_copyright();) oxsubmit oxasir.ccc oxpopstring ");
1.24      takayama  522:       ob = KSpop();
                    523:       if (ob.tag == Sdollar) {
                    524:         printf("%s",ob.lc.str);
                    525:       }
                    526:     }else if ((!NoCopyright) && ((char *)getenv("ASIR_CONFIG") == NULL)) {
                    527:       KSexecuteString(" oxasir.ccc (copyright();) oxsubmit oxasir.ccc oxpopstring ");
1.15      takayama  528:       ob = KSpop();
                    529:       if (ob.tag == Sdollar) {
                    530:         printf("%s",ob.lc.str);
                    531:       }
1.8       takayama  532:     }
1.7       takayama  533:     /* Initialize the setting of asir. */
                    534:     KSexecuteString(" oxasir.ccc (if(1) {  Xm_server_mode = 1; Xm_helpdir = \"help-eg\";  } else { ; } ;) oxsubmit oxasir.ccc oxpopcmo ");
                    535:     KSexecuteString(" oxasir.ccc (if(1) {  ctrl(\"message\",0);  } else { ; } ;) oxsubmit oxasir.ccc oxpopcmo ");
                    536:     /* bug; if ctrl is written with Xm_helpdir = ... without oxpopcmo, then it does
                    537:        not work. */
1.9       takayama  538:     KSexecuteString(" oxasir.ccc (print(\"----------- Messages from asir ------------------------------\")$ ) oxsubmit oxasir.ccc oxpopcmo ");
1.5       takayama  539:   }
1.23      takayama  540:   printf("%s",Data_end[View]);
1.1       takayama  541:   fflush(NULL);
                    542: }
1.2       takayama  543:
                    544: /* test data
                    545:
                    546: 1.  print("hello"); print("afo");
                    547:
                    548:     1+2;
                    549:
                    550: 2. def foo(N) { for (I=0; I<10; I++) {   --> error
                    551:
                    552:    3+5;
                    553:
                    554: 4.  print("hello"); shift+return print("afo");
                    555:
                    556: */
1.27      takayama  557:
                    558: static void myEncoder(int c) {
                    559:   putchar(0xf8 | (0x3 & (c >> 6)));
                    560:   putchar(0xf0 | (0x7 & (c >> 3)));
                    561:   putchar(0xf0 | (0x7 & c));
                    562: }
                    563: static void myEncoderS(unsigned char *s) {
                    564:   int i,n;
                    565:   n = strlen(s);
                    566:   for (i = 0; i<n ; i++) myEncoder(s[i]);
                    567: }
                    568: static void myEncoderSn(unsigned char *s,int n) {
                    569:   int i;
                    570:   for (i = 0; i<n ; i++) myEncoder(s[i]);
                    571: }
                    572: static void outputStringToTunnel0(int channel, unsigned char *s, int n,int view) {
                    573:   unsigned char ts[128];
                    574:   int i;
                    575:   if (view == GENERIC) {
                    576:     printf("{%d<%d ",channel,n+1);
                    577:     for (i=0; i<n; i++) putchar(s[i]);
                    578:     printf("%c>}",0);
                    579:   }else if (view == V_CFEP) {
                    580:     sprintf(ts,"{%d<%d ",channel,n+1);
                    581:     myEncoderS(ts);
                    582:     myEncoderSn(s,n); myEncoder(0);
                    583:     myEncoderS(">}");
                    584:   }
                    585:   fflush(stdout);
                    586: }
1.28      takayama  587: #define LINE_FEED 0xc   /* ^L */
1.27      takayama  588: static void outputStringToTunnel(int channel, unsigned char *s, int view) {
                    589:   int start, i;
                    590:   start = i = 0;
                    591:   while (s[i] != 0) {
1.28      takayama  592:        if (s[i] == LINE_FEED) {
                    593:          outputStringToTunnel0(channel,&(s[start]),i-start,view);
1.27      takayama  594:          start = i+1;
                    595:        }
                    596:        i++;
                    597:   }
                    598: }
                    599:
1.2       takayama  600:
                    601:
                    602:

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