blob: b3c421429ed440b1eebcdbdefa9c223a74c81920 [file] [log] [blame]
Greg Kroah-Hartmanb2441312017-11-01 15:07:57 +01001// SPDX-License-Identifier: GPL-2.0
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03002#include <stdio.h>
3#include <stdlib.h>
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -02004#include <string.h>
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03005
Arnaldo Carvalho de Melo1e6dd072010-08-10 15:58:50 -03006#include "../debug.h"
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -03007#include "helpline.h"
Arnaldo Carvalho de Melo5c35d692011-02-09 11:38:43 -02008#include "ui.h"
Arnaldo Carvalho de Melo175729f2016-07-07 11:38:09 -03009#include "../util.h"
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030010
Arnaldo Carvalho de Melo4610e412011-10-26 12:04:37 -020011char ui_helpline__current[512];
12
Namhyung Kime6e90462012-08-16 17:14:50 +090013static void nop_helpline__pop(void)
14{
15}
16
Irina Tirdea1d037ca2012-09-11 01:15:03 +030017static void nop_helpline__push(const char *msg __maybe_unused)
Namhyung Kime6e90462012-08-16 17:14:50 +090018{
19}
20
Namhyung Kimb56e5332012-11-15 01:47:41 +090021static int nop_helpline__show(const char *fmt __maybe_unused,
22 va_list ap __maybe_unused)
23{
24 return 0;
25}
26
Namhyung Kime6e90462012-08-16 17:14:50 +090027static struct ui_helpline default_helpline_fns = {
28 .pop = nop_helpline__pop,
29 .push = nop_helpline__push,
Namhyung Kimb56e5332012-11-15 01:47:41 +090030 .show = nop_helpline__show,
Namhyung Kime6e90462012-08-16 17:14:50 +090031};
32
33struct ui_helpline *helpline_fns = &default_helpline_fns;
34
35void ui_helpline__pop(void)
36{
37 helpline_fns->pop();
38}
39
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030040void ui_helpline__push(const char *msg)
41{
Namhyung Kime6e90462012-08-16 17:14:50 +090042 helpline_fns->push(msg);
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030043}
44
Arnaldo Carvalho de Melo59e8fe32010-08-10 15:44:20 -030045void ui_helpline__vpush(const char *fmt, va_list ap)
Arnaldo Carvalho de Melo55755362010-08-08 19:48:31 -030046{
47 char *s;
48
49 if (vasprintf(&s, fmt, ap) < 0)
50 vfprintf(stderr, fmt, ap);
51 else {
52 ui_helpline__push(s);
53 free(s);
54 }
55}
56
57void ui_helpline__fpush(const char *fmt, ...)
58{
59 va_list ap;
60
61 va_start(ap, fmt);
62 ui_helpline__vpush(fmt, ap);
63 va_end(ap);
64}
65
66void ui_helpline__puts(const char *msg)
67{
68 ui_helpline__pop();
69 ui_helpline__push(msg);
70}
Namhyung Kimb56e5332012-11-15 01:47:41 +090071
72int ui_helpline__vshow(const char *fmt, va_list ap)
73{
74 return helpline_fns->show(fmt, ap);
75}
Arnaldo Carvalho de Melo9484b862016-11-25 15:48:25 -030076
77void ui_helpline__printf(const char *fmt, ...)
78{
79 va_list ap;
80
81 ui_helpline__pop();
82 va_start(ap, fmt);
83 ui_helpline__vpush(fmt, ap);
84 va_end(ap);
85}