added a way to edit, remove, and add words

This commit is contained in:
UndeadMaelys
2022-03-24 21:47:24 +01:00
parent 39335c7e09
commit 93da415c03
9 changed files with 396 additions and 177 deletions

View File

@@ -1,44 +1,45 @@
return function(query)
results_table = {}
for i=1, #words do
local exit = true
local all = true
for _, v in pairs(arg) do
if v == "-r" or v == "--raw" then
all = false
word = string.gsub(words[i][1],"%p","")
if string.find(word, query) then
exit = false
break
end
end
if v == "-e" or v == "--english" then
all = false
word = string.gsub(words[i][2],"%p","")
if string.find(word, query) then
exit = false
break
end
end
end
if all == true then
for j=1, #words[i]-1 do
word = string.gsub(words[i][j],"%p","")
if string.find(word, query) then
exit = false
break
end
end
end
if not exit then
local word = {i,words[i]}
table.insert(results_table,word)
end
end
if #results_table ~= 0 then
results_table = adjustTableSizes(results_table)
printOutputTable(results_table)
else
print("no words found for <" .. query .. ">")
end
end
function addWord()
number = tonumber(number)
-- open file
local file = io.open(data_get, "r")
local pos = 0
-- get insertion point
pos = file:seek("end",-9)
-- store after
local after = file:read("*all")
-- store before
file:seek("set")
local before = file:read(pos-1)
-- done reading
file:close()
modify = {}
print("insert new phonetics:")
modify[1] = io.read()
print("insert new meaning:")
modify[2] = io.read()
print("insert new type:")
modify[3] = io.read()
print("insert new canon origin:")
modify[4] = io.read()
print("insert new meta origin:")
modify[5] = io.read()
print("insert new notes:")
modify[6] = io.read()
local file = io.open(data_output, "w+")
file:write(before)
file:write("\ntable.insert(t,{\"")
for i=1, #modify do
if i > 1 then
file:write("\",\"")
end
file:write(modify[i])
end
file:write("\"})\n")
file:write(after)
file:close()
end