Annotation of sbbs/src/xpdev/gen_defs.h, revision 1.1.1.2

1.1       root        1: /* gen_defs.h */
                      2: 
                      3: /* General(ly useful) constant, macro, and type definitions */
                      4: 
1.1.1.2 ! root        5: /* $Id: gen_defs.h,v 1.55 2011/07/13 11:23:28 rswindell Exp $ */
1.1       root        6: 
                      7: /****************************************************************************
1.1.1.2 ! root        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 2011 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.     *
1.1       root       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)
1.1.1.2 ! root       45:         #define EDEADLOCK EDEADLK
1.1       root       46: #endif
                     47: 
                     48: #if defined(_WIN32)
1.1.1.2 ! root       49:         #define WIN32_LEAN_AND_MEAN     /* Don't bring in excess baggage */
        !            50:         #include <windows.h>
1.1       root       51: #elif defined(__OS2__)
1.1.1.2 ! root       52:         #define INCL_BASE       /* need this for DosSleep prototype */
        !            53:         #include <os2.h>
1.1       root       54: #else
1.1.1.2 ! root       55:         #if (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__)) || defined (__NetBSD__)
        !            56:                 #ifndef __unix__
        !            57:                         #define __unix__
        !            58:                 #endif
        !            59:         #endif
1.1       root       60: #endif
                     61: 
                     62: 
                     63: #include <sys/types.h>
1.1.1.2 ! root       64: #ifdef HAS_INTTYPES_H
        !            65: #include <inttypes.h>
        !            66: #else
        !            67: #ifdef HAS_STDINT_H
        !            68: #include <stdint.h>
        !            69: #endif
        !            70: #endif
1.1       root       71: 
1.1.1.2 ! root       72:                                                                         /* Control characters */
1.1       root       73: #ifndef STX
1.1.1.2 ! root       74: #define STX     0x02                            /* Start of text                        ^B      */
1.1       root       75: #endif
                     76: #ifndef ETX
1.1.1.2 ! root       77: #define ETX     0x03                            /* End of text                          ^C      */
1.1       root       78: #endif
                     79: #ifndef BEL
1.1.1.2 ! root       80: #define BEL             0x07                            /* Bell/beep                            ^G      */
1.1       root       81: #endif
                     82: #ifndef FF
1.1.1.2 ! root       83: #define FF              0x0c                            /* Form feed                            ^L      */
1.1       root       84: #endif
                     85: #ifndef ESC
1.1.1.2 ! root       86: #define ESC     0x1b                            /* Escape                                       ^[      */
1.1       root       87: #endif
                     88: #ifndef DEL
1.1.1.2 ! root       89: #define DEL             0x7f                            /* Delete                                       ^BS     */
1.1       root       90: #endif
                     91: #ifndef BS
1.1.1.2 ! root       92: #define BS              '\b'                            /* Back space                           ^H      */
1.1       root       93: #endif
                     94: #ifndef TAB
1.1.1.2 ! root       95: #define TAB     '\t'                            /* Horizontal tabulation        ^I      */
1.1       root       96: #endif
                     97: #ifndef LF
1.1.1.2 ! root       98: #define LF              '\n'                            /* Line feed                            ^J      */
1.1       root       99: #endif
                    100: #ifndef CR
1.1.1.2 ! root      101: #define CR              '\r'                            /* Carriage return                      ^M      */
1.1       root      102: #endif
                    103: 
1.1.1.2 ! root      104: #ifndef CTRL_A
1.1       root      105: enum {
1.1.1.2 ! root      106:          CTRL_A=1
        !           107:         ,CTRL_B
        !           108:         ,CTRL_C
        !           109:         ,CTRL_D 
        !           110:         ,CTRL_E
        !           111:         ,CTRL_F
        !           112:         ,CTRL_G
        !           113:         ,CTRL_H
        !           114:         ,CTRL_I
        !           115:         ,CTRL_J
        !           116:         ,CTRL_K
        !           117:         ,CTRL_L
        !           118:         ,CTRL_M
        !           119:         ,CTRL_N
        !           120:         ,CTRL_O
        !           121:         ,CTRL_P
        !           122:         ,CTRL_Q
        !           123:         ,CTRL_R
        !           124:         ,CTRL_S
        !           125:         ,CTRL_T
        !           126:         ,CTRL_U
        !           127:         ,CTRL_V
        !           128:         ,CTRL_W
        !           129:         ,CTRL_X
        !           130:         ,CTRL_Y
        !           131:         ,CTRL_Z
1.1       root      132: };
1.1.1.2 ! root      133: #endif
1.1       root      134: 
1.1.1.2 ! root      135: /* Unsigned type short-hands    */
1.1       root      136: #ifndef uchar
1.1.1.2 ! root      137:         #define uchar   unsigned char
1.1       root      138: #endif
                    139: #ifndef __GLIBC__
