/****************************************************************************** * MODULE : tm_axiom.c * DESCRIPTION: Glue between TeXmacs and Axiom * COPYRIGHT : (C) 1999 Andrey Grozin ******************************************************************************* * This software falls under the GNU general public license and comes WITHOUT * ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details. * If you don't have this file, write to the Free Software Foundation, Inc., * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ******************************************************************************/ #include #include #include #include #define NORMAL 0 #define LONG 1 #define END 2 #define PROMPT 3 #define MATH 4 #define TYPE 5 #define LEN 256 /* #define LOG "/tmp/tm_axiom.log" */ char buf[LEN]; char mathbuf[4096]; int len,code,writing=0,wait_type=0,mmode=0; /* was writing=1 */ char prompt[]="-> "; char math[]="$$\n"; char Type[]="Type: "; FILE *axin,*axout; #ifdef LOG FILE *log; int details=0; void lline(void) { switch (code) { case NORMAL: fputs("NORMAL",log); break; case LONG: fputs("LONG ",log); break; case END: fputs("END ",log); break; case PROMPT: fputs("PROMPT",log); break; case MATH: fputs("MATH ",log); break; case TYPE: fputs("TYPE ",log); break; } fprintf(log," %3d: ",len); fputs(buf,log); if ((code==PROMPT)||(code==MATH)) fputs("\n",log); fflush(log); } #endif int ch(void) { char c; while (1) { c=getc(axout); #ifdef LOG if (details) { fprintf(log,"%02x",c); if (c>=' ') fprintf(log," [%c]",c); fprintf(log,"\n"); fflush(log); } #endif if (c!='\r') return c; } } void tail(void) { int c; while (1) { c=ch(); if (c==EOF) { code=END; break; } else if (c=='\r') { c=ch(); if (c==EOF) { code=END; break; } else if (c=='\n') { if (writing) putchar('\n'); break; } else if (writing) putchar(c); } else if (writing) putchar(c); } } void iline(void) { int i=0,j=0,k,c; while (1) { c=ch(); if (c==prompt[j]) if (j==2) { code=PROMPT; break; } else j++; else { for (k=0;kLEN-4) { code=LONG; break; } else if (c==EOF) { code=END; break; } else if (c=='\n') { buf[i++]='\n'; code=NORMAL; break; } else buf[i++]=c; } } buf[i]='\0'; len=i; if (len==78) if (buf[77]=='\n') { j=1; for (k=0;k<76;k++) if (buf[k]!='-') { j=0; break; } if (j) code=TYPE; } #ifdef LOG lline(); #endif if (code==PROMPT) return; if (writing) fputs(buf,stdout); if (code==LONG) tail(); if (code==END) { fputs("\n\2latex:\\red Unexpected end\\black5\5",stdout); exit(1); } if (code==LONG) code=NORMAL; } void line(void) { int i=0,j,k,c; char *s; code=NORMAL; c=ch(); if (c==EOF) code=END; else if (c=='-') { j=1; while (1) { c=ch(); if (c==prompt[j]) if (j==2) { code=PROMPT; break; } else j++; else { for (k=0;kLEN-2) { code=LONG; break; } else if (c=='\n') break; c=ch(); if (c==EOF) { code=END; break; } else buf[i++]=c; } buf[i]='\0'; len=i; #ifdef LOG lline(); #endif if (/*wait_type && */(code==NORMAL)) { if (len==1) return; wait_type=0; if (len==78) { for (s=buf,k=0;k