0001
0002 #include <stdio.h>
0003 #include <stdlib.h>
0004 #include <string.h>
0005
0006 #include "helpline.h"
0007 #include "ui.h"
0008
0009 char ui_helpline__current[512];
0010
0011 static void nop_helpline__pop(void)
0012 {
0013 }
0014
0015 static void nop_helpline__push(const char *msg __maybe_unused)
0016 {
0017 }
0018
0019 static int nop_helpline__show(const char *fmt __maybe_unused,
0020 va_list ap __maybe_unused)
0021 {
0022 return 0;
0023 }
0024
0025 static struct ui_helpline default_helpline_fns = {
0026 .pop = nop_helpline__pop,
0027 .push = nop_helpline__push,
0028 .show = nop_helpline__show,
0029 };
0030
0031 struct ui_helpline *helpline_fns = &default_helpline_fns;
0032
0033 void ui_helpline__pop(void)
0034 {
0035 helpline_fns->pop();
0036 }
0037
0038 void ui_helpline__push(const char *msg)
0039 {
0040 helpline_fns->push(msg);
0041 }
0042
0043 void ui_helpline__vpush(const char *fmt, va_list ap)
0044 {
0045 char *s;
0046
0047 if (vasprintf(&s, fmt, ap) < 0)
0048 vfprintf(stderr, fmt, ap);
0049 else {
0050 ui_helpline__push(s);
0051 free(s);
0052 }
0053 }
0054
0055 void ui_helpline__fpush(const char *fmt, ...)
0056 {
0057 va_list ap;
0058
0059 va_start(ap, fmt);
0060 ui_helpline__vpush(fmt, ap);
0061 va_end(ap);
0062 }
0063
0064 void ui_helpline__puts(const char *msg)
0065 {
0066 ui_helpline__pop();
0067 ui_helpline__push(msg);
0068 }
0069
0070 int ui_helpline__vshow(const char *fmt, va_list ap)
0071 {
0072 return helpline_fns->show(fmt, ap);
0073 }
0074
0075 void ui_helpline__printf(const char *fmt, ...)
0076 {
0077 va_list ap;
0078
0079 ui_helpline__pop();
0080 va_start(ap, fmt);
0081 ui_helpline__vpush(fmt, ap);
0082 va_end(ap);
0083 }