1.1.1.2 ! root      140:         #ifndef ushort
        !           141:         #define ushort  unsigned short
        !           142:         #define uint    unsigned int
        !           143:         #define ulong   unsigned long
        !           144:         #endif
        !           145: #endif
        !           146: 
        !           147: #if !defined(HAS_INTTYPES_H) && !defined(XPDEV_DONT_DEFINE_INTTYPES)
        !           148: 
        !           149: #if !defined(HAS_STDINT_H)
        !           150: 
        !           151: typedef char    int8_t;
        !           152: typedef short   int16_t;
        !           153: typedef long    int32_t;
        !           154: typedef uchar   uint8_t;
        !           155: typedef ushort  uint16_t;
        !           156: typedef ulong   uint32_t;
        !           157: 
        !           158: #endif
        !           159: 
        !           160: #if defined(_MSC_VER) || defined(__WATCOMC__) || defined(__BORLANDC__)
        !           161: typedef signed __int64 int64_t;
        !           162: typedef unsigned __int64 uint64_t;
        !           163: #define INTTYPES_H_64BIT_PREFIX         "I64"
        !           164: #else
        !           165: typedef signed long long int int64_t;
        !           166: typedef unsigned long long int uint64_t;
        !           167: #define INTTYPES_H_64BIT_PREFIX         "ll"
        !           168: #endif
        !           169: 
        !           170: #define PRIi64  INTTYPES_H_64BIT_PREFIX"i"
        !           171: #define PRIu64  INTTYPES_H_64BIT_PREFIX"u"
        !           172: #define PRId64  INTTYPES_H_64BIT_PREFIX"d"
        !           173: #define PRIx64  INTTYPES_H_64BIT_PREFIX"x"
        !           174: #define PRIo64  INTTYPES_H_64BIT_PREFIX"o"
        !           175: 
        !           176: #endif
        !           177: 
        !           178: /* Legacy 32-bit time_t */
        !           179: typedef int32_t         time32_t;
        !           180: 
        !           181: #if defined(_WIN32)
        !           182: #  if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS==64)
        !           183: #    define     off_t           int64_t
        !           184: #    define PRIdOFF             PRId64
        !           185: #    define PRIuOFF             PRIu64
        !           186: #  else
        !           187: #    define PRIdOFF             "ld"
        !           188: #    define PRIuOFF             "lu"
        !           189: #  endif
        !           190: #elif defined(__linux__) || defined(__sun__)
        !           191: #  if defined(_FILE_OFFSET_BITS) && (_FILE_OFFSET_BITS==64)
        !           192: #    define PRIdOFF             PRId64
        !           193: #    define PRIuOFF             PRIu64
        !           194: #  else
        !           195: #    define PRIdOFF             PRId32
        !           196: #    define PRIuOFF             PRIu32
        !           197: #  endif
        !           198: #else
        !           199: #  define PRIdOFF       PRId64
        !           200: #  define PRIuOFF       PRIu64
1.1       root      201: #endif
                    202: 
                    203: /* Windows Types */
1.1.1.2 ! root      204: 
1.1       root      205: #ifndef BYTE
1.1.1.2 ! root      206: #define BYTE    uint8_t
1.1       root      207: #endif
                    208: #ifndef WORD
1.1.1.2 ! root      209: #define WORD    uint16_t
1.1       root      210: #endif
                    211: #ifndef DWORD
1.1.1.2 ! root      212: #define DWORD   uint32_t
1.1       root      213: #endif
                    214: #ifndef BOOL
1.1.1.2 ! root      215: #define BOOL    int
1.1       root      216: #endif
1.1.1.2 ! root      217: 
1.1       root      218: #ifndef TRUE
1.1.1.2 ! root      219: #define TRUE    1
        !           220: #define FALSE   0
