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

Webmaster