blob: 700fb3cfa1c739128bc0c8009039f48e1f964c93 [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
Irina Tirdea1d037ca2012-09-11 01:15:03 +030015static void nop_helpline__push(const char *msg __maybe_unused)
Namhyung Kime6e90462012-08-16 17:14:50 +090016{
17}
18
Namhyung Kimb56e5332012-11-15 01:47:41 +090019static int nop_helpline__show(const char *fmt __maybe_unused,
20 va_list ap __maybe_unused)
21{
22 return 0;
23}
24
Namhyung Kime6e90462012-08-16 17:14:50 +090025static struct ui_helpline default_helpline_fns = {
26 .pop = nop_helpline__pop,
27 .push = nop_helpline__push,
Namhyung Kimb56e5332012-11-15 01:47:41 +090028 .show = nop_helpline__show,
Namhyung Kime6e90462012-08-16 17:14:50 +090029};
30
31struct ui_helpline *helpline_fns = &default_helpline_fns;
32
33void ui_helpline__pop(void)
34{
35 helpline_fns->pop();
36}
37
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030038void ui_helpline__push(const char *msg)
39{
Namhyung Kime6e90462012-08-16 17:14:50 +090040 helpline_fns->push(msg);
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030041}
42
Arnaldo Carvalho de Melo59e8fe32010-08-10 15:44:20 -030043void ui_helpline__vpush(const char *fmt, va_list ap)
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030044{
45 char *s;
46
47 if (vasprintf(&s, fmt, ap) < 0)
48 vfprintf(stderr, fmt, ap);
49 else {
50 ui_helpline__push(s);
51 free(s);
52 }
53}
54
55void ui_helpline__fpush(const char *fmt, ...)
56{
57 va_list ap;
58
59 va_start(ap, fmt);
60 ui_helpline__vpush(fmt, ap);
61 va_end(ap);
62}
63
64void ui_helpline__puts(const char *msg)
65{
66 ui_helpline__pop();
67 ui_helpline__push(msg);
68}
Namhyung Kimb56e5332012-11-15 01:47:41 +090069
70int ui_helpline__vshow(const char *fmt, va_list ap)
71{
72 return helpline_fns->show(fmt, ap);
73}