helpline.c 1.2 KB

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