home *** CD-ROM | disk | FTP | other *** search
/ ftp.barnyard.co.uk / 2015.02.ftp.barnyard.co.uk.tar / ftp.barnyard.co.uk / cpm / walnut-creek-CDROM / CPM / LANGUAGS / XLISP / XLISP11.ARK / XLIO.C < prev    next >
Text File  |  1986-10-12  |  2KB  |  101 lines

  1. /* xlio - xlisp i/o routines */
  2.  
  3. #ifdef AZTEC
  4. #include "a:stdio.h"
  5. #else
  6. #include <stdio.h>
  7. #endif
  8.  
  9. #include "xlisp.h"
  10.  
  11. /* global variables */
  12. int (*xlgetc)();
  13. int xlpvals;
  14. int xlplevel;
  15.  
  16. /* local variables */
  17. static int prompt;
  18. static FILE *ifp;
  19.  
  20. /* tgetc - get a character from the terminal */
  21. static int tgetc()
  22. {
  23.     int ch;
  24.  
  25.     /* prompt if necessary */
  26.     if (prompt) {
  27.     if (xlplevel > 0)
  28.         printf("%d> ",xlplevel);
  29.     else
  30.         printf("> ");
  31.     prompt = FALSE;
  32.     }
  33.  
  34.     /* get the character */
  35.     if ((ch = getc(stdin)) == '\n')
  36.     prompt = TRUE;
  37.  
  38.     /* return the character */
  39.     return (ch);
  40. }
  41.  
  42. /* xltin - setup terminal input */
  43. int xltin(flag)
  44.   int flag;
  45. {
  46.     /* flush line if flag is set */
  47.     if (flag & !prompt)
  48.     while (tgetc() != '\n')
  49.         ;
  50.  
  51.     /* initialize */
  52.     prompt = TRUE;
  53.     xlplevel = 0;
  54.     xlgetc = tgetc;
  55.     xlpvals = TRUE;
  56. }
  57.  
  58. /* fgetcx - get a character from a file */
  59. static int fgetcx()
  60. {
  61.     int ch;
  62.  
  63.     /* get a character */
  64.     if ((ch = getc(ifp)) <= 0) {
  65.     xlgetc = tgetc;
  66.     xlpvals = TRUE;
  67.     return (tgetc());
  68.     }
  69.  
  70.     /* return it */
  71.     return (ch);
  72. }
  73.  
  74. /* xlfin - setup file input */
  75. xlfin(str)
  76.   char *str;
  77. {
  78. #ifdef DEFEXT
  79.     char fname[100];
  80.  
  81.     /* create the file name */
  82.     strcpy(fname,str);
  83.  
  84.     /* check for extension */
  85.     if (strchr(fname,'.') == 0)
  86.     strcat(fname,".lsp");
  87. #else
  88. #define fname str
  89. #endif
  90.  
  91.     /* open the input file */
  92.     if ((ifp = fopen(fname,"r")) == NULL) {
  93.     printf("can't open \"%s\" for input\n",fname);
  94.     return;
  95.     }
  96.  
  97.     /* setup input from the file */
  98.     xlgetc = fgetcx;
  99.     xlpvals = FALSE;
  100. }
  101.