# HG changeset patch
# User lost
# Date 1267488632 0
# Node ID 67224d8d1024085e8081243e809baf7ee59bdd07
# Parent ed35532965800eb3b008d1671bd074100db04567
Basic input layer works
diff -r ed3553296580 -r 67224d8d1024 lwasm/Makefile.am
--- 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
diff -r ed3553296580 -r 67224d8d1024 lwasm/input.c
--- 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)
diff -r ed3553296580 -r 67224d8d1024 lwasm/main.c
--- 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);
}
diff -r ed3553296580 -r 67224d8d1024 lwasm/pass1.c
--- /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 .
+*/
+
+#include
+
+#include
+
+#include
+
+#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);
+ }
+}