/* * 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); }