Once the conversion of source records is complete, the citation references also need adjustment. There may be insertions of _FIELD items. In many cases, it is necessary to parse the contents of PAGE items.
I'm wondering if the code below is the best way to approach this. The function visitSourceReferences() is called with the target source record Id. The unlisted function, processSourceCitationTag(), prints out a debug message.
Code: Select all
local function visitSourceReferences(sourceRecordId)
local pi = fhNewItemPtr()
local recordsWithSources = {"INDI", "FAM", "OBJE", "NOTE", "_RNOT"}
for i, tag in ipairs(recordsWithSources) do
pi:MoveToFirstRecord(tag)
while not pi:IsNull() do
if fhGetTag(pi) == "SOUR" then
local ptrSourceRef = fhGetValueAsLink(pi)
if fhGetRecordId(ptrSourceRef) == sourceRecordId then
-- This source matches "sourceRecordId"
local childPtr = fhNewItemPtr()
if fhHasChildItem(pi) then
childPtr:MoveToFirstChildItem(pi)
while not childPtr:IsNull() do
-- Process child items of the citation
-- or insert new _FIELD items
processSourceCitationTag(childPtr)
childPtr:MoveNext()
end
end
end
end
pi:MoveNextSpecial()
end
end
end