a9dcee307b3acd4ec6ec738ff068a310d02891d1
[framework/uifw/xorg/util/x11-xkb-utils.git] / xkbevd / 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 #include        <stdarg.h>
37 #include        <stddef.h>
38
39 _XFUNCPROTOBEGIN
40
41
42 #ifndef NUL
43 #define NUL     '\0'
44 #endif
45
46 /***====================================================================***/
47
48 #ifndef OPAQUE_DEFINED
49 typedef void *Opaque;
50 #endif
51 #ifndef NullOpaque
52 #define NullOpaque      ((Opaque)NULL)
53 #endif
54
55 #ifndef BOOLEAN_DEFINED
56 typedef char    Boolean;
57 #endif
58
59 #ifndef True
60 #define True    ((Boolean)1)
61 #define False   ((Boolean)0)
62 #endif /* ndef True */
63 #define booleanText(b)  ((b)?"True":"False")
64
65 #ifndef COMPARISON_DEFINED
66 typedef int             Comparison;
67
68 #define Greater         ((Comparison)1)
69 #define Equal           ((Comparison)0)
70 #define Less            ((Comparison)-1)
71 #define CannotCompare   ((Comparison)-37)
72 #define comparisonText(c)       ((c)?((c)<0?"Less":"Greater"):"Equal")
73 #endif
74
75 #ifdef notyet
76 typedef union {
77         int              i;
78         unsigned         u;
79         void            *p;
80         void            *(*fp)();
81 } Union;
82 #endif
83
84 /***====================================================================***/
85
86 extern  Opaque  uAlloc(
87     unsigned    /* size */
88 );
89 extern  Opaque  uCalloc(
90     unsigned    /* n */,
91     unsigned    /* size */
92 );
93 extern  Opaque  uRealloc(
94     Opaque      /* old */,
95     unsigned    /* newSize */
96 );
97 extern  Opaque  uRecalloc(
98     Opaque      /* old */,
99     unsigned    /* nOld */,
100     unsigned    /* nNew */,
101     unsigned    /* newSize */
102 );
103 extern  void    uFree(
104     Opaque      /* ptr */
105 );
106
107 #define uTypedAlloc(t)          ((t *)uAlloc((unsigned)sizeof(t)))
108 #define uTypedCalloc(n,t)       ((t *)uCalloc((unsigned)n,(unsigned)sizeof(t)))
109 #define uTypedRealloc(pO,n,t)   ((t *)uRealloc((Opaque)pO,((unsigned)n)*sizeof(t)))
110 #define uTypedRecalloc(pO,o,n,t) ((t *)uRecalloc((Opaque)pO,((unsigned)o),((unsigned)n),sizeof(t)))
111 #if (defined mdHasAlloca) && (mdHasAlloca)
112 #define uTmpAlloc(n)    ((Opaque)alloca((unsigned)n))
113 #define uTmpFree(p)
114 #else
115 #define uTmpAlloc(n)    uAlloc(n)
116 #define uTmpFree(p)     uFree(p)
117 #endif
118
119 /***====================================================================***/
120
121 extern Boolean uSetErrorFile ( const char *name );
122 extern void uInformation ( const char *s, ...) _X_ATTRIBUTE_PRINTF(1,2);
123 extern void uAction ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
124 extern void uWarning ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
125 extern void uError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
126 extern void uFatalError( const char *s,...) _X_ATTRIBUTE_PRINTF(1,2);
127 extern void uInternalError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
128
129 /***====================================================================***/
130
131 #define NullString      ((char *)NULL)
132
133 #define uStringText(s)          ((s)==NullString?"<NullString>":(s))
134 #define uStringEqual(s1,s2)     (uStringCompare(s1,s2)==Equal)
135 #define uStringPrefix(p,s)      (strncmp(p,s,strlen(p))==0)
136 #define uStringCompare(s1,s2)   (strcmp(s1,s2))
137 #define uStrCaseEqual(s1,s2)    (uStrCaseCmp(s1,s2)==0)
138 #ifdef HAVE_STRCASECMP
139 #define uStrCaseCmp(s1,s2)      (strcasecmp(s1,s2))
140 #define uStrCasePrefix(p,s)     (strncasecmp(p,s,strlen(p))==0)
141 #else
142 extern  int uStrCaseCmp(
143         const char *    /* s1 */,
144         const char *    /* s2 */
145 );
146 extern  int uStrCasePrefix(
147         const char *    /* p */,
148         const char *    /* str */
149 );
150 #endif
151 #ifdef HAVE_STRDUP
152 #define uStringDup(s1)          (strdup(s1))
153 #else
154 extern  char *uStringDup(
155         const char *    /* s1 */
156 );
157 #endif
158
159 /***====================================================================***/
160
161 #ifdef  ASSERTIONS_ON
162 #define uASSERT(where,why) \
163         {if (!(why)) uFatalError("assertion botched in %s ( why )\n",where);}
164 #else
165 #define uASSERT(where,why)
166 #endif
167
168 /***====================================================================***/
169
170 #ifndef DEBUG_VAR
171 #define DEBUG_VAR       debugFlags
172 #endif
173
174 extern
175 unsigned        int     DEBUG_VAR;
176
177 extern  void    uDebug( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
178 extern  void    uDebugNOI( const char *s, ... ) /* no indent */
179     _X_ATTRIBUTE_PRINTF(1,2);
180 extern  Boolean uSetDebugFile(
181     const char *name
182 );
183 extern  FILE    *uDebugFile;
184 extern  int     uDebugIndentLevel;
185 extern  int     uDebugIndentSize;
186 #define uDebugIndent(l)         (uDebugIndentLevel+=(l))
187 #define uDebugOutdent(l)        (uDebugIndentLevel-=(l))
188 #ifdef DEBUG_ON
189 #define uDEBUG(f,s)             { if (DEBUG_VAR&(f)) uDebug(s);}
190 #define uDEBUG1(f,s,a)          { if (DEBUG_VAR&(f)) uDebug(s,a);}
191 #define uDEBUG2(f,s,a,b)        { if (DEBUG_VAR&(f)) uDebug(s,a,b);}
192 #define uDEBUG3(f,s,a,b,c)      { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);}
193 #define uDEBUG4(f,s,a,b,c,d)    { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);}
194 #define uDEBUG5(f,s,a,b,c,d,e)  { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);}
195 #define uDEBUG_NOI(f,s)         { if (DEBUG_VAR&(f)) uDebug(s);}
196 #define uDEBUG_NOI1(f,s,a)      { if (DEBUG_VAR&(f)) uDebugNOI(s,a);}
197 #define uDEBUG_NOI2(f,s,a,b)    { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);}
198 #define uDEBUG_NOI3(f,s,a,b,c)  { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);}
199 #define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);}
200 #define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);}
201 #else
202 #define uDEBUG(f,s)
203 #define uDEBUG1(f,s,a)
204 #define uDEBUG2(f,s,a,b)
205 #define uDEBUG3(f,s,a,b,c)
206 #define uDEBUG4(f,s,a,b,c,d)
207 #define uDEBUG5(f,s,a,b,c,d,e)
208 #define uDEBUG_NOI(f,s)
209 #define uDEBUG_NOI1(f,s,a)
210 #define uDEBUG_NOI2(f,s,a,b)
211 #define uDEBUG_NOI3(f,s,a,b,c)
212 #define uDEBUG_NOI4(f,s,a,b,c,d)
213 #define uDEBUG_NOI5(f,s,a,b,c,d,e)
214 #endif
215
216 extern  Boolean uSetEntryFile(
217     const char *name
218 );
219 extern  void    uEntry(int l, const char *s, ... ) _X_ATTRIBUTE_PRINTF(2,3);
220 extern  void    uExit(
221     int l, const char *rtVal
222 );
223 #ifdef ENTRY_TRACKING_ON
224 #define ENTRY_BIT       0x10
225 #define LOW_ENTRY_BIT   0x1000
226 #define ENTER   (DEBUG_VAR&ENTRY_BIT)
227 #define FLAG(fLag)      (DEBUG_VAR&(fLag))
228
229 extern  int     uEntryLevel;
230
231 #define uENTRY(s)                       { if (ENTER) uEntry(1,s);}
232 #define uENTRY1(s,a)                    { if (ENTER) uEntry(1,s,a);}
233 #define uENTRY2(s,a,b)                  { if (ENTER) uEntry(1,s,a,b);}
234 #define uENTRY3(s,a,b,c)                { if (ENTER) uEntry(1,s,a,b,c);}
235 #define uENTRY4(s,a,b,c,d)              { if (ENTER) uEntry(1,s,a,b,c,d);}
236 #define uENTRY5(s,a,b,c,d,e)            { if (ENTER) uEntry(1,s,a,b,c,d,e);}
237 #define uENTRY6(s,a,b,c,d,e,f)          { if (ENTER) uEntry(1,s,a,b,c,d,e,f);}
238 #define uENTRY7(s,a,b,c,d,e,f,g)        { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);}
239 #define uRETURN(v)                      { if (ENTER) uEntryLevel--; return(v); }
240 #define uVOIDRETURN                     { if (ENTER) uEntryLevel--; return; }
241
242 #define uFLAG_ENTRY(w,s)                { if (FLAG(w)) uEntry(0,s);}
243 #define uFLAG_ENTRY1(w,s,a)             { if (FLAG(w)) uEntry(0,s,a);}
244 #define uFLAG_ENTRY2(w,s,a,b)           { if (FLAG(w)) uEntry(0,s,a,b);}
245 #define uFLAG_ENTRY3(w,s,a,b,c)         { if (FLAG(w)) uEntry(0,s,a,b,c);}
246 #define uFLAG_ENTRY4(w,s,a,b,c,d)       { if (FLAG(w)) uEntry(0,s,a,b,c,d);}
247 #define uFLAG_ENTRY5(w,s,a,b,c,d,e)     { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);}
248 #define uFLAG_ENTRY6(w,s,a,b,c,d,e,f)   { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);}
249 #define uFLAG_ENTRY7(w,s,a,b,c,d,e,f,g) { if(FLAG(w))uEntry(0,s,a,b,c,d,e,f,g);}
250 #define uFLAG_RETURN(v)                 { return(v);}
251 #define uFLAG_VOIDRETURN                { return; }
252 #else
253 #define uENTRY(s)
254 #define uENTRY1(s,a)
255 #define uENTRY2(s,a1,a2)
256 #define uENTRY3(s,a1,a2,a3)
257 #define uENTRY4(s,a1,a2,a3,a4)
258 #define uENTRY5(s,a1,a2,a3,a4,a5)
259 #define uENTRY6(s,a1,a2,a3,a4,a5,a6)
260 #define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7)
261 #define uRETURN(v)      { return(v); }
262 #define uVOIDRETURN     { return; }
263
264 #define uFLAG_ENTRY(f,s)
265 #define uFLAG_ENTRY1(f,s,a)
266 #define uFLAG_ENTRY2(f,s,a,b)
267 #define uFLAG_ENTRY3(f,s,a,b,c)
268 #define uFLAG_ENTRY4(f,s,a,b,c,d)
269 #define uFLAG_ENTRY5(f,s,a,b,c,d,e)
270 #define uFLAG_ENTRY6(f,s,a,b,c,d,e,g)
271 #define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h)
272 #define uFLAG_RETURN(v)                 { return(v);}
273 #define uFLAG_VOIDRETURN                { return; }
274 #endif
275
276 _XFUNCPROTOEND
277
278 #endif /* UTILS_H */
279
280