blob: 379039ab00d82d8cb00e6583864761f1e8f84a5a [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 Melo175729f2016-07-07 11:38:09 -03008#include "../util.h"
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03009
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -020010char ui_helpline__current[512];
11
Namhyung Kime6e90462012-08-16 17:14:50 +090012static void nop_helpline__pop(void)
13{
14}
15
Irina Tirdea1d037ca2012-09-11 01:15:03 +030016static void nop_helpline__push(const char *msg __maybe_unused)
Namhyung Kime6e90462012-08-16 17:14:50 +090017{
18}
19
Namhyung Kimb56e5332012-11-15 01:47:41 +090020static int nop_helpline__show(const char *fmt __maybe_unused,
21 va_list ap __maybe_unused)
22{
23 return 0;
24}
25
Namhyung Kime6e90462012-08-16 17:14:50 +090026static struct ui_helpline default_helpline_fns = {
27 .pop = nop_helpline__pop,
28 .push = nop_helpline__push,
Namhyung Kimb56e5332012-11-15 01:47:41 +090029 .show = nop_helpline__show,
Namhyung Kime6e90462012-08-16 17:14:50 +090030};
31
32struct ui_helpline *helpline_fns = &default_helpline_fns;
33
34void ui_helpline__pop(void)
35{
36 helpline_fns->pop();
37}
38
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030039void ui_helpline__push(const char *msg)
40{
Namhyung Kime6e90462012-08-16 17:14:50 +090041 helpline_fns->push(msg);
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030042}
43
Arnaldo Carvalho de Melo59e8fe32010-08-10 15:44:20 -030044void ui_helpline__vpush(const char *fmt, va_list ap)
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030045{
46 char *s;
47
48 if (vasprintf(&s, fmt, ap) < 0)
49 vfprintf(stderr, fmt, ap);
50 else {
51 ui_helpline__push(s);
52 free(s);
53 }
54}
55
56void ui_helpline__fpush(const char *fmt, ...)
57{
58 va_list ap;
59
60 va_start(ap, fmt);
61 ui_helpline__vpush(fmt, ap);
62 va_end(ap);
63}
64
65void ui_helpline__puts(const char *msg)
66{
67 ui_helpline__pop();
68 ui_helpline__push(msg);
69}
Namhyung Kimb56e5332012-11-15 01:47:41 +090070
71int ui_helpline__vshow(const char *fmt, va_list ap)
72{
73 return helpline_fns->show(fmt, ap);
74}
Arnaldo Carvalho de Melo9484b862016-11-25 15:48:25 -030075
76void ui_helpline__printf(const char *fmt, ...)
77{
78 va_list ap;
79
80 ui_helpline__pop();
81 va_start(ap, fmt);
82 ui_helpline__vpush(fmt, ap);
83 va_end(ap);
84}