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

2.6       timbl       1: <HTML>
                      2: <HEAD>
2.63      frystyk     3: <TITLE>W3C Reference Library libwww BASIC MACROS</TITLE>
2.68    ! frystyk     4: <!-- Changed by: Henrik Frystyk Nielsen,  6-Apr-1996 -->
2.6       timbl       5: </HEAD>
2.3       timbl       6: <BODY>
2.24      frystyk     7: 
2.56      frystyk     8: <H1>General Purpose Macros</H1>
2.20      frystyk     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.44      frystyk    18: HREF="http://www.w3.org/pub/WWW/Library/"> W3C Reference Library</A>.
2.20      frystyk    19: 
2.62      frystyk    20: See also the system dependent file <A HREF="sysdep.html">tcp module</A>
2.26      frystyk    21: for system specific information. <P>
                     22: 
2.1       timbl      23: <PRE>
                     24: #ifndef HTUTILS_H
                     25: #define HTUTILS_H
2.56      frystyk    26: </PRE>
                     27: 
                     28: <A NAME="debug"><H2>Debug Message Control</H2></A>
2.20      frystyk    29: 
2.56      frystyk    30: This is the global flag for setting the WWWTRACE options. The verbose
                     31: mode is no longer a simple boolean but a bit field so that it is
                     32: possible to see parts of the output messages. 
2.20      frystyk    33: 
                     34: <PRE>
2.26      frystyk    35: #ifndef DEBUG
                     36: #define DEBUG  /* No one ever turns this off as trace is too important */
2.56      frystyk    37: #endif
                     38: </PRE>
                     39: 
                     40: <H3>Definition of the Global Trace Flag</H3>
2.26      frystyk    41: 
2.56      frystyk    42: The global trace flag variable is available everywhere.
                     43: 
                     44: <PRE>
                     45: #ifdef DEBUG
2.44      frystyk    46: #ifdef WWW_WIN_DLL
2.56      frystyk    47: extern int *           WWW_TraceFlag;   /* In DLLs, we need the indirection */
                     48: #define WWWTRACE       (*WWW_TraceFlag) 
2.44      frystyk    49: #else
2.56      frystyk    50: extern int             WWW_TraceFlag;       /* Global flag for all W3 trace */
                     51: #define WWWTRACE       (WWW_TraceFlag)
                     52: #endif /* WWW_WIN_DLL */
                     53: #else
                     54: #define WWWTRACE       0
                     55: #endif /* DEBUG */
2.20      frystyk    56: </PRE>
                     57: 
2.56      frystyk    58: The <EM>WWWTRACE</EM> define outputs messages if verbose mode is
                     59: active according to the following rules:
2.1       timbl      60: 
2.20      frystyk    61: <PRE>
2.56      frystyk    62: typedef enum _HTTraceFlags {
                     63:     SHOW_UTIL_TRACE    = 0x1,                          /*                 1 */
                     64:     SHOW_APP_TRACE     = 0x2,                          /*                10 */
                     65:     SHOW_CACHE_TRACE   = 0x4,                          /*               100 */
                     66:     SHOW_SGML_TRACE    = 0x8,                          /*              1000 */
                     67:     SHOW_BIND_TRACE    = 0x10,                         /*            1.0000 */
                     68:     SHOW_THREAD_TRACE  = 0x20,                         /*           10.0000 */
                     69:     SHOW_STREAM_TRACE  = 0x40,                         /*          100.0000 */
                     70:     SHOW_PROTOCOL_TRACE = 0x80,                                /*         1000.0000 */
2.57      frystyk    71:     SHOW_MEM_TRACE     = 0x100,                        /*       1.0000.0000 */
2.56      frystyk    72:     SHOW_URI_TRACE     = 0x200,                        /*      10.0000.0000 */
2.67      hallam     73:     SHOW_AUTH_TRACE    = 0x400,                        /*     100.0000.0000 */
                     74:     SHOW_ANCHOR_TRACE  = 0x800,                        /*    1000.0000.0000 */
                     75:     SHOW_PICS_TRACE    = 0x1000,                       /*  1.0000.0000.0000 */
                     76:     SHOW_CORE_TRACE    = 0x2000,                       /* 10.0000.0000.0000 */
                     77:     SHOW_ALL_TRACE     = 0x3FFF                        /* 11.1111.1111.1111 */
2.56      frystyk    78: } HTTraceFlags;
                     79: </PRE>
                     80: 
                     81: The flags are made so that they can serve as a group flag for
                     82: correlated trace messages, e.g. showing messages for SGML and HTML at
                     83: the same time.
                     84: 
                     85: <PRE>
                     86: #define UTIL_TRACE     (WWWTRACE & SHOW_UTIL_TRACE)
                     87: #define APP_TRACE      (WWWTRACE & SHOW_APP_TRACE)
                     88: #define CACHE_TRACE    (WWWTRACE & SHOW_CACHE_TRACE)
                     89: #define SGML_TRACE     (WWWTRACE & SHOW_SGML_TRACE)
                     90: #define BIND_TRACE     (WWWTRACE & SHOW_BIND_TRACE)
                     91: #define THD_TRACE      (WWWTRACE & SHOW_THREAD_TRACE)
                     92: #define STREAM_TRACE   (WWWTRACE & SHOW_STREAM_TRACE)
                     93: #define PROT_TRACE     (WWWTRACE & SHOW_PROTOCOL_TRACE)
