Skip to content
Permalink
Browse files

read/write shell history

git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@5193 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
rblazek
rblazek committed Apr 6, 2006
1 parent 8e7f09c commit c4ca867058f6eda3fb172312000bb50c227f2a86
Showing with 69 additions and 0 deletions.
  1. +32 −0 src/plugins/grass/qgsgrassshell.cpp
  2. +3 −0 src/plugins/grass/qgsgrassshell.h
  3. +34 −0 src/plugins/grass/qgsgrasstools.cpp
@@ -46,6 +46,8 @@ extern "C" {
#include <sys/stat.h>
#include <sys/ioctl.h>
#include <fcntl.h>
#include <signal.h>
#include <sys/wait.h>
#endif //!WIN32
}

@@ -219,6 +221,8 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,
exit(1);
}

mPid = pid;

// Create socket notifier
mOutNotifier = new QSocketNotifier ( mFdMaster, QSocketNotifier::Read, this);

@@ -239,6 +243,34 @@ QgsGrassShell::QgsGrassShell ( QgsGrassTools *tools,

QgsGrassShell::~QgsGrassShell()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassShell::~QgsGrassShell()" << std::endl;
#endif

// TODO: find signal to write history before exit
// instead of sending 'exit'

int ret = write( mFdMaster, "exit\015\012", 6);
int status;

while ( 1 )
{
readStdout(0);
if ( waitpid ( mPid, &status, WNOHANG ) > 0 ) break;

struct timespec t, r;
t.tv_sec = 0;
t.tv_nsec = 10000000; // 0.01 s
nanosleep ( &t, &r );
}

/*
std::cerr << "kill shell pid = " << mPid << std::endl;
if ( kill(mPid,SIGTERM ) == -1 )
{
std::cerr << "cannot kill shell pid = " << mPid << std::endl;
}
*/
}

void QgsGrassShell::keyPressEvent( QKeyEvent * e )
@@ -153,6 +153,9 @@ public slots:
// Buffer for data read form shell stderr
Q3CString mStderrBuffer;

// Shell process PID
int mPid;

// Modes
bool mMode[ModeCount];

@@ -109,6 +109,9 @@ QgsGrassTools::QgsGrassTools ( QgisApp *qgisApp, QgisIface *iface,
mIface = iface;
mCanvas = mIface->getMapCanvas();

connect( qApp, SIGNAL(aboutToQuit()),
this, SLOT(closeTools()) );

mTabWidget = new QgsGrassToolsTabWidget (this);
QVBoxLayout *layout1 = new QVBoxLayout(this);
layout1->addWidget(mTabWidget);
@@ -184,6 +187,25 @@ void QgsGrassTools::moduleClicked( Q3ListViewItem * item )
QgsGrassShell *sh = 0;
if ( name == "shell" )
{
// Set history file
QString mapsetPath = QgsGrass::getDefaultGisdbase() + "/"
+ QgsGrass::getDefaultLocation() + "/"
+ QgsGrass::getDefaultMapset();

// bash
QString hist = "HISTFILE=" + mapsetPath + "/.bash_history";
char *histChar = new char[hist.length()+1];
strcpy ( histChar, const_cast<char *>(hist.ascii()) );
putenv( histChar );

// csh/tcsh
#ifndef WIN32
hist = "histfile=" + mapsetPath + "/.history";
histChar = new char[hist.length()+1];
strcpy ( histChar, const_cast<char *>(hist.ascii()) );
putenv( histChar );
#endif

#ifdef WIN32
// Run MSYS if available
// Note: I was not able to run cmd.exe and command.com
@@ -422,3 +444,15 @@ void QgsGrassTools::emitRegionChanged()
#endif
emit regionChanged();
}

void QgsGrassTools::closeTools()
{
#ifdef QGISDEBUG
std::cerr << "QgsGrassTools::closeTools()" << std::endl;
#endif

for ( int i = mTabWidget->count()-1; i > 1; i-- )
{
delete mTabWidget->widget(i);
}
}

0 comments on commit c4ca867

Please sign in to comment.
You can’t perform that action at this time.