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