# HG changeset patch # User lost # Date 1266041306 0 # Node ID 591d01b343b92385231bfca87d767b8d7376efae # Parent 80826bf2827be9a1f89f36d45e653374dcce8211 checkpoint - input layer diff -r 80826bf2827b -r 591d01b343b9 lwasm/input.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/input.c Sat Feb 13 06:08:26 2010 +0000 @@ -0,0 +1,83 @@ +/* +input.c + +Copyright © 2010 William Astle + +This file is part of LWTOOLS. + +LWTOOLS is free software: you can redistribute it and/or modify it under the +terms of the GNU General Public License as published by the Free Software +Foundation, either version 3 of the License, or (at your option) any later +version. + +This program is distributed in the hope that it will be useful, but WITHOUT +ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +more details. + +You should have received a copy of the GNU General Public License along with +this program. If not, see . +*/ + +#include + +/* +This file is used to handle reading input files. It serves to encapsulate +the entire input system to make porting to different media and systems +less difficult. +*/ + +#include +#include + +struct input_layer +{ + lw_stringlist_t inputlist; + struct input_layer *nextlayer; + + FILE *fp; +}; + + +static struct input_layer *layerstack = NULL; + +void input_push(lw_stringlist_t list) +{ + struct input_layer *i; + + i = lw_alloc(sizeof(struct input_layer)); + i -> nextlayer = layerstack; + layerstack = i; + i -> inputlist = lw_stringlist_copy(list); +} + +/* fetch a line of input from the top of the input stack */ +/* return NULL if no input left */ +char *input_fetchline(void) +{ +again: + if (!layerstack) + return NULL; + + if (!layerstack -> fp) + { + // no open file + char *fn; + + fn = lw_stringlist_current(layerstack -> inputlist); + lw_stringlist_next(layerstack -> inputlist); + if (!fn) + { + struct input_list *t; + t = layerstack; + layerstack = layerstack -> nextlayer; + lw_stringlist_destroy(t -> inputlist); + lw_free(t); + goto again; + } + + // open the file here + } + + +} diff -r 80826bf2827b -r 591d01b343b9 lwasm/main.c --- a/lwasm/main.c Sat Feb 13 06:08:04 2010 +0000 +++ b/lwasm/main.c Sat Feb 13 06:08:26 2010 +0000 @@ -174,5 +174,10 @@ /* parse command line arguments */ argp_parse(&argp, argc, argv, 0, 0, &asmstate); + if (!asmstate.output_file) + { + asmstate.output_file = lw_strdup("a.out"); + } + exit(0); }