diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/main.c | 82 |
1 files changed, 78 insertions, 4 deletions
@@ -70,6 +70,52 @@ struct option _longopts[] = { #endif static void +_help(const char *program_name) +{ + printf("Usage: %s OPTION... PACKAGE\n", program_name); + puts("Options:"); +#ifdef HAVE_GETOPT_LONG + puts(" -I, --info=CONTROL-FILE Print the named control file. If " + "this option is"); + puts(" given multiple times, the named " + "control files will be"); + puts(" printed in the order they appear in " + "the package."); + puts(" -f, --control Print the control file."); + puts(" -c, --contents List the contents of the filesystem " + "tree archive"); + puts(" portion of the package. It is " + "currently produced in"); + puts(" a format similar to that generated by " + "GNU and BusyBox"); + puts(" tar's verbose listing. User and " + "group IDs and names"); + puts(" are not checked against those on the " + "host system,"); + puts(" since they may differ."); + puts(" -h, --help Show this help information and exit."); + puts(" -V, --version Show version information and exit."); +#else + puts(" -I Print the named control file. If this option is given " + "multiple times, the"); + puts(" named control files will be printed in the order they " + "appear in the"); + puts(" package."); + puts(" -f Print the control file."); + puts(" -c List the contents of the filesystem tree archive portion " + "of the package."); + puts(" It is currently produced in a format similar to that " + "generated by GNU and"); + puts(" BusyBox tar's verbose listing. User and group IDs and " + "names are not"); + puts(" checked against those on the host system, since they may " + "differ."); + puts(" -h Show this help information and exit."); + puts(" -V Show version information and exit."); +#endif +} + +static void _version(void) { printf("%s %s%s\n", PACKAGE_NAME, PACKAGE_VERSION, PACKAGE_VERSION_GIT); @@ -83,14 +129,28 @@ _version(void) printf("Please report bugs to <%s>.\n", PACKAGE_BUGREPORT); } +static void +_help_tip(const char *program_name) +{ + fprintf(stderr, "Try \"%s %s\" for more information\n", program_name, +#ifdef HAVE_GETOPT_LONG + "--help" +#else + "-h" +#endif + ); +} + int main(int argc, char *argv[]) { + const char *program_name; struct opkg_opk_ustar_seek_name *control_files; int list_members; int opt; struct opkg_opk_opk *opk; + program_name = argv[0]; control_files = NULL; list_members = 0; #ifdef HAVE_GETOPT_LONG @@ -118,19 +178,33 @@ main(int argc, char *argv[]) list_members = 1; break; case 'h': - /* TODO */ - break; + _help(program_name); + return EXIT_SUCCESS; case 'V': _version(); return EXIT_SUCCESS; default: - /* TODO */ - break; + fprintf(stderr, "%s: Invalid option: \"%c\"\n", + program_name, optopt); + _help_tip(program_name); + return EXIT_FAILURE; } } argc -= optind; argv += optind; + if (argc < 1) { + fprintf(stderr, "%s: Missing package file operand\n", + program_name); + _help_tip(program_name); + return EXIT_FAILURE; + } else if (argc > 1) { + fprintf(stderr, "%s: Too many package file operands\n", + program_name); + _help_tip(program_name); + return EXIT_FAILURE; + } + /* Initialize outer archive. */ opk = opkg_opk_opk_init(argv[0]); if (opk == NULL) { |