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

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: This module is a part of the <A
                     17: HREF="http://info.cern.ch/hypertext/WWW/Library/User/Guide/Guide.html">
                     18: Library of Common Code</A>.
2.20      frystyk    19: 
2.26    ! frystyk    20: See also the system dependent file <A HREF="tcp.html">tcp module</A>
        !            21: for system specific information. <P>
        !            22: 
2.1       timbl      23: <PRE>
                     24: #ifndef HTUTILS_H
                     25: #define HTUTILS_H
                     26: 
2.26    ! frystyk    27: #if defined(__STDC__) || defined(__cplusplus) || defined(_WINDOWS)
        !            28: #define _STANDARD_CODE_
2.1       timbl      29: #endif
2.20      frystyk    30: </PRE>
                     31: 
                     32: <H2>Debug message control</H2>
                     33: 
                     34: This is the global flag for setting the TRACE options.
                     35: 
                     36: <PRE>
2.26    ! frystyk    37: #ifndef DEBUG
        !            38: #define DEBUG  /* No one ever turns this off as trace is too important */
        !            39: #endif         /* Keep option for really small memory applications too */
        !            40: 
2.20      frystyk    41: extern int WWW_TraceFlag;                   /* Global flag for all W3 trace */
                     42: </PRE>
                     43: 
                     44: The verbose mode is no longer a simple boolean but a bit field so that it is
                     45: possible to see parts of the output messages. The <EM>TRACE</EM> define still
                     46: outputs all messages if verbose mode is active, but in addition the following
                     47: TRACE defines have been made:
2.1       timbl      48: 
2.20      frystyk    49: <PRE>
2.26    ! frystyk    50: #ifdef NO_STDIO
        !            51: extern FILE *WWWTrace;
        !            52: #ifndef TRACE_FILE
        !            53: #define TRACE_FILE "WWWTRACE.TXT"
        !            54: #endif
        !            55: #define TDEST WWWTrace 
        !            56: #else /* got stdio */
        !            57: #define TDEST stderr
        !            58: #endif
        !            59: 
2.20      frystyk    60: typedef enum _HTTraceFlags {
                     61:     SHOW_SGML_TRACE    = 0xF,                          /*              1111 */
2.23      frystyk    62:     SHOW_THREAD_TRACE  = 0x30,                         /*           11.0000 */
                     63:     SHOW_PROTOCOL_TRACE = 0xC0,                                /*         1100.0000 */
2.20      frystyk    64:     SHOW_URI_TRACE     = 0x300,                        /*      11.0000.0000 */
                     65:     SHOW_ANCHOR_TRACE  = 0xC00,                        /*   11.00.0000.0000 */
                     66:     SHOW_ALL_TRACE     = 0xFFF                         /*   11.11.1111.1111 */
                     67: } HTTraceFlags;
                     68: </PRE>
                     69: 
                     70: The flags are made so that they can serve as a group flag for correlated
                     71: trace messages, e.g. showing messages for SGML and HTML at the same time. 
                     72: 
                     73: <PRE>
2.1       timbl      74: #ifdef DEBUG
2.20      frystyk    75: #define TRACE          (WWW_TraceFlag)
                     76: #define SGML_TRACE     (WWW_TraceFlag & SHOW_SGML_TRACE)
2.23      frystyk    77: #define THD_TRACE      (WWW_TraceFlag & SHOW_THREAD_TRACE)
2.20      frystyk    78: #define PROT_TRACE     (WWW_TraceFlag & SHOW_PROTOCOL_TRACE)
                     79: #define URI_TRACE      (WWW_TraceFlag & SHOW_URI_TRACE)
                     80: #define ANCH_TRACE     (WWW_TraceFlag & SHOW_ANCHOR_TRACE)
                     81: #define PROGRESS(str)  printf(str)
2.1       timbl      82: #else
2.20      frystyk    83: #define TRACE          0
                     84: #define SGML_TRACE     0
                     85: #define PROT_TRACE     0
2.23      frystyk    86: #define THD_TRACE      0
2.20      frystyk    87: #define URI_TRACE      0
                     88: #define ANCH_TRACE     0
                     89: #define PROGRESS(str)  /* nothing for now */
2.1       timbl      90: #endif
2.20      frystyk    91: </PRE>
                     92: 
2.26    ! frystyk    93: <EM><B>Note: </B> The CTRACE flag might interfere with other if ()
        !            94: else constructions in the code. IT SHOULD NOT BE USED BUT REPLACED BY
        !            95: TRACE</EM>
2.1       timbl      96: 
2.20      frystyk    97: <PRE>
                     98: #define CTRACE if(TRACE) fprintf
                     99: </PRE>
