You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

62 lines
1.6 KiB

  1. /* $Id: macros.h,v 1.4 2001/11/22 17:53:48 tausq Rel $ */
  2. #ifndef _MACROS_H
  3. #define _MACROS_H
  4. #include <stdio.h>
  5. #include <errno.h>
  6. #ifdef DEBUG
  7. #define DPRINTF(fmt, arg...) \
  8. do { \
  9. fprintf(stderr, "%s:%d ", __FILE__, __LINE__); \
  10. fprintf(stderr, fmt, ##arg); \
  11. fprintf(stderr, "\r\n"); \
  12. } while (0);
  13. #define ASSERT(cond) \
  14. if (!(cond)) { \
  15. if (ui_running()) ui_shutdown(); \
  16. fprintf(stderr, "ASSERTION FAILED at %s:%d! (%s)\n", __FILE__, __LINE__, #cond); \
  17. exit(255); \
  18. }
  19. #define VERIFY(cond) ASSERT(cond)
  20. #define ABORT abort()
  21. #define STRDUP(s) safe_strdup(s)
  22. #define MALLOC(sz) safe_malloc(sz)
  23. #define REALLOC(x,sz) safe_realloc(x,sz)
  24. #define FREE(p) safe_free((void **)&p);
  25. #else
  26. #define DPRINTF(fmt, arg...)
  27. #define ASSERT(cond)
  28. #define VERIFY(cond)
  29. #define ABORT exit(255)
  30. #define STRDUP(s) (s ? strdup(s) : NULL)
  31. #define MALLOC(sz) malloc(sz)
  32. #define REALLOC(x,sz) realloc(x,sz)
  33. #define FREE(p) if (p) free(p)
  34. #endif
  35. /* Do you see a perl influence? :-) */
  36. #define DIE(fmt, arg...) \
  37. do { \
  38. if (ui_running()) ui_shutdown(); \
  39. fprintf(stderr, _("Fatal error encountered at %s:%d\r\n\t"), __FILE__, __LINE__); \
  40. fprintf(stderr, fmt, ##arg); \
  41. fprintf(stderr, "\r\n"); \
  42. ABORT; \
  43. } while (0);
  44. #define PERROR(ctx) \
  45. do { \
  46. if (ui_running()) ui_shutdown(); \
  47. fprintf(stderr, _("I/O error at %s:%d\r\n\t"), __FILE__, __LINE__); \
  48. fprintf(stderr, "%s: %s\r\n", ctx, strerror(errno)); \
  49. ABORT; \
  50. } while (0);
  51. #define NEW(S) (S *)MALLOC(sizeof(S))
  52. #define _(s) gettext(s)
  53. #define gettext_noop(s) (s)
  54. #define N_(s) gettext_noop (s)
  55. #endif