home *** CD-ROM | disk | FTP | other *** search
/ Chip 2005 June / ccd0605.iso / Software / Shareware / Comunicatii / nat32 / RSS.TCL < prev    next >
Text File  |  2004-03-15  |  981b  |  42 lines

  1. #!tcl
  2.  
  3. #
  4. # RSS Paser
  5. #
  6.  
  7. set counter 0
  8. set item 0
  9. set tcount 0
  10. set lcount 0
  11. set link ""
  12. set title ""
  13.  
  14. # Parse STDIN line by line, write HTML to STDOUT
  15.  
  16. while {[set len [gets stdin line]] >= 0} {
  17.  
  18.     regsub -all "\\&" $line "\\\\&" line
  19.  
  20.     if {[regexp "<item(.*)>" $line]} { set item 1 }
  21.     if {[regexp "</item>" $line]} { set item 0 }
  22.     if {$item == 1} {
  23.         if {[regexp "<title>(.*)</title>" $line title]} {
  24.             regsub "<title>" $title "" title
  25.             regsub "</title>" $title "" title
  26.             incr tcount
  27.         }
  28.         if {[regexp "<link>(.*)</link>" $line link]} {
  29.             regsub "<link>" $link "" link
  30.             regsub "</link>" $link "" link
  31.             incr lcount
  32.         }
  33.         if {$tcount && $lcount} {
  34.             puts stdout "<br><a href=\"$link\">$title</a>"
  35.             incr counter
  36.             set tcount 0
  37.             set lcount 0
  38.         }
  39.     }
  40. }
  41. echo "<br> $counter links converted"
  42.