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

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

Webmaster