windows support

This commit is contained in:
Nishi 2026-08-11 23:46:39 +09:00
commit d14a9b982f
3 changed files with 24 additions and 15 deletions

View file

@ -30,7 +30,6 @@
#include <stddef.h>
#include <sys/types.h>
#include <err.h>
#include <stdint.h>
#define MAXLINE 133
@ -169,6 +168,10 @@ extern unsigned lineno;
extern int err_count;
extern char line[], *lineptr;
#ifdef _WIN32
#include <malloc.h>
#else
#include <alloca.h>
#endif
#define new(x) ((x) = malloc(sizeof(*(x))))

View file

@ -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 */

30
gspa.c
View file

@ -29,7 +29,6 @@
*/
#include <sys/param.h>
#include <err.h>
#include <errno.h>
#include <setjmp.h>
#include <stdarg.h>
@ -37,6 +36,7 @@
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <string.h>
#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, "<stdin>", sizeof(in_name));
strncpy(in_name, "<stdin>", 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);