Commit 8741db7d authored by Mathieu Faverge's avatar Mathieu Faverge
Browse files

Rename get_state in get_options

parent 5535e041
......@@ -187,7 +187,7 @@ Core::Core(int &argc, char ** argv)
* Warning: Work on a copy of argv to keep parameter
* that could be usefull to boost or Qt, as psn
* on Mac for example */
_state = get_state(argc, argv);
_state = get_options(argc, argv);
#ifdef USE_MPI
boost::mpi::environment env(argc, argv);
......@@ -229,7 +229,245 @@ Core::~Core(){
if ( graphic_app != NULL ) delete graphic_app;
}
/***********************************
*
* The command line parameter processing functions.
*
**********************************/
#define GETOPT_STRING "t:e:c:i:s:h"
#if defined(HAVE_GETOPT_LONG)
static struct option long_options[] =
{
{"interval", required_argument, 0, 't'},
{"export", required_argument, 0, 'e'},
{"load_containers_config", required_argument, 0, 'c'},
{"input", required_argument, 0, 'i'},
{"split", required_argument, 0, 's'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
#endif
int Core::get_options(int &argc, char **argv)
{
int state = 0;
int opt = 0;
int c;
int largc;
char **largv;
/* Ignore any -psn_%d_%d argument, which is Mac OS specific */
largc = 0;
largv = (char**)calloc(argc+1, sizeof(char**));
for(c = 0; c < argc; c++) {
if( strncmp(argv[c], "-psn", 4) )
largv[largc++] = argv[c];
}
// No parameters, launch the window interface
if( largc == 1 ){
state = _STATE_LAUNCH_GRAPHICAL_INTERFACE;
goto cleanup;
}
do
{
#if defined(HAVE_GETOPT_LONG)
c = getopt_long_only(largc, largv, "",
long_options, &opt);
#else
c = getopt(largc, largv, GETOPT_STRING);
(void) opt;
#endif // defined(HAVE_GETOPT_LONG)
switch(c) {
case 't' :
double t1, t2;
// Only the end
if( optarg[0] == ':' ) {
if ( sscanf( optarg, ":%lf", &t2) == 1 ) {
_time_end = t2;
} else {
cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
state=_STATE_DISPLAY_HELP;
goto cleanup;
}
} else {
int ret = sscanf( optarg, "%lf:%lf", &t1, &t2);
switch( ret ) {
case 2:
_time_end = t2;
case 1 :
_time_start = t1;
break;
case 0:
cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
state=_STATE_DISPLAY_HELP;
goto cleanup;
}
}
//cerr << "Interval: from " << _time_start << " to " << _time_end << endl;
break;
case 'e' :
_path_to_export = optarg;
state = _STATE_EXPORT_FILE;
//cerr << "Export in file: " << _path_to_export << endl;
break;
case 'i' :
_file_opened = optarg;
if (state == 0) state = _STATE_OPEN_FILE;
//cerr << "Open file: " << _file_opened << endl;
break;
case 's' :
// We want to split the file and save its parts
_file_opened = optarg;
Info::Splitter::split=true;
if (state == 0) state = _STATE_SPLITTING ;
break;
case 'h' :
state=_STATE_DISPLAY_HELP;
goto cleanup;
case 'c' :
_xml_config_file = optarg;
//cerr << "Export in file: " << _path_to_export << endl;
break;
default:
continue;
}
} while(-1 != c);
if(optind < argc)
{
_file_opened = largv[optind];
if (state == 0) state = _STATE_OPEN_FILE;
}
// This is here where we put new options !! (for filters for example)
// if((string)argv[i] == "-epsilon") {
// i ++;
// if(i > argc) {
// cerr << QObject::tr("need another argument for epsilon").toStdString() << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// double accuracy = convert_to_double(argv[i]);
// if(accuracy < 0.) {
// cerr << QObject::tr("need a positive accuracy for epsilon").toStdString() << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_accuracy(accuracy);
// }
// }
// }
// else if((string)argv[i] == "-wide") {
// i ++;
// if (i > argc) {
// cerr << "need another argument for wide" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double wide = convert_to_double(argv[i]);
// if(wide < 0.) {
// cerr << "need a positive width for the export" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_wide_factor(wide);
// }
// }
// else if((string)argv[i] == "-grow") {
// i ++;
// if (i > argc) {
// cerr << "need another argument for grow" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double grow = convert_to_double(argv[i]);
// if(grow < 0.) {
// cerr << "need a positive grown for the export" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_height_factor(grow);
// }
// }
// else if((string)argv[i] == "-scale") {
// i ++;
// if (i > argc) {
// cerr << "need another argument for scale" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double scale = convert_to_double(argv[i]);
// if(scale < 0.) {
// cerr << "need a positive scale for the export" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_scale_frequency(scale);
// }
// }
// else
// if((string)argv[i] == "-interval") {
// if (!(i +2 < argc)) {
// cerr << "interval argc" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// if (argv[i+1][0] == '-') {
// cerr << "interval -" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// if (!(argv[i+2][0] != '-')) {
// cerr << "interval -" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double t1 = atof(argv[i+1]);
// double t2 = atof(argv[i+2]);
// if (t1 >= t2) {
// cerr << "interval neg" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// // Svg::set_interval(t1, t2);
// i += 2;
// }
// else {
// cerr << "the argument "<< argv[i] << " is unknown." << endl;
// state=_STATE_DISPLAY_HELP;
// goto cleanup;
// }
// }
// else{ // This is a file to open
// _file_opened = argv[i];
// state = _STATE_OPEN_FILE;
// }
cleanup:
free(largv);
return state;
}
/***********************************
*
......@@ -595,249 +833,6 @@ int Core::run(){
/***********************************
*
*
*
* The command line parameter processing functions.
*
*
*
**********************************/
#define GETOPT_STRING "t:e:c:i:s:h"
#if defined(HAVE_GETOPT_LONG)
static struct option long_options[] =
{
{"interval", required_argument, 0, 't'},
{"export", required_argument, 0, 'e'},
{"load_containers_config", required_argument, 0, 'c'},
{"input", required_argument, 0, 'i'},
{"split", required_argument, 0, 's'},
{"help", no_argument, 0, 'h'},
{0, 0, 0, 0}
};
#endif
int Core::get_state(int& argc, char** argv){
int state = 0;
int opt = 0;
int c;
int largc;
char **largv;
/* Ignore any -psn_%d_%d argument, which is Mac OS specific */
largc = 0;
largv = (char**)calloc(argc+1, sizeof(char**));
for(c = 0; c < argc; c++) {
if( strncmp(argv[c], "-psn", 4) )
largv[largc++] = argv[c];
}
// No parameters, launch the window interface
if( largc == 1 ){
state = _STATE_LAUNCH_GRAPHICAL_INTERFACE;
goto cleanup;
}
do
{
#if defined(HAVE_GETOPT_LONG)
c = getopt_long_only(largc, largv, "",
long_options, &opt);
#else
c = getopt(largc, largv, GETOPT_STRING);
(void) opt;
#endif // defined(HAVE_GETOPT_LONG)
switch(c) {
case 't' :
double t1, t2;
// Only the end
if( optarg[0] == ':' ) {
if ( sscanf( optarg, ":%lf", &t2) == 1 ) {
_time_end = t2;
} else {
cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
state=_STATE_DISPLAY_HELP;
goto cleanup;
}
} else {
int ret = sscanf( optarg, "%lf:%lf", &t1, &t2);
switch( ret ) {
case 2:
_time_end = t2;
case 1 :
_time_start = t1;
break;
case 0:
cerr << QObject::tr("Interval is not in the correct format [%d:%d]").toStdString() << endl;
state=_STATE_DISPLAY_HELP;
goto cleanup;
}
}
//cerr << "Interval: from " << _time_start << " to " << _time_end << endl;
break;
case 'e' :
_path_to_export = optarg;
state = _STATE_EXPORT_FILE;
//cerr << "Export in file: " << _path_to_export << endl;
break;
case 'i' :
_file_opened = optarg;
if (state == 0) state = _STATE_OPEN_FILE;
//cerr << "Open file: " << _file_opened << endl;
break;
case 's' :
// We want to split the file and save its parts
_file_opened = optarg;
Info::Splitter::split=true;
if (state == 0) state = _STATE_SPLITTING ;
break;
case 'h' :
state=_STATE_DISPLAY_HELP;
goto cleanup;
case 'c' :
_xml_config_file = optarg;
//cerr << "Export in file: " << _path_to_export << endl;
break;
default:
continue;
}
} while(-1 != c);
if(optind < argc)
{
_file_opened = largv[optind];
if (state == 0) state = _STATE_OPEN_FILE;
}
// This is here where we put new options !! (for filters for example)
// if((string)argv[i] == "-epsilon") {
// i ++;
// if(i > argc) {
// cerr << QObject::tr("need another argument for epsilon").toStdString() << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// double accuracy = convert_to_double(argv[i]);
// if(accuracy < 0.) {
// cerr << QObject::tr("need a positive accuracy for epsilon").toStdString() << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_accuracy(accuracy);
// }
// }
// }
// else if((string)argv[i] == "-wide") {
// i ++;
// if (i > argc) {
// cerr << "need another argument for wide" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double wide = convert_to_double(argv[i]);
// if(wide < 0.) {
// cerr << "need a positive width for the export" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_wide_factor(wide);
// }
// }
// else if((string)argv[i] == "-grow") {
// i ++;
// if (i > argc) {
// cerr << "need another argument for grow" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double grow = convert_to_double(argv[i]);
// if(grow < 0.) {
// cerr << "need a positive grown for the export" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_height_factor(grow);
// }
// }
// else if((string)argv[i] == "-scale") {
// i ++;
// if (i > argc) {
// cerr << "need another argument for scale" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double scale = convert_to_double(argv[i]);
// if(scale < 0.) {
// cerr << "need a positive scale for the export" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// else {
// // Svg::set_scale_frequency(scale);
// }
// }
// else
// if((string)argv[i] == "-interval") {
// if (!(i +2 < argc)) {
// cerr << "interval argc" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// if (argv[i+1][0] == '-') {
// cerr << "interval -" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// if (!(argv[i+2][0] != '-')) {
// cerr << "interval -" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// double t1 = atof(argv[i+1]);
// double t2 = atof(argv[i+2]);
// if (t1 >= t2) {
// cerr << "interval neg" << endl;
// state=_STATE_UNKNOWN;
// goto cleanup;
// }
// // Svg::set_interval(t1, t2);
// i += 2;
// }
// else {
// cerr << "the argument "<< argv[i] << " is unknown." << endl;
// state=_STATE_DISPLAY_HELP;
// goto cleanup;
// }
// }
// else{ // This is a file to open
// _file_opened = argv[i];
// state = _STATE_OPEN_FILE;
// }
cleanup:
free(largv);
return state;
}
void Core::launch_action(int state, void* arg) {
DrawTrace buf;
......
/*
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
**
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
**
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
**
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
** - JAZEIX Johnny
** - LAGRASSE Olivier
** - MARCOUEILLE Jule
** - NOISETTE Pascal
** - REDONDY Arthur
** - VUCHENER Clément
**
*/
** This file is part of the ViTE project.
**
** This software is governed by the CeCILL-A license under French law
** and abiding by the rules of distribution of free software. You can
** use, modify and/or redistribute the software under the terms of the
** CeCILL-A license as circulated by CEA, CNRS and INRIA at the following
** URL: "http://www.cecill.info".
**
** As a counterpart to the access to the source code and rights to copy,
** modify and redistribute granted by the license, users are provided
** only with a limited warranty and the software's author, the holder of
** the economic rights, and the successive licensors have only limited
** liability.
**
** In this respect, the user's attention is drawn to the risks associated
** with loading, using, modifying and/or developing or reproducing the
** software by the user in light of its specific status of free software,
** that may mean that it is complicated to manipulate, and that also
** therefore means that it is reserved for developers and experienced
** professionals having in-depth computer knowledge. Users are therefore
** encouraged to load and test the software's suitability as regards
** their requirements in conditions enabling the security of their
** systems and/or data to be ensured and, more generally, to use and
** operate it in the same conditions as regards security.
**
** The fact that you are presently reading this means that you have had
** knowledge of the CeCILL-A license and that you accept its terms.
**
**
** ViTE developers are (for version 0.* to 1.0):
**
** - COULOMB Kevin
** - FAVERGE Mathieu
** - JAZEIX Johnny
** - LAGRASSE Olivier
** - MARCOUEILLE Jule
** - NOISETTE Pascal
** - REDONDY Arthur
** - VUCHENER Clément
**
*/
/*!
*\file Core.hpp
*/
......@@ -81,20 +81,20 @@ class QWaitCondition ;
*\brief This class is an terminal interface, it inherited from the Interface interface.
*/
class Core : public QObject, public Interface {
Q_OBJECT
public:
Q_OBJECT
public:
/***********************************
*
* The command line parameter processing functions.
*
**********************************/
/*!
*\brief An error state.
*/
static const int _STATE_UNKNOWN = -1;
/*!
*\brief A state which corresponds to display a help text.
*/
......@@ -124,7 +124,7 @@ public:
*\brief A state which corresponds to an export of file.
*/
static const int _STATE_EXPORT_FILE_IN_INTERVAL = 5;
/*!
*\brief A state which corresponds to release the OpenGL render area (display the wait screen).
*/
......@@ -154,7 +154,7 @@ public:
*\brief Informs that a trace has to be exported in svg format.
*/
static const int _DRAW_SVG = 11;
/*!
*\brief A state which corresponds to display the ViTE window.
*/
......@@ -169,7 +169,7 @@ public:
*\brief A state which corresponds to replace the render area translate.
*/
static const int _STATE_RENDER_AREA_REPLACE_TRANSLATE = 14;
/*!
*\brief A state which corresponds to replace the render area translate.
*/
......@@ -184,12 +184,12 @@ public:
*\brief A state which corresponds to change the render area scale.