2.57      frystyk    94: #define MEM_TRACE      (WWWTRACE & SHOW_MEM_TRACE)
2.56      frystyk    95: #define URI_TRACE      (WWWTRACE & SHOW_URI_TRACE)
2.61      frystyk    96: #define AUTH_TRACE     (WWWTRACE & SHOW_AUTH_TRACE)
2.56      frystyk    97: #define ANCH_TRACE     (WWWTRACE & SHOW_ANCHOR_TRACE)
2.67      hallam     98: #define PICS_TRACE     (WWWTRACE & SHOW_PICS_TRACE)
                     99: #define CORE_TRACE     (WWWTRACE & SHOW_CORE_TRACE)
2.56      frystyk   100: </PRE>
                    101: 
2.59      frystyk   102: <H3>Destination for Trace Messages</H3>
                    103: 
                    104: You can send trace messages to various destinations depending on the
                    105: type of your application. By default, on Unix the messages are sent to
                    106: stderr using fprintf() and if we are on Windows and have a windows
                    107: applications then register a HTTraceCallback function. This is done with
                    108: HTTrace_setCallback. It tells HTTrace to call a HTTraceCallback. If your 
                    109: compiler has problems with va_list, then you may forget about registering 
                    110: the callback and instead macro HTTrace as follows:
                    111: #define HTTrace MyAppSpecificTrace
                    112: 
2.67      hallam    113: <A NAME="HTTrace"></A>
2.59      frystyk   114: <PRE>
2.62      frystyk   115: typedef int HTTraceCallback(const char * fmt, va_list pArgs);
2.59      frystyk   116: 
                    117: extern void HTTrace_setCallback(HTTraceCallback * pCall);
                    118: extern HTTraceCallback * HTTrace_getCallback(void);
                    119: 
2.62      frystyk   120: extern int HTTrace(const char * fmt, ...);
2.26      frystyk   121: </PRE>
                    122: 
2.56      frystyk   123: <A NAME="declaration"><H2>Macros for Function Declarations</H2></A>
2.26      frystyk   124: 
                    125: <PRE>
                    126: #define PUBLIC                 /* Accessible outside this module     */
2.1       timbl     127: #define PRIVATE static         /* Accessible only within this module */
2.56      frystyk   128: </PRE>
                    129: 
                    130: <H2>Often used Interger Macros</H2>
2.1       timbl     131: 
2.56      frystyk   132: <H3>Min and Max functions</H3>
                    133: 
                    134: <PRE>
2.11      timbl     135: #ifndef HTMIN 
                    136: #define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
                    137: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1       timbl     138: #endif
2.26      frystyk   139: </PRE>
2.1       timbl     140: 
2.56      frystyk   141: <H3>Double abs function</H3>
                    142: 
                    143: <PRE>
                    144: #ifndef HTDABS
                    145: #define HTDABS(a) ((a) &lt; 0.0 ? (-(a)) : (a))
                    146: #endif
                    147: </PRE>
                    148: 
2.35      frystyk   149: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules and Streams</H2></A>
                    150: 
                    151: Theese are the codes returned from the protocol modules, and the
                    152: stream modules. Success are (&gt;=0) and failure are (&lt;0)
