# HG changeset patch # User Michael Spacefalcon # Date 1404442581 0 # Node ID 13a9ce1590fc785d1dd0da270cddfbb3d769dea2 # Parent 466b3926019c86bbddda8c8a90e036e57fb54bd7 objgrep: parsing of -r and -s options implemented, no functionality yet diff -r 466b3926019c -r 13a9ce1590fc objgrep/main.c --- 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 #include #include +#include #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
\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");