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

2.6       timbl       1: <HTML>
                      2: <HEAD>
2.20    ! frystyk     3: <TITLE>Utility macros for the W3 code library</TITLE>
2.6       timbl       4: <NEXTID N="z2">
                      5: </HEAD>
2.3       timbl       6: <BODY>
2.20    ! frystyk     7: <H1>Macros for general use</H1>
        !             8: 
        !             9: This module is a very basic module of the <A HREF="Overview.html">CERN
        !            10: Common Code Library</A> See also: the system dependent file<A NAME="z0"
        !            11: HREF="tcp.html">"tcp.h"</A> for system specific information.
        !            12: 
2.1       timbl      13: <PRE>
                     14: #ifndef HTUTILS_H
                     15: #define HTUTILS_H
                     16: 
2.20    ! frystyk    17: #ifndef DEBUG
        !            18: #define DEBUG  /* No one ever turns this off as trace is too important */
        !            19: #endif         /* Keep option for really small memory applications too */
        !            20: 
2.3       timbl      21: #ifdef _WINDOWS                                /* SCW */
                     22: #include "windef.h"
                     23: #define BOOLEAN_DEFINED
                     24: #endif
                     25: 
2.1       timbl      26: #ifdef SHORT_NAMES
                     27: #define WWW_TraceFlag HTTrFlag
                     28: #endif
                     29: 
2.20    ! frystyk    30: #ifndef STDIO_H
2.3       timbl      31: #include &lt;stdio.h>
2.1       timbl      32: #define STDIO_H
                     33: #endif
2.20    ! frystyk    34: </PRE>
        !            35: 
        !            36: <H2>Debug message control</H2>
        !            37: 
        !            38: This is the global flag for setting the TRACE options.
        !            39: 
        !            40: <PRE>
        !            41: extern int WWW_TraceFlag;                   /* Global flag for all W3 trace */
        !            42: </PRE>
        !            43: 
        !            44: The verbose mode is no longer a simple boolean but a bit field so that it is
        !            45: possible to see parts of the output messages. The <EM>TRACE</EM> define still
        !            46: outputs all messages if verbose mode is active, but in addition the following
        !            47: TRACE defines have been made:
2.1       timbl      48: 
2.20    ! frystyk    49: <PRE>
        !            50: typedef enum _HTTraceFlags {
        !            51:     SHOW_SGML_TRACE    = 0xF,                          /*              1111 */
        !            52:     SHOW_PROTOCOL_TRACE = 0xF0,                                /*         1111.0000 */
        !            53:     SHOW_URI_TRACE     = 0x300,                        /*      11.0000.0000 */
        !            54:     SHOW_ANCHOR_TRACE  = 0xC00,                        /*   11.00.0000.0000 */
        !            55:     SHOW_ALL_TRACE     = 0xFFF                         /*   11.11.1111.1111 */
        !            56: } HTTraceFlags;
        !            57: </PRE>
        !            58: 
        !            59: The flags are made so that they can serve as a group flag for correlated
        !            60: trace messages, e.g. showing messages for SGML and HTML at the same time. 
        !            61: 
        !            62: <PRE>
2.1       timbl      63: #ifdef DEBUG
2.20    ! frystyk    64: #define TRACE          (WWW_TraceFlag)
        !            65: #define SGML_TRACE     (WWW_TraceFlag & SHOW_SGML_TRACE)
        !            66: #define PROT_TRACE     (WWW_TraceFlag & SHOW_PROTOCOL_TRACE)
        !            67: #define URI_TRACE      (WWW_TraceFlag & SHOW_URI_TRACE)
        !            68: #define ANCH_TRACE     (WWW_TraceFlag & SHOW_ANCHOR_TRACE)
        !            69: #define PROGRESS(str)  printf(str)
2.1       timbl      70: #else
2.20    ! frystyk    71: #define TRACE          0
        !            72: #define SGML_TRACE     0
        !            73: #define PROT_TRACE     0
        !            74: #define URI_TRACE      0
        !            75: #define ANCH_TRACE     0
        !            76: #define PROGRESS(str)  /* nothing for now */
