From fb8fb378dcce0564085eb6222053a0db57eb480c Mon Sep 17 00:00:00 2001 From: Tavian Barnes Date: Wed, 16 Dec 2009 19:25:11 -0500 Subject: Accept width and height command-line arguments. --- dimension/main.c | 34 +++++++++++++++++++++++++++++++++- dimension/realize.c | 7 ------- 2 files changed, 33 insertions(+), 8 deletions(-) (limited to 'dimension') diff --git a/dimension/main.c b/dimension/main.c index a0fa35c..e8b0d22 100644 --- a/dimension/main.c +++ b/dimension/main.c @@ -27,6 +27,7 @@ #include static const char *output = NULL, *input = NULL; +static unsigned int width = 640, height = 480; static int tokenize = 0, parse = 0; int @@ -38,6 +39,8 @@ main(int argc, char **argv) { static struct option long_options[] = { { "output", required_argument, NULL, 'o' }, { "input", required_argument, NULL, 'i' }, + { "width", required_argument, NULL, 'w' }, + { "height", required_argument, NULL, 'h' }, { "tokenize", no_argument, &tokenize, 1 }, { "parse", no_argument, &parse, 1 }, { 0, 0, 0, 0 } @@ -45,7 +48,7 @@ main(int argc, char **argv) { int opt, opt_index; while (1) { - opt = getopt_long(argc, argv, "o:i:", long_options, &opt_index); + opt = getopt_long(argc, argv, "o:i:w:h:", long_options, &opt_index); if (opt == -1) break; @@ -73,6 +76,27 @@ main(int argc, char **argv) { } break; + case 'w': + { + char *endptr; + width = strtoul(optarg, &endptr, 10); + if (*endptr != '\0' || endptr == optarg) { + fprintf(stderr, "Invalid argument to --width!\n"); + return EXIT_FAILURE; + } + break; + } + case 'h': + { + char *endptr; + height = strtoul(optarg, &endptr, 10); + if (*endptr != '\0' || endptr == optarg) { + fprintf(stderr, "Invalid argument to --height!\n"); + return EXIT_FAILURE; + } + break; + } + default: fprintf(stderr, "Invalid command line option!\n"); return EXIT_FAILURE; @@ -166,6 +190,14 @@ main(int argc, char **argv) { } dmnsn_delete_astree(astree); + /* Allocate a canvas */ + scene->canvas = dmnsn_new_canvas(width, height); + if (!scene->canvas) { + dmnsn_delete_scene(scene); + fprintf(stderr, "Couldn't allocate canvas!\n"); + return EXIT_FAILURE; + } + /* * Now we render the scene */ diff --git a/dimension/realize.c b/dimension/realize.c index d030a76..1a42be9 100644 --- a/dimension/realize.c +++ b/dimension/realize.c @@ -555,13 +555,6 @@ dmnsn_realize(const dmnsn_array *astree) /* Background color */ scene->background = dmnsn_black; - /* Allocate a canvas */ - scene->canvas = dmnsn_new_canvas(768, 480); - if (!scene->canvas) { - dmnsn_delete_scene(scene); - return NULL; - } - /* Create the default perspective camera */ scene->camera = dmnsn_new_perspective_camera(); if (!scene->camera) { -- cgit v1.2.3