4 -- Copyright (c) Tuomo Valkonen 2004-2009. |
4 -- Copyright (c) Tuomo Valkonen 2004-2009. |
5 -- |
5 -- |
6 -- See the included file LICENSE for details. |
6 -- See the included file LICENSE for details. |
7 -- |
7 -- |
8 |
8 |
|
9 local lfs=require("lfs") |
|
10 local path=require("mypath") |
9 |
11 |
10 --DOC |
12 --DOC |
11 -- Make \var{str} shell-safe. |
13 -- Make \var{str} shell-safe. |
12 function string.shell_safe(str) |
14 function string.shell_safe(str) |
13 return "'"..string.gsub(str, "'", "'\\''").."'" |
15 return "'"..string.gsub(str, "'", "'\\''").."'" |
85 for k, v in pairs({...}) do |
87 for k, v in pairs({...}) do |
86 _G[v]=lib[v] |
88 _G[v]=lib[v] |
87 end |
89 end |
88 end |
90 end |
89 |
91 |
90 function io.openX(file, ...) |
92 function io.openX(file, mode) |
91 local f, err = io.open(file, ...) |
93 if mode=='w' then |
|
94 local dn = path.dirname(file) |
|
95 if not lfs.attributes(dn) then |
|
96 print("Ensure directory", dn) |
|
97 lfs.mkdir(dn) |
|
98 end |
|
99 end |
|
100 local f, err = io.open(file, mode) |
92 if not f then |
101 if not f then |
93 error(file..": "..err) |
102 error(file..": "..err) |
94 end |
103 end |
95 return f |
104 return f |
96 end |
105 end |