From 3f4fd784c202574bb356b18fc6754d0148d7db50 Mon Sep 17 00:00:00 2001 From: Daniel Kolesa Date: Thu, 22 May 2014 14:07:02 +0100 Subject: [PATCH] elua: file search function --- src/bin/elua/apps/xgettext.lua | 2 ++ src/bin/elua/core/util.lua | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/bin/elua/apps/xgettext.lua b/src/bin/elua/apps/xgettext.lua index efd037f..5953fef 100644 --- a/src/bin/elua/apps/xgettext.lua +++ b/src/bin/elua/apps/xgettext.lua @@ -2,6 +2,7 @@ -- provides a drop-in replacement of xgettext that supports Lua (but not any -- other language) +local util = require("util") local cutil = require("cutil") local getopt = require("getopt") @@ -267,6 +268,7 @@ for i, fname in ipairs(input_files) do if not excluded_files[fname] then if onlylua or (not neverlua and fname:lower():match("^.+%.lua$")) then -- parse lua files here + local fpath = util.find_file(fname, search_dirs) else args_nolua[#args_nolua] = fname local f = assert(cutil.popenv(hasxgettext, "r", diff --git a/src/bin/elua/core/util.lua b/src/bin/elua/core/util.lua index 45267fc..a76c6d2 100644 --- a/src/bin/elua/core/util.lua +++ b/src/bin/elua/core/util.lua @@ -348,4 +348,22 @@ getmetatable("").__mod = function(fmts, params) return ret end +-- file utils + +M.find_file = function(fname, paths) + for i, path in ipairs(paths) do + local actual_path + if path:match(".*/") then + actual_path = path .. fname + else + actual_path = path .. "/" .. fname + end + local f = io.open(actual_path) + if f then + f:close() + return actual_path + end + end +end + return M \ No newline at end of file -- 2.7.4