#!/usr/bin/ruby # vim: et sw=2 VER="(3437c6a)" ME="vlinks.rb: " $all_fields=["as","comment","speed"] $lst_fields=[] $str_fields=["comment"] $num_fields=["speed"] $mesh=false $incl=[] $excl=[] $skip=[] flags="" mode="txt" def is_fl(str,tp) tp.each_byte do |a| f=true str.each_byte do |b| if a==b f=false break end end return false if f end return true end def add_fl(str,tp) tp.each_byte do |a| f=true str.each_byte do |b| if a==b f=false break end end str.concat(a) if f end end def del_fl(str,tp) str.delete!(tp) end def in_list(s,list) for i in list if i.match(s) return true end end return false end def regexfix(str) tmp=[] for t in str.scan(/(_)|(\|)|([^_\|]*)/).flatten.compact tmp.push(t) if not t.empty? end res="" while t=tmp.shift case t when("_") then res+=(tmp.empty?) ? "( +|$)" : "( +)" when("|") then res+="|" else res+="(#{t})" end end return res end class Node attr_reader :nm attr_accessor :idx, :we def initialize(_nm,_hub) @nm=_nm @we=0.0 @as=nil @hub=_hub end def label return "#{@nm} (#{@as})" if @as return @nm end def color col=["#9eb0ff","#e6e6e6"] col[0]="#ef715a" if @as col[1]="#9eb0ff" if @hub return col end def add_as(_as) return if !_as or _as.empty? if !v=@as @as=_as return end v+=","+_as a=v.split(",") a.uniq! a.sort! v=a.join(",") @as=v end end class Link attr_reader :n1, :n2, :ml attr_accessor :we def initialize(_n1,_n2,_ml) @n1=_n1 @n2=_n2 @we=0.0 @ml=_ml @comment="" @attr={} end def attr(f,t=nil) if t v=@attr[f] if $lst_fields.include?(f) v=(v) ? v+","+t : t a=v.split(",") a.uniq! a.sort! { |x,y| scomp(x,y) } v=a.join(",") @attr[f]=v end if $str_fields.include?(f) v=(v) ? v+"; "+t : t @attr[f]=v end end return @attr[f] end def sattr(f) v=@attr[f] return (v) ? v.dump : "null" end end def in_fields(t,fields) fields.length.times do |i| return i if fields[i]==t end return nil end $nodes={} $links=[] def $nodes.add(nm,hub=false) if o=$nodes[nm] return o end o=Node.new(nm,hub) $nodes[nm]=o return o end def $links.get(n1,n2) for l in $links return l if l.n1==n1 and l.n2==n2 return l if l.n1==n2 and l.n2==n1 end return nil end def $links.add(n1,n2,ml=true) if l=$links.get(n1,n2) return l end l=Link.new(n1,n2,ml) $links<1 f=fields[i] t=tmp[j] i+=1 j+=1 n-=1 next if not $all_fields.include?(f) ll.attr(f,t) end next end nm=tmp[1].split(":")[0] next if nm.start_with?("-") or nm.start_with?("?") or nm.start_with?("(") next if not $incl.empty? and not in_list(nm,$incl) next if in_list(nm,$excl) if m=/<([^ <>]*)>/.match(s) next if is_fl(m[1],"X") end n2=$nodes.add(nm) we2=0.0 l=$links.add(n1,n2) next if fields.empty? fields.length.times do |k| break if !tmp[k] or tmp[k].empty? f=fields[k] next if not $all_fields.include?(f) str=tmp[k] m=/\<.*\> (.*)/.match(str) str=m[1] if m m=/(.*) \<.*\>/.match(str) str=m[1] if m m=/\[.*\] (.*)/.match(str) str=m[1] if m m=/(.*) \[.*\]/.match(str) str=m[1] if m next if /\<.*\>/.match(str) next if /\[.*\]/.match(str) if f=="speed" if not str.start_with?("-") and not str.start_with?("?") we2=str.to_f end next end if f=="as" n2.add_as(str) if not str.start_with?("-") and not str.start_with?("?") next end l.attr(f,str) end n2.we=we2 if we2>0 we=(we2>0 and we2]*)>/.match(s) next if is_fl(m[1],"i") end ns< ..." exit end i=0 while i=ARGV.length for l in $stdin l.chop! next if l.empty? next if /^! /.match(l) next if /^<[^>]*>$/.match(l) buf.push(l) end else while i
EOF f.close fork { exec("start /tmp/vlinks.htm") }