Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SDK
KDE Development Scripts
Commits
4a21df49
Commit
4a21df49
authored
May 20, 2013
by
David Faure
Browse files
Many improvements in the kcmdlineargs->QCommandLineParser porting script
parent
87d3bc50
Changes
1
Hide whitespace changes
Inline
Side-by-side
kf5/convert-kcmdlineargs.pl
View file @
4a21df49
...
...
@@ -11,22 +11,57 @@ use functionUtilkde;
foreach
my
$file
(
@ARGV
)
{
my
$context
=
"
\"
main
\"
";
my
$opt
;
my
$short
=
"";
my
$args
;
my
%negatedOptions
=
();
functionUtilkde::
substInFile
{
if
(
/KCmdLineOptions (\w*)/
)
{
$opt
=
$
1
;
s/KCmdLineOptions/QCommandLineParser/
;
s/$opt/parser/
;
}
elsif
(
defined
$opt
&&
/(.*)$opt.add\s*\("([^\"]*)", ki18n\((.*)\)\)/
)
{
s/KCmdLineOptions /QCommandLineParser \*/
;
s/$opt/parser = new QCommandLineParser/
;
$_
.=
"
parser->addVersionOption(INSERT_VERSION_NUMBER_HERE);
\n
";
$_
.=
"
parser->addHelpOption(INSERT_DESCRIPTION_HERE);
\n
";
}
elsif
(
defined
$opt
&&
/KCmdLineArgs::addCmdLineOptions\s*\(\s*$opt\s*\)/
||
/KCmdLineArgs::init/
)
{
$_
=
"";
}
elsif
(
defined
$opt
&&
/(.*)$opt.add\s*\("([^\"]*)"\)/
)
{
# short option
$short
=
"
\"
$1
\"
,
";
}
elsif
(
defined
$opt
&&
/(.*)$opt.add\s*\("([^\"]*)", ki18n\((.*)\)(?:,\s*([^\)]*))?\)/
)
{
my
$prefix
=
$
1
;
# e.g. indent
my
$
str
=
$
2
;
my
$
name
=
$
2
;
my
$description
=
$
3
;
my
$defaultValue
=
$
4
;
my
$trail
=
"";
if
(
$str
=~
/(\w*) <(.*)>/
)
{
# "stylesheet <xsl>"
$str
=
$
1
;
$trail
=
"
, QCommandLineOption::OneValue
";
if
(
$name
=~
/(\w*) <(.*)>/
)
{
# "stylesheet <xsl>"
$name
=
$
1
;
$trail
=
"
,
\"
$2
\"
";
}
if
(
defined
$defaultValue
)
{
$trail
.=
"
, false,
$defaultValue
";
}
elsif
(
$name
=~
/^no/
)
{
# negative option, e.g. --nosignal
$negatedOptions
{
$name
}
=
1
;
}
$_
=
"
${prefix}
parser->addOption(QCommandLineOption(QStringList() <<
$short
\"
$name
\"
, QCoreApplication::translate(
$context
,
$description
)
$trail
));
\n
";
$short
=
"";
}
elsif
(
/KCmdLineArgs\s*\*(\w*)\s*=\s*KCmdLineArgs::parsedArgs\(\)/
)
{
$args
=
$
1
;
$_
=
"";
}
else
{
s/KCmdLineArgs::qtArgc\(\)/argc/
;
s/KCmdLineArgs::qtArgv\(\)/argv/
;
if
(
defined
$args
)
{
s/${args}\->getOptionList/parser->arguments/
;
s/${args}\->getOption/parser->argument/
;
s/${args}\->isSet/parser->isSet/
;
s/${args}\->count/parser->remainingArguments().count/
;
if
(
/arguments?\(\"(\w*)/
||
/isSet\(\"(\w*)/
)
{
my
$optionName
=
$
1
;
if
(
defined
$negatedOptions
{"
no
$optionName
"})
{
s/$/\/\/ TODO: negate check/
;
s/$optionName/no$optionName/g
;
}
}
}
$_
=
"
${prefix}
parser.addOption(QCommandLineOption(QStringList() <<
\"
$str
\"
, QCoreApplication::translate(
$context
,
$description
)
$trail
));
\n
";
}
$_
;
}
$file
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment