Mercurial > hg-old > index.cgi
changeset 328:591d01b343b9
checkpoint - input layer
author | lost |
---|---|
date | Sat, 13 Feb 2010 06:08:26 +0000 |
parents | 80826bf2827b |
children | c15cca3ae6a2 |
files | lwasm/input.c lwasm/main.c |
diffstat | 2 files changed, 88 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- /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 <http://www.gnu.org/licenses/>. +*/ + +#include <config.h> + +/* +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 <lw_alloc.h> +#include <lw_stringlist.h> + +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 + } + + +}