This is the mail archive of the systemtap@sourceware.org mailing list for the systemtap project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: String parsing in stap script


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]