home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / files / language / xlispst / ststuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-09-20  |  5.1 KB  |  273 lines

  1. /* ststuff.c - atari-st specific routines */
  2.  
  3. #include <osbind.h>
  4. #include "xlisp.h"
  5.  
  6. #define LBSIZE 200
  7.  
  8. /* set MWC memory parameters */
  9. long _stksize = 16384;    /* stack must be 16K */
  10.  
  11. /* external variables */
  12. extern LVAL s_unbound,true;
  13. extern int errno;
  14. extern FILE *tfp;
  15. extern char buf[];
  16.  
  17. /* line buffer variables */
  18. static char lbuf[LBSIZE];
  19. static int  lpos[LBSIZE];
  20. static int lindex;
  21. static int lcount;
  22. static int lposition;
  23.  
  24. /* osinit - initialize */
  25. osinit(banner)
  26.   char *banner;
  27. {
  28.     printf("\033v%s\n",banner);
  29.     lposition = 0;
  30.     lindex = 0;
  31.     lcount = 0;
  32. }
  33.  
  34. /* osfinish - clean up before a return to the operating system */
  35. osfinish()
  36. {
  37. }
  38.  
  39. /* oserror - print an error message */
  40. oserror(msg)
  41.   char *msg;
  42. {
  43.     printf("error: %s\n",msg);
  44. }
  45.  
  46. /* osrand - return a random number between 0 and n-1 */
  47. int osrand(n)
  48.   int n;
  49. {
  50.     return (rand() % n);
  51. }
  52.  
  53. /* osaopen - open an ascii file */
  54. FILE *osaopen(name,mode)
  55.   char *name,*mode;
  56. {
  57.     return (fopen(name,mode));
  58. }
  59.  
  60. /* osbopen - open a binary file */
  61. FILE *osbopen(name,mode)
  62.   char *name,*mode;
  63. {
  64.     char rmode[5];
  65.     strcpy(rmode,mode); strcat(rmode,"b");
  66.     return (fopen(name,rmode));
  67. }
  68.  
  69. /* osclose - close a file */
  70. int osclose(fp)
  71.   FILE *fp;
  72. {
  73.     return (fclose(fp));
  74. }
  75.  
  76. /* osagetc - get a character from an ascii file */
  77. int osagetc(fp)
  78.   FILE *fp;
  79. {
  80.     return (getc(fp));
  81. }
  82.  
  83. /* osaputc - put a character to an ascii file */
  84. int osaputc(ch,fp)
  85.   int ch; FILE *fp;
  86. {
  87.     return (putc(ch,fp));
  88. }
  89.  
  90. /* osbgetc - get a character from a binary file */
  91. int osbgetc(fp)
  92.   FILE *fp;
  93. {
  94.     return (getc(fp));
  95. }
  96.  
  97. /* osbputc - put a character to a binary file */
  98. int osbputc(ch,fp)
  99.   int ch; FILE *fp;
  100. {
  101.     return (putc(ch,fp));
  102. }
  103.  
  104. /* ostgetc - get a character from the terminal */
  105. int ostgetc()
  106. {
  107.     int ch;
  108.  
  109.     /* check for a buffered character */
  110.     if (lcount--)
  111.     return (lbuf[lindex++]);
  112.  
  113.     /* get an input line */
  114.     for (lcount = 0; ; )
  115.     switch (ch = xgetc()) {
  116.     case '\r':
  117.         lbuf[lcount++] = '\n';
  118.         xputc('\r'); xputc('\n'); lposition = 0;
  119.         if (tfp)
  120.             for (lindex = 0; lindex < lcount; ++lindex)
  121.             osaputc(lbuf[lindex],tfp);
  122.         lindex = 0; lcount--;
  123.         return (lbuf[lindex++]);
  124.     case '\010':
  125.     case '\177':
  126.         if (lcount) {
  127.             lcount--;
  128.             while (lposition > lpos[lcount]) {
  129.             xputc('\010'); xputc(' '); xputc('\010');
  130.             lposition--;
  131.             }
  132.         }
  133.         break;
  134.     case '\032':
  135.         xflush();
  136.         return (EOF);
  137.     default:
  138.         if (ch == '\t' || (ch >= 0x20 && ch < 0x7F)) {
  139.             lbuf[lcount] = ch;
  140.             lpos[lcount] = lposition;
  141.             if (ch == '\t')
  142.             do {
  143.                 xputc(' ');
  144.             } while (++lposition & 7);
  145.             else {
  146.             xputc(ch); lposition++;
  147.             }
  148.             lcount++;
  149.         }
  150.         else {
  151.             xflush();
  152.             switch (ch) {
  153.             case '\003':    xltoplevel();    /* control-c */
  154.             case '\007':    xlcleanup();    /* control-g */
  155.             case '\020':    xlcontinue();    /* control-p */
  156.             case '\032':    return (EOF);    /* control-z */
  157.             default:        return (ch);
  158.             }
  159.         }
  160.     }
  161. }
  162.  
  163. /* ostputc - put a character to the terminal */
  164. ostputc(ch)
  165.   int ch;
  166. {
  167.     /* check for control characters */
  168.     oscheck();
  169.  
  170.     /* output the character */
  171.     if (ch == '\n') {
  172.     xputc('\r'); xputc('\n');
  173.     lposition = 0;
  174.     }
  175.     else {
  176.     xputc(ch);
  177.     lposition++;
  178.    }
  179.  
  180.    /* output the character to the transcript file */
  181.    if (tfp)
  182.     osaputc(ch,tfp);
  183. }
  184.  
  185. /* oscheck - check for control characters during execution */
  186. oscheck()
  187. {
  188.     int ch;
  189.     if (ch = xcheck())
  190.     switch (ch) {
  191.     case '\002':    xflush(); xlbreak("BREAK",s_unbound); break;
  192.     case '\003':    xflush(); xltoplevel(); break;
  193.     }
  194. }
  195.  
  196. /* osflush - flush the input line buffer */
  197. osflush()
  198. {
  199.     lindex = lcount = 0;
  200. }
  201.  
  202. /* xflush - flush the input line buffer */
  203. static xflush()
  204. {
  205.     ostputc('\n');
  206.     osflush();
  207. }
  208.  
  209. /* xgetc - get a character from the terminal without echo */
  210. static int xgetc()
  211. {
  212.     int ch;
  213.     while ((ch = Crawio(0xFF)) == 0)
  214.     ;
  215.     return (ch & 0xFF);
  216. }
  217.  
  218. /* xputc - put a character to the terminal */
  219. static xputc(ch)
  220.   int ch;
  221. {
  222.     Crawio(ch);
  223. }
  224.  
  225. /* xcheck - check for a character */
  226. static int xcheck()
  227. {
  228.     return (Crawio(0xFF));
  229. }
  230.  
  231. /* file name extension table */
  232. char *ext[] = { ".prg",".tos",".ttp",NULL };
  233.  
  234. /* xsystem - the built-in function 'system' */
  235. LVAL xsystem()
  236. {
  237.     char *str,*p,cmd[100];
  238.     int cmdlen,sts,i;
  239.  
  240.     /* get the command string */
  241.     str = getstring(xlgastring());
  242.     xllastarg();
  243.  
  244.     /* get the command name */
  245.     for (p = cmd, cmdlen = 0; *str && !isspace(*str); ++cmdlen)
  246.     *p++ = *str++;
  247.     *p = '\0';
  248.  
  249.     /* skip spaces between the command name and the arguments */
  250.     while (*str && isspace(*str))
  251.     ++str;
  252.  
  253.     /* make a counted ascii argument list */
  254.     for (p = &buf[1], buf[0] = '\0'; *str; ++buf[0])
  255.     *p++ = *str++;
  256.     *p = '\0';
  257.  
  258.     /* try each extension */
  259.     for (i = 0; ext[i]; ++i) {
  260.     strcpy(&cmd[cmdlen],ext[i]);
  261.     if ((sts = Pexec(0,cmd,buf,"")) != -33)
  262.         break;
  263.     }
  264.  
  265.     /* return the completion status */
  266.     return (cvfixnum((FIXTYPE)sts));
  267. }
  268.  
  269. /* ossymbols - lookup important symbols */
  270. ossymbols()
  271. {
  272. }
  273.