home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / PERL4036.ZIP / handy.h < prev    next >
C/C++ Source or Header  |  1993-02-08  |  5KB  |  148 lines

  1. /* $RCSfile: handy.h,v $$Revision: 4.0.1.4 $$Date: 92/06/08 13:23:17 $
  2.  *
  3.  *    Copyright (c) 1991, 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.  * $Log:    handy.h,v $
  9.  * Revision 4.0.1.4  92/06/08  13:23:17  lwall
  10.  * patch20: isascii() may now be supplied by a library routine
  11.  * patch20: Perl now distinguishes overlapped copies from non-overlapped
  12.  * 
  13.  * Revision 4.0.1.3  91/11/05  22:54:26  lwall
  14.  * patch11: erratum
  15.  * 
  16.  * Revision 4.0.1.2  91/11/05  17:23:38  lwall
  17.  * patch11: prepared for ctype implementations that don't define isascii()
  18.  * 
  19.  * Revision 4.0.1.1  91/06/07  11:09:56  lwall
  20.  * patch4: new copyright notice
  21.  * 
  22.  * Revision 4.0  91/03/20  01:22:15  lwall
  23.  * 4.0 baseline.
  24.  * 
  25.  */
  26.  
  27. #ifdef NULL
  28. #undef NULL
  29. #endif
  30. #ifndef I286
  31. #  define NULL 0
  32. #else
  33. #  define NULL 0L
  34. #endif
  35. #define Null(type) ((type)NULL)
  36. #define Nullch Null(char*)
  37. #define Nullfp Null(FILE*)
  38.  
  39. #ifdef UTS
  40. #define bool int
  41. #else
  42. #define bool char
  43. #endif
  44.  
  45. #ifdef TRUE
  46. #undef TRUE
  47. #endif
  48. #ifdef FALSE
  49. #undef FALSE
  50. #endif
  51. #define TRUE (1)
  52. #define FALSE (0)
  53.  
  54. #define Ctl(ch) (ch & 037)
  55.  
  56. #define strNE(s1,s2) (strcmp(s1,s2))
  57. #define strEQ(s1,s2) (!strcmp(s1,s2))
  58. #define strLT(s1,s2) (strcmp(s1,s2) < 0)
  59. #define strLE(s1,s2) (strcmp(s1,s2) <= 0)
  60. #define strGT(s1,s2) (strcmp(s1,s2) > 0)
  61. #define strGE(s1,s2) (strcmp(s1,s2) >= 0)
  62. #define strnNE(s1,s2,l) (strncmp(s1,s2,l))
  63. #define strnEQ(s1,s2,l) (!strncmp(s1,s2,l))
  64.  
  65. #if defined(CTYPE256) || (!defined(isascii) && !defined(HAS_ISASCII))
  66. #define isALNUM(c) (isalpha(c) || isdigit(c) || c == '_')
  67. #define isALPHA(c) isalpha(c)
  68. #define isSPACE(c) isspace(c)
  69. #define isDIGIT(c) isdigit(c)
  70. #define isUPPER(c) isupper(c)
  71. #define isLOWER(c) islower(c)
  72. #else
  73. #define isALNUM(c) (isascii(c) && (isalpha(c) || isdigit(c) || c == '_'))
  74. #define isALPHA(c) (isascii(c) && isalpha(c))
  75. #define isSPACE(c) (isascii(c) && isspace(c))
  76. #define isDIGIT(c) (isascii(c) && isdigit(c))
  77. #define isUPPER(c) (isascii(c) && isupper(c))
  78. #define isLOWER(c) (isascii(c) && islower(c))
  79. #endif
  80.  
  81. /* Line numbers are unsigned, 16 bits. */
  82. typedef unsigned short line_t;
  83. #ifdef lint
  84. #define NOLINE ((line_t)0)
  85. #else
  86. #define NOLINE ((line_t) 65535)
  87. #endif
  88.  
  89. #ifndef lint
  90. #ifndef LEAKTEST
  91. #ifndef safemalloc
  92. char *safemalloc();
  93. char *saferealloc();
  94. void safefree();
  95. #endif
  96. #ifndef MSDOS
  97. #define New(x,v,n,t)  (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  98. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc((MEM_SIZE)((n) * sizeof(t))))
  99. #define Newz(x,v,n,t) (v = (t*)safemalloc((MEM_SIZE)((n) * sizeof(t)))), \
  100.     memzero((char*)(v), (n) * sizeof(t))
  101. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  102. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  103. #else
  104. #define New(x,v,n,t)  (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t))))
  105. #define Newc(x,v,n,t,c)  (v = (c*)safemalloc(((unsigned long)(n) * sizeof(t))))
  106. #define Newz(x,v,n,t) (v = (t*)safemalloc(((unsigned long)(n) * sizeof(t)))), \
  107.     memzero((char*)(v), (n) * sizeof(t))
  108. #define Renew(v,n,t) (v = (t*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  109. #define Renewc(v,n,t,c) (v = (c*)saferealloc((char*)(v),((unsigned long)(n)*sizeof(t))))
  110. #endif /* MSDOS */
  111. #define Safefree(d) safefree((char*)d)
  112. #define Str_new(x,len) str_new(len)
  113. #else /* LEAKTEST */
  114. char *safexmalloc();
  115. char *safexrealloc();
  116. void safexfree();
  117. #define New(x,v,n,t)  (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  118. #define Newc(x,v,n,t,c)  (v = (c*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t))))
  119. #define Newz(x,v,n,t) (v = (t*)safexmalloc(x,(MEM_SIZE)((n) * sizeof(t)))), \
  120.     memzero((char*)(v), (n) * sizeof(t))
  121. #define Renew(v,n,t) (v = (t*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  122. #define Renewc(v,n,t,c) (v = (c*)safexrealloc((char*)(v),(MEM_SIZE)((n)*sizeof(t))))
  123. #define Safefree(d) safexfree((char*)d)
  124. #define Str_new(x,len) str_new(x,len)
  125. #define MAXXCOUNT 1200
  126. long xcount[MAXXCOUNT];
  127. long lastxcount[MAXXCOUNT];
  128. #endif /* LEAKTEST */
  129. #define Move(s,d,n,t) (void)memmove((char*)(d),(char*)(s), (n) * sizeof(t))
  130. #define Copy(s,d,n,t) (void)memcpy((char*)(d),(char*)(s), (n) * sizeof(t))
  131. #define Zero(d,n,t) (void)memzero((char*)(d), (n) * sizeof(t))
  132. #else /* lint */
  133. #define New(x,v,n,s) (v = Null(s *))
  134. #define Newc(x,v,n,s,c) (v = Null(s *))
  135. #define Newz(x,v,n,s) (v = Null(s *))
  136. #define Renew(v,n,s) (v = Null(s *))
  137. #define Move(s,d,n,t)
  138. #define Copy(s,d,n,t)
  139. #define Zero(d,n,t)
  140. #define Safefree(d) d = d
  141. #endif /* lint */
  142.  
  143. #ifdef STRUCTCOPY
  144. #define StructCopy(s,d,t) *((t*)(d)) = *((t*)(s))
  145. #else
  146. #define StructCopy(s,d,t) Copy(s,d,1,t)
  147. #endif
  148.