String parsing in stap script
Frank Ch. Eigler
fche@redhat.com
Thu Nov 9 21:57:00 GMT 2006
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
More information about the Systemtap
mailing list