From 99f9cfca7f64a131e8ea627906a5cd45f426a031 Mon Sep 17 00:00:00 2001 From: helixhorned Date: Wed, 26 Sep 2012 22:54:01 +0000 Subject: [PATCH] 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 --- polymer/eduke32/source/lunatic/findmaps.sh | 16 ++++++++++++++++ polymer/eduke32/source/lunatic/foreachmap.lua | 14 +++++++++----- 2 files changed, 25 insertions(+), 5 deletions(-) create mode 100755 polymer/eduke32/source/lunatic/findmaps.sh diff --git a/polymer/eduke32/source/lunatic/findmaps.sh b/polymer/eduke32/source/lunatic/findmaps.sh new file mode 100755 index 000000000..2df7491c8 --- /dev/null +++ b/polymer/eduke32/source/lunatic/findmaps.sh @@ -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 " + exit 1 +fi + +find -L "$1" -name '*.map' -print0 | xargs -0 ./foreachmap.lua "-e$2" diff --git a/polymer/eduke32/source/lunatic/foreachmap.lua b/polymer/eduke32/source/lunatic/foreachmap.lua index f7a4c92bd..841d8a41d 100755 --- a/polymer/eduke32/source/lunatic/foreachmap.lua +++ b/polymer/eduke32/source/lunatic/foreachmap.lua @@ -31,7 +31,8 @@ if (#arg < 1) then 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("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 end @@ -42,14 +43,17 @@ if (modname:sub(1,2) == "-e") then local body = modname:sub(3) -- sector/wall/sprite finder shortcut - local b, e, what = body:find("^([a-z]+):") + local b, e, what = body:find("^([a-z]+)::?") if (what) then + local onlyfiles = (body:sub(e-1,e)=="::") -- "::" means "only list files" (like grep -l) body = body:sub(e+1) body = body:gsub("%.[a-z]+", what.."[i]%0") body = - "for i=0,num"..what.."s-1 do".. - " if ("..body..") then print(fn..': '..i) end ".. - "end" + "for i=0,num"..what.."s-1 do\n".. + " if ("..body..") then\n".. + (onlyfiles and "print(fn); return\n" or "print(fn..': '..i)\n") .. + " end\n".. + "end\n" end local successfunc, errmsg = loadstring(