From 671c81a754a4812c68929345781a80778b87bb95 Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 13 Dec 2019 00:01:28 -0500 Subject: [PATCH] make it compile. --- link.cpp | 28 +++++++++++++++++----------- main.cpp | 2 +- script.h | 26 ++++++++++++++++++++++++++ script.re2c | 4 ++-- 4 files changed, 46 insertions(+), 14 deletions(-) create mode 100644 script.h diff --git a/link.cpp b/link.cpp index baa478c..15d874c 100644 --- a/link.cpp +++ b/link.cpp @@ -26,6 +26,7 @@ #include "omf.h" #include "rel.h" #include "link.h" +#include "script.h" void save_omf(const std::string &path, std::vector &segments, bool compress, bool expressload); int set_file_type(const std::string &path, uint16_t file_type, uint32_t aux_type, std::error_code &ec); @@ -420,7 +421,7 @@ namespace { uint32_t active_bits = 1; bool active = true; - std::unordered_map symbol_table; + std::unordered_map local_symbol_table; } @@ -463,7 +464,8 @@ void evaluate(label_t label, opcode_t opcode, operand_t operand) { if (!end && lkv == 2) { /* finish up */ segments.pop_back(); - finish(); + if (!segments.empty()) + finish(); } end = true; break; @@ -471,13 +473,13 @@ void evaluate(label_t label, opcode_t opcode, operand_t operand) { case OP_DAT: { /* 29-DEC-88 4:18:37 PM */ time_t t = time(nullptr); - struct tm tm = localtime(&t); + struct tm *tm = localtime(&t); char buffer[32]; strftime(buffer, sizeof(buffer), "%d-%b-%y %H:%M:%S %p", tm); for(char &c : buffer) c = std::toupper(c); - printf(stdout, "%s\n", buffer); + fprintf(stdout, "%s\n", buffer); break; } @@ -539,7 +541,6 @@ void evaluate(label_t label, opcode_t opcode, operand_t operand) { seg.segname = std::get(operand); seg.kind = kind; - /* if this is the first segment, also save the /* add a new segment */ segments.emplace_back(); } @@ -560,13 +561,17 @@ void process_script(const char *path) { extern void parse_line(const char *); - FILE *fp; - fp = fopen(path, "r"); - if (!fp) { - warn("Unable to open %s", path); - return -1; + FILE *fp = nullptr; + + if (!path || !strcmp(path, "-")) fp = stdin; + else { + fp = fopen(path, "r"); + if (!fp) { + err(1, "Unable to open %s", path); + } } + int no = 1; int errors = 0; char *line = NULL; @@ -598,7 +603,8 @@ void process_script(const char *path) { } } } - fclose(fp); + if (fp != stdin) + fclose(fp); free(line); exit(errors ? EX_DATAERR : 0); } diff --git a/main.cpp b/main.cpp index f4fc1b2..9375254 100644 --- a/main.cpp +++ b/main.cpp @@ -150,7 +150,7 @@ int main(int argc, char **argv) { if (script && argc > 1) usage(EX_USAGE); if (argc == 1 && is_S(*argv)) script = true; - if (script) process_script(*argv); + if (script) process_script(argc ? *argv : nullptr); else process_files(argc, argv); exit(0); diff --git a/script.h b/script.h new file mode 100644 index 0000000..0286307 --- /dev/null +++ b/script.h @@ -0,0 +1,26 @@ +#ifndef script_h +#define script_h + +#include +#include +#include + +typedef std::string label_t; +typedef std::variant operand_t; + +enum opcode_t { + + OP_NONE = 0, + #define x(op) OP_##op, + #include "ops.h" + #undef x + OP_EQ +}; + +enum { + OVR_NONE = 1, + OVR_ALL = -1, + OVR_OFF = 0 +}; + +#endif diff --git a/script.re2c b/script.re2c index e53af9b..d7e3706 100644 --- a/script.re2c +++ b/script.re2c @@ -33,7 +33,7 @@ */ namespace { - std::unordered_map opcodes = { + std::unordered_map opcodes = { #define x(op) { #op, OP_##op }, #include "ops.h" @@ -496,7 +496,7 @@ operand: } case OP_CMD: - str_operand = std::string(YYCURSOR); + operand = std::string(YYCURSOR); break; default: