Mercurial > hg-old > index.cgi
view lwasm/input.c @ 328:591d01b343b9
checkpoint - input layer
author | lost |
---|---|
date | Sat, 13 Feb 2010 06:08:26 +0000 |
parents | |
children | c15cca3ae6a2 |
line wrap: on
line source
/* 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 } }