]> sourceware.org Git - systemtap.git/commitdiff
Added new string functions tokenize() and strtol().
authormmason <mmason>
Tue, 23 Jan 2007 18:03:50 +0000 (18:03 +0000)
committermmason <mmason>
Tue, 23 Jan 2007 18:03:50 +0000 (18:03 +0000)
tapset/ChangeLog
tapset/string.stp
testsuite/ChangeLog
testsuite/systemtap.string/strtol.exp [new file with mode: 0644]
testsuite/systemtap.string/strtol.stp [new file with mode: 0644]
testsuite/systemtap.string/tokenize.exp [new file with mode: 0644]
testsuite/systemtap.string/tokenize.stp [new file with mode: 0644]

index a7408fe73d9c5931b6d7beaad6c957dc6168e221..33eef0014d126887d7caf727c8c25af06a0ce70f 100644 (file)
@@ -1,3 +1,7 @@
+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.
index 77925d0d717438f970170156d016552e9953724a..15791134369beef822976978b7949707635bdf1b 100644 (file)
@@ -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);
+%}
 
 /** @} */
index e34d66f299d2d0b472c49ebb1f1159b20ab8f53a..82749ee7bf4ad9fa945ab368d086d9cafd2fe88d 100644 (file)
@@ -1,3 +1,9 @@
+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
diff --git a/testsuite/systemtap.string/strtol.exp b/testsuite/systemtap.string/strtol.exp
new file mode 100644 (file)
index 0000000..12d63f0
--- /dev/null
@@ -0,0 +1,15 @@
+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
diff --git a/testsuite/systemtap.string/strtol.stp b/testsuite/systemtap.string/strtol.stp
new file mode 100644 (file)
index 0000000..dcd1fe7
--- /dev/null
@@ -0,0 +1,29 @@
+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()
+}
diff --git a/testsuite/systemtap.string/tokenize.exp b/testsuite/systemtap.string/tokenize.exp
new file mode 100644 (file)
index 0000000..697b7c7
--- /dev/null
@@ -0,0 +1,26 @@
+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
diff --git a/testsuite/systemtap.string/tokenize.stp b/testsuite/systemtap.string/tokenize.stp
new file mode 100644 (file)
index 0000000..10703d9
--- /dev/null
@@ -0,0 +1,46 @@
+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()
+}
This page took 0.036085 seconds and 5 git commands to generate.