2 // Copyright (C) 2008 Francesco Salvestrini
4 // This program is free software; you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation; either version 2 of the License, or
7 // (at your option) any later version.
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
14 // You should have received a copy of the GNU General Public License along
15 // with this program; if not, write to the Free Software Foundation, Inc.,
16 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 #include "misc/debug.h"
27 #include "misc/environment.h"
29 #define PROGRAM_NAME "distribute"
34 << PROGRAM_NAME
<< " (" << PACKAGE_NAME
<< ") " << PACKAGE_VERSION
<< std::endl
36 << "Copyright (C) 2008 Francesco Salvestrini" << std::endl
38 << "This is free software. You may redistribute copies of it under the terms of" << std::endl
39 << "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>." << std::endl
40 << "There is NO WARRANTY, to the extent permitted by law." << std::endl
;
47 << "Usage: " << PROGRAM_NAME
<< " [OPTION]... "<< std::endl
49 << "Options: " << std::endl
50 << " -t, --time-out=TIME start time-out (seconds)" << std::endl
51 << " -j, --job=FILE use FILE as job to distribute" << std::endl
52 << " -d, --debug enable debugging traces" << std::endl
53 << " -h, --help print this help, then exit" << std::endl
54 << " -V, --version print version number, then exit" << std::endl
56 << "Report bugs to <" << PACKAGE_BUGREPORT
<< ">" << std::endl
;
59 void hint(const std::string
& message
)
61 BUG_ON(message
.size() == 0);
64 << message
<< std::endl
65 << "Try `" << PROGRAM_NAME
<< " -h' for more information." << std::endl
;
68 int main(int argc
, char * argv
[])
70 TR_CONFIG_LVL(TR_LVL_DEFAULT
);
71 TR_CONFIG_PFX(PROGRAM_NAME
);
74 int time_out
= 0; // XXX FIXME: Change to a constant
75 std::string job
= ""; // XXX FIXME: Change to a constant
78 //int digit_optind = 0;
80 //int this_option_optind = optind ? optind : 1;
83 static struct option long_options
[] = {
85 { "time-out", 1, 0, 't' },
86 { "debug", 0, 0, 'd' },
87 { "version", 0, 0, 'V' },
88 { "help", 0, 0, 'h' },
92 c
= getopt_long(argc
, argv
, "t:j:dVh",
93 long_options
, &option_index
);
102 // The current solution is ugly.
103 // Add modifiers (s, m, h) to
104 // this option in order to use
105 // different time granularity.
107 time_out
= atoi(optarg
);
109 hint("Wrong time-out value");
117 trace_level
= TR_LVL_DEBUG
;
126 hint("Unrecognized option");
135 // XXX FIXME: Add options related checks here
137 // Build configuration file path
138 std::string homedir
= Environment::get("HOME");
139 std::string confdir
=
143 std::string(PACKAGE_TARNAME
);
145 // Dump (acquired and derived) infos
146 TR_DBG("Time out: '%d'\n", time_out
);
147 TR_DBG("Job: '%s'\n", job
.c_str());
148 TR_DBG("Home directory: '%s'\n", homedir
.c_str());
149 TR_DBG("Configuration file: '%s'\n", confdir
.c_str());
151 // Do the supposed work