2.1       timbl     100: 
2.20      frystyk   101: <H2>Error type</H2>
2.17      frystyk   102: 
                    103: THIS IS NOW OBSOLETE AND WILL BE REMOVED IN FUTURE RELEASES <P>
                    104: 
                    105: This is passed back when streams
2.6       timbl     106: are aborted. It might be nice to
                    107: have some structure of error messages,
                    108: numbers, and recursive pointers to
                    109: reasons. Curently this is a placeholder
                    110: for something more sophisticated.
                    111: <PRE>typedef void * HTError;                   /* Unused at present -- best definition? */
2.3       timbl     112: </PRE>
2.26    ! frystyk   113: 
        !           114: <H2>Standard C library for malloc() etc</H2>
        !           115: 
        !           116: Replace memory allocation and free C RTL functions with VAXC$xxx_OPT
        !           117: altrenatives for VAXC (but not DECC) on VMS. This makes a big
        !           118: performance difference. (Foteos Macrides).
        !           119: 
        !           120: <PRE>
        !           121: #ifdef vax
        !           122: #ifdef unix
        !           123: #define ultrix /* Assume vax+unix=ultrix */
        !           124: #endif
        !           125: #endif
        !           126: 
        !           127: #ifndef VMS
        !           128: #ifndef ultrix
        !           129: #ifdef NeXT
        !           130: #include &lt;libc.h&gt;        /* NeXT */
        !           131: #endif
        !           132: 
        !           133: #ifndef Mips
        !           134: #ifndef MACH /* Vincent.Cate@furmint.nectar.cs.cmu.edu */
        !           135: #include &lt;stdlib.h&gt;      /* ANSI */
        !           136: #endif
        !           137: #endif
        !           138: 
        !           139: #else /* ultrix */
        !           140: #include &lt;malloc.h&gt;
        !           141: #include &lt;memory.h&gt;
        !           142: #include &lt;stdio.h&gt;
        !           143: #include &lt;stdlib.h&gt;   /* ANSI */   /* BSN */
        !           144: #endif
        !           145: 
        !           146: #else  /* VMS */
        !           147: #include &lt;stdio.h&gt;
        !           148: #include &lt;stdlib.h&gt;
        !           149: #include &lt;unixlib.h&gt;
        !           150: #include &lt;ctype.h&gt;
        !           151: #if defined(VAXC) && !defined(__DECC)
        !           152: #define malloc VAXC$MALLOC_OPT
        !           153: #define calloc VAXC$CALLOC_OPT
        !           154: #define free   VAXC$FREE_OPT
        !           155: #define cfree  VAXC$CFREE_OPT
        !           156: #define realloc        VAXC$REALLOC_OPT
        !           157: #endif /* VAXC but not DECC */
        !           158: #define unlink remove
        !           159: #define gmtime localtime
        !           160: #include &lt;stat.h&gt;
        !           161: #define S_ISDIR(m)      (((m)&S_IFMT) == S_IFDIR)
        !           162: #define S_ISREG(m)      (((m)&S_IFMT) == S_IFREG)
        !           163: #define putenv HTVMS_putenv
        !           164: #endif
        !           165: </PRE>
        !           166: 
2.3       timbl     167: <H2>Macros for declarations</H2>
2.26    ! frystyk   168: 
        !           169: <PRE>
        !           170: #define PUBLIC                 /* Accessible outside this module     */
2.1       timbl     171: #define PRIVATE static         /* Accessible only within this module */
                    172: 
2.26    ! frystyk   173: #ifdef _STANDARD_CODE_
        !           174: 
        !           175: #ifndef sco                    /* The sco CC compiler does not know const */
        !           176: #define CONST const            /* "const" only exists in STDC */
        !           177: #else
        !           178: #define CONST
        !           179: #endif
        !           180: 
2.1       timbl     181: #define NOPARAMS (void)
                    182: #define PARAMS(parameter_list) parameter_list
                    183: #define NOARGS (void)
                    184: #define ARGS1(t,a) \
                    185:                (t a)
                    186: #define ARGS2(t,a,u,b) \
                    187:                (t a, u b)
                    188: #define ARGS3(t,a,u,b,v,c) \
                    189:                (t a, u b, v c)
                    190: #define ARGS4(t,a,u,b,v,c,w,d) \
                    191:                (t a, u b, v c, w d)
                    192: #define ARGS5(t,a,u,b,v,c,w,d,x,e) \
                    193:                (t a, u b, v c, w d, x e)
                    194: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) \
                    195:                (t a, u b, v c, w d, x e, y f)
                    196: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) \
                    197:                (t a, u b, v c, w d, x e, y f, z g)
                    198: #define ARGS8(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h) \
                    199:                (t a, u b, v c, w d, x e, y f, z g, s h)
                    200: #define ARGS9(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i) \
                    201:                (t a, u b, v c, w d, x e, y f, z g, s h, r i)
                    202: #define ARGS10(t,a,u,b,v,c,w,d,x,e,y,f,z,g,s,h,r,i,q,j) \
                    203:                (t a, u b, v c, w d, x e, y f, z g, s h, r i, q j)
                    204: 
                    205: #else  /* not ANSI */
                    206: 
