summaryrefslogtreecommitdiff
path: root/tools/scan_includes.c
diff options
context:
space:
mode:
authoryenatch <yenatch@gmail.com>2017-05-28 01:12:16 -0400
committeryenatch <yenatch@gmail.com>2017-05-28 01:12:16 -0400
commitfe38946b0e2717c973839a4f8db647de0f1d9f3a (patch)
tree29a85eb4ef0a96d6ab9ea1c876aea009dd8af7d6 /tools/scan_includes.c
parent27ba16d827a4a50a1786c32691c2093bd05b1a2a (diff)
scan_includes: add --strict so it doesn't have to be default
Diffstat (limited to 'tools/scan_includes.c')
-rw-r--r--tools/scan_includes.c63
1 files changed, 56 insertions, 7 deletions
diff --git a/tools/scan_includes.c b/tools/scan_includes.c
index 4aba83eaa..bec42ed75 100644
--- a/tools/scan_includes.c
+++ b/tools/scan_includes.c
@@ -2,12 +2,24 @@
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
+#include <getopt.h>
void usage(void) {
- printf("Usage: scan_includes filename\n");
- exit(1);
+ printf("Usage: scan_includes [-h] [-s] filename\n"
+ "-h, --help\n"
+ " Print usage and exit\n"
+ "-s, --strict\n"
+ " Fail if a file cannot be read\n");
}
+struct Options {
+ bool help;
+ bool strict;
+};
+
+struct Options Options = {0};
+
+
void scan_file(char* filename) {
FILE* f;
long size;
@@ -17,9 +29,13 @@ void scan_file(char* filename) {
int length;
f = fopen(filename, "r");
- if (f == NULL) {
- fprintf(stderr, "Could not open file: '%s'\n", filename);
- exit(1);
+ if (!f) {
+ if (Options.strict) {
+ fprintf(stderr, "Could not open file: '%s'\n", filename);
+ exit(1);
+ } else {
+ return;
+ }
}
fseek(f, 0, SEEK_END);
@@ -68,10 +84,43 @@ void scan_file(char* filename) {
free(orig);
}
+void get_args(int argc, char *argv[]) {
+ while (1) {
+ struct option long_options[] = {
+ {"strict", no_argument, 0, 's'},
+ {"help", no_argument, 0, 'h'},
+ {0}
+ };
+ int i = 0;
+ int opt = getopt_long(argc, argv, "sh", long_options, &i);
+
+ if (opt == -1) {
+ break;
+ }
+
+ switch (opt) {
+ case 's':
+ Options.strict = true;
+ break;
+ case 'h':
+ Options.help = true;
+ break;
+ }
+ }
+}
+
int main(int argc, char* argv[]) {
- if (argc < 2) {
+ get_args(argc, argv);
+ argc -= optind;
+ argv += optind;
+ if (Options.help) {
usage();
+ return 0;
+ }
+ if (argc < 1) {
+ usage();
+ exit(1);
}
- scan_file(argv[1]);
+ scan_file(argv[0]);
return 0;
}