This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
[PATCH 1/3] Add function of returning the char in given position of string.
- From: Wenji Huang <wenji dot huang at oracle dot com>
- To: systemtap at sourceware dot org
- Cc: Wenji Huang <wenji dot huang at oracle dot com>
- Date: Fri, 24 Apr 2009 13:23:08 -0400
- Subject: [PATCH 1/3] Add function of returning the char in given position of string.
* tapset/string.stp: New function chrofstr.
* testsuite/systemtap.printf/char1.exp: Update test case.
* testsuite/systemtap.printf/char1.stp: Ditto.
---
tapset/string.stp | 12 ++++++++++++
testsuite/systemtap.printf/char1.exp | 2 +-
testsuite/systemtap.printf/char1.stp | 1 +
3 files changed, 14 insertions(+), 1 deletions(-)
diff --git a/tapset/string.stp b/tapset/string.stp
index 2f43aec..db5404c 100644
--- a/tapset/string.stp
+++ b/tapset/string.stp
@@ -25,6 +25,18 @@ function substr:string(str:string,start:long, length:long) %{ /* pure */
strlcpy(THIS->__retvalue, THIS->str + THIS->start, length);
%}
+/** @addtogroup library
+* @code function strofchr:string(str:string, pos:long) @endcode
+* @param str string
+* @param pos the given position. 0 = start of the string
+* @return Returns the char in given position of string.
+*/
+function chrofstr:long(str:string, pos:long) %{ /* pure */
+ if (THIS->pos >= 0 && THIS->pos < strlen(THIS->str))
+ THIS->__retvalue = THIS->str[THIS->pos];
+ else
+ THIS->__retvalue = 0;
+%}
/** @addtogroup library
* @code isinstr:long(s1:string,s2:string) @endcode
diff --git a/testsuite/systemtap.printf/char1.exp b/testsuite/systemtap.printf/char1.exp
index 35aa479..f9343c0 100644
--- a/testsuite/systemtap.printf/char1.exp
+++ b/testsuite/systemtap.printf/char1.exp
@@ -1,3 +1,3 @@
set test "char1"
-set ::result_string {stap}
+set ::result_string {stapok}
stap_run2 $srcdir/$subdir/$test.stp
diff --git a/testsuite/systemtap.printf/char1.stp b/testsuite/systemtap.printf/char1.stp
index 207d1bc..8b3941a 100644
--- a/testsuite/systemtap.printf/char1.stp
+++ b/testsuite/systemtap.printf/char1.stp
@@ -3,6 +3,7 @@ probe begin
printf("%c", 115)
printf("%c", 116)
printf("%c%c", 97, 112)
+ printf("%c%c", chrofstr("ok", 0), chrofstr("ok", 1))
print("\n")
exit()
}
--
1.5.6