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

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

Webmaster