annotate lwasm/input.c @ 328:591d01b343b9

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