commit 9f9ec428a8a5857cf0d1a5d00ed5d3533d535b11
parent 5e82a4f6e2a6beb00682e148ab5d7da555c9aa87
Author: Roberto E. Vargas Caballero <k0ga@shike2.com>
Date: Thu, 23 Nov 2017 23:15:22 +0100
[nm] Add nm() function
This function is going to be the core of the program. At this moment
it does almost nothing, but at least it opens the file.
Diffstat:
M | nm/main.c | | | 34 | +++++++++++++++++++++++++++++----- |
1 file changed, 29 insertions(+), 5 deletions(-)
diff --git a/nm/main.c b/nm/main.c
@@ -1,17 +1,38 @@
static char sccsid[] = "@(#) ./nm/main.c";
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
#include "../inc/arg.h"
#include "../inc/scc.h"
+#include "../inc/myro.h"
char *argv0;
+int radix = 16;
+
+void
+nm(char *fname)
+{
+ FILE *fp;
+ struct myrohdr hdr;
+
+ if ((fp = fopen(fname, "rb")) == NULL)
+ goto file_error;
+ if (readhdr(fp, &hdr) == EOF)
+ goto file_error;
+ if (strncmp(hdr.magic, MYROMAGIC, MYROMAGIC_SIZ))
+ die("nm: %s: File format not recognized", fname);
+
+file_error:
+ die("nm: %s: %s", fname, strerror(errno));
+}
void
usage(void)
{
- fputs("nm [-APv][-efox][ -g| -u][-t format] file...\n", stderr);
+ fputs("nm [-APv][ -g| -u][-t format] file...\n", stderr);
exit(1);
}
@@ -20,18 +41,21 @@ main(int argc, char *argv[])
{
ARGBEGIN {
case 'A':
- case 'e':
- case 'f':
case 'g':
- case 'o':
case 'u':
case 'v':
- case 'x':
/* case 't': */
;
default:
usage();
} ARGEND
+ if (argc == 0) {
+ nm("a.out");
+ } else {
+ while (argc-- > 0)
+ nm(*++argv);
+ }
+
return 0;
}