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

2.6       timbl       1: <HTML>
                      2: <HEAD>
2.35      frystyk     3: <TITLE>Utility macros</TITLE>
2.40      frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen,  5-Nov-1995 -->
2.6       timbl       5: </HEAD>
2.3       timbl       6: <BODY>
2.24      frystyk     7: 
2.20      frystyk     8: <H1>Macros for general use</H1>
                      9: 
2.24      frystyk    10: <PRE>
                     11: /*
2.31      frystyk    12: **     (c) COPYRIGHT MIT 1995.
2.24      frystyk    13: **     Please first read the full copyright statement in the file COPYRIGH.
                     14: */
                     15: </PRE>
                     16: 
                     17: This module is a part of the <A
2.36      frystyk    18: HREF="http://www.w3.org/pub/WWW/Library/">
2.33      frystyk    19: W3C Reference Library</A>.
2.20      frystyk    20: 
2.26      frystyk    21: See also the system dependent file <A HREF="tcp.html">tcp module</A>
                     22: for system specific information. <P>
                     23: 
2.1       timbl      24: <PRE>
                     25: #ifndef HTUTILS_H
                     26: #define HTUTILS_H
                     27: 
2.26      frystyk    28: #if defined(__STDC__) || defined(__cplusplus) || defined(_WINDOWS)
                     29: #define _STANDARD_CODE_
2.1       timbl      30: #endif
2.20      frystyk    31: </PRE>
                     32: 
                     33: <H2>Debug message control</H2>
                     34: 
2.39      frystyk    35: This is the global flag for setting the WWWTRACE options.
2.20      frystyk    36: 
                     37: <PRE>
2.26      frystyk    38: #ifndef DEBUG
                     39: #define DEBUG  /* No one ever turns this off as trace is too important */
                     40: #endif         /* Keep option for really small memory applications too */
                     41: 
2.20      frystyk    42: extern int WWW_TraceFlag;                   /* Global flag for all W3 trace */
                     43: </PRE>
                     44: 
2.39      frystyk    45: The verbose mode is no longer a simple boolean but a bit field so that
                     46: it is possible to see parts of the output messages. The
                     47: <EM>WWWTRACE</EM> define still outputs all messages if verbose mode is
                     48: active, but in addition the following WWWTRACE defines have been made:
2.1       timbl      49: 
2.20      frystyk    50: <PRE>
2.40      frystyk    51: #define WWWTRACE_FILE  1
                     52: #define WWWTRACE_STDERR        2
                     53: #define WWWTRACE_TTY   3
                     54: 
                     55: #ifndef WWWTRACE_MODE
                     56: #define WWWTRACE_MODE WWWTRACE_STDERR
                     57: #endif
                     58: 
                     59: #if WWWTRACE_MODE == WWWTRACE_FILE
2.26      frystyk    60: extern FILE *WWWTrace;
2.40      frystyk    61: #ifndef WWWTRACE_FILE
                     62: #define WWWTRACE_FILE  "WWWTRACE.TXT"
2.26      frystyk    63: #endif
2.40      frystyk    64: #define TTYPrint fprintf
                     65: #define TDEST   WWWTrace
                     66: #endif
                     67: 
                     68: #if WWWTRACE_MODE == WWWTRACE_STDERR
                     69: #define TTYPrint fprintf
                     70: #define TDEST   stderr
2.26      frystyk    71: #endif
2.40      frystyk    72: 
                     73: #if WWWTRACE_MODE == WWWTRACE_TTY
                     74: #if defined(_WINDOWS) && !defined(_CONSOLE) /* EGP */
                     75: /* standard windows 3.x and non-console WIN32 programs */
2.41    ! frystyk    76: #define TDEST   0
2.40      frystyk    77: int TTYPrint(unsigned int target, const char* fmt, ...);
                     78: #else
                     79: /* if there is a real console, us it */
2.41    ! frystyk    80: #define TDEST   stderr
2.40      frystyk    81: int TTYPrint(FILE* target, const char* fmt, ...);
                     82: #endif
                     83: #endif
                     84: 
