blob: 78ba28ac7a2ceb3fc756c49e06b16618281bf93e [file] [log] [blame]
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03001#include <stdio.h>
2#include <stdlib.h>
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -02003#include <string.h>
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03004
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -03005#include "../debug.h"
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03006#include "helpline.h"
Arnaldo Carvalho de Melo5c35d692011-02-09 11:38:43 -02007#include "ui.h"
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03008
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -02009char ui_helpline__current[512];
10
Namhyung Kime6e90462012-08-16 17:14:50 +090011static void nop_helpline__pop(void)
12{
13}
14
15static void nop_helpline__push(const char *msg __used)
16{
17}
18
19static struct ui_helpline default_helpline_fns = {
20 .pop = nop_helpline__pop,
21 .push = nop_helpline__push,
22};
23
24struct ui_helpline *helpline_fns = &default_helpline_fns;
25
26void ui_helpline__pop(void)
27{
28 helpline_fns->pop();
29}
30
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030031void ui_helpline__push(const char *msg)
32{
Namhyung Kime6e90462012-08-16 17:14:50 +090033 helpline_fns->push(msg);
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030034}
35
Arnaldo Carvalho de Melo59e8fe32010-08-10 15:44:20 -030036void ui_helpline__vpush(const char *fmt, va_list ap)
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030037{
38 char *s;
39
40 if (vasprintf(&s, fmt, ap) < 0)
41 vfprintf(stderr, fmt, ap);
42 else {
43 ui_helpline__push(s);
44 free(s);
45 }
46}
47
48void ui_helpline__fpush(const char *fmt, ...)
49{
50 va_list ap;
51
52 va_start(ap, fmt);
53 ui_helpline__vpush(fmt, ap);
54 va_end(ap);
55}
56
57void ui_helpline__puts(const char *msg)
58{
59 ui_helpline__pop();
60 ui_helpline__push(msg);
61}