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