'===========================================================================
' Subject: HTML VIEWER V1.02 FOR PB           Date: 11-02-97 (14:45)       
'  Author: Ian Smith                          Code: PB                     
'  Origin: ian@isis.demon.co.uk             Packet: HTML.ABC
'===========================================================================
'HTML Viewer - Ian Smith - ian@isis.demon.co.uk - PB 3.2
'I regard it as PD, so feel free to do with it as you wish...
'
'Written to view HTML docs, select links and, optionally, put the
'URLs for those links into a script for collection.
'
'Use: hv <htmlfile> (.htm suffix not required, but if the suffix is
'                    anything other than .htm the suffix *is* required.)
'
'Keys: Home        - go to top of file
'      Up arrow    - move display up one line
'      Down arrow  - move display down one line
'      End         - go to end of file  
'      Page down   - move display down one page
'      Space bar   - ditto
'      Page up     - move display up one page
'      TAB         - jump highlight to next link
'      Enter       - save URL from highlighted link
'      Esc         - Exit
'
'History:
'HTML decoder was inspired by the  V3.07 one in the ABC collection,
'written by Toshigiro Horie.
'Converted to PB and modified to pull URLs from the page.
'That was a long time ago...
'
'Small memory model with minimal string allocation to run under
'YAN 1.3 (KA9Q). Speed traded for size.... 

$STRING 1
OPTION BINARY BASE 1
DEFINT A-Z
'$DYNAMIC
DECLARE SUB Process(file$)
DECLARE SUB URLproc()
DECLARE SUB Pullhref()
DECLARE SUB Pullimf()
DECLARE SUB Textout()
DECLARE SUB Htmlproc()
DECLARE SUB Catchall()
DECLARE SUB Bypass()
DECLARE SUB Lineproc(cline$)
DECLARE SUB Entities(cline$)
DECLARE SUB Spaces(cline$)
DECLARE SUB Tabs(cline$)
DECLARE SUB Display()
DECLARE SUB Debug()

SHARED urlcnt%, lcnt%, tabby%, count%,filesize&, textarrow%
SHARED fg%, quit%, html%, pre%, cols%, textarrow%, xline$
SHARED aline$, baseadd$, version$, a$, table%, Title$, order%
DIM httpc(300) AS SHARED INTEGER   'HTTP col position def
DIM httpl(300) AS SHARED INTEGER   'HTTP line position def
DIM http(300) AS SHARED STRING	   'HTTP URLs
DIM url(50) AS SHARED STRING       'URLs pulled for script
DIM pline(3000) AS SHARED STRING   'display lines
Version$ = "1.02"
CMD$ = UCASE$(COMMAND$)     ' command line string
Title$ = "HTML VIEWER V" + version$

SCREEN 0
CLS
COLOR 7, 0
IF INSTR(Cmd$, ".HTM") = 0 THEN Cmd$ = Cmd$ + ".HTM"
IF Cmd$ = ".HTM" OR Cmd$ = "" THEN
	PRINT "File not found"
        END
END IF
'                           OK, we've got a valid page to process
Process Cmd$
Display
URLproc
' Debug    ' display and log some diags stuff and log the converted doc.
END
'-------------------------------------------------------------------------
SUB Debug			' debug data - can be dropped
	OPEN "DEBUG" FOR OUTPUT AS #2
	       	PRINT #2,"         --==< Debug Info >==--"
		PRINT #2, USING "Free Memory: #######. Stack low water mark: ####.";fre(-1), fre(-2)
		PRINT #2, USING "Display lines used: ####. URLs found: ###."; lcnt%, count%
		PRINT #2, USING "HTML file size: ######.";filesize&
		PRINT #2, " "
		FOR db% = 1 to lcnt%
		PRINT #2, pline$(db%)
		NEXT
	CLOSE
	PRINT "         --==< Debug Info >==--"
	PRINT USING "Free Memory: #######. Stack low water mark: ####.";fre(-1), fre(-2)
	PRINT USING "Display lines used: ####. URLs found: ###."; lcnt%, count%
	PRINT USING "HTML file size: ######.";filesize&
END SUB
'-------------------------------------------------------------------------
SUB Process (file$)
a$ = " "
lcnt% = 1

