Annotation of libwww/Library/src/HTUtils.html, revision 2.21
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.1 timbl 166: #define CONST const /* "const" only exists in STDC */
167: #define NOPARAMS (void)
168: #define PARAMS(parameter_list) parameter_list
169: #define NOARGS (void)
170: #define ARGS1(t,a) \
171: (t a)
172: #define ARGS2(t,a,u,b) \
173: (t a, u b)
174: #define ARGS3(t,a,u,b,v,c) \
175: (t a, u b, v c)
176: #define ARGS4(t,a,u,b,v,c,w,d) \
177: (t a, u b, v c, w d)
178: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
179: (t a, u b, v c, w d, x e)
180: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
181: (t a, u b, v c, w d, x e, y f)
182: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
183: (t a, u b, v c, w d, x e, y f, z g)
184: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
185: (t a, u b, v c, w d, x e, y f, z g, s h)
186: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
187: (t a, u b, v c, w d, x e, y f, z g, s h, r i)
188: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
189: (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
190:
191: #else /* not ANSI */
192:
2.3 timbl 193: #ifndef _WINDOWS
2.1 timbl 194: #define CONST
2.3 timbl 195: #endif
2.1 timbl 196: #define NOPARAMS ()
197: #define PARAMS(parameter_list) ()
198: #define NOARGS ()
199: #define ARGS1(t,a) (a) \
200: t a;
201: #define ARGS2(t,a,u,b) (a,b) \
202: t a; u b;
203: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
204: t a; u b; v c;
205: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
206: t a; u b; v c; w d;
207: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,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) (a,b,c,d,e,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) (a,b,c,d,e,f,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) (a,b,c,d,e,f,g,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) (a,b,c,d,e,f,g,h,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) (a,b,c,d,e,f,g,h,i,j) \
2.4 timbl 218: t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1 timbl 219:
220:
2.21 ! frystyk 221: #endif /* _STANDARD_CODE_ (ANSI) */
2.1 timbl 222:
223: #ifndef NULL
224: #define NULL ((void *)0)
225: #endif
226:
2.3 timbl 227: </PRE>
228: <H2>Booleans</H2>
229: <PRE>/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
230: /* #define GOOD(status) ((status)38;1) VMS style status: test bit 0 */
2.1 timbl 231: /* #define BAD(status) (!GOOD(status)) Bit 0 set if OK, otherwise clear */
232:
2.3 timbl 233: #ifndef _WINDOWS
2.1 timbl 234: #ifndef BOOLEAN_DEFINED
235: typedef char BOOLEAN; /* Logical value */
236: #ifndef CURSES
237: #ifndef TRUE
238: #define TRUE (BOOLEAN)1
239: #define FALSE (BOOLEAN)0
240: #endif
2.3 timbl 241: #endif /* CURSES */
242: #endif /* _WINDOWS */
2.1 timbl 243: #define BOOLEAN_DEFINED
244: #endif
245:
246: #ifndef BOOL
247: #define BOOL BOOLEAN
248: #endif
249: #ifndef YES
2.14 timbl 250: #define YES (BOOL)1
251: #define NO (BOOL)0
2.1 timbl 252: #endif
253:
2.11 timbl 254: #ifndef HTMIN
255: #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
256: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1 timbl 257: #endif
258:
259: #define TCP_PORT 80 /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
260: #define OLD_TCP_PORT 2784 /* Try the old one if no answer on 80 */
261: #define DNP_OBJ 80 /* This one doesn't look busy, but we must check */
2.3 timbl 262: /* That one was for decnet */
2.1 timbl 263:
2.18 frystyk 264: </PRE>
265: <H2>Return Codes for Protocol Modules</H2>
2.1 timbl 266:
2.18 frystyk 267: Theese are the codes returned from the protocol modules. Success (>=0) and
268: failure (<0) codes
2.3 timbl 269: <PRE>
2.18 frystyk 270: #define HT_NO_DATA -9999 /* OK but no data was loaded */
271: /* Typically, other app started */
2.15 frystyk 272: #define HT_INTERRUPTED -29998 /* Note the negative value! */
2.20 frystyk 273: #define HT_LOADED 29999 /* Instead of a socket */
274: #define HT_REDIRECTION_ON_FLY 29998 /* Redo the retrieve with a new URL */
2.1 timbl 275:
2.20 frystyk 276: #define HT_OK 0 /* Generic success*/
2.1 timbl 277: #define HT_NO_ACCESS -10 /* Access not available */
278: #define HT_FORBIDDEN -11 /* Access forbidden */
279: #define HT_INTERNAL -12 /* Weird -- should never happen. */
2.12 luotonen 280: #define HT_BAD_EOF -13 /* Premature EOF */
2.1 timbl 281:
2.7 luotonen 282:
2.3 timbl 283: #include "HTString.h" /* String utilities */
2.1 timbl 284:
2.21 ! frystyk 285: #ifdef _STANDARD_CODE_
2.3 timbl 286: #include <stdarg.h>
2.1 timbl 287: #else
2.3 timbl 288: #include <varargs.h>
2.1 timbl 289: #endif
290:
291: #ifdef CURSES
292: /* htbrowse.c; */
2.6 timbl 293: #ifdef ULTRIX /* or DECSTATION */
294: #include <cursesX.h> /* Extended curses under X. Only decent one :lou. */
295: #else
2.3 timbl 296: #include <curses.h>
2.6 timbl 297: #endif /* ULTRIX */
2.1 timbl 298: extern WINDOW *w_top, *w_text, *w_prompt;
299: extern void user_message PARAMS((const char *fmt, ...));
300: extern void prompt_set PARAMS((CONST char * msg));
301: extern void prompt_count PARAMS((long kb));
302: #else
303: #define user_message printf
304: #endif
305:
2.3 timbl 306: </PRE>
307: <H2>Out Of Memory checking for malloc()
308: return:</H2>
309: <PRE>#ifndef __FILE__
2.1 timbl 310: #define __FILE__ ""
311: #define __LINE__ ""
312: #endif
313:
314: #define outofmem(file, func) \
315: { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
316: exit(1);}
317: /* extern void outofmem PARAMS((const char *fname, const char *func)); */
318:
319:
2.3 timbl 320: </PRE>
321: <H3>who put these in and what are they
322: anyway?</H3>
323: <PRE>#ifdef THEY_WILL_BE_REMOVED
2.1 timbl 324: extern void msg_init PARAMS((int height));
325: extern void msg_printf PARAMS((int y, const char *fmt, ...));
326: extern void msg_exit PARAMS((int wait_for_key));
2.3 timbl 327: #endif
2.1 timbl 328:
2.3 timbl 329: </PRE>
330: <H2>Upper- and Lowercase macros</H2>The problem here is that toupper(x)
331: is not defined officially unless
332: isupper(x) is. These macros are
333: CERTAINLY needed on #if defined(pyr)
334: || define(mips) or BDSI platforms.
335: For safefy, we make them mandatory.
336: <PRE>#include <ctype.h>
2.1 timbl 337:
338: #ifndef TOLOWER
339: /* Pyramid and Mips can't uppercase non-alpha */
340: #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
341: #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
342: #endif /* ndef TOLOWER */
343:
2.6 timbl 344: </PRE>
345: <H2>The local equivalents of CR and LF</H2>We can check for these after net
346: ascii text has been converted to
347: the local representation. Similarly,
348: we include them in strings to be
349: sent as net ascii after translation.
350: <PRE>#define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */
351: #define CR FROMASCII('\015') /* Will be converted to ^M for transmission */
352:
2.1 timbl 353: #endif /* HTUTILS_H */
354:
2.11 timbl 355: </PRE>end of utilities</BODY>
2.6 timbl 356: </HTML>
Webmaster