home *** CD-ROM | disk | FTP | other *** search
/ RISC DISC 2 / RISC_DISC_2.iso / pd_share / utilities / cli / perl / !Perl / h / handy < prev    next >
Encoding:
Text File  |  1995-02-08  |  5.6 KB  |  176 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. /* bool is built-in for g++-2.6.3, which might be used for an extension. */
  27. #if !defined(HAS_BOOL) && !defined(_G_HAVE_BOOL)
  28. #ifdef UTS
  29. #define bool int
  30. #else
  31. #define bool char
  32. #endif
  33. #endif /* !defined(HAS_BOOL) && !defined(_G_HAVE_BOOL) */
  34.  
  35. #ifdef TRUE
  36. #undef TRUE
  37. #endif
  38. #ifdef FALSE
  39. #undef FALSE
  40. #endif
  41. #define TRUE (1)
  42. #define FALSE (0)
  43.  
  44. typedef char        I8;
  45. typedef unsigned char    U8;
  46.  
  47. typedef short        I16;
  48. typedef unsigned short    U16;
  49.  
  50. #if BYTEORDER > 0x4321
  51.   typedef int        I32;
  52.   typedef unsigned int    U32;
  53. #else
  54.   typedef long        I32;
  55.   typedef unsigned long    U32;
  56. #endif
  57.  
  58. #define Ctl(ch) (ch & 037)
  59.  
  60. #define strNE(s1,s2) (strcmp(s1,s2))
  61. #define strEQ(s1,s2) (!strcmp(s1,s2))
  62. #define strLT(s1,s2) (strcmp(s1,s2) < 0)
  63. #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
  64. #define strGT(s1,s2) (strcmp(s1,s2) > 0)
  65. #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
  66. #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  67. #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  68.  
  69. #ifdef HAS_SETLOCALE  /* XXX Is there a better test for this? */
  70. #  ifndef CTYPE256
  71. #    define CTYPE256
  72. #  endif
  73. #endif
  74.  
  75. #ifdef USE_NEXT_CTYPE 
  76. #define isALNUM(c)   (NXIsAlpha((unsigned int)c) || NXIsDigit((unsigned int)c) || c == '_')
  77. #define isIDFIRST(c) (NXIsAlpha((unsigned int)c) || c == '_')
  78. #define isALPHA(c)   NXIsAlpha((unsigned int)c)
  79. #define isSPACE(c)   NXIsSpace((unsigned int)c)
  80. #define isDIGIT(c)   NXIsDigit((unsigned int)c)
  81. #define isUPPER(c)   NXIsUpper((unsigned int)c)
  82. #define isLOWER(c)   NXIsLower((unsigned int)c)
  83. #define toUPPER(c)   NXToUpper((unsigned int)c)
  84. #define toLOWER(c)   NXToLower((unsigned int)c)
  85. #else /* USE_NEXT_CTYPE */
  86. #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
  87. #define isALNUM(c)   (isalpha((unsigned char)(c)) || isdigit((unsigned char)(c)) || c == '_')
  88. #define isIDFIRST(c) (isalpha((unsigned char)(c)) || (c) == '_')
  89. #define isALPHA(c)   isalpha((unsigned char)(c))
  90. #define isSPACE(c)   isspace((unsigned char)(c))
  91. #define isDIGIT(c)   isdigit((unsigned char)(c))
  92. #define isUPPER(c)   isupper((unsigned char)(c))
  93. #define isLOWER(c)   islower((unsigned char)(c))
  94. #define toUPPER(c)   toupper((unsigned char)(c))
  95. #define toLOWER(c)   tolower((unsigned char)(c))
  96. #else
  97. #define isALNUM(c)   (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
  98. #define isIDFIRST(c) (isascii(c) && (isalpha(c) || (c) == '_'))
  99. #define isALPHA(c)   (isascii(c) && isalpha(c))
  100. #define isSPACE(c)   (isascii(c) && isspace(c))
  101. #define isDIGIT(c)   (isascii(c) && isdigit(c))
  102. #define isUPPER(c)   (isascii(c) && isupper(c))
  103. #define isLOWER(c)   (isascii(c) && islower(c))
  104. #define toUPPER(c)   toupper(c)
  105. #define toLOWER(c)   tolower(c)
  106. #endif
  107. #endif /* USE_NEXT_CTYPE */
  108.  
  109. /* Line numbers are unsigned, 16 bits. */
  110. typedef U16 line_t;
  111. #ifdef lint
  112. #define NOLINE ((line_t)0)
  113. #else
  114. #define NOLINE ((line_t) 65535)
  115. #endif
  116.  
  117. #ifndef lint
  118. #ifndef LEAKTEST
  119. #ifndef safemalloc
  120. char *safemalloc _((MEM_SIZE));
  121. char *saferealloc _((char *, MEM_SIZE));
  122. void safefree _((char *));
  123. #endif
  124. #ifndef MSDOS
  125. #define New(x,v,n,t)  (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  126. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  127. #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
  128.     memzero((char*)(v), (n) * sizeof(t))
  129. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  130. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  131. #else
  132. #define New(x,v,n,t)  (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
  133. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
  134. #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
  135.     memzero((char*)(v), (n) * sizeof(t))
  136. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  137. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  138. #endif /* MSDOS */
  139. #define Safefree(d) safefree((char*)d)
  140. #define NEWSV(x,len) newSV(len)
  141. #else /* LEAKTEST */
  142. char *safexmalloc();
  143. char *safexrealloc();
  144. void safexfree();
  145. #define New(x,v,n,t)  (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  146. #define Newc(x,v,n,t,c)  (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  147. #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
  148.     memzero((char*)(v), (n) * sizeof(t))
  149. #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  150. #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  151. #define Safefree(d) safexfree((char*)d)
  152. #define NEWSV(x,len) newSV(x,len)
  153. #define MAXXCOUNT 1200
  154. long xcount[MAXXCOUNT];
  155. long lastxcount[MAXXCOUNT];
  156. #endif /* LEAKTEST */
  157. #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
  158. #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
  159. #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
  160. #else /* lint */
  161. #define New(x,v,n,s) (v = Null(s *))
  162. #define Newc(x,v,n,s,c) (v = Null(s *))
  163. #define Newz(x,v,n,s) (v = Null(s *))
  164. #define Renew(v,n,s) (v = Null(s *))
  165. #define Move(s,d,n,t)
  166. #define Copy(s,d,n,t)
  167. #define Zero(d,n,t)
  168. #define Safefree(d) d = d
  169. #endif /* lint */
  170.  
  171. #ifdef USE_STRUCT_COPY
  172. #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
  173. #else
  174. #define StructCopy(s,d,t) Copy(s,d,1,t)
  175. #endif
  176.