Commit 618d4633 authored by Jule Marcoueille's avatar Jule Marcoueille

Johnny est un bip !!

parent f0eac120
......@@ -26,9 +26,16 @@ Interface_console::Interface_console(int argc, char ** argv){
int state;
bool useGUI;/* if window interface can be displayed */
_prog_path = argv[0];
_run_env[0] = (char *)malloc(_CURRENT_DIR_SIZE*sizeof(char));
if (getcwd(_run_env[0], _CURRENT_DIR_SIZE) == NULL){
cerr << "Error : in " << __FILE__ << " at line " << __LINE__ << "." << endl;
cerr << "Reason : Path length is too long (>" << _CURRENT_DIR_SIZE << "). Try to rise the value of _CURRENT_DIR_SIZE." << endl;
exit(EXIT_FAILURE);
}
_run_env[1] = argv[0];
Message::set_interface_instance(this);/* define which interface will receive messages */
useGUI = true;
......@@ -60,9 +67,11 @@ Interface_console::Interface_console(int argc, char ** argv){
Interface_console::~Interface_console(){
/* Qt desallocates _main_window automatically */
free(_run_env[0]);
}
......@@ -361,6 +370,6 @@ const string Interface_console::get_filename() const{
return _file_opened;
}
const char* Interface_console::get_progpath() const{
return _prog_path;
char const* const* Interface_console::get_runenv() const{
return _run_env;
}
......@@ -98,9 +98,15 @@ protected:
static const int _STATE_EXPORT_FILE_IN_INTERVAL = 5;
/*!
*\brief This attributes contains the relative user program path.
* \brief The size max (hoped) for the current directory name.
* Used for opening a new window with a new trace.
*/
char* _prog_path;
static const int _CURRENT_DIR_SIZE = 256;
/*!
*\brief This attributes contains the launching current directory (_run_env[0]) and the first argument of the running command (_run_env[1]).
*/
char* _run_env[2];
/*!
*\brief If a file must be opened, this attributes contains its path.
......@@ -162,10 +168,8 @@ protected:
public:
/***********************************
*
* Constructor and destructor.
......@@ -225,10 +229,10 @@ protected:
const std::string get_filename() const;
/*!
* \brief Get the first argument of the program, that is to say the relative user program path.
* \brief Get the _run_env matrix.
*
*/
const char* get_progpath() const;
char const* const* get_runenv() const;
/***********************************
......
......@@ -195,35 +195,20 @@ void Interface_graphic::on_open_triggered(){
if (!filename.isEmpty()){
if(_is_rendering_trace == true){/* Realease the previous trace */
if (_is_rendering_trace == true){/* Realease the previous trace */
QStringList arguments = (QStringList() << filename);
char *current_dir = (char *)malloc(_CURRENT_DIR_SIZE*sizeof(char));
QString program = QString();
#ifdef _GNU_SOURCE
current_dir = get_current_dir_name();
#else
#if ((_BSD_SOURCE) || (_XOPEN_SOURCE >= 500))
// for MACOS
char *return_value_of_getcwd = NULL;
return_value_of_getcwd = getcwd(current_dir, _CURRENT_DIR_SIZE);
#endif
#endif
// Il faut faire la différence des 2 !
string prog_path = _core->get_progpath();
if(prog_path.substr(0, strlen(current_dir)) == current_dir){
program = QString("/")+QString(_core->get_progpath()+sizeof(char));
}
else{
program = QString(QString(current_dir)+QString(_core->get_progpath()+sizeof(char)));
}
cout << "\n\nOuverture de : " << filename.toStdString() << "\nCurrent dir :" << current_dir << "\nChemin programme : " << _core->get_progpath() << "\nChemin pseudo absolu : " << program.toStdString()<< endl<<endl;
QProcess * new_process = new QProcess();
QString program;
char const* const* run_env = _core->get_runenv();
chdir(run_env[0]);
if (run_env[1][0] == '.')
program = QString(run_env[0])+QString(run_env[1]+sizeof(char));
else
program = QString(run_env[1]);
QProcess * new_process = new QProcess();
new_process->startDetached(program, arguments);
free (current_dir);
}
else{
opening_file(filename.toStdString());
......
......@@ -306,16 +306,7 @@ protected slots:
* This function can be used to display message for user to store its work before application closes.
*/
void closeEvent(QCloseEvent *event);
public:
/*!
* \brief The size max (hoped) for the current directory name.
* Used for opening a new window with a new trace.
*/
static const int _CURRENT_DIR_SIZE = 128;
};
#endif
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