This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
Re: String parsing in stap script
- From: fche at redhat dot com (Frank Ch. Eigler)
- To: Mike Mason <mmlnx at us dot ibm dot com>
- Cc: systemtap at sources dot redhat dot com
- Date: 09 Nov 2006 15:37:31 -0500
- Subject: Re: String parsing in stap script
- References: <455380BE.4070008@us.ibm.com>
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