From d14a9b982f2473711dd6cef1ef36ce5300e46520 Mon Sep 17 00:00:00 2001 From: Nishi Date: Tue, 11 Aug 2026 23:46:39 +0900 Subject: [PATCH] windows support --- gsp_ass.h | 5 ++++- gsp_inst.c | 4 ++-- gspa.c | 30 ++++++++++++++++++------------ 3 files changed, 24 insertions(+), 15 deletions(-) diff --git a/gsp_ass.h b/gsp_ass.h index a8c9bd9..35b9d53 100644 --- a/gsp_ass.h +++ b/gsp_ass.h @@ -30,7 +30,6 @@ #include #include -#include #include #define MAXLINE 133 @@ -169,6 +168,10 @@ extern unsigned lineno; extern int err_count; extern char line[], *lineptr; +#ifdef _WIN32 +#include +#else #include +#endif #define new(x) ((x) = malloc(sizeof(*(x)))) diff --git a/gsp_inst.c b/gsp_inst.c index b9189e7..16cdccc 100644 --- a/gsp_inst.c +++ b/gsp_inst.c @@ -36,8 +36,8 @@ struct inst { const char *opname; uint16_t opcode; - u_char class; /* instruction class + flags */ - u_char optypes[4]; /* permissible operand classes */ + uint8_t class; /* instruction class + flags */ + uint8_t optypes[4]; /* permissible operand classes */ }; /* Values for flags in class field */ diff --git a/gspa.c b/gspa.c index 753d412..e3e4222 100644 --- a/gspa.c +++ b/gspa.c @@ -29,7 +29,6 @@ */ #include -#include #include #include #include @@ -37,6 +36,7 @@ #include #include #include +#include #include "gsp_ass.h" #include "gsp_gram.h" @@ -116,11 +116,13 @@ main(int argc, char **argv) argv += optind; if (argc == 0) { infile = stdin; - strlcpy(in_name, "", sizeof(in_name)); + strncpy(in_name, "", sizeof(in_name)); } else if (argc == 1) { - strlcpy(in_name, *argv, sizeof(in_name)); - if ((infile = fopen(in_name, "r")) == NULL) - err(1, "fopen"); + strncpy(in_name, *argv, sizeof(in_name)); + if ((infile = fopen(in_name, "r")) == NULL) { + fprintf(stderr, "%s: fopen: %s\n", argv[0], strerror(errno)); + return 1; + } } else usage(); @@ -144,8 +146,10 @@ main(int argc, char **argv) /* Open output files */ if (hex_name == 0) objfile = stdout; - else if ((objfile = fopen(hex_name, "w")) == NULL) - err(1, "fopen"); + else if ((objfile = fopen(hex_name, "w")) == NULL) { + fprintf(stderr, "%s: fopen: %s\n", argv[0], strerror(errno)); + return 1; + } if (c_name) { fprintf(objfile, "/*\n" " * This file was automatically created from\n" @@ -156,8 +160,10 @@ main(int argc, char **argv) "uint16_t %s[] = {\n\t", c_name); } if (list_name) - if ((listfile = fopen(list_name, "w")) == NULL) - err(1, "fopen"); + if ((listfile = fopen(list_name, "w")) == NULL) { + fprintf(stderr, "%s: fopen: %s\n", argv[0], strerror(errno)); + return 1; + } /* Pass 2 */ pass2 = 1; @@ -212,11 +218,11 @@ push_input(char *fn) new(p); p->fp = current_infile; p->lineno = lineno; - strlcpy(p->name, in_name, sizeof(p->name)); + strncpy(p->name, in_name, sizeof(p->name)); p->next = pending_input; current_infile = f; lineno = 1; - strlcpy(in_name, fn, sizeof(in_name)); + strncpy(in_name, fn, sizeof(in_name)); pending_input = p; } @@ -231,7 +237,7 @@ get_line(char *lp, int maxlen) /* pop the input stack */ fclose(current_infile); current_infile = p->fp; - strlcpy(in_name, p->name, sizeof(in_name)); + strncpy(in_name, p->name, sizeof(in_name)); lineno = p->lineno; pending_input = p->next; free(p);