[jamming] Command built-in questions (was Re: Executing shell command, save results to variable)
Diane Holt
holt.diane at gmail.com
Sat Mar 24 09:13:51 PST 2007
I didn't write it (I think I added the comment :) I don't remember now
exactly where I got it, although I'm leaning towards this mailling list (if
not directly, then possibly from someone on the list). I'd like to give the
author credit, but I'm afraid I just don't remember who that is.
Anyway, here it is:
# Strtok - decompose a string (by default, a path) to get its various bits.
rule Strtok
{
local pat = ([^$(2:E=$(SLASH))]+)(.*) ;
local match = [ MATCH $(pat) : $(1) ] ;
local result = $(match[1]) ;
local string = $(match[2]) ;
while $(string) {
match = [ MATCH $(pat) : $(string) ] ;
result += $(match[1]) ;
string = $(match[2]) ;
}
return $(result) ;
}
So, for instance (bit of an artificial example, but just to give you the
idea):
rule MyRule
{
local out = [ Command "grep foo $(<)" ] ;
for elem in $(out) {
if $(DO_STRTOK) {
local tokens = [ Strtok $(elem) : " " ] ;
for tt in $(tokens) { Echo $(tt) ; }
} else {
Echo $(elem) ;
}
}
}
MyRule foofile ;
$ jam foofile
this foo is on a line
this foo is on another line
...found 1 target(s)...
$ DO_STRTOK=1 jam foofile
this
foo
is
on
a
line
this
foo
is
on
another
line
...found 1 target(s)...
Diane
On 3/23/07, David Turner <david at freetype.org> wrote:
>
>
> On Fri, 23 Mar 2007 16:50:02 -0700, "Diane Holt" <holt.diane at gmail.com>
> said:
> > Rather than start adding more builtins, why not just use the Strtok
> rule.
> > It
> > actually does work fine.
> >
> > Diane
> >
>
> OK, I suppose you're talking about a custom rule you wrote based on Match,
> and
> which could be added to the Jambase.
>
> Could you show us your version ? My problem with Match is that some
> special characters
> that you want to use as tokens need to be double-escaped in the parameter
> string, and
> this can lead to surprising results for unsuspecting users.
>
> Regards,
>
> - David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://maillist.perforce.com/pipermail/jamming/attachments/20070324/a8a5e208/attachment.html
More information about the jamming
mailing list