93 lines
2.5 KiB
C
93 lines
2.5 KiB
C
/*
|
|
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"
|
|
|
|
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;
|
|
}
|
|
}
|
|
|
|
void print (char * format, ...) {
|
|
va_list argument_list;
|
|
|
|
int offset, length;
|
|
|
|
length = string_length (format);
|
|
|
|
va_start (argument_list, format);
|
|
|
|
for (offset = 0; offset != length; ++offset) {
|
|
if (format [offset] == '/') {
|
|
++offset;
|
|
print_colour (format [offset]);
|
|
} else if (format [offset] == '%') {
|
|
++offset;
|
|
print_format (format [offset], argument_list);
|
|
} else {
|
|
out (& format [offset], 1);
|
|
}
|
|
}
|
|
|
|
va_end (argument_list);
|
|
}
|
|
|
|
void file_print (int file, char * format, ...) {
|
|
(void) file;
|
|
(void) format;
|
|
return;
|
|
}
|
|
|
|
void string_print (char * string, char * format, ...) {
|
|
(void) string;
|
|
(void) format;
|
|
return;
|
|
}
|
|
|
|
#endif
|