ref: 0298b8c6607844bc77deb5d21da651a4954af076
parent: 30d5a2c869c5f47cca98fdedb9024d462c6b9191
author: Roberto E. Vargas Caballero <[email protected]>
date: Mon Dec 11 14:26:41 EST 2017
[as] Add command line options
--- a/as/as.h
+++ b/as/as.h
@@ -175,4 +175,4 @@
extern TUINT maxaddr;
extern int endian;
extern Symbol *linesym, *symlist;
-extern char *filename;
+extern char *infile;
--- a/as/main.c
+++ b/as/main.c
@@ -7,8 +7,20 @@
#include <string.h>
#include "../inc/scc.h"
+#include "../inc/arg.h"
#include "as.h"
+char *argv0;
+char *outfile, *infile;
+
+
+static void
+cleanup(void)
+{
+ if (outfile)
+ remove(outfile);
+}
+
static int
cmp(const void *f1, const void *f2)
{
@@ -81,7 +93,7 @@
if (fclose(fp))
die("as: error reading from input file '%s'", fname);
if (pass == 2)
- writeout("a.out");
+ writeout(outfile);
/*
* kill tmp symbols because they are not needed anymore
*/
@@ -100,15 +112,27 @@
int
main(int argc, char *argv[])
{
- if (argc != 2)
+ outfile = "a.out";
+
+ ARGBEGIN {
+ case 'o':
+ outfile = EARGF(usage());
+ break;
+ default:
usage();
+ } ARGEND
+ if (argc != 1)
+ usage();
+ infile = *argv;
+
+ atexit(cleanup);
iarch();
- filename = argv[1];
for (pass = 1; pass <= 2; pass++) {
- if (!dopass(filename))
+ if (!dopass(infile))
return 1;
}
+ outfile = NULL;
return 0;
}
--- a/as/parser.c
+++ b/as/parser.c
@@ -12,7 +12,6 @@
#define NARGS 20
#define MAXLINE 100
-char *filename;
int nerrors;
jmp_buf recover;
@@ -24,7 +23,7 @@
va_list va;
va_start(va, msg);
- fprintf(stderr, "as:%s:%u: ", filename, lineno);
+ fprintf(stderr, "as:%s:%u: ", infile, lineno);
vfprintf(stderr, msg, va);
putc('\n', stderr);
nerrors++;