2.26      frystyk    85: 
2.20      frystyk    86: typedef enum _HTTraceFlags {
2.32      frystyk    87:     SHOW_CACHE_TRACE   = 0x2,                          /*                10 */
                     88:     SHOW_SGML_TRACE    = 0x8,                          /*              1000 */
2.29      frystyk    89:     SHOW_BIND_TRACE    = 0x10,                         /*            1.0000 */
2.32      frystyk    90:     SHOW_THREAD_TRACE  = 0x20,                         /*           10.0000 */
2.27      frystyk    91:     SHOW_STREAM_TRACE  = 0x40,                         /*          100.0000 */
2.32      frystyk    92:     SHOW_PROTOCOL_TRACE = 0x80,                                /*         1000.0000 */
                     93:     SHOW_URI_TRACE     = 0x200,                        /*      10.0000.0000 */
                     94:     SHOW_ANCHOR_TRACE  = 0x800,                        /*   10.00.0000.0000 */
2.20      frystyk    95:     SHOW_ALL_TRACE     = 0xFFF                         /*   11.11.1111.1111 */
                     96: } HTTraceFlags;
                     97: </PRE>
                     98: 
                     99: The flags are made so that they can serve as a group flag for correlated
                    100: trace messages, e.g. showing messages for SGML and HTML at the same time. 
                    101: 
                    102: <PRE>
2.1       timbl     103: #ifdef DEBUG
2.39      frystyk   104: #define WWWTRACE       (WWW_TraceFlag)
2.27      frystyk   105: #define CACHE_TRACE    (WWW_TraceFlag & SHOW_CACHE_TRACE)
2.20      frystyk   106: #define SGML_TRACE     (WWW_TraceFlag & SHOW_SGML_TRACE)
2.29      frystyk   107: #define BIND_TRACE     (WWW_TraceFlag & SHOW_BIND_TRACE)
2.23      frystyk   108: #define THD_TRACE      (WWW_TraceFlag & SHOW_THREAD_TRACE)
2.27      frystyk   109: #define STREAM_TRACE   (WWW_TraceFlag & SHOW_STREAM_TRACE)
2.20      frystyk   110: #define PROT_TRACE     (WWW_TraceFlag & SHOW_PROTOCOL_TRACE)
                    111: #define URI_TRACE      (WWW_TraceFlag & SHOW_URI_TRACE)
                    112: #define ANCH_TRACE     (WWW_TraceFlag & SHOW_ANCHOR_TRACE)
2.1       timbl     113: #else
2.39      frystyk   114: #define WWWTRACE       0
2.29      frystyk   115: #define CACHE_TRACE    0
2.20      frystyk   116: #define SGML_TRACE     0
2.29      frystyk   117: #define BIND_TRACE     0
2.27      frystyk   118: #define THD_TRACE      0
                    119: #define STREAM_TRACE   0
2.20      frystyk   120: #define PROT_TRACE     0
                    121: #define URI_TRACE      0
                    122: #define ANCH_TRACE     0
2.1       timbl     123: #endif
2.20      frystyk   124: </PRE>
2.1       timbl     125: 
2.20      frystyk   126: <H2>Error type</H2>
2.17      frystyk   127: 
                    128: THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>
                    129: 
                    130: This is passed back when streams
2.6       timbl     131: are aborted. It might be nice to
                    132: have some structure of error messages,
                    133: numbers, and recursive pointers to
                    134: reasons. Curently this is a placeholder
                    135: for something more sophisticated.
                    136: <PRE>typedef void * HTError;                   /* Unused at present -- best definition? */
