ref: c88028d9a01bb86e4002efbeedb06199f55300ac
parent: e9c151989b3e9d75957e87d85d426581ec91515f
author: Ryan Gonzalez <rymg19@gmail.com>
date: Thu Jan 15 09:22:33 EST 2015
Respect outfile I'm not sure what Myrddin's contributing guidelines are, so I'm doing things the hg-git way of sending the patch to the mailing list. This is really simple: it just actually uses outfile. If someone specifies an output file, then it will be used as the output for the object file; the output's basename will also be used for the use file and the assembler file (if -S was passed). Another patch is attached that fixes a slight logic error in the man page that confused me very much. :)
--- a/6/main.c
+++ b/6/main.c
@@ -48,6 +48,17 @@
printf("\t\t\tu: log type unifications\n");
}
+static void swapout(char* buf, size_t sz, char* suf) {
+ char* psuffix;
+ psuffix = strrchr(outfile, '.');
+ if (psuffix != NULL)
+ swapsuffix(buf, sz, outfile, psuffix, suf);
+ else {
+ strncpy(buf, outfile, sz);
+ strncat(buf, suf, sz);
+ }
+}
+
static void assemble(char *asmsrc, char *path)
{
char *asmcmd[] = Asmcmd;
@@ -57,11 +68,15 @@
size_t ncmd;
int pid, status;
- psuffix = strrchr(path, '+');
- if (psuffix != NULL)
- swapsuffix(objfile, 1024, path, psuffix, Objsuffix);
- else
- swapsuffix(objfile, 1024, path, ".myr", Objsuffix);
+ if (outfile != NULL)
+ strncpy(objfile, outfile, 1024);
+ else {
+ psuffix = strrchr(path, '+');
+ if (psuffix != NULL)
+ swapsuffix(objfile, 1024, path, psuffix, Objsuffix);
+ else
+ swapsuffix(objfile, 1024, path, ".myr", Objsuffix);
+ }
cmd = NULL;
ncmd = 0;
for (p = asmcmd; *p != NULL; p++)
@@ -109,11 +124,15 @@
char buf[1024];
char *psuffix;
- psuffix = strrchr(path, '+');
- if (psuffix != NULL)
- swapsuffix(buf, 1024, path, psuffix, ".use");
- else
- swapsuffix(buf, 1024, path, ".myr", ".use");
+ if (outfile != NULL)
+ swapout(buf, 1024, ".use");
+ else {
+ psuffix = strrchr(path, '+');
+ if (psuffix != NULL)
+ swapsuffix(buf, 1024, path, psuffix, ".use");
+ else
+ swapsuffix(buf, 1024, path, ".myr", ".use");
+ }
f = fopen(buf, "w");
if (!f) {
fprintf(stderr, "Could not open path %s\n", buf);
@@ -130,6 +149,8 @@
Optctx ctx;
size_t i;
+ outfile = NULL;
+
optinit(&ctx, "d:hSo:I:9G", argv, argc);
asmsyntax = Defaultasm;
while (!optdone(&ctx)) {
@@ -168,6 +189,14 @@
}
lappend(&incpaths, &nincpaths, Instroot "/lib/myr");
+
+ if (ctx.nargs == 0) {
+ fprintf(stderr, "No input files given\n");
+ exit(1);
+ }
+ else if (ctx.nargs > 1)
+ outfile = NULL;
+
for (i = 0; i < ctx.nargs; i++) {
globls = mkstab();
tyinit(globls);
@@ -186,7 +215,10 @@
dump(file, stdout);
if (writeasm) {
- swapsuffix(buf, sizeof buf, ctx.args[i], ".myr", ".s");
+ if (outfile != NULL)
+ swapout(buf, sizeof buf, ".s");
+ else
+ swapsuffix(buf, sizeof buf, ctx.args[i], ".myr", ".s");
} else {
gentemp(buf, sizeof buf, ctx.args[i], ".s");
}
--- a/doc/mc.1
+++ b/doc/mc.1
@@ -23,7 +23,7 @@
.PP
The following architectures are currently supported:
-.TP
+.TP
6m
x86-64
@@ -52,7 +52,7 @@
.TP
.B -S
-Generate assembly code instead of an object file.
+Generate assembly code along with the object file.
.SH EXAMPLE
.EX
--- a/parse/util.c
+++ b/parse/util.c
@@ -385,7 +385,7 @@
/* if we have matching suffixes */
if (suflen < slen && !strcmp(suf, &s[slen - suflen])) {
strncat(buf, s, slen - suflen);
- strncat(buf, swap, suflen);
+ strncat(buf, swap, swaplen);
} else {
snprintf(buf, sz, "%s%s", s, swap);
}
@@ -433,7 +433,7 @@
va_end(ap);
}
-void vfindentf(FILE *fd, int depth, char *fmt, va_list ap)
+void vfindentf(FILE *fd, int depth, char *fmt, va_list ap)
{
ssize_t i;