KernelNewbies:

Roel Kluin

Email: roel.kluin@gmail.com)

All code below is GPL v2

# blank_it: replaces spaces with bracket expressions to match
# optional/obligatory spaces for usage with egrep.
bli2()
{
local int="[[:digit:]]"
local hex="[[:xdigit:]]"
local up_="[[:upper:]_]"
local al_="[[:alpha:]_]"
local AN_="[[:upper:][:digit:]_]"
local an_="[[:alnum:]_]"
local sp="[[:space:]]"
local V="$al_+$an_*"

local l="$1"
l="${l//@V/$V}"                 # variable/function/struct name
l="${l//@Q2/[^[:alnum:]_>.]}"   # 1 char left of variable/function/struct name
l="${l//@Q/[^[:alnum:]_]}"      # 1 char right of variable/function/struct name
l="${l//@d/($int+[uUlLfF]?|$int+[uU]?[lL][lL]?|0x$hex+|$int+[lL][lL][uU]|$int*\.$int+[fF]?)}"   # a number
l="${l//@K/$up_+$AN_*}"         # an definition or macro name (uppercase)
l="${l//@s/$sp*}"               # optional space
l="${l//@S/$sp+}"               # obligatory space
l="${l//@w/($V|\.|->|\[$sp*[^][]+$sp*\]|\($sp*[^)(]*$sp*\))+}"          # a variable/array/member/unnested function or macro
l="${l//\\\(...\\\)/\([^()]*(\([^()]*(\([^()]*\)[^()]*)*\)[^()]*)*\)}"  # nested parentheses, 2 backrefs
l="$(echo "$l" | sed -r "s/\\\\\{\.\.\.\\\\\}/\\\\\{\[^\}\{\]*(\\\\\{\[^\}\{\]*(\\\\\{\[^\}\{\]*\\\\\}\[^\}\{\]*)*\\\\\}\[^\}\{\]*)*\\\\\}/g")" # nested curly brackets, 2 backrefs
 echo "$l" | sed -r "
:a
s/($an_)$sp+($an_)/\1$sp+\2/g
s/(\[\[:space:\]\]\*)*$sp+/$sp*/g
$!{
 N
 ba
}
"
}

# echo a sed script to catch $1 from multiline grep and filter out $2.
# e.g. grep -E -n -H -B1 -A10 "foo" ~/file | sed -n -r "$(ecsed "foo" "foo.*bar")"
ecsed()
{
local sp="[[:space:]]";         # space
local ns="[^[:space:]]";        # no space
local bol="$ns*[:-][0-9]+[:-]"  # begin of line
 [ -n "$2" ] && not="/$(bli2 "$2")/b"
echo ":start
/(--|$bol}$s)$/!{
N
b start
}
s/$sp*\/\*+([^*]*|\*[^\/])*\*+\// /g    # remove C style comment
s/(\/\/[^\n]*)?\n$bol/\n/g              # remove C99 comment
$not
s/^($ns*)[:-]([0-9]+)[:-]/---[ vi \1 +\2 ]---\n/
s/\n--$//
/$(bli2 "$1")/p"
}

To use, save and source this file.

Search for allocating of variables without test of success.

goto your git Linux kernel directory and paste into the console:

em='!'
z="[kv][mz]alloc"
git grep -E -n -B3 -A20 "$(bli2 "@Q2$z \(")" | sed -n -r "$(ecsed \
"@Q2(@w) = (\(...\) )* $z \(...\) ;" \
"@Q2(@w) = (@w = )*(\(...\) )* $z \(...\) ;([^\n]*\n)*
[^\n]*([&|(]|return) (\1 [=$em]= NULL|$em? \1|NULL [=$em]= \1) [&|)?]" \
)" | less
em='!'

KernelNewbies: roelkluin (last edited 2009-09-08 23:25:11 by d133062)