Rearranged beacon tracing
[distributed.git] / src / distribute.cxx
blobd125d98b7a72d32a2c887a6f381534a18ddc3588
1 //
2 // Copyright (C) 2008 Francesco Salvestrini
3 //
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.
8 //
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.
19 #include "config.h"
21 #include <unistd.h>
22 #include <getopt.h>
23 #include <string>
24 #include <iostream>
26 #include "misc/debug.h"
27 #include "misc/environment.h"
29 void version(void)
31 std::cout
32 << PACKAGE << " (" << PACKAGE_NAME << ") " << PACKAGE_VERSION << std::endl
33 << std::endl
34 << "Copyright (C) 2008 Francesco Salvestrini" << std::endl
35 << std::endl
36 << "This is free software. You may redistribute copies of it under the terms of" << std::endl
37 << "the GNU General Public License <http://www.gnu.org/licenses/gpl.html>." << std::endl
38 << "There is NO WARRANTY, to the extent permitted by law." << std::endl;
42 void help(void)
44 std::cout
45 << "Usage: " << PACKAGE << " [OPTION]... "<< std::endl
46 << std::endl
47 << "Options: " << std::endl
48 << " -t, --time-out=TIME start time-out (seconds)" << std::endl
49 << " -j, --job=FILE use FILE as job to distribute" << std::endl
50 << " -d, --debug enable debugging traces" << std::endl
51 << " -h, --help print this help, then exit" << std::endl
52 << " -V, --version print version number, then exit" << std::endl
53 << std::endl
54 << "Report bugs to <" << PACKAGE_BUGREPORT << ">" << std::endl;
57 void hint(const std::string & message)
59 BUG_ON(message.size() == 0);
61 std::cout
62 << message << std::endl
63 << "Try `" << PACKAGE << " -h' for more information." << std::endl;
66 int main(int argc, char * argv[])
68 try {
69 int time_out = 0; // XXX FIXME: Change to a constant
70 std::string job = ""; // XXX FIXME: Change to a constant
72 int c;
73 //int digit_optind = 0;
74 while (1) {
75 //int this_option_optind = optind ? optind : 1;
76 int option_index = 0;
78 static struct option long_options[] = {
79 { "job", 1, 0, 'j' },
80 { "time-out", 1, 0, 't' },
81 { "debug", 0, 0, 'd' },
82 { "version", 0, 0, 'V' },
83 { "help", 0, 0, 'h' },
84 { 0, 0, 0, 0 }
87 c = getopt_long(argc, argv, "t:j:dVh",
88 long_options, &option_index);
89 if (c == -1) {
90 break;
93 switch (c) {
94 case 't':
96 // XXX FIXME:
97 // The current solution is ugly.
98 // Add modifiers (s, m, h) to
99 // this option in order to use
100 // different time granularity.
102 time_out = atoi(optarg);
103 if (time_out < 0) {
104 hint("Wrong time-out value");
105 return 1;
107 break;
108 case 'j':
109 job = optarg;
110 break;
111 case 'd':
112 trace_level = TR_LVL_DEBUG;
113 break;
114 case 'V':
115 version();
116 return 0;
117 case 'h':
118 help();
119 return 0;
120 case '?':
121 hint("Unrecognized option");
122 return 1;
124 default:
125 BUG();
126 return 1;
130 // XXX FIXME: Add options related checks here
132 // Build configuration file path
133 std::string homedir = Environment::get("HOME");
134 std::string confdir =
135 homedir +
136 std::string("/") +
137 std::string(".") +
138 std::string(PACKAGE_TARNAME);
140 // Dump (acquired and derived) infos
141 TR_DBG("Time out: '%d'\n", time_out);
142 TR_DBG("Job: '%s'\n", job.c_str());
143 TR_DBG("Home directory: '%s'\n", homedir.c_str());
144 TR_DBG("Configuration file: '%s'\n", confdir.c_str());
146 // Do the supposed work
147 MISSING_CODE();
148 } catch (...) {
149 BUG();
152 return 0;