LOCATE 1, 1
COLOR 11,1
PRINT Title$, TAB(80);
LOCATE 1, 81 - LEN(file$)
PRINT file$;
LOCATE 1, 36
COLOR 11, 1
LOCATE 25, 1
COLOR 0, 7
PRINT TAB(80):PRINT " ";
VIEW TEXT (pbvScrnCols,2) - (pbvScrnCols,24)	'progress window
COLOR 14,3
CLS
VIEW TEXT (1,2)-(pbvScrnCols - 1,24)	' text page
COLOR 7,0
PRINT "Reading input file..."
OPEN file$ FOR BINARY AS #1
filesize& = LOF(1)
GET #1, 1, a$
WHILE NOT EOF(1)
       	IF a$ > CHR$(31) THEN				' legit characters
		IF a$ = "<" OR h% = 1 THEN		' HTML field
                	CALL Htmlproc
	      	ELSE
                	CALL Textout			' Plain text
	      	END IF
        END IF
WEND
CLOSE
END SUB
'------------------------------------------------------------------------
SUB URLproc                    'process selected URLs
VIEW TEXT (1,1)-(pbvScrnCols,25)
COLOR 7, 0
CLS
' print baseadd$
IF LEFT$(baseadd$,4) = "<!--" THEN   ' get the base URL address from the label
	m% = LEN(baseadd$)
	FOR n% = 1 TO m%
		IF MID$(baseadd$,n%,1) = "/" THEN chpos% = n%
	NEXT
	baseadd$ = MID$(baseadd$,13,chpos% - 13) + "/"
ELSE
	baseadd$ = ""
END IF

IF urlcnt% > 0 THEN
	PRINT "Do you want to put tagged URLs into a script ?"
        DO
	       	rep$ = INKEY$
        LOOP UNTIL rep$ <> ""
        IF UCASE$(rep$) = "Y" THEN
        	PRINT "These are the extracted URLs:"
	         OPEN "WEB.SCR" FOR OUTPUT AS #1
		FOR n% = 1 to urlcnt%
        		test$ = UCASE$(LEFT$(url$(n%),5))
	        	IF test$ = "HTTP:" THEN            ' full URL, I hope !
        	        	full_url$ = MID$(url$(n%),8,80)
                                IF UCASE$(LEFT$(full_url$,3)) = "FTP" THEN
                                	full_url$ = "# " + full_url$
                                END IF
			ELSEIF test$ = "MAILT" THEN             ' mail
				ITERATE FOR	   		'skip it
			ELSE                                    ' local doc
                        	IF LEFT$(url$(n%),2) = ".." THEN     ' back a dir
					truncated$ = LEFT$(baseadd$, LEN(baseadd$) - 1)
                                        WHILE RIGHT$(truncated$,1) <> "/"
						truncated$ = LEFT$(truncated$, LEN(truncated$) - 1)
                                        WEND
                                        full_url$ = truncated$ + RIGHT$(url$(n%), LEN(url$(n%))-2)
                                ELSE
	                        	full_url$ = baseadd$ + url$(n%)
                                END IF
                        END IF
                        sfx$ = UCASE$(RIGHT$(full_url$,3))
                                	' HTML page - add label
                        SELECT CASE (sfx$)
                                CASE "TML", "HTM"
                               		full_url$ = full_url$ + " label"
                                CASE "GIF", "JPG", "ZIP", "EXE", "TXT"
                                       	'do nothing - it's OK
                                CASE ELSE
                                       	IF TALLY(sfx$, ANY ".") = 0 THEN
                                        	full_url$ = full_url$ + "/ label"
                                        END IF
                        END SELECT
        	        REPLACE "//" WITH "/" IN full_url$ ' deal, hopefully,
                	REPLACE "//" WITH "/" IN full_url$ ' with multiple /'s
                        PRINT #1, full_url$
        	        PRINT full_url$
		NEXT
	        CLOSE
        END IF
