144 lines
3.1 KiB
Lua
144 lines
3.1 KiB
Lua
function editWord(number)
|
|
number = tonumber(number)
|
|
-- determine modifications
|
|
local modify_all = true
|
|
local reenable_modify_all = false
|
|
local mph = false
|
|
local mm = false
|
|
local mt = false
|
|
local mco = false
|
|
local mmo = false
|
|
local mn = false
|
|
|
|
for _, v in pairs(arg) do
|
|
if v == "--modify-phonetics"
|
|
or v == "-mph" then
|
|
modify_all = false
|
|
mph = true
|
|
end
|
|
if v == "--modify-meaning"
|
|
or v == "-mm" then
|
|
modify_all = false
|
|
mm = true
|
|
end
|
|
if v == "--modify-type"
|
|
or v == "-mt" then
|
|
modify_all = false
|
|
mt = true
|
|
end
|
|
if v == "--modify-canon-origin"
|
|
or v == "-mco" then
|
|
modify_all = false
|
|
mco = true
|
|
end
|
|
if v == "--modify-meta-origin"
|
|
or v == "-mmo" then
|
|
modify_all = false
|
|
mmo = true
|
|
end
|
|
if v == "--modify-notes"
|
|
or v == "-mn" then
|
|
modify_all = false
|
|
mn = true
|
|
end
|
|
if v == "--modify-all"
|
|
or v == "-ma" then
|
|
reenable_modify_all = true
|
|
end
|
|
end
|
|
if reenable_modify_all then
|
|
modify_all = true
|
|
end
|
|
-- open file
|
|
local file = io.open(data_get, "r")
|
|
local text = file:read("*all")
|
|
local pos = 0
|
|
|
|
-- move to line
|
|
for i=1, number do
|
|
local npos = string.find(text,"\n",pos+1)
|
|
if npos == nil then break end
|
|
pos = npos
|
|
end
|
|
|
|
file:seek("set",0)
|
|
local before = file:read(pos)
|
|
file:seek("set",pos)
|
|
|
|
-- move to things to modify
|
|
pos = string.find(text,"{\"",pos)+1
|
|
file:seek("set",pos)
|
|
|
|
modify = {}
|
|
for i=1, 6 do
|
|
-- find next "
|
|
length = string.find(text,"\"",pos+1)-pos
|
|
table.insert(modify,file:read(length-1))
|
|
if i < 6 then
|
|
pos = string.find(text,"\"",pos+length+1)
|
|
end
|
|
file:seek("set",pos)
|
|
end
|
|
file:seek("set",string.find(text,"})",pos+length+1)+1)
|
|
local after = file:read("*all") or ""
|
|
file:close()
|
|
|
|
print("FILE:")
|
|
print(" phonetics",modify[1])
|
|
print(" meaning",modify[2])
|
|
print(" type",modify[3])
|
|
print(" canon origin",modify[4])
|
|
print(" meta origin",modify[5])
|
|
print(" notes",modify[6])
|
|
|
|
print("")
|
|
if modify_all or mph then
|
|
print("insert new phonetics:")
|
|
modify[1] = io.read()
|
|
end
|
|
if modify_all or mm then
|
|
print("insert new meaning:")
|
|
modify[2] = io.read()
|
|
end
|
|
if modify_all or mt then
|
|
print("insert new type:")
|
|
modify[3] = io.read()
|
|
end
|
|
if modify_all or mco then
|
|
print("insert new canon origin:")
|
|
modify[4] = io.read()
|
|
end
|
|
|
|
if modify_all or mmo then
|
|
print("insert new meta origin:")
|
|
modify[5] = io.read()
|
|
end
|
|
|
|
if modify_all or mn then
|
|
print("insert new notes:")
|
|
modify[6] = io.read()
|
|
end
|
|
|
|
print("NEW:")
|
|
print(" phonetics",modify[1])
|
|
print(" meaning",modify[2])
|
|
print(" type",modify[3])
|
|
print(" canon origin",modify[4])
|
|
print(" meta origin",modify[5])
|
|
print(" notes",modify[6])
|
|
|
|
--rewrite with new info
|
|
local file = io.open(data_output, "w+")
|
|
file:write(before)
|
|
file:write("\n")
|
|
for i=1, #modify do
|
|
if i > 1 then
|
|
file:write(" ")
|
|
end
|
|
file:write(modify[i])
|
|
end
|
|
file:write("")
|
|
file:write(after)
|
|
file:close()
|
|
end
|