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" 8aca7a94dSNamhyung Kim 9aca7a94dSNamhyung Kim char ui_helpline__current[512]; 10aca7a94dSNamhyung Kim 11*e6e90468SNamhyung Kim static void nop_helpline__pop(void) 12*e6e90468SNamhyung Kim { 13*e6e90468SNamhyung Kim } 14*e6e90468SNamhyung Kim 15*e6e90468SNamhyung Kim static void nop_helpline__push(const char *msg __used) 16*e6e90468SNamhyung Kim { 17*e6e90468SNamhyung Kim } 18*e6e90468SNamhyung Kim 19*e6e90468SNamhyung Kim static struct ui_helpline default_helpline_fns = { 20*e6e90468SNamhyung Kim .pop = nop_helpline__pop, 21*e6e90468SNamhyung Kim .push = nop_helpline__push, 22*e6e90468SNamhyung Kim }; 23*e6e90468SNamhyung Kim 24*e6e90468SNamhyung Kim struct ui_helpline *helpline_fns = &default_helpline_fns; 25*e6e90468SNamhyung Kim 26*e6e90468SNamhyung Kim void ui_helpline__pop(void) 27*e6e90468SNamhyung Kim { 28*e6e90468SNamhyung Kim helpline_fns->pop(); 29*e6e90468SNamhyung Kim } 30*e6e90468SNamhyung Kim 31aca7a94dSNamhyung Kim void ui_helpline__push(const char *msg) 32aca7a94dSNamhyung Kim { 33*e6e90468SNamhyung Kim helpline_fns->push(msg); 34aca7a94dSNamhyung Kim } 35aca7a94dSNamhyung Kim 36aca7a94dSNamhyung Kim void ui_helpline__vpush(const char *fmt, va_list ap) 37aca7a94dSNamhyung Kim { 38aca7a94dSNamhyung Kim char *s; 39aca7a94dSNamhyung Kim 40aca7a94dSNamhyung Kim if (vasprintf(&s, fmt, ap) < 0) 41aca7a94dSNamhyung Kim vfprintf(stderr, fmt, ap); 42aca7a94dSNamhyung Kim else { 43aca7a94dSNamhyung Kim ui_helpline__push(s); 44aca7a94dSNamhyung Kim free(s); 45aca7a94dSNamhyung Kim } 46aca7a94dSNamhyung Kim } 47aca7a94dSNamhyung Kim 48aca7a94dSNamhyung Kim void ui_helpline__fpush(const char *fmt, ...) 49aca7a94dSNamhyung Kim { 50aca7a94dSNamhyung Kim va_list ap; 51aca7a94dSNamhyung Kim 52aca7a94dSNamhyung Kim va_start(ap, fmt); 53aca7a94dSNamhyung Kim ui_helpline__vpush(fmt, ap); 54aca7a94dSNamhyung Kim va_end(ap); 55aca7a94dSNamhyung Kim } 56aca7a94dSNamhyung Kim 57aca7a94dSNamhyung Kim void ui_helpline__puts(const char *msg) 58aca7a94dSNamhyung Kim { 59aca7a94dSNamhyung Kim ui_helpline__pop(); 60aca7a94dSNamhyung Kim ui_helpline__push(msg); 61aca7a94dSNamhyung Kim } 62