2.1       timbl      77: #endif
2.20    ! frystyk    78: </PRE>
        !            79: 
        !            80: <EM><B>Note: </B> The CTRACE flag might interfere with other if () else
        !            81: constructions in the code</EM>
2.1       timbl      82: 
2.20    ! frystyk    83: <PRE>
        !            84: #define CTRACE if(TRACE) fprintf
2.5       timbl      85: #define tfp stderr
2.20    ! frystyk    86: </PRE>
2.1       timbl      87: 
2.20    ! frystyk    88: 
        !            89: <H2>Error type</H2>
2.17      frystyk    90: 
                     91: THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>
                     92: 
                     93: This is passed back when streams
2.6       timbl      94: are aborted. It might be nice to
                     95: have some structure of error messages,
                     96: numbers, and recursive pointers to
                     97: reasons. Curently this is a placeholder
                     98: for something more sophisticated.
                     99: <PRE>typedef void * HTError;                   /* Unused at present -- best definition? */
2.1       timbl     100: 
2.3       timbl     101: </PRE>
                    102: <H2>Standard C library for malloc() etc</H2>
2.19      duns      103: 
                    104: Replace memory allocation and free C RTL functions
                    105: with VAXC$xxx_OPT altrenatives for VAXC (but not DECC)
                    106: on VMS. This makes a big performance difference. (Foteos
                    107: Macrides).
                    108: 
2.3       timbl     109: <PRE>#ifdef vax
2.1       timbl     110: #ifdef unix
                    111: #define ultrix /* Assume vax+unix=ultrix */
                    112: #endif
                    113: #endif
                    114: 
                    115: #ifndef VMS
                    116: #ifndef ultrix
                    117: #ifdef NeXT
2.3       timbl     118: #include &lt;libc.h>   /* NeXT */
2.1       timbl     119: #endif
2.16      luotonen  120: #ifndef Mips
2.1       timbl     121: #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
2.3       timbl     122: #include &lt;stdlib.h> /* ANSI */
2.1       timbl     123: #endif
2.16      luotonen  124: #else /* Mips */
                    125: #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
                    126: #define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
                    127: #endif /* Mips */
2.1       timbl     128: #else /* ultrix */
2.3       timbl     129: #include &lt;malloc.h>
                    130: #include &lt;memory.h>
                    131: #include &lt;stdio.h>
2.8       secret    132: #include &lt;stdlib.h>   /* ANSI */   /* BSN */
2.1       timbl     133: #endif
                    134: 
                    135: #else  /* VMS */
2.3       timbl     136: #include &lt;stdio.h>
2.19      duns      137: #include &lt;stdlib.h>
                    138: #include &lt;unixlib.h>
2.3       timbl     139: #include &lt;ctype.h>
2.19      duns      140: #if defined(VAXC) && !defined(__DECC)
                    141: #define malloc VAXC$MALLOC_OPT
                    142: #define calloc VAXC$CALLOC_OPT
                    143: #define free   VAXC$FREE_OPT
                    144: #define cfree  VAXC$CFREE_OPT
                    145: #define realloc        VAXC$REALLOC_OPT
                    146: #endif /* VAXC but not DECC */
2.13      duns      147: #define unlink remove
2.19      duns      148: #define gmtime localtime
2.13      duns      149: #include &lt;stat.h>
                    150: #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
                    151: #define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
                    152: #define putenv HTVMS_putenv
2.1       timbl     153: #endif
                    154: 
2.3       timbl     155: </PRE>
                    156: <H2>Macros for declarations</H2>
                    157: <PRE>#define PUBLIC                    /* Accessible outside this module     */
2.1       timbl     158: #define PRIVATE static         /* Accessible only within this module */
                    159: 
                    160: #ifdef __STDC__
                    161: #define CONST const            /* "const" only exists in STDC */
                    162: #define NOPARAMS (void)
                    163: #define PARAMS(parameter_list) parameter_list
                    164: #define NOARGS (void)
                    165: #define ARGS1(t,a) \
                    166:                (t a)
                    167: #define ARGS2(t,a,u,b) \
                    168:                (t a, u b)
                    169: #define ARGS3(t,a,u,b,v,c) \
                    170:                (t a, u b, v c)
                    171: #define ARGS4(t,a,u,b,v,c,w,d) \
                    172:                (t a, u b, v c, w d)
                    173: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
                    174:                (t a, u b, v c, w d, x e)
                    175: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
                    176:                (t a, u b, v c, w d, x e, y f)
                    177: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
                    178:                (t a, u b, v c, w d, x e, y f, z g)
                    179: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
                    180:                (t a, u b, v c, w d, x e, y f, z g, s h)
                    181: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
                    182:                (t a, u b, v c, w d, x e, y f, z g, s h, r i)
                    183: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
                    184:                (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
                    185: 
                    186: #else  /* not ANSI */
                    187: 
2.3       timbl     188: #ifndef _WINDOWS
2.1       timbl     189: #define CONST
2.3       timbl     190: #endif
2.1       timbl     191: #define NOPARAMS ()
                    192: #define PARAMS(parameter_list) ()
                    193: #define NOARGS ()
                    194: #define ARGS1(t,a) (a) \
                    195:                t a;
                    196: #define ARGS2(t,a,u,b) (a,b) \
                    197:                t a; u b;
                    198: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
                    199:                t a; u b; v c;
                    200: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
                    201:                t a; u b; v c; w d;
                    202: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
                    203:                t a; u b; v c; w d; x e;
                    204: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
                    205:                t a; u b; v c; w d; x e; y f;
                    206: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
                    207:                t a; u b; v c; w d; x e; y f; z g;
                    208: #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) \
                    209:                t a; u b; v c; w d; x e; y f; z g; s h;
                    210: #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) \
                    211:                t a; u b; v c; w d; x e; y f; z g; s h; r i;
                    212: #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     213:                t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1       timbl     214:                
                    215:        
                    216: #endif /* __STDC__ (ANSI) */
                    217: 
                    218: #ifndef NULL
                    219: #define NULL ((void *)0)
                    220: #endif
                    221: 
2.3       timbl     222: </PRE>
                    223: <H2>Booleans</H2>
                    224: <PRE>/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
                    225: /* #define GOOD(status) ((status)38;1)  VMS style status: test bit 0         */
2.1       timbl     226: /* #define BAD(status)  (!GOOD(status))         Bit 0 set if OK, otherwise clear   */
                    227: 
2.3       timbl     228: #ifndef _WINDOWS
2.1       timbl     229: #ifndef BOOLEAN_DEFINED
                    230:        typedef char    BOOLEAN;                /* Logical value */
                    231: #ifndef CURSES
                    232: #ifndef TRUE
                    233: #define TRUE   (BOOLEAN)1
                    234: #define        FALSE   (BOOLEAN)0
                    235: #endif
2.3       timbl     236: #endif  /*  CURSES  */
                    237: #endif   /* _WINDOWS */
2.1       timbl     238: #define BOOLEAN_DEFINED
                    239: #endif
                    240: 
                    241: #ifndef BOOL
                    242: #define BOOL BOOLEAN
                    243: #endif
                    244: #ifndef YES
2.14      timbl     245: #define YES             (BOOL)1
                    246: #define NO              (BOOL)0
2.1       timbl     247: #endif
                    248: 
2.11      timbl     249: #ifndef HTMIN 
                    250: #define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
                    251: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1       timbl     252: #endif
                    253: 
                    254: #define TCP_PORT 80    /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
                    255: #define OLD_TCP_PORT 2784      /* Try the old one if no answer on 80 */
                    256: #define DNP_OBJ 80     /* This one doesn't look busy, but we must check */
2.3       timbl     257:                        /* That one was for decnet */
2.1       timbl     258: 
2.18      frystyk   259: </PRE>
                    260: <H2>Return Codes for Protocol Modules</H2>
2.1       timbl     261: 
2.18      frystyk   262: Theese are the codes returned from the protocol modules. Success (&gt;=0) and
                    263: failure (&lt;0) codes
2.3       timbl     264: <PRE>
2.18      frystyk   265: #define HT_NO_DATA             -9999   /* OK but no data was loaded */
                    266:                                        /* Typically, other app started */
2.15      frystyk   267: #define HT_INTERRUPTED                 -29998  /* Note the negative value! */
2.20    ! frystyk   268: #define HT_LOADED               29999  /* Instead of a socket */
        !           269: #define HT_REDIRECTION_ON_FLY   29998  /* Redo the retrieve with a new URL */
2.1       timbl     270: 
2.20    ! frystyk   271: #define HT_OK            0             /* Generic success*/
2.1       timbl     272: #define HT_NO_ACCESS   -10             /* Access not available */
                    273: #define HT_FORBIDDEN   -11             /* Access forbidden */
                    274: #define HT_INTERNAL    -12             /* Weird -- should never happen. */
2.12      luotonen  275: #define HT_BAD_EOF     -13             /* Premature EOF */
2.1       timbl     276: 
2.7       luotonen  277: 
2.3       timbl     278: #include "HTString.h"          /* String utilities */
2.1       timbl     279: 
                    280: #ifdef __STDC__
2.3       timbl     281: #include &lt;stdarg.h>
2.1       timbl     282: #else
2.3       timbl     283: #include &lt;varargs.h>
2.1       timbl     284: #endif
                    285: 
                    286: #ifdef CURSES
                    287:        /* htbrowse.c; */
2.6       timbl     288: #ifdef ULTRIX      /* or DECSTATION */
                    289: #include &lt;cursesX.h>        /* Extended curses under X. Only decent one :lou. */
                    290: #else
2.3       timbl     291: #include &lt;curses.h>
2.6       timbl     292: #endif /* ULTRIX */
2.1       timbl     293:        extern        WINDOW  *w_top, *w_text, *w_prompt;
                    294:        extern        void    user_message PARAMS((const char *fmt, ...));
                    295:        extern        void    prompt_set PARAMS((CONST char * msg));
                    296:        extern        void    prompt_count PARAMS((long kb));
                    297: #else
                    298: #define user_message printf
                    299: #endif
                    300: 
2.3       timbl     301: </PRE>
                    302: <H2>Out Of Memory checking for malloc()
                    303: return:</H2>
                    304: <PRE>#ifndef __FILE__
2.1       timbl     305: #define __FILE__ ""
                    306: #define __LINE__ ""
                    307: #endif
                    308: 
                    309: #define outofmem(file, func) \
                    310:  { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
                    311:   exit(1);}
                    312: /* extern void outofmem PARAMS((const char *fname, const char *func)); */
                    313: 
                    314: 
2.3       timbl     315: </PRE>
                    316: <H3>who put these in and what are they
                    317: anyway?</H3>
                    318: <PRE>#ifdef THEY_WILL_BE_REMOVED
2.1       timbl     319: extern void msg_init PARAMS((int height));
                    320: extern void msg_printf PARAMS((int y, const char *fmt, ...));
                    321: extern void msg_exit PARAMS((int wait_for_key));
2.3       timbl     322: #endif
2.1       timbl     323: 
2.3       timbl     324: </PRE>
                    325: <H2>Upper- and Lowercase macros</H2>The problem here is that toupper(x)
                    326: is not defined officially unless
                    327: isupper(x) is.  These macros are
                    328: CERTAINLY needed on #if defined(pyr)
                    329: || define(mips) or BDSI platforms.
                    330: For safefy, we make them mandatory.
                    331: <PRE>#include &lt;ctype.h>
2.1       timbl     332: 
                    333: #ifndef TOLOWER
                    334:   /* Pyramid and Mips can't uppercase non-alpha */
                    335: #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
                    336: #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
                    337: #endif /* ndef TOLOWER */
                    338: 
2.6       timbl     339: </PRE>
                    340: <H2>The local equivalents of CR and LF</H2>We can check for these after net
                    341: ascii text has been converted to
                    342: the local representation. Similarly,
                    343: we include them in strings to be
                    344: sent as net ascii after translation.
                    345: <PRE>#define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
                    346: #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
                    347: 
2.1       timbl     348: #endif /* HTUTILS_H */
                    349: 
2.11      timbl     350: </PRE>end of utilities</BODY>
2.6       timbl     351: </HTML>

Webmaster