+2007-01-23 Mike Mason <mmlnx@us.ibm.com>
+
+ * string.stp: Added tokenize() and strtol() functions.
+
2007-01-17 Martin Hunt <hunt@redhat.com>
* syscalls.stp: Add syscall.creat.
_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);
+%}
/** @} */
+2007-01-23 Mike Mason <mmlnx@us.ibm.com>
+
+ * systemtap.string/tokenize.exp, systemtap.string/tokenize.stp,
+ systemtap.string/strtol.exp, systemtap.string/strtol.stp:
+ Tests for new tokenize and strtol functions.
+
2007-01-22 Josh Stone <joshua.i.stone@intel.com>
* systemtap.base/deref.stp: Rewrite test, and now also check the ability
--- /dev/null
+set test "strtol"
+set ::result_string {1
+-1
+123456789
+-123456789
+0
+1
+0
+0
+1000
+4096
+512
+8
+0}
+stap_run2 $srcdir/$subdir/$test.stp
--- /dev/null
+probe begin
+{
+ teststr1 = "1"
+ teststr2 = "-1"
+ teststr3 = "123456789"
+ teststr4 = "-123456789"
+ teststr5 = "abcdef"
+ teststr6 = "123456789abcdef"
+ teststr7 = " 1 2 3 4"
+ teststr8 = ""
+ teststr9 = "1000"
+ teststr6 = "1a2b3c4d5e6f7g8h9"
+
+ printf("%d\n", strtol(teststr1, 10))
+ printf("%d\n", strtol(teststr2, 10))
+ printf("%d\n", strtol(teststr3, 10))
+ printf("%d\n", strtol(teststr4, 10))
+ printf("%d\n", strtol(teststr5, 10))
+ printf("%d\n", strtol(teststr6, 10))
+ printf("%d\n", strtol(teststr7, 10))
+ printf("%d\n", strtol(teststr8, 10))
+ printf("%d\n", strtol(teststr9, 10))
+ printf("%d\n", strtol(teststr9, 16))
+ printf("%d\n", strtol(teststr9, 8))
+ printf("%d\n", strtol(teststr9, 2))
+ printf("%d\n", strtol(teststr10, 2))
+
+ exit()
+}
--- /dev/null
+set test "tokenize"
+set ::result_string {one
+two
+three
+four
+five
+six
+seven
+eight
+nine
+ten
+one|two|three|four|five|six|seven|eight|nine|ten
+a
+b
+c
+d
+e
+f
+g
+1
+2
+3
+
+4
+this is a string with no delimiters}
+stap_run2 $srcdir/$subdir/$test.stp
--- /dev/null
+probe begin
+{
+ teststr1 = "one|two|three|four|five|six|seven|eight|nine|ten"
+ teststr2 = "a,b,c,d,e,f,g"
+ teststr3 = "1,,2,3, ,4"
+ teststr4 = ""
+ teststr5 = "this is a string with no delimiters"
+
+ tok = tokenize(teststr1, "|")
+ while (tok != "") {
+ printf("%s\n", tok)
+ tok = tokenize("", "|")
+ }
+
+ tok = tokenize(teststr1, ",")
+ while (tok != "") {
+ printf("%s\n", tok)
+ tok = tokenize("", "|")
+ }
+
+ tok = tokenize(teststr2, ",")
+ while (tok != "") {
+ printf("%s\n", tok)
+ tok = tokenize("", ",")
+ }
+
+ tok = tokenize(teststr3, ",")
+ while (tok != "") {
+ printf("%s\n", tok)
+ tok = tokenize("", ",")
+ }
+
+ tok = tokenize(teststr4, ",")
+ while (tok != "") {
+ printf("%s\n", tok)
+ tok = tokenize("", ",")
+ }
+
+ tok = tokenize(teststr5, ",")
+ while (tok != "") {
+ printf("%s\n", tok)
+ tok = tokenize("", ",")
+ }
+
+ exit()
+}