END IF
END SUB
'--------------------------------------------------------------------------
SUB Pullhref                                    ' extract URLs
	WHILE a$ <> ">"
        	GET$ #1, 1, a$
                aline$ = aline$ + a$
        WEND
    	href$ = MID$(aline$, INSTR(aline$, CHR$(34)) + 1, 80)
        IF href$ = aline$ THEN
		href$ = MID$(aline$, INSTR(aline$, "=") + 1, 80)
	        href$ = LEFT$(href$, INSTR(href$, ">") - 1)
         ELSE
                l% = LEN(href$)
         	IF l% > 70 THEN
                	href$ = "Too damned long !"
                ELSE
                	e% = INSTR(href$, CHR$(34))
                	IF e% > 0 THEN
                        	href$ = LEFT$(href$, e% - 1)
                        ELSE
                        	href$ = LEFT$(href$,l% - 1)
                        END IF
         	END IF
        END IF
	INCR count%:http$(count%) = href$
        IF cols% > 65 THEN INCR lcnt%: cols% = 0
        fg% = 182
	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%) + "*"
        INCR cols%
        CALL Lineproc(pline$(lcnt%))
      	httpc%(count%) =  LEN(pline$(lcnt%)) - 1
        httpl%(count%) = lcnt%
END SUB
'------------------------------------------------------------------------
SUB Bypass                                ' skip rest of html field
	WHILE a$ <> ">" AND NOT EOF(1)
                GET$ #1,1, a$
'        color 15,1:print a$;
        WEND
        h% = 0
END SUB
'--------------------------------------------------------------------------
SUB Textout				' Stuff the test into the array
	WHILE a$ <> "<" AND NOT EOF(1)
        	GET$ #1, 1, a$
      '  color 15,1:print a$;
                IF a$ = CHR$(13) OR a$ = "<" THEN	' LFs and html start
                       	'discard em

		ELSEIF pre% = 1 THEN			' preformatted text
                	IF a$ = CHR$(10) THEN		' LF
                	        pline$(lcnt%) = pline$(lcnt%) + word$
	                       	CALL Lineproc(pline$(lcnt%))
     '  color 15,2:print pline$(lcnt%);
	                	INCR lcnt%
        	                pline$(lcnt%) = CHR$(fg%)
                        	cols% = LEN(word$) + 1
	                        word$ = ""
           	     	ELSE
	                	word$ = word$ + a$
                        END IF

		ELSE				        'unformatted text
                	IF a$ = CHR$(10) THEN a$ = " "	'replace CR with space
	               	IF a$ = " " THEN	' word break
                               	IF cols% + LEN(word$) < 80 THEN	'fits in
                                       	pline$(lcnt%) = pline$(lcnt%) + word$
                                        cols% = cols% + LEN(word$)
                                        word$ = ""
                                ELSE                        ' new line
                                       	CALL Lineproc(pline$(lcnt%))
                                       	INCR lcnt%
                                        pline$(lcnt%) = CHR$(fg%)
                                        pline$(lcnt%) = pline$(lcnt%) + word$
                                        cols% = LEN(word$)
                                        word$ = ""
                                END IF
     '  color 15,5:print pline$(lcnt%);
                        END IF
                        word$ = word$ + a$
	        END IF
        WEND					' end of text - add to line
        IF cols% + LEN(word$) < 80 THEN  	'fits in
       	       	pline$(lcnt%) = pline$(lcnt%) + " " + word$
                CALL Lineproc(pline$(lcnt%))
               	cols% = cols% + LEN(word$) + 1
                word$ = ""
       	ELSE                        		' new line
       		CALL Lineproc(pline$(lcnt%))
             	INCR lcnt%
       	        pline$(lcnt%) = CHR$(fg%)
               	pline$(lcnt%) = pline$(lcnt%) + word$
                cols% = LEN(word$)
       	        word$ = ""
        END IF
        h% = 1
      '     color 11,6:print a$;
END SUB
'------------------------------------------------------------------ entities
SUB Entities(cline$)
	IF INSTR(cline$,"&") > 0 THEN
		REPLACE  "&quot;" WITH CHR$(34) IN cline$      	'quote
                REPLACE  "&copy;" WITH "(c)" IN cline$		'copy
                REPLACE  "&amp;" WITH "&" IN cline$		'&
       		REPLACE  "&tilde;" WITH "~" IN cline$		'tilde
                REPLACE  "&aacute;" WITH "" IN cline$		'a acute
		REPLACE  "&eacute;" WITH "" IN cline$		'e acute
                REPLACE  "&iacute;" WITH "" IN cline$		'i acute
                REPLACE  "&uacute;" WITH "" IN cline$		'u acute
                REPLACE  "&uuml;" WITH "" IN cline$		'umlat
                REPLACE  "&lt;" WITH "<" IN cline$		'less than
                REPLACE  "&nbsp;" WITH " " IN cline$		'non break space
                REPLACE  "&gt;" WITH ">" IN cline$		'greater than
        END IF
