Move more stuff around and fix all compiler errors and warnings
diff --git a/Makefile.in b/Makefile.in
index 761d387..666d79e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -145,10 +145,8 @@
BC_LIB_C_ARGS = bc_lib bc.h bc_lib_name $(BC_ENABLED_NAME) 1
BC_LIB2_C_ARGS = bc_lib2 bc.h bc_lib2_name "$(BC_ENABLED_NAME) && $(BC_ENABLE_EXTRA_MATH_NAME)" 1
-OBJS1 = $(OBJ) $(DC_OBJ) $(BC_OBJ) $(HISTORY_OBJ) $(RAND_OBJ) $(BC_HELP_O) $(DC_HELP_O)
-OBJS = $(OBJS1) $(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O)
-OBJ_TARGETS1 = $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(BC_LIB3_O)
-OBJ_TARGETS = $(OBJ_TARGETS1) $(BC_OBJ) $(DC_OBJ) $(HISTORY_OBJ) $(RAND_OBJ) $(OBJ)
+OBJS = $(BC_HELP_O) $(DC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(OBJ)
+OBJ_TARGETS = $(DC_HELP_O) $(BC_HELP_O) $(BC_LIB_O) $(BC_LIB2_O) $(OBJ)
.c.o:
$(CC) $(CFLAGS) -o $@ -c $<
@@ -159,8 +157,8 @@
$(CC) $(CFLAGS) $(OBJS) $(LDFLAGS) -o $(EXEC)
%%LINK%%
-library: make_bin $(OBJ_TARGETS)
- ar -r -cu $(LIBBC) $(OBJ_TARGETS)
+library: make_bin $(OBJ) $(BC_LIB_O) $(BC_LIB2_O)
+ ar -r -cu $(LIBBC) $(BC_LIB_O) $(BC_LIB2_O) $(OBJ)
$(GEN_EXEC):
%%GEN_EXEC_TARGET%%
diff --git a/configure.sh b/configure.sh
index b8ee06e..a0fd3e9 100755
--- a/configure.sh
+++ b/configure.sh
@@ -791,11 +791,11 @@
printf 'Testing history...\n'
flags="-DBC_ENABLE_HISTORY=1 -DBC_ENABLED=$bc -DDC_ENABLED=$dc"
- flags="$flags -DBC_ENABLE_NLS=$nls"
+ flags="$flags -DBC_ENABLE_NLS=$nls -DBC_ENABLE_LIBRARY=0"
flags="$flags -DBC_ENABLE_EXTRA_MATH=$extra_math -I./include/"
flags="$flags -D_POSIX_C_SOURCE=200809L -D_XOPEN_SOURCE=700"
- "$CC" $CPPFLAGS $CFLAGS $flags -c "src/history/history.c" -o "$scriptdir/history.o" > /dev/null 2>&1
+ "$CC" $CPPFLAGS $CFLAGS $flags -c "src/history.c" -o "$scriptdir/history.o"
err="$?"
@@ -864,7 +864,7 @@
unneeded=""
if [ "$hist" -eq 0 ]; then
- unneeded="$unneeded history/history.c"
+ unneeded="$unneeded history.c"
fi
if [ "$bc" -eq 0 ]; then
@@ -876,7 +876,7 @@
fi
if [ "$extra_math" -eq 0 ]; then
- unneeded="$unneeded rand/rand.c"
+ unneeded="$unneeded rand.c"
fi
if [ "$library" -eq 1 ]; then
diff --git a/gen/strgen.c b/gen/strgen.c
index f4c4b51..7b787d2 100644
--- a/gen/strgen.c
+++ b/gen/strgen.c
@@ -45,13 +45,15 @@
static const char* const bc_gen_header =
"// Copyright (c) 2018-2020 Gavin D. Howard and contributors.\n"
"// Licensed under the 2-clause BSD license.\n"
- "// *** AUTOMATICALLY GENERATED FROM %s. DO NOT MODIFY. ***\n";
+ "// *** AUTOMATICALLY GENERATED FROM %s. DO NOT MODIFY. ***\n\n";
-static const char* const bc_gen_include = "#include <%s>\n\n";
+/*static const char* const bc_gen_include = "#include \"%s\"\n\n";*/
static const char* const bc_gen_label = "const char *%s = \"%s\";\n\n";
+static const char* const bc_gen_label_extern = "extern const char *%s;\n\n";
static const char* const bc_gen_ifdef = "#if %s\n";
static const char* const bc_gen_endif = "#endif // %s\n";
static const char* const bc_gen_name = "const char %s[] = {\n";
+static const char* const bc_gen_name_extern = "extern const char %s[];\n\n";
#define IO_ERR (1)
#define INVALID_INPUT_FILE (2)
@@ -89,8 +91,9 @@
if (!out) goto out_err;
if (fprintf(out, bc_gen_header, argv[1]) < 0) goto err;
+ if (has_label && fprintf(out, bc_gen_label_extern, label) < 0) goto err;
+ if (fprintf(out, bc_gen_name_extern, name) < 0) goto err;
if (has_define && fprintf(out, bc_gen_ifdef, define) < 0) goto err;
- if (fprintf(out, bc_gen_include, include) < 0) goto err;
if (has_label && fprintf(out, bc_gen_label, label, argv[1]) < 0) goto err;
if (fprintf(out, bc_gen_name, name) < 0) goto err;
diff --git a/gen/strgen.sh b/gen/strgen.sh
index f389c12..53acece 100755
--- a/gen/strgen.sh
+++ b/gen/strgen.sh
@@ -50,6 +50,7 @@
if [ -n "$label" ]; then
nameline="const char *${label} = \"${input}\";"
+ labelexternline="extern const char *${label};"
fi
if [ -n "$define" ]; then
@@ -64,11 +65,14 @@
fi
cat<<EOF
+// Copyright (c) 2018-2020 Gavin D. Howard and contributors.
// Licensed under the 2-clause BSD license.
// *** AUTOMATICALLY GENERATED FROM ${input}. DO NOT MODIFY. ***
${condstart}
-#include <${header}>
+$labelexternline
+
+extern const char $name[];
$nameline
diff --git a/src/status.h b/include/status.h
similarity index 100%
rename from src/status.h
rename to include/status.h
diff --git a/src/args.c b/src/args.c
index 0292376..b381c79 100644
--- a/src/args.c
+++ b/src/args.c
@@ -42,11 +42,11 @@
#include <unistd.h>
#include <status.h>
-#include <vector.h>
-#include <read.h>
-#include <vm.h>
-#include <args.h>
-#include <opt.h>
+#include "vector.h"
+#include "read.h"
+#include "vm.h"
+#include "args.h"
+#include "opt.h"
static const BcOptLong bc_args_lopt[] = {
diff --git a/src/args.h b/src/args.h
index f2bc2d6..698297f 100644
--- a/src/args.h
+++ b/src/args.h
@@ -37,7 +37,7 @@
#define BC_ARGS_H
#include <status.h>
-#include <vm.h>
+#include "vm.h"
void bc_args(int argc, char *argv[]);
diff --git a/src/bc/bc.c b/src/bc.c
similarity index 98%
rename from src/bc/bc.c
rename to src/bc.c
index 3d488b5..2448026 100644
--- a/src/bc/bc.c
+++ b/src/bc.c
@@ -38,8 +38,8 @@
#include <string.h>
#include <status.h>
-#include <bc.h>
-#include <vm.h>
+#include "bc.h"
+#include "vm.h"
void bc_main(int argc, char **argv) {
diff --git a/src/bc.h b/src/bc.h
index 383e7e7..ca15aab 100644
--- a/src/bc.h
+++ b/src/bc.h
@@ -42,8 +42,8 @@
#include <stdbool.h>
#include <status.h>
-#include <lex.h>
-#include <parse.h>
+#include "lex.h"
+#include "parse.h"
void bc_main(int argc, char **argv);
diff --git a/src/bc/lex.c b/src/bc_lex.c
similarity index 98%
rename from src/bc/lex.c
rename to src/bc_lex.c
index cc780e0..8c6d255 100644
--- a/src/bc/lex.c
+++ b/src/bc_lex.c
@@ -39,9 +39,9 @@
#include <ctype.h>
#include <string.h>
-#include <lex.h>
-#include <bc.h>
-#include <vm.h>
+#include "lex.h"
+#include "bc.h"
+#include "vm.h"
static void bc_lex_identifier(BcLex *l) {
diff --git a/src/bc/parse.c b/src/bc_parse.c
similarity index 99%
rename from src/bc/parse.c
rename to src/bc_parse.c
index 7f15ebe..b26a40e 100644
--- a/src/bc/parse.c
+++ b/src/bc_parse.c
@@ -42,11 +42,11 @@
#include <setjmp.h>
-#include <lex.h>
-#include <parse.h>
-#include <bc.h>
-#include <num.h>
-#include <vm.h>
+#include "lex.h"
+#include "parse.h"
+#include "bc.h"
+#include "num.h"
+#include "vm.h"
static void bc_parse_else(BcParse *p);
static void bc_parse_stmt(BcParse *p);
diff --git a/src/data.c b/src/data.c
index 51c5b89..789ccb6 100644
--- a/src/data.c
+++ b/src/data.c
@@ -33,15 +33,15 @@
*
*/
-#include <args.h>
-#include <lex.h>
-#include <parse.h>
-#include <bc.h>
-#include <dc.h>
-#include <num.h>
-#include <rand.h>
-#include <program.h>
-#include <vm.h>
+#include "args.h"
+#include "lex.h"
+#include "parse.h"
+#include "bc.h"
+#include "dc.h"
+#include "num.h"
+#include "rand.h"
+#include "program.h"
+#include "vm.h"
#if BC_ENABLED
const char bc_sig_msg[] = "\ninterrupt (type \"quit\" to exit)\n";
diff --git a/src/dc/dc.c b/src/dc.c
similarity index 98%
rename from src/dc/dc.c
rename to src/dc.c
index 8c03ccf..857837f 100644
--- a/src/dc/dc.c
+++ b/src/dc.c
@@ -38,8 +38,8 @@
#include <string.h>
#include <status.h>
-#include <dc.h>
-#include <vm.h>
+#include "dc.h"
+#include "vm.h"
void dc_main(int argc, char **argv) {
diff --git a/src/dc.h b/src/dc.h
index 07af135..356a623 100644
--- a/src/dc.h
+++ b/src/dc.h
@@ -39,8 +39,8 @@
#if DC_ENABLED
#include <status.h>
-#include <lex.h>
-#include <parse.h>
+#include "lex.h"
+#include "parse.h"
void dc_main(int argc, char **argv);
diff --git a/src/dc/lex.c b/src/dc_lex.c
similarity index 98%
rename from src/dc/lex.c
rename to src/dc_lex.c
index b17f01b..d83201d 100644
--- a/src/dc/lex.c
+++ b/src/dc_lex.c
@@ -38,9 +38,9 @@
#include <ctype.h>
#include <status.h>
-#include <lex.h>
-#include <dc.h>
-#include <vm.h>
+#include "lex.h"
+#include "dc.h"
+#include "vm.h"
bool dc_lex_negCommand(BcLex *l) {
char c = l->buf[l->i];
diff --git a/src/dc/parse.c b/src/dc_parse.c
similarity index 98%
rename from src/dc/parse.c
rename to src/dc_parse.c
index dbf28dc..0041968 100644
--- a/src/dc/parse.c
+++ b/src/dc_parse.c
@@ -41,10 +41,10 @@
#include <setjmp.h>
#include <status.h>
-#include <parse.h>
-#include <dc.h>
-#include <program.h>
-#include <vm.h>
+#include "parse.h"
+#include "dc.h"
+#include "program.h"
+#include "vm.h"
static void dc_parse_register(BcParse *p, bool var) {
diff --git a/src/file.c b/src/file.c
index f3f0535..72c557c 100644
--- a/src/file.c
+++ b/src/file.c
@@ -38,8 +38,8 @@
#include <string.h>
#include <unistd.h>
-#include <file.h>
-#include <vm.h>
+#include "file.h"
+#include "vm.h"
static void bc_file_ultoa(unsigned long long val, char buf[BC_FILE_ULL_LENGTH])
{
diff --git a/src/file.h b/src/file.h
index 6fa08b3..6409b48 100644
--- a/src/file.h
+++ b/src/file.h
@@ -38,7 +38,7 @@
#include <stdarg.h>
-#include <vector.h>
+#include "vector.h"
#define BC_FILE_ULL_LENGTH (21)
diff --git a/src/history/history.c b/src/history.c
similarity index 99%
rename from src/history/history.c
rename to src/history.c
index b94fbb7..1cf1845 100644
--- a/src/history/history.c
+++ b/src/history.c
@@ -160,11 +160,11 @@
#include <sys/ioctl.h>
#include <sys/select.h>
-#include <vector.h>
-#include <history.h>
-#include <read.h>
-#include <file.h>
-#include <vm.h>
+#include "vector.h"
+#include "history.h"
+#include "read.h"
+#include "file.h"
+#include "vm.h"
static void bc_history_add(BcHistory *h, char *line);
static void bc_history_add_empty(BcHistory *h);
diff --git a/src/history.h b/src/history.h
index c632bc8..e600cbe 100644
--- a/src/history.h
+++ b/src/history.h
@@ -100,11 +100,11 @@
#include <sys/select.h>
#include <status.h>
-#include <vector.h>
-#include <read.h>
+#include "vector.h"
+#include "read.h"
#if BC_DEBUG_CODE
-#include <file.h>
+#include "file.h"
#endif // BC_DEBUG_CODE
#define BC_HIST_DEF_COLS (80)
diff --git a/src/lang.c b/src/lang.c
index bd287c7..5d5c6d3 100644
--- a/src/lang.c
+++ b/src/lang.c
@@ -37,8 +37,8 @@
#include <stdlib.h>
#include <string.h>
-#include <lang.h>
-#include <vm.h>
+#include "lang.h"
+#include "vm.h"
#ifndef NDEBUG
void bc_id_free(void *id) {
diff --git a/src/lang.h b/src/lang.h
index a8ab08a..ab1d6fc 100644
--- a/src/lang.h
+++ b/src/lang.h
@@ -39,8 +39,8 @@
#include <stdbool.h>
#include <status.h>
-#include <vector.h>
-#include <num.h>
+#include "vector.h"
+#include "num.h"
#if BC_ENABLED
#define BC_INST_IS_ASSIGN(i) \
diff --git a/src/lex.c b/src/lex.c
index 2b705c8..4758063 100644
--- a/src/lex.c
+++ b/src/lex.c
@@ -39,9 +39,9 @@
#include <string.h>
#include <status.h>
-#include <lex.h>
-#include <vm.h>
-#include <bc.h>
+#include "lex.h"
+#include "vm.h"
+#include "bc.h"
void bc_lex_invalidChar(BcLex *l, char c) {
l->t = BC_LEX_INVALID;
diff --git a/src/lex.h b/src/lex.h
index 68b72a7..e98b454 100644
--- a/src/lex.h
+++ b/src/lex.h
@@ -40,8 +40,8 @@
#include <stddef.h>
#include <status.h>
-#include <vector.h>
-#include <lang.h>
+#include "vector.h"
+#include "lang.h"
#define bc_lex_err(l, e) (bc_vm_error((e), (l)->line))
#define bc_lex_verr(l, e, ...) (bc_vm_error((e), (l)->line, __VA_ARGS__))
diff --git a/src/main.c b/src/main.c
index 7e5e290..11a043d 100644
--- a/src/main.c
+++ b/src/main.c
@@ -43,9 +43,9 @@
#include <setjmp.h>
#include <status.h>
-#include <vm.h>
-#include <bc.h>
-#include <dc.h>
+#include "vm.h"
+#include "bc.h"
+#include "dc.h"
char output_bufs[BC_VM_BUF_SIZE];
BcVm vm;
diff --git a/src/num.c b/src/num.c
index 18888f3..dadc78c 100644
--- a/src/num.c
+++ b/src/num.c
@@ -42,9 +42,9 @@
#include <limits.h>
#include <status.h>
-#include <num.h>
-#include <rand.h>
-#include <vm.h>
+#include "num.h"
+#include "rand.h"
+#include "vm.h"
static void bc_num_m(BcNum *a, BcNum *b, BcNum *restrict c, size_t scale);
diff --git a/src/num.h b/src/num.h
index b33b197..f74d707 100644
--- a/src/num.h
+++ b/src/num.h
@@ -44,7 +44,7 @@
#include <sys/types.h>
#include <status.h>
-#include <vector.h>
+#include "vector.h"
#ifndef BC_ENABLE_EXTRA_MATH
#define BC_ENABLE_EXTRA_MATH (1)
diff --git a/src/opt.c b/src/opt.c
index 85bfb27..a6d54e7 100644
--- a/src/opt.c
+++ b/src/opt.c
@@ -44,8 +44,8 @@
#include <string.h>
#include <status.h>
-#include <opt.h>
-#include <vm.h>
+#include "opt.h"
+#include "vm.h"
static inline bool bc_opt_longoptsEnd(const BcOptLong *longopts, size_t i) {
return !longopts[i].name && !longopts[i].val;
diff --git a/src/parse.c b/src/parse.c
index a48f580..202f1d5 100644
--- a/src/parse.c
+++ b/src/parse.c
@@ -41,11 +41,11 @@
#include <limits.h>
#include <status.h>
-#include <vector.h>
-#include <lex.h>
-#include <parse.h>
-#include <program.h>
-#include <vm.h>
+#include "vector.h"
+#include "lex.h"
+#include "parse.h"
+#include "program.h"
+#include "vm.h"
void bc_parse_updateFunc(BcParse *p, size_t fidx) {
p->fidx = fidx;
diff --git a/src/parse.h b/src/parse.h
index a568fab..010fddb 100644
--- a/src/parse.h
+++ b/src/parse.h
@@ -41,9 +41,9 @@
#include <stdint.h>
#include <status.h>
-#include <vector.h>
-#include <lex.h>
-#include <lang.h>
+#include "vector.h"
+#include "lex.h"
+#include "lang.h"
#define BC_PARSE_REL (UINTMAX_C(1)<<0)
#define BC_PARSE_PRINT (UINTMAX_C(1)<<1)
diff --git a/src/program.c b/src/program.c
index 697aa74..c360ff0 100644
--- a/src/program.c
+++ b/src/program.c
@@ -43,10 +43,10 @@
#include <time.h>
-#include <read.h>
-#include <parse.h>
-#include <program.h>
-#include <vm.h>
+#include "read.h"
+#include "parse.h"
+#include "program.h"
+#include "vm.h"
static void bc_program_addFunc(BcProgram *p, BcFunc *f, BcId *id_ptr);
diff --git a/src/program.h b/src/program.h
index a9805fb..f0a5352 100644
--- a/src/program.h
+++ b/src/program.h
@@ -39,10 +39,10 @@
#include <stddef.h>
#include <status.h>
-#include <parse.h>
-#include <lang.h>
-#include <num.h>
-#include <rand.h>
+#include "parse.h"
+#include "lang.h"
+#include "num.h"
+#include "rand.h"
#define BC_PROG_GLOBALS_IBASE (0)
#define BC_PROG_GLOBALS_OBASE (1)
diff --git a/src/rand/rand.c b/src/rand.c
similarity index 99%
rename from src/rand/rand.c
rename to src/rand.c
index b16061d..faf755a 100644
--- a/src/rand/rand.c
+++ b/src/rand.c
@@ -74,9 +74,8 @@
#include <unistd.h>
#include <status.h>
-#include <num.h>
-#include <rand.h>
-#include <vm.h>
+#include "rand.h"
+#include "vm.h"
#if BC_ENABLE_EXTRA_MATH && BC_ENABLE_RAND
diff --git a/src/rand.h b/src/rand.h
index 3c8aafd..efaa381 100644
--- a/src/rand.h
+++ b/src/rand.h
@@ -72,8 +72,8 @@
#include <stdint.h>
#include <inttypes.h>
-#include <vector.h>
-#include <num.h>
+#include "vector.h"
+#include "num.h"
#if BC_ENABLE_EXTRA_MATH
diff --git a/src/read.c b/src/read.c
index 6886a7e..e6878b1 100644
--- a/src/read.c
+++ b/src/read.c
@@ -45,10 +45,10 @@
#include <sys/stat.h>
#include <unistd.h>
-#include <read.h>
-#include <history.h>
-#include <program.h>
-#include <vm.h>
+#include "read.h"
+#include "history.h"
+#include "program.h"
+#include "vm.h"
static bool bc_read_binary(const char *buf, size_t size) {
diff --git a/src/read.h b/src/read.h
index 664ff98..064d276 100644
--- a/src/read.h
+++ b/src/read.h
@@ -39,7 +39,7 @@
#include <stdlib.h>
#include <status.h>
-#include <vector.h>
+#include "vector.h"
#ifndef BC_ENABLE_PROMPT
#define BC_ENABLE_PROMPT (1)
diff --git a/src/vector.c b/src/vector.c
index f45bcb1..7572af3 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -38,9 +38,9 @@
#include <string.h>
#include <status.h>
-#include <vector.h>
-#include <lang.h>
-#include <vm.h>
+#include "vector.h"
+#include "lang.h"
+#include "vm.h"
static void bc_vec_grow(BcVec *restrict v, size_t n) {
diff --git a/src/vm.c b/src/vm.c
index e15b139..a73f357 100644
--- a/src/vm.c
+++ b/src/vm.c
@@ -57,11 +57,11 @@
#endif // _WIN32
#include <status.h>
-#include <vector.h>
-#include <args.h>
-#include <vm.h>
-#include <read.h>
-#include <bc.h>
+#include "vector.h"
+#include "args.h"
+#include "vm.h"
+#include "read.h"
+#include "bc.h"
#if BC_DEBUG_CODE
BC_NORETURN void bc_vm_jmp(const char* f) {
diff --git a/src/vm.h b/src/vm.h
index f178c03..02e3208 100644
--- a/src/vm.h
+++ b/src/vm.h
@@ -52,11 +52,14 @@
#endif // BC_ENABLE_NLS
#include <status.h>
-#include <num.h>
-#include <parse.h>
-#include <program.h>
-#include <history.h>
-#include <file.h>
+#include "num.h"
+#include "parse.h"
+#include "program.h"
+#include "history.h"
+
+#if !BC_ENABLE_LIBRARY
+#include "file.h"
+#endif // !BC_ENABLE_LIBRARY
#if !BC_ENABLED && !DC_ENABLED
#error Must define BC_ENABLED, DC_ENABLED, or both