FreeCalypso > hg > freecalypso-reveng
comparison objgrep/main.c @ 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 |
comparison
equal
deleted
inserted
replaced
169:466b3926019c | 170:13a9ce1590fc |
---|---|
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include <string.h> | 8 #include <string.h> |
9 #include <strings.h> | 9 #include <strings.h> |
10 #include <unistd.h> | |
10 #include "globals.h" | 11 #include "globals.h" |
11 #include "intstruct.h" | 12 #include "intstruct.h" |
13 | |
14 static int rflag, sflag; | |
12 | 15 |
13 main(argc, argv) | 16 main(argc, argv) |
14 char **argv; | 17 char **argv; |
15 { | 18 { |
16 unsigned n; | 19 unsigned n; |
20 int c; | |
21 extern int optind; | |
17 | 22 |
18 if (argc != 4) { | 23 while ((c = getopt(argc, argv, "rs")) != EOF) |
19 fprintf(stderr, "usage: %s <objfile> <section> <binfile>\n", | 24 switch (c) { |
20 argv[0]); | 25 case 'r': |
21 exit(2); | 26 rflag++; |
22 } | 27 continue; |
23 objfilename = argv[1]; | 28 case 's': |
29 sflag++; | |
30 continue; | |
31 default: | |
32 usage: | |
33 fprintf(stderr, | |
34 "usage: %s [-rs] objfile section binfile\n", | |
35 argv[0]); | |
36 exit(2); | |
37 } | |
38 if (argc - optind != 3) | |
39 goto usage; | |
40 | |
41 objfilename = argv[optind]; | |
24 mmap_objfile(); | 42 mmap_objfile(); |
25 initial_parse_hdr(); | 43 initial_parse_hdr(); |
26 get_int_section_table(); | 44 get_int_section_table(); |
27 for (n = 0; n < nsections; n++) | 45 for (n = 0; n < nsections; n++) |
28 if (!strcmp(sections[n].name, argv[2])) { | 46 if (!strcmp(sections[n].name, argv[optind+1])) { |
29 grep_section = sections + n; | 47 grep_section = sections + n; |
30 break; | 48 break; |
31 } | 49 } |
32 if (!grep_section) { | 50 if (!grep_section) { |
33 fprintf(stderr, "no section named \"%s\" found in %s\n", | 51 fprintf(stderr, "no section named \"%s\" found in %s\n", |
34 argv[2], objfilename); | 52 argv[optind+1], objfilename); |
35 exit(2); | 53 exit(2); |
36 } | 54 } |
37 if (!grep_section->size) { | 55 if (!grep_section->size) { |
38 printf("%s:%s is empty\n", objfilename, grep_section->name); | 56 printf("%s:%s is empty\n", objfilename, grep_section->name); |
39 exit(1); | 57 exit(1); |
40 } | 58 } |
41 get_int_symbol_table(); | 59 get_int_symbol_table(); |
42 prepare_pattern(); | 60 prepare_pattern(); |
43 binfilename = argv[3]; | 61 binfilename = argv[optind+2]; |
44 mmap_binfile(); | 62 mmap_binfile(); |
45 if (!do_grep()) { | 63 if (!do_grep()) { |
46 printf("no match\n"); | 64 printf("no match\n"); |
47 exit(1); | 65 exit(1); |
48 } | 66 } |