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 | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 8 | |
Arnaldo Carvalho de Melo | 4610e41 | 2011-10-26 12:04:37 -0200 | [diff] [blame] | 9 | char ui_helpline__current[512]; |
| 10 | |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 11 | static void nop_helpline__pop(void) |
| 12 | { |
| 13 | } |
| 14 | |
Irina Tirdea | 1d037ca | 2012-09-11 01:15:03 +0300 | [diff] [blame] | 15 | static void nop_helpline__push(const char *msg __maybe_unused) |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 16 | { |
| 17 | } |
| 18 | |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 19 | static int nop_helpline__show(const char *fmt __maybe_unused, |
| 20 | va_list ap __maybe_unused) |
| 21 | { |
| 22 | return 0; |
| 23 | } |
| 24 | |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 25 | static struct ui_helpline default_helpline_fns = { |
| 26 | .pop = nop_helpline__pop, |
| 27 | .push = nop_helpline__push, |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 28 | .show = nop_helpline__show, |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 29 | }; |
| 30 | |
| 31 | struct ui_helpline *helpline_fns = &default_helpline_fns; |
| 32 | |
| 33 | void ui_helpline__pop(void) |
| 34 | { |
| 35 | helpline_fns->pop(); |
| 36 | } |
| 37 | |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 38 | void ui_helpline__push(const char *msg) |
| 39 | { |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 40 | helpline_fns->push(msg); |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 41 | } |
| 42 | |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 43 | void ui_helpline__vpush(const char *fmt, va_list ap) |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 44 | { |
| 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 | |
| 55 | void 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 | |
| 64 | void ui_helpline__puts(const char *msg) |
| 65 | { |
| 66 | ui_helpline__pop(); |
| 67 | ui_helpline__push(msg); |
| 68 | } |
Namhyung Kim | b56e533 | 2012-11-15 01:47:41 +0900 | [diff] [blame] | 69 | |
| 70 | int ui_helpline__vshow(const char *fmt, va_list ap) |
| 71 | { |
| 72 | return helpline_fns->show(fmt, ap); |
| 73 | } |