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