diff options
-rw-r--r-- | src/main.c | 143 |
1 files changed, 103 insertions, 40 deletions
@@ -36,26 +36,32 @@ extern const char *PACKAGE_VERSION_GIT; -const char *_optstring = "I:fchV"; +const char *_optstring = "f:F:lLhV"; #ifdef HAVE_GETOPT_LONG struct option _longopts[] = { { - .name = "info", + .name = "control-file", .has_arg = 1, .flag = NULL, - .val = 'I', + .val = 'f', }, { - .name = "control", + .name = "data-file", + .has_arg = 1, + .flag = NULL, + .val = 'F', + }, + { + .name = "list-control", .has_arg = 0, .flag = NULL, - .val = 'f', + .val = 'l', }, { - .name = "contents", + .name = "list-data", .has_arg = 0, .flag = NULL, - .val = 'c', + .val = 'L', }, { .name = "help", @@ -75,38 +81,52 @@ struct option _longopts[] = { static void _help(const char *program_name) { - printf(_("Usage: %s OPTION... PACKAGE\n"), program_name); + printf(_("Usage: %s [-f CONTROL-FILE] [-F DATA-FILE] [-l] [-L] " + "PACKAGE\n"), program_name); #ifdef HAVE_GETOPT_LONG puts(_("Options:\n" -" -I, --info=CONTROL-FILE Print the named control file. If this option is\n" -" given multiple times, the named control files will " - "be\n" -" printed in the order they appear in the package.\n" -" -f, --control Print the control file.\n" -" -c, --contents List the contents of the filesystem tree archive\n" -" portion of the package. It is currently produced " - "in\n" -" a format similar to that generated by GNU and " - "BusyBox\n" -" tar's verbose listing. User and group IDs and " - "names\n" -" are not checked against those on the host system,\n" -" since they may differ.\n" -" -h, --help Show this help information and exit.\n" -" -V, --version Show version information and exit.")); +" -f, --control-file=CONTROL-FILE Print the contents of the named control " + "file.\n" +" If this option is given multiple times, the" + "\n" +" named control files will be printed in the" + "\n" +" order they appear in the package.\n" +" -F, --data-file=DATA-FILE Print the contents of the named data file." + "\n" +" If this option is given multiple times, the" + "\n" +" named data files will be printed in the " + "order\n" +" they appear in the package.\n" +" -l, --list-control List the control files.\n" +" -L, --list-data List the data files. The list is currently" + "\n" +" produced in a format similar to that\n" +" generated by GNU and BusyBox tar's verbose" + "\n" +" listing. User and group IDs and names are" + "\n" +" not checked against those on the host " + "system,\n" +" since they may differ.\n" +" -h, --help Show this help information and exit.\n" +" -V, --version Show version information and exit.")); #else puts(_("Options:\n" -" -I Print the named control file. If this option is given multiple times, " - "the\n" -" named control files will be printed in the order they appear in the\n" -" package.\n" -" -f Print the control file.\n" -" -c List the contents of the filesystem tree archive portion of the " - "package.\n" -" It is currently produced in a format similar to that generated by GNU " - "and\n" -" BusyBox tar's verbose listing. User and group IDs and names are not\n" -" checked against those on the host system, since they may differ.\n" +" -f Print the contents of the named control file. If this option is given\n" +" multiple times, the named control files will be printed in the order " + "they\n" +" appear in the package.\n" +" -F Print the contents of the named data file. If this option is given\n" +" multiple times, the named data files will be printed in the order they\n" +" appear in the package.\n" +" -l List the control files.\n" +" -L List the data files. The list is currently produced in a format " + "similar\n" +" to that generated by GNU and BusyBox tar's verbose listing. User and\n" +" group IDs and names are not checked against those on the host system,\n" +" since they may differ.\n" " -h Show this help information and exit.\n" " -V Show version information and exit.")); #endif @@ -142,11 +162,23 @@ _help_tip(const char *program_name) ); } +static void +_opt_mutex(const char *program_name, char opt1, char opt2) +{ + fprintf(stderr, _("%s: Options -%c and -%c are mutually exclusive\n"), + program_name, opt1, opt2); + _help_tip(program_name); +} + int main(int argc, char *argv[]) { const char *program_name; struct opkg_opk_opk *opk; + int opt_f; + int opt_F; + int opt_l; + int opt_L; int opt; #ifdef ENABLE_NLS @@ -166,7 +198,11 @@ main(int argc, char *argv[]) return EXIT_FAILURE; } - opterr = 0; + opterr = 0; + opt_f = 0; + opt_F = 0; + opt_l = 0; + opt_L = 0; #ifdef HAVE_GETOPT_LONG while ((opt = getopt_long(argc, argv, _optstring, _longopts, NULL)) != -1) { @@ -174,21 +210,48 @@ main(int argc, char *argv[]) while ((opt = getopt(argc, argv, _optstring)) != -1) { #endif switch(opt) { - case 'I': + case 'f': + if (opt_l > 0) { + _opt_mutex(program_name, 'f', 'l'); + opkg_opk_opk_free(opk); + return EXIT_FAILURE; + } + opt_f = 1; if (opkg_opk_opk_print_control(opk, optarg) != OPKG_OPK_OK) { opkg_opk_opk_free(opk); return EXIT_FAILURE; } break; - case 'f': - if (opkg_opk_opk_print_control(opk, "control") + case 'F': + if (opt_L > 0) { + _opt_mutex(program_name, 'F', 'L'); + opkg_opk_opk_free(opk); + return EXIT_FAILURE; + } + opt_F = 1; + if (opkg_opk_opk_print_data(opk, optarg) != OPKG_OPK_OK) { opkg_opk_opk_free(opk); return EXIT_FAILURE; } break; - case 'c': + case 'l': + if (opt_f > 0) { + _opt_mutex(program_name, 'f', 'l'); + opkg_opk_opk_free(opk); + return EXIT_FAILURE; + } + opt_l = 1; + opkg_opk_opk_list_control(opk); + break; + case 'L': + if (opt_F > 0) { + _opt_mutex(program_name, 'F', 'L'); + opkg_opk_opk_free(opk); + return EXIT_FAILURE; + } + opt_L = 1; opkg_opk_opk_list_data(opk); break; case 'h': |