/* xlio - xlisp i/o routines */ #include #include "xlisp.h" /* global variables */ int (*xlgetc)(); int xlpvals; int xlplevel; int prompt; extern char xlprompt[32], xlpr2[32]; /* local variables */ static FILE *ifp; /* tgetc - get a character from the terminal */ static int tgetc() { int ch; /* prompt if necessary */ if (prompt) { if (xlplevel > 0) printf(xlpr2, xlplevel); else printf(xlprompt); prompt = FALSE; } /* get the character */ if ((ch = getchar()) == '\n') prompt = TRUE; /* return the character */ return (ch); } /* xltin - setup terminal input */ int xltin(flag) int flag; { /* flush line if flag is set */ if (flag & !prompt) while (tgetc() != '\n') ; /* initialize */ prompt = TRUE; xlplevel = 0; xlgetc = tgetc; xlpvals = TRUE; } /* fgetcx - get a character from a file */ static int fgetcx() { int ch; /* get a character */ if ((ch = getc(ifp)) <= 0) { xlgetc = tgetc; xlpvals = TRUE; return (tgetc()); } /* return it */ return (ch); } /* xlfin - setup file input */ xlfin(str) char *str; { #ifdef DEFEXT char fname[100]; /* create the file name */ strcpy(fname,str); /* check for extension */ if (strchr(fname,'.') == 0) strcat(fname,".lsp"); #else #define fname str #endif /* open the input file */ if ((ifp = fopen(fname,"r")) == NULL) { printf("can't open \"%s\" for input\n",fname); return; } /* setup input from the file */ xlgetc = fgetcx; xlpvals = FALSE; } /* kbin() - Just read one character already.. */ kbin() { return(getchar()); }