1 /* 2 * Copyright 2009, Ingo Weinhold, ingo_weinhold@gmx.de. 3 * Copyright 2011, Oliver Tappe <zooey@hirschkaefer.de> 4 * Distributed under the terms of the MIT License. 5 */ 6 7 8 #include "package.h" 9 10 #include <errno.h> 11 #include <getopt.h> 12 #include <stdio.h> 13 #include <stdlib.h> 14 #include <string.h> 15 16 17 extern const char* __progname; 18 const char* kCommandName = __progname; 19 20 21 static const char* kUsage = 22 "Usage: %s <command> <command args>\n" 23 "Creates, inspects, or extracts a Haiku package.\n" 24 "\n" 25 "Commands:\n" 26 " create [ <options> ] <package>\n" 27 " Creates package file <package> from contents of current directory.\n" 28 "\n" 29 " -C <dir> - Change to directory <dir> before starting.\n" 30 " -i <info> - Use the package info file <info>. It will be added as\n" 31 " \".PackageInfo\", overriding a \".PackageInfo\" file,\n" 32 " existing.\n" 33 " -q - Be quiet (don't show any output except for errors).\n" 34 " -v - Be verbose (show more info about created package).\n" 35 "\n" 36 " dump [ <options> ] <package>\n" 37 " Dumps the TOC section of package file <package>. For debugging only.\n" 38 "\n" 39 " extract [ <options> ] <package> [ <entries>... ]\n" 40 " Extracts the contents of package file <package>. If <entries> are\n" 41 " specified, only those entries are extracted (directories " 42 "recursively).\n" 43 "\n" 44 " -C <dir> - Change to directory <dir> before extracting the " 45 "contents\n" 46 " of the archive.\n" 47 " -i <info> - Extract the .PackageInfo file to <info> instead.\n" 48 "\n" 49 " list [ <options> ] <package>\n" 50 " Lists the contents of package file <package>.\n" 51 "\n" 52 " -a - Also list the file attributes.\n" 53 "\n" 54 "Common Options:\n" 55 " -h, --help - Print this usage info.\n" 56 ; 57 58 59 void 60 print_usage_and_exit(bool error) 61 { 62 fprintf(error ? stderr : stdout, kUsage, kCommandName); 63 exit(error ? 1 : 0); 64 } 65 66 67 int 68 main(int argc, const char* const* argv) 69 { 70 if (argc < 2) 71 print_usage_and_exit(true); 72 73 const char* command = argv[1]; 74 if (strcmp(command, "create") == 0) 75 return command_create(argc - 1, argv + 1); 76 77 if (strcmp(command, "dump") == 0) 78 return command_dump(argc - 1, argv + 1); 79 80 if (strcmp(command, "extract") == 0) 81 return command_extract(argc - 1, argv + 1); 82 83 if (strcmp(command, "list") == 0) 84 return command_list(argc - 1, argv + 1); 85 86 if (strcmp(command, "help") == 0) 87 print_usage_and_exit(false); 88 else 89 print_usage_and_exit(true); 90 91 // never gets here 92 return 0; 93 } 94