home *** CD-ROM | disk | FTP | other *** search
/ Internet Publisher's Toolbox 2.0 / Internet Publisher's Toolbox.iso / internet / ntserver / wtsource / cutil.h < prev    next >
Encoding:
C/C++ Source or Header  |  1994-11-14  |  6.1 KB  |  227 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.  * $Log: cutil.h,v $
  9.  * Revision 1.1  1993/02/16  15:05:35  freewais
  10.  * Initial revision
  11.  *
  12.  * Revision 1.19  92/03/07  19:44:24  jonathan
  13.  * Added some IBM defines. mycroft@hal.gnu.ai.mit.edu.
  14.  * 
  15.  * Revision 1.18  92/02/21  11:01:07  jonathan
  16.  * Added wais_log_level
  17.  * 
  18.  * Revision 1.17  92/02/16  21:24:25  jonathan
  19.  * Removed macro for waislog under BSD, since vprintf is now part of cutil.c
  20.  * 
  21.  *
  22.  */
  23.  
  24. /* Copyright (c) CNIDR (see ../COPYRIGHT) */
  25.  
  26.  
  27. #ifndef _H_C_util_
  28. #define _H_C_util_
  29.  
  30. #include "cdialect.h"
  31.  
  32. #if defined(ANSI_LIKE) || defined(PROTO_ANSI)
  33. #include <stdarg.h>
  34. #else /* ndef ANSI_LIKE */
  35. #include <varargs.h>
  36. #endif /* ndef ANSI_LIKE */
  37.  
  38. #include <stdio.h>   /* this used to be wrapped in an ifndef NULL, 
  39.             but messed up on some gcc's */
  40. #if defined(THINK_C) || defined(_IBMR2) || defined(WIN32)
  41. #include <time.h>
  42. #endif
  43. #if !defined(THINK_C) && !defined(WIN32)
  44. #include <sys/time.h>
  45. #endif
  46.  
  47. #define MAX_FILENAME_LEN 255
  48. #define MAX_DELIMITERS 256
  49.  
  50. #ifdef ANSI_LIKE
  51. #ifndef EXIT_SUCCESS /* only include it if not already included */
  52. #include <stdlib.h> /* this is a shame */
  53. #endif /* ndef EXIT_SUCCESS */
  54. #else   
  55. #include "ustubs.h"
  56. #endif /* else */
  57.  
  58. /*----------------------------------------------------------------------*/
  59. /* types and constants */
  60.  
  61. #ifndef boolean
  62. #define boolean unsigned long
  63. #endif /* ndef boolean */ 
  64.  
  65. #ifndef THINK_C
  66. #ifndef Boolean
  67. #define Boolean boolean
  68. #endif /* ndef Boolean */ 
  69. #endif /* ndef THINK_C */
  70.  
  71. #ifndef true
  72. #define true    (boolean)1L
  73. #endif /* ndef true */
  74.  
  75. #ifndef false
  76. #define false   (boolean)0L   /* used to be (!true), but broke 
  77.                  some compilers */
  78. #endif /* ndef false */
  79.  
  80. #ifndef TRUE
  81. #define TRUE    true
  82. #endif /* ndef TRUE */
  83.  
  84. #ifndef FALSE
  85. #define FALSE   false
  86. #endif /* ndef FALSE */
  87.  
  88. #ifndef NULL
  89. #define NULL    0L
  90. #endif /* ndef NULL */
  91.  
  92. /*----------------------------------------------------------------------*/
  93. /* Fast string macros - warning don't pass NULL to these! */
  94.  
  95. #define STREQ(s1,s2) ((*(s1)==*(s2)) && !strcmp(s1,s2))
  96. #define STRNCMP(s1,s2,n) \
  97.     ((*(s1)==*(s2)) ? strncmp(s1,s2,n) : (*(s1) - *(s2)))
  98.  
  99. /*----------------------------------------------------------------------*/
  100. /* convenience */
  101.  
  102. #define NL() printf("\n")
  103.  
  104. /*----------------------------------------------------------------------*/
  105. /* functions */
  106.  
  107. #ifdef __cplusplus
  108. /* declare these as C style functions */
  109. extern "C"
  110.     {
  111. #endif /* def __cplusplus */
  112.  
  113. /* enhanced memory handling functions - don't call them directly, use the
  114.    macros below */
  115. void    fs_checkPtr _AP((void* ptr));
  116. void*   fs_malloc _AP((size_t size));
  117. void*   fs_realloc _AP((void* ptr,size_t size));
  118. void    fs_free _AP((void* ptr));
  119. char*   fs_strncat _AP((char* dst,char* src,size_t maxToAdd,size_t maxTotal));
  120. char*   fs_strncpy _AP((char* s1,char* s2, long n));
  121.  
  122. /* macros for memory functions.  call these in your program.  */
  123. #define s_checkPtr(ptr)     fs_checkPtr(ptr)
  124. #define s_malloc(size)          fs_malloc(size)
  125. #define s_realloc(ptr,size) fs_realloc((ptr),(size))
  126. #define s_free(ptr)     { fs_free((char*)ptr); ptr = NULL; }
  127. #define s_strncat(dst,src,maxToAdd,maxTotal)    fs_strncat((dst),(src),(maxToAdd),(maxTotal))
  128. #define s_strncpy(s1,s2,n) fs_strncpy((s1), (s2), (n))
  129.  
  130. char*   s_strdup _AP((char* s));
  131.  
  132. boolean wordbreak_notalnum _AP(( long ch));  /* dgg */
  133. boolean wordbreak_notgraph _AP(( long ch));  /* dgg */
  134. boolean wordbreak_user _AP(( long ch));  /* dgg, uses gDelimiters */
  135.  
  136. char*   strtokf _AP((char* s1,boolean (*isDelimiter)(long c))); 
  137. char* strtokf_isalnum _AP((char* s1));
  138.  
  139. #define IS_DELIMITER    true
  140. #define NOT_DELIMITER   false
  141.  
  142. #ifdef ANSI_LIKE    /* use ansi */
  143. long        cprintf _AP((boolean print,char* format,...));
  144. #else /* use K & R */
  145. long        cprintf _AP(());
  146. #endif
  147.  
  148. #ifdef ANSI_LIKE    /* use ansi */
  149. void        waislog _AP((long priority, long message, char* format,...));
  150. void        vwaislog _AP((long priority, long message, char *format, va_list));
  151. #else /* use K & R */
  152. void        waislog _AP(());
  153. void        vwaislog _AP(());
  154. #endif /* ANSI_LIKE */
  155.  
  156. /* waislog priorities and messages */
  157. /* this is backwards because of how wais_log_level works. */
  158. #define WLOG_HIGH   1
  159. #define WLOG_MEDIUM     5
  160. #define WLOG_LOW    9
  161.  
  162. #define WLOG_CONNECT    1
  163. #define WLOG_CLOSE  2
  164. #define WLOG_SEARCH 3
  165. #define WLOG_RESULTS    4
  166. #define WLOG_RETRIEVE   5
  167. #define WLOG_INDEX  6
  168. #define WLOG_INFO   100
  169. #define WLOG_ERROR  -1
  170. #define WLOG_WARNING    -2
  171.  
  172. void    warn _AP((char* message));
  173.  
  174. boolean substrcmp _AP((char *string1, char *string2));
  175. #ifndef MAX
  176. #define MAX(x,y) (((x) > (y)) ? (x) : (y))
  177. #endif
  178. #ifndef MIN
  179. #define MIN(x,y) (((x) < (y)) ? (x) : (y))
  180. #endif
  181. #define ABS(x) (((x) < 0) ? (-(x)) : (x))
  182.  
  183. char *printable_time _AP((void));
  184.  
  185. char char_downcase _AP((unsigned long ch));
  186. char *string_downcase _AP((char* word));
  187.  
  188.  
  189. char *next_arg _AP((int *argc, char ***argv));
  190. char *peek_arg _AP((int *argc, char ***argv));
  191.  
  192. void        beFriendly _AP((void));
  193.  
  194. #ifdef _C_C_util_
  195. long wais_pid = 0;
  196. long log_line = 0;
  197. long wais_log_level = 10;
  198. char gDelimiters[MAX_DELIMITERS];  /* dgg */
  199. char *log_file_name = NULL;
  200. FILE *logfile = NULL;
  201. #else
  202. extern long wais_pid;
  203. extern long log_line;
  204. extern wais_log_level;
  205. extern char gDelimiters[];  /* dgg */
  206. extern char *log_file_name;
  207. extern FILE *logfile;
  208. #endif /* _C_C_util_ */
  209.  
  210. #ifdef __cplusplus
  211.     }
  212. #endif /* def __cplusplus */
  213.  
  214. #ifdef USE_SYSLOG
  215. #define LOG_WAIS LOG_LOCAL5
  216. #endif
  217.  
  218. /*----------------------------------------------------------------------*/
  219.  
  220. #ifdef SOLARIS
  221. #define bzero(str,size) memset(str,0,size)
  222. #define bcopy(s,d,c) memcpy(d,s,c)
  223. #define index(str,c)  strchr(str,c)
  224. #define rindex(str,c) strrchr(str,c)
  225. #endif
  226. #endif /* ndef _H_C_util_ */
  227.