home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / plbin.zip / pl / src / pl-os.h < prev    next >
C/C++ Source or Header  |  1993-02-23  |  8KB  |  298 lines

  1. /*  pl-os.h,v 1.10 1993/02/23 13:16:40 jan Exp
  2.  
  3.     Copyright (c) 1990 Jan Wielemaker. All rights reserved.
  4.     See ../LICENCE to find out about your rights.
  5.     jan@swi.psy.uva.nl
  6.  
  7.     Purpose: Describe your OS here
  8. */
  9.  
  10. #ifdef TIME_INCLUDE
  11. #include TIME_INCLUDE
  12. #else
  13. #include <sys/time.h>
  14. #endif
  15.  
  16. #if tos
  17. struct timeval
  18. { long tv_sec;
  19.   long tv_usec;
  20. };
  21. #endif
  22.  
  23.  
  24.  
  25.         /********************************
  26.         *             OS-TYPES        *
  27.         ********************************/
  28.  
  29. extern int    puti P((int, FILE *));
  30. extern int    geti P((FILE *));
  31.  
  32. /* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  33. The types below should (mostly) be in stdlib.h.  They are not and this
  34. file keeps GCC silent while using the -Wall flag.
  35. - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  36.  
  37. #if sun
  38. extern int    getpid P((void));
  39. extern int    isatty P((int));
  40. extern int    fclose P(( FILE * ));
  41. extern int    pclose P((FILE *));
  42. extern int    _filbuf P((FILE *));
  43. extern int    _flsbuf P((unsigned char, FILE *));
  44. extern int    fflush P((FILE *));
  45. extern char *   vsprintf P((char *, char *, va_list));
  46. extern void    bzero P((Void, int));
  47. extern void    exit P((int));
  48. extern int    close P((int));
  49. extern int    read P((int, Void, int));
  50. extern int    access P((char *, int));
  51. extern unsigned    sleep P((unsigned));
  52. extern int    fprintf P((FILE *, char *, ...));
  53. extern int    printf P((char *, ...));
  54. extern long    putw P((long, FILE *));
  55. extern long    getw P((FILE *));
  56. extern char *    index P((char *, char));
  57. extern int    write P((int, Void, int));
  58. extern int    gettimeofday P((struct timeval *, struct timeval *));
  59. extern long    strtol P((char *, char**, int));
  60. extern int    vfprintf P((FILE *, char *, ...));
  61. extern int    vfork P((void));
  62. #endif
  63.  
  64.  
  65.         /********************************
  66.         *        MEMORY MANAGEMENT      *
  67.         *********************************/
  68.  
  69. #if !ANSI
  70. #define memcpy(to, from, n)    bcopy(from, to, n)
  71. #endif
  72.  
  73.  
  74. #define malloc_t    size_t        /* Argument type of malloc(), etc */
  75. #define alloc_t        size_t        /* argument type of Prolog's alloc */
  76.  
  77. #define Malloc(n)    malloc((malloc_t) (n))
  78. #define Free(p)        free((char *)(p))
  79. #define Realloc(p, n)    realloc((char *)p, (malloc_t)(n))
  80.  
  81. #define allocHeap(n)    alloc_heap((alloc_t) (n))
  82. #define freeHeap(p, n)    free_heap((char *)(p), (alloc_t)(n))
  83. #define allocGlobal(n)    alloc_global((alloc_t) (n))
  84. #define allocLocal(n)    alloc_local((alloc_t) (n))
  85.  
  86. extern Void Allocate P((long));
  87.  
  88.         /********************************
  89.         *         MISCELLANEOUS         *
  90.         *********************************/
  91.  
  92. extern char *Setenv P((char *name, char *value));
  93. extern char *Unsetenv P((char *name));
  94.  
  95. extern long Time P((void));
  96. extern char *OsError P((void));
  97. extern bool initOs P((void));
  98. extern volatile void Halt P((int));
  99.  
  100.         /********************************
  101.         *           ARITHMETIC          *
  102.         *********************************/
  103.  
  104. extern long Random P((void));
  105.  
  106.  
  107.         /********************************
  108.         *              FILES            *
  109.         *********************************/
  110.  
  111. #ifndef STREAM_OPEN_BIN_READ
  112. #define STREAM_OPEN_BIN_READ "rb"
  113. #endif
  114.  
  115. #ifndef STREAM_OPEN_BIN_WRITE
  116. #define STREAM_OPEN_BIN_WRITE "wb"
  117. #endif
  118.  
  119. #if unix
  120. #define PIPE 1
  121. #define Popen(path, m)    popen(OsPath(path), m)
  122. #define Pclose(fd)    pclose(fd)
  123. #endif
  124. #if OS2 && EMX
  125. #define PIPE 1
  126. #define Popen(path, m)    popen(OsPath(path), m)
  127. #define Pclose(fd)    pclose(fd)
  128. #endif
  129.  
  130. #if tos
  131. #define MAXPATHLEN    PATH_MAX
  132. #endif
  133.  
  134.  
  135. #define Fflush(fd)        fflush(fd)
  136. #define Fopen(path, m)        fopen(OsPath(path), m)
  137. #define Fclose(fd)        fclose(fd)
  138. #define Open(path, how, mode)    open(OsPath(path), how, mode)
  139. #define Close(fd)        close(fd)
  140. #define Read(fd, buf, size)    read(fd, buf, size)
  141. #define Write(fd, buf, size)    write(fd, buf, size)
  142. #define Getc(fd)        getc(fd)
  143. #define Putc(c, fd)        putc((char)(c), fd)
  144. #define Putw(w, fd)        putw((long)(w), fd)
  145. #define Getw(fd)        getw(fd)
  146.  
  147. Char        GetChar P((void));
  148. Atom        TemporaryFile P((char *key));
  149. void        RemoveTemporaryFiles P((void));
  150. int        GetDTableSize P((void));
  151. long        LastModifiedFile P((char *name)),
  152.         SizeFile P((char *name));
  153. bool        AccessFile P((char *name, int how)),
  154.         ExistsFile P((char *name)),
  155.         ExistsDirectory P((char *name)),
  156.         DeleteFile P((char *name)),
  157.         RenameFile P((char *old, char *new)),
  158.         SameFile P((char *file1, char *file2)),
  159.         OpenStream P((int index)),
  160.         MarkExecutable P((char *name)),
  161.         expandVars P((char *pattern, char *expanded)),
  162.         ChDir P((char *dir));
  163. char         *AbsoluteFile P((char *)),
  164.         *ExpandOneFile P((char *)),
  165.         *BaseName P((char *)),
  166.         *DirName P((char *)),
  167.         *PrologPath P((char *)),
  168.         *OsPath P((char *));
  169.  
  170. #define ACCESS_EXECUTE    1
  171. #define ACCESS_READ    2
  172. #define ACCESS_WRITE    4
  173.  
  174.         /********************************
  175.         *        TIME CONVERSION        *
  176.         *********************************/
  177.  
  178. extern struct tm *LocalTime P((long *));
  179. extern real      CpuTime P((void));
  180.  
  181.  
  182.         /********************************
  183.         *       FILE DESCR. SETS    *
  184.         ********************************/
  185.  
  186. #ifndef FD_ZERO
  187. /* typedef ulong fd_set;        prior SunOs 4.0 compatibility */
  188. #define FD_ZERO(s)    { *((ulong *)(s)) = (0L); }
  189. #define FD_SET(fd, s)    { *((ulong *)(s)) |= (1L << (fd)); }
  190. #define FD_ISSET(fd, s) ( (*((ulong *)(s)) & (1L << (fd))) != 0 )
  191. #endif
  192.  
  193.         /********************************
  194.         *        TERMINAL CONTROL       *
  195.         *********************************/
  196.  
  197. #define TTY_COOKED     1        /* Initial mode: echo */
  198. #define TTY_EXTEND_ATOMS 2        /* Atom-completion Mode: echo */
  199. #define TTY_APPEND     3        /* Add input from Prolog: echo */
  200. #define TTY_RAW         4        /* Non-blocking, non-echo */
  201. #define TTY_RETYPE     5        /* Retype input: non-echo */
  202. #define    TTY_SAVE     6        /* Save parameters only */
  203.  
  204. #if unix
  205. #if O_TERMIOS
  206. #ifdef TERMIO_INCLUDE
  207. #include TERMIO_INCLUDE
  208. #else
  209. #include <sys/termio.h>
  210. #endif
  211.  
  212. typedef struct
  213. { struct termio tab;        /* saved tty status */
  214.   int        mode;        /* Prolog;'s view on mode */
  215. } ttybuf;
  216.  
  217. #else /* O_TERMIOS */
  218.  
  219. #include <sgtty.h>
  220.  
  221. typedef struct
  222. { struct sgttyb tab;        /* saved tty flags */
  223.   struct tchars chars;        /* tty characters */
  224.   int        mode;        /* Prolog's view on mode */
  225. } ttybuf;
  226. #endif /* O_TERMIOS */
  227.  
  228. #elif OS2 && EMX
  229. #if O_TERMIOS
  230. #include <sys/termio.h>
  231. #include <sys/kbdscan.h>
  232.  
  233.  
  234. typedef struct
  235. { struct termio tab;        /* saved tty status */
  236.   int        mode;        /* Prolog;'s view on mode */
  237. } ttybuf;
  238.  
  239. #else /* ! O_TERMIOS */
  240.  
  241. #include <sgtty.h>
  242.  
  243. typedef struct
  244. { struct sgttyb tab;        /* saved tty flags */
  245.   struct tchars chars;        /* tty characters */
  246.   int        mode;        /* Prolog's view on mode */
  247. } ttybuf;
  248. #endif /* O_TERMIOS */
  249.  
  250. #else /* OS2 */
  251. typedef struct
  252. { int        mode;        /* Prolog's view on mode */
  253. } ttybuf;
  254. #endif /* unix */
  255.  
  256. extern ttybuf    ttytab;            /* saved tty status */
  257. extern int    ttymode;        /* Current tty mode */
  258.  
  259. #if O_LINE_EDIT
  260. #define QSIZE (256)
  261. extern struct tty_driver
  262. { char  werase;         /* word erase character */
  263.   char  kill;           /* kill character */
  264.   char  erase;          /* erase character */
  265.   char  erase2;         /* alternative erase character */
  266.   char  eol;            /* alternative end-of-line */
  267.   char  eol2;           /* 2nd alternative end-of-line */
  268.   char  reprint;        /* reprint input */
  269.   char  intr;           /* interrupt */
  270.   int   mode;           /* mode of the driver */
  271.   int   emitting;       /* Lines available */
  272.   bool  isatty;         /* stdin actually is a terminal? */
  273.   int   column;         /* current cursor column */
  274.   int   in;             /* in-pointer in queue */
  275.   int   out;            /* out-pointer in queue */
  276.   short flags;          /* FLAGS */
  277.   char  queue[QSIZE];   /* character queue */
  278. } stdin_driver ;
  279. #endif /* O_LINE_EDIT */
  280. #define IsaTty(fd)    isatty(fd)
  281.  
  282. extern bool PushTty P((ttybuf *, int mode));
  283. extern bool PopTty P((ttybuf *));
  284. extern void PretendTyped P((char));
  285. extern void ResetTty P((void));
  286. extern void TtyAddChar P((Char));
  287.  
  288.  
  289.         /********************************
  290.         *        PROCESS CONTROL        *
  291.         *********************************/
  292.  
  293. #define Wait(stat)    wait(stat)
  294.  
  295. extern int System P((char *command));
  296. extern void Sleep P((real time));
  297. extern char *Symbols P((void));
  298.