CRUX-ARM : Home

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