Annotation of libwww/Library/src/HTUtils.html, revision 2.35
2.6 timbl 1: <HTML>
2: <HEAD>
2.35 ! frystyk 3: <TITLE>Utility macros</TITLE>
! 4: <!-- Changed by: Henrik Frystyk Nielsen, 16-Aug-1995 -->
2.6 timbl 5: </HEAD>
2.3 timbl 6: <BODY>
2.24 frystyk 7:
2.20 frystyk 8: <H1>Macros for general use</H1>
9:
2.24 frystyk 10: <PRE>
11: /*
2.31 frystyk 12: ** (c) COPYRIGHT MIT 1995.
2.24 frystyk 13: ** Please first read the full copyright statement in the file COPYRIGH.
14: */
15: </PRE>
16:
17: This module is a part of the <A
2.33 frystyk 18: HREF="http://www.w3.org/hypertext/WWW/Library/">
19: W3C Reference Library</A>.
2.20 frystyk 20:
2.26 frystyk 21: See also the system dependent file <A HREF="tcp.html">tcp module</A>
22: for system specific information. <P>
23:
2.1 timbl 24: <PRE>
25: #ifndef HTUTILS_H
26: #define HTUTILS_H
27:
2.26 frystyk 28: #if defined(__STDC__) || defined(__cplusplus) || defined(_WINDOWS)
29: #define _STANDARD_CODE_
2.1 timbl 30: #endif
2.20 frystyk 31: </PRE>
32:
33: <H2>Debug message control</H2>
34:
35: This is the global flag for setting the TRACE options.
36:
37: <PRE>
2.26 frystyk 38: #ifndef DEBUG
39: #define DEBUG /* No one ever turns this off as trace is too important */
40: #endif /* Keep option for really small memory applications too */
41:
2.20 frystyk 42: extern int WWW_TraceFlag; /* Global flag for all W3 trace */
43: </PRE>
44:
45: The verbose mode is no longer a simple boolean but a bit field so that it is
46: possible to see parts of the output messages. The <EM>TRACE</EM> define still
47: outputs all messages if verbose mode is active, but in addition the following
48: TRACE defines have been made:
2.1 timbl 49:
2.20 frystyk 50: <PRE>
2.26 frystyk 51: #ifdef NO_STDIO
52: extern FILE *WWWTrace;
53: #ifndef TRACE_FILE
54: #define TRACE_FILE "WWWTRACE.TXT"
55: #endif
56: #define TDEST WWWTrace
57: #else /* got stdio */
58: #define TDEST stderr
59: #endif
60:
2.20 frystyk 61: typedef enum _HTTraceFlags {
2.32 frystyk 62: SHOW_CACHE_TRACE = 0x2, /* 10 */
63: SHOW_SGML_TRACE = 0x8, /* 1000 */
2.29 frystyk 64: SHOW_BIND_TRACE = 0x10, /* 1.0000 */
2.32 frystyk 65: SHOW_THREAD_TRACE = 0x20, /* 10.0000 */
2.27 frystyk 66: SHOW_STREAM_TRACE = 0x40, /* 100.0000 */
2.32 frystyk 67: SHOW_PROTOCOL_TRACE = 0x80, /* 1000.0000 */
68: SHOW_URI_TRACE = 0x200, /* 10.0000.0000 */
69: SHOW_ANCHOR_TRACE = 0x800, /* 10.00.0000.0000 */
2.20 frystyk 70: SHOW_ALL_TRACE = 0xFFF /* 11.11.1111.1111 */
71: } HTTraceFlags;
72: </PRE>
73:
74: The flags are made so that they can serve as a group flag for correlated
75: trace messages, e.g. showing messages for SGML and HTML at the same time.
76:
77: <PRE>
2.1 timbl 78: #ifdef DEBUG
2.20 frystyk 79: #define TRACE (WWW_TraceFlag)
2.27 frystyk 80: #define CACHE_TRACE (WWW_TraceFlag & SHOW_CACHE_TRACE)
2.20 frystyk 81: #define SGML_TRACE (WWW_TraceFlag & SHOW_SGML_TRACE)
2.29 frystyk 82: #define BIND_TRACE (WWW_TraceFlag & SHOW_BIND_TRACE)
2.23 frystyk 83: #define THD_TRACE (WWW_TraceFlag & SHOW_THREAD_TRACE)
2.27 frystyk 84: #define STREAM_TRACE (WWW_TraceFlag & SHOW_STREAM_TRACE)
2.20 frystyk 85: #define PROT_TRACE (WWW_TraceFlag & SHOW_PROTOCOL_TRACE)
86: #define URI_TRACE (WWW_TraceFlag & SHOW_URI_TRACE)
87: #define ANCH_TRACE (WWW_TraceFlag & SHOW_ANCHOR_TRACE)
2.1 timbl 88: #else
2.20 frystyk 89: #define TRACE 0
2.29 frystyk 90: #define CACHE_TRACE 0
2.20 frystyk 91: #define SGML_TRACE 0
2.29 frystyk 92: #define BIND_TRACE 0
2.27 frystyk 93: #define THD_TRACE 0
94: #define STREAM_TRACE 0
2.20 frystyk 95: #define PROT_TRACE 0
96: #define URI_TRACE 0
97: #define ANCH_TRACE 0
2.1 timbl 98: #endif
2.20 frystyk 99: </PRE>
100:
2.26 frystyk 101: <EM><B>Note: </B> The CTRACE flag might interfere with other if ()
102: else constructions in the code. IT SHOULD NOT BE USED BUT REPLACED BY
103: TRACE</EM>
2.1 timbl 104:
2.20 frystyk 105: <PRE>
106: #define CTRACE if(TRACE) fprintf
107: </PRE>
2.1 timbl 108:
2.20 frystyk 109: <H2>Error type</H2>
2.17 frystyk 110:
111: THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>
112:
113: This is passed back when streams
2.6 timbl 114: are aborted. It might be nice to
115: have some structure of error messages,
116: numbers, and recursive pointers to
117: reasons. Curently this is a placeholder
118: for something more sophisticated.
119: <PRE>typedef void * HTError; /* Unused at present -- best definition? */
2.3 timbl 120: </PRE>
2.26 frystyk 121:
122: <H2>Standard C library for malloc() etc</H2>
123:
124: Replace memory allocation and free C RTL functions with VAXC$xxx_OPT
125: altrenatives for VAXC (but not DECC) on VMS. This makes a big
126: performance difference. (Foteos Macrides).
127:
128: <PRE>
129: #ifdef vax
130: #ifdef unix
131: #define ultrix /* Assume vax+unix=ultrix */
132: #endif
133: #endif
134:
135: #ifndef VMS
136: #ifndef ultrix
137: #ifdef NeXT
138: #include <libc.h> /* NeXT */
139: #endif
140:
141: #ifndef Mips
142: #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
143: #include <stdlib.h> /* ANSI */
144: #endif
145: #endif
146:
147: #else /* ultrix */
148: #include <malloc.h>
149: #include <memory.h>
150: #include <stdio.h>
151: #include <stdlib.h> /* ANSI */ /* BSN */
152: #endif
153:
154: #else /* VMS */
155: #include <stdio.h>
156: #include <stdlib.h>
157: #include <unixlib.h>
158: #include <ctype.h>
159: #if defined(VAXC) && !defined(__DECC)
160: #define malloc VAXC$MALLOC_OPT
161: #define calloc VAXC$CALLOC_OPT
162: #define free VAXC$FREE_OPT
163: #define cfree VAXC$CFREE_OPT
164: #define realloc VAXC$REALLOC_OPT
165: #endif /* VAXC but not DECC */
166: #define unlink remove
167: #define gmtime localtime
168: #include <stat.h>
169: #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
170: #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
171: #define putenv HTVMS_putenv
172: #endif
173: </PRE>
174:
2.29 frystyk 175: <H3>Safe Cleaning Memory</H3>
176:
177: <PRE>
178: #define FREE(x) if (x) {free(x); x=NULL;}
179: </PRE>
180:
181: <A NAME="declaration"><H2>Macros for declarations</H2></A>
2.26 frystyk 182:
183: <PRE>
184: #define PUBLIC /* Accessible outside this module */
2.1 timbl 185: #define PRIVATE static /* Accessible only within this module */
186:
2.26 frystyk 187: #ifdef _STANDARD_CODE_
188:
2.34 frystyk 189: /* The sco ODT 3.0 CC compiler has some trouble with const */
190: #if !defined(sco) || defined(sco_os5)
2.26 frystyk 191: #define CONST const /* "const" only exists in STDC */
192: #else
193: #define CONST
194: #endif
195:
2.1 timbl 196: #define NOPARAMS (void)
197: #define PARAMS(parameter_list) parameter_list
198: #define NOARGS (void)
199: #define ARGS1(t,a) \
200: (t a)
201: #define ARGS2(t,a,u,b) \
202: (t a, u b)
203: #define ARGS3(t,a,u,b,v,c) \
204: (t a, u b, v c)
205: #define ARGS4(t,a,u,b,v,c,w,d) \
206: (t a, u b, v c, w d)
207: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
208: (t a, u b, v c, w d, x e)
209: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
210: (t a, u b, v c, w d, x e, y f)
211: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
212: (t a, u b, v c, w d, x e, y f, z g)
213: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
214: (t a, u b, v c, w d, x e, y f, z g, s h)
215: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
216: (t a, u b, v c, w d, x e, y f, z g, s h, r i)
217: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
218: (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
219:
220: #else /* not ANSI */
221:
2.26 frystyk 222: #define CONST
223:
2.1 timbl 224: #define NOPARAMS ()
225: #define PARAMS(parameter_list) ()
226: #define NOARGS ()
227: #define ARGS1(t,a) (a) \
228: t a;
229: #define ARGS2(t,a,u,b) (a,b) \
230: t a; u b;
231: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
232: t a; u b; v c;
233: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
234: t a; u b; v c; w d;
235: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
236: t a; u b; v c; w d; x e;
237: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
238: t a; u b; v c; w d; x e; y f;
239: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
240: t a; u b; v c; w d; x e; y f; z g;
241: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) (a,b,c,d,e,f,g,h) \
242: t a; u b; v c; w d; x e; y f; z g; s h;
243: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) (a,b,c,d,e,f,g,h,i) \
244: t a; u b; v c; w d; x e; y f; z g; s h; r i;
245: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) (a,b,c,d,e,f,g,h,i,j) \
2.4 timbl 246: t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1 timbl 247:
248:
2.21 frystyk 249: #endif /* _STANDARD_CODE_ (ANSI) */
2.1 timbl 250:
251: #ifndef NULL
252: #define NULL ((void *)0)
253: #endif
2.26 frystyk 254: </PRE>
2.1 timbl 255:
2.3 timbl 256: <H2>Booleans</H2>
2.26 frystyk 257:
258: <PRE>
2.30 frystyk 259: #ifndef BOOLEAN_DEFINED
2.26 frystyk 260: typedef char BOOLEAN; /* Logical value */
2.30 frystyk 261: #endif
2.1 timbl 262:
263: #ifndef CURSES
264: #ifndef TRUE
265: #define TRUE (BOOLEAN)1
266: #define FALSE (BOOLEAN)0
267: #endif
2.3 timbl 268: #endif /* CURSES */
2.1 timbl 269:
270: #ifndef BOOL
271: #define BOOL BOOLEAN
272: #endif
273: #ifndef YES
2.14 timbl 274: #define YES (BOOL)1
275: #define NO (BOOL)0
2.1 timbl 276: #endif
277:
2.11 timbl 278: #ifndef HTMIN
279: #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
280: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1 timbl 281: #endif
282:
283: #define TCP_PORT 80 /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
284: #define OLD_TCP_PORT 2784 /* Try the old one if no answer on 80 */
285: #define DNP_OBJ 80 /* This one doesn't look busy, but we must check */
2.3 timbl 286: /* That one was for decnet */
2.26 frystyk 287: </PRE>
2.1 timbl 288:
2.35 ! frystyk 289: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules and Streams</H2></A>
! 290:
! 291: Theese are the codes returned from the protocol modules, and the
! 292: stream modules. Success are (>=0) and failure are (<0)
2.1 timbl 293:
2.3 timbl 294: <PRE>
2.23 frystyk 295: #define HT_OK 0 /* Generic success */
2.35 ! frystyk 296: #define HT_NO_DATA 29997 /* OK but no data was loaded */
! 297: #define HT_REDIRECTION_ON_FLY 29998 /* Redo the retrieve with a new URL */
2.23 frystyk 298: #define HT_LOADED 29999 /* Instead of a socket */
299:
300: #define HT_ERROR -1 /* Generic failure */
301: #define HT_NO_ACCESS -10 /* Access not available */
302: #define HT_FORBIDDEN -11 /* Access forbidden */
303: #define HT_INTERNAL -12 /* Weird -- should never happen. */
2.35 ! frystyk 304:
! 305: #define HT_RETRY -29996 /* If service isn't available */
2.23 frystyk 306: #define HT_WOULD_BLOCK -29997 /* If we are in a select */
2.15 frystyk 307: #define HT_INTERRUPTED -29998 /* Note the negative value! */
2.35 ! frystyk 308: </PRE>
! 309:
! 310: The following codes are positive values that will be parsed back
! 311: through streams. This can be used to introduce stream specific return
! 312: values
2.1 timbl 313:
2.35 ! frystyk 314: <PRE>
! 315: #define HT_RELOAD 29996 /* If we must reload the document */
! 316: </PRE>
! 317:
! 318: <H2>Other stuff</H2>
! 319:
! 320: <PRE>
2.26 frystyk 321: #ifdef _STANDARD_CODE_
322: #include <stdarg.h>
323: #else
324: #include <varargs.h>
325: #endif
2.1 timbl 326:
327: #ifdef CURSES
2.26 frystyk 328: /* htbrowse.c; */
329: #ifdef ULTRIX /* or DECSTATION */
330: #include <cursesX.h> /* Extended curses under X. Only decent one :lou. */
331: #else
332: #include <curses.h>
333: #endif /* ULTRIX */
2.1 timbl 334: extern WINDOW *w_top, *w_text, *w_prompt;
335: extern void user_message PARAMS((const char *fmt, ...));
336: extern void prompt_set PARAMS((CONST char * msg));
337: extern void prompt_count PARAMS((long kb));
338: #else
339: #define user_message printf
340: #endif
341:
2.3 timbl 342: </PRE>
2.26 frystyk 343:
344: <H2>Out Of Memory checking for malloc() return:</H2>
345:
346: <PRE>
347: #ifndef __FILE__
2.1 timbl 348: #define __FILE__ ""
349: #define __LINE__ ""
350: #endif
351:
352: #define outofmem(file, func) \
2.26 frystyk 353: { fprintf(TDEST, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
2.1 timbl 354: exit(1);}
355:
2.26 frystyk 356: </PRE>
2.1 timbl 357:
2.26 frystyk 358: <H2>Upper- and Lowercase macros</H2>
359:
360: The problem here is that toupper(x) is not defined officially unless
361: isupper(x) is. These macros are CERTAINLY needed on #if defined(pyr)
362: || define(mips) or BDSI platforms. For safefy, we make them mandatory.
2.1 timbl 363:
2.25 roeber 364: <PRE>
2.26 frystyk 365: #include <ctype.h>
2.1 timbl 366:
367: #ifndef TOLOWER
2.27 frystyk 368: #define TOLOWER(c) tolower(c)
369: #define TOUPPER(c) toupper(c)
2.29 frystyk 370: #endif
371: </PRE>
372:
373: <H2>Max and Min values for Integers and Floating Point</H2>
374:
375: <PRE>
376: #ifdef FLT_EPSILON /* The ANSI C way define */
377: #define HT_EPSILON FLT_EPSILON
378: #else
379: #define HT_EPSILON 0.00000001
2.27 frystyk 380: #endif
381: </PRE>
382:
383: <H2>White Characters</H2>
384:
385: Is character <B>c</B> white space?
386:
387: <PRE>
388: #ifdef OLD_CODE
389: #define WHITE(c) (((unsigned char)(TOASCII(c))) <= 32)
390: #else
391: #define WHITE(c) isspace(c)
392: #endif
2.26 frystyk 393: </PRE>
394:
395: <H2>The local equivalents of CR and LF</H2>
2.1 timbl 396:
2.26 frystyk 397: We can check for these after net ascii text has been converted to the
398: local representation. Similarly, we include them in strings to be sent
399: as net ascii after translation.
400:
401: <PRE>
402: #define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */
403: #define CR FROMASCII('\015') /* Will be converted to ^M for transmission */
2.6 timbl 404:
2.1 timbl 405: #endif /* HTUTILS_H */
2.26 frystyk 406: </PRE>
2.1 timbl 407:
2.26 frystyk 408: end of utilities
409: </BODY>
2.6 timbl 410: </HTML>
Webmaster