2.1       timbl     153: 
2.3       timbl     154: <PRE>
2.23      frystyk   155: #define HT_OK                  0       /* Generic success */
2.37      frystyk   156: #define HT_ALL                 1       /* Used by Net Manager */
                    157: 
2.53      frystyk   158: #define HT_CLOSED              29992   /* The socket was closed */
2.52      frystyk   159: #define HT_PERSISTENT          29993   /* Wait for persistent connection */
                    160: #define HT_IGNORE              29994   /* Ignore this in the Net manager */
                    161: #define HT_NO_DATA             29995   /* OK but no data was loaded */
2.53      frystyk   162: #define HT_RELOAD              29996   /* If we must reload the document */
2.52      frystyk   163: #define HT_PERM_REDIRECT       29997   /* Redo the retrieve with a new URL */
                    164: #define HT_TEMP_REDIRECT       29998   /* Redo the retrieve with a new URL */
2.23      frystyk   165: #define HT_LOADED              29999   /* Instead of a socket */
                    166: 
                    167: #define HT_ERROR               -1      /* Generic failure */
2.53      frystyk   168: 
2.23      frystyk   169: #define HT_NO_ACCESS           -10     /* Access not available */
                    170: #define HT_FORBIDDEN           -11     /* Access forbidden */
2.53      frystyk   171: #define HT_RETRY               -13     /* If service isn't available */
                    172: 
                    173: #define HT_INTERNAL            -100    /* Weird -- should never happen. */
2.35      frystyk   174: 
2.23      frystyk   175: #define HT_WOULD_BLOCK         -29997  /* If we are in a select */
2.15      frystyk   176: #define HT_INTERRUPTED                 -29998  /* Note the negative value! */
2.53      frystyk   177: #define HT_PAUSE                -29999  /* If we want to pause a stream */
2.35      frystyk   178: </PRE>
                    179: 
2.26      frystyk   180: <H2>Upper- and Lowercase macros</H2>
                    181: 
                    182: The problem here is that toupper(x) is not defined officially unless
                    183: isupper(x) is.  These macros are CERTAINLY needed on #if defined(pyr)
                    184: || define(mips) or BDSI platforms. For safefy, we make them mandatory.
2.1       timbl     185: 
2.25      roeber    186: <PRE>
2.1       timbl     187: #ifndef TOLOWER
2.27      frystyk   188: #define TOLOWER(c) tolower(c)
                    189: #define TOUPPER(c) toupper(c)
2.29      frystyk   190: #endif
                    191: </PRE>
                    192: 
                    193: <H2>Max and Min values for Integers and Floating Point</H2>
                    194: 
                    195: <PRE>
                    196: #ifdef FLT_EPSILON                                 /* The ANSI C way define */
                    197: #define HT_EPSILON FLT_EPSILON
                    198: #else
                    199: #define HT_EPSILON 0.00000001
2.27      frystyk   200: #endif
                    201: </PRE>
                    202: 
                    203: <H2>White Characters</H2>
                    204: 
                    205: Is character <B>c</B> white space?
                    206: 
                    207: <PRE>
                    208: #define WHITE(c) isspace(c)
2.26      frystyk   209: </PRE>
                    210: 
                    211: <H2>The local equivalents of CR and LF</H2>
2.1       timbl     212: 
2.26      frystyk   213: We can check for these after net ascii text has been converted to the
                    214: local representation. Similarly, we include them in strings to be sent
                    215: as net ascii after translation.
                    216: 
                    217: <PRE>
                    218: #define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
                    219: #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
2.54      frystyk   220: </PRE>
                    221: 
                    222: <H2>Library Dynamic Memory Magement</H2>
                    223: 
                    224: The Library has it's own dynamic memory API which is declared in <A
                    225: HREF="HTMemory.html">memory management module</A>.
                    226: 
                    227: <PRE>
2.55      frystyk   228: #include "HTMemory.h"
2.26      frystyk   229: </PRE>
2.1       timbl     230: 
2.56      frystyk   231: <PRE>
                    232: #endif /* HT_UTILS.h */
                    233: </PRE>
                    234: 
2.68    ! frystyk   235: <HR>
        !           236: <ADDRESS>
        !           237: @(#) $Id: Date Author State $
        !           238: </ADDRESS>
2.26      frystyk   239: </BODY>
2.6       timbl     240: </HTML>

Webmaster