Mercurial > hg-old > index.cgi
comparison lwasm/input.c @ 328:591d01b343b9
checkpoint - input layer
author | lost |
---|---|
date | Sat, 13 Feb 2010 06:08:26 +0000 |
parents | |
children | c15cca3ae6a2 |
comparison
equal
deleted
inserted
replaced
327:80826bf2827b | 328:591d01b343b9 |
---|---|
1 /* | |
2 input.c | |
3 | |
4 Copyright © 2010 William Astle | |
5 | |
6 This file is part of LWTOOLS. | |
7 | |
8 LWTOOLS is free software: you can redistribute it and/or modify it under the | |
9 terms of the GNU General Public License as published by the Free Software | |
10 Foundation, either version 3 of the License, or (at your option) any later | |
11 version. | |
12 | |
13 This program is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for | |
16 more details. | |
17 | |
18 You should have received a copy of the GNU General Public License along with | |
19 this program. If not, see <http://www.gnu.org/licenses/>. | |
20 */ | |
21 | |
22 #include <config.h> | |
23 | |
24 /* | |
25 This file is used to handle reading input files. It serves to encapsulate | |
26 the entire input system to make porting to different media and systems | |
27 less difficult. | |
28 */ | |
29 | |
30 #include <lw_alloc.h> | |
31 #include <lw_stringlist.h> | |
32 | |
33 struct input_layer | |
34 { | |
35 lw_stringlist_t inputlist; | |
36 struct input_layer *nextlayer; | |
37 | |
38 FILE *fp; | |
39 }; | |
40 | |
41 | |
42 static struct input_layer *layerstack = NULL; | |
43 | |
44 void input_push(lw_stringlist_t list) | |
45 { | |
46 struct input_layer *i; | |
47 | |
48 i = lw_alloc(sizeof(struct input_layer)); | |
49 i -> nextlayer = layerstack; | |
50 layerstack = i; | |
51 i -> inputlist = lw_stringlist_copy(list); | |
52 } | |
53 | |
54 /* fetch a line of input from the top of the input stack */ | |
55 /* return NULL if no input left */ | |
56 char *input_fetchline(void) | |
57 { | |
58 again: | |
59 if (!layerstack) | |
60 return NULL; | |
61 | |
62 if (!layerstack -> fp) | |
63 { | |
64 // no open file | |
65 char *fn; | |
66 | |
67 fn = lw_stringlist_current(layerstack -> inputlist); | |
68 lw_stringlist_next(layerstack -> inputlist); | |
69 if (!fn) | |
70 { | |
71 struct input_list *t; | |
72 t = layerstack; | |
73 layerstack = layerstack -> nextlayer; | |
74 lw_stringlist_destroy(t -> inputlist); | |
75 lw_free(t); | |
76 goto again; | |
77 } | |
78 | |
79 // open the file here | |
80 } | |
81 | |
82 | |
83 } |