elua: file search function
authorDaniel Kolesa <d.kolesa@samsung.com>
Thu, 22 May 2014 13:07:02 +0000 (14:07 +0100)
committerDaniel Kolesa <d.kolesa@samsung.com>
Tue, 10 Jun 2014 14:48:51 +0000 (15:48 +0100)
src/bin/elua/apps/xgettext.lua
src/bin/elua/core/util.lua

index efd037f..5953fef 100644 (file)
@@ -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",
index 45267fc..a76c6d2 100644 (file)
@@ -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