foreachmap.lua: add option of only printing matching file names (like grep -l)

Also, add convenience wrapper script findmaps.sh for quickly searching for
sprites/walls/sectors satisfying a certain condition in all map files under
a given directory.

git-svn-id: https://svn.eduke32.com/eduke32@3030 1a8010ca-5511-0410-912e-c29ae57300e0
This commit is contained in:
helixhorned 2012-09-26 22:54:01 +00:00
parent 599a2049e6
commit 99f9cfca7f
2 changed files with 25 additions and 5 deletions

View file

@ -0,0 +1,16 @@
#!/bin/sh
ok=yes
if [ -z "$1" ]; then
ok=
fi
if [ -z "$2" ]; then
ok=
fi
if [ -z "$ok" ]; then
echo "Usage: $0 <dir> <code for foreachmap.lua -e>"
exit 1
fi
find -L "$1" -name '*.map' -print0 | xargs -0 ./foreachmap.lua "-e$2"

View file

@ -31,7 +31,8 @@ if (#arg < 1) then
wr("The third form is a shortcut for quickly finding sectors/walls/sprites\n") wr("The third form is a shortcut for quickly finding sectors/walls/sprites\n")
wr("satisfying a certain condition (see example below)\n\n") wr("satisfying a certain condition (see example below)\n\n")
wr("Examples: ./foreachmap.lua -e\"if map.numbunches==1 then print(fn) end\" ~/.eduke32/*.map\n") wr("Examples: ./foreachmap.lua -e\"if map.numbunches==1 then print(fn) end\" ~/.eduke32/*.map\n")
wr(" ./foreachmap.lua -e\"sprite: .picnum==10 and .lotag==2563\" *.map\n\n") wr(" ./foreachmap.lua -e\"sprite: .picnum==10 and .lotag==2563\" *.map\n")
wr(" ./foreachmap.lua -e\"sprite:: ... -- (only prints the file names)\n\n")
return return
end end
@ -42,14 +43,17 @@ if (modname:sub(1,2) == "-e") then
local body = modname:sub(3) local body = modname:sub(3)
-- sector/wall/sprite finder shortcut -- sector/wall/sprite finder shortcut
local b, e, what = body:find("^([a-z]+):") local b, e, what = body:find("^([a-z]+)::?")
if (what) then if (what) then
local onlyfiles = (body:sub(e-1,e)=="::") -- "::" means "only list files" (like grep -l)
body = body:sub(e+1) body = body:sub(e+1)
body = body:gsub("%.[a-z]+", what.."[i]%0") body = body:gsub("%.[a-z]+", what.."[i]%0")
body = body =
"for i=0,num"..what.."s-1 do".. "for i=0,num"..what.."s-1 do\n"..
" if ("..body..") then print(fn..': '..i) end ".. " if ("..body..") then\n"..
"end" (onlyfiles and "print(fn); return\n" or "print(fn..': '..i)\n") ..
" end\n"..
"end\n"
end end
local successfunc, errmsg = loadstring( local successfunc, errmsg = loadstring(