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