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