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

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.22      frystyk   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.3       timbl     210: #ifndef _WINDOWS
2.1       timbl     211: #define CONST
2.3       timbl     212: #endif
2.1       timbl     213: #define NOPARAMS ()
                    214: #define PARAMS(parameter_list) ()
                    215: #define NOARGS ()
                    216: #define ARGS1(t,a) (a) \
                    217:                t a;
                    218: #define ARGS2(t,a,u,b) (a,b) \
                    219:                t a; u b;
                    220: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
                    221:                t a; u b; v c;
                    222: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
                    223:                t a; u b; v c; w d;
                    224: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
                    225:                t a; u b; v c; w d; x e;
                    226: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
                    227:                t a; u b; v c; w d; x e; y f;
                    228: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
                    229:                t a; u b; v c; w d; x e; y f; z g;
                    230: #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) \
                    231:                t a; u b; v c; w d; x e; y f; z g; s h;
                    232: #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) \
                    233:                t a; u b; v c; w d; x e; y f; z g; s h; r i;
                    234: #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     235:                t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1       timbl     236:                
                    237:        
2.21      frystyk   238: #endif /* _STANDARD_CODE_ (ANSI) */
2.1       timbl     239: 
                    240: #ifndef NULL
                    241: #define NULL ((void *)0)
                    242: #endif
                    243: 
2.3       timbl     244: </PRE>
                    245: <H2>Booleans</H2>
                    246: <PRE>/* Note: GOOD and BAD are already defined (differently) on RS6000 aix */
                    247: /* #define GOOD(status) ((status)38;1)  VMS style status: test bit 0         */
2.1       timbl     248: /* #define BAD(status)  (!GOOD(status))         Bit 0 set if OK, otherwise clear   */
                    249: 
2.3       timbl     250: #ifndef _WINDOWS
2.1       timbl     251: #ifndef BOOLEAN_DEFINED
                    252:        typedef char    BOOLEAN;                /* Logical value */
                    253: #ifndef CURSES
                    254: #ifndef TRUE
                    255: #define TRUE   (BOOLEAN)1
                    256: #define        FALSE   (BOOLEAN)0
                    257: #endif
2.3       timbl     258: #endif  /*  CURSES  */
                    259: #endif   /* _WINDOWS */
2.1       timbl     260: #define BOOLEAN_DEFINED
                    261: #endif
                    262: 
                    263: #ifndef BOOL
                    264: #define BOOL BOOLEAN
                    265: #endif
                    266: #ifndef YES
2.14      timbl     267: #define YES             (BOOL)1
                    268: #define NO              (BOOL)0
2.1       timbl     269: #endif
                    270: 
2.11      timbl     271: #ifndef HTMIN 
                    272: #define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
                    273: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1       timbl     274: #endif
                    275: 
                    276: #define TCP_PORT 80    /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
                    277: #define OLD_TCP_PORT 2784      /* Try the old one if no answer on 80 */
                    278: #define DNP_OBJ 80     /* This one doesn't look busy, but we must check */
2.3       timbl     279:                        /* That one was for decnet */
2.1       timbl     280: 
2.18      frystyk   281: </PRE>
2.23      frystyk   282: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules</H2></A>
2.1       timbl     283: 
2.18      frystyk   284: Theese are the codes returned from the protocol modules. Success (&gt;=0) and
                    285: failure (&lt;0) codes
2.3       timbl     286: <PRE>
2.23      frystyk   287: #define HT_OK                  0       /* Generic success */
                    288: #define HT_LOADED              29999   /* Instead of a socket */
                    289: #define HT_REDIRECTION_ON_FLY   29998  /* Redo the retrieve with a new URL */
                    290: 
                    291: #define HT_ERROR               -1      /* Generic failure */
                    292: #define HT_NO_ACCESS           -10     /* Access not available */
                    293: #define HT_FORBIDDEN           -11     /* Access forbidden */
                    294: #define HT_INTERNAL            -12     /* Weird -- should never happen. */
