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

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

Webmaster