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>\n" 40 " Extracts the contents of package file <package>.\n" 41 "\n" 42 " -C <dir> - Change to directory <dir> before extracting the " 43 "contents\n" 44 " of the archive.\n" 45 " -i <info> - Extract the .PackageInfo file to <info> instead.\n" 46 "\n" 47 " list [ <options> ] <package>\n" 48 " Lists the contents of package file <package>.\n" 49 "\n" 50 " -a - Also list the file attributes.\n" 51 "\n" 52 "Common Options:\n" 53 " -h, --help - Print this usage info.\n" 54 ; 55 56 57 void 58 print_usage_and_exit(bool error) 59 { 60 fprintf(error ? stderr : stdout, kUsage, kCommandName); 61 exit(error ? 1 : 0); 62 } 63 64 65 int 66 main(int argc, const char* const* argv) 67 { 68 if (argc < 2) 69 print_usage_and_exit(true); 70 71 const char* command = argv[1]; 72 if (strcmp(command, "create") == 0) 73 return command_create(argc - 1, argv + 1); 74 75 if (strcmp(command, "dump") == 0) 76 return command_dump(argc - 1, argv + 1); 77 78 if (strcmp(command, "extract") == 0) 79 return command_extract(argc - 1, argv + 1); 80 81 if (strcmp(command, "list") == 0) 82 return command_list(argc - 1, argv + 1); 83 84 if (strcmp(command, "help") == 0) 85 print_usage_and_exit(false); 86 else 87 print_usage_and_exit(true); 88 89 // never gets here 90 return 0; 91 } 92