1.1       root      221: #endif
                    222: #ifndef INT_TO_BOOL
1.1.1.2 ! root      223: #define INT_TO_BOOL(x)  ((x)?TRUE:FALSE)
1.1       root      224: #endif
                    225: #ifndef HANDLE
1.1.1.2 ! root      226: #define HANDLE  void*
1.1       root      227: #endif
                    228: 
                    229: /* Custom Types */
                    230: typedef struct {
1.1.1.2 ! root      231:         char*   name;
        !           232:         char*   value;
1.1       root      233: } named_string_t;
                    234: 
                    235: typedef struct {
1.1.1.2 ! root      236:         char*   name;
        !           237:         int             value;
1.1       root      238: } named_int_t;
                    239: 
                    240: typedef struct {
1.1.1.2 ! root      241:         char*   name;
        !           242:         uint    value;
1.1       root      243: } named_uint_t;
                    244: 
                    245: typedef struct {
1.1.1.2 ! root      246:         char*   name;
        !           247:         long    value;
1.1       root      248: } named_long_t;
                    249: 
                    250: typedef struct {
1.1.1.2 ! root      251:         char*   name;
        !           252:         ulong   value;
1.1       root      253: } named_ulong_t;
                    254: 
                    255: typedef struct {
1.1.1.2 ! root      256:         char*   name;
        !           257:         short   value;
1.1       root      258: } named_short_t;
                    259: 
                    260: typedef struct {
1.1.1.2 ! root      261:         char*   name;
        !           262:         ushort  value;
1.1       root      263: } named_ushort_t;
                    264: 
                    265: typedef struct {
1.1.1.2 ! root      266:         char*   name;
        !           267:         float   value;
1.1       root      268: } named_float_t;
                    269: 
                    270: typedef struct {
1.1.1.2 ! root      271:         char*   name;
        !           272:         double  value;
1.1       root      273: } named_double_t;
                    274: 
                    275: typedef struct {
1.1.1.2 ! root      276:         char*   name;
        !           277:         BOOL    value;
1.1       root      278: } named_bool_t;
                    279: 
                    280: typedef struct {
1.1.1.2 ! root      281:         int             key;
        !           282:         char*   value;
1.1       root      283: } keyed_string_t;
                    284: 
                    285: typedef struct {
1.1.1.2 ! root      286:         int             key;
        !           287:         int             value;
1.1       root      288: } keyed_int_t;
                    289: 
                    290: 
                    291: /************************/
                    292: /* Handy Integer Macros */
                    293: /************************/
                    294: 
                    295: /* Data Block Length Alignment Macro (returns required padding length for proper alignment) */
1.1.1.2 ! root      296: #define PAD_LENGTH_FOR_ALIGNMENT(len,blk)       (((len)%(blk))==0 ? 0 : (blk)-((len)%(blk)))
1.1       root      297: 
                    298: /***********************/
                    299: /* Handy String Macros */
                    300: /***********************/
                    301: 
                    302: /* Null-Terminate an ASCIIZ char array */
1.1.1.2 ! root      303: #define TERMINATE(str)                                  str[sizeof(str)-1]=0
1.1       root      304: 
                    305: /* This is a bound-safe version of strcpy basically - only works with fixed-length arrays */
                    306: #ifdef SAFECOPY_USES_SPRINTF
1.1.1.2 ! root      307: #define SAFECOPY(dst,src)                               sprintf(dst,"%.*s",(int)sizeof(dst)-1,src)
        !           308: #else   /* strncpy is faster */
        !           309: #define SAFECOPY(dst,src)                               (strncpy(dst,src,sizeof(dst)), TERMINATE(dst))
1.1       root      310: #endif
                    311: 
                    312: /* Bound-safe version of sprintf() - only works with fixed-length arrays */
                    313: #if (defined __FreeBSD__) || (defined __NetBSD__) || (defined __OpenBSD__) || (defined(__APPLE__) && defined(__MACH__) && defined(__POWERPC__))
                    314: /* *BSD *nprintf() is already safe */
