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

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

Webmaster