Fixed tracing setup
[distributed.git] / src / distribute.cxx
blob493674b99ff96c18eeae947de078ee176b5f6b46
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 #define PROGRAM_NAME "distribute"
31 void version(void)
33 std::cout
34 << PROGRAM_NAME << " (" << PACKAGE_NAME << ") " << PACKAGE_VERSION << std::endl
35 << std::endl
36 << "Copyright (C) 2008 Francesco Salvestrini" << std::endl
37 << 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;
44 void help(void)
46 std::cout
47 << "Usage: " << PROGRAM_NAME << " [OPTION]... "<< std::endl
48 << 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
55 << std::endl
56 << "Report bugs to <" << PACKAGE_BUGREPORT << ">" << std::endl;
59 void hint(const std::string & message)
61 BUG_ON(message.size() == 0);
63 std::cout
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);
73 try {
74 int time_out = 0; // XXX FIXME: Change to a constant
75 std::string job = ""; // XXX FIXME: Change to a constant
77 int c;
78 //int digit_optind = 0;
79 while (1) {
80 //int this_option_optind = optind ? optind : 1;
81 int option_index = 0;
83 static struct option long_options[] = {
84 { "job", 1, 0, 'j' },
85 { "time-out", 1, 0, 't' },
86 { "debug", 0, 0, 'd' },
87 { "version", 0, 0, 'V' },
88 { "help", 0, 0, 'h' },
89 { 0, 0, 0, 0 }
92 c = getopt_long(argc, argv, "t:j:dVh",
93 long_options, &option_index);
94 if (c == -1) {
95 break;
98 switch (c) {
99 case 't':
101 // XXX FIXME:
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);
108 if (time_out < 0) {
109 hint("Wrong time-out value");
110 return 1;
112 break;
113 case 'j':
114 job = optarg;
115 break;
116 case 'd':
117 TR_CONFIG_LVL(TR_LVL_DEBUG);
118 break;
119 case 'V':
120 version();
121 return 0;
122 case 'h':
123 help();
124 return 0;
125 case '?':
126 hint("Unrecognized option");
127 return 1;
129 default:
130 BUG();
131 return 1;
135 // XXX FIXME: Add options related checks here
137 // Build configuration file path
138 std::string homedir = Environment::get("HOME");
139 std::string confdir =
140 homedir +
141 std::string("/") +
142 std::string(".") +
143 std::string(PACKAGE_TARNAME);
144 std::string conffile =
145 confdir +
146 std::string("/") +
147 std::string(PROGRAM_NAME);
149 // Dump (acquired and derived) infos
150 TR_DBG("Time out: '%d'\n", time_out);
151 TR_DBG("Job: '%s'\n", job.c_str());
152 TR_DBG("Home directory: '%s'\n", homedir.c_str());
153 TR_DBG("Configuration directory: '%s'\n", confdir.c_str());
154 TR_DBG("Configuration file: '%s'\n", conffile.c_str());
156 // Do the supposed work
157 MISSING_CODE();
158 } catch (...) {
159 BUG();
162 return 0;