Annotation of libwww/Library/src/HTUtils.html, revision 2.39
2.6 timbl 1: <HTML>
2: <HEAD>
2.35 frystyk 3: <TITLE>Utility macros</TITLE>
2.39 ! frystyk 4: <!-- Changed by: Henrik Frystyk Nielsen, 9-Oct-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.36 frystyk 18: HREF="http://www.w3.org/pub/WWW/Library/">
2.33 frystyk 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:
2.39 ! frystyk 35: This is the global flag for setting the WWWTRACE options.
2.20 frystyk 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:
2.39 ! frystyk 45: The verbose mode is no longer a simple boolean but a bit field so that
! 46: it is possible to see parts of the output messages. The
! 47: <EM>WWWTRACE</EM> define still outputs all messages if verbose mode is
! 48: active, but in addition the following WWWTRACE 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.39 ! frystyk 79: #define WWWTRACE (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.39 ! frystyk 89: #define WWWTRACE 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>
2.1 timbl 100:
2.20 frystyk 101: <H2>Error type</H2>
2.17 frystyk 102:
103: THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>
104:
105: This is passed back when streams
2.6 timbl 106: are aborted. It might be nice to
107: have some structure of error messages,
108: numbers, and recursive pointers to
109: reasons. Curently this is a placeholder
110: for something more sophisticated.
111: <PRE>typedef void * HTError; /* Unused at present -- best definition? */
2.3 timbl 112: </PRE>
2.26 frystyk 113:
114: <H2>Standard C library for malloc() etc</H2>
115:
116: Replace memory allocation and free C RTL functions with VAXC$xxx_OPT
117: altrenatives for VAXC (but not DECC) on VMS. This makes a big
118: performance difference. (Foteos Macrides).
119:
120: <PRE>
121: #ifdef vax
122: #ifdef unix
123: #define ultrix /* Assume vax+unix=ultrix */
124: #endif
125: #endif
126:
127: #ifndef VMS
128: #ifndef ultrix
129: #ifdef NeXT
130: #include <libc.h> /* NeXT */
131: #endif
132:
133: #ifndef Mips
134: #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
135: #include <stdlib.h> /* ANSI */
136: #endif
137: #endif
138:
139: #else /* ultrix */
140: #include <malloc.h>
141: #include <memory.h>
142: #include <stdio.h>
143: #include <stdlib.h> /* ANSI */ /* BSN */
144: #endif
145:
146: #else /* VMS */
147: #include <stdio.h>
148: #include <stdlib.h>
149: #include <unixlib.h>
150: #include <ctype.h>
151: #if defined(VAXC) && !defined(__DECC)
152: #define malloc VAXC$MALLOC_OPT
153: #define calloc VAXC$CALLOC_OPT
154: #define free VAXC$FREE_OPT
155: #define cfree VAXC$CFREE_OPT
156: #define realloc VAXC$REALLOC_OPT
157: #endif /* VAXC but not DECC */
158: #define unlink remove
159: #define gmtime localtime
160: #include <stat.h>
161: #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
162: #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
163: #define putenv HTVMS_putenv
164: #endif
165: </PRE>
166:
2.29 frystyk 167: <H3>Safe Cleaning Memory</H3>
168:
169: <PRE>
170: #define FREE(x) if (x) {free(x); x=NULL;}
171: </PRE>
172:
173: <A NAME="declaration"><H2>Macros for declarations</H2></A>
2.26 frystyk 174:
175: <PRE>
176: #define PUBLIC /* Accessible outside this module */
2.1 timbl 177: #define PRIVATE static /* Accessible only within this module */
178:
2.26 frystyk 179: #ifdef _STANDARD_CODE_
180:
2.34 frystyk 181: /* The sco ODT 3.0 CC compiler has some trouble with const */
182: #if !defined(sco) || defined(sco_os5)
2.26 frystyk 183: #define CONST const /* "const" only exists in STDC */
184: #else
185: #define CONST
186: #endif
187:
2.1 timbl 188: #define NOPARAMS (void)
189: #define PARAMS(parameter_list) parameter_list
190: #define NOARGS (void)
191: #define ARGS1(t,a) \
192: (t a)
193: #define ARGS2(t,a,u,b) \
194: (t a, u b)
195: #define ARGS3(t,a,u,b,v,c) \
196: (t a, u b, v c)
197: #define ARGS4(t,a,u,b,v,c,w,d) \
198: (t a, u b, v c, w d)
199: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
200: (t a, u b, v c, w d, x e)
201: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
202: (t a, u b, v c, w d, x e, y f)
203: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
204: (t a, u b, v c, w d, x e, y f, z g)
205: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
206: (t a, u b, v c, w d, x e, y f, z g, s h)
207: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
208: (t a, u b, v c, w d, x e, y f, z g, s h, r i)
209: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
210: (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
211:
212: #else /* not ANSI */
213:
2.26 frystyk 214: #define CONST
215:
2.1 timbl 216: #define NOPARAMS ()
217: #define PARAMS(parameter_list) ()
218: #define NOARGS ()
219: #define ARGS1(t,a) (a) \
220: t a;
221: #define ARGS2(t,a,u,b) (a,b) \
222: t a; u b;
223: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
224: t a; u b; v c;
225: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
226: t a; u b; v c; w d;
227: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
228: t a; u b; v c; w d; x e;
229: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
230: t a; u b; v c; w d; x e; y f;
231: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
232: t a; u b; v c; w d; x e; y f; z g;
233: #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) \
234: t a; u b; v c; w d; x e; y f; z g; s h;
235: #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) \
236: t a; u b; v c; w d; x e; y f; z g; s h; r i;
237: #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 238: t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1 timbl 239:
240:
2.21 frystyk 241: #endif /* _STANDARD_CODE_ (ANSI) */
2.1 timbl 242:
243: #ifndef NULL
244: #define NULL ((void *)0)
245: #endif
2.26 frystyk 246: </PRE>
2.1 timbl 247:
2.3 timbl 248: <H2>Booleans</H2>
2.26 frystyk 249:
250: <PRE>
2.30 frystyk 251: #ifndef BOOLEAN_DEFINED
2.26 frystyk 252: typedef char BOOLEAN; /* Logical value */
2.30 frystyk 253: #endif
2.1 timbl 254:
255: #ifndef CURSES
256: #ifndef TRUE
257: #define TRUE (BOOLEAN)1
258: #define FALSE (BOOLEAN)0
259: #endif
2.3 timbl 260: #endif /* CURSES */
2.1 timbl 261:
262: #ifndef BOOL
263: #define BOOL BOOLEAN
264: #endif
265: #ifndef YES
2.14 timbl 266: #define YES (BOOL)1
267: #define NO (BOOL)0
2.1 timbl 268: #endif
269:
2.11 timbl 270: #ifndef HTMIN
271: #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
272: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1 timbl 273: #endif
2.26 frystyk 274: </PRE>
2.1 timbl 275:
2.35 frystyk 276: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules and Streams</H2></A>
277:
278: Theese are the codes returned from the protocol modules, and the
279: stream modules. Success are (>=0) and failure are (<0)
2.1 timbl 280:
2.3 timbl 281: <PRE>
2.23 frystyk 282: #define HT_OK 0 /* Generic success */
2.37 frystyk 283: #define HT_ALL 1 /* Used by Net Manager */
284:
2.38 frystyk 285: #define HT_PERSISTENT 29995 /* Wait for persistent connection */
2.37 frystyk 286: #define HT_IGNORE 29996 /* Ignore this in the Net manager */
2.35 frystyk 287: #define HT_NO_DATA 29997 /* OK but no data was loaded */
288: #define HT_REDIRECTION_ON_FLY 29998 /* Redo the retrieve with a new URL */
2.23 frystyk 289: #define HT_LOADED 29999 /* Instead of a socket */
290:
291: #define HT_ERROR -1 /* Generic failure */
292: #define HT_NO_ACCESS -10 /* Access not available */
293: #define HT_FORBIDDEN -11 /* Access forbidden */
294: #define HT_INTERNAL -12 /* Weird -- should never happen. */
2.35 frystyk 295:
296: #define HT_RETRY -29996 /* If service isn't available */
2.23 frystyk 297: #define HT_WOULD_BLOCK -29997 /* If we are in a select */
2.15 frystyk 298: #define HT_INTERRUPTED -29998 /* Note the negative value! */
2.35 frystyk 299: </PRE>
300:
301: The following codes are positive values that will be parsed back
302: through streams. This can be used to introduce stream specific return
303: values
2.1 timbl 304:
2.35 frystyk 305: <PRE>
306: #define HT_RELOAD 29996 /* If we must reload the document */
307: </PRE>
308:
309: <H2>Other stuff</H2>
310:
311: <PRE>
2.26 frystyk 312: #ifdef _STANDARD_CODE_
313: #include <stdarg.h>
314: #else
315: #include <varargs.h>
316: #endif
2.1 timbl 317:
318: #ifdef CURSES
2.26 frystyk 319: /* htbrowse.c; */
320: #ifdef ULTRIX /* or DECSTATION */
321: #include <cursesX.h> /* Extended curses under X. Only decent one :lou. */
322: #else
323: #include <curses.h>
324: #endif /* ULTRIX */
2.1 timbl 325: extern WINDOW *w_top, *w_text, *w_prompt;
326: extern void user_message PARAMS((const char *fmt, ...));
327: extern void prompt_set PARAMS((CONST char * msg));
328: extern void prompt_count PARAMS((long kb));
329: #else
330: #define user_message printf
331: #endif
332:
2.3 timbl 333: </PRE>
2.26 frystyk 334:
335: <H2>Out Of Memory checking for malloc() return:</H2>
336:
337: <PRE>
338: #ifndef __FILE__
2.1 timbl 339: #define __FILE__ ""
340: #define __LINE__ ""
341: #endif
342:
343: #define outofmem(file, func) \
2.26 frystyk 344: { fprintf(TDEST, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
2.1 timbl 345: exit(1);}
346:
2.26 frystyk 347: </PRE>
2.1 timbl 348:
2.26 frystyk 349: <H2>Upper- and Lowercase macros</H2>
350:
351: The problem here is that toupper(x) is not defined officially unless
352: isupper(x) is. These macros are CERTAINLY needed on #if defined(pyr)
353: || define(mips) or BDSI platforms. For safefy, we make them mandatory.
2.1 timbl 354:
2.25 roeber 355: <PRE>
2.26 frystyk 356: #include <ctype.h>
2.1 timbl 357:
358: #ifndef TOLOWER
2.27 frystyk 359: #define TOLOWER(c) tolower(c)
360: #define TOUPPER(c) toupper(c)
2.29 frystyk 361: #endif
362: </PRE>
363:
364: <H2>Max and Min values for Integers and Floating Point</H2>
365:
366: <PRE>
367: #ifdef FLT_EPSILON /* The ANSI C way define */
368: #define HT_EPSILON FLT_EPSILON
369: #else
370: #define HT_EPSILON 0.00000001
2.27 frystyk 371: #endif
372: </PRE>
373:
374: <H2>White Characters</H2>
375:
376: Is character <B>c</B> white space?
377:
378: <PRE>
379: #ifdef OLD_CODE
380: #define WHITE(c) (((unsigned char)(TOASCII(c))) <= 32)
381: #else
382: #define WHITE(c) isspace(c)
383: #endif
2.26 frystyk 384: </PRE>
385:
386: <H2>The local equivalents of CR and LF</H2>
2.1 timbl 387:
2.26 frystyk 388: We can check for these after net ascii text has been converted to the
389: local representation. Similarly, we include them in strings to be sent
390: as net ascii after translation.
391:
392: <PRE>
393: #define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */
394: #define CR FROMASCII('\015') /* Will be converted to ^M for transmission */
2.6 timbl 395:
2.1 timbl 396: #endif /* HTUTILS_H */
2.26 frystyk 397: </PRE>
2.1 timbl 398:
2.26 frystyk 399: end of utilities
400: </BODY>
2.6 timbl 401: </HTML>
Webmaster