[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.1 and 1.2

version 1.1, 2004/02/29 03:00:37 version 1.2, 2004/02/29 08:19:54
Line 1 
Line 1 
 /* $OpenXM$ */  /* $OpenXM: OpenXM/src/kxx/ox_texmacs.c,v 1.1 2004/02/29 03:00:37 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 DATA_BEGIN_V  "<S type=verbatim>"     /* "\0x2verbatim:" */  /* #define DEBUG */
 #define DATA_BEGIN_L  "<S type=latex>"        /* "\0x2latex:" */  #ifdef DEBUG
 #define DATA_BEGIN_P  "<S type=prompt>"        /* "\0x2prompt:" */  #define DATA_BEGIN_V  "<S type=verbatim>"     /* "\002verbatim:" */
 #define DATA_END      "</S>"    /* "\0x5" */  #define DATA_BEGIN_L  "<S type=latex>"        /* "\002latex:" */
   #define DATA_BEGIN_P  "<S type=prompt>"        /* "\002channel:prompt " */
   #define DATA_END      "</S>"    /* "\005" */
   #else
   #define DATA_BEGIN_V  "\002verbatim:"
   #define DATA_BEGIN_L  "\002latex:"
   #define DATA_BEGIN_P  "\002prompt:"
   #define DATA_END      "\005"
   #endif
   
   /*
   #define END_OF_INPUT  '#'
   */
   #define END_OF_INPUT '\n'
   
 extern int Quiet;  extern int Quiet;
 extern JMP_BUF EnvOfStackMachine;  extern JMP_BUF EnvOfStackMachine;
 int Format=0;  int Format=0;
Line 29  void ctrlC();
Line 42  void ctrlC();
 struct object KpoString(char *s);  struct object KpoString(char *s);
 char *KSpopString(void);  char *KSpopString(void);
   
 static char *readString(FILE *fp);  static char *readString(FILE *fp,char *prolog, char *eplog);
 static void printv(char *s);  static void printv(char *s);
 static void printl(char *s);  static void printl(char *s);
 static void printp(char *s);  static void printp(char *s);
   static void printCopyright(char *s);
   
   /* tail -f /tmp/debug-texmacs.txt
      Debug output to understand the timing problem of pipe interface.
   */
   FILE *dfp;
   
 main() {  main() {
   char *s;    char *s;
   char *r;    char *r;
   char *sys;    char *sys;
   struct object ob;    struct object ob;
   
     dfp = fopen("/tmp/debug-texmacs.txt","w");
   
   /* Set consts */    /* Set consts */
   sys = "asir> ";    sys = "asir> ";
   Quiet = 1;    Quiet = 1;
Line 56  main() {
Line 77  main() {
         signal(SIGINT,ctrlC);          signal(SIGINT,ctrlC);
   }    }
   /* Main loop */    /* Main loop */
     printCopyright("");
   while(1) {    while(1) {
         printp(sys);          /* printp(sys);  no prompt */
         if (SETJMP(EnvOfStackMachine)) {          if (SETJMP(EnvOfStackMachine)) {
           printv("Syntax error or an interruption\n");            printv("Syntax error or an interruption\n");
           KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */            KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */
Line 66  main() {
Line 88  main() {
           }            }
           continue;            continue;
         } else {  }          } else {  }
         s=readString(stdin);          s=readString(stdin, "if (1) { ", " ; }else{ };"); /* see test data */
         if (s[0] == 0 || (strcmp(s,"quit;")==0)) break;          if (s == NULL) break;
     KSexecuteString(" ox.engine ");      KSexecuteString(" ox.engine ");
     ob = KpoString(s);      ob = KpoString(s);
         KSpush(ob);          KSpush(ob);
Line 84  main() {
Line 106  main() {
   }    }
 }  }
   
   
 #define SB_SIZE 1024  #define SB_SIZE 1024
 static char *readString(FILE *fp) {  #define INC_BUF         if (n >= limit-3) { \
             tmp = s; \
             limit *= 2;  \
             s = (char *) sGC_malloc(limit); \
             if (s == NULL) { \
                   fprintf(stderr,"No more memory.\n"); \
                   exit(10); \
             } \
             strcpy(s,tmp); \
           }
   /*   */
   static char *readString(FILE *fp, char *prolog, char *epilog) {
   int n = 0;    int n = 0;
   static int limit = 0;    static int limit = 0;
   static char *s;    static char *s;
   int c;    int c;
   char *tmp;    char *tmp;
     int i;
     int m;
   if (limit == 0) {    if (limit == 0) {
         limit = 1024;          limit = 1024;
         s = (char *)sGC_malloc(limit);          s = (char *)sGC_malloc(limit);
Line 100  static char *readString(FILE *fp) {
Line 134  static char *readString(FILE *fp) {
           exit(10);            exit(10);
         }          }
   }    }
   s[0] = 0; n = 0;    s[0] = 0; n = 0; m = 0;
     for (i=0; i < strlen(prolog); i++) {
           s[n++] = prolog[i];  s[n] = 0;
       INC_BUF ;
     }
   while ((c = fgetc(fp)) != EOF) {    while ((c = fgetc(fp)) != EOF) {
         if (c == '\n') {          fprintf(dfp,"[%x] ",c); fflush(dfp);
           return s;          if (c == END_OF_INPUT) {
             break;
         }          }
         s[n++] = c; s[n] = 0;          if (c == '\n') c=' ';
         if (n >= limit-3) {          s[n++] = c; s[n] = 0;  m++;
           tmp = s;      INC_BUF ;
           limit *= 2;  
           s = (char *) sGC_malloc(limit);  
           if (s == NULL) {  
                 fprintf(stderr,"No more memory.\n");  
                 exit(10);  
           }  
           strcpy(s,tmp);  
         }  
   }    }
     if (m == 0) return (char *) NULL;
     for (i=0; i < strlen(epilog); i++) {
           s[n++] = epilog[i];  s[n] = 0;
       INC_BUF ;
     }
   return s;    return s;
 }  }
   
Line 125  static void printv(char *s) {
Line 161  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);
   /* for debug "hello;    /* for debug "hello;
   for (i=0; i<strlen(s); i++) {    for (i=0; i<strlen(s); i++) {
         printf("%x ",s[i]);          printf("%x ",s[i]);
Line 142  static void printl(char *s) {
Line 179  static void printl(char *s) {
 }  }
 static void printp(char *s) {  static void printp(char *s) {
   printf("%s",DATA_BEGIN_P);    printf("%s",DATA_BEGIN_P);
     printf("%s",DATA_END);
     printf("%s] ",s);
     fflush(NULL);
   }
   static void printCopyright(char *s) {
     printf("%s",DATA_BEGIN_P);
     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);
   fflush(NULL);    fflush(NULL);
 }  }
   
   /* test data
   
   1.  print("hello"); print("afo");
   
       1+2;
   
   2. def foo(N) { for (I=0; I<10; I++) {   --> error
   
      3+5;
   
   4.  print("hello"); shift+return print("afo");
   
   */
   
   
   

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

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