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

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

Webmaster