mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-23 20:14:05 +00:00
opt: remove parsecmdline.cc
by using QProcess::splitCommand
This commit is contained in:
parent
ea4f45ad55
commit
0a5827fd20
|
@ -6,7 +6,6 @@
|
|||
#include "htmlescape.hh"
|
||||
#include "utf8.hh"
|
||||
#include "wstring_qt.hh"
|
||||
#include "parsecmdline.hh"
|
||||
#include "iconv.hh"
|
||||
#include "utils.hh"
|
||||
#include "globalbroadcaster.hh"
|
||||
|
@ -142,7 +141,7 @@ RunInstance::RunInstance():
|
|||
|
||||
bool RunInstance::start( Config::Program const & prg, QString const & word, QString & error )
|
||||
{
|
||||
QStringList args = parseCommandLine( prg.commandLine );
|
||||
QStringList args = QProcess::splitCommand( prg.commandLine );
|
||||
|
||||
if ( !args.empty() ) {
|
||||
QString programName = args.first();
|
||||
|
|
|
@ -4,7 +4,6 @@
|
|||
#include <QDir>
|
||||
#include <QTimer>
|
||||
#include "externalviewer.hh"
|
||||
#include "parsecmdline.hh"
|
||||
#include "gddebug.hh"
|
||||
|
||||
ExternalViewer::ExternalViewer(
|
||||
|
@ -34,19 +33,19 @@ void ExternalViewer::start()
|
|||
connect( &viewer, &QProcess::finished, this, &QObject::deleteLater );
|
||||
connect( &viewer, &QProcess::errorOccurred, this, &QObject::deleteLater );
|
||||
|
||||
QStringList args = parseCommandLine( viewerCmdLine );
|
||||
|
||||
QStringList args = QProcess::splitCommand( viewerCmdLine );
|
||||
if ( !args.isEmpty() ) {
|
||||
QString program = args.first();
|
||||
args.pop_front();
|
||||
const QString program = args.takeFirst();
|
||||
args.push_back( tempFileName );
|
||||
viewer.start( program, args, QIODevice::NotOpen );
|
||||
if ( !viewer.waitForStarted() )
|
||||
if ( !viewer.waitForStarted() ) {
|
||||
throw exCantRunViewer( viewerCmdLine.toUtf8().data() );
|
||||
}
|
||||
else
|
||||
}
|
||||
else {
|
||||
throw exCantRunViewer( tr( "the viewer program name is empty" ).toUtf8().data() );
|
||||
}
|
||||
}
|
||||
|
||||
bool ExternalViewer::stop()
|
||||
{
|
||||
|
|
|
@ -1,42 +0,0 @@
|
|||
#include "parsecmdline.hh"
|
||||
|
||||
QStringList parseCommandLine( QString const & commandLine )
|
||||
{
|
||||
// Parse arguments. Handle quotes correctly.
|
||||
QStringList args;
|
||||
bool openQuote = false;
|
||||
bool possibleDoubleQuote = false;
|
||||
bool startNew = true;
|
||||
for ( QString::const_iterator c = commandLine.begin(), e = commandLine.end(); c != e; ) {
|
||||
if ( *c == '"' && !possibleDoubleQuote ) {
|
||||
++c;
|
||||
if ( !openQuote ) {
|
||||
openQuote = true;
|
||||
if ( startNew ) {
|
||||
args.push_back( QString() );
|
||||
startNew = false;
|
||||
}
|
||||
}
|
||||
else
|
||||
possibleDoubleQuote = true;
|
||||
}
|
||||
else if ( possibleDoubleQuote && *c != '"' ) {
|
||||
openQuote = false;
|
||||
possibleDoubleQuote = false;
|
||||
}
|
||||
else if ( *c == ' ' && !openQuote ) {
|
||||
++c;
|
||||
startNew = true;
|
||||
}
|
||||
else {
|
||||
if ( startNew ) {
|
||||
args.push_back( QString() );
|
||||
startNew = false;
|
||||
}
|
||||
args.last().push_back( *c++ );
|
||||
possibleDoubleQuote = false;
|
||||
}
|
||||
}
|
||||
|
||||
return args;
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
#ifndef PARSECMDLINE_HH
|
||||
#define PARSECMDLINE_HH
|
||||
|
||||
#include <QStringList>
|
||||
|
||||
/// Given a command line (name of the executable with optional arguments),
|
||||
/// separates-out the name and all the arguments into a list. Supports quotes
|
||||
/// and double-quotes.
|
||||
QStringList parseCommandLine( QString const & );
|
||||
|
||||
#endif // PARSECMDLINE_HH
|
Loading…
Reference in a new issue