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 | |
| 15 | static void nop_helpline__push(const char *msg __used) |
| 16 | { |
| 17 | } |
| 18 | |
| 19 | static struct ui_helpline default_helpline_fns = { |
| 20 | .pop = nop_helpline__pop, |
| 21 | .push = nop_helpline__push, |
| 22 | }; |
| 23 | |
| 24 | struct ui_helpline *helpline_fns = &default_helpline_fns; |
| 25 | |
| 26 | void ui_helpline__pop(void) |
| 27 | { |
| 28 | helpline_fns->pop(); |
| 29 | } |
| 30 | |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 31 | void ui_helpline__push(const char *msg) |
| 32 | { |
Namhyung Kim | e6e9046 | 2012-08-16 17:14:50 +0900 | [diff] [blame] | 33 | helpline_fns->push(msg); |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 34 | } |
| 35 | |
Arnaldo Carvalho de Melo | 59e8fe3 | 2010-08-10 15:44:20 -0300 | [diff] [blame] | 36 | void ui_helpline__vpush(const char *fmt, va_list ap) |
Arnaldo Carvalho de Melo | 5575536 | 2010-08-08 19:48:31 -0300 | [diff] [blame] | 37 | { |
| 38 | char *s; |
| 39 | |
| 40 | if (vasprintf(&s, fmt, ap) < 0) |
| 41 | vfprintf(stderr, fmt, ap); |
| 42 | else { |
| 43 | ui_helpline__push(s); |
| 44 | free(s); |
| 45 | } |
| 46 | } |
| 47 | |
| 48 | void ui_helpline__fpush(const char *fmt, ...) |
| 49 | { |
| 50 | va_list ap; |
| 51 | |
| 52 | va_start(ap, fmt); |
| 53 | ui_helpline__vpush(fmt, ap); |
| 54 | va_end(ap); |
| 55 | } |
| 56 | |
| 57 | void ui_helpline__puts(const char *msg) |
| 58 | { |
| 59 | ui_helpline__pop(); |
| 60 | ui_helpline__push(msg); |
| 61 | } |