fnmap = Hash.new # Uebersetzung alter Index --> neuer Index
fndir = Hash.new # Neuer Index --> Fussnotentext
footnote_number = 1 # aktuelle Fussnote, 0 wenn im Fussnotenbereich
File.open(ARGV[0]) do |file|
while line = file.gets
if line == "@footnote:\n"
footnote_number = 0
else
if footnote_number == 0
# Wir sind im Fussnoten-Bereich
line.scan(/^(\[\d+\]) (.*)/) do |idx,text|
fndir[fnmap[idx]] = text
fnmap.delete(idx) # wichtig fuer Memory-Verbrauch!
end
else
# Wir sind im Text-Bereich
line.gsub!(/\[\d+\]/) do |idx|
if not fnmap.has_key?(idx)
fnmap[idx] = "[#{footnote_number}]"
footnote_number += 1
end
fnmap[idx]
end
print line
end
end
end
# Jetzt geben wir die Fussnoten aus
print "\nFussnoten:\n"
for i in 1..fndir.size
k="[#{i}]"
if fndir.has_key?(k)
print "#{k} #{fndir[k]}\n"
else
print "#{k} <NOT AVAILABLE>\n"
end
end
end