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 " -q - be quiet (don't show any output except for errors).\n" 31 " -v - be verbose (show more info about created package).\n" 32 "\n" 33 " dump [ <options> ] <package>\n" 34 " Dumps the TOC section of package file <package>. For debugging only.\n" 35 "\n" 36 " extract [ <options> ] <package>\n" 37 " Extracts the contents of package file <package>.\n" 38 "\n" 39 " -C <dir> - Change to directory <dir> before extracting the " 40 "contents\n" 41 " of the archive.\n" 42 "\n" 43 " list [ <options> ] <package>\n" 44 " Lists the contents of package file <package>.\n" 45 "\n" 46 " -a - Also list the file attributes.\n" 47 "\n" 48 "Common Options:\n" 49 " -h, --help - Print this usage info.\n" 50 ; 51 52 53 void 54 print_usage_and_exit(bool error) 55 { 56 fprintf(error ? stderr : stdout, kUsage, kCommandName); 57 exit(error ? 1 : 0); 58 } 59 60 61 int 62 main(int argc, const char* const* argv) 63 { 64 if (argc < 2) 65 print_usage_and_exit(true); 66 67 const char* command = argv[1]; 68 if (strcmp(command, "create") == 0) 69 return command_create(argc - 1, argv + 1); 70 71 if (strcmp(command, "dump") == 0) 72 return command_dump(argc - 1, argv + 1); 73 74 if (strcmp(command, "extract") == 0) 75 return command_extract(argc - 1, argv + 1); 76 77 if (strcmp(command, "list") == 0) 78 return command_list(argc - 1, argv + 1); 79 80 if (strcmp(command, "help") == 0) 81 print_usage_and_exit(false); 82 else 83 print_usage_and_exit(true); 84 85 // never gets here 86 return 0; 87 } 88