mirror of
https://github.com/xiaoyifang/goldendict-ng.git
synced 2024-11-27 15:24: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 "htmlescape.hh"
|
||||||
#include "utf8.hh"
|
#include "utf8.hh"
|
||||||
#include "wstring_qt.hh"
|
#include "wstring_qt.hh"
|
||||||
#include "parsecmdline.hh"
|
|
||||||
#include "iconv.hh"
|
#include "iconv.hh"
|
||||||
#include "utils.hh"
|
#include "utils.hh"
|
||||||
#include "globalbroadcaster.hh"
|
#include "globalbroadcaster.hh"
|
||||||
|
@ -142,7 +141,7 @@ RunInstance::RunInstance():
|
||||||
|
|
||||||
bool RunInstance::start( Config::Program const & prg, QString const & word, QString & error )
|
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() ) {
|
if ( !args.empty() ) {
|
||||||
QString programName = args.first();
|
QString programName = args.first();
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include <QDir>
|
#include <QDir>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
#include "externalviewer.hh"
|
#include "externalviewer.hh"
|
||||||
#include "parsecmdline.hh"
|
|
||||||
#include "gddebug.hh"
|
#include "gddebug.hh"
|
||||||
|
|
||||||
ExternalViewer::ExternalViewer(
|
ExternalViewer::ExternalViewer(
|
||||||
|
@ -34,18 +33,18 @@ void ExternalViewer::start()
|
||||||
connect( &viewer, &QProcess::finished, this, &QObject::deleteLater );
|
connect( &viewer, &QProcess::finished, this, &QObject::deleteLater );
|
||||||
connect( &viewer, &QProcess::errorOccurred, this, &QObject::deleteLater );
|
connect( &viewer, &QProcess::errorOccurred, this, &QObject::deleteLater );
|
||||||
|
|
||||||
QStringList args = parseCommandLine( viewerCmdLine );
|
QStringList args = QProcess::splitCommand( viewerCmdLine );
|
||||||
|
|
||||||
if ( !args.isEmpty() ) {
|
if ( !args.isEmpty() ) {
|
||||||
QString program = args.first();
|
const QString program = args.takeFirst();
|
||||||
args.pop_front();
|
|
||||||
args.push_back( tempFileName );
|
args.push_back( tempFileName );
|
||||||
viewer.start( program, args, QIODevice::NotOpen );
|
viewer.start( program, args, QIODevice::NotOpen );
|
||||||
if ( !viewer.waitForStarted() )
|
if ( !viewer.waitForStarted() ) {
|
||||||
throw exCantRunViewer( viewerCmdLine.toUtf8().data() );
|
throw exCantRunViewer( viewerCmdLine.toUtf8().data() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
throw exCantRunViewer( tr( "the viewer program name is empty" ).toUtf8().data() );
|
throw exCantRunViewer( tr( "the viewer program name is empty" ).toUtf8().data() );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ExternalViewer::stop()
|
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