# HG changeset patch
# User lost@l-w.ca
# Date 1295755263 25200
# Node ID 7c35fa8dbc91f906501d9db8b7ed6d149e91a76d
# Parent ac311e7ffed6bfb996133f1595916322652e0d51
Added initial framework for lwbasic
diff -r ac311e7ffed6 -r 7c35fa8dbc91 .hgignore
--- a/.hgignore Sat Jan 22 18:28:07 2011 -0700
+++ b/.hgignore Sat Jan 22 21:01:03 2011 -0700
@@ -9,5 +9,6 @@
lwar
lwlink
lwobjdump
+lwbasic
*.html
*.pdf
diff -r ac311e7ffed6 -r 7c35fa8dbc91 Makefile
--- a/Makefile Sat Jan 22 18:28:07 2011 -0700
+++ b/Makefile Sat Jan 22 21:01:03 2011 -0700
@@ -28,7 +28,7 @@
.PHONY: all
all: $(MAIN_TARGETS)
-subdirs := lwasm lwlink lwar lwlib docs
+subdirs := lwasm lwlink lwar lwlib lwbasic docs
-include $(subdirs:=/rules.make)
@@ -50,6 +50,9 @@
lwar: lwar/lwar$(PROGSUFFIX)
lwobjdump: lwlink/lwobjdump$(PROGSUFFIX)
+.PHONY: lwbasic
+lwbasic: lwbasic/lwbasic$(PROGSUFFIX)
+
lwasm/lwasm$(PROGSUFFIX): $(lwasm_objs) lwlib lwasm/rules.make
@echo Linking $@
@$(CC) -o $@ $(lwasm_objs) $(LDFLAGS)
@@ -98,7 +101,7 @@
.PHONY: clean
-clean:
+clean: $(cleantargs)
@echo "Cleaning up"
@rm -f lwlib/liblw.a lwasm/lwasm$(PROGSUFFIX) lwlink/lwlink$(PROGSUFFIX) lwlink/lwobjdump$(PROGSUFFIX) lwar/lwar$(PROGSUFFIX)
@rm -f $(lwasm_objs) $(lwlink_objs) $(lwar_objs) $(lwlib_objs) $(lwobjdump_objs)
@@ -106,7 +109,7 @@
@rm -f */*.exe
.PHONY: realclean
-realclean: clean
+realclean: clean $(realcleantargs)
@echo "Cleaning up even more"
@rm -f $(lwasm_deps) $(lwlink_deps) $(lwar_deps) $(lwlib_deps) $(lwobjdump_deps)
@rm -f docs/manual/*.html docs/manual/*.pdf
diff -r ac311e7ffed6 -r 7c35fa8dbc91 lwbasic/lwbasic.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lwbasic/lwbasic.h Sat Jan 22 21:01:03 2011 -0700
@@ -0,0 +1,37 @@
+/*
+lwbasic.h
+
+Copyright © 2011 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 .
+*/
+
+/*
+definitions used throughout lwbasic
+*/
+
+#ifndef __lwbasic_h_seen__
+#define __lwbasic_h_seen__
+
+typedef struct
+{
+ char *output_file;
+ char *input_file;
+
+ int debug_level;
+} cstate;
+
+#endif /* __lwbasic_h_seen__ */
diff -r ac311e7ffed6 -r 7c35fa8dbc91 lwbasic/main.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lwbasic/main.c Sat Jan 22 21:01:03 2011 -0700
@@ -0,0 +1,100 @@
+/*
+main.c
+
+Copyright © 2011 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 .
+*/
+
+/*
+main program startup handling for lwbasic
+*/
+
+#include
+#include
+
+#include
+#include
+#include
+
+#include "lwbasic.h"
+
+#define PROGVER "lwbasic from " PACKAGE_STRING
+
+static struct lw_cmdline_options options[] =
+{
+ { "output", 'o', "FILE", 0, "Output to FILE"},
+ { "debug", 'd', "LEVEL", lw_cmdline_opt_optional, "Set debug mode"},
+ { 0 }
+};
+
+static int parse_opts(int key, char *arg, void *data)
+{
+ cstate *state = data;
+
+ switch (key)
+ {
+ case 'o':
+ if (state -> output_file)
+ lw_free(state -> output_file);
+ state -> output_file = lw_strdup(arg);
+ break;
+
+ case 'd':
+ if (!arg)
+ state -> debug_level = 50;
+ else
+ state -> debug_level = atoi(arg);
+ break;
+
+ case lw_cmdline_key_end:
+ return 0;
+
+ case lw_cmdline_key_arg:
+ if (state -> input_file)
+ {
+ fprintf(stderr, "Already have an input file; ignoring %s\n", arg);
+ }
+ else
+ {
+ state -> input_file = lw_strdup(arg);
+ }
+ break;
+
+ default:
+ return lw_cmdline_err_unknown;
+ }
+
+ return 0;
+}
+
+static struct lw_cmdline_parser cmdline_parser =
+{
+ options,
+ parse_opts,
+ "INPUTFILE",
+ "lwbasic, a compiler for a dialect of Basic\vPlease report bugs to lost@l-w.ca.",
+ PROGVER
+};
+
+int main(int argc, char **argv)
+{
+ cstate state = { 0 };
+
+ lw_cmdline_parse(&cmdline_parser, argc, argv, 0, 0, &state);
+
+ exit(0);
+}
diff -r ac311e7ffed6 -r 7c35fa8dbc91 lwbasic/rules.make
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lwbasic/rules.make Sat Jan 22 21:01:03 2011 -0700
@@ -0,0 +1,28 @@
+dirname := $(dir $(lastword $(MAKEFILE_LIST)))
+lwbasic_dir := $(dirname)
+
+lwbasic_lsrcs := main.c
+
+lwbasic_srcs := $(addprefix $(dirname),$(lwbasic_lsrcs))
+lwbasic_objs := $(lwbasic_srcs:.c=.o)
+lwbasic_deps := $(lwbasic_srcs:.c=.d)
+
+
+
+$(lwbasic_dir)lwbasic$(PROGSUFFIX): $(lwbasic_objs) lwlib $(lwbasic_dir)rules.make
+ @echo "Linking $@"
+ @$(CC) -o $@ $(lwbasic_objs) $(LDFLAGS)
+
+cleantargs := $(cleantargs) lwbasicclean
+realcleantargs := $(realcleantargs) lwbasicrealclean
+
+.PHONY: lwbasicclean lwbasicrealclean
+lwbasicrealclean:
+ @echo "Really cleaning up lwbasic"
+ @cd $(lwbasic_dir) && rm -f *.d
+
+lwbasicclean:
+ @echo "Cleaning up lwbasic"
+ @cd $(lwbasic_dir) && rm -f *.o *.exe lwbasic
+
+-include $(lwbasic_deps)