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