1
0

dump.c 955 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. /*
  2. * dump.c
  3. * Provides indented printf functionality
  4. */
  5. #include "private.h"
  6. #include <stdio.h>
  7. #include <stdarg.h>
  8. static int indent = 0;
  9. /*--------------------------------------------------------- */
  10. int lub_dump_printf(const char *fmt, ...)
  11. {
  12. va_list args;
  13. int len;
  14. va_start(args, fmt);
  15. fprintf(stderr, "%*s", indent, "");
  16. len = vfprintf(stderr, fmt, args);
  17. va_end(args);
  18. return len;
  19. }
  20. /*--------------------------------------------------------- */
  21. static void lub_dump_divider(char c)
  22. {
  23. int i;
  24. lub_dump_printf("");
  25. for (i = 0; i < (80 - indent); i++) {
  26. fputc(c, stderr);
  27. }
  28. fputc('\n', stderr);
  29. }
  30. /*--------------------------------------------------------- */
  31. void lub_dump_indent(void)
  32. {
  33. indent += 2;
  34. lub_dump_divider('_');
  35. }
  36. /*--------------------------------------------------------- */
  37. void lub_dump_undent(void)
  38. {
  39. lub_dump_divider('^');
  40. indent -= 2;
  41. }
  42. /*--------------------------------------------------------- */