Size: 2606
Comment:
|
Size: 3370
Comment:
|
Deletions are marked like this. | Additions are marked like this. |
Line 24: | Line 24: |
local em='!' | |
Line 33: | Line 34: |
l="${l//\\$em/$em}" # Because bash bangs otherwise | |
Line 47: | Line 49: |
# 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")" |
# echo a sed script to catch from multiline grep $n (where n=$#) and filter out $1 up to ${n-1}. # e.g. grep -E -n -H -B1 -A10 "foo" ~/file | sed -n -r "$(ecsed2 "foo.*bar" "foo")" # searches for lines with `foo', not followed by `bar' |
Line 51: | Line 54: |
local app; if [ "${1:0:6}" = "--PrE=" ]; then app="${1:6}"; shift; fi |
|
Line 54: | Line 61: |
[ -n "$2" ] && not="/$(bli2 "$2")/b" | local not; while [ -n "$2" ]; do not="$not/$(bli2 "$app$1")/b;" shift; done |
Line 65: | Line 76: |
/$(bli2 "$1")/p" | /$(bli2 "$app$1")/p" } # gsl does something like # git grep -E -n [-opts] "[parsed $1]" | sed -n -r "[parsed ${@:2}]" gres() { local opts; local o; local append; local gq; local sq; while [ $# -ne 0 ]; do [ "${1:0:1}" != "-" ] && break; [ "${1:0:6}" != "--PrE=" ] && opts="$opts $1" || gq="${1:6}"; shift; done if [ -z "$gq" ]; then gq="$(bli2 "$1")"; shift; sq="$(ecsed2 "$@")" else gq="$(bli2 "$gq")" sq="$(ecsed2 "--PrE=$gq" "$@")"; fi git grep -E -n $opts "$gq" | sed -n -r "$sq" |
Line 75: | Line 107: |
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='!' |
z="[kv][zm]alloc" gres -B1 -A20 "^((.* (@w) =)? (\( @V \** \) )*)? $z \(" \ "@Q2(\**@w) = (\**@w = )*(\( @V \** \) )* $z \(...\) ;.* (return|[&|(]) (\1 [=\!]= NULL|\!? \1|NULL [=\!]= \1) [&|)?;]" \ "@Q2(\**@w = )+(\( @V \** \) )* $z \(...\) ;" | less |
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 em='!' 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//\\$em/$em}" # Because bash bangs otherwise 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 from multiline grep $n (where n=$#) and filter out $1 up to ${n-1}. # e.g. grep -E -n -H -B1 -A10 "foo" ~/file | sed -n -r "$(ecsed2 "foo.*bar" "foo")" # searches for lines with `foo', not followed by `bar' ecsed() { local app; if [ "${1:0:6}" = "--PrE=" ]; then app="${1:6}"; shift; fi local sp="[[:space:]]"; # space local ns="[^[:space:]]"; # no space local bol="$ns*[:-][0-9]+[:-]" # begin of line local not; while [ -n "$2" ]; do not="$not/$(bli2 "$app$1")/b;" shift; done 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 "$app$1")/p" } # gsl does something like # git grep -E -n [-opts] "[parsed $1]" | sed -n -r "[parsed ${@:2}]" gres() { local opts; local o; local append; local gq; local sq; while [ $# -ne 0 ]; do [ "${1:0:1}" != "-" ] && break; [ "${1:0:6}" != "--PrE=" ] && opts="$opts $1" || gq="${1:6}"; shift; done if [ -z "$gq" ]; then gq="$(bli2 "$1")"; shift; sq="$(ecsed2 "$@")" else gq="$(bli2 "$gq")" sq="$(ecsed2 "--PrE=$gq" "$@")"; fi git grep -E -n $opts "$gq" | sed -n -r "$sq" }
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:
z="[kv][zm]alloc" gres -B1 -A20 "^((.* (@w) =)? (\( @V \** \) )*)? $z \(" \ "@Q2(\**@w) = (\**@w = )*(\( @V \** \) )* $z \(...\) ;.* (return|[&|(]) (\1 [=\!]= NULL|\!? \1|NULL [=\!]= \1) [&|)?;]" \ "@Q2(\**@w = )+(\( @V \** \) )* $z \(...\) ;" | less