Introduce xkb_keycode_t for keycodes
[platform/upstream/libxkbcommon.git] / src / xkbcomp / utils.h
1 #ifndef UTILS_H
2 #define UTILS_H 1
3
4   /*\
5    *
6    *                          COPYRIGHT 1990
7    *                    DIGITAL EQUIPMENT CORPORATION
8    *                       MAYNARD, MASSACHUSETTS
9    *                        ALL RIGHTS RESERVED.
10    *
11    * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
12    * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
13    * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
14    * FOR ANY PURPOSE.  IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
15    * WARRANTY.
16    *
17    * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
18    * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
19    * ADDITION TO THAT SET FORTH ABOVE.
20    *
21    * Permission to use, copy, modify, and distribute this software and its
22    * documentation for any purpose and without fee is hereby granted, provided
23    * that the above copyright notice appear in all copies and that both that
24    * copyright notice and this permission notice appear in supporting
25    * documentation, and that the name of Digital Equipment Corporation not be
26    * used in advertising or publicity pertaining to distribution of the
27    * software without specific, written prior permission.
28    \*/
29
30 /***====================================================================***/
31
32 #include        <stdio.h>
33 #include        <X11/Xos.h>
34 #include        <X11/Xfuncproto.h>
35 #include        <X11/Xfuncs.h>
36
37 #include <stddef.h>
38 #include "config.h"
39
40 #ifndef NUL
41 #define NUL     '\0'
42 #endif
43
44 /***====================================================================***/
45
46 #ifndef BOOLEAN_DEFINED
47 typedef char Boolean;
48 #endif
49
50 #ifndef True
51 #define True    ((Boolean)1)
52 #define False   ((Boolean)0)
53 #endif /* ndef True */
54 #define booleanText(b)  ((b)?"True":"False")
55
56 #ifndef COMPARISON_DEFINED
57 typedef int Comparison;
58
59 #define Greater         ((Comparison)1)
60 #define Equal           ((Comparison)0)
61 #define Less            ((Comparison)-1)
62 #define CannotCompare   ((Comparison)-37)
63 #define comparisonText(c)       ((c)?((c)<0?"Less":"Greater"):"Equal")
64 #endif
65
66 /***====================================================================***/
67
68 extern void *
69 recalloc(void * old, unsigned nOld, unsigned nNew, unsigned newSize);
70
71 #define uTypedAlloc(t)          ((t *)malloc((unsigned)sizeof(t)))
72 #define uTypedCalloc(n,t)       ((t *)calloc((unsigned)n,(unsigned)sizeof(t)))
73 #define uTypedRealloc(pO,n,t)   ((t *)realloc((void *)pO,((unsigned)n)*sizeof(t)))
74 #define uTypedRecalloc(pO,o,n,t) ((t *)recalloc((void *)pO,((unsigned)o),((unsigned)n),sizeof(t)))
75 #if (defined mdHasAlloca) && (mdHasAlloca)
76 #define uTmpAlloc(n)    ((void *)alloca((unsigned)n))
77 #define uTmpFree(p)
78 #else
79 #define uTmpAlloc(n)    malloc(n)
80 #define uTmpFree(p)     free(p)
81 #endif
82
83 /***====================================================================***/
84
85 extern Boolean
86 uSetErrorFile(char *name);
87
88 #if defined(__GNUC__) && \
89     ((__GNUC__ > 2) || ((__GNUC__ == 2) && (__GNUC_MINOR__ >= 6)))
90 #define __ATTR_PRINTF(i, f) __attribute__ ((format(printf, (i), (f))))
91 #else
92 #define __ATTR_PRINTF(i, f)
93 #endif
94
95 #define INFO                    uInformation
96
97 extern __ATTR_PRINTF(1, 2) void
98 uInformation(const char *s, ...);
99
100 #define ACTION                  uAction
101
102 extern __ATTR_PRINTF(1, 2) void
103 uAction(const char *s, ...);
104
105 #define WARN                    uWarning
106
107 extern __ATTR_PRINTF(1, 2) void
108 uWarning(const char *s, ...);
109
110 #define ERROR                   uError
111
112 extern __ATTR_PRINTF(1, 2) void
113 uError(const char *s, ...);
114
115 #define FATAL                   uFatalError
116
117 extern __ATTR_PRINTF(1, 2) void
118 uFatalError(const char *s, ...);
119
120 /* WSGO stands for "Weird Stuff Going On" (wtf???) */
121 #define WSGO                    uInternalError
122
123 extern __ATTR_PRINTF(1, 2) void
124 uInternalError(const char *s, ...);
125
126 /***====================================================================***/
127
128 #define NullString      ((char *)NULL)
129
130 #define uStringText(s)          ((s)==NullString?"<NullString>":(s))
131 #define uStringEqual(s1,s2)     (uStringCompare(s1,s2)==Equal)
132 #define uStringPrefix(p,s)      (strncmp(p,s,strlen(p))==0)
133 #define uStringCompare(s1,s2)   (((s1)==NullString||(s2)==NullString)?\
134                                  (s1)!=(s2):strcmp(s1,s2))
135 #define uStrCaseEqual(s1,s2)    (uStrCaseCmp(s1,s2)==0)
136 #ifdef HAVE_STRCASECMP
137 #define uStrCaseCmp(s1,s2)      (strcasecmp(s1,s2))
138 #define uStrCasePrefix(p,s)     (strncasecmp(p,s,strlen(p))==0)
139 #else
140 extern int
141 uStrCaseCmp(const char *s1, const char *s2);
142 extern int
143 uStrCasePrefix(const char *p, char *str);
144 #endif
145
146 /***====================================================================***/
147
148 #ifdef  ASSERTIONS_ON
149 #define uASSERT(where,why) \
150         {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);}
151 #else
152 #define uASSERT(where,why)
153 #endif
154
155 /***====================================================================***/
156
157 #ifndef DEBUG_VAR
158 #define DEBUG_VAR       debugFlags
159 #endif
160
161 extern unsigned int DEBUG_VAR;
162
163 #endif /* UTILS_H */