helpline.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include "../debug.h"
  5. #include "helpline.h"
  6. #include "ui.h"
  7. char ui_helpline__current[512];
  8. static void nop_helpline__pop(void)
  9. {
  10. }
  11. static void nop_helpline__push(const char *msg __maybe_unused)
  12. {
  13. }
  14. static int nop_helpline__show(const char *fmt __maybe_unused,
  15. va_list ap __maybe_unused)
  16. {
  17. return 0;
  18. }
  19. static struct ui_helpline default_helpline_fns = {
  20. .pop = nop_helpline__pop,
  21. .push = nop_helpline__push,
  22. .show = nop_helpline__show,
  23. };
  24. struct ui_helpline *helpline_fns = &default_helpline_fns;
  25. void ui_helpline__pop(void)
  26. {
  27. helpline_fns->pop();
  28. }
  29. void ui_helpline__push(const char *msg)
  30. {
  31. helpline_fns->push(msg);
  32. }
  33. void ui_helpline__vpush(const char *fmt, va_list ap)
  34. {
  35. char *s;
  36. if (vasprintf(&s, fmt, ap) < 0)
  37. vfprintf(stderr, fmt, ap);
  38. else {
  39. ui_helpline__push(s);
  40. free(s);
  41. }
  42. }
  43. void ui_helpline__fpush(const char *fmt, ...)
  44. {
  45. va_list ap;
  46. va_start(ap, fmt);
  47. ui_helpline__vpush(fmt, ap);
  48. va_end(ap);
  49. }
  50. void ui_helpline__puts(const char *msg)
  51. {
  52. ui_helpline__pop();
  53. ui_helpline__push(msg);
  54. }
  55. int ui_helpline__vshow(const char *fmt, va_list ap)
  56. {
  57. return helpline_fns->show(fmt, ap);
  58. }