2023-11-12 07:19:44 -05:00
|
|
|
/*
|
|
|
|
Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
|
|
|
|
|
|
|
|
Xhartae is free software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
|
|
|
|
And when you do redistribute it or modify it, it will use either version 3 of the License, or (at yours truly opinion) any later version.
|
|
|
|
It is distributed in the hope that it will be useful or harmful, it really depends... But no warranty what so ever, seriously. See GNU/GPLv3.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef CHAPTER_3_SOURCE
|
|
|
|
#define CHAPTER_3_SOURCE
|
|
|
|
|
|
|
|
#include "chapter_3.h"
|
|
|
|
|
2023-11-12 20:58:41 -05:00
|
|
|
static void print_colour (char colour_id) {
|
|
|
|
switch (colour_id) {
|
|
|
|
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_colour (COLOUR_WHITE, EFFECT_NORMAL); break;
|
|
|
|
default: terminal_colour (COLOUR_WHITE, EFFECT_NORMAL); break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void print_format (char format_id, va_list argument_list) {
|
|
|
|
switch (format_id) {
|
|
|
|
case '%': {
|
|
|
|
out ("%", 1);
|
|
|
|
} break;
|
|
|
|
case 'i': {
|
|
|
|
int integer;
|
|
|
|
integer = va_arg (argument_list, int);
|
|
|
|
echo (number_to_string (integer));
|
|
|
|
} break;
|
|
|
|
case 'f': {
|
|
|
|
double ieee754;
|
|
|
|
ieee754 = va_arg (argument_list, double);
|
|
|
|
echo (number_to_string ((int) ieee754));
|
|
|
|
} break;
|
|
|
|
case 's': {
|
|
|
|
char * string;
|
|
|
|
string = va_arg (argument_list, char *);
|
|
|
|
echo (string);
|
|
|
|
} break;
|
|
|
|
default: {
|
|
|
|
out ("?", 1);
|
|
|
|
} break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-12 07:19:44 -05:00
|
|
|
void print (char * format, ...) {
|
2023-11-12 20:58:41 -05:00
|
|
|
va_list argument_list;
|
2023-11-12 07:19:44 -05:00
|
|
|
|
|
|
|
int offset, length;
|
|
|
|
|
|
|
|
length = string_length (format);
|
|
|
|
|
2023-11-12 20:58:41 -05:00
|
|
|
va_start (argument_list, format);
|
2023-11-12 07:19:44 -05:00
|
|
|
|
|
|
|
for (offset = 0; offset != length; ++offset) {
|
2023-11-12 20:58:41 -05:00
|
|
|
if (format [offset] == '/') {
|
2023-11-12 07:19:44 -05:00
|
|
|
++offset;
|
2023-11-12 20:58:41 -05:00
|
|
|
print_colour (format [offset]);
|
|
|
|
} else if (format [offset] == '%') {
|
2023-11-12 07:19:44 -05:00
|
|
|
++offset;
|
2023-11-12 20:58:41 -05:00
|
|
|
print_format (format [offset], argument_list);
|
2023-11-12 07:19:44 -05:00
|
|
|
} else {
|
|
|
|
out (& format [offset], 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-12 20:58:41 -05:00
|
|
|
va_end (argument_list);
|
2023-11-12 07:19:44 -05:00
|
|
|
}
|
|
|
|
|
2023-11-12 20:58:41 -05:00
|
|
|
void file_print (int file, char * format, ...) {
|
|
|
|
(void) file;
|
2023-11-12 07:19:44 -05:00
|
|
|
(void) format;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-11-12 20:58:41 -05:00
|
|
|
void string_print (char * string, char * format, ...) {
|
|
|
|
(void) string;
|
2023-11-12 07:19:44 -05:00
|
|
|
(void) format;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|