Annotation of sbbs/src/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.36 2006/05/28 22:01:57 deuce 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 2006 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: #ifndef STX
                     67: #define STX    0x02                            /* Start of text                        ^B      */
                     68: #endif
                     69: #ifndef ETX
                     70: #define ETX    0x03                            /* End of text                          ^C      */
                     71: #endif
                     72: #ifndef BEL
                     73: #define BEL            0x07                            /* Bell/beep                            ^G      */
                     74: #endif
                     75: #ifndef FF
                     76: #define FF             0x0c                            /* Form feed                            ^L      */
                     77: #endif
                     78: #ifndef ESC
                     79: #define ESC    0x1b                            /* Escape                                       ^[      */
                     80: #endif
                     81: #ifndef DEL
                     82: #define DEL            0x7f                            /* Delete                                       ^BS     */
                     83: #endif
                     84: #ifndef BS
                     85: #define BS             '\b'                            /* Back space                           ^H      */
                     86: #endif
                     87: #ifndef TAB
                     88: #define TAB    '\t'                            /* Horizontal tabulation        ^I      */
                     89: #endif
                     90: #ifndef LF
                     91: #define LF             '\n'                            /* Line feed                            ^J      */
                     92: #endif
                     93: #ifndef CR
                     94: #define CR             '\r'                            /* Carriage return                      ^M      */
                     95: #endif
                     96: 
                     97: 
                     98: enum {
                     99:         CTRL_A=1
                    100:        ,CTRL_B
                    101:        ,CTRL_C
                    102:        ,CTRL_D 
                    103:        ,CTRL_E
                    104:        ,CTRL_F
                    105:        ,CTRL_G
                    106:        ,CTRL_H
                    107:        ,CTRL_I
                    108:        ,CTRL_J
                    109:        ,CTRL_K
                    110:        ,CTRL_L
                    111:        ,CTRL_M
                    112:        ,CTRL_N
                    113:        ,CTRL_O
                    114:        ,CTRL_P
                    115:        ,CTRL_Q
                    116:        ,CTRL_R
                    117:        ,CTRL_S
                    118:        ,CTRL_T
                    119:        ,CTRL_U
                    120:        ,CTRL_V
                    121:        ,CTRL_W
                    122:        ,CTRL_X
                    123:        ,CTRL_Y
                    124:        ,CTRL_Z
                    125: };
                    126: 
                    127: /* Unsigned type short-hands   */
                    128: #ifndef uchar
                    129:        #define uchar   unsigned char
                    130: #endif
                    131: #ifndef __GLIBC__
                    132:        #ifndef ushort
                    133:        #define ushort  unsigned short
                    134:        #define uint    unsigned int
                    135:        #define ulong   unsigned long
                    136:        #endif
                    137: #endif
                    138: 
                    139: /* Windows Types */
                    140: #ifndef BYTE
                    141: #define BYTE   uchar
                    142: #endif
                    143: #ifndef WORD
                    144: #define WORD   ushort
                    145: #endif
                    146: #ifndef DWORD
                    147: #define DWORD  ulong
                    148: #endif
                    149: #ifndef BOOL
                    150: #define BOOL   int
                    151: #endif
                    152: #ifndef TRUE
                    153: #define TRUE   1
                    154: #define FALSE  0
                    155: #endif
                    156: #ifndef INT_TO_BOOL
                    157: #define INT_TO_BOOL(x) ((x)?TRUE:FALSE)
                    158: #endif
                    159: #ifndef HANDLE
                    160: #define HANDLE void*
                    161: #endif
                    162: 
                    163: /* Custom Types */
                    164: typedef struct {
                    165:        char*   name;
                    166:        char*   value;
                    167: } named_string_t;
                    168: 
                    169: typedef struct {
                    170:        char*   name;
                    171:        int             value;
                    172: } named_int_t;
                    173: 
                    174: typedef struct {
                    175:        char*   name;
                    176:        uint    value;
                    177: } named_uint_t;
                    178: 
                    179: typedef struct {
                    180:        char*   name;
                    181:        long    value;
                    182: } named_long_t;
                    183: 
                    184: typedef struct {
                    185:        char*   name;
                    186:        ulong   value;
                    187: } named_ulong_t;
                    188: 
                    189: typedef struct {
                    190:        char*   name;
                    191:        short   value;
                    192: } named_short_t;
                    193: 
                    194: typedef struct {
                    195:        char*   name;
                    196:        ushort  value;
                    197: } named_ushort_t;
                    198: 
                    199: typedef struct {
                    200:        char*   name;
                    201:        float   value;
                    202: } named_float_t;
                    203: 
                    204: typedef struct {
                    205:        char*   name;
                    206:        double  value;
                    207: } named_double_t;
                    208: 
                    209: typedef struct {
                    210:        char*   name;
                    211:        BOOL    value;
                    212: } named_bool_t;
                    213: 
                    214: typedef struct {
                    215:        int             key;
                    216:        char*   value;
                    217: } keyed_string_t;
                    218: 
                    219: typedef struct {
                    220:        int             key;
                    221:        int             value;
                    222: } keyed_int_t;
                    223: 
                    224: 
                    225: /************************/
                    226: /* Handy Integer Macros */
                    227: /************************/
                    228: 
                    229: /* Data Block Length Alignment Macro (returns required padding length for proper alignment) */
                    230: #define PAD_LENGTH_FOR_ALIGNMENT(len,blk)      (((len)%(blk))==0 ? 0 : (blk)-((len)%(blk)))
                    231: 
                    232: /***********************/
                    233: /* Handy String Macros */
                    234: /***********************/
                    235: 
                    236: /* Null-Terminate an ASCIIZ char array */
                    237: #define TERMINATE(str)                                 str[sizeof(str)-1]=0
                    238: 
                    239: /* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */
                    240: #ifdef SAFECOPY_USES_SPRINTF
                    241: #define SAFECOPY(dst,src)                              sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
                    242: #else  /* strncpy is faster */
                    243: #define SAFECOPY(dst,src)                              (strncpy(dst,src,sizeof(dst)), TERMINATE(dst))
                    244: #endif
                    245: 
                    246: /* Bound-safe version of sprintf() - only works with fixed-length arrays */
                    247: #if (defined __FreeBSD__) || (defined __NetBSD__) || (defined __OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__))
                    248: /* *BSD *nprintf() is already safe */
                    249: #define SAFEPRINTF(dst,fmt,arg)                        snprintf(dst,sizeof(dst),fmt,arg)
                    250: #define SAFEPRINTF2(dst,fmt,a1,a2)             snprintf(dst,sizeof(dst),fmt,a1,a2)
                    251: #define SAFEPRINTF3(dst,fmt,a1,a2,a3)  snprintf(dst,sizeof(dst),fmt,a1,a2,a3)
                    252: #define SAFEPRINTF4(dst,fmt,a1,a2,a3,a4) snprintf(dst,sizeof(dst),fmt,a1,a2,a3,a4)
                    253: #else
                    254: #define SAFEPRINTF(dst,fmt,arg)                        snprintf(dst,sizeof(dst),fmt,arg), TERMINATE(dst)
                    255: #define SAFEPRINTF2(dst,fmt,a1,a2)             snprintf(dst,sizeof(dst),fmt,a1,a2), TERMINATE(dst)
                    256: #define SAFEPRINTF3(dst,fmt,a1,a2,a3)  snprintf(dst,sizeof(dst),fmt,a1,a2,a3), TERMINATE(dst)
                    257: #define SAFEPRINTF4(dst,fmt,a1,a2,a3,a4) snprintf(dst,sizeof(dst),fmt,a1,a2,a3,a4), TERMINATE(dst)
                    258: #endif
                    259: 
                    260: /* Replace every occurance of c1 in str with c2, using p as a temporary char pointer */
                    261: #define REPLACE_CHARS(str,c1,c2,p)     for((p)=(str);*(p);(p)++) if(*(p)==(c1)) *(p)=(c2);
                    262: 
                    263: /* ASCIIZ char* parsing helper macros */
                    264: #define SKIP_WHITESPACE(p)                     while(*(p) && isspace(*(p)))                    (p)++;
                    265: #define FIND_WHITESPACE(p)                     while(*(p) && !isspace(*(p)))                   (p)++;
                    266: #define SKIP_CHAR(p,c)                         while(*(p)==c)                                                  (p)++;
                    267: #define FIND_CHAR(p,c)                         while(*(p) && *(p)!=c)                                  (p)++;
                    268: #define SKIP_CHARSET(p,s)                      while(*(p) && strchr(s,*(p))!=NULL)             (p)++;
                    269: #define FIND_CHARSET(p,s)                      while(*(p) && strchr(s,*(p))==NULL)             (p)++;
                    270: #define SKIP_ALPHA(p)                          while(*(p) && isalpha(*(p)))                    (p)++;
                    271: #define FIND_ALPHA(p)                          while(*(p) && !isalpha(*(p)))                   (p)++;
                    272: #define SKIP_ALPHANUMERIC(p)           while(*(p) && isalnum(*(p)))                    (p)++;
                    273: #define FIND_ALPHANUMERIC(p)           while(*(p) && !isalnum(*(p)))                   (p)++;
                    274: #define SKIP_DIGIT(p)                          while(*(p) && isdigit(*(p)))                    (p)++;
                    275: #define FIND_DIGIT(p)                          while(*(p) && !isdigit(*(p)))                   (p)++;
                    276: #define SKIP_HEXDIGIT(p)                       while(*(p) && isxdigit(*(p)))                   (p)++;
                    277: #define FIND_HEXDIGIT(p)                       while(*(p) && !isxdigit(*(p)))                  (p)++;
                    278: 
                    279: /* Variable/buffer initialization (with zeros) */
                    280: #define ZERO_VAR(var)                          memset(&(var),0,sizeof(var))
                    281: #define ZERO_ARRAY(array)                      memset(array,0,sizeof(array))
                    282: 
                    283: /****************************************************************************/
                    284: /* MALLOC/FREE Macros for various compilers and environments                           */
                    285: /* MALLOC is used for allocations of 64k or less                                                       */
                    286: /* FREE is used to free buffers allocated with MALLOC                                          */
                    287: /* LMALLOC is used for allocations of possibly larger than 64k                         */
                    288: /* LFREE is used to free buffers allocated with LMALLOC                                        */
                    289: /* REALLOC is used to re-size a previously MALLOCed or LMALLOCed buffer        */
                    290: /* FAR16 is used to create a far (32-bit) pointer in 16-bit compilers          */
                    291: /* HUGE16 is used to create a huge (32-bit) pointer in 16-bit compilers        */
                    292: /****************************************************************************/
                    293: #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
                    294:        #define HUGE16 huge
                    295:        #define FAR16 far
                    296:        #if defined(__TURBOC__)
                    297:                #define REALLOC(x,y) farrealloc(x,y)
                    298:                #define LMALLOC(x) farmalloc(x)
                    299:                #define MALLOC(x) farmalloc(x)
                    300:                #define LFREE(x) farfree(x)
                    301:                #define FREE(x) farfree(x)
                    302:        #elif defined(__WATCOMC__)
                    303:                #define REALLOC realloc
                    304:                #define LMALLOC(x) halloc(x,1)  /* far heap, but slow */
                    305:                #define MALLOC malloc                   /* far heap, but 64k max */
                    306:                #define LFREE hfree
                    307:                #define FREE free
                    308:        #else   /* Other 16-bit Compiler */
                    309:                #define REALLOC realloc
                    310:                #define LMALLOC malloc
                    311:                #define MALLOC malloc
                    312:                #define LFREE free
                    313:                #define FREE free
                    314:        #endif
                    315: #else          /* 32-bit Compiler or Small Memory Model */
                    316:        #define HUGE16
                    317:        #define FAR16
                    318:        #define REALLOC realloc
                    319:        #define LMALLOC malloc
                    320:        #define MALLOC malloc
                    321:        #define LFREE free
                    322:        #define FREE free
                    323: #endif
                    324: 
                    325: /********************************/
                    326: /* Handy Pointer-freeing Macros */
                    327: /********************************/
                    328: #define FREE_AND_NULL(x)                       if(x!=NULL) { FREE(x); x=NULL; }
                    329: #define FREE_LIST_ITEMS(list,i)                if(list!=NULL) {                                \
                    330:                                                                                for(i=0;list[i]!=NULL;i++)      \
                    331:                                                                                        FREE_AND_NULL(list[i]); \
                    332:                                                                        }
                    333: #define FREE_LIST(list,i)                      FREE_LIST_ITEMS(list,i) FREE_AND_NULL(list)
                    334: 
                    335: /********************************/
                    336: /* Other Pointer-List Macros   */
                    337: /********************************/
                    338: #define COUNT_LIST_ITEMS(list,i)       { i=0; if(list!=NULL) while(list[i]!=NULL) i++; }
                    339: 
                    340: #if defined(__unix__)
                    341:        #include <syslog.h>
                    342: #else
                    343:        /*
                    344:         * log priorities (copied from BSD syslog.h)
                    345:         */
                    346:        #define LOG_EMERG       0       /* system is unusable */
                    347:        #define LOG_ALERT       1       /* action must be taken immediately */
                    348:        #define LOG_CRIT        2       /* critical conditions */
                    349:        #define LOG_ERR         3       /* error conditions */
                    350:        #define LOG_WARNING     4       /* warning conditions */
                    351:        #define LOG_NOTICE      5       /* normal but significant condition */
                    352:        #define LOG_INFO        6       /* informational */
                    353:        #define LOG_DEBUG       7       /* debug-level messages */
                    354: #endif
                    355: 
                    356: /* Special hackery for SDL */
                    357: #ifdef WITH_SDL
                    358:        #include <SDL.h>
                    359: 
                    360:        #ifdef main
                    361:                #undef main
                    362:        #endif
                    363:        #define main    XPDEV_main
                    364: #endif
                    365: 
                    366: #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.