home *** CD-ROM | disk | FTP | other *** search
/ Il CD di internet / CD.iso / SOURCE / CONTRIB / MBASE / MBASE51.TAR / mbase51 / src / stdinc.h < prev    next >
Encoding:
C/C++ Source or Header  |  1993-09-04  |  6.1 KB  |  340 lines

  1. /*
  2.  * METALBASE 5.1
  3.  *
  4.  * Released January 1st, 1993 by Huan-Ti [ t-richj@microsoft.com ]
  5.  *
  6.  */
  7.  
  8. #ifndef STDINC_H
  9. #define STDINC_H
  10.  
  11.  
  12. /*
  13.  * DETERMINATION OF SYSTEM ----------------------------------------------------
  14.  *
  15.  */
  16.  
  17. #ifndef AMIGA
  18. #ifndef COHERENT  /* Doesn't really count, as of version 3.1 */
  19. #ifndef MSDOS
  20. #ifndef applec
  21.  
  22. #define UNIX
  23.  
  24. #endif /* applec */
  25. #endif /* MSDOS */
  26. #endif /* COHERENT */
  27. #endif /* AMIGA */
  28.  
  29.  
  30. /*
  31.  * STANDARD SYSTEM DEPENDENCIES -----------------------------------------------
  32.  *
  33.  */
  34.  
  35. #ifdef COHERENT     /* COHERENT -------------------------------------------- */
  36. #ifndef SYS_FCNTL
  37. #define SYS_FCNTL
  38. #endif
  39. #ifndef NO_VOIDPTR
  40. #define NO_VOIDPTR
  41. #endif
  42. /*
  43.  * #ifdef  NO_USHORT
  44.  * #undef  NO_USHORT
  45.  * #endif
  46.  * #ifdef  NO_ULONG
  47.  * #undef  NO_ULONG
  48.  * #endif
  49.  * #ifdef  LONGARGS
  50.  * #undef  LONGARGS
  51.  * #endif
  52.  *
  53.  */
  54. #endif
  55.  
  56. #ifdef applec       /* MACINTOSH ------------------------------------------- */
  57. /*
  58.  * #ifdef  NO_USHORT
  59.  * #undef  NO_USHORT
  60.  * #endif
  61.  *
  62.  */
  63. #endif
  64.  
  65. #ifdef sgi          /* SILICON GRAPHICS ------------------------------------ */
  66. #ifndef NO_ULONG
  67. #define NO_ULONG
  68. #endif
  69. #endif
  70.  
  71. #ifdef MSDOS        /* MS-DOS ---------------------------------------------- */
  72. #ifndef LONGARGS
  73. #define LONGARGS
  74. #endif
  75. #ifndef SYS_TIMEB
  76. #define SYS_TIMEB
  77. #endif
  78. /*
  79.  * #ifdef  NO_ULONG
  80.  * #undef  NO_ULONG
  81.  * #endif
  82.  * #ifdef  NO_USHORT
  83.  * #undef  NO_USHORT
  84.  * #endif
  85.  *
  86.  */
  87. #endif
  88.  
  89.  
  90. /*
  91.  * STANDARD INCLUDES ----------------------------------------------------------
  92.  *
  93.  */
  94.  
  95. #ifdef MSDOS
  96. #include <io.h>
  97. #include <stdlib.h>
  98. #include <process.h>
  99. #include <share.h>
  100. #else
  101. #ifdef SOLARIS2
  102. #include <stdlib.h>
  103. #endif
  104. #endif
  105.  
  106. #ifdef SYS_FCNTL
  107. #include <sys/fcntl.h>
  108. #else
  109. #include <fcntl.h>
  110. #endif
  111.  
  112. #include <stdio.h>
  113. #include <ctype.h>
  114. #include <sys/types.h>
  115. #include <string.h>
  116. #include <time.h>
  117. #include <sys/stat.h>
  118.  
  119. #ifndef NO_TIMEB
  120. #ifdef SYS_TIMEB
  121. #include <sys/timeb.h>
  122. #else
  123. #include <timeb.h>
  124. #endif
  125. #endif
  126.  
  127. #ifdef UNIX
  128. #ifdef NeXT
  129. #include <dir.h>
  130. #else
  131. #ifndef apollo
  132. #include <unistd.h>
  133. #endif
  134. #endif
  135. #endif
  136.  
  137. #ifdef LONGARGS
  138. #define XARGS(x) x
  139. #else
  140. #define XARGS(x) ()
  141. #endif
  142.  
  143. extern time_t time  XARGS( (time_t *) );
  144.  
  145. #ifndef MSDOS
  146.    extern char *getenv XARGS( (char *) );
  147. #endif
  148.  
  149.  
  150. /*
  151.  * STANDARD MACROS ------------------------------------------------------------
  152.  *
  153.  */
  154.  
  155. #ifdef  tolower
  156. #undef  tolower
  157. #endif
  158. #define tolower(x)  (char)(((x)>='A' && (x)<='Z')?((x)+('a'-'A')):(x))
  159.  
  160. #ifdef  toupper
  161. #undef  toupper
  162. #endif
  163. #define toupper(x)  (char)(((x)>='a' && (x)<='z')?((x)+('A'-'a')):(x))
  164.  
  165. #ifdef  isdigit
  166. #undef  isdigit
  167. #endif
  168. #define isdigit(x)  ((x) >= '0' && (x) <= '9')
  169.  
  170. #ifdef  until
  171. #undef  until
  172. #endif
  173. #define until(x)    while (!(x))
  174.  
  175. #ifdef  New
  176. #undef  New
  177. #endif
  178. #define New(x)      (x *)malloc (sizeof(x))
  179.  
  180. #ifdef  min
  181. #undef  min
  182. #endif
  183. #define min(a,b)    ((a)<(b)?(a):(b))
  184.  
  185. #ifdef  max
  186. #undef  max
  187. #endif
  188. #define max(a,b)    ((a)>(b)?(a):(b))
  189.  
  190.  
  191. /*
  192.  * STANDARD TYPEDEFS ----------------------------------------------------------
  193.  *
  194.  */
  195.  
  196. #ifndef NO_UCHAR                        /* uchar --------------------------- */
  197. #ifdef CHAR_IS_UNS
  198.    typedef char uchar;
  199. #else
  200.    typedef unsigned char uchar;
  201. #endif
  202. #endif
  203.  
  204. #ifndef NO_VOIDPTR                      /* dataptr ------------------------- */
  205.    typedef void * dataptr;
  206. #else
  207.    typedef char * dataptr;
  208. #endif
  209.  
  210. #ifndef NO_CHARPTR                      /* charptr ------------------------- */
  211.    typedef char * charptr;
  212. #endif
  213.  
  214. #ifndef NO_ULONG                        /* ulong --------------------------- */
  215.    typedef unsigned long ulong;
  216. #endif
  217.  
  218. #ifndef NO_USHORT                       /* ushort -------------------------- */
  219.    typedef unsigned short ushort;
  220. #endif
  221.  
  222. #ifndef NO_FILE                         /* file ---------------------------- */
  223.    typedef int file;
  224. #endif
  225.  
  226. #ifndef NO_BOOL                         /* bool ---------------------------- */
  227.    typedef char bool;
  228. #endif
  229.  
  230. #ifndef NO_BYTE                         /* byte ---------------------------- */
  231.    typedef uchar byte;
  232. #endif
  233.  
  234.  
  235. /*
  236.  * STANDARD DEFINES -----------------------------------------------------------
  237.  *
  238.  */
  239.  
  240. #ifdef FALSE
  241. #undef FALSE
  242. #endif
  243. #define FALSE (bool)0
  244.  
  245. #ifdef TRUE
  246. #undef TRUE
  247. #endif
  248. #define TRUE (bool)1
  249.  
  250. #ifdef MSDOS
  251. #define DIRSEP  '\\'
  252. #define szEOL   "\r\n"
  253. #else
  254. #define DIRSEP  '/'
  255. #define szEOL   "\n"
  256. #endif
  257.  
  258. #ifdef ESC
  259. #undef ESC
  260. #endif
  261.  
  262. #define CTRL_A (char)1
  263. #define CTRL_B (char)2
  264. #define CTRL_C (char)3
  265. #define CTRL_D (char)4
  266. #define CTRL_E (char)5
  267. #define CTRL_F (char)6
  268. #define CTRL_G (char)7
  269. #define CTRL_H (char)8
  270. #define CTRL_I (char)9
  271. #define CTRL_J (char)10
  272. #define CTRL_K (char)11
  273. #define CTRL_L (char)12
  274. #define CTRL_M (char)13
  275. #define CTRL_N (char)14
  276. #define CTRL_O (char)15
  277. #define CTRL_P (char)16
  278. #define CTRL_Q (char)17
  279. #define CTRL_R (char)18
  280. #define CTRL_S (char)19
  281. #define CTRL_T (char)20
  282. #define CTRL_U (char)21
  283. #define CTRL_V (char)22
  284. #define CTRL_W (char)23
  285. #define CTRL_X (char)24
  286. #define CTRL_Y (char)25
  287. #define CTRL_Z (char)26
  288. #define ESC    (char)27
  289.  
  290.  
  291. /*
  292.  * PORTABLE FILE OPERATIONS ---------------------------------------------------
  293.  *
  294.  * Use the following functions for file I/O
  295.  *
  296.  *     readx  -  read from a file (of course)
  297.  *     writx  -  write to a file
  298.  *     modex  -  change the attributes on a file
  299.  *     openx  -  open a file (use OPENMODE or READMODE, for R/W or R access)
  300.  *     close  -  close a file
  301.  *     lseek  -  move within a file
  302.  *     creatx -  create a new file
  303.  *
  304.  * A quick note: Never use modex() on a file which has open filehandles; on
  305.  * MS-DOS systems, if SHARE is loaded, that will invalidate the filehandle.
  306.  * Honest!
  307.  *
  308.  */
  309.  
  310. #define creatx(x)      creat  (x, 0666)
  311. #define modex(f,n)     chmod  (f, n)
  312. #define openx(f,n)     open   (f, n)
  313. #define readx(f,b,n)   read   (f, (char *)(b), (int)(n))
  314. #define writx(f,b,n)   write  (f, (char *)(b), (int)(n))
  315.  
  316. #define OPENMODE O_RDWR
  317. #define READMODE O_RDONLY
  318.  
  319. #ifndef S_IWRITE
  320. #undef  modex
  321. #define modex(f,n)
  322. #endif
  323.  
  324. #ifdef  applec
  325. #undef  creatx
  326. #define creatx(x) creat(x)
  327. #endif
  328.  
  329. #ifdef MSDOS
  330. #undef  READMODE
  331. #define READMODE O_RDONLY|O_BINARY
  332. #undef  OPENMODE
  333. #define OPENMODE O_RDWR|O_BINARY
  334. #undef  openx
  335. #define openx(f,m)  sopen (f, m, SH_DENYNO, S_IREAD|S_IWRITE)
  336. #endif
  337.  
  338. #endif  /* STDINC_H */
  339.  
  340.