1aca7a94dSNamhyung Kim #include <stdio.h> 2aca7a94dSNamhyung Kim #include <stdlib.h> 3aca7a94dSNamhyung Kim #include <string.h> 4aca7a94dSNamhyung Kim 5aca7a94dSNamhyung Kim #include "../debug.h" 6aca7a94dSNamhyung Kim #include "helpline.h" 7aca7a94dSNamhyung Kim #include "ui.h" 8175729fcSArnaldo Carvalho de Melo #include "../util.h" 9aca7a94dSNamhyung Kim 10aca7a94dSNamhyung Kim char ui_helpline__current[512]; 11aca7a94dSNamhyung Kim 12e6e90468SNamhyung Kim static void nop_helpline__pop(void) 13e6e90468SNamhyung Kim { 14e6e90468SNamhyung Kim } 15e6e90468SNamhyung Kim 161d037ca1SIrina Tirdea static void nop_helpline__push(const char *msg __maybe_unused) 17e6e90468SNamhyung Kim { 18e6e90468SNamhyung Kim } 19e6e90468SNamhyung Kim 20b56e5331SNamhyung Kim static int nop_helpline__show(const char *fmt __maybe_unused, 21b56e5331SNamhyung Kim va_list ap __maybe_unused) 22b56e5331SNamhyung Kim { 23b56e5331SNamhyung Kim return 0; 24b56e5331SNamhyung Kim } 25b56e5331SNamhyung Kim 26e6e90468SNamhyung Kim static struct ui_helpline default_helpline_fns = { 27e6e90468SNamhyung Kim .pop = nop_helpline__pop, 28e6e90468SNamhyung Kim .push = nop_helpline__push, 29b56e5331SNamhyung Kim .show = nop_helpline__show, 30e6e90468SNamhyung Kim }; 31e6e90468SNamhyung Kim 32e6e90468SNamhyung Kim struct ui_helpline *helpline_fns = &default_helpline_fns; 33e6e90468SNamhyung Kim 34e6e90468SNamhyung Kim void ui_helpline__pop(void) 35e6e90468SNamhyung Kim { 36e6e90468SNamhyung Kim helpline_fns->pop(); 37e6e90468SNamhyung Kim } 38e6e90468SNamhyung Kim 39aca7a94dSNamhyung Kim void ui_helpline__push(const char *msg) 40aca7a94dSNamhyung Kim { 41e6e90468SNamhyung Kim helpline_fns->push(msg); 42aca7a94dSNamhyung Kim } 43aca7a94dSNamhyung Kim 44aca7a94dSNamhyung Kim void ui_helpline__vpush(const char *fmt, va_list ap) 45aca7a94dSNamhyung Kim { 46aca7a94dSNamhyung Kim char *s; 47aca7a94dSNamhyung Kim 48aca7a94dSNamhyung Kim if (vasprintf(&s, fmt, ap) < 0) 49aca7a94dSNamhyung Kim vfprintf(stderr, fmt, ap); 50aca7a94dSNamhyung Kim else { 51aca7a94dSNamhyung Kim ui_helpline__push(s); 52aca7a94dSNamhyung Kim free(s); 53aca7a94dSNamhyung Kim } 54aca7a94dSNamhyung Kim } 55aca7a94dSNamhyung Kim 56aca7a94dSNamhyung Kim void ui_helpline__fpush(const char *fmt, ...) 57aca7a94dSNamhyung Kim { 58aca7a94dSNamhyung Kim va_list ap; 59aca7a94dSNamhyung Kim 60aca7a94dSNamhyung Kim va_start(ap, fmt); 61aca7a94dSNamhyung Kim ui_helpline__vpush(fmt, ap); 62aca7a94dSNamhyung Kim va_end(ap); 63aca7a94dSNamhyung Kim } 64aca7a94dSNamhyung Kim 65aca7a94dSNamhyung Kim void ui_helpline__puts(const char *msg) 66aca7a94dSNamhyung Kim { 67aca7a94dSNamhyung Kim ui_helpline__pop(); 68aca7a94dSNamhyung Kim ui_helpline__push(msg); 69aca7a94dSNamhyung Kim } 70b56e5331SNamhyung Kim 71b56e5331SNamhyung Kim int ui_helpline__vshow(const char *fmt, va_list ap) 72b56e5331SNamhyung Kim { 73b56e5331SNamhyung Kim return helpline_fns->show(fmt, ap); 74b56e5331SNamhyung Kim } 75*9484b86eSArnaldo Carvalho de Melo 76*9484b86eSArnaldo Carvalho de Melo void ui_helpline__printf(const char *fmt, ...) 77*9484b86eSArnaldo Carvalho de Melo { 78*9484b86eSArnaldo Carvalho de Melo va_list ap; 79*9484b86eSArnaldo Carvalho de Melo 80*9484b86eSArnaldo Carvalho de Melo ui_helpline__pop(); 81*9484b86eSArnaldo Carvalho de Melo va_start(ap, fmt); 82*9484b86eSArnaldo Carvalho de Melo ui_helpline__vpush(fmt, ap); 83*9484b86eSArnaldo Carvalho de Melo va_end(ap); 84*9484b86eSArnaldo Carvalho de Melo } 85