3 # HTML reference generator
8 ###########################################################################
16 if /([a-zA-Z+\-]+):(.*)/ =~ str then
23 if %r'//([^/]*)(/.*)' =~ str then
26 elsif %r'//([^/]*)$' =~ str then
30 if hostpart != '' then
31 if /(.*):(\d+)/ =~ hostpart then
41 if /(.*)#(.*)/ =~ str then
51 if s == 'news' or s == 'mailto' then
55 s += ":"+@port if @port.size > 0
57 s += "#"+@label if @label.size > 0
61 @scheme = current.scheme if @scheme == 'unknown'
62 @port = current.port if @host == '' and @port == ''
63 @host = current.host if @host == ''
64 unless @file =~ %r'^/' then
65 @file = File.expand_path(File.dirname(current.file)+'/'+@file)
73 if str =~ /<(.+)>/ then
77 @tagname = tags.shift.downcase
81 tn,tv = t.split(/\s*=\s*/,2)
84 @vals[tn.downcase] = tv
86 @vals[t.downcase] = TRUE
102 if tagname =~ /!--/ then
106 if @vals.size == 0 then
113 t += " #{a}=\"#{v}\""
127 if file.kind_of?(IO) then
136 def read_until(endsym)
140 while @bpos < @buf.size
148 if c == 10 || c == 13 then
171 @buf = Kconv.toeuc(@buf)
174 if @buf[@bpos] == TAG_START then
175 return Tag.new(read_until(TAG_END))
176 elsif @buf[@bpos] == AMP_START then
177 return read_until(AMP_END)
180 while i < @buf.size && @buf[i] != TAG_START && @buf[i] != AMP_START
183 r = @buf[@bpos,i-@bpos]
184 if i == @buf.size then
200 ################################ MAIN ####################################
204 body_finished = false
205 html_finished = false
207 immediate_ref = false
209 while ARGV[0] =~ /^-/
212 currentURL = URL.new(ARGV.shift)
218 if ARGV.size > 0 then
219 f = TokenStream.new(ARGV[0])
221 f = TokenStream.new(STDIN)
226 if tok.kind_of?(Tag) then
227 if tok.tagname == 'a' and !tok.switch('href').nil? then
228 refs[refnum] = tok.switch('href')
230 elsif tok.tagname == '/a' then
231 if immediate_ref then
233 if !currentURL.nil? then
234 r = URL.new(r).complete(currentURL).to_s
240 elsif tok.tagname == '/body' then
243 elsif tok.tagname == '/html' then
252 if !immediate_ref and refs.size > 0 then
253 print "<hr><h2>References</h2>\n"
254 for i in 0..refs.size-1
255 if currentURL.nil? then
259 r.complete(currentURL)
262 print "[#{i+1}] #{r}<br>\n"
265 print "</body>\n" unless body_finished
266 print "</html>\n" unless html_finished