2.3       timbl     137: </PRE>
2.26      frystyk   138: 
                    139: <H2>Standard C library for malloc() etc</H2>
                    140: 
                    141: Replace memory allocation and free C RTL functions with VAXC$xxx_OPT
                    142: altrenatives for VAXC (but not DECC) on VMS. This makes a big
                    143: performance difference. (Foteos Macrides).
                    144: 
                    145: <PRE>
                    146: #ifdef vax
                    147: #ifdef unix
                    148: #define ultrix /* Assume vax+unix=ultrix */
                    149: #endif
                    150: #endif
                    151: 
                    152: #ifndef VMS
                    153: #ifndef ultrix
                    154: #ifdef NeXT
                    155: #include &lt;libc.h&gt;        /* NeXT */
                    156: #endif
                    157: 
                    158: #ifndef Mips
                    159: #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
                    160: #include &lt;stdlib.h&gt;      /* ANSI */
                    161: #endif
                    162: #endif
                    163: 
                    164: #else /* ultrix */
                    165: #include &lt;malloc.h&gt;
                    166: #include &lt;memory.h&gt;
                    167: #include &lt;stdio.h&gt;
                    168: #include &lt;stdlib.h&gt;   /* ANSI */   /* BSN */
                    169: #endif
                    170: 
                    171: #else  /* VMS */
                    172: #include &lt;stdio.h&gt;
                    173: #include &lt;stdlib.h&gt;
                    174: #include &lt;unixlib.h&gt;
                    175: #include &lt;ctype.h&gt;
                    176: #if defined(VAXC) && !defined(__DECC)
                    177: #define malloc VAXC$MALLOC_OPT
                    178: #define calloc VAXC$CALLOC_OPT
                    179: #define free   VAXC$FREE_OPT
                    180: #define cfree  VAXC$CFREE_OPT
                    181: #define realloc        VAXC$REALLOC_OPT
                    182: #endif /* VAXC but not DECC */
                    183: #define unlink remove
                    184: #define gmtime localtime
                    185: #include &lt;stat.h&gt;
                    186: #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
                    187: #define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
                    188: #define putenv HTVMS_putenv
                    189: #endif
                    190: </PRE>
                    191: 
2.29      frystyk   192: <H3>Safe Cleaning Memory</H3>
                    193: 
                    194: <PRE>
                    195: #define FREE(x)        if (x) {free(x); x=NULL;}
                    196: </PRE>
                    197: 
                    198: <A NAME="declaration"><H2>Macros for declarations</H2></A>
2.26      frystyk   199: 
                    200: <PRE>
                    201: #define PUBLIC                 /* Accessible outside this module     */
2.1       timbl     202: #define PRIVATE static         /* Accessible only within this module */
                    203: 
2.26      frystyk   204: #ifdef _STANDARD_CODE_
                    205: 
2.34      frystyk   206: /* The sco ODT 3.0 CC compiler has some trouble with  const */
                    207: #if !defined(sco) || defined(sco_os5) 
2.26      frystyk   208: #define CONST const            /* "const" only exists in STDC */
                    209: #else
                    210: #define CONST
                    211: #endif
                    212: 
