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