1 /*   (C) Copyright 2000, 2001, 2002, 2003, 2004, 2005 Stijn van Dongen
2  *   (C) Copyright 2006, 2007, 2008, 2009 Stijn van Dongen
3  *
4  * This file is part of tingea.  You can redistribute and/or modify tingea
5  * under the terms of the GNU General Public License; either version 3 of the
6  * License or (at your option) any later version.  You should have received a
7  * copy of the GPL along with tingea, in the file COPYING.
8 */
9 
10 #ifndef types_h
11 #define types_h
12 
13 #include "inttypes.h"
14 
15 typedef unsigned long mcxbits  ;
16 typedef unsigned long mcxmode  ;
17 typedef unsigned long mcxenum  ;
18          /* mcxstatus   defined below */
19          /* mcxbool     defined below */
20 
21 #define BIT_ON(var,bits)   (var) |= (bits)
22 #define BIT_OFF(var, bits)  do { (var) |= (bits); (var) ^= (bits); } while (0)
23 
24 #define ALL_BITS_OFF   0
25 
26 #define VOID_TO_UINT (unsigned)
27 #define UINT_TO_VOID (void*)
28 #define VOID_TO_ULONG (unsigned long)
29 #define ULONG_TO_VOID (void*)
30 
31 #define NOTHING   do { } while (0)
32 
33 
34 /*  **************************************************************************
35  * *
36  **            Implementation notes (a few).
37  *
38  *
39  *  The intent is that routines that return mcxstatus can define their own
40  *  values, so one must check the interface of a given routine as to what kind
41  *  of symbolic values it may return.
42  *
43  *  For example, the opt library defines MCX_OPT_OK, MCX_OPT_NOARG, and
44  *  MCX_OPT_UNKNOWN.
45  *
46  *  The intent is also that the OK value is always defined as zero -- it's
47  *  not the zero that counts but the fact that all OK values (e.g. STATUS_OK,
48  *  MCX_OPT_OK etc) are equal. One should be able to count on this.
49  *  If multiple ok values are possible, use one of mcxenum, mcxbits, mcxmode.
50  *
51 */
52 
53 typedef enum
54 {  STATUS_OK      =  0
55 ,  STATUS_FAIL
56 ,  STATUS_DONE             /* for iterator type interfaces (e.g. readLine) */
57 ,  STATUS_IGNORE           /* for iterator type interfaces (line parser)   */
58 ,  STATUS_NOMEM
59 ,  STATUS_ABORT            /* e.g. user response                           */
60 ,  STATUS_NEW              /* for cache type interfaces                    */
61 ,  STATUS_UNUSED           /* use this as lower bound for new statuses     */
62 }  mcxstatus         ;
63 
64 extern const char* mcx_status_list[];
65 
66 #define MCXSTATUS(status)           \
67       (  status <= STATUS_UNUSED    \
68       ?  mcx_status_list[status]    \
69       :  "NO_such_status!"          \
70       )
71 
72 #ifndef FALSE
73    typedef enum
74    {  FALSE       =  0
75    ,  TRUE        =  1
76    }  mcxbool        ;
77 #else
78    typedef int mcxbool ;
79 #endif
80 
81 typedef enum
82 {  RETURN_ON_FAIL =  1960
83 ,  EXIT_ON_FAIL
84 ,  SLEEP_ON_FAIL
85 ,  ENQUIRE_ON_FAIL    /* user sets TINGEA_MEM_DO to e.g. exit or retry */
86 }  mcxOnFail         ;
87 
88 
89 #define  MCX_DATUM_THREADING  1
90 #define  MCX_DATUM_FIND       2
91 #define  MCX_DATUM_INSERT     4
92 #define  MCX_DATUM_DELETE     8
93 
94 #endif
95 
96