summaryrefslogtreecommitdiff
path: root/6/main.c
diff options
context:
space:
mode:
authorRyan Gonzalez <rymg19@gmail.com>2015-01-15 14:22:33 -0600
committerOri Bernstein <ori@eigenstate.org>2015-01-15 17:20:36 -0500
commitc88028d9a01bb86e4002efbeedb06199f55300ac (patch)
treeccf9801bec00574da3777bb56b659e0694d9e4d9 /6/main.c
parente9c151989b3e9d75957e87d85d426581ec91515f (diff)
downloadmc-c88028d9a01bb86e4002efbeedb06199f55300ac.tar.gz
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. :)
Diffstat (limited to '6/main.c')
-rw-r--r--6/main.c54
1 files changed, 43 insertions, 11 deletions
diff --git a/6/main.c b/6/main.c
index 46af550..9918e07 100644
--- a/6/main.c
+++ b/6/main.c
@@ -48,6 +48,17 @@ static void usage(char *prog)
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 @@ static void assemble(char *asmsrc, char *path)
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 @@ static void genuse(char *path)
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 @@ int main(int argc, char **argv)
Optctx ctx;
size_t i;
+ outfile = NULL;
+
optinit(&ctx, "d:hSo:I:9G", argv, argc);
asmsyntax = Defaultasm;
while (!optdone(&ctx)) {
@@ -168,6 +189,14 @@ int main(int argc, char **argv)
}
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 @@ int main(int argc, char **argv)
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");
}