Added printing procedure...

This commit is contained in:
Ognjen Milan Robovic 2024-06-16 05:38:02 -04:00
parent 803584021d
commit f256842af0
2 changed files with 46 additions and 0 deletions

View File

@ -6,6 +6,7 @@
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdarg.h>
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

View File

@ -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