'===========================================================================
' Subject: EXTRACT LINKS FROM TEXT FILE       Date: 01-20-00 (14:27)       
'  Author: Dave Navarro, Jr.                  Code: PBCC, PBDLL            
'  Origin: dave@powerbasic.com              Packet: PBCC.ABC
'===========================================================================
'This is a quick & dirty little utility I wrote to extract all of the links 
'in a text file and display them on the screen (redirectable).

FUNCTION PbMain()

   LOCAL htmlfile AS STRING
   LOCAL buffer   AS STRING
   LOCAL link     AS STRING
   LOCAL s        AS LONG
   LOCAL l        AS LONG

   htmlfile = TRIM$(COMMAND$)

   IF ISFALSE LEN(DIR$(htmlfile)) THEN
     PRINT "Error: "; htmlfile;" not found."
     EXIT FUNCTION
   END IF

   OPEN htmlfile FOR BINARY AS #1
     GET$ #1, LOF(1), buffer
   CLOSE #1

   STDOUT "File: " & htmlfile
   STDOUT ""

   s = 1
   DO
     REGEXPR "<a href=.+>.+</a>" IN buffer AT s TO s, l
     IF ISFALSE s THEN
       EXIT DO
     ELSE
       link = REMOVE$(MID$(buffer, s, l), ANY CHR$(13,10))
     END IF
     STDOUT link
     s = s + l
   LOOP

END FUNCTION
