[PATCH] Respect outfile
[Thread Prev] | [Thread Next]
- Subject: [PATCH] Respect outfile
- From: Ryan Gonzalez <rymg19@xxxxxxxxx>
- Date: Thu, 15 Jan 2015 14:22:33 -0600
- To: myrddin-dev@xxxxxxxxxxxxxx
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. :) -- Ryan If anybody ever asks me why I prefer C++ to C, my answer will be simple: "It's becauseslejfp23(@#Q*(E*EIdc-SEGFAULT. Wait, I don't think that was nul-terminated." Personal reality distortion fields are immune to contradictory evidence. - srean Check out my website: http://kirbyfan64.github.io/
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");
}
diff --git a/parse/util.c b/parse/util.c
index b43ee43..9b3b29e 100644
--- a/parse/util.c
+++ b/parse/util.c
@@ -385,7 +385,7 @@ char *swapsuffix(char *buf, size_t sz, char *s, char *suf, char *swap)
/* 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 @@ void findentf(FILE *fd, int depth, char *fmt, ...)
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;
diff --git a/doc/mc.1 b/doc/mc.1 index 471d013..6261ad8 100644 --- a/doc/mc.1 +++ b/doc/mc.1 @@ -23,7 +23,7 @@ will simply be appended to it. .PP The following architectures are currently supported: -.TP +.TP 6m x86-64 @@ -52,7 +52,7 @@ Specify that the generated code should be placed in .TP .B -S -Generate assembly code instead of an object file. +Generate assembly code along with the object file. .SH EXAMPLE .EX
| Re: [PATCH] Respect outfile | Ori Bernstein <ori@xxxxxxxxxxxxxx> |
- Prev by Date: Re: Exporting functions
- Next by Date: Re: [PATCH] Respect outfile
- Previous by thread: Re: Exporting functions
- Next by thread: Re: [PATCH] Respect outfile
- Index(es):