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

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

Webmaster