/* * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. * Copyright 2011, Oliver Tappe * Distributed under the terms of the MIT License. */ #include "package.h" #include #include #include #include #include extern const char* __progname; const char* kCommandName = __progname; static const char* kUsage = "Usage: %s \n" "Creates, inspects, or extracts a Haiku package.\n" "\n" "Commands:\n" " create [ ] \n" " Creates package file from contents of current directory.\n" "\n" " -C - Change to directory before starting.\n" " -i - Use the package info file . It will be added as\n" " \".PackageInfo\", overriding a \".PackageInfo\" file,\n" " existing.\n" " -q - Be quiet (don't show any output except for errors).\n" " -v - Be verbose (show more info about created package).\n" "\n" " dump [ ] \n" " Dumps the TOC section of package file . For debugging only.\n" "\n" " extract [ ] \n" " Extracts the contents of package file .\n" "\n" " -C - Change to directory before extracting the " "contents\n" " of the archive.\n" " -i - Extract the .PackageInfo file to instead.\n" "\n" " list [ ] \n" " Lists the contents of package file .\n" "\n" " -a - Also list the file attributes.\n" "\n" "Common Options:\n" " -h, --help - Print this usage info.\n" ; void print_usage_and_exit(bool error) { fprintf(error ? stderr : stdout, kUsage, kCommandName); exit(error ? 1 : 0); } int main(int argc, const char* const* argv) { if (argc < 2) print_usage_and_exit(true); const char* command = argv[1]; if (strcmp(command, "create") == 0) return command_create(argc - 1, argv + 1); if (strcmp(command, "dump") == 0) return command_dump(argc - 1, argv + 1); if (strcmp(command, "extract") == 0) return command_extract(argc - 1, argv + 1); if (strcmp(command, "list") == 0) return command_list(argc - 1, argv + 1); if (strcmp(command, "help") == 0) print_usage_and_exit(false); else print_usage_and_exit(true); // never gets here return 0; }