Commit 77df97ad authored by Johnny Jazeix's avatar Johnny Jazeix

Début du respect des normes.

parent 23d5a7b0
......@@ -175,7 +175,7 @@ int Interface_console::run(){
int Interface_console::get_state(int argc, char** argv){
/*The folowing statics must be initialised in case their are not overrided by a command line request*/
/*The folowing statics must be initialised in case their are not overrided by a command line request*/
Svg::set_height_factor (20);
Svg::set_wide_factor (100);
Svg::set_interval(0,0);
......@@ -196,11 +196,12 @@ int Interface_console::get_state(int argc, char** argv){
for(int i = 1 ; i < argc ; i ++){
if(strncmp(argv[i], "-h", 2) == 0){
cout << "argv[" << i <<"] : "<< argv[i] << endl;
if((string)argv[i] == "-h"){
// display the help message
return _STATE_DISPLAY_HELP;
}
else if(strncmp(argv[i], "-f", 2) == 0 || strncmp(argv[i], "-a", 2) == 0){
else if((string)argv[i] == "-f" || (string)argv[i] == "-a"){
// We want to open the file which follow this argument
i ++;
if(i < argc){
......@@ -212,7 +213,7 @@ int Interface_console::get_state(int argc, char** argv){
return _STATE_UNKNOWN;
}
}
else if(strncmp(argv[i], "-e", 3) == 0){
else if((string)argv[i] == "-e"){
// We want to export the file which follow this argument
i ++;
if(i < argc){
......@@ -224,109 +225,99 @@ int Interface_console::get_state(int argc, char** argv){
return _STATE_UNKNOWN;
}
}
else if(strncmp(argv[i], "-t", 2) == 0){
else if((string)argv[i] == "-t"){
// We want to export the file which follow this argument
extract_times(argv[++ i]);
state |= _STATE_IN_AN_INTERVAL;
}
else if(argv[i][0] == '-'){
else if(argv[i][0] == '-') {
// This is here where we put new options !! (for filters for example or export)
if(strncmp(argv[i],"-epsilon",8) == 0){
if (!(i + 1 < argc)) {
cerr << "epsilon argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i +1 ][0] != '-')){
cerr << "epsilon -" << endl;
return _STATE_UNKNOWN;
}
Svg::set_accuracy(atof(argv[i+1]));
}
else if(strncmp(argv[i],"-interval",9) == 0){
if (!(i +2 < argc) ) {
cerr << "interval argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i+1][0] != '-')) {
cerr << "interval -" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i+2][0] != '-')) {
cerr << "interval -" << endl;
return _STATE_UNKNOWN;
if((string)argv[i] == "-epsilon"){
i ++;
if(i > argc){
cerr << "need an other argument for epsilon" << endl;
return _STATE_UNKNOWN;
}
else{
double accuracy = convert_to_double(argv[i]);
if(accuracy < 0.) {
cerr << "need a positive accuracy for epsilon" << endl;
return _STATE_UNKNOWN;
}
else{
Svg::set_accuracy(accuracy);
}
}
}
// else if((string)argv[i] == "-interval"){
// if (!(i +2 < argc)) {
// cerr << "interval argc" << endl;
// return _STATE_UNKNOWN;
// }
// if (argv[i+1][0] == '-') {
// cerr << "interval -" << endl;
// return _STATE_UNKNOWN;
// }
// if (!(argv[i+2][0] != '-')) {
// cerr << "interval -" << endl;
// return _STATE_UNKNOWN;
// }
double t1 = atof(argv[i+1]);
double t2 = atof(argv[i+2]);
if ((t1>=t2)) {
cerr << "interval neg" << endl;
return _STATE_UNKNOWN;
}
Svg::set_interval(t1,t2);
// double t1 = atof(argv[i+1]);
// double t2 = atof(argv[i+2]);
}
else if(strncmp(argv[i],"-wide",5) == 0){
if (!(i + 1 < argc)) {
cerr << "wide argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i + 1 ][0] != '-')) {
cerr << "wide -" << endl;
return _STATE_UNKNOWN;
}
Svg::set_wide_factor(atof(argv[i+1]));
}
else if(strncmp(argv[i],"-grow",5) == 0){
if (!(i + 1 < argc)) {
cerr << "grow argc" << endl;
return _STATE_UNKNOWN;
}
if (!(argv[i + 1 ][0] != '-')){
cerr << "grow -" << endl;
return _STATE_UNKNOWN;
// if (t1 >= t2) {
// cerr << "interval neg" << endl;
// return _STATE_UNKNOWN;
// }
// Svg::set_interval(t1,t2);
//}
else if((string)argv[i] == "-wide") {
if (i + 1 >= argc) {
cerr << "wide argc" << endl;
return _STATE_UNKNOWN;
}
if (argv[i+1][0] == '-') {
cerr << "wide -" << endl;
return _STATE_UNKNOWN;
}
Svg::set_wide_factor(atof(argv[i+1]));
}
else if((string)argv[i] == "-grow"){
if (!(i + 1 < argc)) {
cerr << "grow argc" << endl;
return _STATE_UNKNOWN;
}
if (argv[i+1][0] == '-') {
cerr << "grow -" << endl;
return _STATE_UNKNOWN;
}
Svg::set_height_factor(atof(argv[i+1]));
}
Svg::set_height_factor(atof(argv[i+1]));
}
else
{
cerr << "any" << endl;
return _STATE_UNKNOWN;
}
else {
cerr << "the argument "<< argv[i] << " is unknown." << endl;
return _STATE_DISPLAY_HELP;
}
}
else{ // This is a file to open
}
else{ // This is a file to open
_file_opened = argv[i];
state |= _STATE_OPEN_FILE;
}
}
return state;
}
void Interface_console::extract_times(const char *name){
bool has_time_start = false;
bool has_time_end = false;
if(name[0] == '['){
bool has_time_start = false;
bool has_time_end = false;
if(name[0] == '['){
has_time_start = true;
}
if(name[strlen(name)-1] == ']'){
......@@ -348,6 +339,35 @@ void Interface_console::extract_times(const char *name){
}
}
double Interface_console::convert_to_double(const char *arg){
double value = -1.0; // Value returned
string arg_temp = (string)arg + " 3"; // The same hint as in Date.cpp is used, we simulate a double sscanf
int useless;
if(sscanf(arg_temp.c_str(), "%lf %d", &value, &useless) == 2){
return value; // It is the good format
}
else{ // We change the locale to test
bool is_english_system_needed = false; // We have dot as separator of decimal and integer.
if(arg_temp.find('.') != string::npos){
is_english_system_needed = true;
}
if(is_english_system_needed){ // We had dots initially, we need to have the english system
setlocale(LC_NUMERIC, "en_GB.UTF-8");
}
else{
setlocale(LC_NUMERIC, "fr_FR.UTF-8");
}
if(sscanf(arg_temp.c_str(), "%lf %d", &value, &useless) == 2){
return value;
}
else{
return -1;
}
}
}
void Interface_console::launch_action(int state, void* arg){
......
......@@ -195,7 +195,11 @@ protected:
*/
void extract_times(const char *name);
/*!
* \brief Convert the string in double
* \arg arg : the string to be doublized.
*/
double convert_to_double(const char *arg);
/*!
* \brief Displays in the terminal the help text.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment