HTUtils.h
上传用户:zlh9724
上传日期:2007-01-04
资源大小:1991k
文件大小:10k
源码类别:

浏览器

开发平台:

Unix_Linux

  1. /*                                                                             Utility macros
  2.                                   GENERAL PURPOSE MACROS
  3.                                              
  4.  */
  5. /*
  6. **      (c) COPYRIGHT MIT 1995.
  7. **      Please first read the full copyright statement in the file COPYRIGH.
  8. */
  9. /*
  10.    This module is a part of the  W3C Reference Library. See also the system dependent file
  11.    tcp module for system specific information.
  12.    
  13.  */
  14. #ifndef HTUTILS_H
  15. #define HTUTILS_H
  16. /*
  17. Are we using Standard Code?
  18.    We hopefully are...
  19.    
  20.  */
  21. #if defined(__STDC__) || defined(__cplusplus) || defined(WWW_MSWINDOWS)
  22. #define _STANDARD_CODE_
  23. #endif
  24. /*
  25. Debug Message Control
  26.    This is the global flag for setting the WWWTRACE options. The verbose mode is no longer
  27.    a simple boolean but a bit field so that it is possible to see parts of the output
  28.    messages.
  29.    
  30.  */
  31. #ifndef DEBUG
  32. #define DEBUG   /* No one ever turns this off as trace is too important */
  33. #endif
  34. /*
  35.   DEFINITION OF THE GLOBAL TRACE FLAG
  36.   
  37.    The global trace flag variable is available everywhere.
  38.    
  39.  */
  40. #ifdef DEBUG
  41. #ifdef WWW_WIN_DLL
  42. extern int *            WWW_TraceFlag;   /* In DLLs, we need the indirection */
  43. #define WWWTRACE        (*WWW_TraceFlag)
  44. #else
  45. extern int              WWW_TraceFlag;       /* Global flag for all W3 trace */
  46. #define WWWTRACE        (WWW_TraceFlag)
  47. #endif /* WWW_WIN_DLL */
  48. #else
  49. #define WWWTRACE        0
  50. #endif /* DEBUG */
  51. /*
  52.    The WWWTRACE define outputs messages if verbose mode is active according to the
  53.    following rules:
  54.    
  55.  */
  56. typedef enum _HTTraceFlags {
  57.     SHOW_UTIL_TRACE     = 0x1,                          /*                 1 */
  58.     SHOW_APP_TRACE      = 0x2,                          /*                10 */
  59.     SHOW_CACHE_TRACE    = 0x4,                          /*               100 */
  60.     SHOW_SGML_TRACE     = 0x8,                          /*              1000 */
  61.     SHOW_BIND_TRACE     = 0x10,                         /*            1.0000 */
  62.     SHOW_THREAD_TRACE   = 0x20,                         /*           10.0000 */
  63.     SHOW_STREAM_TRACE   = 0x40,                         /*          100.0000 */
  64.     SHOW_PROTOCOL_TRACE = 0x80,                         /*         1000.0000 */
  65.     SHOW_MEM_TRACE      = 0x100,                        /*       1.0000.0000 */
  66.     SHOW_URI_TRACE      = 0x200,                        /*      10.0000.0000 */
  67.     SHOW_ANCHOR_TRACE   = 0x800,                        /*   10.00.0000.0000 */
  68.     SHOW_ALL_TRACE      = 0xFFF                         /*   11.11.1111.1111 */
  69. } HTTraceFlags;
  70. /*
  71.    The flags are made so that they can serve as a group flag for correlated trace
  72.    messages, e.g. showing messages for SGML and HTML at the same time.
  73.    
  74.  */
  75. #define UTIL_TRACE      (WWWTRACE & SHOW_UTIL_TRACE)
  76. #define APP_TRACE       (WWWTRACE & SHOW_APP_TRACE)
  77. #define CACHE_TRACE     (WWWTRACE & SHOW_CACHE_TRACE)
  78. #define SGML_TRACE      (WWWTRACE & SHOW_SGML_TRACE)
  79. #define BIND_TRACE      (WWWTRACE & SHOW_BIND_TRACE)
  80. #define THD_TRACE       (WWWTRACE & SHOW_THREAD_TRACE)
  81. #define STREAM_TRACE    (WWWTRACE & SHOW_STREAM_TRACE)
  82. #define PROT_TRACE      (WWWTRACE & SHOW_PROTOCOL_TRACE)
  83. #define MEM_TRACE       (WWWTRACE & SHOW_MEM_TRACE)
  84. #define URI_TRACE       (WWWTRACE & SHOW_URI_TRACE)
  85. #define ANCH_TRACE      (WWWTRACE & SHOW_ANCHOR_TRACE)
  86. /*
  87.   DESTINATION FOR TRACE MESSAGES
  88.   
  89.    You can send trace messages to various destinations depending on the type of your
  90.    application. By default, on Unix the messages are sent to stderr using fprintf() and if
  91.    we are on Windows and have a windows applications then use the TTYPrint function.
  92.    
  93.  */
  94. #define WWWTRACE_FILE   1               /* Output to file */
  95. #define WWWTRACE_STDERR 2               /* Output to stderr */
  96. #define WWWTRACE_TTY    3               /* Output to TTY */
  97. #ifndef WWWTRACE_MODE
  98. #ifdef WWW_WIN_WINDOW
  99. #define WWWTRACE_MODE WWWTRACE_TTY
  100. #else
  101. #define WWWTRACE_MODE WWWTRACE_STDERR
  102. #endif
  103. #endif
  104. #if WWWTRACE_MODE == WWWTRACE_FILE
  105. extern FILE *WWWTrace;
  106. #ifndef HT_TRACE_FILE
  107. #define HT_TRACE_FILE   "WWWTRACE.TXT"
  108. #endif
  109. #define TTYPrint fprintf
  110. #define TDEST    WWWTrace
  111. #endif
  112. #if WWWTRACE_MODE == WWWTRACE_STDERR
  113. #define TTYPrint fprintf
  114. #define TDEST    stderr
  115. #endif
  116. #if WWWTRACE_MODE == WWWTRACE_TTY
  117. #ifdef WWW_WIN_WINDOW
  118. /* standard windows 3.x and non-console WIN32 programs */
  119. #define TDEST    0
  120. #ifdef WWW_WIN_DLL
  121. typedef int TTYPrint_t(unsigned int target, const char* fmt, ...);
  122. extern TTYPrint_t** PTTYPrint;
  123. #define TTYPrint (**PTTYPrint)
  124. #else
  125. int TTYPrint(unsigned int target, const char* fmt, ...);
  126. #endif
  127. #else
  128. /* if there is a real console, us it */
  129. #define TDEST    stderr
  130. int TTYPrint(FILE* target, const char* fmt, ...);
  131. #endif
  132. #endif
  133. /*
  134. Standard C library for malloc() etc
  135.    Replace memory allocation and free C RTL functions with VAXC$xxx_OPT alternatives for
  136.    VAXC (but not DECC) on VMS. This makes a big performance difference. (Foteos Macrides).
  137.    Also have a look at the Dynamic Memory Module for how to handle malloc and calloc.
  138.    
  139.  */
  140. #ifdef vax
  141. #ifdef unix
  142. #define ultrix  /* Assume vax+unix=ultrix */
  143. #endif
  144. #endif
  145. #ifndef VMS
  146. #ifndef ultrix
  147. #ifdef NeXT
  148. #include <libc.h>       /* NeXT */
  149. #endif
  150. #ifndef Mips
  151. #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
  152. #include <stdlib.h>     /* ANSI */
  153. #endif
  154. #endif
  155. #else /* ultrix */
  156. #include <malloc.h>
  157. #include <memory.h>
  158. #include <stdio.h>
  159. #include <stdlib.h>   /* ANSI */   /* BSN */
  160. #endif
  161. #else   /* VMS */
  162. #include <stdio.h>
  163. #include <stdlib.h>
  164. #include <unixlib.h>
  165. #include <ctype.h>
  166. #if defined(VAXC) && !defined(__DECC)
  167. #define malloc  VAXC$MALLOC_OPT
  168. #define calloc  VAXC$CALLOC_OPT
  169. #define free    VAXC$FREE_OPT
  170. #define cfree   VAXC$CFREE_OPT
  171. #define realloc VAXC$REALLOC_OPT
  172. #endif /* VAXC but not DECC */
  173. #define unlink remove
  174. #define gmtime localtime
  175. #include <stat.h>
  176. #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
  177. #define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
  178. #define putenv HTVMS_putenv
  179. #endif
  180. /*
  181. Macros for Function Declarations
  182.  */
  183. #define PUBLIC                  /* Accessible outside this module     */
  184. #define PRIVATE static          /* Accessible only within this module */
  185. #ifdef _STANDARD_CODE_
  186. #if defined(sco) && !defined(_SCO_DS)
  187. #define CONST             /* The pre SCO 5.0 CC compiler does not know const */
  188. #else
  189. #define CONST const                           /* "const" only exists in STDC */
  190. #endif
  191. #else
  192. #define CONST
  193. #endif /* _STANDARD_CODE_ (ANSI) */
  194. /*
  195. Variable Argument Functions
  196.    This is normally one of the more tricky part in portable code as it very often doesn't
  197.    work. If you are going to use it then watch out!
  198.    
  199.  */
  200. #ifdef _STANDARD_CODE_
  201. #include <stdarg.h>
  202. #else
  203. #include <varargs.h>
  204. #endif
  205. /*
  206. Booleans
  207.  */
  208. #ifndef BOOLEAN_DEFINED
  209. typedef char    BOOLEAN;                                    /* Logical value */
  210. #endif
  211. #ifndef CURSES
  212. #ifndef TRUE
  213. #define TRUE    (BOOLEAN)1
  214. #define FALSE   (BOOLEAN)0
  215. #endif
  216. #endif   /*  CURSES  */
  217. #ifndef BOOL
  218. #define BOOL BOOLEAN
  219. #endif
  220. #ifndef YES
  221. #define YES             (BOOL)1
  222. #define NO              (BOOL)0
  223. #endif
  224. /*
  225. NULL Definition
  226.  */
  227. #ifndef NULL
  228. #define NULL ((void *)0)
  229. #endif
  230. /*
  231. Often used Interger Macros
  232.   MIN AND MAX FUNCTIONS
  233.   
  234.  */
  235. #ifndef HTMIN
  236. #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
  237. #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
  238. #endif
  239. /*
  240.   DOUBLE ABS FUNCTION
  241.   
  242.  */
  243. #ifndef HTDABS
  244. #define HTDABS(a) ((a) < 0.0 ? (-(a)) : (a))
  245. #endif
  246. /*
  247. Return Codes for Protocol Modules and Streams
  248.    Theese are the codes returned from the protocol modules, and the stream modules.
  249.    Success are (>=0) and failure are (<0)
  250.    
  251.  */
  252. #define HT_OK                   0       /* Generic success */
  253. #define HT_ALL                  1       /* Used by Net Manager */
  254. #define HT_CLOSED               29992   /* The socket was closed */
  255. #define HT_PERSISTENT           29993   /* Wait for persistent connection */
  256. #define HT_IGNORE               29994   /* Ignore this in the Net manager */
  257. #define HT_NO_DATA              29995   /* OK but no data was loaded */
  258. #define HT_RELOAD               29996   /* If we must reload the document */
  259. #define HT_PERM_REDIRECT        29997   /* Redo the retrieve with a new URL */
  260. #define HT_TEMP_REDIRECT        29998   /* Redo the retrieve with a new URL */
  261. #define HT_LOADED               29999   /* Instead of a socket */
  262. #define HT_ERROR                -1      /* Generic failure */
  263. #define HT_NO_ACCESS            -10     /* Access not available */
  264. #define HT_FORBIDDEN            -11     /* Access forbidden */
  265. #define HT_RETRY                -13     /* If service isn't available */
  266. #define HT_INTERNAL             -100    /* Weird -- should never happen. */
  267. #define HT_WOULD_BLOCK          -29997  /* If we are in a select */
  268. #define HT_INTERRUPTED          -29998  /* Note the negative value! */
  269. #define HT_PAUSE                -29999  /* If we want to pause a stream */
  270. /*
  271. Upper- and Lowercase macros
  272.    The problem here is that toupper(x) is not defined officially unless isupper(x) is.
  273.    These macros are CERTAINLY needed on #if defined(pyr) || define(mips) or BDSI
  274.    platforms. For safefy, we make them mandatory.
  275.    
  276.  */
  277. #include <ctype.h>
  278. #ifndef TOLOWER
  279. #define TOLOWER(c) tolower(c)
  280. #define TOUPPER(c) toupper(c)
  281. #endif
  282. /*
  283. Max and Min values for Integers and Floating Point
  284.  */
  285. #ifdef FLT_EPSILON                                  /* The ANSI C way define */
  286. #define HT_EPSILON FLT_EPSILON
  287. #else
  288. #define HT_EPSILON 0.00000001
  289. #endif
  290. /*
  291. White Characters
  292.    Is character c white space?
  293.    
  294.  */
  295. #define WHITE(c) isspace(c)
  296. /*
  297. The local equivalents of CR and LF
  298.    We can check for these after net ascii text has been converted to the local
  299.    representation. Similarly, we include them in strings to be sent as net ascii after
  300.    translation.
  301.    
  302.  */
  303. #define LF   FROMASCII('12')  /* ASCII line feed LOCAL EQUIVALENT */
  304. #define CR   FROMASCII('15')  /* Will be converted to ^M for transmission */
  305. /*
  306. Library Dynamic Memory Magement
  307.    The Library has it's own dynamic memory API which is declared in memory management
  308.    module.
  309.    
  310.  */
  311. #include "HTMemory.h"
  312. /*
  313.  */
  314. #endif /* HT_UTILS.h */
  315. /*
  316.    End of utility declarations */