|
1 | | -#!/usr/bin/env lua |
| 1 | +#!/usr/bin/env lua |
2 | 2 |
|
3 | 3 | help = [[ |
4 | 4 | DOS and UNIX disagree on what a new line should be |
@@ -43,47 +43,47 @@ local function Shebang(inFile) |
43 | 43 | return nil |
44 | 44 | end |
45 | 45 |
|
46 | | -for i = 1, #arg do |
47 | | - local iFile, err = io.open(arg[i]) |
48 | | - if not iFile then print(arg[i] .. ": " .. err) else |
49 | | - local oFile |
50 | | - oFile, err = io.open(arg[i] .. ".tmp", "wb") |
51 | | - if not oFile then |
52 | | - print(arg[i] .. ".tmp: " .. err) |
| 46 | +for j = 1, #arg do |
| 47 | + local i, e = io.open(arg[j]) |
| 48 | + if not i then print(arg[j] .. ": " .. e) else |
| 49 | + local o |
| 50 | + o, e = io.open(arg[j] .. ".tmp", "wb") |
| 51 | + if not o then |
| 52 | + print(arg[j] .. ".tmp: " .. e) |
53 | 53 | else |
54 | | - local shebang = Shebang(iFile) |
55 | | - if shebang then |
56 | | - oFile:write(shebang) |
| 54 | + local s = Shebang(i) |
| 55 | + if s then |
| 56 | + o:write(s) |
57 | 57 | while true do |
58 | | - local line = iFile:read("*l") |
59 | | - if line then |
60 | | - oFile:write(StripCarriage(line) .. CRLF) |
| 58 | + local l = i:read("*l") |
| 59 | + if l then |
| 60 | + o:write(StripCarriage(l) .. CRLF) |
61 | 61 | else |
62 | 62 | break |
63 | 63 | end |
64 | 64 | end |
65 | | - iFile:close() oFile:close() |
| 65 | + i:close() o:close() |
66 | 66 |
|
67 | 67 | --[[ |
68 | 68 | Swap the temporary file and original file around |
69 | 69 | so that the original files is being copied to. |
70 | 70 | This allows system file permissions to remain unchanged. |
71 | 71 | --]] |
72 | 72 |
|
73 | | - iFile = io.open(arg[i] .. ".tmp", "rb") |
74 | | - oFile = io.open(arg[i], "wb") |
75 | | - if iFile and oFile then |
| 73 | + i = io.open(arg[j] .. ".tmp", "rb") |
| 74 | + o = io.open(arg[j], "wb") |
| 75 | + if i and o then |
76 | 76 | while true do |
77 | | - local data = iFile:read(1024) |
78 | | - if not data then |
| 77 | + local d = i:read(1024) |
| 78 | + if not d then |
79 | 79 | break |
80 | 80 | end |
81 | | - oFile:write(data) |
| 81 | + o:write(d) |
82 | 82 | end |
83 | | - iFile:close() oFile:close() |
| 83 | + i:close() o:close() |
84 | 84 | end |
85 | 85 | end |
86 | | - os.remove(arg[i] .. ".tmp") |
| 86 | + os.remove(arg[j] .. ".tmp") |
87 | 87 | end |
88 | 88 | end |
89 | 89 | end |
0 commit comments