END SUB
'-------------------------------------------------------------------- TABs
SUB Tabs(cline$)
	tab_no% = TALLY(cline$, CHR$(9))
	IF INSTR(cline$, CHR$(10)+CHR$(9)) = 0 THEN
        	REPLACE CHR$(9) WITH "    " IN cline$
                cols% = cols% + tab_no% * 3
        ELSE
        	REPLACE CHR$(9) WITH "" IN cline$
                cols% = cols% - tab_no%
        END IF
END SUB
'-------------------------------------------------------------------- spaces
SUB Spaces(cline$)			' strip out extraneous spaces
	IF pre% = 0 AND INSTR(cline$, "  ") > 0 THEN
        	extra_spc% = TALLY(cline$, "   ")
                REPLACE "   " WITH " " IN cline$
                cols% = cols% - extra_spc% * 2
        	extra_spc% = TALLY(cline$, "  ")
                REPLACE "  " WITH " " IN cline$
                cols% = cols% - extra_spc%

        END IF
END SUB
 '--------------------------------------------------------------------------
 SUB Display
        n% = 1: dline% = 1
        COLOR 7, 0
	CLS
	n% = 1: dline% = 1
 	DO
        	IF n% >= lcnt% THEN n% = lcnt% - 22
	        IF n% < 1 THEN n% = 1                 'set the limits
                WHILE dline% < 24 AND n% < lcnt% + 1
                	LOCATE dline%, 1
	        	FOR m% = 1 TO LEN(pline$(n%))
        	        	char$ = MID$(pline$(n%),m%,1)

 'Colour character code
 ' = 180,  = 181  = 182,  = 183,  = 184,  = 185,  = 186,  = 187
 ' = 188,  = 189,  = 190,  = 191,  = 192,  = 193,  = 194,  = 195

                	        IF ASC(char$) > 180 AND ASC(char$) < 212 THEN
                        		fg% = ASC(char$)
                                	IF fg% = 205 THEN    ' title
	                                	COLOR 15,1
                        	        ELSEIF fg% = 208 THEN   ' blink
                                		COLOR 28,0
                                                fg% = 28
					ELSE
                                                IF m% = httpc%(tabby%) AND n% = httpl%(tabby%) THEN
							COLOR 0, 3
                                                ELSE
	                        			fg% = fg% - 180
                                                       ' print fg%
        	                        	        COLOR fg%, 0
                                                END IF
	                                END IF
        	                ELSE
                	        	PRINT char$;
                        	END IF
			NEXT
        	         INCR n%: INCR dline%:
                        IF CSRLIN < 23 THEN PRINT
		WEND
       	        progress% = 23 * n% / lcnt%
               	IF progress% < 1 THEN progress% = 1
                IF progress% > 23 THEN progress% = 23
                VIEW TEXT (pbvScrnCols,2) - (pbvScrnCols, 24)
       	        COLOR 14,3
                CLS
                LOCATE progress%, 1
                PRINT CHR$(220);		' block progress marker
                VIEW TEXT (1,2) - (pbvScrnCols - 1, 24)
		DO
               		DO
				U$ = INKEY$
                  	LOOP UNTIL U$ <> ""
       	               	SELECT CASE U$
                	        		   ' End
                       		CASE CHR$(0) + CHR$(79)
                                	dline% = 1:n% = lcnt% - 22
					COLOR 7, 0
					CLS
					EXIT DO

	                        		   ' Home
       	                	CASE CHR$(0) + CHR$(71)
                                	dline% = 1: n% = 1
					COLOR 7, 0
					CLS
					EXIT DO

                                	           'Page up
                                CASE CHR$(0) + CHR$(73)
                                	dline% = 1: n% = n% - 46
                                        COLOR 7, 0
					CLS
					EXIT DO
                                	           'Arrow  up
                                CASE CHR$(0) + CHR$(72)
                                	dline% = 1: n% = n% - 24
					COLOR 7, 0
					CLS
					EXIT DO

	                                           'Page down, SPACE also works
				CASE CHR$(0) + CHR$(81), CHR$(32)
                                        dline% = 1
                                        COLOR 7, 0
					CLS
               	                        EXIT DO
	                                           'Arrow down
				CASE CHR$(0) + CHR$(80)
                                        dline% = 1:n% = n% - 22
                       	                COLOR 7, 0
					CLS
               	                        EXIT DO

                                            ' TAB round the visible http refs
                                CASE CHR$(09)
               	                	INCR tabby%
                       	                IF tabby% > count% THEN tabby% = 1
                               	        VIEW TEXT (1,25)-(pbvScrnCols,25)
                                       	COLOR 0, 7
                                        CLS
                                        IF UCASE$(LEFT$(http$(tabby%),4)) = "HTTP" THEN
               	                        	PRINT LEFT$(http$(tabby%),79);
                       	                ELSEIF UCASE$(LEFT$(http$(tabby%),4)) = "MAIL" THEN
                               	        	PRINT LEFT$(http$(tabby%),79);
                                       	ELSE
	                                       	PRINT "file:"+ http$(tabby%);
                                              '	PRINT STR$(httpl%(tabby%)) + STR$(httpc%(tabby%))+"file:"+ http$(tabby%);

                                        END IF
               	                        VIEW TEXT (1,2)-(pbvScrnCols-1,24)
                                        dline% = 1
                       	                n% = n% - 23
                                       	COLOR 7, 0
	                                CLS
                               	        EXIT DO
                                        	    ' ENTER selects HTTP picked by
	                                            ' TAB and pulls the URL
                                CASE CHR$(13)
               	                	IF tabby% > 0 THEN
                                        	n% = n% - 23
                                                dline% = 1
                       	                        INCR urlcnt%
                               	                url$(urlcnt%) = http$(tabby%)
	                                        COLOR 7,0
                                                CLS
                                       	        EXIT DO
	                                END IF
        	                                    'Exit with ESC
				CASE CHR$(27)
                       	        	CLOSE
                               	        quit% = 1
	                       		EXIT DO
        	        END SELECT
                LOOP
                IF quit% = 1 THEN EXIT DO
	LOOP
 END SUB
