* [PATCH 1/3] Add function of returning the char in given position of string.
@ 2009-04-24 10:41 Wenji Huang
0 siblings, 0 replies; only message in thread
From: Wenji Huang @ 2009-04-24 10:41 UTC (permalink / raw)
To: systemtap; +Cc: Wenji Huang
* 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
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2009-04-24 10:41 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-04-24 10:41 [PATCH 1/3] Add function of returning the char in given position of string Wenji Huang
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).