[prev in list] [next in list] [prev in thread] [next in thread]
List: kde-core-devel
Subject: Command line parsing in e.g. konsole.
From: Waldo Bastian <bastian () kde ! org>
Date: 2000-08-28 19:51:50
[Download RAW message or body]
Hiya,
konsole and some other programs suffer from the problem that a command line
like:
konsole -e mutt -s "bla bla"
Doesn't really work because "-s" is parsed as a non-existing konsole option.
The current work around is to type:
konsole -e mutt -- -s "bla bla"
The "--" indicates that all following arguments should not be treated as
konsole options.
The following patch allows programs like konsole to specify that all
arguments following a certain option should be treated as arguments instead
of options.
Effectively this means that:
konsole -e mutt -s "bla bla"
will now work as expected.
Attached you find a patch that add support for the '!' modifier to indicate
that an option is the last option and a patch for konsole to make use of this.
Cheers,
Waldo
--
KDE/Linux, made for people, made by people.
["kcmdlineargs.diff" (text/x-c++)]
Index: kcmdlineargs.cpp
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kcmdlineargs.cpp,v
retrieving revision 1.43
diff -u -r1.43 kcmdlineargs.cpp
--- kcmdlineargs.cpp 2000/08/08 19:46:43 1.43
+++ kcmdlineargs.cpp 2000/08/28 19:48:24
@@ -330,17 +330,24 @@
* 2 - inverse option found ('no') // -nofork
* 3 - option + arg found // -fork now
*
+ * +4 - no more options follow // !fork
*/
static int
findOption(const KCmdLineOptions *options, QCString &opt,
const char *&opt_name, const char *&def, bool &enabled)
{
+ int result = 0;
bool inverse;
int len = opt.length();
while(options && options->name)
{
inverse = false;
opt_name = options->name;
+ if (opt_name[0] == '!')
+ {
+ opt_name++;
+ result = 4;
+ }
if ((opt_name[0] == 'n') && (opt_name[1] == 'o'))
{
opt_name += 2;
@@ -352,13 +359,13 @@
if (!opt_name[0])
{
if (inverse)
- return 2;
+ return result+2;
if (!options->description)
{
options++;
if (!options->name)
- return 0;
+ return result+0;
QCString nextOption = options->name;
int p = nextOption.find(' ');
if (p > 0)
@@ -368,7 +375,7 @@
nextOption = nextOption.mid(2);
enabled = !enabled;
}
- int result = findOption(options, nextOption, opt_name, def, enabled);
+ result = findOption(options, nextOption, opt_name, def, enabled);
assert(result);
opt = nextOption;
return result;
@@ -380,7 +387,7 @@
{
opt_name++;
def = options->def;
- return 3;
+ return result+3;
}
}
@@ -391,7 +398,7 @@
void
-KCmdLineArgs::findOption(const char *_opt, QCString opt, int &i, bool _enabled)
+KCmdLineArgs::findOption(const char *_opt, QCString opt, int &i, bool _enabled, bool &moreOptions)
{
KCmdLineArgs *args = argsList->first();
const char *opt_name;
@@ -415,6 +422,12 @@
usage( i18n("Unknown option '%1'.").arg(_opt));
}
+ if ((result & 4) != 0)
+ {
+ result &= ~4;
+ moreOptions = false;
+ }
+
if (result == 3) // This option takes an argument
{
if (!enabled)
@@ -524,7 +537,7 @@
option += 2;
enabled = false;
}
- findOption(orig, option, i, enabled);
+ findOption(orig, option, i, enabled, inOptions);
}
}
else
@@ -766,6 +779,9 @@
hasOptions = true;
}
+ if (name[0] == '!')
+ name = name.mid(1);
+
if ((name.length() == 1) || (name[1] == ' '))
name = "-"+name;
else
@@ -954,7 +970,7 @@
const char *def;
bool dummy = true;
QCString opt = _opt;
- int result = ::findOption( options, opt, opt_name, def, dummy);
+ int result = ::findOption( options, opt, opt_name, def, dummy) & ~4;
if (result != 3)
{
@@ -1007,7 +1023,7 @@
const char *def;
bool dummy = true;
QCString opt = _opt;
- int result = ::findOption( options, opt, opt_name, def, dummy);
+ int result = ::findOption( options, opt, opt_name, def, dummy) & ~4;
if (result == 0)
{
Index: kcmdlineargs.h
===================================================================
RCS file: /home/kde/kdelibs/kdecore/kcmdlineargs.h,v
retrieving revision 1.29
diff -u -r1.29 kcmdlineargs.h
--- kcmdlineargs.h 2000/08/24 12:44:48 1.29
+++ kcmdlineargs.h 2000/08/28 19:48:27
@@ -447,7 +447,7 @@
*
* Checks what to do with a single option
*/
- static void findOption(const char *_opt, QCString opt, int &i, bool enabled);
+ static void findOption(const char *_opt, QCString opt, int &i, bool enabled, bool &moreOptions);
/**
* @internal
["konsole.diff" (text/english)]
Index: main.C
===================================================================
RCS file: /home/kde/kdebase/konsole/src/main.C,v
retrieving revision 1.151
diff -u -r1.151 main.C
--- main.C 2000/07/29 01:48:09 1.151
+++ main.C 2000/08/28 19:49:32
@@ -35,9 +35,8 @@
{ "xwin", I18N_NOOP("ignored"), 0 },
{ "nohist", I18N_NOOP("Do not save lines in scroll-back buffer"), 0 },
{ "vt_sz CCxLL", I18N_NOOP("Terminal size in columns x lines"), 0 },
- { "e <command>", I18N_NOOP("Execute 'command' instead of shell"), 0 },
-//FIXME: WABA: We need a way to say that all options after -e
- // should be treated as arguments.
+ { "!e <command>", I18N_NOOP("Execute 'command' instead of shell"), 0 },
+ // WABA: All options after -e are treated as arguments.
{ "+[args]", I18N_NOOP("Arguments for 'command'"), 0 },
{ 0, 0, 0 }
};
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic