1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
|
/***************************************************************************
* Copyright (C) 2005 by David Saxton *
* david@bluehaze.org *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
***************************************************************************/
#include "externallanguage.h"
#include "languagemanager.h"
#include "logview.h"
#include <kdebug.h>
#include <kprocess.h>
#include <tqregexp.h>
#include <tqtimer.h>
ExternalLanguage::ExternalLanguage( ProcessChain *processChain, KTechlab *parent, const TQString &name )
: Language( processChain, parent, name )
{
m_languageProcess = 0l;
}
ExternalLanguage::~ExternalLanguage()
{
deleteLanguageProcess();
}
void ExternalLanguage::deleteLanguageProcess()
{
if (!m_languageProcess)
return;
// I'm not too sure if this combination of killing the process is the best way....
// m_languageProcess->tryTerminate();
// TQTimer::singleShot( 5000, m_languageProcess, TQT_SLOT( kill() ) );
// delete m_languageProcess;
m_languageProcess->kill();
m_languageProcess->deleteLater();
m_languageProcess = 0L;
}
void ExternalLanguage::receivedStdout( TDEProcess *, char * buffer, int buflen )
{
TQStringList lines = TQStringList::split( '\n', TQString::fromLocal8Bit( buffer, buflen ), false );
TQStringList::iterator end = lines.end();
for ( TQStringList::iterator it = lines.begin(); it != end; ++it )
{
if ( isError( *it ) )
{
outputError( *it );
outputtedError( *it );
}
else if ( isWarning( *it ) )
{
outputWarning( *it );
outputtedWarning( *it );
}
else
{
outputMessage( *it );
outputtedMessage( *it );
}
}
}
void ExternalLanguage::receivedStderr( TDEProcess *, char * buffer, int buflen )
{
TQStringList lines = TQStringList::split( '\n', TQString::fromLocal8Bit( buffer, buflen ), false );
TQStringList::iterator end = lines.end();
for ( TQStringList::iterator it = lines.begin(); it != end; ++it )
{
if ( isStderrOutputFatal( *it ) )
{
outputError( *it );
outputtedError( *it );
}
else
{
outputWarning( *it );
outputtedWarning( *it );
}
}
}
void ExternalLanguage::processExited( TDEProcess * )
{
if ( !m_languageProcess )
return;
bool allOk = processExited( m_languageProcess->normalExit() && m_errorCount == 0 );
finish(allOk);
deleteLanguageProcess();
}
void ExternalLanguage::processInitFailed()
{
finish(false);
deleteLanguageProcess();
}
bool ExternalLanguage::start()
{
displayProcessCommand();
return m_languageProcess->start( TDEProcess::NotifyOnExit, TDEProcess::All );
}
void ExternalLanguage::resetLanguageProcess()
{
reset();
deleteLanguageProcess();
m_errorCount = 0;
m_languageProcess = new TDEProcess(this);
connect( m_languageProcess, TQT_SIGNAL(receivedStdout( TDEProcess*, char*, int )),
this, TQT_SLOT(receivedStdout( TDEProcess*, char*, int )) );
connect( m_languageProcess, TQT_SIGNAL(receivedStderr( TDEProcess*, char*, int )),
this, TQT_SLOT(receivedStderr( TDEProcess*, char*, int )) );
connect( m_languageProcess, TQT_SIGNAL(processExited( TDEProcess* )),
this, TQT_SLOT(processExited( TDEProcess* )) );
}
void ExternalLanguage::displayProcessCommand()
{
TQStringList quotedArguments;
TQValueList<TQCString> arguments = m_languageProcess->args();
if ( arguments.size() == 1 )
quotedArguments << arguments[0];
else
{
TQValueList<TQCString>::const_iterator end = arguments.end();
for ( TQValueList<TQCString>::const_iterator it = arguments.begin(); it != end; ++it )
{
if ( (*it).isEmpty() || (*it).contains( TQRegExp("[\\s]") ) )
quotedArguments << TDEProcess::quote( *it );
else
quotedArguments << *it;
}
}
// outputMessage( "<i>" + quotedArguments.join(" ") + "</i>" );
outputMessage( quotedArguments.join(" ") );
// LanguageManager::self()->logView()->addOutput( quotedArguments.join(" "), LogView::ot_info );
}
#include "externallanguage.moc"
|