Dozens of incomplete stuff in Desktop Entry Standard

Oswald Buddenhagen ossi at kde.org
Fri Jun 27 01:17:51 EEST 2003


On Thu, Jun 26, 2003 at 10:27:02PM +0200, Waldo Bastian wrote:
> >   - Okay, let's assume that we follow the execve() approach. How
> >   should the command line be split into arguments? At spaces, or
> >   spaces and TABs?  What to do with adjacent or trailing spaces? Are
> >   there any escaping or quoting possibilities? If yes, what are
> >   they? Is there a way to pass an argument that itself contains a
> >   space? Is there a way to pass an empty argument?
> 
> Oswald may be able to comment on that.
> 
kde currently contains a bourne shell (+ ksh/bash extensions) syntax
dequoter - consult the man page of your prefered sh derivate for
details.
if the argument splitting fails due to unhandled meta characters
(redirections, stubstitutions), the original string (after %-expando
substitution) is passed as-is to /bin/sh.
this handling effectively ensures, that commands are always handled the
way system() would handle them, i.e., the direct execve() variant is a
transparent optimization.
as for the %-expando substitution ... of course it is quite tricky in
shell command context. see kdelibs/kdecore/kmacroexpander.cpp,
KMacroExpanderBase::expandMacrosShellQuote for the gory details.
essentially it tracks shell quoting and quotes the substituted values
according to the current state.
the important fact is, that %-expandos are automatically properly
quoted. you can't sneak in code by using a bogus file name. unless the
command containing the expandos triggers one of bash's parser bugs, of
course, but that's not my fault. you're safe as long as you don't use
expandos within substitutions or stick to simple constructs, which you
should do anyway (as you can't rely on /bin/sh being bash, etc.).

> >   - About the Exec parameter variables: it is completely unclear to me
> >   which one of these %f %F and friends may expand to at most one, exactly
> >   one, at least one or any number (including zero) command line arguments.
> >   For example, will %f disappear or substitute to an empty argument if I
> >   launch the application from a menu entry? Will %c disappear or be an
> >   empty argument if there's no Comment key in the .desktop file? And if
> >   there's a "Comment=" line in the .desktop file (with no value)?
> 
> %f, %u, %d, %n may expand to 0 or 1 argument.
>
unless quoted, in which case it will be always one arg, possibly empty.

> %F, %U, %D, %N may expand to 0, 1 or more arguments.
> 
unless quoted, in which case it will be one arg, which is the
space-joint contents of all elements.

> All others always expand to 1 argument.
> 
%m and %i actually expand to two args, but i think this is a kde
extension?

> >   - In case the meaning of %f %F %c etc. were defined precisely:
> >   what's their meaning if they don't appear on their own? E.g. if %F might
> >   expand to multiple arguments, then what happens if I write foo%Fbar in
> >   the file?
> > Will the first filename be prefixed by foo and the last one suffixed by bar?
>
yes

> > Will all the filenames be prefixed and suffixed by these?
>
no, but we could implement bash-style brace expansion. :)
foo{%F}bar would be like foo{el1,el2,...}bar, obviously.

> > What does this expand to if %F expands to zero filenames?
> 
i think the result will be foobar, currently.

> > Or do they only have special meaning if they appear on their own?
>
up to kde 3.1, yes. at least i think so - the code was a major mess. :)

> >   - In KDE plenty of the .desktop files have something like this:
> >   ``Exec=kscd -caption "%c" %i %m'' However, I don't see the double quotes
> >   in the process listing which would be trivial if the system() method
> >   was be followed by KDE, but since KDE follows the execve() method I
> >   don't have a clue who and when swallows those double quotes. So: when
> >   and how should the double quotes be substituted to something?
> 
see above, according to the usual sh (not csh!) quoting rules.

> >   - How to pass a % sign to the application? Is %% (like for printf) okay?
> 
> I think we support that yes. Not sure since how long.
> 
about forever, i guess. no bet, though. :)

greetings

-- 
Hi! I'm a .signature virus! Copy me into your ~/.signature, please!
--
Chaos, panic, and disorder - my work here is done.



More information about the xdg mailing list