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

Diff for /OpenXM/src/kxx/ox_texmacs.c between version 1.2 and 1.3

version 1.2, 2004/02/29 08:19:54 version 1.3, 2004/02/29 13:02:44
Line 1 
Line 1 
 /* $OpenXM: OpenXM/src/kxx/ox_texmacs.c,v 1.1 2004/02/29 03:00:37 takayama Exp $ */  /* $OpenXM: OpenXM/src/kxx/ox_texmacs.c,v 1.2 2004/02/29 08:19:54 takayama Exp $ */
   
 #include <stdio.h>  #include <stdio.h>
 #include <setjmp.h>  #include <setjmp.h>
Line 16 
Line 16 
 #define LONGJMP(env,p)  longjmp(env,p)  #define LONGJMP(env,p)  longjmp(env,p)
 #endif  #endif
   
 /* #define DEBUG */  /*
   #define DEBUG
   */
   #define DEBUG2
   
 #ifdef DEBUG  #ifdef DEBUG
 #define DATA_BEGIN_V  "<S type=verbatim>"     /* "\002verbatim:" */  #define DATA_BEGIN_V  "<S type=verbatim>"     /* "\002verbatim:" */
 #define DATA_BEGIN_L  "<S type=latex>"        /* "\002latex:" */  #define DATA_BEGIN_L  "<S type=latex>"        /* "\002latex:" */
Line 36 
Line 40 
   
 extern int Quiet;  extern int Quiet;
 extern JMP_BUF EnvOfStackMachine;  extern JMP_BUF EnvOfStackMachine;
 int Format=0;  int Format=1;  /* 1 : latex mode */
   int OutputLimit_for_TeXmacs = (1024*10);
   
 void ctrlC();  void ctrlC();
 struct object KpoString(char *s);  struct object KpoString(char *s);
