diff --git a/xtandard.c b/xtandard.c index 15deb1d..844199b 100644 --- a/xtandard.c +++ b/xtandard.c @@ -6,6 +6,7 @@ #include #include #include +#include static char * log_notify = null; @@ -818,4 +819,47 @@ char * format_to_string (int number, int sign, int base, int amount, char charac return (string); } +void print (char * format, ...) { + va_list list; + + va_start (list, format); + + for (; * format != character_null; ++format) { + switch (* format) { + case '%': { + int integer; + char * string; + ++format; + switch (* format) { + case '%': out ("%", 1); break; + case 'i': integer = va_arg (list, int); string = number_to_string (integer); out (string, string_length (string)); break; + case 's': string = va_arg (list, char *); out (string, string_length (string)); break; + default: out ("?", 1); break; + } + } break; + case '/': { + ++format; + switch (* format) { + case '/': out ("/", 1); break; + case '0': terminal_colour (colour_grey, effect_bold); break; + case '1': terminal_colour (colour_red, effect_bold); break; + case '2': terminal_colour (colour_green, effect_bold); break; + case '3': terminal_colour (colour_yellow, effect_bold); break; + case '4': terminal_colour (colour_blue, effect_bold); break; + case '5': terminal_colour (colour_pink, effect_bold); break; + case '6': terminal_colour (colour_cyan, effect_bold); break; + case '7': terminal_colour (colour_white, effect_bold); break; + case '-': terminal_cancel (); break; + default: out ("?", 1); break; + } + } break; + default: { + out (format, 1); + } break; + } + } + + va_end (list); +} + #endif diff --git a/xtandard.h b/xtandard.h index a1b8e95..9f2c0fa 100644 --- a/xtandard.h +++ b/xtandard.h @@ -158,4 +158,6 @@ extern char * number_to_string (int number); extern char * format_to_string (int number, int sign, int base, int amount, char character); +extern void print (char * format, ...); + #endif