Annotation of libwww/Library/src/HTUtils.html, revision 2.4

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

Webmaster