/* * process_flags - parse the command line options * * It will not return if an error is encountered. */ static void process_flags (int argc, char **argv) { int arg; /* * Parse the command line arguments */ while ((arg = getopt (argc, argv, "qrs")) != EOF) { switch (arg) { case 'q': /* quiet - ignored for now */ break; case 'r': read_only = true; break; case 's': sort_mode = true; break; default: usage (); } } if (sort_mode && read_only) { fprintf (stderr, _("%s: -s and -r are incompatibile\n"), Prog); exit (E_USAGE); } /* * Make certain we have the right number of arguments */ #ifdef SHADOWGRP if ((argc < optind) || (argc > (optind + 2))) #else if ((argc < optind) || (argc > (optind + 1))) #endif { usage (); } /* * If there are two left over filenames, use those as the group and * group password filenames. */ if (optind != argc) { grp_file = argv[optind]; gr_setdbname (grp_file); use_system_grp_file = false; } #ifdef SHADOWGRP if ((optind + 2) == argc) { sgr_file = argv[optind + 1]; sgr_setdbname (sgr_file); is_shadow = true; use_system_sgr_file = false; } else if (optind == argc) { is_shadow = sgr_file_present (); } #endif }
/* * process_flags - parse the command line options * * It will not return if an error is encountered. */ static void process_flags (int argc, char **argv) { int c; static struct option long_options[] = { {"help", no_argument, NULL, 'h'}, {"quiet", no_argument, NULL, 'q'}, {"read-only", no_argument, NULL, 'r'}, {"root", required_argument, NULL, 'R'}, {"sort", no_argument, NULL, 's'}, {NULL, 0, NULL, '\0'} }; /* * Parse the command line arguments */ while ((c = getopt_long (argc, argv, "hqrR:s", long_options, NULL)) != -1) { switch (c) { case 'h': usage (E_SUCCESS); /*@notreached@*/break; case 'q': /* quiet - ignored for now */ break; case 'r': read_only = true; break; case 'R': /* no-op, handled in process_root_flag () */ break; case 's': sort_mode = true; break; default: usage (E_USAGE); } } if (sort_mode && read_only) { fprintf (stderr, _("%s: -s and -r are incompatible\n"), Prog); exit (E_USAGE); } /* * Make certain we have the right number of arguments */ #ifdef SHADOWGRP if (argc > (optind + 2)) #else if (argc > (optind + 1)) #endif { usage (E_USAGE); } /* * If there are two left over filenames, use those as the group and * group password filenames. */ if (optind != argc) { grp_file = argv[optind]; gr_setdbname (grp_file); use_system_grp_file = false; } #ifdef SHADOWGRP if ((optind + 2) == argc) { sgr_file = argv[optind + 1]; sgr_setdbname (sgr_file); is_shadow = true; use_system_sgr_file = false; } else if (optind == argc) { is_shadow = sgr_file_present (); } #endif }