From: Francois Fleuret Date: Mon, 24 Dec 2012 16:47:57 +0000 (+0100) Subject: Moved all the global variables into Global global; X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mtp.git;a=commitdiff_plain;h=23dae2d97cfbc14f63d3d2c9050d3d4f1ef7bd66 Moved all the global variables into Global global; --- diff --git a/mtp.cc b/mtp.cc index 300e4a6..d77bd62 100644 --- a/mtp.cc +++ b/mtp.cc @@ -35,9 +35,11 @@ using namespace std; #define FILENAME_SIZE 1024 -char trajectory_filename[FILENAME_SIZE]; -char graph_filename[FILENAME_SIZE]; -int verbose; +struct Global { + char trajectory_filename[FILENAME_SIZE]; + char graph_filename[FILENAME_SIZE]; + int verbose; +} global; void usage(ostream *os) { (*os) << "mtp [-h|--help] [--help-formats] [-v|--verbose] [-t|--trajectory-filename ] [-g|--graph-filename ] []" << endl; @@ -95,41 +97,41 @@ void do_tracking(istream *in_tracker) { timeval start_time, end_time; MTPTracker *tracker = new MTPTracker(); - if(verbose) { cout << "Reading the tracking parameters." << endl; } + if(global.verbose) { cout << "Reading the tracking parameters." << endl; } tracker->read(in_tracker); - if(verbose) { + if(global.verbose) { cout << "Building the graph ... "; cout.flush(); gettimeofday(&start_time, 0); } tracker->build_graph(); - if(verbose) { + if(global.verbose) { gettimeofday(&end_time, 0); cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl; } - if(verbose) { + if(global.verbose) { cout << "Tracking ... "; cout.flush(); gettimeofday(&start_time, 0); } tracker->track(); - if(verbose) { + if(global.verbose) { gettimeofday(&end_time, 0); cout << "done (" << diff_in_second(&start_time, &end_time) << "s)." << endl; } - if(strcmp(trajectory_filename, "")) { - ofstream out_traj(trajectory_filename); + if(strcmp(global.trajectory_filename, "")) { + ofstream out_traj(global.trajectory_filename); tracker->write_trajectories(&out_traj); - if(verbose) { cout << "Wrote " << trajectory_filename << "." << endl; } + if(global.verbose) { cout << "Wrote " << global.trajectory_filename << "." << endl; } } else { tracker->write_trajectories(&cout); } - if(strcmp(graph_filename, "") != 0) { - ofstream out_dot(graph_filename); + if(strcmp(global.graph_filename, "") != 0) { + ofstream out_dot(global.graph_filename); tracker->print_graph_dot(&out_dot); - if(verbose) { cout << "Wrote " << graph_filename << "." << endl; } + if(global.verbose) { cout << "Wrote " << global.graph_filename << "." << endl; } } delete tracker; @@ -153,21 +155,20 @@ int main(int argc, char **argv) { int c; int error = 0, show_help = 0; - strncpy(trajectory_filename, "", FILENAME_SIZE); - strncpy(graph_filename, "", FILENAME_SIZE); - verbose = 0; + strncpy(global.trajectory_filename, "", FILENAME_SIZE); + strncpy(global.graph_filename, "", FILENAME_SIZE); + global.verbose = 0; - while ((c = getopt_long(argc, argv, "t:g:hv", - long_options, NULL)) != -1) { + while ((c = getopt_long(argc, argv, "t:g:hv", long_options, NULL)) != -1) { switch(c) { case 't': - strncpy(trajectory_filename, optarg, FILENAME_SIZE); + strncpy(global.trajectory_filename, optarg, FILENAME_SIZE); break; case 'g': - strncpy(graph_filename, optarg, FILENAME_SIZE); + strncpy(global.graph_filename, optarg, FILENAME_SIZE); break; case 'h': @@ -180,7 +181,7 @@ int main(int argc, char **argv) { break; case 'v': - verbose = 1; + global.verbose = 1; break; default: