Annotation of libwww/Library/src/HTUtils.html, revision 2.23
2.6 timbl 1: <HTML>
2: <HEAD>
2.20 frystyk 3: <TITLE>Utility macros for the W3 code library</TITLE>
2.6 timbl 4: <NEXTID N="z2">
5: </HEAD>
2.3 timbl 6: <BODY>
2.20 frystyk 7: <H1>Macros for general use</H1>
8:
9: This module is a very basic module of the <A HREF="Overview.html">CERN
10: Common Code Library</A> See also: the system dependent file<A NAME="z0"
11: HREF="tcp.html">"tcp.h"</A> for system specific information.
12:
2.1 timbl 13: <PRE>
14: #ifndef HTUTILS_H
15: #define HTUTILS_H
16:
2.21 frystyk 17: #if defined(__STDC__) || defined(__cplusplus)
18: #define _STANDARD_CODE_
19: #endif
20:
2.20 frystyk 21: #ifndef DEBUG
22: #define DEBUG /* No one ever turns this off as trace is too important */
23: #endif /* Keep option for really small memory applications too */
24:
2.3 timbl 25: #ifdef _WINDOWS /* SCW */
26: #include "windef.h"
27: #define BOOLEAN_DEFINED
28: #endif
29:
2.1 timbl 30: #ifdef SHORT_NAMES
31: #define WWW_TraceFlag HTTrFlag
32: #endif
33:
2.20 frystyk 34: #ifndef STDIO_H
2.3 timbl 35: #include <stdio.h>
2.1 timbl 36: #define STDIO_H
37: #endif
2.21 frystyk 38:
2.20 frystyk 39: </PRE>
40:
41: <H2>Debug message control</H2>
42:
43: This is the global flag for setting the TRACE options.
44:
45: <PRE>
46: extern int WWW_TraceFlag; /* Global flag for all W3 trace */
47: </PRE>
48:
49: The verbose mode is no longer a simple boolean but a bit field so that it is
50: possible to see parts of the output messages. The <EM>TRACE</EM> define still
51: outputs all messages if verbose mode is active, but in addition the following
52: TRACE defines have been made:
2.1 timbl 53:
2.20 frystyk 54: <PRE>
55: typedef enum _HTTraceFlags {
56: SHOW_SGML_TRACE = 0xF, /* 1111 */
2.23 ! frystyk 57: SHOW_THREAD_TRACE = 0x30, /* 11.0000 */
! 58: SHOW_PROTOCOL_TRACE = 0xC0, /* 1100.0000 */
2.20 frystyk 59: SHOW_URI_TRACE = 0x300, /* 11.0000.0000 */
60: SHOW_ANCHOR_TRACE = 0xC00, /* 11.00.0000.0000 */
61: SHOW_ALL_TRACE = 0xFFF /* 11.11.1111.1111 */
62: } HTTraceFlags;
63: </PRE>
64:
65: The flags are made so that they can serve as a group flag for correlated
66: trace messages, e.g. showing messages for SGML and HTML at the same time.
67:
68: <PRE>
2.1 timbl 69: #ifdef DEBUG
2.20 frystyk 70: #define TRACE (WWW_TraceFlag)
71: #define SGML_TRACE (WWW_TraceFlag & SHOW_SGML_TRACE)
2.23 ! frystyk 72: #define THD_TRACE (WWW_TraceFlag & SHOW_THREAD_TRACE)
2.20 frystyk 73: #define PROT_TRACE (WWW_TraceFlag & SHOW_PROTOCOL_TRACE)
74: #define URI_TRACE (WWW_TraceFlag & SHOW_URI_TRACE)
75: #define ANCH_TRACE (WWW_TraceFlag & SHOW_ANCHOR_TRACE)
76: #define PROGRESS(str) printf(str)
2.1 timbl 77: #else
2.20 frystyk 78: #define TRACE 0
79: #define SGML_TRACE 0
80: #define PROT_TRACE 0
2.23 ! frystyk 81: #define THD_TRACE 0
2.20 frystyk 82: #define URI_TRACE 0
83: #define ANCH_TRACE 0
84: #define PROGRESS(str) /* nothing for now */
2.1 timbl 85: #endif
2.20 frystyk 86: </PRE>
87:
88: <EM><B>Note: </B> The CTRACE flag might interfere with other if () else
2.21 frystyk 89: constructions in the code. It should not be used but replaced by TRACE</EM>
2.1 timbl 90:
2.20 frystyk 91: <PRE>
92: #define CTRACE if(TRACE) fprintf
2.5 timbl 93: #define tfp stderr
2.20 frystyk 94: </PRE>
2.1 timbl 95:
2.20 frystyk 96:
97: <H2>Error type</H2>
2.17 frystyk 98:
99: THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>
100:
101: This is passed back when streams
2.6 timbl 102: are aborted. It might be nice to
103: have some structure of error messages,
104: numbers, and recursive pointers to
105: reasons. Curently this is a placeholder
106: for something more sophisticated.
107: <PRE>typedef void * HTError; /* Unused at present -- best definition? */
2.1 timbl 108:
2.3 timbl 109: </PRE>
110: <H2>Standard C library for malloc() etc</H2>
2.19 duns 111:
112: Replace memory allocation and free C RTL functions
113: with VAXC$xxx_OPT altrenatives for VAXC (but not DECC)
114: on VMS. This makes a big performance difference. (Foteos
115: Macrides).
116:
2.3 timbl 117: <PRE>#ifdef vax
2.1 timbl 118: #ifdef unix
119: #define ultrix /* Assume vax+unix=ultrix */
120: #endif
121: #endif
122:
123: #ifndef VMS
124: #ifndef ultrix
125: #ifdef NeXT
2.3 timbl 126: #include <libc.h> /* NeXT */
2.1 timbl 127: #endif
2.16 luotonen 128: #ifndef Mips
2.1 timbl 129: #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
2.3 timbl 130: #include <stdlib.h> /* ANSI */
2.1 timbl 131: #endif
2.16 luotonen 132: #else /* Mips */
133: #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
134: #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
135: #endif /* Mips */
2.1 timbl 136: #else /* ultrix */
2.3 timbl 137: #include <malloc.h>
138: #include <memory.h>
139: #include <stdio.h>
2.8 secret 140: #include <stdlib.h> /* ANSI */ /* BSN */
2.1 timbl 141: #endif
142:
143: #else /* VMS */
2.3 timbl 144: #include <stdio.h>
2.19 duns 145: #include <stdlib.h>
146: #include <unixlib.h>
2.3 timbl 147: #include <ctype.h>
2.19 duns 148: #if defined(VAXC) && !defined(__DECC)
149: #define malloc VAXC$MALLOC_OPT
150: #define calloc VAXC$CALLOC_OPT
151: #define free VAXC$FREE_OPT
152: #define cfree VAXC$CFREE_OPT
153: #define realloc VAXC$REALLOC_OPT
154: #endif /* VAXC but not DECC */
2.13 duns 155: #define unlink remove
2.19 duns 156: #define gmtime localtime
2.13 duns 157: #include <stat.h>
158: #define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
159: #define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
160: #define putenv HTVMS_putenv
2.1 timbl 161: #endif
162:
2.3 timbl 163: </PRE>
164: <H2>Macros for declarations</H2>
165: <PRE>#define PUBLIC /* Accessible outside this module */
2.1 timbl 166: #define PRIVATE static /* Accessible only within this module */
167:
2.21 frystyk 168: #ifdef _STANDARD_CODE_
2.22 frystyk 169:
170: #ifndef sco /* The sco CC compiler does not know const */
2.1 timbl 171: #define CONST const /* "const" only exists in STDC */
2.22 frystyk 172: #endif
173:
2.1 timbl 174: #define NOPARAMS (void)
175: #define PARAMS(parameter_list) parameter_list
176: #define NOARGS (void)
177: #define ARGS1(t,a) \
178: (t a)
179: #define ARGS2(t,a,u,b) \
180: (t a, u b)
181: #define ARGS3(t,a,u,b,v,c) \
182: (t a, u b, v c)
183: #define ARGS4(t,a,u,b,v,c,w,d) \
184: (t a, u b, v c, w d)
185: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
186: (t a, u b, v c, w d, x e)
187: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
188: (t a, u b, v c, w d, x e, y f)
189: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
190: (t a, u b, v c, w d, x e, y f, z g)
191: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
192: (t a, u b, v c, w d, x e, y f, z g, s h)
193: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
194: (t a, u b, v c, w d, x e, y f, z g, s h, r i)
195: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
196: (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
197:
198: #else /* not ANSI */
199:
2.3 timbl 200: #ifndef _WINDOWS
2.1 timbl 201: #define CONST
2.3 timbl 202: #endif
2.1 timbl 203: #define NOPARAMS ()
204: #define PARAMS(parameter_list) ()
205: #define NOARGS ()
206: #define ARGS1(t,a) (a) \
207: t a;
208: #define ARGS2(t,a,u,b) (a,b) \
209: t a; u b;
210: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
211: t a; u b; v c;
212: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
213: t a; u b; v c; w d;
214: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
215: t a; u b; v c; w d; x e;
216: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
217: t a; u b; v c; w d; x e; y f;
218: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
219: t a; u b; v c; w d; x e; y f; z g;
220: #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) \
221: t a; u b; v c; w d; x e; y f; z g; s h;
222: #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) \
223: t a; u b; v c; w d; x e; y f; z g; s h; r i;
224: #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 225: t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1 timbl 226:
227:
2.21 frystyk 228: #endif /* _STANDARD_CODE_ (ANSI) */
2.1 timbl 229:
230: #ifndef NULL
231: #define NULL ((void *)0)
232: #endif
233:
2.3 timbl 234: </PRE>
235: <H2>Booleans</H2>
236: <PRE>/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
237: /* #define GOOD(status) ((status)38;1) VMS style status: test bit 0 */
2.1 timbl 238: /* #define BAD(status) (!GOOD(status)) Bit 0 set if OK, otherwise clear */
239:
2.3 timbl 240: #ifndef _WINDOWS
2.1 timbl 241: #ifndef BOOLEAN_DEFINED
242: typedef char BOOLEAN; /* Logical value */
243: #ifndef CURSES
244: #ifndef TRUE
245: #define TRUE (BOOLEAN)1
246: #define FALSE (BOOLEAN)0
247: #endif
2.3 timbl 248: #endif /* CURSES */
249: #endif /* _WINDOWS */
2.1 timbl 250: #define BOOLEAN_DEFINED
251: #endif
252:
253: #ifndef BOOL
254: #define BOOL BOOLEAN
255: #endif
256: #ifndef YES
2.14 timbl 257: #define YES (BOOL)1
258: #define NO (BOOL)0
2.1 timbl 259: #endif
260:
2.11 timbl 261: #ifndef HTMIN
262: #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
263: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1 timbl 264: #endif
265:
266: #define TCP_PORT 80 /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
267: #define OLD_TCP_PORT 2784 /* Try the old one if no answer on 80 */
268: #define DNP_OBJ 80 /* This one doesn't look busy, but we must check */
2.3 timbl 269: /* That one was for decnet */
2.1 timbl 270:
2.18 frystyk 271: </PRE>
2.23 ! frystyk 272: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules</H2></A>
2.1 timbl 273:
2.18 frystyk 274: Theese are the codes returned from the protocol modules. Success (>=0) and
275: failure (<0) codes
2.3 timbl 276: <PRE>
2.23 ! frystyk 277: #define HT_OK 0 /* Generic success */
! 278: #define HT_LOADED 29999 /* Instead of a socket */
! 279: #define HT_REDIRECTION_ON_FLY 29998 /* Redo the retrieve with a new URL */
! 280:
! 281: #define HT_ERROR -1 /* Generic failure */
! 282: #define HT_NO_ACCESS -10 /* Access not available */
! 283: #define HT_FORBIDDEN -11 /* Access forbidden */
! 284: #define HT_INTERNAL -12 /* Weird -- should never happen. */
2.18 frystyk 285: #define HT_NO_DATA -9999 /* OK but no data was loaded */
286: /* Typically, other app started */
2.23 ! frystyk 287: #define HT_WOULD_BLOCK -29997 /* If we are in a select */
2.15 frystyk 288: #define HT_INTERRUPTED -29998 /* Note the negative value! */
2.1 timbl 289:
2.7 luotonen 290:
2.3 timbl 291: #include "HTString.h" /* String utilities */
2.1 timbl 292:
2.21 frystyk 293: #ifdef _STANDARD_CODE_
2.3 timbl 294: #include <stdarg.h>
2.1 timbl 295: #else
2.3 timbl 296: #include <varargs.h>
2.1 timbl 297: #endif
298:
299: #ifdef CURSES
300: /* htbrowse.c; */
2.6 timbl 301: #ifdef ULTRIX /* or DECSTATION */
302: #include <cursesX.h> /* Extended curses under X. Only decent one :lou. */
303: #else
2.3 timbl 304: #include <curses.h>
2.6 timbl 305: #endif /* ULTRIX */
2.1 timbl 306: extern WINDOW *w_top, *w_text, *w_prompt;
307: extern void user_message PARAMS((const char *fmt, ...));
308: extern void prompt_set PARAMS((CONST char * msg));
309: extern void prompt_count PARAMS((long kb));
310: #else
311: #define user_message printf
312: #endif
313:
2.3 timbl 314: </PRE>
315: <H2>Out Of Memory checking for malloc()
316: return:</H2>
317: <PRE>#ifndef __FILE__
2.1 timbl 318: #define __FILE__ ""
319: #define __LINE__ ""
320: #endif
321:
322: #define outofmem(file, func) \
323: { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
324: exit(1);}
325: /* extern void outofmem PARAMS((const char *fname, const char *func)); */
326:
327:
2.3 timbl 328: </PRE>
329: <H3>who put these in and what are they
330: anyway?</H3>
331: <PRE>#ifdef THEY_WILL_BE_REMOVED
2.1 timbl 332: extern void msg_init PARAMS((int height));
333: extern void msg_printf PARAMS((int y, const char *fmt, ...));
334: extern void msg_exit PARAMS((int wait_for_key));
2.3 timbl 335: #endif
2.1 timbl 336:
2.3 timbl 337: </PRE>
338: <H2>Upper- and Lowercase macros</H2>The problem here is that toupper(x)
339: is not defined officially unless
340: isupper(x) is. These macros are
341: CERTAINLY needed on #if defined(pyr)
342: || define(mips) or BDSI platforms.
343: For safefy, we make them mandatory.
344: <PRE>#include <ctype.h>
2.1 timbl 345:
346: #ifndef TOLOWER
347: /* Pyramid and Mips can't uppercase non-alpha */
348: #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
349: #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
350: #endif /* ndef TOLOWER */
351:
2.6 timbl 352: </PRE>
353: <H2>The local equivalents of CR and LF</H2>We can check for these after net
354: ascii text has been converted to
355: the local representation. Similarly,
356: we include them in strings to be
357: sent as net ascii after translation.
358: <PRE>#define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */
359: #define CR FROMASCII('\015') /* Will be converted to ^M for transmission */
360:
2.1 timbl 361: #endif /* HTUTILS_H */
362:
2.11 timbl 363: </PRE>end of utilities</BODY>
2.6 timbl 364: </HTML>
Webmaster