-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenerations Pre-Load Source Clean.fh_lua
69 lines (63 loc) · 1.51 KB
/
Generations Pre-Load Source Clean.fh_lua
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
--[[
@Title: Generations Gedcom - Pre-Load
@Author: Jane Taubman
@LastUpdated: March 2021
@Description: Clean TEXT lines in sources so they don't get excluded.
]]
function string.starts(String,Start)
return string.sub(String,1,string.len(Start))==Start
end
function splitfilename(strfilename)
-- Returns the Path Filename and extension as 3 values
return string.match(strfilename, "(.-)([^\\]-([^%.]+))$")
end
require 'iuplua'
strProjectFile = ''
strProjectFile,strReturn = iup.GetFile(strProjectFile)
if strReturn ~= 0 then
return
end
path,name,ext = splitfilename(strProjectFile)
NewProjectFile = path..'updated-'..name
tblData = {}
tblNew = {}
tblText = {}
file = io.open(strProjectFile,'r')
if file then
for line in file:lines() do
table.insert(tblData,line)
end
file:close()
else
error('Bang')
end
i = 1
print(tblData[i])
print(#tblData)
newflag = false
bText = false
while tblData[i] ~= nil do
line = tblData[i]
if line == '1 TEXT ' then
-- Handle Blank lines
line = '1 TEXT '
end
level,key,rest = line:match('(.-) (.-) (.+)')
print(level,key,rest)
if level == '1' and key == 'TEXT' then
if bText then
key = 'CONT'
tblData[i] = '2 CONT '..rest
else
bText = true
end
else
bText = false
end
i = i + 1
end
data = table.concat(tblData, "\n") .. "\n"
file = io.open(NewProjectFile,'w')
file:write(data)
file:close()
fhMessageBox('File:'..NewProjectFile..' Created')