-- This JFile database created by Norman Ramsey's pdb converter -- To use the output, get http://www.tecgraf.puc-rio.br/lua -- For more information, see http://www.cs.virginia.edu/~nr/pilot -- The value `Database' represents the database Database = { -- the first four fields are required name = "Locus Poll Results", type = "JbDb", creator = "JBas", version = 1, -- no flags are required (default to nil) backup = 1, -- Date format: -- unixtime is seconds since 1/1/1970. -- If unixtime is present, all other fields are ignored. -- Otherwise, as many fields as are present are used to construct -- a date, with missing fields defaulting to minimum values. -- The value `today' (without quotes!) may be used instead -- of a table; it is bound to a table with suitable unixtime dates = { create = { month = 6, day = 29, year = 1998, weekday = "Mon", hour = 22, min = 36, sec = 35, unixtime = "899174195" }, modify = today, backup = { month = 12, day = 31, year = 1969, weekday = "Wed", hour = 18, min = 59, sec = 59, unixtime = "4294967295" }, }, -- these next three fields default to 0 if omitted modnum = 19022, -- `version' is required. -- The `fields' array is required, and every element of it must be a -- table or a string. (If a string, it stands for a field with that -- name and all else defaulted.) -- The table doesn't have to contain anything, but 'name' is -- highly recommended. typenum has priority over type if both are -- present; missings types are strings. The type field can only be -- interpreted if the Typemap array is present. -- Everything else besides `fields' and `version' can be defaulted. appInfo = { -- standard relation between types and typenums Typemap = { string = 1, boolean = 2, date = 4, int = 8, float = 16, time = 32, popup = 64 }, version = 452, fields = { { type = "int", typenum = 8, width = 13, name = "Year" }, { type = "int", typenum = 8, width = 18, name = "#" }, { type = "string", typenum = 1, width = 60, name = "Author" }, { type = "string", typenum = 1, width = 80, name = "Title" }, { type = "string", typenum = 1, width = 80, name = "Publisher" }, { type = "string", typenum = 1, width = 80, name = "Category" }, { type = "string", typenum = 1, width = 80, name = "Other Title" }, } }, sortInfo = nil, -- Records: -- records must be an array, and each item a table. -- All fields except data can be omitted and default to 0 (or nil). -- delete = deleted busy = locked by an app -- secret = need passwd dirty = set at modify (cleared when?) records = { } } -- take a Database and write comma-separated values -- note this doesn't use C-like quoting conventions function writecsv(t) local fields, records i = 1 while t.appInfo.fields[i] do if i > 1 then write(',') end write(csvquote(t.appInfo.fields[i].name)) i = i + 1 end write('\n') j = 1 while t.records[j] do i = 1 while t.records[j].data[i] do if i > 1 then write(',') end write(csvquote(t.records[j].data[i])) i = i + 1 end write('\n') j = j + 1 end end function csvquote(s) -- convert newlines to blanks and repeat double quotes return '"' .. gsub(gsub(s, '"', '""'), '[\n\r]', ' ') .. '"' end ---------------------------------------------------------------- -- support for building a Locus database nextrec = 1 fmap = { } -- to get field name, lower case and strip spaces i = 1 while Database.appInfo.fields[i] do local s = gsub(strlower(Database.appInfo.fields[i].name), " ", "") fmap[i] = s fmap[s] = i i = i + 1 end numfields = i - 1 thisyear = "????" thiscat = "?" function setyear(s) thisyear = gsub(s, " Locus Poll", "") end function setcategory(s) thiscat = s end function additem(t) local i, r r = { } i = 1 while i <= numfields do if fmap[i] == "year" then r[i] = thisyear elseif fmap[i] == "category" then r[i] = thiscat else r[i] = (t[fmap[i]] or "") end i = i + 1 end Database.records[nextrec] = { data = r } -- write("Item ", nextrec, " is ", t.author, ": ", t.title, "\n") -- i = 1 -- while i <= numfields do -- write(" ", i, " = ", (r[i] and format('%q', r[i])) or "nil", "\n") -- i = i + 1 -- end nextrec = nextrec + 1 end if Database.modnum then Database.modnum = Database.modnum + 1 end dofile('/home/nr/etc/locus/novs.lua')