1.1.1.2 ! root      315: #define SAFEPRINTF(dst,fmt,arg)                 snprintf(dst,sizeof(dst),fmt,arg)
        !           316: #define SAFEPRINTF2(dst,fmt,a1,a2)              snprintf(dst,sizeof(dst),fmt,a1,a2)
        !           317: #define SAFEPRINTF3(dst,fmt,a1,a2,a3)   snprintf(dst,sizeof(dst),fmt,a1,a2,a3)
1.1       root      318: #define SAFEPRINTF4(dst,fmt,a1,a2,a3,a4) snprintf(dst,sizeof(dst),fmt,a1,a2,a3,a4)
                    319: #else
1.1.1.2 ! root      320: #define SAFEPRINTF(dst,fmt,arg)                 snprintf(dst,sizeof(dst),fmt,arg), TERMINATE(dst)
        !           321: #define SAFEPRINTF2(dst,fmt,a1,a2)              snprintf(dst,sizeof(dst),fmt,a1,a2), TERMINATE(dst)
        !           322: #define SAFEPRINTF3(dst,fmt,a1,a2,a3)   snprintf(dst,sizeof(dst),fmt,a1,a2,a3), TERMINATE(dst)
1.1       root      323: #define SAFEPRINTF4(dst,fmt,a1,a2,a3,a4) snprintf(dst,sizeof(dst),fmt,a1,a2,a3,a4), TERMINATE(dst)
                    324: #endif
                    325: 
                    326: /* Replace every occurance of c1 in str with c2, using p as a temporary char pointer */
1.1.1.2 ! root      327: #define REPLACE_CHARS(str,c1,c2,p)      for((p)=(str);*(p);(p)++) if(*(p)==(c1)) *(p)=(c2);
1.1       root      328: 
                    329: /* ASCIIZ char* parsing helper macros */
1.1.1.2 ! root      330: #define SKIP_WHITESPACE(p)                      while(*(p) && isspace((unsigned char)*(p)))                     (p)++;
        !           331: #define FIND_WHITESPACE(p)                      while(*(p) && !isspace((unsigned char)*(p)))            (p)++;
        !           332: #define SKIP_CHAR(p,c)                          while(*(p)==c)                                                                          (p)++;
        !           333: #define FIND_CHAR(p,c)                          while(*(p) && *(p)!=c)                                                          (p)++;
        !           334: #define SKIP_CHARSET(p,s)                       while(*(p) && strchr(s,*(p))!=NULL)                                     (p)++;
        !           335: #define FIND_CHARSET(p,s)                       while(*(p) && strchr(s,*(p))==NULL)                                     (p)++;
        !           336: #define SKIP_ALPHA(p)                           while(*(p) && isalpha((unsigned char)*(p)))                     (p)++;
        !           337: #define FIND_ALPHA(p)                           while(*(p) && !isalpha((unsigned char)*(p)))            (p)++;
        !           338: #define SKIP_ALPHANUMERIC(p)            while(*(p) && isalnum((unsigned char)*(p)))                     (p)++;
        !           339: #define FIND_ALPHANUMERIC(p)            while(*(p) && !isalnum((unsigned char)*(p)))            (p)++;
        !           340: #define SKIP_DIGIT(p)                           while(*(p) && isdigit((unsigned char)*(p)))                     (p)++;
        !           341: #define FIND_DIGIT(p)                           while(*(p) && !isdigit((unsigned char)*(p)))            (p)++;
        !           342: #define SKIP_HEXDIGIT(p)                        while(*(p) && isxdigit((unsigned char)*(p)))            (p)++;
        !           343: #define FIND_HEXDIGIT(p)                        while(*(p) && !isxdigit((unsigned char)*(p)))           (p)++;
1.1       root      344: 
                    345: /* Variable/buffer initialization (with zeros) */
1.1.1.2 ! root      346: #define ZERO_VAR(var)                           memset(&(var),0,sizeof(var))
        !           347: #define ZERO_ARRAY(array)                       memset(array,0,sizeof(array))
1.1       root      348: 
                    349: /****************************************************************************/
1.1.1.2 ! root      350: /* MALLOC/FREE Macros for various compilers and environments                            */
        !           351: /* MALLOC is used for allocations of 64k or less                                                        */
        !           352: /* FREE is used to free buffers allocated with MALLOC                                           */
        !           353: /* LMALLOC is used for allocations of possibly larger than 64k                          */
        !           354: /* LFREE is used to free buffers allocated with LMALLOC                                         */
        !           355: /* REALLOC is used to re-size a previously MALLOCed or LMALLOCed buffer         */
        !           356: /* FAR16 is used to create a far (32-bit) pointer in 16-bit compilers           */
        !           357: /* HUGE16 is used to create a huge (32-bit) pointer in 16-bit compilers         */
