Commit | Line | Data |
---|---|---|
9ac667e6 SR |
1 | // |
2 | // pkgutils | |
3 | // | |
4 | // Copyright (c) 2000-2005 Per Liden | |
5 | // | |
6 | // This program is free software; you can redistribute it and/or modify | |
7 | // it under the terms of the GNU General Public License as published by | |
8 | // the Free Software Foundation; either version 2 of the License, or | |
9 | // (at your option) any later version. | |
10 | // | |
11 | // This program is distributed in the hope that it will be useful, | |
12 | // but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 | // GNU General Public License for more details. | |
15 | // | |
16 | // You should have received a copy of the GNU General Public License | |
17 | // along with this program; if not, write to the Free Software | |
18 | // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, | |
19 | // USA. | |
20 | // | |
21 | ||
22 | #if (__GNUC__ < 3) | |
23 | #error This program requires GCC 3.x to compile. | |
24 | #endif | |
25 | ||
26 | #include <iostream> | |
27 | #include <string> | |
28 | #include <memory> | |
29 | #include <cstdlib> | |
30 | #include <libgen.h> | |
31 | #include "pkgutil.h" | |
32 | #include "pkgadd.h" | |
33 | #include "pkgrm.h" | |
34 | #include "pkginfo.h" | |
35 | ||
36 | using namespace std; | |
37 | ||
38 | static pkgutil* select_utility(const string& name) | |
39 | { | |
40 | if (name == "pkgadd") | |
41 | return new pkgadd; | |
42 | else if (name == "pkgrm") | |
43 | return new pkgrm; | |
44 | else if (name == "pkginfo") | |
45 | return new pkginfo; | |
46 | else | |
47 | throw runtime_error("command not supported by pkgutils"); | |
48 | } | |
49 | ||
50 | int main(int argc, char** argv) | |
51 | { | |
52 | string name = basename(argv[0]); | |
53 | ||
54 | try { | |
55 | auto_ptr<pkgutil> util(select_utility(name)); | |
56 | ||
57 | // Handle common options | |
58 | for (int i = 1; i < argc; i++) { | |
59 | string option(argv[i]); | |
60 | if (option == "-v" || option == "--version") { | |
61 | util->print_version(); | |
62 | return EXIT_SUCCESS; | |
63 | } else if (option == "-h" || option == "--help") { | |
64 | util->print_help(); | |
65 | return EXIT_SUCCESS; | |
66 | } | |
67 | } | |
68 | ||
69 | util->run(argc, argv); | |
70 | } catch (runtime_error& e) { | |
71 | cerr << name << ": " << e.what() << endl; | |
72 | return EXIT_FAILURE; | |
73 | } | |
74 | ||
75 | return EXIT_SUCCESS; | |
76 | } |