home *** CD-ROM | disk | FTP | other *** search
/ OpenStep 4.2J (Developer) / os42jdev.iso / NextDeveloper / Source / GNU / perl / Perl / handy.h < prev    next >
C/C++ Source or Header  |  1995-12-06  |  6KB  |  202 lines

  1. /*    handy.h
  2.  *
  3.  *    Copyright (c) 1991-1994, Larry Wall
  4.  *
  5.  *    You may distribute under the terms of either the GNU General Public
  6.  *    License or the Artistic License, as specified in the README file.
  7.  *
  8.  */
  9.  
  10. #if !defined(__STDC__)
  11. #ifdef NULL
  12. #undef NULL
  13. #endif
  14. #ifndef I286
  15. #  define NULL 0
  16. #else
  17. #  define NULL 0L
  18. #endif
  19. #endif
  20.  
  21. #define Null(type) ((type)NULL)
  22. #define Nullch Null(char*)
  23. #define Nullfp Null(FILE*)
  24. #define Nullsv Null(SV*)
  25.  
  26. #ifdef TRUE
  27. #undef TRUE
  28. #endif
  29. #ifdef FALSE
  30. #undef FALSE
  31. #endif
  32. #define TRUE (1)
  33. #define FALSE (0)
  34.  
  35. /* bool is built-in for g++-2.6.3, which might be used for an extension.
  36.    If the extension includes <_G_config.h> before this file then
  37.    _G_HAVE_BOOL will be properly set.  If, however, the extension includes
  38.    this file first, then you will have to manually set -DHAS_BOOL in 
  39.    your command line to avoid a conflict.
  40. */
  41. #ifdef _G_HAVE_BOOL
  42. # if _G_HAVE_BOOL
  43. #  ifndef HAS_BOOL
  44. #   define HAS_BOOL 1
  45. #  endif
  46. # endif
  47. #endif
  48.  
  49. /* The NeXT dynamic loader headers will not build with the bool macro
  50.    So declare them now to clear confusion.
  51. */
  52. #ifdef NeXT
  53. # undef FALSE
  54. # undef TRUE
  55.   typedef enum bool { FALSE = 0, TRUE = 1 } bool;
  56. # define ENUM_BOOL 1
  57. # ifndef HAS_BOOL
  58. #  define HAS_BOOL 1
  59. # endif /* !HAS_BOOL */
  60. #endif /* NeXT */
  61.  
  62. #ifndef HAS_BOOL
  63. # ifdef UTS
  64. #  define bool int
  65. # else
  66. #  define bool char
  67. # endif
  68. #endif
  69.  
  70. typedef char        I8;
  71. typedef unsigned char    U8;
  72.  
  73. typedef short        I16;
  74. typedef unsigned short    U16;
  75.  
  76. #if BYTEORDER > 0x4321
  77.   typedef int        I32;
  78.   typedef unsigned int    U32;
  79. #else
  80.   typedef long        I32;
  81.   typedef unsigned long    U32;
  82. #endif
  83.  
  84. #define Ctl(ch) (ch & 037)
  85.  
  86. #define strNE(s1,s2) (strcmp(s1,s2))
  87. #define strEQ(s1,s2) (!strcmp(s1,s2))
  88. #define strLT(s1,s2) (strcmp(s1,s2) < 0)
  89. #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
  90. #define strGT(s1,s2) (strcmp(s1,s2) > 0)
  91. #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
  92. #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  93. #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  94.  
  95. #ifdef HAS_SETLOCALE  /* XXX Is there a better test for this? */
  96. #  ifndef CTYPE256
  97. #    define CTYPE256
  98. #  endif
  99. #endif
  100.  
  101. #ifdef USE_NEXT_CTYPE 
  102. #define isALNUM(c)   (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
  103. #define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
  104. #define isALPHA(c)   NXIsAlpha((unsigned int)c)
  105. #define isSPACE(c)   NXIsSpace((unsigned int)c)
  106. #define isDIGIT(c)   NXIsDigit((unsigned int)c)
  107. #define isUPPER(c)   NXIsUpper((unsigned int)c)
  108. #define isLOWER(c)   NXIsLower((unsigned int)c)
  109. #define toUPPER(c)   NXToUpper((unsigned int)c)
  110. #define toLOWER(c)   NXToLower((unsigned int)c)
  111. #else /* USE_NEXT_CTYPE */
  112. #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
  113. #define isALNUM(c)   (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
  114. #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
  115. #define isALPHA(c)   isalpha((unsigned char)(c))
  116. #define isSPACE(c)   isspace((unsigned char)(c))
  117. #define isDIGIT(c)   isdigit((unsigned char)(c))
  118. #define isUPPER(c)   isupper((unsigned char)(c))
  119. #define isLOWER(c)   islower((unsigned char)(c))
  120. #define toUPPER(c)   toupper((unsigned char)(c))
  121. #define toLOWER(c)   tolower((unsigned char)(c))
  122. #else
  123. #define isALNUM(c)   (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
  124. #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
  125. #define isALPHA(c)   (isascii(c) && isalpha(c))
  126. #define isSPACE(c)   (isascii(c) && isspace(c))
  127. #define isDIGIT(c)   (isascii(c) && isdigit(c))
  128. #define isUPPER(c)   (isascii(c) && isupper(c))
  129. #define isLOWER(c)   (isascii(c) && islower(c))
  130. #define toUPPER(c)   toupper(c)
  131. #define toLOWER(c)   tolower(c)
  132. #endif
  133. #endif /* USE_NEXT_CTYPE */
  134.  
  135. /* Line numbers are unsigned, 16 bits. */
  136. typedef U16 line_t;
  137. #ifdef lint
  138. #define NOLINE ((line_t)0)
  139. #else
  140. #define NOLINE ((line_t) 65535)
  141. #endif
  142.  
  143. #ifndef lint
  144. #ifndef LEAKTEST
  145. #ifndef safemalloc
  146. char *safemalloc _((MEM_SIZE));
  147. char *saferealloc _((char *, MEM_SIZE));
  148. void safefree _((char *));
  149. #endif
  150. #ifndef MSDOS
  151. #define New(x,v,n,t)  (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  152. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  153. #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
  154.     memzero((char*)(v), (n) * sizeof(t))
  155. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  156. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  157. #else
  158. #define New(x,v,n,t)  (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
  159. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
  160. #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
  161.     memzero((char*)(v), (n) * sizeof(t))
  162. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  163. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  164. #endif /* MSDOS */
  165. #define Safefree(d) safefree((char*)d)
  166. #define NEWSV(x,len) newSV(len)
  167. #else /* LEAKTEST */
  168. char *safexmalloc();
  169. char *safexrealloc();
  170. void safexfree();
  171. #define New(x,v,n,t)  (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  172. #define Newc(x,v,n,t,c)  (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  173. #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
  174.     memzero((char*)(v), (n) * sizeof(t))
  175. #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  176. #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  177. #define Safefree(d) safexfree((char*)d)
  178. #define NEWSV(x,len) newSV(x,len)
  179. #define MAXXCOUNT 1200
  180. long xcount[MAXXCOUNT];
  181. long lastxcount[MAXXCOUNT];
  182. #endif /* LEAKTEST */
  183. #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
  184. #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
  185. #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
  186. #else /* lint */
  187. #define New(x,v,n,s) (v = Null(s *))
  188. #define Newc(x,v,n,s,c) (v = Null(s *))
  189. #define Newz(x,v,n,s) (v = Null(s *))
  190. #define Renew(v,n,s) (v = Null(s *))
  191. #define Move(s,d,n,t)
  192. #define Copy(s,d,n,t)
  193. #define Zero(d,n,t)
  194. #define Safefree(d) d = d
  195. #endif /* lint */
  196.  
  197. #ifdef USE_STRUCT_COPY
  198. #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
  199. #else
  200. #define StructCopy(s,d,t) Copy(s,d,1,t)
  201. #endif
  202.