Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 1 | #include <stdio.h> |
| 2 | #include <stdlib.h> |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 3 | #include <string.h> |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 4 | |
Arnaldo Carvalho de Melo | 1e6dd07 | 2010-08-10 15:58:50 -0300 | [diff] [blame] | 5 | #include "../debug.h" |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 6 | #include "helpline.h" |
Arnaldo Carvalho de Melo | 5c35d69 | 2011-02-09 11:38:43 -0200 | [diff] [blame] | 7 | #include "ui.h" |
Arnaldo Carvalho de Melo | 175729f | 2016-07-07 11:38:09 -0300 | [diff] [blame] | 8 | #include "../util.h" |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 9 | |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 10 | char ui_helpline__current[512]; |
| 11 | |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 12 | static void nop_helpline__pop(void) |
| 13 | { |
| 14 | } |
| 15 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 16 | static void nop_helpline__push(const char *msg __maybe_unused) |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 17 | { |
| 18 | } |
| 19 | |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 20 | static int nop_helpline__show(const char *fmt __maybe_unused, |
| 21 | va_list ap __maybe_unused) |
| 22 | { |
| 23 | return 0; |
| 24 | } |
| 25 | |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 26 | static struct ui_helpline default_helpline_fns = { |
| 27 | .pop = nop_helpline__pop, |
| 28 | .push = nop_helpline__push, |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 29 | .show = nop_helpline__show, |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | struct ui_helpline *helpline_fns = &default_helpline_fns; |
| 33 | |
| 34 | void ui_helpline__pop(void) |
| 35 | { |
| 36 | helpline_fns->pop(); |
| 37 | } |
| 38 | |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 39 | void ui_helpline__push(const char *msg) |
| 40 | { |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 41 | helpline_fns->push(msg); |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 42 | } |
| 43 | |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 44 | void ui_helpline__vpush(const char *fmt, va_list ap) |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 45 | { |
| 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 | |
| 56 | void 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 | |
| 65 | void ui_helpline__puts(const char *msg) |
| 66 | { |
| 67 | ui_helpline__pop(); |
| 68 | ui_helpline__push(msg); |
| 69 | } |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 70 | |
| 71 | int ui_helpline__vshow(const char *fmt, va_list ap) |
| 72 | { |
| 73 | return helpline_fns->show(fmt, ap); |
| 74 | } |
Arnaldo Carvalho de Melo | 9484b86 | 2016-11-25 15:48:25 -0300 | [diff] [blame] | 75 | |
| 76 | void 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 | } |