home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / alib / d3xx / d386 / xlispstat.lha / XLispStat / src3.lzh / UNIX / X11BSDstuff.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-07-30  |  4.3 KB  |  262 lines

  1. /* X11BSDstuff.c - X11 BSD interface routines for xlisp */
  2. /* XLISP-STAT 2.1 Copyright (c) 1990, by Luke Tierney                  */
  3. /* Additions to Xlisp 2.1, Copyright (c) 1989 by David Michael Betz    */
  4. /* You may give out copies of this software; for conditions see the    */
  5. /* file COPYING included with this distribution.                       */
  6.  
  7. # include <signal.h>
  8. # include <sys/ioctl.h>
  9. # include <sys/types.h>
  10. # include <sys/times.h>
  11. # include "xlisp.h"
  12. # include "version.h"
  13.  
  14. /* externals */
  15. extern FILE *tfp;
  16. extern long time_stamp;
  17.  
  18. /* symbols */
  19. LVAL s_true, s_ivalue, s_sublist, s_select, s_elt, s_vector;
  20. LVAL s_list, s_ielement, s_icontents, s_displacedto, s_arrayident;
  21. LVAL s_subarray, a_float, s_pi;
  22.  
  23. /* static variables to protect gc from interrupt */
  24. static int in_gc = FALSE, gc_interrupt = FALSE;
  25.  
  26. osinit(name)
  27.   char *name;
  28. {
  29.   extern intercatch(), fpecatch();
  30.  
  31.   if (signal(SIGINT, SIG_IGN) != SIG_IGN)
  32.     signal(SIGINT, intercatch);
  33.   signal(SIGFPE, fpecatch);
  34.   printf(name);
  35.   printf("\nXLISP-STAT version %s, Copyright (c) 1989, by Luke Tierney.\n",
  36.      XLISPSTAT_VERSION);
  37.   printf("Several files will be loaded; this may take a few minutes.\n\n\n");
  38. }
  39.  
  40. osfinish()
  41. {
  42.   StX11Finish();
  43. }
  44.  
  45. osreset()
  46. {
  47.   if (StHasWindows()) {
  48.     StGWResetBuffer();
  49.     StX11DialogReset();
  50.     StX11ReleaseButton();
  51.   }
  52. }
  53.  
  54. oserror(msg)
  55. {
  56.     char line[100],*p;
  57.     sprintf(line,"error: %s\n",msg);
  58.     for (p = line; *p != '\0'; ++p)
  59.     ostputc(*p);
  60. }
  61.  
  62. FILE *osaopen(name,mode)
  63.   char *name,*mode;
  64. {
  65.     return (fopen(name,mode));
  66. }
  67.  
  68. FILE *osbopen(name,mode)
  69.   char *name,*mode;
  70. {
  71.     char nmode[4];
  72.     strcpy(nmode,mode); strcat(nmode,"b");
  73.     return (fopen(name,nmode));
  74. }
  75.  
  76. int osclose(fp)
  77.   FILE *fp;
  78. {
  79.     return (fclose(fp));
  80. }
  81.  
  82. int osagetc(fp)
  83.   FILE *fp;
  84. {
  85.     return (getc(fp));
  86. }
  87.  
  88. int osbgetc(fp)
  89.   FILE *fp;
  90. {
  91.     return (getc(fp));
  92. }
  93.  
  94. int osaputc(ch,fp)
  95.   int ch; FILE *fp;
  96. {
  97.     return (putc(ch,fp));
  98. }
  99.  
  100. int osbputc(ch,fp)
  101.   int ch; FILE *fp;
  102. {
  103.     return (putc(ch,fp));
  104. }
  105.  
  106. int ostgetc()
  107. {
  108.   int ch;
  109.   ch = x11_get_char();
  110.   if (tfp) osaputc(ch,tfp);
  111.   return(ch);
  112. }
  113.  
  114. int ostputc(ch)
  115.   int ch;
  116. {
  117.     putchar(ch);
  118.     if (tfp)
  119.     osaputc(ch,tfp);
  120.     return (1);
  121. }
  122.  
  123. osflush()
  124. {
  125. }
  126.  
  127. oscheck()
  128. {
  129. }
  130.  
  131. ossymbols()
  132. {
  133.   statsymbols();
  134. }
  135.  
  136. osfinit()
  137. {
  138.   statfinit();
  139. }
  140.  
  141. intercatch()
  142. {
  143.   signal(SIGINT, intercatch);
  144.   if (in_gc) gc_interrupt = TRUE;
  145.   else xltoplevel();
  146. }
  147.  
  148. fpecatch()
  149. {
  150.   signal(SIGFPE, fpecatch);
  151.   xlfail("floating point error");
  152. }
  153.  
  154. max(x, y)
  155.      int x, y;
  156. {
  157.   return((x > y) ? x : y);
  158. }
  159.  
  160. min(x, y)
  161.      int x, y;
  162. {
  163.   return((x < y) ? x : y);
  164. }
  165.  
  166. set_gc_cursor(on) 
  167.      int on;
  168. {
  169.   if (on) in_gc = TRUE;
  170.   else {
  171.     if (gc_interrupt) {
  172.       gc_interrupt = FALSE;
  173.       in_gc = FALSE;
  174.       xltoplevel();
  175.     }
  176.     else in_gc = FALSE;
  177.   }
  178. }
  179.  
  180. SysBeep(n)
  181.      int n;
  182. {
  183.   n = n / 10 - 1;
  184.   do {
  185.     printf("\007");
  186.   } while (n-- > 0);
  187.   fflush(stdout);
  188. }
  189.  
  190. #ifndef HZ
  191. #define HZ 60
  192. #endif
  193.  
  194. unsigned long ticks_per_second() { return((unsigned long) HZ); }
  195.  
  196. unsigned long run_tick_count()
  197. {
  198.   struct tms tm;
  199.  
  200.   times(&tm);
  201.   
  202.   return((unsigned long) tm.tms_utime + tm.tms_stime);
  203. }
  204.  
  205. unsigned long real_tick_count() 
  206. {
  207.   return((unsigned long) (60 * (time((unsigned long *) NULL) - time_stamp)));
  208. }
  209.  
  210. /* The following routines will have to be changed for non-BSD systems. At
  211.  * present they use a BSD-specific ioctl call as well as file structure
  212.  * information to determine when terminal input characters are available.
  213.  * While no characters are available events are processed. 
  214.  *
  215.  * An alternative polling system can be constructed using alarm or
  216.  * setitimer. The alarm aproach is used in the S X11 and NeWS drivers.
  217.  */
  218.  
  219. static x11_get_char()
  220. {
  221.   int ch;
  222.  
  223.   fflush(stdout);
  224.   do {
  225.     StPollEvent();
  226.   } while (! char_available());
  227.   ch =  getchar();
  228.   return(ch);
  229. }
  230.  
  231. static char_available()
  232. {
  233.   FILE *file = stdin;
  234.   int c = 0;
  235.   
  236.   if (file->_cnt > 0) return(TRUE);
  237.   ioctl(fileno(file), FIONREAD, &c);
  238.   if (c > 0) return(TRUE);
  239.   else return(StBlockForInput());
  240. }
  241.  
  242. /* 
  243.  * This routine is used to flush input to the tty during modal dialogs.
  244.  * The ioctl call seems to do the job on BDS systems but may not exist
  245.  * (in this form) on other systems. The ifdef is a hack to see if the
  246.  * call is available.
  247.  */
  248. StX11FlushStdin()
  249. {
  250. #ifdef TIOCFLUSH
  251.   int c = 0;
  252.   ioctl(fileno(stdin), TIOCFLUSH, &c);
  253. #else
  254.   fflush(stdin);
  255. #endif
  256. }
  257.  
  258. #undef getenv
  259. extern char *getenv();
  260.  
  261. char *getunixenv(s) { return(getenv(s)); }
  262.