Remove largely unnecessary putenv() replacement
[platform/upstream/rpm.git] / luaext / linit.lua
1
2 rex.new = rex.newPOSIX
3
4 util = {}
5
6 function util.grep(expr, filename)
7         if not posix.stat(filename, "mode") then
8                 return nil
9         end
10         local lines = {}
11         local pat = rex.new(expr)
12         local pos = 1
13         for line in io.lines(filename) do
14                 if pat:match(line) then
15                         table.insert(lines, pos, line)
16                 end
17                 pos = pos + 1
18         end
19         if table.getn(lines) == 0 then
20                 return nil
21         end
22         return lines
23 end
24
25 function util.igrep(expr, filename)
26         return ipairs(rex.grep(expr, filename))
27 end
28
29 function util.bgrep(expr, filename)
30         if not posix.stat(filename, "mode") then
31                 return nil
32         end
33         local pat = rex.new(expr)
34         for line in io.lines(filename) do
35                 if pat:match(line) then
36                         return true
37                 end
38         end
39         return false
40 end
41