#!/usr/local/bin/no -- read tables for Pilot's Todo application and write them out nicely -- by category -- pipe input from 'pdb unpack ToDoDB.pdb' -- requires the noweb 3 driver separator = "" showall = nil while argv[1] == "-n" or argv[1] == "-done" do case argv[1] of | "-n" => separator = " " | "-done" => showall = 1 end List.get(argv) end if argv[1] then dofile(argv[1]) else dofile() end function showtodo(t) if t.completed then write(format("[*] %s\n", t.description)) else write(format("[%d] %s\n", t.priority, t.description)) end if t.note then write(format(" %s\n", gsub(t.note, "\n", "\n "))) end end -- put list of categories in cats (alphabetical, then Unfiled) catlist = Database.appInfo.categories.categories cats = List.new { } i = 1 while catlist[i] do if catlist[i].name ~= "Unfiled" then List.put(cats, catlist[i].name) end i = i + 1 end cats = sort(alphacmp, cats) List.put(cats, "Unfiled") -- read records, put in table todosbycat records = Database.records todosbycat = { } -- maps category name to list of incomplete items i = 1 while records[i] do r = records[i].data if showall or not r.completed then c = r.category todosbycat[c] = todosbycat[c] or { } List.put(todosbycat[c], r) end i = i + 1 end i = 1 while cats[i] do t = todosbycat[cats[i]] if t then write(separator, cats[i], "\n", gsub(cats[i], ".", "~"), "\n\n") j = 1 while t[j] do showtodo(t[j]) j = j + 1 end write("\n\n\n") end i = i + 1 end