2.26    ! frystyk   207: #define CONST
        !           208: 
2.1       timbl     209: #define NOPARAMS ()
                    210: #define PARAMS(parameter_list) ()
                    211: #define NOARGS ()
                    212: #define ARGS1(t,a) (a) \
                    213:                t a;
                    214: #define ARGS2(t,a,u,b) (a,b) \
                    215:                t a; u b;
                    216: #define ARGS3(t,a,u,b,v,c) (a,b,c) \
                    217:                t a; u b; v c;
                    218: #define ARGS4(t,a,u,b,v,c,w,d) (a,b,c,d) \
                    219:                t a; u b; v c; w d;
                    220: #define ARGS5(t,a,u,b,v,c,w,d,x,e) (a,b,c,d,e) \
                    221:                t a; u b; v c; w d; x e;
                    222: #define ARGS6(t,a,u,b,v,c,w,d,x,e,y,f) (a,b,c,d,e,f) \
                    223:                t a; u b; v c; w d; x e; y f;
                    224: #define ARGS7(t,a,u,b,v,c,w,d,x,e,y,f,z,g) (a,b,c,d,e,f,g) \
                    225:                t a; u b; v c; w d; x e; y f; z g;
                    226: #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) \
                    227:                t a; u b; v c; w d; x e; y f; z g; s h;
                    228: #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) \
                    229:                t a; u b; v c; w d; x e; y f; z g; s h; r i;
                    230: #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     231:                t a; u b; v c; w d; x e; y f; z g; s h; r i; q j;
2.1       timbl     232:                
                    233:        
2.21      frystyk   234: #endif /* _STANDARD_CODE_ (ANSI) */
2.1       timbl     235: 
                    236: #ifndef NULL
                    237: #define NULL ((void *)0)
                    238: #endif
2.26    ! frystyk   239: </PRE>
2.1       timbl     240: 
2.3       timbl     241: <H2>Booleans</H2>
2.26    ! frystyk   242: 
        !           243: <PRE>
        !           244: typedef char   BOOLEAN;                                    /* Logical value */
2.1       timbl     245: 
                    246: #ifndef CURSES
                    247: #ifndef TRUE
                    248: #define TRUE   (BOOLEAN)1
                    249: #define        FALSE   (BOOLEAN)0
                    250: #endif
2.3       timbl     251: #endif  /*  CURSES  */
2.1       timbl     252: 
                    253: #ifndef BOOL
                    254: #define BOOL BOOLEAN
                    255: #endif
                    256: #ifndef YES
2.14      timbl     257: #define YES             (BOOL)1
                    258: #define NO              (BOOL)0
2.1       timbl     259: #endif
                    260: 
2.11      timbl     261: #ifndef HTMIN 
                    262: #define HTMIN(a,b) ((a) &lt;= (b) ? (a) : (b))
                    263: #define HTMAX(a,b) ((a) >= (b) ? (a) : (b))
2.1       timbl     264: #endif
                    265: 
                    266: #define TCP_PORT 80    /* Allocated to http by Jon Postel/ISI 24-Jan-92 */
                    267: #define OLD_TCP_PORT 2784      /* Try the old one if no answer on 80 */
                    268: #define DNP_OBJ 80     /* This one doesn't look busy, but we must check */
2.3       timbl     269:                        /* That one was for decnet */
2.26    ! frystyk   270: </PRE>
2.1       timbl     271: 
2.23      frystyk   272: <A NAME="ReturnCodes"><H2>Return Codes for Protocol Modules</H2></A>
2.1       timbl     273: 
2.18      frystyk   274: Theese are the codes returned from the protocol modules. Success (&gt;=0) and
                    275: failure (&lt;0) codes
