From 76b9ae922f4d8aac0033b88da240b5c75f16cdd3 Mon Sep 17 00:00:00 2001 From: Aaron Taylor Date: Mon, 15 Mar 2021 08:39:05 -0700 Subject: [PATCH] Misc 'catchup' commit on WolframAutomata.c. --- hacks/WolframAutomata/WolframAutomata.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/hacks/WolframAutomata/WolframAutomata.c b/hacks/WolframAutomata/WolframAutomata.c index faab86b..59562b3 100644 --- a/hacks/WolframAutomata/WolframAutomata.c +++ b/hacks/WolframAutomata/WolframAutomata.c @@ -10,8 +10,10 @@ /* TODO: I suppose a lot of this stuff goes in the README instead. */ /* TODO: Explain the data structures in detail. */ /* TODO: Explain all the options, like the various starting conditions. */ +/* TODO: Explain all the dependencies like libXpm. */ +/* TODO: Add a #define for the hack version. */ /* TODO: Check manpage for all functions I use and ensure my includes are correct. I don't want to depend on picking up includes via screenhack.h. */ /* TODO: Verify everything in this file is C89. Get rid of things like '//' comments, pack all my declarations upfront, no stdint, etc. */ @@ -33,9 +35,13 @@ // Command line options // directory to output XBM files of each run (and call an external command to convert to PNGs?) // -save-dir STRING +// (could use libXpm to save an XPM and then convert to PNG with ImageMagick) (this is a single function call to go from pixmap -> file) +// (since it depends on an external library, make this whole feature optional at build-time?) // number of generations to simulate +// -random-generations // -num-generations N // delay time (speed of simulation) +// -random-delay // -delay-usec N // foreground and background color // -random-colors (highest precedence) @@ -57,6 +63,7 @@ // (the two options above only apply to the simulation under the -rule-random or -rule N options. in curated mode, starting population is defined in the curation array) // TODO: In the future, add the option for user to pass list of cell IDs to turn ON. // size of pixel square (e.g. 1x1, 2x2, 3x3, etc) +// -random-pixel-size // -pixel-size N /* -------------------------------------------------------------------------- */ @@ -231,7 +238,12 @@ render_current_generation(struct state * state) static void * WolframAutomata_init(Display * dpy, Window win) { - struct state * state = calloc(1, sizeof(*state)); // TODO: Check calloc() call + struct state * state = calloc(1, sizeof(*state)); + if (!state) { + fprintf(stderr, "ERROR: Failed to calloc() for state struct in WolframAutomata_init().\n"); + exit(EXIT_FAILURE); + } + XGCValues gcv; XWindowAttributes xgwa; const struct curated_ruleset * curated_ruleset = NULL; @@ -302,7 +314,7 @@ WolframAutomata_init(Display * dpy, Window win) if (state->population_density < 0 || state->population_density > 100) state->population_density = 50; state->current_generation = calloc(1, sizeof(*state->current_generation)*state->number_of_cells); if (!state->current_generation) { - fprintf(stderr, "ERROR: Failed to calloc() in WolframAutomata_init().\n"); + fprintf(stderr, "ERROR: Failed to calloc() for cell generation in WolframAutomata_init().\n"); exit(EXIT_FAILURE); } if (curated_ruleset) { -- 2.20.1