home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume29 / parseargs / part04 / useful.h < prev   
Encoding:
C/C++ Source or Header  |  1992-05-19  |  8.3 KB  |  333 lines

  1. /*************************************************************************
  2. ** ^FILE: useful.h - various definitions of general interest
  3. **
  4. ** ^DESCRIPTION:
  5. **    This file #defines several macros that are either of very general
  6. **    use, or that assist in writing portable programs between various
  7. **    systems and/or compilers.
  8. **
  9. ** ^HISTORY:
  10. **    --/--/--    Brad Appleton    <brad@ssd.csd.harris.com>    
  11. **    - Added OS specific #defines for unix, SYSV, BSD, etc ...
  12. **    - Added structured block comments
  13. **    - Added varargs/stdarg macros
  14. **    - Added BSET, BCLEAR, BTEST macros for handling bitmasks
  15. **    - #defined EXTERN to be extern "C" for C++
  16. **    - Added #defines for STDIN, STDOUT, and STDERR file descriptors
  17. **
  18. **    --/--/--    Peter da Silva    <peter@ferranti.com>    
  19. **
  20. **    --/--/--    Eric P. Allman    <eric@Berkeley.EDU>     Created
  21. ***^^**********************************************************************/
  22.  
  23. /* $Header: useful.h,v 2.0 89/12/24 00:56:33 eric Exp $ */
  24.  
  25. #ifndef _USEFUL_H_
  26. #define _USEFUL_H_
  27.  
  28. #if (defined(_unix) || defined(__unix) || defined(_unix_) || defined(__unix__))
  29. # ifndef unix
  30. #   define unix
  31. # endif
  32. #endif /* _unix */
  33.  
  34. #if (defined(_UNIX) || defined(__UNIX) || defined(_UNIX_) || defined(__UNIX__))
  35. # ifndef unix
  36. #   define unix
  37. # endif
  38. #endif /* _UNIX */
  39.  
  40.    /* give a stab at the dual Unix universe dilemma (UCB vs AT&T) */
  41. #ifdef unix
  42. # if ( defined(_BSD) && !defined(BSD) )
  43. #  define BSD
  44. # endif
  45. # if ( defined(_SYSV) && !defined(SYSV) )
  46. #  define SYSV
  47. # endif
  48.  
  49. # ifndef BSD
  50. #  ifdef sun
  51. #   define BSD
  52. #  endif
  53. #  if ( defined(apollo) || defined(aegis) )
  54. #   define BSD
  55. #  endif
  56. #  if ( defined(_CX_UX) && defined(ucb_universe) )
  57. #   define BSD
  58. #  endif
  59. #  if ( defined(VAX_BSD) || defined(ULTRIX) || defined(ultrix) )
  60. #   define BSD
  61. #  endif
  62. #  if ( defined(DYNIX) || defined(dynix) )
  63. #   define BSD
  64. #  endif
  65. #  if ( defined(UTX) || defined(utx) )
  66. #   define BSD
  67. #  endif
  68. # endif /* !BSD */
  69.  
  70. # ifndef SYSV
  71. #  ifdef mips
  72. #   define SYSV
  73. #  endif
  74. #  ifdef DGUX
  75. #   define SYSV
  76. #  endif
  77. #  if ( defined(_CX_UX) && defined(att_universe) )
  78. #   define SYSV
  79. #  endif
  80. #  if ( defined(hpux) || defined(HPUX) )
  81. #   define SYSV
  82. #  endif
  83. #  if ( defined(irix) || defined(IRIX) )
  84. #   define SYSV
  85. #  endif
  86. #  if ( defined(aix) || defined(AIX) )
  87. #   define SYSV
  88. #  endif
  89. # endif /* !SYSV */
  90. #endif /* unix */
  91.  
  92. #ifndef MSDOS
  93. # if (defined(_MSDOS_)||defined(__MSDOS__)||defined(_MSDOS)||defined(__MSDOS))
  94. #  define MSDOS
  95. # endif
  96. #endif
  97.  
  98. #ifndef OS2
  99. # if ( defined(_OS2_) || defined(__OS2__) || defined(_OS2) || defined(__OS2) )
  100. #  define OS2
  101. # endif
  102. #endif
  103.  
  104. #ifndef AmigaDOS
  105. # if ( defined(AMIGA) || defined(MANX) || defined(AZTEC) )
  106. #   define AmigaDOS
  107. # endif
  108. #endif /* AmigaDOS */
  109.  
  110.  
  111. #ifdef __STDC__
  112. # include <stddef.h>
  113. # include <stdlib.h>
  114. #endif
  115.  
  116. #if ( !defined(__STDC__) && defined(vms) )
  117. # include <stdlib.h>
  118. #endif
  119.  
  120. #ifndef FILE
  121. # include <stdio.h>
  122. #endif
  123.  
  124. #ifndef STDIN
  125. # define STDIN   0
  126. # define STDOUT  1
  127. # define STDERR  2
  128. #endif
  129.  
  130.    /* macros to portably convert character case */
  131. #define TOUPPER(c)  ( islower(c) ) ? toupper(c) : (c)
  132. #define TOLOWER(c)  ( isupper(c) ) ? tolower(c) : (c)
  133.  
  134.    /* give a stab at the multiple-language dilemma */
  135. #ifdef __STDC__
  136. #  define ARGS(x)        x
  137. #  define NOARGS        ( void )
  138. #  define __ANSI_C__
  139. #else
  140. #  if defined(c_plusplus) || defined(__cplusplus)
  141. #    define ARGS(x)        x
  142. #    define NOARGS        ()
  143. #    define __ANSI_C__
  144. #  else
  145. #    define ARGS(x)        ()
  146. #    define NOARGS        ()
  147. #  endif
  148. #endif
  149.  
  150.    /* give a stab at the variable arguments dilemma  --BDA */
  151. #ifdef __STDC__
  152. #  ifndef va_arg
  153. #    include <stdarg.h>
  154. #  endif
  155. #  define  VA_START(ap,last)  va_start(ap, last)
  156. #  define  VA_ARG(ap,type)    va_arg(ap, type)
  157. #  define  VA_END(ap)         va_end(ap)
  158. #else
  159. #  ifndef va_arg
  160. #    include  <varargs.h>
  161. #  endif
  162. #  define  VA_START(ap,last)  va_start(ap)
  163. #  define  VA_ARG(ap,type)    va_arg(ap, type)
  164. #  define  VA_END(ap)         va_end(ap)
  165. #endif
  166.  
  167. #ifndef VOID
  168. #  if ( defined(__ANSI_C__)  ||  !defined(NOVOID) )
  169. #    define VOID        void
  170. #  else
  171. #    define VOID        int
  172. #  endif
  173. #endif
  174.  
  175. #ifndef TRUE
  176. #  define TRUE        1
  177. #  define FALSE        0
  178. #endif
  179.  
  180. #ifndef STATIC
  181. #  ifndef NODEBUG
  182. #    define STATIC
  183. #  else
  184. #    define STATIC        static
  185. #  endif
  186. #endif
  187.  
  188. #ifndef EXTERN
  189. #  if defined(c_plusplus) || defined(__cplusplus)
  190. #    define EXTERN        extern "C"
  191. #  else
  192. #    define EXTERN        extern
  193. #  endif
  194. #endif
  195.  
  196. #ifndef CONST
  197. #  ifdef __ANSI_C__
  198. #    define CONST        const
  199. #  else
  200. #    define CONST
  201. #  endif
  202. #endif
  203.  
  204. #ifndef NULL
  205. #  define NULL        0
  206. #endif
  207.  
  208. #ifndef CHARNULL
  209. #  define CHARNULL    ((char *) NULL)
  210. #endif
  211.  
  212. #ifndef FILENULL
  213. #  define FILENULL    ((FILE *) NULL)
  214. #endif
  215.  
  216. #if ( defined(__ANSI_C__)  ||  defined(vms) )
  217.    typedef   void *ARBPTR;
  218. #else
  219.    typedef   char *ARBPTR;
  220. #endif
  221.  
  222. #define __        (ARBPTR)
  223. #define ARBNULL        (__ NULL)
  224.  
  225. #ifndef BOOL
  226.    typedef   char   BOOL;
  227. #endif
  228.  
  229. #ifdef lint
  230. #  define VERSIONID(v)
  231. #else
  232. #  define VERSIONID(v)    static char _Version[] = v
  233. #endif
  234.  
  235.    /* keep BITSET for compatibilty
  236.    ** but use BSET, BCLEAR, etc... instead   --BDA
  237.    */
  238. #define BITSET(bstr,mask)    ( ((bstr) & (mask)) != 0 )
  239.  
  240. #define BTEST(bstr,mask)    ( ((bstr) & (mask)) != 0 )
  241. #define BSET(bstr,mask)     (bstr) |= (mask)
  242. #define BCLEAR(bstr,mask)   (bstr) &= ~(mask)
  243.  
  244. #ifndef __STRING_H
  245. # define __STRING_H
  246.    EXTERN  char  *strcat    ARGS(( char *, const char * ));
  247.    EXTERN  char  *strncat   ARGS(( char *, const char *, int ));
  248.    EXTERN  int    strcmp    ARGS(( const char *, const char * ));
  249.    EXTERN  int    strncmp   ARGS(( const char *, const char *, int ));
  250.    EXTERN  char  *strcpy    ARGS(( char *, const char * ));
  251.    EXTERN  char  *strncpy   ARGS(( char *, const char *, int ));
  252.    EXTERN  int    strlen    ARGS(( const char * ));
  253.    
  254. # ifndef BSD
  255. #  define index(s,c)   strchr(s,c)
  256. #  define rindex(s,c)  strrchr(s,c)
  257.    EXTERN  char  *strchr    ARGS(( const char *, int ));
  258.    EXTERN  char  *strrchr   ARGS(( const char *, int ));
  259.    EXTERN  char  *strpbrk   ARGS(( const char *, const char * ));
  260.    EXTERN  int    strspn    ARGS(( const char *, const char * ));
  261.    EXTERN  int    strcspn   ARGS(( const char *, const char * ));
  262.    EXTERN  char  *strtok    ARGS(( char *, const char * ));
  263.    
  264. # else
  265. #  define strchr(s,c)   index(s,c)
  266. #  define strrchr(s,c)  rindex(s,c)
  267.    EXTERN  char  *index     ARGS(( const char *, int ));
  268.    EXTERN  char  *rindex    ARGS(( const char *, int ));
  269. # endif /* !BSD */
  270.    
  271. # ifndef BSD
  272. #  define bcmp(b1,b2,n)   memcmp(b1,b2,n)
  273. #  define bcopy(b1,b2,n)  memcpy(b2,b1,n)
  274. #  define bzero(b,n)      memset(b,'\0',n)
  275. #  ifndef __MEMORY_H
  276. #    define __MEMORY_H
  277.    EXTERN  ARBPTR  memccpy   ARGS(( ARBPTR, const ARBPTR, int, int ));
  278.    EXTERN  ARBPTR  memchr    ARGS(( ARBPTR, int, int ));
  279.    EXTERN  int     memcmp    ARGS(( const ARBPTR, const ARBPTR, int ));
  280.    EXTERN  ARBPTR  memcpy    ARGS(( ARBPTR, const ARBPTR, int ));
  281.    EXTERN  ARBPTR  memmove   ARGS(( ARBPTR, const ARBPTR, int ));
  282.    EXTERN  ARBPTR  memset    ARGS(( ARBPTR, int, int ));
  283. #  endif  /* __MEMORY_H */
  284.    
  285. # else
  286. #  define memcmp(b1,b2,n)  bcmp(b1,b2,n)
  287. #  define memcpy(b1,b2,n)  bcopy(b2,b1,n)
  288. #  ifndef __BSTRING_H
  289. #    define __BSTRING_H
  290.    EXTERN  VOID   bcopy     ARGS(( const ARBPTR, ARBPTR, int ));
  291.    EXTERN  int    bcmp      ARGS(( const ARBPTR, const ARBPTR, int ));
  292.    EXTERN  VOID   bzero     ARGS(( ARBPTR, int ));
  293.    EXTERN  int    ffs       ARGS(( int ));
  294. #  endif  /* __BSTRING_H */
  295. # endif /* !BSD */
  296. #endif /* __STRING_H */
  297.  
  298. #if ( !defined(__ANSI_C__)  &&  !defined(_SIZE_T_DEFINED) )
  299. # if (defined(sun) && defined(BSD))
  300. #  include <sys/types.h>
  301. #  if (!defined (__sys_stdtypes_h) && !defined(_TYPES_))
  302.     /* size_t is also defined in <sys/stdtypes.h> in SunOS 4.1
  303.     ** and int <types.h> in SunOS 4.0.3
  304.     */
  305.     typedef int size_t;
  306. #  endif
  307. #  define _SIZE_T_DEFINED 1
  308. # endif /* sun */
  309. # if (defined(vms) && defined(__STDDEF_LOADED))
  310. #  define _SIZE_T_DEFINED 1
  311. # endif /* vms */
  312. # ifndef _SIZE_T_DEFINED
  313.    typedef unsigned int size_t;
  314. #  define _SIZE_T_DEFINED 1
  315. # endif  /* !_SIZE_T_DEFINED */
  316. #endif
  317.  
  318. #if ( !defined(__malloc_h) && !defined(__MALLOC_H) && !defined(vms) )
  319. # include <malloc.h>
  320. #else
  321.   EXTERN  ARBPTR  malloc   ARGS(( size_t ));
  322.   EXTERN  ARBPTR  realloc  ARGS(( ARBPTR, size_t ));
  323.   EXTERN  VOID    free     ARGS(( ARBPTR ));
  324. #endif /*__malloc_h*/
  325.  
  326. EXTERN  ARBPTR  ckalloc  ARGS(( size_t ));
  327. EXTERN  VOID    exit     ARGS(( int ));
  328.  
  329. #define MAXINPUTLINE    200        /* maximum string input line */
  330. #define MAXWORDLEN    100        /* maximum word (token) length */
  331.  
  332. #endif /* _USEFUL_H_ */
  333.