Annotation of sbbs/xpdev/gen_defs.h, revision 1.1.1.1

1.1       root        1: /* gen_defs.h */
                      2: 
                      3: /* General(ly useful) constant, macro, and type definitions */
                      4: 
                      5: /* $Id: gen_defs.h,v 1.27 2004/11/19 03:41:07 rswindell Exp $ */
                      6: 
                      7: /****************************************************************************
                      8:  * @format.tab-size 4          (Plain Text/Source Code File Header)                    *
                      9:  * @format.use-tabs true       (see http://www.synchro.net/ptsc_hdr.html)              *
                     10:  *                                                                                                                                                     *
                     11:  * Copyright 2004 Rob Swindell - http://www.synchro.net/copyright.html         *
                     12:  *                                                                                                                                                     *
                     13:  * This library is free software; you can redistribute it and/or                       *
                     14:  * modify it under the terms of the GNU Lesser General Public License          *
                     15:  * as published by the Free Software Foundation; either version 2                      *
                     16:  * of the License, or (at your option) any later version.                                      *
                     17:  * See the GNU Lesser General Public License for more details: lgpl.txt or     *
                     18:  * http://www.fsf.org/copyleft/lesser.html                                                                     *
                     19:  *                                                                                                                                                     *
                     20:  * Anonymous FTP access to the most recent released source is available at     *
                     21:  * ftp://vert.synchro.net, ftp://cvs.synchro.net and ftp://ftp.synchro.net     *
                     22:  *                                                                                                                                                     *
                     23:  * Anonymous CVS access to the development source and modification history     *
                     24:  * is available at cvs.synchro.net:/cvsroot/sbbs, example:                                     *
                     25:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs login                       *
                     26:  *     (just hit return, no password is necessary)                                                     *
                     27:  * cvs -d :pserver:[email protected]:/cvsroot/sbbs checkout src                *
                     28:  *                                                                                                                                                     *
                     29:  * For Synchronet coding style and modification guidelines, see                                *
                     30:  * http://www.synchro.net/source.html                                                                          *
                     31:  *                                                                                                                                                     *
                     32:  * You are encouraged to submit any modifications (preferably in Unix diff     *
                     33:  * format) via e-mail to [email protected]                                                                      *
                     34:  *                                                                                                                                                     *
                     35:  * Note: If this box doesn't appear square, then you need to fix your tabs.    *
                     36:  ****************************************************************************/
                     37: 
                     38: #ifndef _GEN_DEFS_H
                     39: #define _GEN_DEFS_H
                     40: 
                     41: #include <errno.h>
                     42: 
                     43: /* Resolve multi-named errno constants */
                     44: #if defined(EDEADLK) && !defined(EDEADLOCK)
                     45:        #define EDEADLOCK EDEADLK
                     46: #endif
                     47: 
                     48: #if defined(_WIN32)
                     49:        #define WIN32_LEAN_AND_MEAN     /* Don't bring in excess baggage */
                     50:        #include <windows.h>
                     51: #elif defined(__OS2__)
                     52:        #define INCL_BASE       /* need this for DosSleep prototype */
                     53:        #include <os2.h>
                     54: #else
                     55:        #if (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__)) || defined (__NetBSD__)
                     56:                #ifndef __unix__
                     57:                        #define __unix__
                     58:                #endif
                     59:        #endif
                     60: #endif
                     61: 
                     62: 
                     63: #include <sys/types.h>
                     64: 
                     65:                                                                        /* Control characters */
                     66: #define STX    0x02                            /* Start of text                        ^B      */
                     67: #define ETX    0x03                            /* End of text                          ^C      */
                     68: #define BEL            0x07                            /* Bell/beep                            ^G      */
                     69: #define FF             0x0c                            /* Form feed                            ^L      */
                     70: #define ESC    0x1b                            /* Escape                                       ^[      */
                     71: #define DEL            0x7f                            /* Delete                                       ^BS     */
                     72: #define BS             '\b'                            /* Back space                           ^H      */
                     73: #define TAB    '\t'                            /* Horizontal tabulation        ^I      */
                     74: #define LF             '\n'                            /* Line feed                            ^J      */
                     75: #define CR             '\r'                            /* Carriage return                      ^M      */
                     76: 
                     77: enum {
                     78:         CTRL_A=1
                     79:        ,CTRL_B
                     80:        ,CTRL_C
                     81:        ,CTRL_D 
                     82:        ,CTRL_E
                     83:        ,CTRL_F
                     84:        ,CTRL_G
                     85:        ,CTRL_H
                     86:        ,CTRL_I
                     87:        ,CTRL_J
                     88:        ,CTRL_K
                     89:        ,CTRL_L
                     90:        ,CTRL_M
                     91:        ,CTRL_N
                     92:        ,CTRL_O
                     93:        ,CTRL_P
                     94:        ,CTRL_Q
                     95:        ,CTRL_R
                     96:        ,CTRL_S
                     97:        ,CTRL_T
                     98:        ,CTRL_U
                     99:        ,CTRL_V
                    100:        ,CTRL_W
                    101:        ,CTRL_X
                    102:        ,CTRL_Y
                    103:        ,CTRL_Z
                    104: };
                    105: 
                    106: /* Unsigned type short-hands   */
                    107: #ifndef uchar
                    108:        #define uchar   unsigned char
                    109: #endif
                    110: #ifndef __GLIBC__
                    111:        #ifndef ushort
                    112:        #define ushort  unsigned short
                    113:        #define uint    unsigned int
                    114:        #define ulong   unsigned long
                    115:        #endif
                    116: #endif
                    117: 
                    118: /* Windows Types */
                    119: #ifndef BYTE
                    120: #define BYTE   uchar
                    121: #endif
                    122: #ifndef WORD
                    123: #define WORD   ushort
                    124: #endif
                    125: #ifndef DWORD
                    126: #define DWORD  ulong
                    127: #endif
                    128: #ifndef BOOL
                    129: #define BOOL   int
                    130: #endif
                    131: #ifndef TRUE
                    132: #define TRUE   1
                    133: #define FALSE  0
                    134: #endif
                    135: #ifndef INT_TO_BOOL
                    136: #define INT_TO_BOOL(x) ((x)?TRUE:FALSE)
                    137: #endif
                    138: #ifndef HANDLE
                    139: #define HANDLE void*
                    140: #endif
                    141: 
                    142: /* Custom Types */
                    143: typedef struct {
                    144:        char*   name;
                    145:        char*   value;
                    146: } named_string_t;
                    147: 
                    148: typedef struct {
                    149:        char*   name;
                    150:        int             value;
                    151: } named_int_t;
                    152: 
                    153: typedef struct {
                    154:        char*   name;
                    155:        uint    value;
                    156: } named_uint_t;
                    157: 
                    158: typedef struct {
                    159:        char*   name;
                    160:        long    value;
                    161: } named_long_t;
                    162: 
                    163: typedef struct {
                    164:        char*   name;
                    165:        ulong   value;
                    166: } named_ulong_t;
                    167: 
                    168: typedef struct {
                    169:        char*   name;
                    170:        short   value;
                    171: } named_short_t;
                    172: 
                    173: typedef struct {
                    174:        char*   name;
                    175:        ushort  value;
                    176: } named_ushort_t;
                    177: 
                    178: typedef struct {
                    179:        char*   name;
                    180:        BOOL    value;
                    181: } named_bool_t;
                    182: 
                    183: /************************/
                    184: /* Handy Integer Macros */
                    185: /************************/
                    186: 
                    187: /* Data Block Length Alignment Macro (returns required padding length for proper alignment) */
                    188: #define PAD_LENGTH_FOR_ALIGNMENT(len,blk)      (((len)%(blk))==0 ? 0 : (blk)-((len)%(blk)))
                    189: 
                    190: /***********************/
                    191: /* Handy String Macros */
                    192: /***********************/
                    193: 
                    194: /* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */
                    195: #define SAFECOPY(dst,src)                              sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
                    196: #define TERMINATE(str)                                 str[sizeof(str)-1]=0
                    197: #define SAFEPRINTF(dst,fmt,arg)                        snprintf(dst,sizeof(dst),fmt,arg), TERMINATE(dst)
                    198: #define SAFEPRINTF2(dst,fmt,a1,a2)             snprintf(dst,sizeof(dst),fmt,a1,a2), TERMINATE(dst)
                    199: #define SAFEPRINTF3(dst,fmt,a1,a2,a3)  snprintf(dst,sizeof(dst),fmt,a1,a2,a3), TERMINATE(dst)
                    200: #define SAFEPRINTF4(dst,fmt,a1,a2,a3,a4) snprintf(dst,sizeof(dst),fmt,a1,a2,a3,a4), TERMINATE(dst)
                    201: 
                    202: /* Replace every occurance of c1 in str with c2, using p as a temporary char pointer */
                    203: #define REPLACE_CHARS(str,c1,c2,p)     for((p)=(str);*(p);(p)++) if(*(p)==(c1)) *(p)=(c2);
                    204: 
                    205: /* ASCIIZ char* parsing helper macros */
                    206: #define SKIP_WHITESPACE(p)                     while(*(p) && isspace(*(p)))                    (p)++;
                    207: #define FIND_WHITESPACE(p)                     while(*(p) && !isspace(*(p)))                   (p)++;
                    208: #define SKIP_CHAR(p,c)                         while(*(p)==c)                                                  (p)++;
                    209: #define FIND_CHAR(p,c)                         while(*(p) && *(p)!=c)                                  (p)++;
                    210: #define SKIP_CHARSET(p,s)                      while(*(p) && strchr(s,*(p))!=NULL)             (p)++;
                    211: #define FIND_CHARSET(p,s)                      while(*(p) && strchr(s,*(p))==NULL)             (p)++;
                    212: #define SKIP_ALPHA(p)                          while(*(p) && isalpha(*(p)))                    (p)++;
                    213: #define FIND_ALPHA(p)                          while(*(p) && !isalpha(*(p)))                   (p)++;
                    214: #define SKIP_ALPHANUMERIC(p)           while(*(p) && isalnum(*(p)))                    (p)++;
                    215: #define FIND_ALPHANUMERIC(p)           while(*(p) && !isalnum(*(p)))                   (p)++;
                    216: #define SKIP_DIGIT(p)                          while(*(p) && isdigit(*(p)))                    (p)++;
                    217: #define FIND_DIGIT(p)                          while(*(p) && !isdigit(*(p)))                   (p)++;
                    218: #define SKIP_HEXDIGIT(p)                       while(*(p) && isxdigit(*(p)))                   (p)++;
                    219: #define FIND_HEXDIGIT(p)                       while(*(p) && !isxdigit(*(p)))                  (p)++;
                    220: 
                    221: /* Variable/buffer initialization (with zeros) */
                    222: #define ZERO_VAR(var)                          memset(&(var),0,sizeof(var))
                    223: #define ZERO_ARRAY(array)                      memset(array,0,sizeof(array))
                    224: 
                    225: /****************************************************************************/
                    226: /* MALLOC/FREE Macros for various compilers and environments                           */
                    227: /* MALLOC is used for allocations of 64k or less                                                       */
                    228: /* FREE is used to free buffers allocated with MALLOC                                          */
                    229: /* LMALLOC is used for allocations of possibly larger than 64k                         */
                    230: /* LFREE is used to free buffers allocated with LMALLOC                                        */
                    231: /* REALLOC is used to re-size a previously MALLOCed or LMALLOCed buffer        */
                    232: /* FAR16 is used to create a far (32-bit) pointer in 16-bit compilers          */
                    233: /* HUGE16 is used to create a huge (32-bit) pointer in 16-bit compilers        */
                    234: /****************************************************************************/
                    235: #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
                    236:        #define HUGE16 huge
                    237:        #define FAR16 far
                    238:        #if defined(__TURBOC__)
                    239:                #define REALLOC(x,y) farrealloc(x,y)
                    240:                #define LMALLOC(x) farmalloc(x)
                    241:                #define MALLOC(x) farmalloc(x)
                    242:                #define LFREE(x) farfree(x)
                    243:                #define FREE(x) farfree(x)
                    244:        #elif defined(__WATCOMC__)
                    245:                #define REALLOC realloc
                    246:                #define LMALLOC(x) halloc(x,1)  /* far heap, but slow */
                    247:                #define MALLOC malloc                   /* far heap, but 64k max */
                    248:                #define LFREE hfree
                    249:                #define FREE free
                    250:        #else   /* Other 16-bit Compiler */
                    251:                #define REALLOC realloc
                    252:                #define LMALLOC malloc
                    253:                #define MALLOC malloc
                    254:                #define LFREE free
                    255:                #define FREE free
                    256:        #endif
                    257: #else          /* 32-bit Compiler or Small Memory Model */
                    258:        #define HUGE16
                    259:        #define FAR16
                    260:        #define REALLOC realloc
                    261:        #define LMALLOC malloc
                    262:        #define MALLOC malloc
                    263:        #define LFREE free
                    264:        #define FREE free
                    265: #endif
                    266: 
                    267: /********************************/
                    268: /* Handy Pointer-freeing Macros */
                    269: /********************************/
                    270: #define FREE_AND_NULL(x)                       if(x!=NULL) { FREE(x); x=NULL; }
                    271: #define FREE_LIST_ITEMS(list,i)                if(list!=NULL) {                                \
                    272:                                                                                for(i=0;list[i]!=NULL;i++)      \
                    273:                                                                                        FREE_AND_NULL(list[i]); \
                    274:                                                                        }
                    275: #define FREE_LIST(list,i)                      FREE_LIST_ITEMS(list,i) FREE_AND_NULL(list)
                    276: 
                    277: /********************************/
                    278: /* Other Pointer-List Macros   */
                    279: /********************************/
                    280: #define COUNT_LIST_ITEMS(list,i)       { i=0; if(list!=NULL) while(list[i]!=NULL) i++; }
                    281: 
                    282: #if defined(__unix__)
                    283:        #include <syslog.h>
                    284: #else
                    285:        /*
                    286:         * log priorities (copied from BSD syslog.h)
                    287:         */
                    288:        #define LOG_EMERG       0       /* system is unusable */
                    289:        #define LOG_ALERT       1       /* action must be taken immediately */
                    290:        #define LOG_CRIT        2       /* critical conditions */
                    291:        #define LOG_ERR         3       /* error conditions */
                    292:        #define LOG_WARNING     4       /* warning conditions */
                    293:        #define LOG_NOTICE      5       /* normal but significant condition */
                    294:        #define LOG_INFO        6       /* informational */
                    295:        #define LOG_DEBUG       7       /* debug-level messages */
                    296: #endif
                    297: 
                    298: 
                    299: #endif /* Don't add anything after this #endif statement */

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.