'--------------------------------------------------------------------------
SUB Lineproc(cline$)	' process a line of text
	IF textarrow% = 0 THEN
		b_arrows% = TALLY(cline$, "<")
	        IF b_arrows% > 0 THEN
        		cline$ = REMOVE$(cline$, "<")	'strip trailing <
	        	cols% = cols% - b_arrows%
	       END IF
        END IF
        CALL Entities(cline$)           ' entities replaced
	CALL Tabs(cline$)             	'TABs
        CALL Spaces(cline$)             'strip spaces
END SUB
'==========================================================================
SUB Htmlproc
	hcnt% = 1
        xline$ = a$
	WHILE a$ <> ">" AND hcnt% < 5
        	GET$ #1, 1, a$
                IF a$ <> CHR$(10) AND a$ <> CHR$(13) AND a$ <> CHR$(9) THEN
	                xline$ = xline$ + a$
        	        INCR hcnt%
                END IF
        WEND
        aline$ = UCASE$(xline$)
        a$ = MID$(aline$, 2, 1)
'        color 14,0: print aline$;:delay 3
'-------------------------------------------------------------------- trailers
	IF a$ = "/" THEN
               	IF aline$ = "</PRE" THEN 'preformatted block
	               	INCR lcnt%:cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
	               	pre% = 0
		ELSEIF aline$ = "</FON" THEN 'font off
                	fg% = 187
	       	        pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
	        ELSEIF aline$ = "</A>"  THEN 		'http
                	fg% = 187
	                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
               	ELSEIF aline$ = "</H1>" THEN  		'H1
                	fg% = 187
                        INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
              	ELSEIF aline$ = "</H2>" THEN  		'H2
                	fg% = 187
                        INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
              	ELSEIF aline$ = "</H3>" THEN  		'H3
                	fg% = 187
                        INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
              	ELSEIF aline$ = "</H4>" THEN  		'H4
                	fg% = 187
                        INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
              	ELSEIF aline$ = "</H5>" THEN  		'H5
                	fg% = 187
                        INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
              	ELSEIF aline$ = "</TIT" THEN  		'title
                	fg% = 187
	                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                        INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
              	ELSEIF aline$ = "</COD" THEN 		'code
                	fg% = 187
	                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
		ELSEIF aline$ = "</TAB" THEN 		'table
	                table% = 0
                     	INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
        	ELSEIF aline$ = "</CAP" THEN		'caption
	                INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
                ELSEIF aline$ = "</OL>" THEN		'ordered list
                	INCR lcnt%: cols% = 0
                	order% = 0
                ELSE 			            	'catchall
                	fg% = 187
	                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                END IF
