=================================================================== RCS file: /home/cvs/OpenXM/src/kxx/ox_texmacs.c,v retrieving revision 1.1 retrieving revision 1.2 diff -u -p -r1.1 -r1.2 --- OpenXM/src/kxx/ox_texmacs.c 2004/02/29 03:00:37 1.1 +++ OpenXM/src/kxx/ox_texmacs.c 2004/02/29 08:19:54 1.2 @@ -1,4 +1,4 @@ -/* $OpenXM$ */ +/* $OpenXM: OpenXM/src/kxx/ox_texmacs.c,v 1.1 2004/02/29 03:00:37 takayama Exp $ */ #include #include @@ -16,11 +16,24 @@ #define LONGJMP(env,p) longjmp(env,p) #endif -#define DATA_BEGIN_V "" /* "\0x2verbatim:" */ -#define DATA_BEGIN_L "" /* "\0x2latex:" */ -#define DATA_BEGIN_P "" /* "\0x2prompt:" */ -#define DATA_END "" /* "\0x5" */ +/* #define DEBUG */ +#ifdef DEBUG +#define DATA_BEGIN_V "" /* "\002verbatim:" */ +#define DATA_BEGIN_L "" /* "\002latex:" */ +#define DATA_BEGIN_P "" /* "\002channel:prompt " */ +#define DATA_END "" /* "\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 JMP_BUF EnvOfStackMachine; int Format=0; @@ -29,17 +42,25 @@ void ctrlC(); struct object KpoString(char *s); char *KSpopString(void); -static char *readString(FILE *fp); +static char *readString(FILE *fp,char *prolog, char *eplog); static void printv(char *s); static void printl(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() { char *s; char *r; char *sys; struct object ob; + dfp = fopen("/tmp/debug-texmacs.txt","w"); + /* Set consts */ sys = "asir> "; Quiet = 1; @@ -56,8 +77,9 @@ main() { signal(SIGINT,ctrlC); } /* Main loop */ + printCopyright(""); while(1) { - printp(sys); + /* printp(sys); no prompt */ if (SETJMP(EnvOfStackMachine)) { printv("Syntax error or an interruption\n"); KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */ @@ -66,8 +88,8 @@ main() { } continue; } else { } - s=readString(stdin); - if (s[0] == 0 || (strcmp(s,"quit;")==0)) break; + s=readString(stdin, "if (1) { ", " ; }else{ };"); /* see test data */ + if (s == NULL) break; KSexecuteString(" ox.engine "); ob = KpoString(s); KSpush(ob); @@ -84,14 +106,26 @@ main() { } } - #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; static int limit = 0; static char *s; int c; char *tmp; + int i; + int m; if (limit == 0) { limit = 1024; s = (char *)sGC_malloc(limit); @@ -100,23 +134,25 @@ static char *readString(FILE *fp) { 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) { - if (c == '\n') { - return s; + fprintf(dfp,"[%x] ",c); fflush(dfp); + if (c == END_OF_INPUT) { + break; } - s[n++] = c; s[n] = 0; - 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); - } + if (c == '\n') c=' '; + s[n++] = c; s[n] = 0; m++; + INC_BUF ; } + if (m == 0) return (char *) NULL; + for (i=0; i < strlen(epilog); i++) { + s[n++] = epilog[i]; s[n] = 0; + INC_BUF ; + } return s; } @@ -125,6 +161,7 @@ static void printv(char *s) { printf("%s",DATA_BEGIN_V); printf("%s",s); printf("%s",DATA_END); + fprintf(dfp,"<%s>",s); fflush(dfp); /* for debug "hello; for (i=0; i error + + 3+5; + +4. print("hello"); shift+return print("afo"); + +*/ + + +