--[[
This program creates an index of all the soft links in the current filing system.
It requires RiscLua7.
--]]
local dir in require "riscos"
local open in io
local root = (obey$dir ""):gsub ("%$.*",  "$")
local j = "%s.%s"
local index = obey$dir ".index"
local db = { }
local note = \ (linkfile)
  local o = open (linkfile, "r")
  local srcfile = o:read  "*l"
  o:close ( )
  db[1 + #db] = { src = srcfile, link = linkfile }
  end -- function
local sweep, act
sweep = \ (d)
    for leaf, ttype in dir (d) do
       local this = j (d, leaf)
       local action = act[ttype]
       if action then action (this) end -- if
    end -- for
end -- function
act = { [0x1000] = sweep; [0xfdc] = note; }
sweep (root)
table.sort (db, \ (x, y) => x.src < y.src end)
local fmt = [[%s =>
 %s
]]
local o = open (index, "w")
for _, val in ipairs (db) do
  local src, link in val
  o:write (fmt (link, src))
end -- for
o:close ( )
local settypetext = "settype %s text"
os.execute (settypetext (index))
