utils.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. #ifndef UTILS_H
  2. #define UTILS_H 1
  3. /*\
  4. * COPYRIGHT 1990
  5. * DIGITAL EQUIPMENT CORPORATION
  6. * MAYNARD, MASSACHUSETTS
  7. * ALL RIGHTS RESERVED.
  8. *
  9. * THE INFORMATION IN THIS SOFTWARE IS SUBJECT TO CHANGE WITHOUT NOTICE AND
  10. * SHOULD NOT BE CONSTRUED AS A COMMITMENT BY DIGITAL EQUIPMENT CORPORATION.
  11. * DIGITAL MAKES NO REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE
  12. * FOR ANY PURPOSE. IT IS SUPPLIED "AS IS" WITHOUT EXPRESS OR IMPLIED
  13. * WARRANTY.
  14. *
  15. * IF THE SOFTWARE IS MODIFIED IN A MANNER CREATING DERIVATIVE COPYRIGHT
  16. * RIGHTS, APPROPRIATE LEGENDS MAY BE PLACED ON THE DERIVATIVE WORK IN
  17. * ADDITION TO THAT SET FORTH ABOVE.
  18. *
  19. * Permission to use, copy, modify, and distribute this software and its
  20. * documentation for any purpose and without fee is hereby granted, provided
  21. * that the above copyright notice appear in all copies and that both that
  22. * copyright notice and this permission notice appear in supporting
  23. * documentation, and that the name of Digital Equipment Corporation not be
  24. * used in advertising or publicity pertaining to distribution of the
  25. * software without specific, written prior permission.
  26. \*/
  27. /***====================================================================***/
  28. #include <stdio.h>
  29. #include <X11/Xos.h>
  30. #include <X11/Xfuncproto.h>
  31. #include <X11/Xfuncs.h>
  32. #include <stdarg.h>
  33. #include <stddef.h>
  34. _XFUNCPROTOBEGIN
  35. #ifndef NUL
  36. #define NUL '\0'
  37. #endif
  38. /***====================================================================***/
  39. #ifndef OPAQUE_DEFINED
  40. typedef void *Opaque;
  41. #endif
  42. #ifndef NullOpaque
  43. #define NullOpaque ((Opaque)NULL)
  44. #endif
  45. #ifndef BOOLEAN_DEFINED
  46. typedef char Boolean;
  47. #endif
  48. #ifndef True
  49. #define True ((Boolean)1)
  50. #define False ((Boolean)0)
  51. #endif /* ndef True */
  52. #define booleanText(b) ((b)?"True":"False")
  53. #ifndef COMPARISON_DEFINED
  54. typedef int Comparison;
  55. #define Greater ((Comparison)1)
  56. #define Equal ((Comparison)0)
  57. #define Less ((Comparison)-1)
  58. #define CannotCompare ((Comparison)-37)
  59. #define comparisonText(c) ((c)?((c)<0?"Less":"Greater"):"Equal")
  60. #endif
  61. /***====================================================================***/
  62. extern Boolean uSetErrorFile(const char *name);
  63. extern void uInformation(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2);
  64. extern void uAction(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2);
  65. extern void uWarning(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2);
  66. extern void uError(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2);
  67. extern void uFatalError(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2)
  68. _X_NORETURN;
  69. extern void uInternalError(const char *s, ...) _X_ATTRIBUTE_PRINTF(1, 2);
  70. /***====================================================================***/
  71. #define NullString ((char *)NULL)
  72. #define uStringText(s) ((s)==NullString?"<NullString>":(s))
  73. #define uStringEqual(s1,s2) (uStringCompare(s1,s2)==Equal)
  74. #define uStringPrefix(p,s) (strncmp(p,s,strlen(p))==0)
  75. #define uStringCompare(s1,s2) (strcmp(s1,s2))
  76. #define uStrCaseEqual(s1,s2) (strcasecmp(s1,s2)==0)
  77. #ifndef HAVE_ASPRINTF
  78. extern _X_HIDDEN int _X_ATTRIBUTE_PRINTF(2,3)
  79. uAsprintf(char ** ret, const char *format, ...);
  80. #define asprintf uAsprintf
  81. #endif
  82. /***====================================================================***/
  83. _XFUNCPROTOEND
  84. #endif /* UTILS_H */