2.18      frystyk   295: #define HT_NO_DATA             -9999   /* OK but no data was loaded */
                    296:                                        /* Typically, other app started */
2.23      frystyk   297: #define HT_WOULD_BLOCK         -29997  /* If we are in a select */
2.15      frystyk   298: #define HT_INTERRUPTED                 -29998  /* Note the negative value! */
2.1       timbl     299: 
2.7       luotonen  300: 
2.3       timbl     301: #include "HTString.h"          /* String utilities */
2.1       timbl     302: 
2.21      frystyk   303: #ifdef _STANDARD_CODE_
2.3       timbl     304: #include &lt;stdarg.h>
2.1       timbl     305: #else
2.3       timbl     306: #include &lt;varargs.h>
2.1       timbl     307: #endif
                    308: 
                    309: #ifdef CURSES
                    310:        /* htbrowse.c; */
2.6       timbl     311: #ifdef ULTRIX      /* or DECSTATION */
                    312: #include &lt;cursesX.h>        /* Extended curses under X. Only decent one :lou. */
                    313: #else
2.3       timbl     314: #include &lt;curses.h>
2.6       timbl     315: #endif /* ULTRIX */
2.1       timbl     316:        extern        WINDOW  *w_top, *w_text, *w_prompt;
                    317:        extern        void    user_message PARAMS((const char *fmt, ...));
                    318:        extern        void    prompt_set PARAMS((CONST char * msg));
                    319:        extern        void    prompt_count PARAMS((long kb));
                    320: #else
                    321: #define user_message printf
                    322: #endif
                    323: 
2.3       timbl     324: </PRE>
                    325: <H2>Out Of Memory checking for malloc()
                    326: return:</H2>
                    327: <PRE>#ifndef __FILE__
2.1       timbl     328: #define __FILE__ ""
                    329: #define __LINE__ ""
                    330: #endif
                    331: 
                    332: #define outofmem(file, func) \
                    333:  { fprintf(stderr, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
                    334:   exit(1);}
                    335: /* extern void outofmem PARAMS((const char *fname, const char *func)); */
                    336: 
                    337: 
2.3       timbl     338: </PRE>
                    339: <H3>who put these in and what are they
                    340: anyway?</H3>
                    341: <PRE>#ifdef THEY_WILL_BE_REMOVED
2.1       timbl     342: extern void msg_init PARAMS((int height));
                    343: extern void msg_printf PARAMS((int y, const char *fmt, ...));
                    344: extern void msg_exit PARAMS((int wait_for_key));
2.3       timbl     345: #endif
2.1       timbl     346: 
2.3       timbl     347: </PRE>
                    348: <H2>Upper- and Lowercase macros</H2>The problem here is that toupper(x)
                    349: is not defined officially unless
                    350: isupper(x) is.  These macros are
                    351: CERTAINLY needed on #if defined(pyr)
                    352: || define(mips) or BDSI platforms.
                    353: For safefy, we make them mandatory.
                    354: <PRE>#include &lt;ctype.h>
2.1       timbl     355: 
                    356: #ifndef TOLOWER
                    357:   /* Pyramid and Mips can't uppercase non-alpha */
                    358: #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
                    359: #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
                    360: #endif /* ndef TOLOWER */
                    361: 
2.6       timbl     362: </PRE>
                    363: <H2>The local equivalents of CR and LF</H2>We can check for these after net
                    364: ascii text has been converted to
                    365: the local representation. Similarly,
                    366: we include them in strings to be
                    367: sent as net ascii after translation.
                    368: <PRE>#define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
                    369: #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
                    370: 
2.1       timbl     371: #endif /* HTUTILS_H */
                    372: 
2.11      timbl     373: </PRE>end of utilities</BODY>
2.6       timbl     374: </HTML>

Webmaster