'--------------------------------------------------------------- bold italic
	ELSEIF a$ = "B" THEN
        	bline$ = LEFT$(aline$,4)
        	IF bline$ = "<B>" THEN
			fg% = 195
                        pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'---------------------------------------------------------------- blockquote
	       	ELSEIF bline$ = "<BLO" THEN
                	fg% = 189
        	       	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'--------------------------------------------------------------------- blink
	       	ELSEIF bline$ = "<BLI" THEN
                	fg% = 208
	                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'---------------------------------------------------------------------- body
	        ELSEIF bline$ = "<BOD" THEN
 ' 	                pline$(lcnt%) = pline$(lcnt%) + "<< BODY >>"
 			INCR lcnt%: cols% = 0
                        pline$(lcnt%) = CHR$(fg%)
'---------------------------------------------------------------- line break
		ELSEIF bline$ = "<BR>" OR bline$ = "<BR " THEN
	                IF table% = 0 THEN
        	               	INCR lcnt%: cols% = 0
	                        pline$(lcnt%) = CHR$(fg%)
	                END IF
                ELSE
                	CALL Catchall
        	END IF
'--------------------------------------------------------------- Html header
	ELSEIF a$ = "H" THEN
        	hline$ = LEFT$(aline$,3)
                IF hline$ = "<HT" THEN
        		table% = 0
        	        html% = 1
'---------------------------------------------------------------------- head
		ELSEIF hline$ = "<HE" THEN
                	' do what ? Ignore it
'---------------------------------------------------------------------- rule
       	      	ELSEIF hline$ = "<HR" THEN
			INCR lcnt%: cols% = 0
                        fg% = 186
        	        pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                	pline$(lcnt%) = pline$(lcnt%) + "  " + STRING$(75, "-")
                        INCR lcnt%: cols% = 0
                        fg% = 187
                        pline$(lcnt%) = CHR$(fg%)
'-------------------------------------------------------------------- header 5
               	ELSEIF hline$ = "<H5" THEN
                	INCR lcnt%: cols% = 0
                        fg% = 195
		        pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                	table% = 0
'-------------------------------------------------------------------- header 4
               	ELSEIF hline$ = "<H4" THEN
                	INCR lcnt%: cols% = 0
                        fg% = 194
                        pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                        table% = 0
'-------------------------------------------------------------------- header 3
       		ELSEIF hline$ = "<H3" THEN
                	INCR lcnt%: cols% = 0
                        fg% = 193
                        pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
       	                table% = 0
'-------------------------------------------------------------------- header 2
       		ELSEIF hline$ = "<H2" THEN
                	INCR lcnt%: cols% = 0
                        fg% = 191
	                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                        table% = 0
'-------------------------------------------------------------------- header 1
               	ELSEIF hline$ = "<H1" THEN
                	INCR lcnt%: cols% = 0
                        fg% = 190
                        pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                        table% = 0
                ELSE
                	CALL Catchall
               	END IF
        ELSEIF a$ = "T" THEN
        	tline$ = LEFT$(aline$,3)
'--------------------------------------------------------------------- table
		IF tline$ = "<TA" THEN
        		table% = 1
	                INCR lcnt%: cols% = 0
        	        pline$(lcnt%) = CHR$(fg%)