2.3       timbl     276: <PRE>
2.23      frystyk   277: #define HT_OK                  0       /* Generic success */
                    278: #define HT_LOADED              29999   /* Instead of a socket */
                    279: #define HT_REDIRECTION_ON_FLY   29998  /* Redo the retrieve with a new URL */
                    280: 
                    281: #define HT_ERROR               -1      /* Generic failure */
                    282: #define HT_NO_ACCESS           -10     /* Access not available */
                    283: #define HT_FORBIDDEN           -11     /* Access forbidden */
                    284: #define HT_INTERNAL            -12     /* Weird -- should never happen. */
2.18      frystyk   285: #define HT_NO_DATA             -9999   /* OK but no data was loaded */
                    286:                                        /* Typically, other app started */
2.23      frystyk   287: #define HT_WOULD_BLOCK         -29997  /* If we are in a select */
2.15      frystyk   288: #define HT_INTERRUPTED                 -29998  /* Note the negative value! */
2.1       timbl     289: 
2.26    ! frystyk   290: #ifdef _STANDARD_CODE_
        !           291: #include &lt;stdarg.h&gt;
        !           292: #else
        !           293: #include &lt;varargs.h&gt;
        !           294: #endif
2.1       timbl     295: 
                    296: #ifdef CURSES
2.26    ! frystyk   297:        /* htbrowse.c; */
        !           298: #ifdef ULTRIX      /* or DECSTATION */
        !           299: #include &lt;cursesX.h&gt; /* Extended curses under X. Only decent one :lou. */
        !           300: #else
        !           301: #include &lt;curses.h&gt;
        !           302: #endif /* ULTRIX */
2.1       timbl     303:        extern        WINDOW  *w_top, *w_text, *w_prompt;
                    304:        extern        void    user_message PARAMS((const char *fmt, ...));
                    305:        extern        void    prompt_set PARAMS((CONST char * msg));
                    306:        extern        void    prompt_count PARAMS((long kb));
                    307: #else
                    308: #define user_message printf
                    309: #endif
                    310: 
2.3       timbl     311: </PRE>
2.26    ! frystyk   312: 
        !           313: <H2>Out Of Memory checking for malloc() return:</H2>
        !           314: 
        !           315: <PRE>
        !           316: #ifndef __FILE__
2.1       timbl     317: #define __FILE__ ""
                    318: #define __LINE__ ""
                    319: #endif
                    320: 
                    321: #define outofmem(file, func) \
2.26    ! frystyk   322:  { fprintf(TDEST, "%s %s: out of memory.\nProgram aborted.\n", file, func); \
2.1       timbl     323:   exit(1);}
                    324: 
2.26    ! frystyk   325: </PRE>
2.1       timbl     326: 
2.26    ! frystyk   327: <H2>Upper- and Lowercase macros</H2>
        !           328: 
        !           329: The problem here is that toupper(x) is not defined officially unless
        !           330: isupper(x) is.  These macros are CERTAINLY needed on #if defined(pyr)
        !           331: || define(mips) or BDSI platforms. For safefy, we make them mandatory.
2.1       timbl     332: 
2.25      roeber    333: <PRE>
2.26    ! frystyk   334: #include &lt;ctype.h&gt;
2.1       timbl     335: 
                    336: #ifndef TOLOWER
                    337:   /* Pyramid and Mips can't uppercase non-alpha */
                    338: #define TOLOWER(c) (isupper(c) ? tolower(c) : (c))
                    339: #define TOUPPER(c) (islower(c) ? toupper(c) : (c))
                    340: #endif /* ndef TOLOWER */
2.26    ! frystyk   341: </PRE>
        !           342: 
        !           343: <H2>The local equivalents of CR and LF</H2>
2.1       timbl     344: 
2.26    ! frystyk   345: We can check for these after net ascii text has been converted to the
        !           346: local representation. Similarly, we include them in strings to be sent
        !           347: as net ascii after translation.
        !           348: 
        !           349: <PRE>
        !           350: #define LF   FROMASCII('\012')  /* ASCII line feed LOCAL EQUIVALENT */
        !           351: #define CR   FROMASCII('\015')  /* Will be converted to ^M for transmission */
2.6       timbl     352: </PRE>
2.26    ! frystyk   353: 
        !           354: <H3>Other Macros...</H3>
        !           355: 
        !           356: Where else to put these..
        !           357: 
        !           358: <PRE>
        !           359: #ifndef MAXPASSWDLEN
        !           360: #define MAXPASSWDLEN   64
        !           361: #endif
2.6       timbl     362: 
2.1       timbl     363: #endif /* HTUTILS_H */
2.26    ! frystyk   364: </PRE>
2.1       timbl     365: 
2.26    ! frystyk   366: end of utilities
        !           367: </BODY>
2.6       timbl     368: </HTML>

Webmaster