1.1       root      358: /****************************************************************************/
                    359: #if defined(__COMPACT__) || defined(__LARGE__) || defined(__HUGE__)
1.1.1.2 ! root      360:         #define HUGE16 huge
        !           361:         #define FAR16 far
        !           362:         #if defined(__TURBOC__)
        !           363:                 #define REALLOC(x,y) farrealloc(x,y)
        !           364:                 #define LMALLOC(x) farmalloc(x)
        !           365:                 #define MALLOC(x) farmalloc(x)
        !           366:                 #define LFREE(x) farfree(x)
        !           367:                 #define FREE(x) farfree(x)
        !           368:         #elif defined(__WATCOMC__)
        !           369:                 #define REALLOC realloc
        !           370:                 #define LMALLOC(x) halloc(x,1)  /* far heap, but slow */
        !           371:                 #define MALLOC malloc                   /* far heap, but 64k max */
        !           372:                 #define LFREE hfree
        !           373:                 #define FREE free
        !           374:         #else   /* Other 16-bit Compiler */
        !           375:                 #define REALLOC realloc
        !           376:                 #define LMALLOC malloc
        !           377:                 #define MALLOC malloc
        !           378:                 #define LFREE free
        !           379:                 #define FREE free
        !           380:         #endif
        !           381: #else           /* 32-bit Compiler or Small Memory Model */
        !           382:         #define HUGE16
        !           383:         #define FAR16
        !           384:         #define REALLOC realloc
        !           385:         #define LMALLOC malloc
        !           386:         #define MALLOC malloc
        !           387:         #define LFREE free
        !           388:         #define FREE free
1.1       root      389: #endif
                    390: 
                    391: /********************************/
                    392: /* Handy Pointer-freeing Macros */
                    393: /********************************/
1.1.1.2 ! root      394: #define FREE_AND_NULL(x)                        if(x!=NULL) { FREE(x); x=NULL; }
        !           395: #define FREE_LIST_ITEMS(list,i)         if(list!=NULL) {                                \
        !           396:                                                                                 for(i=0;list[i]!=NULL;i++)      \
        !           397:                                                                                         FREE_AND_NULL(list[i]); \
        !           398:                                                                         }
        !           399: #define FREE_LIST(list,i)                       FREE_LIST_ITEMS(list,i) FREE_AND_NULL(list)
1.1       root      400: 
                    401: /********************************/
1.1.1.2 ! root      402: /* Other Pointer-List Macros    */
1.1       root      403: /********************************/
1.1.1.2 ! root      404: #define COUNT_LIST_ITEMS(list,i)        { i=0; if(list!=NULL) while(list[i]!=NULL) i++; }
1.1       root      405: 
                    406: #if defined(__unix__)
1.1.1.2 ! root      407:         #include <syslog.h>
1.1       root      408: #else
1.1.1.2 ! root      409:         /*
        !           410:          * log priorities (copied from BSD syslog.h)
        !           411:          */
        !           412:         #define LOG_EMERG       0       /* system is unusable */
        !           413:         #define LOG_ALERT       1       /* action must be taken immediately */
        !           414:         #define LOG_CRIT        2       /* critical conditions */
        !           415:         #define LOG_ERR         3       /* error conditions */
        !           416:         #define LOG_WARNING     4       /* warning conditions */
        !           417:         #define LOG_NOTICE      5       /* normal but significant condition */
        !           418:         #define LOG_INFO        6       /* informational */
        !           419:         #define LOG_DEBUG       7       /* debug-level messages */
1.1       root      420: #endif
                    421: 
                    422: /* Special hackery for SDL */
1.1.1.2 ! root      423: #ifdef WITH_SDL_AUDIO
        !           424:         #include <SDL.h>
1.1       root      425: 
1.1.1.2 ! root      426:         #ifdef main
        !           427:                 #undef main
        !           428:         #endif
        !           429:         #define main    XPDEV_main
1.1       root      430: #endif
                    431: 
                    432: #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.