]> Trent Huber's Code - xpmview.git/commitdiff
Cleaning up
authorTrent Huber <trentmhuber@gmail.com>
Tue, 15 Oct 2024 03:50:12 +0000 (23:50 -0400)
committerTrent Huber <trentmhuber@gmail.com>
Tue, 15 Oct 2024 03:50:12 +0000 (23:50 -0400)
 - Removed stb_image_writer dependency (included in Raylib)
 - Compartmentalized translation units ("const" and "static")

.gitmodules
external/cbs.c
external/stb [deleted submodule]
src/main.c
src/parser.c
src/tokenizer.c
src/tokenizer.h
src/xpm_mode.c
src/xpm_mode.h

index 14aea5dc22b4ebb4f989ce20351eaef0194f8100..5daa9e9431533e19f9825080bdd5be03aa95dd49 100644 (file)
@@ -4,6 +4,3 @@
 [submodule "external/raylib"]
    path = external/raylib
    url = git@github.com:raysan5/raylib.git
-[submodule "external/stb"]
-   path = external/stb
-   url = git@github.com:nothings/stb.git
index d68d408fba0c4744900d5d3af65efdcd9953e3b9..70c49cc555591adee15a16d17306105d7b2f1c03 100644 (file)
@@ -4,7 +4,10 @@
 
 #define CC "cc"
 
