From 65087f82753a12e330fa0e6fc0c0e4b70c6a6c63 Mon Sep 17 00:00:00 2001 From: ache Date: Sat, 11 Nov 2017 03:57:47 +0000 Subject: PoC menu Contact --- basic_curses.c | 152 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 152 insertions(+) create mode 100644 basic_curses.c (limited to 'basic_curses.c') diff --git a/basic_curses.c b/basic_curses.c new file mode 100644 index 0000000..1a48b8d --- /dev/null +++ b/basic_curses.c @@ -0,0 +1,152 @@ +/* + * Ache - 2017-08-14 - GPLv3 + */ + +#include "basic_curses.h" + +/* + * Set of functions to easy print on the ncurse interface + */ + + + +void printfc(char* fstrc, int max_length, ...) { + int i = 0; + int nbC = 0; + char* tmp = NULL; + int toP = 0; + + + va_list ap; + va_start(ap, max_length); + + + while(fstrc[i] && nbC < max_length) { + if( strchr( "${<%>}#", fstrc[i]) ) { + if( tmp ) { + printw("%.*s", toP, tmp); + tmp=NULL; + toP=0; + } + switch( fstrc[i] ) { + case '$': + if( fstrc[i+1] ) { + if( isdigit(fstrc[i+1]) ) { + if( fstrc[i+1] == '9') { + ; + }else + attrset( COLOR_PAIR(fstrc[i+1]-'0') | A_NORMAL); + }else{ +#ifdef DEBUG + fprintf(stderr,"%c isn't a color, skipping", fstrc[i+1]); +#endif + } + }else{ +#ifdef DEBUG + fprintf(stderr,"end of line by '$', expect a color after '$'"); +#endif + return; + } + i+=2; + break; + case '%': + { + int j = 1; + char format[10] = "%"; + while(j < 9 && !strchr("diouxXeEfFgGaAcsp%", format[j] = fstrc[i+j]) ); + if( j == 9 ) { +#ifdef DEBUG + fprintf(stderr,"format too long %s...",format); +#endif + return; + } + if( strchr("di", format[j] ) ) { + printw(format, va_arg(ap, int)); + }else if( strchr("ouxX", format[j]) ) { + printw(format, va_arg(ap, unsigned int)); + }else if( strchr("eE", format[j]) ) { + printw(format, va_arg(ap, double)); + }else if( strchr("fF", format[j]) ) { + printw(format, va_arg(ap, double)); + }else if( strchr("gG", format[j]) ) { + printw(format, va_arg(ap, double)); + }else if( strchr("aA", format[j]) ) { + printw(format, va_arg(ap, double)); + }else if( strchr("c", format[j]) ) { + printw(format, va_arg(ap, int)); + }else if( strchr("s", format[j]) ) { + printw(format, va_arg(ap, const char*)); + }else if( strchr("p", format[j]) ) { + printw(format, va_arg(ap, void*)); + }else if( strchr("%", format[j]) ) { + printw("%%"); + } +// nbC+= + + i+=j; + } + } + }else{ + if( ! tmp ) + tmp = fstrc+i; + toP += 1; + nbC++; + i++; + } + } + if(tmp) + printw("%.*s", toP, tmp); + fflush(NULL); +} + +void printc(char* fstrc, int max_length) { + int i = 0; + int nbC = 0; + char* tmp = NULL; + int toP = 0; + while(fstrc[i] && nbC < max_length) { + if( strchr( "${<>}#", fstrc[i]) ) { + if( tmp ) { + printw("%.*s", toP, tmp); + tmp=NULL; + toP=0; + } + switch( fstrc[i] ) { + case '$': + if( fstrc[i+1] ) { + if( isdigit(fstrc[i+1]) ) { + if( fstrc[i+1] == '9') { + ; + }else + attrset( COLOR_PAIR(fstrc[i+1]-'0') | A_NORMAL); + }else{ +#ifdef DEBUG + fprintf(stderr,"%c isn't a color, skipping", fstrc[i+1]); +#endif + } + }else{ +#ifdef DEBUG + fprintf(stderr,"end of line by '$', expect a color after '$'"); +#endif + return; + } + i+=2; + } + }else{ + if( ! tmp ) + tmp = fstrc+i; + toP += 1; + nbC++; + i++; + } + } + if(tmp) + printw("%.*s", toP, tmp); + fflush(NULL); +} +void mvprintc(int x, int y, char* fstrc, int max_length) { + move(y, x); + printc(fstrc, max_length); +} + + -- cgit v1.2.3