This is the mail archive of the
systemtap@sourceware.org
mailing list for the systemtap project.
script coding style - mask_string.stp
- From: "Frank Ch. Eigler" <fche at redhat dot com>
- To: systemtap at sources dot redhat dot com
- Date: Wed, 28 Sep 2005 06:49:21 -0400
- Subject: script coding style - mask_string.stp
Hi, Kevin -
Regarding mask_string.stp, some comments. Script code need not look
like C so much. Script functions generally don't need the
parameter/result type declarations, nor all those semicolons. These
functions could be placed within system_calls.stp, if there is little
likelihood of them being used from elsewhere. Use of the _name/_bits
global arrays as additional implicit arguments to _bitstring() is both
inefficient and unsafe (in the face of concurrency). Consider instead
this simpler, safer version:
function _bitstring_buildup (bs,number,name,mask) {
// bs contains built-up string so far
if (number & mask)
if (bs == "")
return name
else
return bs."|".name
}
function sys_adjtimex_mode_str (flags) {
// bs is local, initialized empty
bs = _bitstring_buildup (bs, flags, "ADJ_OFFSET", 1)
bs = _bitstring_buildup (bs, flags, "ADJ_FREQUENCY", 2)
// and so on
return bs
}
- FChE