* String parsing in stap script
@ 2006-11-09 19:42 Mike Mason
2006-11-09 20:37 ` Jim Keniston
2006-11-09 21:57 ` Frank Ch. Eigler
0 siblings, 2 replies; 3+ messages in thread
From: Mike Mason @ 2006-11-09 19:42 UTC (permalink / raw)
To: systemtap
I'm trying to figure out how to parse a string in a stap script. Ideally, I'd like a function like strsep() where I pass in a string and delimiter and get back a token and a pointer to the string past the token. Given that a stap function can only pass back one value, I don't see how to accomplish this. Any suggestions or is this just not possible?
BTW, my initial reason for wanting this is to pass an array from a shell script to a stap script. I figure I can just pass it as one long delimited string, then parse it on the stap side to get it back in array form.
- Mike
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: String parsing in stap script
2006-11-09 19:42 String parsing in stap script Mike Mason
@ 2006-11-09 20:37 ` Jim Keniston
2006-11-09 21:57 ` Frank Ch. Eigler
1 sibling, 0 replies; 3+ messages in thread
From: Jim Keniston @ 2006-11-09 20:37 UTC (permalink / raw)
To: Mike Mason; +Cc: SystemTAP
On Thu, 2006-11-09 at 11:25, Mike Mason wrote:
> I'm trying to figure out how to parse a string in a stap script. Ideally,
> I'd like a function like strsep() where I pass in a string and delimiter
> and get back a token and a pointer to the string past the token. Given
> that a stap function can only pass back one value, I don't see how to
> accomplish this. Any suggestions or is this just not possible?
Have you considered storing the parsing context in a struct (created via
embedded C) and passing around a pointer to that?
Jim
>
> BTW, my initial reason for wanting this is to pass an array from a shell
> script to a stap script. I figure I can just pass it as one long
> delimited string, then parse it on the stap side to get it back in array
> form.
>
> - Mike
>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: String parsing in stap script
2006-11-09 19:42 String parsing in stap script Mike Mason
2006-11-09 20:37 ` Jim Keniston
@ 2006-11-09 21:57 ` Frank Ch. Eigler
1 sibling, 0 replies; 3+ messages in thread
From: Frank Ch. Eigler @ 2006-11-09 21:57 UTC (permalink / raw)
To: Mike Mason; +Cc: systemtap
Mike Mason <mmlnx@us.ibm.com> writes:
> I'm trying to figure out how to parse a string in a stap script.
> Ideally, I'd like a function like strsep() where I pass in a string
> and delimiter and get back a token and a pointer to the string past
> the token. [...]
If you're willing to sacrifice concurrent use of the same tokenizing
process, you could write a single function, something like:
function tokenize:string (input:string, separator:string) %{
static char tokenstr[MAXSTRINGLEN];
static char* tokenptr = & tokenstr[0];
char *tokenptr_start = tokenptr;
if (THIS->input[0]) {
strncpy (tokenstr, THIS->input, MAXSTRINGLEN);
tokenptr = & tokenstr[0];
}
/* ... now call strsep or whatever on tokenstr/tokenptr ... */
if (/* token found */)
strncpy (THIS->__retvalue, tokenptr_start, (tokenptr - tokenptr_start));
/* else THIS->__retvalue is already empty */
%}
- FChE
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2006-11-09 20:37 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2006-11-09 19:42 String parsing in stap script Mike Mason
2006-11-09 20:37 ` Jim Keniston
2006-11-09 21:57 ` Frank Ch. Eigler
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).