blob: 2d866dd9bf219fdf63742c7f1190bd939e0d8168 (
plain)
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
|
#!/opt/local/bin/lua
--
-- See ../README.md
--
--
-- Run as: lua ch-1.lua < input-file
--
for line in io . lines () do
--
-- Split into parts
--
local parts = {}
for part in line : gmatch ("[^/]+") do
table . insert (parts, part)
end
--
-- Copy to new structure
--
local parts2 = {}
for index, part in ipairs (parts) do
if part == "." then -- Current directory -> skip
goto continue
end
if part == ".." then -- Parent direction -> pop from new structure
table . remove (parts2)
goto continue
end
table . insert (parts2, part) -- Else, copy
::continue::
end
print ("/" .. table . concat (parts2, "/")) -- And print
end
|