diff --git a/compile.sh b/compile.sh new file mode 100644 index 0000000..069c6cf --- /dev/null +++ b/compile.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -xe + +gcc -g -ansi -Wall -Wextra -Wpedantic -Werror -o xode xode.c + +exit diff --git a/install.sh b/install.sh new file mode 100644 index 0000000..cfa6fdd --- /dev/null +++ b/install.sh @@ -0,0 +1,7 @@ +#!/bin/bash + +set -xe + +cp xode /usr/bin/xode + +exit diff --git a/xode.c b/xode.c new file mode 100644 index 0000000..5352f21 --- /dev/null +++ b/xode.c @@ -0,0 +1,81 @@ +/* + * Copyright (c) 2023 : Ognjen 'xolatile' Milan Robovic + * + * Xode 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 +#include + +/* +! Comment line... +[ 0F 05 ] +" World " +' 3.141 ' + label ! set +( label ) ! get +*/ + +static char * preprocess (char * source, char * buffer) { + int offset_0 = 0; + int offset_1 = 0; + + buffer = allocate (string_length (source)); + + do { + if (source [offset_0] == '!') { + do { + ++offset_0; + } while (source [offset_0] != '\n'); + } + if (character_is_blank (source [offset_0]) == 0) { + buffer [offset_1] = source [offset_0]; + ++offset_1; + } + ++offset_0; + } while (source [offset_0] != '\0'); + + buffer [offset_1] = '\0'; + + return (buffer); +} + +int main (int argc, char * * argv) { + int offset = 0; + char * input = NULL; + char * buffer = NULL; + int output = -1; + + if (argc != 3) { + fatal_failure (1, "xompile: xode input output"); + } + + input = file_import (argv [1]); + + output = open (argv [2], O_RDWR); + + buffer = preprocess (input, buffer); + + do { + if (buffer [offset] == '[') { + ++offset; + do { + int byte = encode_byte (& buffer [offset]); + file_write (output, & byte, 1); + ++offset; + ++offset; + } while (buffer [offset] != ']'); + } + + ++offset; + } while (buffer [offset] != '\0'); + + output = file_close (output); + + buffer = deallocate (buffer); + input = deallocate (input); + + return (EXIT_SUCCESS); +}