upload tizen2.0 source
[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 #ifdef HAVE_CONFIG_H
33 #include "config.h"
34 #endif
35
36 #include        <stdio.h>
37 #include        <X11/Xos.h>
38 #include        <X11/Xfuncproto.h>
39 #include        <X11/Xfuncs.h>
40 #include        <stdarg.h>
41 #include        <stddef.h>
42
43 _XFUNCPROTOBEGIN
44
45
46 #ifndef NUL
47 #define NUL     '\0'
48 #endif
49
50 /***====================================================================***/
51
52 #ifndef OPAQUE_DEFINED
53 typedef void *Opaque;
54 #endif
55 #ifndef NullOpaque
56 #define NullOpaque      ((Opaque)NULL)
57 #endif
58
59 #ifndef BOOLEAN_DEFINED
60 typedef char    Boolean;
61 #endif
62
63 #ifndef True
64 #define True    ((Boolean)1)
65 #define False   ((Boolean)0)
66 #endif /* ndef True */
67 #define booleanText(b)  ((b)?"True":"False")
68
69 #ifndef COMPARISON_DEFINED
70 typedef int             Comparison;
71
72 #define Greater         ((Comparison)1)
73 #define Equal           ((Comparison)0)
74 #define Less            ((Comparison)-1)
75 #define CannotCompare   ((Comparison)-37)
76 #define comparisonText(c)       ((c)?((c)<0?"Less":"Greater"):"Equal")
77 #endif
78
79 #ifdef notyet
80 typedef union {
81         int              i;
82         unsigned         u;
83         void            *p;
84         void            *(*fp)();
85 } Union;
86 #endif
87
88 /***====================================================================***/
89
90 extern Boolean uSetErrorFile ( const char *name );
91 extern void uInformation ( const char *s, ...) _X_ATTRIBUTE_PRINTF(1,2);
92 extern void uAction ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
93 extern void uWarning ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
94 extern void uError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
95 extern void uInternalError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
96
97 /***====================================================================***/
98
99 #define NullString      ((char *)NULL)
100
101 #define uStringText(s)          ((s)==NullString?"<NullString>":(s))
102 #define uStringEqual(s1,s2)     (uStringCompare(s1,s2)==Equal)
103 #define uStringPrefix(p,s)      (strncmp(p,s,strlen(p))==0)
104 #define uStringCompare(s1,s2)   (strcmp(s1,s2))
105 #define uStrCaseEqual(s1,s2)    (uStrCaseCmp(s1,s2)==0)
106 #ifdef HAVE_STRCASECMP
107 #define uStrCaseCmp(s1,s2)      (strcasecmp(s1,s2))
108 #define uStrCasePrefix(p,s)     (strncasecmp(p,s,strlen(p))==0)
109 #else
110 extern  int uStrCaseCmp(
111         const char *    /* s1 */,
112         const char *    /* s2 */
113 );
114 extern  int uStrCasePrefix(
115         const char *    /* p */,
116         const char *    /* str */
117 );
118 #endif
119 #define uStringDup(s1)          (strdup(s1))
120
121 /***====================================================================***/
122
123 #ifndef DEBUG_VAR
124 #define DEBUG_VAR       debugFlags
125 #endif
126
127 extern
128 unsigned        int     DEBUG_VAR;
129
130 extern  void    uDebug( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
131 extern  void    uDebugNOI( const char *s, ... ) /* no indent */
132     _X_ATTRIBUTE_PRINTF(1,2);
133 extern  Boolean uSetDebugFile(
134     const char *name
135 );
136 extern  FILE    *uDebugFile;
137 extern  int     uDebugIndentLevel;
138 extern  int     uDebugIndentSize;
139 #define uDebugIndent(l)         (uDebugIndentLevel+=(l))
140 #define uDebugOutdent(l)        (uDebugIndentLevel-=(l))
141 #ifdef DEBUG_ON
142 #define uDEBUG(f,s)             { if (DEBUG_VAR&(f)) uDebug(s);}
143 #define uDEBUG1(f,s,a)          { if (DEBUG_VAR&(f)) uDebug(s,a);}
144 #define uDEBUG2(f,s,a,b)        { if (DEBUG_VAR&(f)) uDebug(s,a,b);}
145 #define uDEBUG3(f,s,a,b,c)      { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);}
146 #define uDEBUG4(f,s,a,b,c,d)    { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);}
147 #define uDEBUG5(f,s,a,b,c,d,e)  { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);}
148 #define uDEBUG_NOI(f,s)         { if (DEBUG_VAR&(f)) uDebug(s);}
149 #define uDEBUG_NOI1(f,s,a)      { if (DEBUG_VAR&(f)) uDebugNOI(s,a);}
150 #define uDEBUG_NOI2(f,s,a,b)    { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);}
151 #define uDEBUG_NOI3(f,s,a,b,c)  { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);}
152 #define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);}
153 #define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);}
154 #else
155 #define uDEBUG(f,s)
156 #define uDEBUG1(f,s,a)
157 #define uDEBUG2(f,s,a,b)
158 #define uDEBUG3(f,s,a,b,c)
159 #define uDEBUG4(f,s,a,b,c,d)
160 #define uDEBUG5(f,s,a,b,c,d,e)
161 #define uDEBUG_NOI(f,s)
162 #define uDEBUG_NOI1(f,s,a)
163 #define uDEBUG_NOI2(f,s,a,b)
164 #define uDEBUG_NOI3(f,s,a,b,c)
165 #define uDEBUG_NOI4(f,s,a,b,c,d)
166 #define uDEBUG_NOI5(f,s,a,b,c,d,e)
167 #endif
168
169 extern  Boolean uSetEntryFile(
170     const char *name
171 );
172 extern  void    uEntry(int l, const char *s, ... ) _X_ATTRIBUTE_PRINTF(2,3);
173 extern  void    uExit(
174     int l, const char *rtVal
175 );
176 #ifdef ENTRY_TRACKING_ON
177 #define ENTRY_BIT       0x10
178 #define LOW_ENTRY_BIT   0x1000
179 #define ENTER   (DEBUG_VAR&ENTRY_BIT)
180 #define FLAG(fLag)      (DEBUG_VAR&(fLag))
181
182 extern  int     uEntryLevel;
183
184 #define uENTRY(s)                       { if (ENTER) uEntry(1,s);}
185 #define uENTRY1(s,a)                    { if (ENTER) uEntry(1,s,a);}
186 #define uENTRY2(s,a,b)                  { if (ENTER) uEntry(1,s,a,b);}
187 #define uENTRY3(s,a,b,c)                { if (ENTER) uEntry(1,s,a,b,c);}
188 #define uENTRY4(s,a,b,c,d)              { if (ENTER) uEntry(1,s,a,b,c,d);}
189 #define uENTRY5(s,a,b,c,d,e)            { if (ENTER) uEntry(1,s,a,b,c,d,e);}
190 #define uENTRY6(s,a,b,c,d,e,f)          { if (ENTER) uEntry(1,s,a,b,c,d,e,f);}
191 #define uENTRY7(s,a,b,c,d,e,f,g)        { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);}
192 #define uRETURN(v)                      { if (ENTER) uEntryLevel--; return(v); }
193 #define uVOIDRETURN                     { if (ENTER) uEntryLevel--; return; }
194
195 #define uFLAG_ENTRY(w,s)                { if (FLAG(w)) uEntry(0,s);}
196 #define uFLAG_ENTRY1(w,s,a)             { if (FLAG(w)) uEntry(0,s,a);}
197 #define uFLAG_ENTRY2(w,s,a,b)           { if (FLAG(w)) uEntry(0,s,a,b);}
198 #define uFLAG_ENTRY3(w,s,a,b,c)         { if (FLAG(w)) uEntry(0,s,a,b,c);}
199 #define uFLAG_ENTRY4(w,s,a,b,c,d)       { if (FLAG(w)) uEntry(0,s,a,b,c,d);}
200 #define uFLAG_ENTRY5(w,s,a,b,c,d,e)     { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);}
201 #define uFLAG_ENTRY6(w,s,a,b,c,d,e,f)   { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);}
202 #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);}
203 #define uFLAG_RETURN(v)                 { return(v);}
204 #define uFLAG_VOIDRETURN                { return; }
205 #else
206 #define uENTRY(s)
207 #define uENTRY1(s,a)
208 #define uENTRY2(s,a1,a2)
209 #define uENTRY3(s,a1,a2,a3)
210 #define uENTRY4(s,a1,a2,a3,a4)
211 #define uENTRY5(s,a1,a2,a3,a4,a5)
212 #define uENTRY6(s,a1,a2,a3,a4,a5,a6)
213 #define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7)
214 #define uRETURN(v)      { return(v); }
215 #define uVOIDRETURN     { return; }
216
217 #define uFLAG_ENTRY(f,s)
218 #define uFLAG_ENTRY1(f,s,a)
219 #define uFLAG_ENTRY2(f,s,a,b)
220 #define uFLAG_ENTRY3(f,s,a,b,c)
221 #define uFLAG_ENTRY4(f,s,a,b,c,d)
222 #define uFLAG_ENTRY5(f,s,a,b,c,d,e)
223 #define uFLAG_ENTRY6(f,s,a,b,c,d,e,g)
224 #define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h)
225 #define uFLAG_RETURN(v)                 { return(v);}
226 #define uFLAG_VOIDRETURN                { return; }
227 #endif
228
229 _XFUNCPROTOEND
230
231 #endif /* UTILS_H */
232
233