Line 51  static void printCopyright(char *s);
Line 56  static void printCopyright(char *s);
 /* tail -f /tmp/debug-texmacs.txt  /* tail -f /tmp/debug-texmacs.txt
    Debug output to understand the timing problem of pipe interface.     Debug output to understand the timing problem of pipe interface.
 */  */
 FILE *dfp;  FILE *Dfp;
   
 main() {  main() {
   char *s;    char *s;
   char *r;    char *r;
   char *sys;    char *sys;
   struct object ob;    struct object ob;
     int irt=0;
   
   dfp = fopen("/tmp/debug-texmacs.txt","w");  #ifdef DEBUG2
     Dfp = fopen("/tmp/debug-texmacs.txt","w");
   #endif
   
   /* Set consts */    /* Set consts */
   sys = "asir> ";    sys = "asir> ";
Line 68  main() {
Line 76  main() {
   /* Initialize kanlib (gc is also initialized) */    /* Initialize kanlib (gc is also initialized) */
   KSstart();    KSstart();
   
     /* Main loop */
     printf("%s",DATA_BEGIN_V);
     printCopyright("");
   
   /* Load ox engine here */    /* Load ox engine here */
   /* engine id should be set to ox.engine */    /* engine id should be set to ox.engine */
   KSexecuteString(" [(parse) (ox.sm1) pushfile] extension ");    KSexecuteString(" [(parse) (ox.sm1) pushfile] extension ");
Line 76  main() {
Line 88  main() {
   if (signal(SIGINT,SIG_IGN) != SIG_IGN) {    if (signal(SIGINT,SIG_IGN) != SIG_IGN) {
         signal(SIGINT,ctrlC);          signal(SIGINT,ctrlC);
   }    }
   /* Main loop */  
   printCopyright("");    irt = 0;
   while(1) {    while(1) {
         /* printp(sys);  no prompt */          /* printp(sys);  no prompt */
         if (SETJMP(EnvOfStackMachine)) {          if (SETJMP(EnvOfStackMachine)) {
Line 86  main() {
Line 98  main() {
           if (signal(SIGINT,SIG_IGN) != SIG_IGN) {            if (signal(SIGINT,SIG_IGN) != SIG_IGN) {
                 signal(SIGINT,ctrlC);                  signal(SIGINT,ctrlC);
           }            }
             irt = 1;
           continue;            continue;
         } else {  }          } else {  }
           if (!irt) {
             printf("%s",DATA_END); fflush(stdout);
           }
           irt = 0;
         s=readString(stdin, "if (1) { ", " ; }else{ };"); /* see test data */          s=readString(stdin, "if (1) { ", " ; }else{ };"); /* see test data */
         if (s == NULL) break;          if (s == NULL) break;
           printf("%s",DATA_BEGIN_V);
     KSexecuteString(" ox.engine ");      KSexecuteString(" ox.engine ");
     ob = KpoString(s);      ob = KpoString(s);
         KSpush(ob);          KSpush(ob);
Line 98  main() {
Line 116  main() {
     /* Get the result in string. */      /* Get the result in string. */
         if (Format == 1) {          if (Format == 1) {
           /* translate to latex form */            /* translate to latex form */
         KSexecuteString(" ox.engine 1 oxpushcmo ox.engine (print_tex_form) oxexec  ");
             KSexecuteString(" ox.engine oxpopstring ");
             r = KSpopString();
             if (strlen(r) < OutputLimit_for_TeXmacs) printl(r);
             else printv("Output is too large.\n");
         }else{          }else{
           KSexecuteString(" ox.engine oxpopstring ");            KSexecuteString(" ox.engine oxpopstring ");
           r = KSpopString();            r = KSpopString();
           printv(r);            if (strlen(r) < OutputLimit_for_TeXmacs) printv(r);
             else printv("Output is too large.\n");
         }          }
   }    }
 }  }
Line 125  static char *readString(FILE *fp, char *prolog, char *
Line 149  static char *readString(FILE *fp, char *prolog, char *
   int c;    int c;
   char *tmp;    char *tmp;
   int i;    int i;
   int m;    int m;
     int start;
   if (limit == 0) {    if (limit == 0) {
         limit = 1024;          limit = 1024;
         s = (char *)sGC_malloc(limit);          s = (char *)sGC_malloc(limit);
Line 139  static char *readString(FILE *fp, char *prolog, char *
Line 164  static char *readString(FILE *fp, char *prolog, char *
         s[n++] = prolog[i];  s[n] = 0;          s[n++] = prolog[i];  s[n] = 0;
     INC_BUF ;      INC_BUF ;
   }    }
     start = n;
   while ((c = fgetc(fp)) != EOF) {    while ((c = fgetc(fp)) != EOF) {
         fprintf(dfp,"[%x] ",c); fflush(dfp);  #ifdef DEBUG2
           fprintf(Dfp,"[%x] ",c); fflush(Dfp);
   #endif
         if (c == END_OF_INPUT) {          if (c == END_OF_INPUT) {
             if (oxSocketSelect0(0,1)) {
                   /* If there remains data in the stream,
                      read the remaining data. */
                   if (c == '\n') c=' ';
                   s[n++] = c; s[n] = 0;  m++;
                   INC_BUF ;
                   continue;
             }
           break;            break;
         }          }
         if (c == '\n') c=' ';          if (c == '\n') c=' ';
         s[n++] = c; s[n] = 0;  m++;          s[n++] = c; s[n] = 0;  m++;
     INC_BUF ;      INC_BUF ;
   }    }
   if (m == 0) return (char *) NULL;    if (strcmp(&(s[start]),"quit;") == 0) {
           printv("Terminated the process ox_texmacs.\n");
           exit(0);
     }
   for (i=0; i < strlen(epilog); i++) {    for (i=0; i < strlen(epilog); i++) {
         s[n++] = epilog[i];  s[n] = 0;          s[n++] = epilog[i];  s[n] = 0;
     INC_BUF ;      INC_BUF ;
Line 161  static void printv(char *s) {
Line 200  static void printv(char *s) {
   printf("%s",DATA_BEGIN_V);    printf("%s",DATA_BEGIN_V);
   printf("%s",s);    printf("%s",s);
   printf("%s",DATA_END);    printf("%s",DATA_END);
   fprintf(dfp,"<%s>",s); fflush(dfp);  #ifdef DEBUG2
   /* for debug "hello;    fprintf(Dfp,"<%s>",s); fflush(Dfp);
   for (i=0; i<strlen(s); i++) {  #endif
         printf("%x ",s[i]);  
   }  
   printf("\n");  
   */  
   
   fflush(NULL);    fflush(NULL);
 }  }
 static void printl(char *s) {  static void printl(char *s) {
Line 184  static void printp(char *s) {
Line 218  static void printp(char *s) {
   fflush(NULL);    fflush(NULL);
 }  }
 static void printCopyright(char *s) {  static void printCopyright(char *s) {
   printf("%s",DATA_BEGIN_P);    printf("%s",DATA_BEGIN_V);
   printf("OpenXM engine (ox engine) interface for TeXmacs\n2004 (C) openxm.org\n");    printf("OpenXM engine (ox engine) interface for TeXmacs\n2004 (C) openxm.org\n");
   printf("%s",s);    printf("%s",s);
   printf("%s",DATA_END);    printf("%s",DATA_END);

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

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