changeset 170:13a9ce1590fc

objgrep: parsing of -r and -s options implemented, no functionality yet
author Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
date Fri, 04 Jul 2014 02:56:21 +0000
parents 466b3926019c
children ddbfc1a1a811
files objgrep/main.c
diffstat 1 files changed, 27 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/objgrep/main.c	Fri Jul 04 01:45:03 2014 +0000
+++ b/objgrep/main.c	Fri Jul 04 02:56:21 2014 +0000
@@ -7,31 +7,49 @@
 #include <stdlib.h>
 #include <string.h>
 #include <strings.h>
+#include <unistd.h>
 #include "globals.h"
 #include "intstruct.h"
 
+static int rflag, sflag;
+
 main(argc, argv)
 	char **argv;
 {
 	unsigned n;
+	int c;
+	extern int optind;
 
-	if (argc != 4) {
-		fprintf(stderr, "usage: %s <objfile> <section> <binfile>\n",
-			argv[0]);
-		exit(2);
-	}
-	objfilename = argv[1];
+	while ((c = getopt(argc, argv, "rs")) != EOF)
+		switch (c) {
+		case 'r':
+			rflag++;
+			continue;
+		case 's':
+			sflag++;
+			continue;
+		default:
+		usage:
+			fprintf(stderr,
+				"usage: %s [-rs] objfile section binfile\n",
+				argv[0]);
+			exit(2);
+		}
+	if (argc - optind != 3)
+		goto usage;
+
+	objfilename = argv[optind];
 	mmap_objfile();
 	initial_parse_hdr();
 	get_int_section_table();
 	for (n = 0; n < nsections; n++)
-		if (!strcmp(sections[n].name, argv[2])) {
+		if (!strcmp(sections[n].name, argv[optind+1])) {
 			grep_section = sections + n;
 			break;
 		}
 	if (!grep_section) {
 		fprintf(stderr, "no section named \"%s\" found in %s\n",
-			argv[2], objfilename);
+			argv[optind+1], objfilename);
 		exit(2);
 	}
 	if (!grep_section->size) {
@@ -40,7 +58,7 @@
 	}
 	get_int_symbol_table();
 	prepare_pattern();
-	binfilename = argv[3];
+	binfilename = argv[optind+2];
 	mmap_binfile();
 	if (!do_grep()) {
 		printf("no match\n");