'-------------------------------------------------------------- table header
		ELSEIF tline$ = "<TH" THEN
        		pline$(lcnt%) = pline$(lcnt%) + "   "
                	cols% = cols% + 2
'----------------------------------------------------------------- table row
		ELSEIF tline$ = "<TR" THEN
        		INCR lcnt%: cols% = 0
                	pline$(lcnt%) = CHR$(fg%)
'---------------------------------------------------------------- table data
		ELSEIF tline$ = "<TD" THEN
        	        pline$(lcnt%) = pline$(lcnt%) + "  "
                	cols% = cols% + 2
'--------------------------------------------------------------------- title
		ELSEIF tline$ = "<TI" THEN
        		INCR lcnt%: cols% = 0
                	fg% = 205
	                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                ELSE
                	CALL Catchall
                END IF
'----------------------------------------------------------------------- map
        ELSEIF aline$ = "<MAP>" THEN

'------------------------------------------------------------- applet - Java ?
	ELSEIF aline$ = "<APPL" THEN

'-------------------------------------------------------------------- script
	ELSEIF aline$ = "<SCRI" THEN

        	CALL Bypass
		WHILE b$ <> "/SC" AND NOT EOF(1)
        	        GET$ #1, 1, a$
                        b$ = b$ + a$
                        b$ = right$(b$, 3)
	'        color 15,1:print a$;
        	WEND
                CALL Bypass
 '------------------------------------------------------- preformatted block
       	ELSEIF aline$ = "<PRE>" THEN
        	pre% = 1
'------------------------------------------------------------ meta statement
	ELSEIF aline$ = "<META" THEN
'---------------------------------------------------------------------- link
	ELSEIF aline$ = "<LINK" THEN
'------------------------------------------------------------------- comment
	ELSEIF MID$(aline$,2,1) = "!" THEN
        	IF html% =  0 THEN  		'html
                        WHILE a$ <> ">"
                        	GET$ #1, 1, a$
                                aline$ = aline$ + a$
                        WEND
       		        baseadd$ = aline$
                        html% = 1
                END IF
'-------------------------------------------------------------- ordered list
       	ELSEIF aline$ = "<OL T" THEN
        	order% = 1
'------------------------------------------------------------ unordered list
	ELSEIF aline$ = "<UL>" THEN
        	order% = 0
'----------------------------------------------------------------- list item
	ELSEIF aline$ = "<LI>" THEN
        	INCR lcnt%: cols% = 0
                IF order% > 0 THEN
	                pline$(lcnt%) = STR$(order%) + ". "
        	        cols% = 3
                	INCR order%
                END IF
'--------------------------------------------------------------------- code
	ELSEIF aline$ = "<CODE" THEN
        	fg% = 190
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'----------------------------------------------------------------- emphasize
	ELSEIF aline$ = "<EM>" THEN
        	fg% = 190
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'-------------------------------------------------------------------- strong
	ELSEIF aline$ = "<ST>" THEN
        	fg% = 193
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'---------------------------------------------------------------------- form
	ELSEIF aline$ = "<FORM" THEN
        	fg% = 191
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'--------------------------------------------------------------------- frame
        ELSEIF aline$ = "<FRAM" THEN
        		' ignore
        ELSEIF aline$ = "<NOFR" THEN
        		' ignore
'---------------------------------------------------------------------- font
	ELSEIF aline$ = "<FONT" THEN
        	fg% = 192
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
        	' do what ?
'------------------------------------------------------------------- address
	ELSEIF aline$ = "<ADDR" THEN
        	' do what ?
'----------------------------------------------------------- definition list
	ELSEIF aline$ = "<DL>" THEN
        	fg% = 187
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
                INCR lcnt%: cols%=0
                pline$(lcnt%) = CHR$(fg%)
 '              pline$(lcnt%) = pline$(lcnt%) + ">> "
 '		cols% = cols% + 3
'               PRINT ">> ";
'------------------------------------------------------------ definition tag
	ELSEIF aline$ = "<DT>" THEN
 '              pline$(lcnt%) = pline$(lcnt%) + CHR$(15)
 '		INCR lcnt%: cols% = 0
'                pline$(lcnt%) = CHR$(fg%)
'---------------------------------------------------- definition description
	ELSEIF aline$ = "<DD>" THEN
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(22)
                INCR lcnt%: cols% = 0
                pline$(lcnt%) = CHR$(fg%)
