diff leo-obj/tool/main.c @ 130:87b82398a08b

leo-obj project subtree started, tiobjd tool moved into it
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Sun, 06 Apr 2014 22:14:39 +0000
parents ticoff/main.c@2c6b1319383b
children fbdb7686a9e9
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/leo-obj/tool/main.c	Sun Apr 06 22:14:39 2014 +0000
@@ -0,0 +1,60 @@
+/*
+ * tiobjd main() function and command dispatch
+ */
+
+#include <sys/types.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <strings.h>
+#include "globals.h"
+
+extern int cmd_basics();
+extern int cmd_disasm();
+extern int cmd_nm();
+extern int cmd_profile();
+extern int cmd_rawrel();
+extern int cmd_reloc();
+extern int cmd_sechdr();
+extern int cmd_symtab();
+extern int dump_filehdr_info();
+
+static struct cmdtab {
+	char	*cmd;
+	int	(*func)();
+} cmdtab[] = {
+	{"basics", cmd_basics},
+	{"disasm", cmd_disasm},
+	{"dumpsym", cmd_symtab},	/* backward compat */
+	{"hdr", dump_filehdr_info},
+	{"nm", cmd_nm},
+	{"profile", cmd_profile},
+	{"rawrel", cmd_rawrel},
+	{"reloc", cmd_reloc},
+	{"sechdr", cmd_sechdr},
+	{"symtab", cmd_symtab},
+	{0, 0}
+};
+
+main(argc, argv)
+	char **argv;
+{
+	struct cmdtab *tp;
+
+	if (argc < 3) {
+		fprintf(stderr, "usage: %s <objfile> <op> [args]\n", argv[0]);
+		exit(1);
+	}
+	objfilename = argv[1];
+	mmap_objfile();
+	initial_parse_hdr();
+	for (tp = cmdtab; tp->cmd; tp++)
+		if (!strcmp(tp->cmd, argv[2]))
+			break;
+	if (!tp->func) {
+		fprintf(stderr, "\"%s\": unknown or unimplemented command\n",
+			argv[2]);
+		exit(1);
+	}
+	return tp->func(argc - 2, argv + 2);
+}