summaryrefslogtreecommitdiffstats
path: root/dimension/main.c
diff options
context:
space:
mode:
authorTavian Barnes <tavianator@gmail.com>2009-12-17 03:12:34 -0500
committerTavian Barnes <tavianator@gmail.com>2009-12-17 03:12:34 -0500
commitc66148484cad66972348ffe850fd23bc9dca60f9 (patch)
treed4616778e980773a2ddb4e606f85193d51f4f71c /dimension/main.c
parentfb8fb378dcce0564085eb6222053a0db57eb480c (diff)
downloaddimension-c66148484cad66972348ffe850fd23bc9dca60f9.tar.xz
Tokenize on-the-fly.
No more manual tokenization and parsing, giving a simpler interface. Also, this brings us closer to a dmnsn_realize_string() interface.
Diffstat (limited to 'dimension/main.c')
-rw-r--r--dimension/main.c53
1 files changed, 20 insertions, 33 deletions
diff --git a/dimension/main.c b/dimension/main.c
index e8b0d22..2c2aea5 100644
--- a/dimension/main.c
+++ b/dimension/main.c
@@ -137,58 +137,45 @@ main(int argc, char **argv) {
return EXIT_FAILURE;
}
- /* Tokenize the input file */
-
- if (!debugging)
- printf("Tokenizing input ...\n");
-
- dmnsn_array *tokens = dmnsn_tokenize(input, input_file);
- if (!tokens) {
- fclose(input_file);
- fprintf(stderr, "Error tokenizing input file!\n");
- return EXIT_FAILURE;
- }
- fclose(input_file);
-
/* Debugging option - output the list of tokens as an S-expression */
if (tokenize) {
+ dmnsn_array *tokens = dmnsn_tokenize(input_file, input);
+ if (!tokens) {
+ fclose(input_file);
+ fprintf(stderr, "Error tokenizing input file!\n");
+ return EXIT_FAILURE;
+ }
dmnsn_print_token_sexpr(stdout, tokens);
+ rewind(input_file);
+ dmnsn_delete_tokens(tokens);
if (!parse) {
- dmnsn_delete_tokens(tokens);
+ fclose(input_file);
return EXIT_SUCCESS;
}
}
- /* Parse the input */
-
- if (!debugging)
- printf("Parsing input ...\n");
-
- dmnsn_array *astree = dmnsn_parse(tokens);
- if (!astree) {
- dmnsn_delete_tokens(tokens);
- fprintf(stderr, "Error parsing input file!\n");
- return EXIT_FAILURE;
- }
- dmnsn_delete_tokens(tokens);
-
/* Debugging option - output the abstract syntax tree as an S-expression */
if (parse) {
+ dmnsn_array *astree = dmnsn_parse(input_file, input);
+ if (!astree) {
+ fprintf(stderr, "Error parsing input file!\n");
+ return EXIT_FAILURE;
+ }
dmnsn_print_astree_sexpr(stdout, astree);
dmnsn_delete_astree(astree);
+
+ fclose(input_file);
return EXIT_SUCCESS;
}
/* Realize the input */
- printf("Generating scene ...\n");
- dmnsn_scene *scene = dmnsn_realize(astree);
+ printf("Parsing scene ...\n");
+ dmnsn_scene *scene = dmnsn_realize(input_file, input);
if (!scene) {
- dmnsn_delete_astree(astree);
fprintf(stderr, "Error realizing input file!\n");
return EXIT_FAILURE;
}
- dmnsn_delete_astree(astree);
/* Allocate a canvas */
scene->canvas = dmnsn_new_canvas(width, height);
@@ -220,7 +207,7 @@ main(int argc, char **argv) {
return EXIT_FAILURE;
}
- dmnsn_progressbar("Rendering scene: ", render_progress);
+ dmnsn_progressbar("Rendering scene ", render_progress);
if (dmnsn_finish_progress(render_progress) != 0) {
dmnsn_delete_scene(scene);
@@ -237,7 +224,7 @@ main(int argc, char **argv) {
return EXIT_FAILURE;
}
- dmnsn_progressbar("Writing PNG: ", output_progress);
+ dmnsn_progressbar("Writing PNG ", output_progress);
if (dmnsn_finish_progress(output_progress) != 0) {
fclose(output_file);