static void display_version(void) { common_print_version(); printf("%1$s comes with NO WARRANTY\n" "to the extent permitted by law.\n" "\n" "You may redistribute copies of %1$s\n" "under the terms of the GNU General Public Licence.\n" "See the file `COPYING' for more information.\n", PROGRAM_NAME); exit(EXIT_SUCCESS); }
static int parse_opt(int argc, char * const argv[]) { while (1) { int key; key = getopt_long(argc, argv, "auMhV", long_options, NULL); if (key == -1) break; switch (key) { case 'a': args.all = 1; break; case 'u': args.ubinfo = 1; break; case 'M': args.map = 1; break; case 'h': display_help(); exit(EXIT_SUCCESS); case 'V': common_print_version(); exit(EXIT_SUCCESS); case ':': return errmsg("parameter is missing"); default: fprintf(stderr, "Use -h for help\n"); return -1; } } if (optind == argc - 1) args.node = argv[optind]; else if (optind < argc) return errmsg("more then one MTD device specified (use -h for help)"); if (args.all && args.node) args.node = NULL; if (args.map && !args.node) return errmsg("-M requires MTD device node name"); return 0; }
static int parse_opt(int argc, char * const argv[]) { ubiutils_srand(); args.image_seq = rand(); while (1) { int key, error = 0; unsigned long int image_seq; key = getopt_long(argc, argv, "nh?Vyqve:x:s:O:f:S:", long_options, NULL); if (key == -1) break; switch (key) { case 's': args.subpage_size = ubiutils_get_bytes(optarg); if (args.subpage_size <= 0) return errmsg("bad sub-page size: \"%s\"", optarg); if (!is_power_of_2(args.subpage_size)) return errmsg("sub-page size should be power of 2"); break; case 'O': args.vid_hdr_offs = simple_strtoul(optarg, &error); if (error || args.vid_hdr_offs <= 0) return errmsg("bad VID header offset: \"%s\"", optarg); break; case 'e': args.ec = simple_strtoull(optarg, &error); if (error || args.ec < 0) return errmsg("bad erase counter value: \"%s\"", optarg); if (args.ec >= EC_MAX) return errmsg("too high erase %llu, counter, max is %u", args.ec, EC_MAX); args.override_ec = 1; break; case 'f': args.image = optarg; break; case 'S': args.image_sz = ubiutils_get_bytes(optarg); if (args.image_sz <= 0) return errmsg("bad image-size: \"%s\"", optarg); break; case 'n': args.novtbl = 1; break; case 'y': args.yes = 1; break; case 'q': args.quiet = 1; break; case 'x': args.ubi_ver = simple_strtoul(optarg, &error); if (error || args.ubi_ver < 0) return errmsg("bad UBI version: \"%s\"", optarg); break; case 'Q': image_seq = simple_strtoul(optarg, &error); if (error || image_seq > 0xFFFFFFFF) return errmsg("bad UBI image sequence number: \"%s\"", optarg); args.image_seq = image_seq; break; case 'v': args.verbose = 1; break; case 'V': common_print_version(); exit(EXIT_SUCCESS); case 'h': case '?': printf("%s\n\n", doc); printf("%s\n\n", usage); printf("%s\n", optionsstr); exit(EXIT_SUCCESS); case ':': return errmsg("parameter is missing"); default: fprintf(stderr, "Use -h for help\n"); return -1; } } if (args.quiet && args.verbose) return errmsg("using \"-q\" and \"-v\" at the same time does not make sense"); if (optind == argc) return errmsg("MTD device name was not specified (use -h for help)"); else if (optind != argc - 1) return errmsg("more then one MTD device specified (use -h for help)"); if (args.image && args.novtbl) return errmsg("-n cannot be used together with -f"); args.node = argv[optind]; return 0; }
static void process_args(int argc, char *argv[]) { int arg_idx; int req_set = 0; for (;;) { int c; c = getopt_long(argc, argv, short_opts, long_opts, NULL); if (c == EOF) break; switch (c) { case 'h': usage(0); break; case 'i': req = REQUEST_ISLOCKED; req_set++; break; case 'l': req = REQUEST_LOCK; req_set++; break; case 'u': req = REQUEST_UNLOCK; req_set++; break; case 'v': common_print_version(); exit(0); default: usage(1); break; } } if (req_set > 1) { errmsg("cannot specify more than one lock/unlock/islocked option"); usage(1); } arg_idx = optind; /* Sanity checks */ if (argc - arg_idx < 1) { errmsg("too few arguments"); usage(1); } else if (argc - arg_idx > 3) { errmsg("too many arguments"); usage(1); } /* First non-option argument */ dev = argv[arg_idx++]; /* Second non-option argument */ if (arg_idx < argc) offs_s = argv[arg_idx++]; else offs_s = NULL; /* Third non-option argument */ if (arg_idx < argc) count_s = argv[arg_idx++]; else count_s = NULL; }