debug.c 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /*====================================================================*
  2. *
  3. * signed debug (signed status, char const * string, char const * format, ...);
  4. *
  5. * error.h
  6. *
  7. * variation of the GNU error() function that accepts a message in
  8. * place of an error code and always returns -1;
  9. *
  10. * Motley Tools by Charles Maier;
  11. * Copyright (c) 2001-2006 by Charles Maier Associates;
  12. * Licensed under the Internet Software Consortium License;
  13. *
  14. *--------------------------------------------------------------------*/
  15. #ifndef DEBUG_SOURCE
  16. #define DEBUG_SOURCE
  17. #include <stdio.h>
  18. #include <stdlib.h>
  19. #include <stdarg.h>
  20. #include <string.h>
  21. #include "../tools/types.h"
  22. #include "../tools/error.h"
  23. #ifdef __GNUC__
  24. __attribute__ ((format (printf, 3, 4)))
  25. #endif
  26. signed debug (signed status, char const * string, char const * format, ...)
  27. {
  28. extern char const * program_name;
  29. if ((program_name) && (* program_name))
  30. {
  31. fprintf (stderr, "%s: ", program_name);
  32. }
  33. if ((string) && (* string))
  34. {
  35. fprintf (stderr, "%s: ", string);
  36. }
  37. if ((format) && (*format))
  38. {
  39. va_list arglist;
  40. va_start (arglist, format);
  41. vfprintf (stderr, format, arglist);
  42. va_end (arglist);
  43. }
  44. fprintf (stderr, "\n");
  45. fflush (stderr);
  46. if (status)
  47. {
  48. exit (status);
  49. }
  50. return (-1);
  51. }
  52. #endif