From: Trent Huber Date: Wed, 6 Aug 2025 18:43:00 +0000 (-0400) Subject: Bug fix in main.c, src/build.c bootstraps itself X-Git-Url: https://trenthuber.com/code?a=commitdiff_plain;h=c6f680c448f544fd3ddad00987ebf65408b0b9d5;p=xpmview.git Bug fix in main.c, src/build.c bootstraps itself --- diff --git a/external/build.c b/external/build.c index 15141c5..d0eec79 100644 --- a/external/build.c +++ b/external/build.c @@ -24,19 +24,10 @@ #define RLSRC "raylib/src/" void buildcbs(void) { - char **c, **l; - - c = cflags; - l = lflags; - cflags = CLPIC; compile("cbs/cbs"); - lflags = NONE; load(LIBTYPE, "cbs/cbs", LIST("cbs/cbs")); - - cflags = c; - lflags = l; } void buildraylib(void) { diff --git a/external/cbs b/external/cbs index 4711a83..5499560 160000 --- a/external/cbs +++ b/external/cbs @@ -1 +1 @@ -Subproject commit 4711a83fafa0282fadeaba701a25539b3e73d073 +Subproject commit 5499560c6a497c72aa1bd5c5dd770795d789d4d5 diff --git a/src/.gitignore b/src/.gitignore index d605eed..96ac906 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,2 @@ colors.c font.c -buildfont diff --git a/src/build.c b/src/build.c index b7d3afd..59e3b38 100644 --- a/src/build.c +++ b/src/build.c @@ -4,7 +4,14 @@ #include "../external/cbs/cbs.c" #include "../external/cbsfile.c" -#define CLRAYLIB LIST("-I../external/raylib/src/") +#ifdef FONT +#include +#include + +#include "raylib.h" +#endif + +#define CFRAYLIB "-I../external/raylib/src/" #ifdef DYNAMICLIBS #define LIBEXT DYEXT #define LLRAYLIB NONE @@ -16,6 +23,7 @@ #define RLLIB "../external/raylib/raylib" LIBEXT #define CBSLIB "../external/cbs/cbs" LIBEXT +#ifdef FONT static void buildcolors(void) { int quit, txtfd, codefd; char *txt, *code, *p; @@ -88,28 +96,34 @@ closetxt: } static void buildfont(void) { - char **c, **l; - pid_t cpid; + char *ttf, *code; + Font font; - c = cflags; - l = lflags; + ttf = "../assets/font.ttf"; + code = "font.c"; - cflags = CLRAYLIB; - compile("buildfont"); + SetTraceLogLevel(LOG_WARNING); + InitWindow(0, 0, ""); - lflags = LLRAYLIB; - load('x', "buildfont", LIST("buildfont", RLLIB)); - - if ((cpid = fork()) == -1) err(EXIT_FAILURE, "Unable to fork"); - else if (cpid == 0) run("buildfont", LIST("buildfont"), "run", "buildfont"); - await(cpid, "run", "buildfont"); + if (!ExportFontAsCode(font = LoadFontEx(ttf, 48, NULL, 95), code)) + errx(EXIT_FAILURE, "Unable to generate `%s' from `%s'", code, ttf); - cflags = c; - lflags = l; + UnloadFont(font); } +#endif int main(void) { - build("./"); +#ifndef FONT + cflags = LIST("-DFONT", CFRAYLIB); + compile("build"); + + lflags = LLRAYLIB; + load('x', "build", LIST("build", RLLIB)); + + run("!build", LIST("build"), "run", "build"); +#else + compile("build"); + load('x', "build", LIST("build")); buildcolors(); buildfont(); @@ -117,14 +131,15 @@ int main(void) { buildfiles((struct cbsfile []){{"../bin/simplexpm", LLRAYLIB, 'x'}, {"colors", NONE}, - {"main", CLRAYLIB}, + {"main", LIST(CFRAYLIB)}, {"options", NONE}, - {"xpm", CLRAYLIB}, + {"xpm", LIST(CFRAYLIB)}, {CBSLIB}, {RLLIB}, {NULL}}); +#endif return EXIT_SUCCESS; } diff --git a/src/buildfont.c b/src/buildfont.c deleted file mode 100644 index a123e51..0000000 --- a/src/buildfont.c +++ /dev/null @@ -1,22 +0,0 @@ -#include -#include - -#include "raylib.h" - -int main(void) { - char *ttf, *code; - Font font; - - ttf = "../assets/font.ttf"; - code = "font.c"; - - SetTraceLogLevel(LOG_WARNING); - InitWindow(0, 0, ""); - - if (!ExportFontAsCode(font = LoadFontEx(ttf, 48, NULL, 95), code)) - errx(EXIT_FAILURE, "Unable to generate `%s' from `%s'", code, ttf); - - UnloadFont(font); - - return EXIT_SUCCESS; -} diff --git a/src/main.c b/src/main.c index 17173e7..e649fb7 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,7 @@ static void handleinput(void) { if (IsFileDropped()) { files = LoadDroppedFiles(); - if (xpm) RL_FREE(xpm); + if (xpm) free(xpm); xpm = allocate(FILENAME_MAX); strcpy(xpm, files.paths[0]); UnloadDroppedFiles(files); @@ -104,8 +104,7 @@ int main(int argc, char **argv) { } if (xpm) free(xpm); - - UnloadTexture(*texture); + if (texture) UnloadTexture(*texture); CloseWindow(); return EXIT_SUCCESS;