jack2 codebase
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.

93 lines
2.2KB

  1. /*
  2. Copyright (C) 2001 Paul Davis
  3. Copyright (C) 2004-2008 Grame
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  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. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. */
  16. #include <stdarg.h>
  17. #include <stdio.h>
  18. #include "JackError.h"
  19. int jack_verbose = 0;
  20. static
  21. void
  22. jack_format_and_log(const char *prefix, const char *fmt, va_list ap, void (* log_callback)(const char *))
  23. {
  24. char buffer[300];
  25. size_t len;
  26. if (prefix != NULL) {
  27. len = strlen(prefix);
  28. memcpy(buffer, prefix, len);
  29. } else {
  30. len = 0;
  31. }
  32. vsnprintf(buffer + len, sizeof(buffer) - len, fmt, ap);
  33. log_callback(buffer);
  34. }
  35. EXPORT void jack_error(const char *fmt, ...)
  36. {
  37. va_list ap;
  38. va_start(ap, fmt);
  39. jack_format_and_log(NULL, fmt, ap, jack_error_callback);
  40. va_end(ap);
  41. }
  42. EXPORT void jack_info(const char *fmt, ...)
  43. {
  44. va_list ap;
  45. va_start(ap, fmt);
  46. jack_format_and_log(NULL, fmt, ap, jack_info_callback);
  47. va_end(ap);
  48. }
  49. EXPORT void jack_info_multiline(const char *fmt, ...)
  50. {
  51. va_list ap;
  52. va_start(ap, fmt);
  53. jack_format_and_log(NULL, fmt, ap, jack_info_callback);
  54. va_end(ap);
  55. }
  56. EXPORT void jack_log(const char *fmt,...)
  57. {
  58. if (jack_verbose) {
  59. va_list ap;
  60. va_start(ap, fmt);
  61. jack_format_and_log("Jack: ", fmt, ap, jack_info_callback);
  62. va_end(ap);
  63. }
  64. }
  65. static void default_jack_error_callback(const char *desc)
  66. {
  67. fprintf(stderr, "%s\n", desc);
  68. fflush(stderr);
  69. }
  70. static void default_jack_info_callback (const char *desc)
  71. {
  72. fprintf(stdout, "%s\n", desc);
  73. fflush(stdout);
  74. }
  75. void (*jack_error_callback)(const char *desc) = &default_jack_error_callback;
  76. void (*jack_info_callback)(const char *desc) = &default_jack_info_callback;