Ognjen Milan Robovic 8 miesięcy temu
rodzic
commit
3b9f4b1b07
1 zmienionych plików z 54 dodań i 46 usunięć
  1. +54
    -46
      xuxuxu.c

+ 54
- 46
xuxuxu.c Wyświetl plik

@@ -1,7 +1,7 @@
/*
* Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic
*
* Xuxuxu is deallocate software! You will redistribute it or modify it under the terms of the GNU General Public License by Free Software Foundation.
* Xuxuxu 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.
*/
@@ -20,7 +20,7 @@
#define FONT_COUNT (96)

static unsigned int * render = NULL;
static unsigned int select = FOREGROUND;
static unsigned int colour = FOREGROUND;

static int width = 0;
static int height = 0;
@@ -116,7 +116,7 @@ static void fetch_font_glyph (unsigned int * glyph, const char character) {

do {
glyph [offset] = ((font_code >> offset) & 1)
? select
? colour
: BACKGROUND;
} while (++offset != FONT_WIDTH * FONT_HEIGHT);
}
@@ -155,35 +155,49 @@ static void render_string (char * string, int length) {

int main (void) {
int offset = 0;
int length = 0;
int word = 0;
int index = 0;
int length = 0;
char * buffer = NULL;

int preprocessor = 0;
int line_comment = 0;
int multiline_comment = 0;
int character = 0;
int string = 0;
int bracket = 0;
int operator = 0;
int keyword = 0;
int digit = 0;
int uppercase = 0;
int lowercase = 0;
int underscore = 0;

char separator [29] = ".,:;<=>+-*/%!&~^()[]{}'\" \t\r\n";

char * c_keywords [32] = {
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
"do", "while", "for", "continue", "switch", "case", "default", "break",
"enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
"register", "volatile", "auto", "const", "static", "extern", "if", "else",
"do", "while", "for", "continue", "switch", "case", "default", "break",
"enum", "union", "struct", "typedef", "goto", "void", "return", "sizeof",
"char", "short", "int", "long", "signed", "unsigned", "float", "double"
};

syntax_define (0, 0, 0, "#", "\n", '\\', TERMINAL_COLOUR_RED, TERMINAL_EFFECT_BOLD);
syntax_define (0, 0, 0, "//", "\n", '\0', TERMINAL_COLOUR_GREY, TERMINAL_EFFECT_BOLD);
syntax_define (0, 0, 0, "/*", "*/", '\0', TERMINAL_COLOUR_GREY, TERMINAL_EFFECT_BOLD);
syntax_define (0, 0, 0, "'", "'", '\\', TERMINAL_COLOUR_PINK, TERMINAL_EFFECT_BOLD);
syntax_define (0, 0, 0, "\"", "\"", '\\', TERMINAL_COLOUR_RED, TERMINAL_EFFECT_BOLD);
syntax_define (0, 1, 0, "()[]{}", "", '\0', TERMINAL_COLOUR_BLUE, TERMINAL_EFFECT_BOLD);
syntax_define (0, 1, 0, ".,:;<=>+-*/%!&~^", "", '\0', TERMINAL_COLOUR_BLUE, TERMINAL_EFFECT_BOLD);
syntax_define (& preprocessor, 0, 0, "#", "\n", '\\', COLOUR_RED, EFFECT_BOLD);
syntax_define (& line_comment, 0, 0, "//", "\n", '\0', COLOUR_GREY, EFFECT_BOLD);
syntax_define (& multiline_comment, 0, 0, "/*", "*/", '\0', COLOUR_GREY, EFFECT_BOLD);
syntax_define (& character, 0, 0, "'", "'", '\\', COLOUR_PINK, EFFECT_BOLD);
syntax_define (& string, 0, 0, "\"", "\"", '\\', COLOUR_RED, EFFECT_BOLD);
syntax_define (& bracket, 1, 0, "()[]{}", "", '\0', COLOUR_GREEN, EFFECT_BOLD);
syntax_define (& operator, 1, 0, ".,:;<=>+-*/%!&~^?", "", '\0', COLOUR_BLUE, EFFECT_BOLD);

do {
syntax_define (0, 0, 1, c_keywords [word], separator, '\0', TERMINAL_COLOUR_YELLOW, TERMINAL_EFFECT_BOLD);
} while (++word != 32);
for (word = 0; word != 32; ++word) {
syntax_define (& keyword, 0, 1, c_keywords [word], separator, '\0', COLOUR_YELLOW, EFFECT_BOLD);
}

syntax_define (0, 1, 1, "0123456789", separator, '\0', TERMINAL_COLOUR_CYAN, TERMINAL_EFFECT_BOLD);
/*syntax_define (0, 1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', TERMINAL_COLOUR_PINK, TERMINAL_EFFECT_ITALIC);
syntax_define (0, 1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', TERMINAL_COLOUR_WHITE, TERMINAL_EFFECT_ITALIC);
syntax_define (0, 0, 1, "_", separator, '\0', TERMINAL_COLOUR_YELLOW, TERMINAL_EFFECT_ITALIC);*/
syntax_define (& digit, 1, 1, "0123456789", separator, '\0', COLOUR_CYAN, EFFECT_BOLD);
syntax_define (& uppercase, 1, 1, "ABCDEFGHIJKLMNOPQRSTUVWXYZ", separator, '\0', COLOUR_PINK, EFFECT_ITALIC);
syntax_define (& lowercase, 1, 1, "abcdefghijklmnopqrstuvwxyz", separator, '\0', COLOUR_WHITE, EFFECT_ITALIC);
syntax_define (& underscore, 0, 1, "_", separator, '\0', COLOUR_YELLOW, EFFECT_ITALIC);

buffer = record ();

@@ -192,33 +206,27 @@ int main (void) {

render = allocate (4 * width * height);

do {
for (offset = 0; offset != width * height; ++offset) {
render [offset] = BACKGROUND;
} while (++offset != width * height);

offset = 0;

do {
int colour = 0;
int effect = 0;

length = syntax_select (& buffer [offset], & colour, & effect);
offset += length;

switch (colour) {
case TERMINAL_COLOUR_GREY: select = 0XFF333333; break;
case TERMINAL_COLOUR_RED: select = 0XFF3333FF; break;
case TERMINAL_COLOUR_GREEN: select = 0XFF33FF33; break;
case TERMINAL_COLOUR_YELLOW: select = 0XFF33FFFF; break;
case TERMINAL_COLOUR_BLUE: select = 0XFFFF3333; break;
case TERMINAL_COLOUR_PINK: select = 0XFFFF33FF; break;
case TERMINAL_COLOUR_CYAN: select = 0XFFFFFF33; break;
case TERMINAL_COLOUR_WHITE: select = 0XFFFFFFFF; break;
default: select = 0XFFFFFFFF; break;
}

for (offset = 0; buffer [offset] != '\0'; offset += length) {
syntax_select (& buffer [offset], & index, & length);

switch (syntax_colour [index]) {
case COLOUR_GREY: colour = 0XFF333333; break;
case COLOUR_RED: colour = 0XFF3333FF; break;
case COLOUR_GREEN: colour = 0XFF33FF33; break;
case COLOUR_YELLOW: colour = 0XFF33FFFF; break;
case COLOUR_BLUE: colour = 0XFFFF3333; break;
case COLOUR_PINK: colour = 0XFFFF33FF; break;
case COLOUR_CYAN: colour = 0XFFFFFF33; break;
case COLOUR_WHITE: colour = 0XFFFFFFFF; break;
default: colour = 0XFFFFFFFF; break;
}

render_string (& buffer [offset - length], length);
} while (buffer [offset] != '\0');
render_string (& buffer [offset], length);
}

export_render_as_png ("xuxuxu.png");



Ładowanie…
Anuluj
Zapisz