xhartae/program/program_1.c

128 lines
6.9 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.
*/
#include "../chapter/chapter_0.c"
#include "../chapter/chapter_1.c"
static void echo_separator (void) {
terminal_colour (COLOUR_GREY, EFFECT_BOLD);
echo (" | ");
terminal_cancel ();
}
static void echo_base (int character, int base, int colour, int effect) {
echo_separator ();
terminal_colour (colour, effect);
if (base == 2) {
echo (format_to_string (character, 0, base, 7, '0'));
} else if (base == 8) {
echo (format_to_string (character, 0, base, 3, '0'));
} else if (base == 16) {
echo (format_to_string (character, 0, base, 2, '0'));
} else {
echo (format_to_string (character, 0, base, 3, ' '));
}
terminal_cancel ();
}
static void echo_code (int character, int colour, int effect) {
char * code [32] = {
"NUL", "SOH", "STX", "ETX", "EOT", "ENQ", "ACK", "BEL", "BS", "HT", "LF", "VT", "FF", "CR", "SO", "SI",
"DLE", "DC1", "DC2", "DC3", "DC4", "NAK", "SYN", "ETB", "CAN", "EM", "SUB", "ESC", "FS", "GS", "RS", "US"
};
echo_separator ();
terminal_colour (colour, effect);
if (character == 0X7F) {
echo ("DEL");
} else if (character_is_invisible (character) != 0) {
echo (code [character]);
if (string_length (code [character]) == 2) {
echo (" ");
}
} else {
out (& character, 1);
echo (" ");
}
terminal_cancel ();
}
static void echo_name (int character, int colour, int effect) {
char * name [128] = {
"Null", "Start of heading", "Start of text", "End of text",
"End of transmission", "Enquiry", "Acknowledge", "Bell",
"Backspace", "Horizontal tab", "Line feed", "Vertical tab",
"Form feed", "Carriage return", "Shift out", "Shift in",
"Data link escape", "Device control 1", "Device control 2", "Device control 3",
"Device control 4", "Negative acknowledge", "Synchronous idle", "End transmission block",
"Cancel", "End of medium", "Substitute", "Escape",
"File separator", "Group separator", "Record separator", "Unit separator",
"Space", "Exclamation mark", "Speech mark", "Number sign",
"Dollar sign", "Percent", "Ampersand", "Quote",
"Open parenthesis", "Close parenthesis", "Asterisk", "Plus",
"Comma", "Minus", "Period", "Slash",
"Zero", "One", "Two", "Three",
"Four", "Five", "Six", "Seven",
"Eight", "Nine", "Colon", "Semicolon",
"Open angled bracket", "Equal", "Close angled bracket", "Question mark",
"At sign", "Uppercase A", "Uppercase B", "Uppercase C",
"Uppercase D", "Uppercase E", "Uppercase F", "Uppercase G",
"Uppercase H", "Uppercase I", "Uppercase J", "Uppercase K",
"Uppercase L", "Uppercase M", "Uppercase N", "Uppercase O",
"Uppercase P", "Uppercase Q", "Uppercase R", "Uppercase S",
"Uppercase T", "Uppercase U", "Uppercase V", "Uppercase W",
"Uppercase X", "Uppercase Y", "Uppercase Z", "Opening bracket",
"Backslash", "Closing bracket", "Caret", "Underscore",
"Grave", "Lowercase a", "Lowercase b", "Lowercase c",
"Lowercase d", "Lowercase e", "Lowercase f", "Lowercase g",
"Lowercase h", "Lowercase i", "Lowercase j", "Lowercase k",
"Lowercase l", "Lowercase m", "Lowercase n", "Lowercase o",
"Lowercase p", "Lowercase q", "Lowercase r", "Lowercase s",
"Lowercase t", "Lowercase u", "Lowercase v", "Lowercase w",
"Lowercase x", "Lowercase y", "Lowercase z", "Opening brace",
"Vertical bar", "Closing brace", "Tilde", "Delete"
};
echo_separator ();
terminal_colour (colour, effect);
echo (name [character]);
out (" ", 40 - string_length (name [character]));
terminal_cancel ();
}
int main (void) {
int character;
for (character = 0; character != 128; ++character) {
echo_base (character, 2, COLOUR_BLUE, EFFECT_NORMAL);
echo_base (character, 8, COLOUR_CYAN, EFFECT_NORMAL);
echo_base (character, 10, COLOUR_CYAN, EFFECT_ITALIC);
echo_base (character, 16, COLOUR_CYAN, EFFECT_BOLD);
echo_code (character, COLOUR_PINK, EFFECT_BOLD);
echo_name (character, COLOUR_WHITE, EFFECT_NORMAL);
if ((character % 2) != 0) {
echo ("\n");
}
}
return (EXIT_SUCCESS);
}