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

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

Webmaster