aboutsummaryrefslogtreecommitdiffhomepage
path: root/main.c
diff options
context:
space:
mode:
authorlemon <lsof@mailbox.org>2023-06-17 23:26:45 +0200
committerlemon <lsof@mailbox.org>2023-06-17 23:26:45 +0200
commit962ad175aee634274b408ead38b13e6bc90e2fe7 (patch)
treecfda733adf56ed12e829f594e0b6d66f0a1a7a70 /main.c
parentec28e9057e84b92acabb7ebf9122af59738917ad (diff)
basic ELF output
Diffstat (limited to 'main.c')
-rw-r--r--main.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/main.c b/main.c
index 5e3e635..c3dbfeb 100644
--- a/main.c
+++ b/main.c
@@ -25,10 +25,10 @@ optval(const char *arg, const char *opt)
}
static void
-optparse(const char **file, const char **targ, char **args)
+optparse(const char **file, const char **outfile, const char **targ, char **args)
{
const char *arg, *x;
- *file = *targ = NULL;
+ *outfile = *file = *targ = NULL;
while ((arg = *++args)) {
if (*arg++ != '-') {
*file = arg-1;
@@ -52,6 +52,10 @@ optparse(const char **file, const char **targ, char **args)
case 'r': ccopt.dbg.r = 1; break;
default: warn(NULL, "-d: invalid debug flag %'c", *arg);
}
+ } else if (*arg == 'o') {
+ if (arg[1]) *outfile = arg+1;
+ else if (args[1]) *outfile = *++args;
+ else goto Bad;
} else Bad: warn(NULL, "invalid option: %'s", arg-1);
}
}
@@ -70,19 +74,19 @@ int
main(int argc, char **argv)
{
struct parser pr;
- const char *file, *targ;
+ const char *file, *outfile, *targ;
atexit(flushstd);
detectcolor();
ccopt.cstd = STDC99; /* C99 by default */
- optparse(&file, &targ, argv);
+ optparse(&file, &outfile, &targ, argv);
if (!file) {
efmt("usage: %s [options] <file>\n", *argv);
return 1;
}
targ_init(targ ? targ : "amd64-sysv");
- objini("a.out");
+ objini(outfile ? outfile : "a.out");
initparser(&pr, file);
parse(&pr);
if (!nerror) objfini();