Annotation of libwww/Library/src/HTUtils.html, revision 2.11
2.6 timbl 1: <HTML>
2: <HEAD>
2.3 timbl 3: <TITLE>Utitlity macros for the W3 code library</TITLE>
2.6 timbl 4: <NEXTID N="z2">
5: </HEAD>
2.3 timbl 6: <BODY>
7: <H1>Macros for general use</H1>Generates: <A
2.6 timbl 8: NAME="z1" HREF="HTUtils.h">HTUtils.h</A><P>
2.3 timbl 9: See also: the system dependent file<A
2.6 timbl 10: NAME="z0" HREF="tcp.html">
2.3 timbl 11: "tcp.h"</A>
2.1 timbl 12: <PRE>
13: #ifndef DEBUG
14: #define DEBUG /* Noone ever turns this off as trace is too important */
15: #endif /* Keeep option for really small memory applications tho */
16:
17: #ifndef HTUTILS_H
18: #define HTUTILS_H
19:
2.3 timbl 20: #ifdef _WINDOWS /* SCW */
21: #include "windef.h"
22: #define BOOLEAN_DEFINED
23: #endif
24:
2.1 timbl 25: #ifdef SHORT_NAMES
26: #define WWW_TraceFlag HTTrFlag
27: #endif
28:
2.3 timbl 29: </PRE>
30: <H2>Debug message control.</H2>
31: <PRE>#ifndef STDIO_H
32: #include <stdio.h>
2.1 timbl 33: #define STDIO_H
34: #endif
35:
36: #ifdef DEBUG
37: #define TRACE (WWW_TraceFlag)
38: #define PROGRESS(str) printf(str)
39: extern int WWW_TraceFlag;
40: #else
41: #define TRACE 0
42: #define PROGRESS(str) /* nothing for now */
43: #endif
44:
45: #define CTRACE if(TRACE)fprintf
2.5 timbl 46: #define tfp stderr
2.1 timbl 47:
2.6 timbl 48: </PRE>
49: <H3>Error type</H3>This is passed back when streams
50: are aborted. It might be nice to
51: have some structure of error messages,
52: numbers, and recursive pointers to
53: reasons. Curently this is a placeholder
54: for something more sophisticated.
55: <PRE>typedef void * HTError; /* Unused at present -- best definition? */
2.1 timbl 56:
2.3 timbl 57: </PRE>
58: <H2>Standard C library for malloc() etc</H2>
59: <PRE>#ifdef vax
2.1 timbl 60: #ifdef unix
61: #define ultrix /* Assume vax+unix=ultrix */
62: #endif
63: #endif
64:
65: #ifndef VMS
66: #ifndef ultrix
67: #ifdef NeXT
2.3 timbl 68: #include <libc.h> /* NeXT */
2.1 timbl 69: #endif
70: #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
2.3 timbl 71: #include <stdlib.h> /* ANSI */
2.1 timbl 72: #endif
73: #else /* ultrix */
2.3 timbl 74: #include <malloc.h>
75: #include <memory.h>
76: #include <stdio.h>
2.8 secret 77: #include <stdlib.h> /* ANSI */ /* BSN */
2.1 timbl 78: #endif
79:
80: #else /* VMS */
2.3 timbl 81: #include <stdio.h>
82: #include <ctype.h>
2.1 timbl 83: #endif
84:
2.3 timbl 85: </PRE>
86: <H2>Macros for declarations</H2>
87: <PRE>#define PUBLIC /* Accessible outside this module */
2.1 timbl 88: #define PRIVATE static /* Accessible only within this module */
89:
90: #ifdef __STDC__
91: #define CONST const /* "const" only exists in STDC */
92: #define NOPARAMS (void)
93: #define PARAMS(parameter_list) parameter_list
94: #define NOARGS (void)
95: #define ARGS1(t,a) \
96: (t a)
97: #define ARGS2(t,a,u,b) \
98: (t a, u b)
99: #define ARGS3(t,a,u,b,v,c) \
100: (t a, u b, v c)
101: #define ARGS4(t,a,u,b,v,c,w,d) \
102: (t a, u b, v c, w d)
103: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
104: (t a, u b, v c, w d, x e)
105: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
106: (t a, u b, v c, w d, x e, y f)
107: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
108: (t a, u b, v c, w d, x e, y f, z g)
109: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
110: (t a, u b, v c, w d, x e, y f, z g, s h)
111: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
112: (t a, u b, v c, w d, x e, y f, z g, s h, r i)
113: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
114: (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
115:
116: #else /* not ANSI */
117:
2.3 timbl 118: #ifndef _WINDOWS
2.1 timbl 119: #define CONST
2.3 timbl 120: #endif
2.1 timbl 121: #define NOPARAMS ()
122: #define PARAMS(parameter_list) ()
123: #define NOARGS ()
124: #define ARGS1(t,a) (a) \
125: t a;
126: #define ARGS2(t,a,u,b) (a,b) \
127: t a; u b;
128: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
129: t a; u b; v c;
130: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
131: t a; u b; v c; w d;
132: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
133: t a; u b; v c; w d; x e;
134: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
135: t a; u b; v c; w d; x e; y f;
136: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
137: t a; u b; v c; w d; x e; y f; z g;
138: #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) \
139: t a; u b; v c; w d; x e; y f; z g; s h;
140: #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) \
141: t a; u b; v c; w d; x e; y f; z g; s h; r i;
142: #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 143: t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1 timbl 144:
145:
146: #endif /* __STDC__ (ANSI) */
147:
148: #ifndef NULL
149: #define NULL ((void *)0)
150: #endif
151:
2.3 timbl 152: </PRE>
153: <H2>Booleans</H2>
154: <PRE>/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
155: /* #define GOOD(status) ((status)38;1) VMS style status: test bit 0 */
2.1 timbl 156: /* #define BAD(status) (!GOOD(status)) Bit 0 set if OK, otherwise clear */
157:
2.3 timbl 158: #ifndef _WINDOWS
2.1 timbl 159: #ifndef BOOLEAN_DEFINED
160: typedef char BOOLEAN; /* Logical value */
161: #ifndef CURSES
162: #ifndef TRUE
163: #define TRUE (BOOLEAN)1
164: #define FALSE (BOOLEAN)0
165: #endif
2.3 timbl 166: #endif /* CURSES */
167: #endif /* _WINDOWS */
2.1 timbl 168: #define BOOLEAN_DEFINED
169: #endif
170:
171: #ifndef BOOL
172: #define BOOL BOOLEAN
173: #endif
174: #ifndef YES
175: #define YES (BOOLEAN)1
176: #define NO (BOOLEAN)0
177: #endif
178:
2.11 ! timbl 179: #ifndef HTMIN
! 180: #define HTMIN(a,b) ((a) <= (b) ? (a) : (b))
! 181: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1 timbl 182: #endif
183:
184: #define TCP_PORT 80 /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
185: #define OLD_TCP_PORT 2784 /* Try the old one if no answer on 80 */
186: #define DNP_OBJ 80 /* This one doesn't look busy, but we must check */
2.3 timbl 187: /* That one was for decnet */
2.1 timbl 188:
189: /* Inline Function WHITE: Is character c white space? */
190: /* For speed, include all control characters */
191:
2.3 timbl 192: #define WHITE(c) (((unsigned char)(TOASCII(c))) <= 32)
2.1 timbl 193:
194:
2.3 timbl 195: </PRE>
196: <H2>Sucess (>=0) and failure (<0) codes</H2>
197: <PRE>
2.1 timbl 198: #define HT_LOADED 29999 /* Instead of a socket */
2.9 luotonen 199: #define HT_REDIRECTION_ON_FLY 29998 /* Redo the retrieve with a new URL */
200:
2.1 timbl 201: #define HT_OK 0 /* Generic success*/
202:
203: #define HT_NO_ACCESS -10 /* Access not available */
204: #define HT_FORBIDDEN -11 /* Access forbidden */
205: #define HT_INTERNAL -12 /* Weird -- should never happen. */
206: #define HT_BAD_EOF -12 /* Premature EOF */
207:
2.7 luotonen 208:
2.3 timbl 209: #include "HTString.h" /* String utilities */
2.1 timbl 210:
211: #ifdef __STDC__
2.3 timbl 212: #include <stdarg.h>
2.1 timbl 213: #else
2.3 timbl 214: #include <varargs.h>
2.1 timbl 215: #endif
216:
217: #ifdef CURSES
218: /* htbrowse.c; */
2.6 timbl 219: #ifdef ULTRIX /* or DECSTATION */
220: #include <cursesX.h> /* Extended curses under X. Only decent one :lou. */
221: #else
2.3 timbl 222: #include <curses.h>
2.6 timbl 223: #endif /* ULTRIX */
2.1 timbl 224: extern WINDOW *w_top, *w_text, *w_prompt;
225: extern void user_message PARAMS((const char *fmt, ...));
226: extern void prompt_set PARAMS((CONST char * msg));
227: extern void prompt_count PARAMS((long kb));
228: #else
229: #define user_message printf
230: #endif
231:
2.3 timbl 232: </PRE>
233: <H2>Out Of Memory checking for malloc()
234: return:</H2>
235: <PRE>#ifndef __FILE__
2.1 timbl 236: #define __FILE__ ""
237: #define __LINE__ ""
238: #endif
239:
240: #define outofmem(file, func) \
241: { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
242: exit(1);}
243: /* extern void outofmem PARAMS((const char *fname, const char *func)); */
244:
245:
2.3 timbl 246: </PRE>
247: <H3>who put these in and what are they
248: anyway?</H3>
249: <PRE>#ifdef THEY_WILL_BE_REMOVED
2.1 timbl 250: extern void msg_init PARAMS((int height));
251: extern void msg_printf PARAMS((int y, const char *fmt, ...));
252: extern void msg_exit PARAMS((int wait_for_key));
2.3 timbl 253: #endif
2.1 timbl 254:
2.3 timbl 255: </PRE>
256: <H2>Upper- and Lowercase macros</H2>The problem here is that toupper(x)
257: is not defined officially unless
258: isupper(x) is. These macros are
259: CERTAINLY needed on #if defined(pyr)
260: || define(mips) or BDSI platforms.
261: For safefy, we make them mandatory.
262: <PRE>#include <ctype.h>
2.1 timbl 263:
264: #ifndef TOLOWER
265: /* Pyramid and Mips can't uppercase non-alpha */
266: #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
267: #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
268: #endif /* ndef TOLOWER */
269:
2.6 timbl 270: </PRE>
271: <H2>The local equivalents of CR and LF</H2>We can check for these after net
272: ascii text has been converted to
273: the local representation. Similarly,
274: we include them in strings to be
275: sent as net ascii after translation.
276: <PRE>#define LF FROMASCII('\012') /* ASCII line feed LOCAL EQUIVALENT */
277: #define CR FROMASCII('\015') /* Will be converted to ^M for transmission */
278:
2.1 timbl 279: #endif /* HTUTILS_H */
280:
2.11 ! timbl 281: </PRE>end of utilities</BODY>
2.6 timbl 282: </HTML>
Webmaster