'------------------------------------------------------------------- caption
	ELSEIF aline$ = "<CAPT" THEN
        	INCR lcnt%: cols% = 0
                pline$(lcnt%) = CHR$(fg%)
'----------------------------------------------------------- image reference
	ELSEIF aline$ = "<IMG " THEN
        	CALL Pullimg
'------------------------------------------------------------------- italics
	ELSEIF aline$ = "<I>" THEN
        	fg% = 190
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'----------------------------------------------------------------- underline
	ELSEIF aline$ = "<U>" THEN
        	fg% = 183
        	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
'------------------------------------------------------------------ citation
	ELSEIF aline$ = "<CITE" THEN
        	fg% = 190
                pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)

'----------------------------------------------------------------- paragraph
	ELSEIF aline$ = "<P>" THEN
        	table% = 0
                INCR lcnt%: cols% = 0
                pline$(lcnt%) = CHR$(fg%)
'----------------------------------------------------------------------- div
	ELSEIF aline$ = "<DI>" THEN
'------------------------------------------------------------ name reference
	ELSEIF aline$ = "<A NA" THEN
                WHILE a$ <> " " AND a$ <> ">"  'search for
                        GET$ #1, 1, a$
                        aline$ = aline$ + a$
                WEND
                IF a$ <> ">" THEN
	                WHILE a$ <> " " AND a$ <> ">"  'search for
        	                GET$ #1, 1, a$
                	        aline$ = aline$ + a$
	                WEND
                	IF UCASE$(LEFT$(aline$,2)) = "HR" THEN CALL Pullhref
                END IF
'-------------------------------------------------------------------- target
	ELSEIF aline$ = "<A TA" THEN
'------------------------------------------------------- hypertext reference
	ELSEIF aline$ = "<A HR" THEN
        	CALL Pullhref
        ELSEIF aline$ = "<A  H" THEN
        	CALL Pullhref
'------------------------------------------------------------- centered text
	ELSEIF aline$ = "<CENT" THEN
        	fg% = 187
                INCR lcnt%:cols% = 0
        	pline$(lcnt%) = CHR$(fg%)
'------------------------------------------------------------- what the hell ?
	ELSE
		CALL Catchall
	END IF
	IF RIGHT$(aline$,1) <> ">" AND textarrow% = 0 THEN CALL Bypass
        textarrow% = 0
END SUB
'-------------------------------------------------------------- pull images
SUB Pullimg
       	WHILE a$ <> ">"
               	GET$ #1, 1, a$
                aline$ = aline$ + a$
        WEND
       	imgs$ = MID$(aline$, INSTR(aline$, CHR$(34)) + 1, 100)
                               ' print imgs$
	IF imgs$ = aline$ THEN
		imgs$ = MID$(aline$, INSTR(aline$, "=") + 1, 80)
	        IF INSTR(imgs$," ") > 0 THEN
	        	imgs$ = LEFT$(imgs$, INSTR(imgs$, " ") - 1)
        	ELSE
	        	imgs$ = LEFT$(imgs$, INSTR(imgs$, ">") - 1)
          	END IF
        ELSE
               	IF LEN(imgs$)> 70 THEN imgs$ = "To damned long !" + CHR$(34)
               	imgs$ = LEFT$(imgs$, INSTR(imgs$, CHR$(34)) - 1)
        END IF
        INCR count%:http$(count%) = imgs$

        fg% = 187
        pline$(lcnt%) = pline$(lcnt%) + CHR$(182)
	pline$(lcnt%) = pline$(lcnt%) +  "[I]"
        cols% = cols% + 3
	pline$(lcnt%) = pline$(lcnt%) + CHR$(fg%)
        CALL Lineproc(pline$(lcnt%))
        httpc%(count%) = LEN(pline$(lcnt%)) - 4
        httpl%(count%) = lcnt%
END SUB
'------------------------------------------------------------- catchall text
SUB Catchall
        	pline$(lcnt%) = pline$(lcnt%) + xline$
		cols% = cols% + 5
                textarrow% = 1
                CALL Textout
END SUB
'-------------------------------------------------------------------------
