Switch to edit mode.
Name(s): _kick1: "Begin generic security check (_kick)"
2: if (verb == "_kick" && !args[1]:isa(this))
3: raise(E_INVARG, "Illegal object", args[1])
4: return E_INVARG
5: endif
6: "End generic security check (_kick)"
7: "Load an index document from Slashdot, and parse it slowly, step by step."
8: "Record all interim steps. Makes debugging a lot easier."
9: "First, get the page."
10: this.page1 = $network:get_url("http://slashdot.org/slashdot.rdf")
11: if (!this.page1)
12: return "Level 1 error"
13: endif
14: "Second, strip off the whitespace."
15: page2 = ""
16: for x in (this.page1)
17: page2 = page2 + $su:trim(x)
18: endfor
19: this.page2 = page2
20: if (!page2)
21: return "Level 2 error"
22: endif
23: "Third, break the text into html tokens."
24: this.page3 = $html_utils:html2token(this.page2)
25: "Fourth, use a finite state machine to extract the data."
26: title = ""
27: link = ""
28: prev = ""
29: titles = {}
30: links = {}
31: for x in (this.page3)
32: $command_utils:suspend_if_needed()
33: if (x == "<item>")
34: title = ""
35: link = ""
36: elseif (x == "</item>")
37: if (title && link)
38: titles = {@titles, title}
39: links = {@links, link}
40: endif
41: elseif (prev == "<title>" && x != "</title>")
42: title = x
43: elseif (prev == "<link>" && x != "</link>")
44: link = x
45: endif
46: prev = x
47: endfor
48: length(titles) == length(links) || raise(E_RANGE, "Can't happen.")
49: if (!titles)
50: return "Level 4 error"
51: endif
52: this.titles = titles
53: this.links = links
54: "Fifth, render the list for the end user."
55: text = ""
56: for x in [1..length(this.titles)]
57: text = tostr(text, "<LI><A HREF=\"", this.links[x], "\">", this.titles[x], "</A>")
58: endfor
59: this.text = "<OL>" + text + "</OL> News from <A HREF=\"http://slashdot.org\">Slashdot</A>."
60: "Last modified by Lao-Tzu (#8084) on Tue Dec 18 08:29:54 2001 MST."