2.1       timbl     213: #define NOPARAMS (void)
                    214: #define PARAMS(parameter_list) parameter_list
                    215: #define NOARGS (void)
                    216: #define ARGS1(t,a) \
                    217:                (t a)
                    218: #define ARGS2(t,a,u,b) \
                    219:                (t a, u b)
                    220: #define ARGS3(t,a,u,b,v,c) \
                    221:                (t a, u b, v c)
                    222: #define ARGS4(t,a,u,b,v,c,w,d) \
                    223:                (t a, u b, v c, w d)
                    224: #define ARGS5(t,a,u,b,v,c,w,d,x,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) \
                    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) \
                    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) \
                    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) \
                    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) \
                    235:                (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
                    236: 
                    237: #else  /* not ANSI */
                    238: 
2.26      frystyk   239: #define CONST
                    240: 
2.1       timbl     241: #define NOPARAMS ()
                    242: #define PARAMS(parameter_list) ()
                    243: #define NOARGS ()
                    244: #define ARGS1(t,a) (a) \
                    245:                t a;
                    246: #define ARGS2(t,a,u,b) (a,b) \
                    247:                t a; u b;
                    248: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
                    249:                t a; u b; v c;
                    250: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
                    251:                t a; u b; v c; w d;
                    252: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
                    253:                t a; u b; v c; w d; x e;
                    254: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
                    255:                t a; u b; v c; w d; x e; y f;
                    256: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
                    257:                t a; u b; v c; w d; x e; y f; z g;
                    258: #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) \
                    259:                t a; u b; v c; w d; x e; y f; z g; s h;
                    260: #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) \
                    261:                t a; u b; v c; w d; x e; y f; z g; s h; r i;
                    262: #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     263:                t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1       timbl     264:                
                    265:        
2.21      frystyk   266: #endif /* _STANDARD_CODE_ (ANSI) */
2.1       timbl     267: 
                    268: #ifndef NULL
                    269: #define NULL ((void *)0)
                    270: #endif
2.26      frystyk   271: </PRE>
2.1       timbl     272: 
2.3       timbl     273: <H2>Booleans</H2>
2.26      frystyk   274: 
                    275: <PRE>
2.30      frystyk   276: #ifndef BOOLEAN_DEFINED
2.26      frystyk   277: typedef char   BOOLEAN;                                    /* Logical value */
2.30      frystyk   278: #endif
2.1       timbl     279: 
                    280: #ifndef CURSES
                    281: #ifndef TRUE
                    282: #define TRUE   (BOOLEAN)1
                    283: #define        FALSE   (BOOLEAN)0
                    284: #endif
2.3       timbl     285: #endif  /*  CURSES  */
2.1       timbl     286: 
                    287: #ifndef BOOL
                    288: #define BOOL BOOLEAN
                    289: #endif
                    290: #ifndef YES
2.14      timbl     291: #define YES             (BOOL)1
                    292: #define NO              (BOOL)0
2.1       timbl     293: #endif
                    294: 
2.11      timbl     295: #ifndef HTMIN 
                    296: #define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
                    297: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1       timbl     298: #endif
2.26      frystyk   299: </PRE>
2.1       timbl     300: 
2.35      frystyk   301: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules and Streams</H2></A>
                    302: 
                    303: Theese are the codes returned from the protocol modules, and the
                    304: stream modules. Success are (&gt;=0) and failure are (&lt;0)
2.1       timbl     305: 
2.3       timbl     306: <PRE>
2.23      frystyk   307: #define HT_OK                  0       /* Generic success */
2.37      frystyk   308: #define HT_ALL                 1       /* Used by Net Manager */
                    309: 
2.38      frystyk   310: #define HT_PERSISTENT          29995   /* Wait for persistent connection */
2.37      frystyk   311: #define HT_IGNORE              29996   /* Ignore this in the Net manager */
2.35      frystyk   312: #define HT_NO_DATA             29997   /* OK but no data was loaded */
                    313: #define HT_REDIRECTION_ON_FLY   29998  /* Redo the retrieve with a new URL */
2.23      frystyk   314: #define HT_LOADED              29999   /* Instead of a socket */
                    315: 
                    316: #define HT_ERROR               -1      /* Generic failure */
                    317: #define HT_NO_ACCESS           -10     /* Access not available */
                    318: #define HT_FORBIDDEN           -11     /* Access forbidden */
                    319: #define HT_INTERNAL            -12     /* Weird -- should never happen. */
2.35      frystyk   320: 
                    321: #define HT_RETRY               -29996  /* If service isn't available */
2.23      frystyk   322: #define HT_WOULD_BLOCK         -29997  /* If we are in a select */
2.15      frystyk   323: #define HT_INTERRUPTED                 -29998  /* Note the negative value! */
2.35      frystyk   324: </PRE>
                    325: 
                    326: The following codes are positive values that will be parsed back
                    327: through streams. This can be used to introduce stream specific return
                    328: values
2.1       timbl     329: 
2.35      frystyk   330: <PRE>
                    331: #define HT_RELOAD              29996   /* If we must reload the document */
                    332: </PRE>
                    333: 
                    334: <H2>Other stuff</H2>
                    335: 
                    336: <PRE>
2.26      frystyk   337: #ifdef _STANDARD_CODE_
                    338: #include &lt;stdarg.h&gt;
                    339: #else
                    340: #include &lt;varargs.h&gt;
                    341: #endif
2.1       timbl     342: 
                    343: #ifdef CURSES
2.26      frystyk   344:        /* htbrowse.c; */
                    345: #ifdef ULTRIX      /* or DECSTATION */
                    346: #include &lt;cursesX.h&gt; /* Extended curses under X. Only decent one :lou. */
                    347: #else
                    348: #include &lt;curses.h&gt;
                    349: #endif /* ULTRIX */
2.1       timbl     350:        extern        WINDOW  *w_top, *w_text, *w_prompt;
                    351:        extern        void    user_message PARAMS((const char *fmt, ...));
                    352:        extern        void    prompt_set PARAMS((CONST char * msg));
                    353:        extern        void    prompt_count PARAMS((long kb));
                    354: #else
                    355: #define user_message printf
                    356: #endif
                    357: 
2.3       timbl     358: </PRE>
2.26      frystyk   359: 
                    360: <H2>Out Of Memory checking for malloc() return:</H2>
                    361: 
                    362: <PRE>
                    363: #ifndef __FILE__
2.1       timbl     364: #define __FILE__ ""
                    365: #define __LINE__ ""
                    366: #endif
                    367: 
                    368: #define outofmem(file, func) \
2.26      frystyk   369:  { fprintf(TDEST, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
2.1       timbl     370:   exit(1);}
                    371: 
2.26      frystyk   372: </PRE>
2.1       timbl     373: 
2.26      frystyk   374: <H2>Upper- and Lowercase macros</H2>
                    375: 
                    376: The problem here is that toupper(x) is not defined officially unless
                    377: isupper(x) is.  These macros are CERTAINLY needed on #if defined(pyr)
                    378: || define(mips) or BDSI platforms. For safefy, we make them mandatory.
2.1       timbl     379: 
2.25      roeber    380: <PRE>
2.26      frystyk   381: #include &lt;ctype.h&gt;
2.1       timbl     382: 
                    383: #ifndef TOLOWER
2.27      frystyk   384: #define TOLOWER(c) tolower(c)
                    385: #define TOUPPER(c) toupper(c)
2.29      frystyk   386: #endif
                    387: </PRE>
                    388: 
                    389: <H2>Max and Min values for Integers and Floating Point</H2>
                    390: 
                    391: <PRE>
                    392: #ifdef FLT_EPSILON                                 /* The ANSI C way define */
                    393: #define HT_EPSILON FLT_EPSILON
                    394: #else
                    395: #define HT_EPSILON 0.00000001
2.27      frystyk   396: #endif
                    397: </PRE>
                    398: 
                    399: <H2>White Characters</H2>
                    400: 
                    401: Is character <B>c</B> white space?
                    402: 
                    403: <PRE>
                    404: #ifdef OLD_CODE
                    405: #define WHITE(c) (((unsigned char)(TOASCII(c))) &lt;= 32)
                    406: #else
                    407: #define WHITE(c) isspace(c)
                    408: #endif
2.26      frystyk   409: </PRE>
                    410: 
                    411: <H2>The local equivalents of CR and LF</H2>
2.1       timbl     412: 
2.26      frystyk   413: We can check for these after net ascii text has been converted to the
                    414: local representation. Similarly, we include them in strings to be sent
                    415: as net ascii after translation.
                    416: 
                    417: <PRE>
                    418: #define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
                    419: #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
2.6       timbl     420: 
2.1       timbl     421: #endif /* HTUTILS_H */
2.26      frystyk   422: </PRE>
2.1       timbl     423: 
2.26      frystyk   424: end of utilities
                    425: </BODY>
2.6       timbl     426: </HTML>

Webmaster