equal
deleted
inserted
replaced
14 local rfcdb = {} |
14 local rfcdb = {} |
15 |
15 |
16 local function parse_file (fname) |
16 local function parse_file (fname) |
17 local fh = io.open(fname) |
17 local fh = io.open(fname) |
18 |
18 |
19 if not fh then |
19 if not fh then return nil, "Cannot open RFC database" end |
20 print("Cannot open RFC database") |
|
21 return 255 |
|
22 end |
|
23 |
20 |
24 -- Skip header |
21 -- Skip header |
25 local count = 0 |
22 local count = 0 |
26 for line in fh:lines() do |
23 for line in fh:lines() do |
27 count = count + 1 |
24 count = count + 1 |
56 |
53 |
57 if data.title then |
54 if data.title then |
58 rfcdb[n] = data |
55 rfcdb[n] = data |
59 end |
56 end |
60 end |
57 end |
|
58 return true |
61 end |
59 end |
62 |
60 |
63 local function rfc_lookup_string (rfcstring) |
61 local function rfc_lookup_string (rfcstring) |
64 rfcstring = rfcstring:lower() |
62 rfcstring = rfcstring:lower() |
65 local r = "" |
63 local r = "" |
104 end |
102 end |
105 |
103 |
106 function rfc.cmd (rfcnum) |
104 function rfc.cmd (rfcnum) |
107 local empty = true |
105 local empty = true |
108 for i,v in pairs(rfcdb) do empty = false; break end |
106 for i,v in pairs(rfcdb) do empty = false; break end |
109 if empty then parse_file(indexfname) end |
107 if empty then |
|
108 local r, err = parse_file(indexfname) |
|
109 if not r then return nil, err end |
|
110 end |
110 |
111 |
111 if (rfcnum) then |
112 if (rfcnum) then |
112 rfcnum = rfcnum:gsub("^RFC[%s%-]*", "") |
113 rfcnum = rfcnum:gsub("^RFC[%s%-]*", "") |
113 rfcnum = rfcnum:gsub("^rfc[%s%-]*", "") |
114 rfcnum = rfcnum:gsub("^rfc[%s%-]*", "") |
114 rfcnum = rfcnum:gsub("[!%?%s:]+$", "") |
115 rfcnum = rfcnum:gsub("[!%?%s:]+$", "") |