File: LuaRocks.reg.lua

package info (click to toggle)
tarantool 2.6.0-1.4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 85,412 kB
  • sloc: ansic: 513,775; cpp: 69,493; sh: 25,650; python: 19,190; perl: 14,973; makefile: 4,178; yacc: 1,329; sql: 1,074; pascal: 620; ruby: 190; awk: 18; lisp: 7
file content (51 lines) | stat: -rw-r--r-- 1,142 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
-- Call this file using its full path and the template file as a parameter;
--
-- C:\> lua.exe "LuaRocks.reg.lua" "c:\luarocks\2.0\LuaRocks.reg.template"
--
-- it will strip the ".template" extension and write to that file the
-- template contents, where "<LUAROCKSPATH>" will be replaced by the path
-- to LuaRocks (including the trailing backslash)



-- Check argument
local f = (arg or {})[1]
if not f then
  print("must provide template file on command line")
  os.exit(1)
end

-- cleanup filepath, remove all double backslashes
while f:match("\\\\") do
  f =  f:gsub("\\\\", "\\")
end

-- extract path and name from argument
local p = ""
local ni = f
for i = #f, 1, -1 do
  if f:sub(i,i) == "\\" then
    ni = f:sub(i+1)
    p = f:sub(1, i)
    break
  end
end

-- create output name
local no = ni:gsub("%.template","")

-- create path substitute; escape backslash by doubles
local ps = p:gsub("\\", "\\\\")

-- read template
local fh = io.open(f)
local content = fh:read("*a")
fh:close()

-- fill template
content = content:gsub("%<LUAROCKSPATH%>", ps)

-- write destination file
fh = io.open(p..no, "w+")
fh:write(content)
fh:close()