dbg.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // Copyright (C) 2003 Mooffie <mooffie@typo.co.il>
  2. //
  3. // This program is free software; you can redistribute it and/or modify
  4. // it under the terms of the GNU General Public License as published by
  5. // the Free Software Foundation; either version 2 of the License, or
  6. // (at your option) any later version.
  7. //
  8. // This program is distributed in the hope that it will be useful,
  9. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. // GNU General Public License for more details.
  12. //
  13. // You should have received a copy of the GNU General Public License
  14. // along with this program; if not, write to the Free Software
  15. // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA.
  16. #include <config.h>
  17. #include <stdarg.h>
  18. #include <stdio.h>
  19. #include <stdlib.h> // exit()
  20. #include "terminal.h" // for the gettext stuff
  21. #include "dbg.h"
  22. static int debug_level = 0;
  23. void set_debug_level(int level)
  24. {
  25. debug_level = level;
  26. }
  27. bool print_debug_level(int level)
  28. {
  29. return level <= debug_level;
  30. }
  31. void debug_print(const char *fmt, ...)
  32. {
  33. va_list ap;
  34. va_start(ap, fmt);
  35. vfprintf(stderr, fmt, ap);
  36. va_end(ap);
  37. }
  38. // I've just noticed that my fatal() function is very similar to fribidi's
  39. // die(). Strange. I've taken the variable names from an example in K&R, and
  40. // used the output of 'ls' ("try ... for more info"). Perhaps it proves
  41. // that two monkeys sitting at two keyboards and not typing randomly can
  42. // produce the same program :-)
  43. void fatal(const char *fmt, ...)
  44. {
  45. va_list ap;
  46. va_start(ap, fmt);
  47. if (fmt) {
  48. fprintf(stderr, PACKAGE ": ");
  49. vfprintf(stderr, fmt, ap);
  50. }
  51. fprintf(stderr, _("Try `%s --help' for more information.\n"), PACKAGE);
  52. va_end(ap);
  53. exit(1);
  54. }