+ static struct option long_options[] = {
+ { "batchmode", required_argument, 0, 'b' },
+ { "help", no_argument, 0, 'h' },
+ { "verbose", required_argument, 0, 'v' },
+ { 0, 0, 0, 0 }
+ };
+ int option_index;
+ int c;
+
+ do {
+ c = getopt_long(argc, argv, "b:hv:", long_options, &option_index);
+ switch (c) {
+ case 'b':
+ if (!optarg || !*optarg) {
+ printf("Invalid argument\n");
+ help();
+ return -EINVAL;
+ }
+
+ if (s_info.input_fd != STDIN_FILENO) {
+ /* Close the previously, opened file */
+ close(s_info.input_fd);
+ }
+
+ s_info.input_fd = open(optarg, O_RDONLY);
+ if (s_info.input_fd < 0) {
+ printf("Unable to access %s (%s)\n", optarg, strerror(errno));
+ return -EIO;
+ }
+ break;
+ case 'h':
+ help();
+ return 0;
+ case 'v':
+ if (!optarg || !*optarg) {
+ printf("Invalid argument\n");
+ help();
+ return -EINVAL;
+ }
+
+ s_info.verbose = !strcmp(optarg, "true");
+ break;
+ default:
+ break;
+ }
+ } while (c != -1);