home *** CD-ROM | disk | FTP | other *** search
/ Education Sampler 1992 [NeXTSTEP] / Education_1992_Sampler.iso / Programming / Source / WAIS / ir / cutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  1992-02-02  |  4.0 KB  |  170 lines

  1. /* WIDE AREA INFORMATION SERVER SOFTWARE
  2.    No guarantees or restrictions.  See the readme file for the full standard
  3.    disclaimer.  
  4.   
  5.    3.26.90    Harry Morris, morris@think.com
  6.    4.11.90  HWM - generalized conditional includes (see c-dialect.h)
  7. */
  8.  
  9. #ifndef _H_C_util_
  10. #define _H_C_util_
  11.  
  12. #include "cdialect.h"
  13.  
  14. #include <stdio.h>   /* this used to be wrapped in an ifndef NULL, 
  15.             but messed up on some gcc's */
  16. #ifdef THINK_C
  17. #include <time.h>
  18. #else
  19. #include <sys/time.h>
  20. #endif
  21.  
  22. #define MAX_FILENAME_LEN 255
  23.  
  24. #ifdef ANSI_LIKE
  25. #ifndef EXIT_SUCCESS /* only include it if not already included */
  26. #include <stdlib.h> /* this is a shame */
  27. #endif /* ndef EXIT_SUCCESS */
  28. #else    
  29. #include "ustubs.h"
  30. #endif /* else */
  31.  
  32. /*----------------------------------------------------------------------*/
  33. /* types and constants */
  34.  
  35. #ifndef boolean
  36. #define boolean    unsigned long
  37. #endif /* ndef boolean */ 
  38.  
  39. #ifndef THINK_C
  40. #ifndef Boolean
  41. #define Boolean    boolean
  42. #endif /* ndef Boolean */ 
  43. #endif /* ndef THINK_C */
  44.  
  45. #ifndef true
  46. #define true     (boolean)1L
  47. #endif /* ndef true */
  48.  
  49. #ifndef false
  50. #define false     (boolean)0L   /* used to be (!true), but broke 
  51.                  some compilers */
  52. #endif /* ndef false */
  53.  
  54. #ifndef TRUE
  55. #define TRUE    true
  56. #endif /* ndef TRUE */
  57.  
  58. #ifndef FALSE
  59. #define FALSE    false
  60. #endif /* ndef FALSE */
  61.  
  62. #ifndef NULL
  63. #define NULL    0L
  64. #endif /* ndef NULL */
  65.  
  66. /*----------------------------------------------------------------------*/
  67. /* Fast string macros - warning don't pass NULL to these! */
  68.  
  69. #define STREQ(s1,s2) ((*(s1)==*(s2)) && !strcmp(s1,s2))
  70. #define STRNCMP(s1,s2,n) \
  71.     ((*(s1)==*(s2)) ? strncmp(s1,s2,n) : (*(s1) - *(s2)))
  72.  
  73. /*----------------------------------------------------------------------*/
  74. /* convenience */
  75.  
  76. #define nl() printf("\n")
  77.  
  78. /*----------------------------------------------------------------------*/
  79. /* functions */
  80.  
  81. #ifdef __cplusplus
  82. /* declare these as C style functions */
  83. extern "C"
  84.     {
  85. #endif /* def __cplusplus */
  86.  
  87. /* enhanced memory handling functions - don't call them directly, use the
  88.    macros below */
  89. void    fs_checkPtr _AP((void* ptr));
  90. void*    fs_malloc _AP((size_t size));
  91. void*    fs_realloc _AP((void* ptr,size_t size));
  92. void    fs_free _AP((void* ptr));
  93. char*     fs_strncat _AP((char* dst,char* src,size_t maxToAdd,size_t maxTotal));
  94.  
  95. /* macros for memory functions.  call these in your program.  */
  96. #define s_checkPtr(ptr)     fs_checkPtr(ptr)
  97. #define s_malloc(size)              fs_malloc(size)
  98. #define s_realloc(ptr,size)    fs_realloc((ptr),(size))
  99. #define s_free(ptr)        { fs_free((char*)ptr); ptr = NULL; }
  100. #define s_strncat(dst,src,maxToAdd,maxTotal)    fs_strncat((dst),(src),(maxToAdd),(maxTotal))
  101.  
  102. char*     s_strdup _AP((char* s));
  103.  
  104. char*    strtokf _AP((char* s1,long (*isDelimiter)(long c))); 
  105.  
  106. #define IS_DELIMITER    1
  107. #define    NOT_DELIMITER    !IS_DELIMITER
  108.  
  109. #ifdef ANSI_LIKE    /* use ansi */
  110. long        cprintf _AP((boolean print,char* format,...));
  111. #else /* use K & R */
  112. long        cprintf _AP(());
  113. #endif
  114.  
  115. #ifdef ANSI_LIKE    /* use ansi */
  116. void        waislog _AP((long priority, long message, char* format,...));
  117. #else /* use K & R */
  118. #ifdef BSD
  119.  
  120. #define waislog printf("\n%d: %s ", getpid(), printable_time()); printf
  121.  
  122. #else
  123. void        waislog _AP(());
  124. #endif /* BSD */
  125. #endif /* ANSI_LIKE */
  126.  
  127. /* waislog priorities and messages */
  128. #define WLOG_HIGH    9
  129. #define WLOG_MEDIUM     5
  130. #define WLOG_LOW    1
  131.  
  132. #define WLOG_CONNECT    1
  133. #define WLOG_CLOSE    2
  134. #define WLOG_SEARCH    3
  135. #define WLOG_RESULTS    4
  136. #define WLOG_RETRIEVE    5
  137. #define WLOG_INDEX    6
  138. #define WLOG_INFO    100
  139. #define WLOG_ERROR    -1
  140.  
  141. void     warn _AP((char* message));
  142.  
  143. boolean substrcmp _AP((char *string1, char *string2));
  144. #ifndef MAX
  145. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  146. #endif
  147. #ifndef MIN
  148. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  149. #endif
  150. #define ABS(x) (((x) < 0) ? (-(x)) : (x))
  151.  
  152. char *printable_time _AP((void));
  153.  
  154. char char_downcase _AP((unsigned long ch));
  155. char *string_downcase _AP((char* word));
  156.  
  157.  
  158. char *next_arg _AP((int *argc, char ***argv));
  159. char *peek_arg _AP((int *argc, char ***argv));
  160.  
  161. void        beFriendly _AP((void));
  162.  
  163. #ifdef __cplusplus
  164.     }
  165. #endif /* def __cplusplus */
  166.  
  167. /*----------------------------------------------------------------------*/
  168.  
  169. #endif /* ndef _H_C_util_ */
  170.