PageRenderTime 39ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/xorg-x11-xkb-utils-7.7/xkbevd-1.1.3/utils.h

#
C++ Header | 233 lines | 171 code | 32 blank | 30 comment | 30 complexity | f301616e68b477b7ea48aaf532d1d720 MD5 | raw file
Possible License(s): MIT
  1. #ifndef UTILS_H
  2. #define UTILS_H 1
  3. /*\
  4. *
  5. * COPYRIGHT 1990
  6. * DIGITAL EQUIPMENT CORPORATION
  7. * MAYNARD, MASSACHUSETTS
  8. * ALL RIGHTS RESERVED.
  9. *
  10. * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
  11. * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
  12. * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
  13. * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
  14. * WARRANTY.
  15. *
  16. * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
  17. * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
  18. * ADDITION TO THAT SET FORTH ABOVE.
  19. *
  20. * Permission to use, copy, modify, and distribute this software and its
  21. * documentation for any purpose and without fee is hereby granted, provided
  22. * that the above copyright notice appear in all copies and that both that
  23. * copyright notice and this permission notice appear in supporting
  24. * documentation, and that the name of Digital Equipment Corporation not be
  25. * used in advertising or publicity pertaining to distribution of the
  26. * software without specific, written prior permission.
  27. \*/
  28. /***====================================================================***/
  29. #ifdef HAVE_CONFIG_H
  30. #include "config.h"
  31. #endif
  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. _XFUNCPROTOBEGIN
  39. #ifndef NUL
  40. #define NUL '\0'
  41. #endif
  42. /***====================================================================***/
  43. #ifndef OPAQUE_DEFINED
  44. typedef void *Opaque;
  45. #endif
  46. #ifndef NullOpaque
  47. #define NullOpaque ((Opaque)NULL)
  48. #endif
  49. #ifndef BOOLEAN_DEFINED
  50. typedef char Boolean;
  51. #endif
  52. #ifndef True
  53. #define True ((Boolean)1)
  54. #define False ((Boolean)0)
  55. #endif /* ndef True */
  56. #define booleanText(b) ((b)?"True":"False")
  57. #ifndef COMPARISON_DEFINED
  58. typedef int Comparison;
  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. #ifdef notyet
  66. typedef union {
  67. int i;
  68. unsigned u;
  69. void *p;
  70. void *(*fp)();
  71. } Union;
  72. #endif
  73. /***====================================================================***/
  74. extern Boolean uSetErrorFile ( const char *name );
  75. extern void uInformation ( const char *s, ...) _X_ATTRIBUTE_PRINTF(1,2);
  76. extern void uAction ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
  77. extern void uWarning ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
  78. extern void uError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
  79. extern void uInternalError ( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
  80. /***====================================================================***/
  81. #define NullString ((char *)NULL)
  82. #define uStringText(s) ((s)==NullString?"<NullString>":(s))
  83. #define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal)
  84. #define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0)
  85. #define uStringCompare(s1,s2) (strcmp(s1,s2))
  86. #define uStrCaseEqual(s1,s2) (uStrCaseCmp(s1,s2)==0)
  87. #ifdef HAVE_STRCASECMP
  88. #define uStrCaseCmp(s1,s2) (strcasecmp(s1,s2))
  89. #define uStrCasePrefix(p,s) (strncasecmp(p,s,strlen(p))==0)
  90. #else
  91. extern int uStrCaseCmp(
  92. const char * /* s1 */,
  93. const char * /* s2 */
  94. );
  95. extern int uStrCasePrefix(
  96. const char * /* p */,
  97. const char * /* str */
  98. );
  99. #endif
  100. #define uStringDup(s1) (strdup(s1))
  101. /***====================================================================***/
  102. #ifndef DEBUG_VAR
  103. #define DEBUG_VAR debugFlags
  104. #endif
  105. extern
  106. unsigned int DEBUG_VAR;
  107. extern void uDebug( const char *s, ... ) _X_ATTRIBUTE_PRINTF(1,2);
  108. extern void uDebugNOI( const char *s, ... ) /* no indent */
  109. _X_ATTRIBUTE_PRINTF(1,2);
  110. extern Boolean uSetDebugFile(
  111. const char *name
  112. );
  113. extern FILE *uDebugFile;
  114. extern int uDebugIndentLevel;
  115. extern int uDebugIndentSize;
  116. #define uDebugIndent(l) (uDebugIndentLevel+=(l))
  117. #define uDebugOutdent(l) (uDebugIndentLevel-=(l))
  118. #ifdef DEBUG_ON
  119. #define uDEBUG(f,s) { if (DEBUG_VAR&(f)) uDebug(s);}
  120. #define uDEBUG1(f,s,a) { if (DEBUG_VAR&(f)) uDebug(s,a);}
  121. #define uDEBUG2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebug(s,a,b);}
  122. #define uDEBUG3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c);}
  123. #define uDEBUG4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d);}
  124. #define uDEBUG5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebug(s,a,b,c,d,e);}
  125. #define uDEBUG_NOI(f,s) { if (DEBUG_VAR&(f)) uDebug(s);}
  126. #define uDEBUG_NOI1(f,s,a) { if (DEBUG_VAR&(f)) uDebugNOI(s,a);}
  127. #define uDEBUG_NOI2(f,s,a,b) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b);}
  128. #define uDEBUG_NOI3(f,s,a,b,c) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c);}
  129. #define uDEBUG_NOI4(f,s,a,b,c,d) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d);}
  130. #define uDEBUG_NOI5(f,s,a,b,c,d,e) { if (DEBUG_VAR&(f)) uDebugNOI(s,a,b,c,d,e);}
  131. #else
  132. #define uDEBUG(f,s)
  133. #define uDEBUG1(f,s,a)
  134. #define uDEBUG2(f,s,a,b)
  135. #define uDEBUG3(f,s,a,b,c)
  136. #define uDEBUG4(f,s,a,b,c,d)
  137. #define uDEBUG5(f,s,a,b,c,d,e)
  138. #define uDEBUG_NOI(f,s)
  139. #define uDEBUG_NOI1(f,s,a)
  140. #define uDEBUG_NOI2(f,s,a,b)
  141. #define uDEBUG_NOI3(f,s,a,b,c)
  142. #define uDEBUG_NOI4(f,s,a,b,c,d)
  143. #define uDEBUG_NOI5(f,s,a,b,c,d,e)
  144. #endif
  145. extern Boolean uSetEntryFile(
  146. const char *name
  147. );
  148. extern void uEntry(int l, const char *s, ... ) _X_ATTRIBUTE_PRINTF(2,3);
  149. extern void uExit(
  150. int l, const char *rtVal
  151. );
  152. #ifdef ENTRY_TRACKING_ON
  153. #define ENTRY_BIT 0x10
  154. #define LOW_ENTRY_BIT 0x1000
  155. #define ENTER (DEBUG_VAR&ENTRY_BIT)
  156. #define FLAG(fLag) (DEBUG_VAR&(fLag))
  157. extern int uEntryLevel;
  158. #define uENTRY(s) { if (ENTER) uEntry(1,s);}
  159. #define uENTRY1(s,a) { if (ENTER) uEntry(1,s,a);}
  160. #define uENTRY2(s,a,b) { if (ENTER) uEntry(1,s,a,b);}
  161. #define uENTRY3(s,a,b,c) { if (ENTER) uEntry(1,s,a,b,c);}
  162. #define uENTRY4(s,a,b,c,d) { if (ENTER) uEntry(1,s,a,b,c,d);}
  163. #define uENTRY5(s,a,b,c,d,e) { if (ENTER) uEntry(1,s,a,b,c,d,e);}
  164. #define uENTRY6(s,a,b,c,d,e,f) { if (ENTER) uEntry(1,s,a,b,c,d,e,f);}
  165. #define uENTRY7(s,a,b,c,d,e,f,g) { if (ENTER) uEntry(1,s,a,b,c,d,e,f,g);}
  166. #define uRETURN(v) { if (ENTER) uEntryLevel--; return(v); }
  167. #define uVOIDRETURN { if (ENTER) uEntryLevel--; return; }
  168. #define uFLAG_ENTRY(w,s) { if (FLAG(w)) uEntry(0,s);}
  169. #define uFLAG_ENTRY1(w,s,a) { if (FLAG(w)) uEntry(0,s,a);}
  170. #define uFLAG_ENTRY2(w,s,a,b) { if (FLAG(w)) uEntry(0,s,a,b);}
  171. #define uFLAG_ENTRY3(w,s,a,b,c) { if (FLAG(w)) uEntry(0,s,a,b,c);}
  172. #define uFLAG_ENTRY4(w,s,a,b,c,d) { if (FLAG(w)) uEntry(0,s,a,b,c,d);}
  173. #define uFLAG_ENTRY5(w,s,a,b,c,d,e) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e);}
  174. #define uFLAG_ENTRY6(w,s,a,b,c,d,e,f) { if (FLAG(w)) uEntry(0,s,a,b,c,d,e,f);}
  175. #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);}
  176. #define uFLAG_RETURN(v) { return(v);}
  177. #define uFLAG_VOIDRETURN { return; }
  178. #else
  179. #define uENTRY(s)
  180. #define uENTRY1(s,a)
  181. #define uENTRY2(s,a1,a2)
  182. #define uENTRY3(s,a1,a2,a3)
  183. #define uENTRY4(s,a1,a2,a3,a4)
  184. #define uENTRY5(s,a1,a2,a3,a4,a5)
  185. #define uENTRY6(s,a1,a2,a3,a4,a5,a6)
  186. #define uENTRY7(s,a1,a2,a3,a4,a5,a6,a7)
  187. #define uRETURN(v) { return(v); }
  188. #define uVOIDRETURN { return; }
  189. #define uFLAG_ENTRY(f,s)
  190. #define uFLAG_ENTRY1(f,s,a)
  191. #define uFLAG_ENTRY2(f,s,a,b)
  192. #define uFLAG_ENTRY3(f,s,a,b,c)
  193. #define uFLAG_ENTRY4(f,s,a,b,c,d)
  194. #define uFLAG_ENTRY5(f,s,a,b,c,d,e)
  195. #define uFLAG_ENTRY6(f,s,a,b,c,d,e,g)
  196. #define uFLAG_ENTRY7(f,s,a,b,c,d,e,g,h)
  197. #define uFLAG_RETURN(v) { return(v);}
  198. #define uFLAG_VOIDRETURN { return; }
  199. #endif
  200. _XFUNCPROTOEND
  201. #endif /* UTILS_H */