Extend KMacroExpander for shell-expansion?

Oswald Buddenhagen ossi at kde.org
Sat Jul 12 14:13:47 BST 2008


On Sat, Jul 12, 2008 at 01:17:51AM +0200, Andreas Pakulat wrote:
> FOOBAR=kde
> MYVAR=$HOME/$FOOBAR/test

> Now I'm thinking this might be of interest for other people too and as
> there's already expanding code in KMacroExpander I'm wondering wether I
> should put a expandShellVariables() function into that namespace too. Or
> should it rather go into KShell??
> 
the right place would be KShell for hopefully obvious reasons.

simple unix-style variable expansion can be implemented rather trivially
with KMacroExpander::expandMacros( str, var2valueMap, QLatin1Char('$') )
(var2valueMap being pre-populated with the environment) or (more
efficiently) by subclassing KWordMacroExpander.
to make subsequent expansions possible, one could use
expandMacrosShellQuote().
note that KMacroExpander is unfit to implement the totally braindead
semantics of dos-style variable expansion - and i suppose we want to use
platform-native expansions?

i think one should introduce a VariableExpand flag to KShell::Options
and pass that as an additional option to KShell::splitArgs().
for the non-splitting variant, one should generalize the tildeExpand()
function into an expand() function that takes an option field like
splitArgs().

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




More information about the kde-core-devel mailing list