summaryrefslogtreecommitdiffstatshomepage
path: root/plugins/hiscore/sort_hiscore.lua
diff options
context:
space:
mode:
Diffstat (limited to 'plugins/hiscore/sort_hiscore.lua')
-rw-r--r--plugins/hiscore/sort_hiscore.lua108
1 files changed, 52 insertions, 56 deletions
diff --git a/plugins/hiscore/sort_hiscore.lua b/plugins/hiscore/sort_hiscore.lua
index b63bfe1673a..7d1f0031558 100644
--- a/plugins/hiscore/sort_hiscore.lua
+++ b/plugins/hiscore/sort_hiscore.lua
@@ -81,20 +81,20 @@ end
lstfile:close()
local sorted = {}
-local comments = 0
+local sindex = {}
+local comments = ""
-for num, entry in ipairs(entries) do
+for num, entry in pairs(entries) do
if not entry.name then
if entry.comment then
if entry.comment[1]:sub(2,4) ~= "@s:" then
- comments = comments + 1
- table.insert(sorted, comments, entry)
+ comments = comments .. table.concat(entry.comment, "\n") .. "\n"
end
end
else
table.sort(entry.name)
entry.src = "source not found"
- for num, name in ipairs(entry.name) do
+ for num, name in pairs(entry.name) do
name = name:match("[^,]*")
if not list[name] then
entry.name[num] = entry.name[num] .. ": ; missing"
@@ -103,61 +103,60 @@ for num, entry in ipairs(entries) do
entry.src = list[name]
end
end
+ entry.data = table.concat(entry.data, "\n")
+ if entry.comment then
+ entry.comment = table.concat(entry.comment, "\n")
+ end
sorted[#sorted + 1] = entry
+ if not sindex[entry.src] then
+ sindex[entry.src] = {}
+ end
+ sindex[entry.src][#sorted] = entry
end
end
-for num1, entry in ipairs(sorted) do
- if entry.data then
- for num2, entry2 in ipairs(sorted) do
- if entry2.data and entry.src == entry2.src and entry ~= entry2 and #entry.data == #entry2.data then
- for i = 1, #entry2.data do
- if entry.data[i] ~= entry2.data[i] then
- break
- end
- if i == #entry2.data then
- for num3, name in ipairs(entry2.name) do
- entry.name[#entry.name + 1] = name
- end
- if entry2.comment then
- for num3, comment in ipairs(entry2.comment) do
- if not entry.comment then
- entry.comment = {}
- end
- entry.comment[#entry.comment + 1] = comment
- end
- end
- sorted[num2] = {}
+for src, entries in pairs(sindex) do
+ for num1, entry in pairs(entries) do
+ for num2, entry2 in pairs(entries) do
+ if entry ~= entry2 and entry.data == entry2.data then
+ for num3, name in pairs(entry2.name) do
+ entry.name[#entry.name + 1] = name
+ end
+ if entry2.comment then
+ if not entry.comment then
+ entry.comment = entry2.comment
+ elseif entry.comment ~= entry2.comment then
+ entry.comment = entry.comment .. "\n" .. entry2.comment
end
end
+ sorted[num2] = {}
+ entries[num2] = {}
end
end
end
end
-for num1, entry in ipairs(sorted) do
+local nindex = {}
+
+for num1, entry in pairs(sorted) do
if entry.name then
- for num2, name in ipairs(entry.name) do
+ for num2, name in pairs(entry.name) do
local curname = name:match("[^:]*")
- for num3, entry2 in ipairs(sorted) do
- if entry2.name and entry.src == entry2.src then
- for num4, name2 in ipairs(entry2.name) do
- if curname == name2:match("[^:]*") then
- if entry ~= entry2 then
- print(name, "duplicate name")
- elseif num2 ~= num4 then
- entry2.name[num4] = nil
- end
- end
- end
+ if nindex[curname] then
+ if nindex[curname] == entry then
+ entry.name[num2] = ""
+ else
+ print(curname, "duplicate name")
end
+ else
+ nindex[curname] = entry
end
end
end
end
-- copyright 2010 Uli Schlachter GPLv2
-function stable_sort(list, comp)
+local function stable_sort(list, comp)
-- A table could contain non-integer keys which we have to ignore.
local num = 0
for k, v in ipairs(list) do
@@ -198,24 +197,21 @@ stable_sort(sorted, function(a,b)
end
end)
-src = "error";
+local src = "error";
+
+print(comments)
for num, entry in ipairs(sorted) do
- local function printall(table)
- for num, str in ipairs(table) do
- print(str)
- end
- end
- if entry.src and entry.src ~= src then
- print(";@s:" .. entry.src .. "\n")
- src = entry.src
- end
- if entry.comment then
- printall(entry.comment)
- end
if entry.name then
- printall(entry.name)
- printall(entry.data)
+ if entry.src and entry.src ~= src then
+ print(";@s:" .. entry.src .. "\n")
+ src = entry.src
+ end
+ if entry.comment then
+ print(entry.comment)
+ end
+ print(table.concat(entry.name, "\n"))
+ print(entry.data)
+ print("\n")
end
- print("\n")
end