Annotation of OpenXM/src/kxx/ox_texmacs.c, Revision 1.1
1.1 ! takayama 1: /* $OpenXM$ */
! 2:
! 3: #include <stdio.h>
! 4: #include <setjmp.h>
! 5: #include <signal.h>
! 6: #include "ox_kan.h"
! 7: #include "serversm.h"
! 8:
! 9: #if defined(__CYGWIN__)
! 10: #define JMP_BUF sigjmp_buf
! 11: #define SETJMP(env) sigsetjmp(env,1)
! 12: #define LONGJMP(env,p) siglongjmp(env,p)
! 13: #else
! 14: #define JMP_BUF jmp_buf
! 15: #define SETJMP(env) setjmp(env)
! 16: #define LONGJMP(env,p) longjmp(env,p)
! 17: #endif
! 18:
! 19: #define DATA_BEGIN_V "<S type=verbatim>" /* "\0x2verbatim:" */
! 20: #define DATA_BEGIN_L "<S type=latex>" /* "\0x2latex:" */
! 21: #define DATA_BEGIN_P "<S type=prompt>" /* "\0x2prompt:" */
! 22: #define DATA_END "</S>" /* "\0x5" */
! 23:
! 24: extern int Quiet;
! 25: extern JMP_BUF EnvOfStackMachine;
! 26: int Format=0;
! 27:
! 28: void ctrlC();
! 29: struct object KpoString(char *s);
! 30: char *KSpopString(void);
! 31:
! 32: static char *readString(FILE *fp);
! 33: static void printv(char *s);
! 34: static void printl(char *s);
! 35: static void printp(char *s);
! 36:
! 37: main() {
! 38: char *s;
! 39: char *r;
! 40: char *sys;
! 41: struct object ob;
! 42:
! 43: /* Set consts */
! 44: sys = "asir> ";
! 45: Quiet = 1;
! 46:
! 47: /* Initialize kanlib (gc is also initialized) */
! 48: KSstart();
! 49:
! 50: /* Load ox engine here */
! 51: /* engine id should be set to ox.engine */
! 52: KSexecuteString(" [(parse) (ox.sm1) pushfile] extension ");
! 53: KSexecuteString(" asirconnectr /ox.engine oxasir.ccc def ");
! 54:
! 55: if (signal(SIGINT,SIG_IGN) != SIG_IGN) {
! 56: signal(SIGINT,ctrlC);
! 57: }
! 58: /* Main loop */
! 59: while(1) {
! 60: printp(sys);
! 61: if (SETJMP(EnvOfStackMachine)) {
! 62: printv("Syntax error or an interruption\n");
! 63: KSexecuteString(" ctrlC-hook "); /* Execute User Defined functions. */
! 64: if (signal(SIGINT,SIG_IGN) != SIG_IGN) {
! 65: signal(SIGINT,ctrlC);
! 66: }
! 67: continue;
! 68: } else { }
! 69: s=readString(stdin);
! 70: if (s[0] == 0 || (strcmp(s,"quit;")==0)) break;
! 71: KSexecuteString(" ox.engine ");
! 72: ob = KpoString(s);
! 73: KSpush(ob);
! 74: KSexecuteString(" oxsubmit ");
! 75:
! 76: /* Get the result in string. */
! 77: if (Format == 1) {
! 78: /* translate to latex form */
! 79: }else{
! 80: KSexecuteString(" ox.engine oxpopstring ");
! 81: r = KSpopString();
! 82: printv(r);
! 83: }
! 84: }
! 85: }
! 86:
! 87:
! 88: #define SB_SIZE 1024
! 89: static char *readString(FILE *fp) {
! 90: int n = 0;
! 91: static int limit = 0;
! 92: static char *s;
! 93: int c;
! 94: char *tmp;
! 95: if (limit == 0) {
! 96: limit = 1024;
! 97: s = (char *)sGC_malloc(limit);
! 98: if (s == NULL) {
! 99: fprintf(stderr,"No more memory.\n");
! 100: exit(10);
! 101: }
! 102: }
! 103: s[0] = 0; n = 0;
! 104: while ((c = fgetc(fp)) != EOF) {
! 105: if (c == '\n') {
! 106: return s;
! 107: }
! 108: s[n++] = c; s[n] = 0;
! 109: if (n >= limit-3) {
! 110: tmp = s;
! 111: limit *= 2;
! 112: s = (char *) sGC_malloc(limit);
! 113: if (s == NULL) {
! 114: fprintf(stderr,"No more memory.\n");
! 115: exit(10);
! 116: }
! 117: strcpy(s,tmp);
! 118: }
! 119: }
! 120: return s;
! 121: }
! 122:
! 123: static void printv(char *s) {
! 124: int i;
! 125: printf("%s",DATA_BEGIN_V);
! 126: printf("%s",s);
! 127: printf("%s",DATA_END);
! 128: /* for debug "hello;
! 129: for (i=0; i<strlen(s); i++) {
! 130: printf("%x ",s[i]);
! 131: }
! 132: printf("\n");
! 133: */
! 134:
! 135: fflush(NULL);
! 136: }
! 137: static void printl(char *s) {
! 138: printf("%s",DATA_BEGIN_L);
! 139: printf("%s",s);
! 140: printf("%s",DATA_END);
! 141: fflush(NULL);
! 142: }
! 143: static void printp(char *s) {
! 144: printf("%s",DATA_BEGIN_P);
! 145: printf("%s",s);
! 146: printf("%s",DATA_END);
! 147: fflush(NULL);
! 148: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>