-void build_raylib(void) {
+int main(int argc, char **argv) {
+   cbs_rebuild_self(argv);
+   cbs_shift_args(&argc, &argv);
+
    const char *raylib_src_dir = "./raylib/src";
    Cbs_File_Paths raylib_src_files = {0}, raylib_obj_files = {0};
    cbs_file_paths_build_file_ext(&raylib_src_files, raylib_src_dir, ".c");
@@ -33,18 +36,6 @@ void build_raylib(void) {
        cbs_cmd_build_file_paths(&cmd, raylib_obj_files);
        cbs_cmd_run(&cmd);
    }
-}
-
-void build_stbi_image_write(void) {
-
-}
-
-int main(int argc, char **argv) {
-   cbs_rebuild_self(argv);
-   cbs_shift_args(&argc, &argv);
-
-   build_raylib();
-   build_stbi_image_write();
 
    return 0;
 }
diff --git a/external/stb b/external/stb
deleted file mode 160000 (submodule)
index f75e8d1..0000000
+++ /dev/null
@@ -1 +0,0 @@
-Subproject commit f75e8d1cad7d90d72ef7a4661f1b994ef78b4e31
index d826cd4c666189e687b6c865a3d65d13d92c48d9..212b36354e5c974fbe9d5e741e72924c223a33ea 100644 (file)
@@ -7,14 +7,18 @@
 #include "raylib.h"
 #include "utils.h"
 
+#define DEFAULT_SCREEN_WIDTH 800
+#define DEFAULT_SCREEN_HEIGHT 600
 #define FILE_PATH_CAP 2048
 #define FONT_SIZE 48
 
-Image image;
-Texture2D texture;
-bool have_texture;
+// TODO: Improve error messages
 
-void create_texture_from_xpm_file(char *xpm_file_path) {
+static Image image;
+static Texture2D texture;
+static bool have_texture;
+
+static void create_texture_from_xpm_file(const char *xpm_file_path) {
    if (!parse_xpm_file(&image, xpm_file_path))
        have_texture = false;
    else {
@@ -27,16 +31,13 @@ void create_texture_from_xpm_file(char *xpm_file_path) {
 int main(int argc, char **argv) {
    char xpm_file_path[FILE_PATH_CAP] = {0};
 
-   // Check if a file was given on the command line
    if (argc >= 2) {
-       strncpy(xpm_file_path, argv[2], FILE_PATH_CAP);
+       strncpy(xpm_file_path, argv[1], FILE_PATH_CAP);
        create_texture_from_xpm_file(xpm_file_path);
    }
 
-   int default_screen_width = 800;
-   int default_screen_height = 600;
    SetTraceLogLevel(LOG_WARNING);
-   InitWindow(default_screen_width, default_screen_height, "simplexpm");
+   InitWindow(DEFAULT_SCREEN_WIDTH, DEFAULT_SCREEN_HEIGHT, "simplexpm");
    SetWindowState(FLAG_WINDOW_RESIZABLE);
 
    Font font = LoadFontEx("./fonts/Comic_Sans_MS.ttf", FONT_SIZE, NULL, 0);
index ecabf1ec3c4d5ebed6f14b34508f0d00db661278..831df1bf4ebf2bcc4cf7ec3161f78db61a8ed77c 100644 (file)
@@ -115,10 +115,10 @@ bool parse_xpm_file(Image *image, const char *file_path) {
                size_t hex_value = convert_token_to_num(++color_str, 16);
                if (hex_value> 0xffffff)
                    SIMPLE_XPM_ERROR("Hex #%s is not a valid color value", color_str);
-               size_t r = (hex_value & 0x00ff0000) >> (2 * 8);
-               size_t g = (hex_value & 0x0000ff00);
-               size_t b = (hex_value & 0x000000ff) << (2 * 8);
-               size_t a = 0xff000000;
+               size_t r = (hex_value & 0x00ff0000) >> (2 * 8),
+                      g = (hex_value & 0x0000ff00),
+                      b = (hex_value & 0x000000ff) << (2 * 8),
+                      a = 0xff000000;
                color = r | g | b | a;
                break;
            case '%':; // HSV
index c9528f7235bd60dff6f2d7204cb95544d50ab06e..3df6491ce5f66f680a0a44f00be081f2f40ef86d 100644 (file)
@@ -3,7 +3,6 @@
 #include <string.h>
 #include <sys/errno.h>
 
-#include "raylib.h"
 #include "utils.h"
 
 // TODO: Ignore comments
@@ -18,7 +17,7 @@ int get_next_line(char **buffer, FILE *file) {
    return 1;
 }
 
-void check_next_token(char **string, char *token) {
+void check_next_token(char **string, const char *token) {
    size_t token_len = strlen(token);
    if (strncmp(strstrip(string), token, token_len) != 0)
        SIMPLE_XPM_ERROR("Unable to parse provided file: expected token \"%s\"", token);
@@ -67,7 +66,7 @@ defer:
    return result;
 }
 
-size_t convert_token_to_num(char *token, int base) {
+size_t convert_token_to_num(const char *token, int base) {
    if (token == NULL)
        SIMPLE_XPM_ERROR("Expected non-null token to parse");
    errno = 0;
index 5e0893a05043f00f887cc282312fbb6f0e39691c..cf9e5b3759d9e53206fa25cf0e4f3240ad7d503e 100644 (file)
@@ -5,9 +5,9 @@
 #include <stdio.h>
 
 int get_next_line(char **buffer, FILE *file);
-void check_next_token(char **string, char *token);
+void check_next_token(char **string, const char *token);
 char *get_next_token(char **string);
 bool get_terminal_token(char **string, char **token);
-size_t convert_token_to_num(char *token, int base);
+size_t convert_token_to_num(const char *token, int base);
 
 #endif // _TOKENIZER_H_
index 812be3b0713eb95fb17606c7466481f8ddda8fa4..b1d90cc94426e5716cbb8ea111d010d6ddccb0b1 100644 (file)
@@ -3,7 +3,7 @@
 #include "xpm_mode.h"
 #include "utils.h"
 
-Xpm_Mode convert_token_to_mode(char *token) {
+Xpm_Mode convert_token_to_mode(const char *token) {
    if (strcmp(token, "m") == 0) return XPM_MODE_MONO;
    if (strcmp(token, "s") == 0) return XPM_MODE_SYMBOLIC;
    if (strcmp(token, "g4") == 0) return XPM_MODE_GRAYSCALE_4;
index 3dc0e98a29b651089f0e396aecc0f6dd1ae8a502..4a72233b5cdfe60bab4b756b98362e121364d5fc 100644 (file)
@@ -10,6 +10,6 @@ typedef enum {
    NUM_XPM_MODES,
 } Xpm_Mode;
 
-Xpm_Mode convert_token_to_mode(char *token);
+Xpm_Mode convert_token_to_mode(const char *token);
 
 #endif // _XPM_MODE_H_