dump.c 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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
  11. lub_dump_printf(const char *fmt,...)
  12. {
  13. va_list args;
  14. int len;
  15. va_start(args, fmt);
  16. fprintf(stderr, "%*s", indent, "");
  17. len = vfprintf(stderr, fmt, args);
  18. va_end(args);
  19. return len;
  20. }
  21. /*--------------------------------------------------------- */
  22. static void
  23. lub_dump_divider(char c)
  24. {
  25. int i;
  26. lub_dump_printf("");
  27. for(i = 0;
  28. i < (80 - indent);
  29. i++)
  30. {
  31. fputc(c, stderr);
  32. }
  33. fputc('\n', stderr);
  34. }
  35. /*--------------------------------------------------------- */
  36. void
  37. lub_dump_indent(void)
  38. {
  39. indent += 2;
  40. lub_dump_divider('_');
  41. }
  42. /*--------------------------------------------------------- */
  43. void
  44. lub_dump_undent(void)
  45. {
  46. lub_dump_divider('^');
  47. indent -= 2;
  48. }
  49. /*--------------------------------------------------------- */