Mercurial > hg-old > index.cgi
changeset 332:67224d8d1024
Basic input layer works
author | lost |
---|---|
date | Tue, 02 Mar 2010 00:10:32 +0000 |
parents | ed3553296580 |
children | ebff3a3e8fa6 |
files | lwasm/Makefile.am lwasm/input.c lwasm/main.c lwasm/pass1.c |
diffstat | 4 files changed, 57 insertions(+), 10 deletions(-) [+] |
line wrap: on
line diff
--- a/lwasm/Makefile.am Sun Feb 28 05:55:07 2010 +0000 +++ b/lwasm/Makefile.am Tue Mar 02 00:10:32 2010 +0000 @@ -1,5 +1,5 @@ AM_CPPFLAGS = -I$(top_builddir)/lib -I$(top_srcdir)/lib -I$(top_builddir)/lwlib -I$(top_srcdir)/lwlib bin_PROGRAMS = lwasm -lwasm_SOURCES = main.c pragma.c input.c +lwasm_SOURCES = main.c pragma.c input.c pass1.c lwasm_LDADD = -L$(top_builddir)/lib -L$(top_srcdir)/lib -L$(top_builddir)/lwlib -L$(top_srcdir)/lwlib -lgnu -llw EXTRA_DIST = lwasm.h input.h
--- a/lwasm/input.c Sun Feb 28 05:55:07 2010 +0000 +++ b/lwasm/input.c Tue Mar 02 00:10:32 2010 +0000 @@ -84,7 +84,7 @@ int o; dn = lw_strdup(fn); - dp = dn + strlen(dp); + dp = dn + strlen(dn); while (--dp != dn) { @@ -130,9 +130,9 @@ t = lw_alloc(sizeof(struct input_stack)); t -> filespec = lw_strdup(s); - for (s2 = s; *s2 && *s2 != ':'; s2++) + for (s2 = s; *s2 && (*s2 != ':'); s2++) /* do nothing */ ; - if (!s2) + if (!*s2) { t -> type = input_type_file; } @@ -142,16 +142,16 @@ ts = lw_strndup(s, s2 - s); s = s2 + 1; - if (!strcmp(ts, "include")) t -> type = input_type_include; else if (!strcmp(ts, "file")) t -> type = input_type_file; else t -> type = input_type_error; + + lw_free(ts); } - - t -> next = IS; + t -> next = as -> input_data; as -> input_data = t; switch (IS -> type) @@ -198,7 +198,7 @@ lw_stringlist_next(as -> include_list); } lw_error("Cannot open include file '%s': %s", s, strerror(errno)); - + case input_type_file: IS -> data = fopen(s, "rb"); @@ -210,7 +210,7 @@ return; } - lw_error("Cannot figure out how to open '%s'.", s); + lw_error("Cannot figure out how to open '%s'.", t -> filespec); } char *input_readline(asmstate_t *as) @@ -235,11 +235,11 @@ case input_type_file: case input_type_include: /* read from a file */ + lbloc = 0; for (;;) { int c, c2; c = fgetc(IS -> data); - lbloc = 0; if (c == EOF) { if (lbloc == 0)
--- a/lwasm/main.c Sun Feb 28 05:55:07 2010 +0000 +++ b/lwasm/main.c Tue Mar 02 00:10:32 2010 +0000 @@ -163,6 +163,8 @@ main function; parse command line, set up assembler state, and run the assembler on the first file */ +extern void do_pass1(asmstate_t *as); + int main(int argc, char **argv) { /* assembler state */ @@ -183,5 +185,7 @@ input_init(&asmstate); + do_pass1(&asmstate); + exit(0); }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/lwasm/pass1.c Tue Mar 02 00:10:32 2010 +0000 @@ -0,0 +1,43 @@ +/* +pass1.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> + +#include <stdio.h> + +#include <lw_alloc.h> + +#include "lwasm.h" +#include "input.h" + +void do_pass1(asmstate_t *as) +{ + char *line; + + for (;;) + { + line = input_readline(as); + if (!line) + break; + printf("%s\n", line); + lw_free(line); + } +}