131 lines
6.2 KiB
C
Executable File
131 lines
6.2 KiB
C
Executable File
#include <xolatile/xtandard.h>
|
|
#include <xolatile/xyntax.h>
|
|
#include <xolatile/xormat/png.h>
|
|
|
|
#define foreground (0xffccccccu)
|
|
#define background (0xff181818u)
|
|
|
|
#define font_indent ( 8)
|
|
#define font_width ( 8)
|
|
#define font_height ( 8)
|
|
#define font_count (96)
|
|
|
|
static natural * render = null;
|
|
static natural colour = foreground;
|
|
|
|
static natural width = 0;
|
|
static natural height = 0;
|
|
static natural x = 0;
|
|
static natural y = 0;
|
|
|
|
static procedure render_character (character character) {
|
|
natural_64 font_code [font_count] = {
|
|
0x0000000000000000, 0x00180018183c3c18, 0x0000000000363636, 0x006c6cfe6cfe6c6c,
|
|
0x00187ed07c16fc30, 0x0060660c18306606, 0x00dc66b61c36361c, 0x0000000000181818,
|
|
0x0030180c0c0c1830, 0x000c18303030180c, 0x0000187e3c7e1800, 0x000018187e181800,
|
|
0x0c18180000000000, 0x000000007e000000, 0x0018180000000000, 0x0000060c18306000,
|
|
0x003c666e7e76663c, 0x007e181818181c18, 0x007e0c183060663c, 0x003c66603860663c,
|
|
0x0030307e363c3830, 0x003c6660603e067e, 0x003c66663e060c38, 0x000c0c0c1830607e,
|
|
0x003c66663c66663c, 0x001c30607c66663c, 0x0018180018180000, 0x0c18180018180000,
|
|
0x0030180c060c1830, 0x0000007e007e0000, 0x000c18306030180c, 0x001800181830663c,
|
|
0x003c06765676663c, 0x006666667e66663c, 0x003e66663e66663e, 0x003c66060606663c,
|
|
0x001e36666666361e, 0x007e06063e06067e, 0x000606063e06067e, 0x003c66667606663c,
|
|
0x006666667e666666, 0x007e18181818187e, 0x001c36303030307c, 0x0066361e0e1e3666,
|
|
0x007e060606060606, 0x00c6c6d6d6feeec6, 0x006666767e6e6666, 0x003c66666666663c,
|
|
0x000606063e66663e, 0x006c36566666663c, 0x006666363e66663e, 0x003c66603c06663c,
|
|
0x001818181818187e, 0x003c666666666666, 0x00183c6666666666, 0x00c6eefed6d6c6c6,
|
|
0x0066663c183c6666, 0x001818183c666666, 0x007e060c1830607e, 0x003e06060606063e,
|
|
0x00006030180c0600, 0x007c60606060607c, 0x000000000000663c, 0xffff000000000000,
|
|
0x000000000030180c, 0x007c667c603c0000, 0x003e6666663e0606, 0x003c6606663c0000,
|
|
0x007c6666667c6060, 0x003c067e663c0000, 0x000c0c0c3e0c0c38, 0x3c607c66667c0000,
|
|
0x00666666663e0606, 0x003c1818181c0018, 0x0e181818181c0018, 0x0066361e36660606,
|
|
0x003c18181818181c, 0x00c6d6d6fe6c0000, 0x00666666663e0000, 0x003c6666663c0000,
|
|
0x06063e66663e0000, 0xe0607c66667c0000, 0x000606066e360000, 0x003e603c067c0000,
|
|
0x00380c0c0c3e0c0c, 0x007c666666660000, 0x00183c6666660000, 0x006cfed6d6c60000,
|
|
0x00663c183c660000, 0x3c607c6666660000, 0x007e0c18307e0000, 0x003018180e181830,
|
|
0x0018181818181818, 0x000c18187018180c, 0x000000000062d68c, 0x0000000000000000
|
|
};
|
|
|
|
for (natural offset = 0; offset < font_width * font_height; ++offset) {
|
|
natural u = offset / font_width + y;
|
|
natural v = offset % font_width + x;
|
|
|
|
render [u * width + v] = ((font_code [(natural) (character - ' ')] >> offset) % 2) ? colour : background;
|
|
}
|
|
|
|
x += font_width + 1;
|
|
}
|
|
|
|
static procedure render_string (character * string, natural length) {
|
|
for (natural offset = 0; offset < length; ++offset) {
|
|
if (string [offset] == '\t') {
|
|
x += font_width * font_indent;
|
|
} else if (string [offset] == '\n') {
|
|
y += font_height + 1;
|
|
x = 1;
|
|
} else {
|
|
render_character (string [offset]);
|
|
}
|
|
}
|
|
}
|
|
|
|
integer main (none) {
|
|
natural index = 0;
|
|
natural length = 0;
|
|
character * buffer = null;
|
|
|
|
character separator [] = ".,:;<=>+-*/%!&~^()[]{}'\" \t\r\n";
|
|
|
|
character * keywords [] = {
|
|
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
|
|
"do", "while", "for", "continue", "switch", "case", "default", "break",
|
|
"enum", "union", "struct", "typedef", "goto", "v0", "return", "sizeof",
|
|
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
|
|
};
|
|
|
|
syntax_structure * syntax = syntax_initialize (0);
|
|
|
|
syntax_define (syntax, false, false, "#", "\n", '\\', 0xff3377aa, 0);
|
|
syntax_define (syntax, false, false, "//", "\n", '\0', 0xff777777, 0);
|
|
syntax_define (syntax, false, false, "/*", "*/", '\0', 0xff777777, 0);
|
|
syntax_define (syntax, false, false, "'", "'", '\\', 0xff9933cc, 0);
|
|
syntax_define (syntax, false, false, "\"", "\"", '\\', 0xffcc3399, 0);
|
|
syntax_define (syntax, true, false, ".,:;<=>+-*/%!&~^?|", "", '\0', 0xffccaa33, 0);
|
|
syntax_define (syntax, true, false, "(){}[]", "", '\0', 0xffcc3333, 0);
|
|
|
|
for (natural_64 word = 0; word < array_length (keywords); ++word) {
|
|
syntax_define (syntax, false, true, keywords [word], separator, '\0', 0xff33aacc, 0);
|
|
}
|
|
|
|
syntax_define (syntax, true, true, "0123456789", separator, '\0', 0xffcc77cc, 0);
|
|
syntax_define (syntax, true, true, "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz_", separator, '\0', 0xffcccccc, 0);
|
|
|
|
buffer = record ();
|
|
|
|
width = string_full_width (buffer, font_indent) * (font_width + 1) + 1;
|
|
height = string_full_height (buffer) * (font_height + 1) + 1;
|
|
|
|
render = allocate (4 * width * height);
|
|
|
|
for (natural offset = 0; offset < width * height; ++offset) {
|
|
render [offset] = background;
|
|
}
|
|
|
|
for (natural offset = 0; buffer [offset] != '\0'; offset += length) {
|
|
index = syntax_select (syntax, & buffer [offset], & length);
|
|
|
|
colour = syntax->colour [index];
|
|
|
|
render_string (& buffer [offset], length);
|
|
}
|
|
|
|
png_image_export ("xuxuxu.png", render, width, height);
|
|
|
|
syntax = syntax_deinitialize (syntax);
|
|
|
|
buffer = deallocate (buffer);
|
|
render = deallocate (render);
|
|
|
|
return (log_success);
|
|
}
|