-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathList Places.fh_lua
127 lines (122 loc) · 3.6 KB
/
List Places.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
--[[
@Title: Place List
@Author: Jane Taubman
@Version: 1.0
@LastUpdated: January 2013
@Description: Lists All Places in the selected database with a use count
]]
function main()
tblOutput,iC = createResultTable()
-- Define Columns
tblOutput.place = {title='Place',type='text',width=140,align='align_left',content={}}
tblOutput.reverseplace = {title='Reversed Place',type='text',width=140,align='align_left',content={}}
tblOutput.count = {title='Count',type='integer',width=140,align='align_left',content={}}
local places = {}
for ptr in allItems() do
if fhGetTag(ptr) == 'PLAC' then
local strPlace = fhGetValueAsText(ptr)
if places[strPlace] then
places[strPlace] = places[strPlace] + 1
else
places[strPlace] = 1
end
end
end
for i,c in pairs(places) do
iC = iC + 1
tblOutput.place.content[iC] = i
tblOutput.reverseplace.content[iC] = reverseString(i)
tblOutput.count.content[iC] = c
end
fhOutputResultSetTitles("All Places", "All Places", "Place List Date: %#x")
for t in tblOutput() do
fhOutputResultSetColumn(t.title, t.type, t.content, iC, t.width,t.align)
end
end
function reverseString(string)
local array = explode(',',string)
local newarray = {}
local i = #array
local j = 1
while i > 0 do
newarray[j] = array[i]
j = j + 1
i = i - 1
end
return table.concat(newarray,',')
end
function explode(div,str)
if (div=='') then return false end
local pos,arr = 0,{}
-- for each divider found
for st,sp in function() return string.find(str,div,pos,true) end do
table.insert(arr,trim(string.sub(str,pos,st-1))) -- Attach chars left of current divider
pos = sp + 1 -- Jump past current divider
end
table.insert(arr,trim(string.sub(str,pos))) -- Attach chars right of last divider
return arr
end
function trim(s)
return (s:gsub("^%s*(.-)%s*$", "%1"))
end
function allItems(...)
local iTypeCount = nil
local iPos = 1
local p1 = fhNewItemPtr()
local p2 = fhNewItemPtr()
local tblRecTypes = {}
if arg['n'] == 0 then
-- No parameter do all Record Types
iTypeCount = fhGetRecordTypeCount() -- Get Count of Record types
for i = 1,iTypeCount do
tblRecTypes[i] = fhGetRecordTypeTag(i)
end
else
-- Got Parameters Process them instead
tblRecTypes = arg
iTypeCount = arg['n']
end
p1:MoveToFirstRecord(tblRecTypes[iPos])
return function()
repeat
while p1:IsNotNull() do
p2:MoveTo(p1)
p1:MoveNextSpecial()
if p2:IsNotNull() then
return p2
end
end
-- Loop through Record Types
iPos = iPos + 1
if iPos <= iTypeCount then
p1:MoveToFirstRecord(tblRecTypes[iPos])
end
until iPos > iTypeCount
end
end
function createResultTable()
-- create metatable
local tblOutput_mt = {}
tblOutput_mt.col = 0
tblOutput_mt.seq = {}
tblOutput_mt.__newindex = function (t,k,v)
rawset(t,k,v) -- update original table
local m = getmetatable(t)
m.col = m.col + 1
table.insert(m.seq,k)
end
tblOutput_mt.__call = function (t)
local i = 0
local m = getmetatable(t)
local n = table.getn(m.seq)
return function ()
i = i + 1
if i <= n then return t[m.seq[i]] end
end
end
local tblOutput = {} -- Define Columns Table
setmetatable(tblOutput, tblOutput_mt)
local iC = 0 -- Define count of lines
return tblOutput,iC
end
main()