From dfd8bb34d4d06033c5062ef19f2e5a2f77d5f6c9 Mon Sep 17 00:00:00 2001 From: mmason Date: Tue, 23 Jan 2007 18:03:50 +0000 Subject: Added new string functions tokenize() and strtol(). --- tapset/ChangeLog | 4 ++++ tapset/string.stp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 36 insertions(+) (limited to 'tapset') diff --git a/tapset/ChangeLog b/tapset/ChangeLog index a7408fe7..33eef001 100644 --- a/tapset/ChangeLog +++ b/tapset/ChangeLog @@ -1,3 +1,7 @@ +2007-01-23 Mike Mason + + * string.stp: Added tokenize() and strtol() functions. + 2007-01-17 Martin Hunt * syscalls.stp: Add syscall.creat. diff --git a/tapset/string.stp b/tapset/string.stp index 77925d0d..15791134 100644 --- a/tapset/string.stp +++ b/tapset/string.stp @@ -58,5 +58,37 @@ function text_strn:string(input:string, len:long, quoted:long) _stp_text_str(THIS->__retvalue, THIS->input, THIS->len, THIS->quoted, 0); %} +/* + * tokenize - Given a string and a token delimiter, + * return the next token in the string + * input String to tokenize. If NULL, returns the next token in the + * string passed in the previous call to tokenize(). + * delim Token delimiter. Note this is a string, but only the first + * character is used as the delimiter. + */ +function tokenize:string(input:string, delim:string) +%{ /* pure */ + static char str[MAXSTRINGLEN]; + static char *str_start; + char *token = NULL; + + if (THIS->input[0]) { + strncpy(str, THIS->input, MAXSTRINGLEN); + str_start = &str[0]; + } + token = strsep(&str_start, THIS->delim); + if (token) + strncpy (THIS->__retvalue, token, MAXSTRINGLEN); +%} + +/* + * strtol - Convert a string to a long + * str String to convert + * base The base to use + */ +function strtol:long(str:string, base:long) +%{ /* pure */ + THIS->__retvalue = simple_strtol(THIS->str, NULL, THIS->base); +%} /** @} */ -- cgit