Annotation of libwww/Library/src/HTUtils.html, revision 2.25
2.6 timbl 1: <HTML>
2: <HEAD>
2.20 frystyk 3: <TITLE>Utility macros for the W3 code library</TITLE>
2.6 timbl 4: </HEAD>
2.3 timbl 5: <BODY>
2.24 frystyk 6:
2.20 frystyk 7: <H1>Macros for general use</H1>
8:
2.24 frystyk 9: <PRE>
10: /*
11: ** (c) COPYRIGHT CERN 1994.
12: ** Please first read the full copyright statement in the file COPYRIGH.
13: */
14: </PRE>
15:
16: See also the system dependent file <A HREF="tcp.html">tcp module</A>
17: for system specific information. <P>
18:
19: This module is a part of the <A
20: HREF="http://info.cern.ch/hypertext/WWW/Library/User/Guide/Guide.html">
21: Library of Common Code</A>.
2.20 frystyk 22:
2.1 timbl 23: <PRE>
24: #ifndef HTUTILS_H
25: #define HTUTILS_H
26:
2.25 ! roeber 27: #include "sysdep.h"
2.3 timbl 28:
2.1 timbl 29: #ifdef SHORT_NAMES
30: #define WWW_TraceFlag HTTrFlag
31: #endif
2.20 frystyk 32: </PRE>
33:
34: <H2>Debug message control</H2>
35:
36: This is the global flag for setting the TRACE options.
37:
38: <PRE>
39: extern int WWW_TraceFlag; /* Global flag for all W3 trace */
40: </PRE>
41:
42: The verbose mode is no longer a simple boolean but a bit field so that it is
43: possible to see parts of the output messages. The <EM>TRACE</EM> define still
44: outputs all messages if verbose mode is active, but in addition the following
45: TRACE defines have been made:
2.1 timbl 46:
2.20 frystyk 47: <PRE>
48: typedef enum _HTTraceFlags {
49: SHOW_SGML_TRACE = 0xF, /* 1111 */
2.23 frystyk 50: SHOW_THREAD_TRACE = 0x30, /* 11.0000 */
51: SHOW_PROTOCOL_TRACE = 0xC0, /* 1100.0000 */
2.20 frystyk 52: SHOW_URI_TRACE = 0x300, /* 11.0000.0000 */
53: SHOW_ANCHOR_TRACE = 0xC00, /* 11.00.0000.0000 */
54: SHOW_ALL_TRACE = 0xFFF /* 11.11.1111.1111 */
55: } HTTraceFlags;
56: </PRE>
57:
58: The flags are made so that they can serve as a group flag for correlated
59: trace messages, e.g. showing messages for SGML and HTML at the same time.
60:
61: <PRE>
2.1 timbl 62: #ifdef DEBUG
2.20 frystyk 63: #define TRACE (WWW_TraceFlag)
64: #define SGML_TRACE (WWW_TraceFlag & SHOW_SGML_TRACE)
2.23 frystyk 65: #define THD_TRACE (WWW_TraceFlag & SHOW_THREAD_TRACE)
2.20 frystyk 66: #define PROT_TRACE (WWW_TraceFlag & SHOW_PROTOCOL_TRACE)
67: #define URI_TRACE (WWW_TraceFlag & SHOW_URI_TRACE)
68: #define ANCH_TRACE (WWW_TraceFlag & SHOW_ANCHOR_TRACE)
69: #define PROGRESS(str) printf(str)
2.1 timbl 70: #else
2.20 frystyk 71: #define TRACE 0
72: #define SGML_TRACE 0
73: #define PROT_TRACE 0
2.23 frystyk 74: #define THD_TRACE 0
2.20 frystyk 75: #define URI_TRACE 0
76: #define ANCH_TRACE 0
77: #define PROGRESS(str) /* nothing for now */
2.1 timbl 78: #endif
2.20 frystyk 79: </PRE>
80:
81: <EM><B>Note: </B> The CTRACE flag might interfere with other if () else
2.21 frystyk 82: constructions in the code. It should not be used but replaced by TRACE</EM>
2.1 timbl 83:
2.20 frystyk 84: <PRE>
85: #define CTRACE if(TRACE) fprintf
2.5 timbl 86: #define tfp stderr
2.20 frystyk 87: </PRE>
2.1 timbl 88:
2.20 frystyk 89:
90: <H2>Error type</H2>
2.17 frystyk 91:
92: THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>
93:
94: This is passed back when streams
2.6 timbl 95: are aborted. It might be nice to
96: have some structure of error messages,
97: numbers, and recursive pointers to
98: reasons. Curently this is a placeholder
99: for something more sophisticated.
100: <PRE>typedef void * HTError; /* Unused at present -- best definition? */
2.3 timbl 101: </PRE>
102: <H2>Macros for declarations</H2>
2.25 ! roeber 103: <PRE>#define PUBLIC /* Accessible outside this module */
2.1 timbl 104: #define PRIVATE static /* Accessible only within this module */
105:
2.25 ! roeber 106: #define CONST const
! 107: #ifdef __STDC__
2.1 timbl 108: #define NOPARAMS (void)
109: #define PARAMS(parameter_list) parameter_list
110: #define NOARGS (void)
111: #define ARGS1(t,a) \
112: (t a)
113: #define ARGS2(t,a,u,b) \
114: (t a, u b)
115: #define ARGS3(t,a,u,b,v,c) \
116: (t a, u b, v c)
117: #define ARGS4(t,a,u,b,v,c,w,d) \
118: (t a, u b, v c, w d)
119: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
120: (t a, u b, v c, w d, x e)
121: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
122: (t a, u b, v c, w d, x e, y f)
123: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
124: (t a, u b, v c, w d, x e, y f, z g)
125: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
126: (t a, u b, v c, w d, x e, y f, z g, s h)
127: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
128: (t a, u b, v c, w d, x e, y f, z g, s h, r i)
129: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
130: (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
131:
132: #else /* not ANSI */
133:
134: #define NOPARAMS ()
135: #define PARAMS(parameter_list) ()
136: #define NOARGS ()
137: #define ARGS1(t,a) (a) \
138: t a;
139: #define ARGS2(t,a,u,b) (a,b) \
140: t a; u b;
141: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
142: t a; u b; v c;
143: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
144: t a; u b; v c; w d;
145: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
146: t a; u b; v c; w d; x e;
147: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
148: t a; u b; v c; w d; x e; y f;
149: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
150: t a; u b; v c; w d; x e; y f; z g;
151: #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) \
152: t a; u b; v c; w d; x e; y f; z g; s h;
153: #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) \
154: t a; u b; v c; w d; x e; y f; z g; s h; r i;
155: #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 156: t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1 timbl 157:
158:
2.21 frystyk 159: #endif /* _STANDARD_CODE_ (ANSI) */
2.1 timbl 160:
161: #ifndef NULL
162: #define NULL ((void *)0)
163: #endif
164:
2.3 timbl 165: </PRE>
166: <H2>Booleans</H2>
167: <PRE>/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
168: /* #define GOOD(status) ((status)38;1) VMS style status: test bit 0 */
2.1 timbl 169: /* #define BAD(status) (!GOOD(status)) Bit 0 set if OK, otherwise clear */
170:
171: #ifndef CURSES
172: #ifndef TRUE
173: #define TRUE (BOOLEAN)1
174: #define FALSE (BOOLEAN)0
175: #endif
2.3 timbl 176: #endif /* CURSES */
2.1 timbl 177:
178: #ifndef BOOL
179: #define BOOL BOOLEAN
180: #endif
181: #ifndef YES
2.14 timbl 182: #define YES (BOOL)1
183: #define NO (BOOL)0
2.1 timbl 184: #endif
185:
2.11 timbl 186: #ifndef HTMIN
187: #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
188: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1 timbl 189: #endif
190:
191: #define TCP_PORT 80 /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
192: #define OLD_TCP_PORT 2784 /* Try the old one if no answer on 80 */
193: #define DNP_OBJ 80 /* This one doesn't look busy, but we must check */
2.3 timbl 194: /* That one was for decnet */
2.1 timbl 195:
2.18 frystyk 196: </PRE>
2.23 frystyk 197: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules</H2></A>
2.1 timbl 198:
2.18 frystyk 199: Theese are the codes returned from the protocol modules. Success (>=0) and
200: failure (<0) codes
2.3 timbl 201: <PRE>
2.23 frystyk 202: #define HT_OK 0 /* Generic success */
203: #define HT_LOADED 29999 /* Instead of a socket */
204: #define HT_REDIRECTION_ON_FLY 29998 /* Redo the retrieve with a new URL */
205:
206: #define HT_ERROR -1 /* Generic failure */
207: #define HT_NO_ACCESS -10 /* Access not available */
208: #define HT_FORBIDDEN -11 /* Access forbidden */
209: #define HT_INTERNAL -12 /* Weird -- should never happen. */
2.18 frystyk 210: #define HT_NO_DATA -9999 /* OK but no data was loaded */
211: /* Typically, other app started */
2.23 frystyk 212: #define HT_WOULD_BLOCK -29997 /* If we are in a select */
2.15 frystyk 213: #define HT_INTERRUPTED -29998 /* Note the negative value! */
2.1 timbl 214:
2.7 luotonen 215:
2.3 timbl 216: #include "HTString.h" /* String utilities */
2.1 timbl 217:
218: #ifdef CURSES
219: extern WINDOW *w_top, *w_text, *w_prompt;
220: extern void user_message PARAMS((const char *fmt, ...));
221: extern void prompt_set PARAMS((CONST char * msg));
222: extern void prompt_count PARAMS((long kb));
223: #else
224: #define user_message printf
225: #endif
226:
2.3 timbl 227: </PRE>
228: <H2>Out Of Memory checking for malloc()
229: return:</H2>
230: <PRE>#ifndef __FILE__
2.1 timbl 231: #define __FILE__ ""
232: #define __LINE__ ""
233: #endif
234:
235: #define outofmem(file, func) \
236: { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
237: exit(1);}
238: /* extern void outofmem PARAMS((const char *fname, const char *func)); */
239:
240:
2.3 timbl 241: </PRE>
242: <H3>who put these in and what are they
243: anyway?</H3>
244: <PRE>#ifdef THEY_WILL_BE_REMOVED
2.1 timbl 245: extern void msg_init PARAMS((int height));
246: extern void msg_printf PARAMS((int y, const char *fmt, ...));
247: extern void msg_exit PARAMS((int wait_for_key));
2.3 timbl 248: #endif
2.1 timbl 249:
2.3 timbl 250: </PRE>
251: <H2>Upper- and Lowercase macros</H2>The problem here is that toupper(x)
252: is not defined officially unless
253: isupper(x) is. These macros are
254: CERTAINLY needed on #if defined(pyr)
255: || define(mips) or BDSI platforms.
256: For safefy, we make them mandatory.
2.25 ! roeber 257: <PRE>
2.1 timbl 258:
259: #ifndef TOLOWER
260: /* Pyramid and Mips can't uppercase non-alpha */
261: #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
262: #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
263: #endif /* ndef TOLOWER */
264:
2.6 timbl 265: </PRE>
266: <H2>The local equivalents of CR and LF</H2>We can check for these after net
267: ascii text has been converted to
268: the local representation. Similarly,
269: we include them in strings to be
270: sent as net ascii after translation.
271: <PRE>#define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */
272: #define CR FROMASCII('\015') /* Will be converted to ^M for transmission */
273:
2.1 timbl 274: #endif /* HTUTILS_H */
275:
2.11 timbl 276: </PRE>end of utilities</BODY>
2.6 timbl 277: </HTML>
Webmaster