From 962ad175aee634274b408ead38b13e6bc90e2fe7 Mon Sep 17 00:00:00 2001 From: lemon Date: Sat, 17 Jun 2023 23:26:45 +0200 Subject: basic ELF output --- main.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'main.c') 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] \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(); -- cgit v1.2.3