1 REM "text2html.rfd" / Created Friday, 1 September 2000 by Richard F. Drushel 2 REM filter program for TWWMCA text files, to turn them into 1st-order HTML '*************************************************************************** CONST VERSION$ = "04" 'version history '04 0009.10 ;added navigator HTML to footer. '03 0009.03 ;removed check for capital letter in ICLASSIFYLINE, as it ' ;turns out I never used letter-outline format! However, I ' ;have used number-outline format, so add this check. Number ' ;outlines get put between
  • and

  • tags. Added ' ;inumlist flag. Made QUOTE$ and TAB$ SHARED so they are ' ;global for all the function calls! '02 0009.02 ;added checks for "This Week With My Coleco ADAM" and "by ' ;Richard F. Drushel". Renamed IBLANKROMANLETTERPARAGRAPH to ' ;ICLASSIFYLINE; paragraph case is now 5 (from 3). Added ' ;"This Week..." to the data. Removed unused variable ' ;iblank. Added QUOTE$. '01 0009.01 ;initial coding '*************************************************************************** DEFDBL A-H, O-Z DEFINT I-N DECLARE FUNCTION DELEAD$ (x$) DECLARE FUNCTION DETRAIL$ (x$) DECLARE FUNCTION TRAPSPECIAL$ (x$) DECLARE FUNCTION ICLASSIFYLINE% (x$) DIM SHARED TAB$, QUOTE$ TAB$ = CHR$(9) 'tab character QUOTE$ = CHR$(34) 'quotation marks '*************************************************************************** 'store our HTML header and footer stuff DIM header$(5), footer$(6) FOR n = 0 TO 5: READ header$(n): NEXT n FOR n = 0 TO 6: READ footer$(n): NEXT n '*************************************************************************** SCREEN 0, 0, 0: WIDTH 80: CLS PRINT "text2html"; VERSION$; ".rfd "; DATE$; " "; TIME$; " TWWMCA text to HTML": PRINT INPUT "Enter listfile name: ", F$: : PRINT OPEN F$ FOR INPUT AS #1 WHILE NOT EOF(1) INPUT #1, f9$ PRINT "processing "; f9$ OPEN f9$ FOR INPUT AS #2 OPEN LEFT$(f9$, LEN(f9$) - 3) + "htm" FOR OUTPUT AS #3 'write the header and a blank line FOR n = 0 TO 5: : PRINT #3, header$(n): NEXT n: PRINT #3, "" 'now process the file ipre = 0 'initialize <PRE> block flag to not pre-formatted ipara = 0 'initialize <P> flag to not in a paragraph inumlist = 0 'initialize <LI> flag for not in numeric list WHILE NOT EOF(2) LINE INPUT #2, x$ GOSUB process PRINT #3, x$ WEND 'write a blank line and the footer PRINT #3, "": FOR n = 0 TO 6: PRINT #3, footer$(n): NEXT n CLOSE #2, #3 WEND CLOSE #1 PRINT : PRINT "All done!" END '**************************************************************************** process: 'deal with each line of text 'on entry, x$=raw line of text, ipre=<PRE> block flag (0=not in a <PRE> 'block, 1=in a <PRE> block), ipara=<P> paragraph flag (0=not in a paragraph, '1=in a paragraph) 'on exit, x$ is the processed text line x$ = DETRAIL$(x$) 'strip trailing spaces and tabs 'check for <PRE> and </PRE> (these will always be on separate lines) SELECT CASE x$ CASE IS = "<PRE>" ipre = 1 'toggle <PRE> block flag on CASE IS = "</PRE>" ipre = 0 'toggle <PRE> block flag off CASE ELSE IF ipre = 1 THEN 'just print the string as-is ELSE 'check for paragraphs x$ = DELEAD$(x$) 'strip leading spaces and tabs x$ = TRAPSPECIAL$(x$) 'trap & < > for HTML IF ipara = 1 THEN 'we're in a paragraph, but is this the blank line of 'separation at the end of the paragraph? IF x$ = "" THEN 'yes, paragraph is done PRINT #3, "</P>" 'close the paragraph ipara = 0 'not in paragraph anymore 'the blank line in x$ gets printed by caller ELSE 'no, just print the line as-is END IF ELSE 'not already in a paragraph; where are we? IF inumlist = 1 THEN 'we're in a numeric list already 'must do same check for blank line of separation 'that we do in paragraphs IF x$ = "" THEN 'yes, list is done PRINT #3, "</P></LI>" 'close the list entry inumlist = 0 'not in list anymore 'the blank line in x$ gets printed by caller ELSE 'no, just print the line as-is END IF ELSE 'still gotta find out where we are SELECT CASE ICLASSIFYLINE(x$) CASE IS = 0 'blank line 'just print the blank line CASE IS = 1 'Roman numeral x$ = "<H2>" + x$ + "</H2>" CASE IS = 2 'number outline form (e.g., (1)) x$ = "<LI><P>" + x$ inumlist = 1 'flag that we're now 'in a number list CASE IS = 3 'This Week With My Coleco ADAM x$ = "<H1 ALIGN=CENTER>" + x$ + "</H1>" CASE IS = 4 'by Richard F. Drushel x$ = "<P ALIGN=CENTER>by <A HREF=" + QUOTE$ + "mailto:drushel@apk.net" + QUOTE$ + ">Richard F. Drushel <I>(drushel@apk.net)</I></A></P>" CASE ELSE '5 and up gets treated as a paragraph x$ = "<P>" + x$ ipara = 1 'flag that we're in a paragraph END SELECT END IF END IF END IF END SELECT RETURN '*************************************************************************** 'header data DATA <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> DATA <HTML> DATA <HEAD> DATA <TITLE>This Week With My Coleco ADAM z DATA DATA 'footer data DATA
    DATA

    Next Article
    DATA Previous Article
    DATA TWWMCA Archive Main Page

    DATA
    DATA DATA '*************************************************************************** FUNCTION DELEAD$ (x$) STATIC '**************************************************************************** 'strip any leading spaces or tabs from a string istop = 0 WHILE ((LEN(x$) > 0) AND (istop = 0)) SELECT CASE LEFT$(x$, 1) CASE IS = " " x$ = RIGHT$(x$, LEN(x$) - 1) 'remove leading space CASE IS = TAB$ x$ = RIGHT$(x$, LEN(x$) - 1) 'remove leading tab CASE ELSE istop = 1 END SELECT WEND DELEAD$ = x$ '**************************************************************************** END FUNCTION FUNCTION DETRAIL$ (x$) STATIC '**************************************************************************** 'strip any trailing spaces or tabs from a string istop = 0 WHILE ((LEN(x$) > 0) AND (istop = 0)) SELECT CASE RIGHT$(x$, 1) CASE IS = " " x$ = LEFT$(x$, LEN(x$) - 1) 'remove trailing space CASE IS = TAB$ x$ = LEFT$(x$, LEN(x$) - 1) 'remove trailing tab CASE ELSE istop = 1 END SELECT WEND DETRAIL$ = x$ '**************************************************************************** END FUNCTION FUNCTION ICLASSIFYLINE% (x$) STATIC '**************************************************************************** 'classify x$ as either blank (0), a Roman numeral header (1), a numeric list 'entry (2), the "This Week With My Coleco ADAM" title (3), the "by Richard 'F. Drushel" author line (4), or a paragraph (5). 'on entry, x$ has been stripped of all leading and trailing spaces and tabs. IF x$ = "" THEN ICLASSIFYLINE = 0 'blank ELSE 'check for Roman numerals 'note that the extremely rare line beginning I. (pronoun) is problematic 'look for start of line with no more than 6 capital letters and a 'period. More than that, or no period, it's something else. 'less than that, look for valid Roman numeral. If not a Roman numeral, 'then figure out what it is. 'max Roman numeral detectable is XXXVII (37), no way I'm near that!! i = INSTR(x$, ".") 'find the period IF i = 0 OR i > 7 THEN 'check for cases 2-5 SELECT CASE LEFT$(x$, 29) CASE IS = "This Week With My Coleco ADAM" ICLASSIFYLINE = 3 CASE IS = "by Richard F. Drushel (drushe" ICLASSIFYLINE = 4 CASE IS = "by Richard F. Drushel (drush" ICLASSIFYLINE = 4 CASE IS = "by Richard F. Drushel drushe" ICLASSIFYLINE = 4 CASE IS = "by Richard F. Drushel drush" ICLASSIFYLINE = 4 CASE ELSE GOSUB find2or5 'numeric list or paragraph? ICLASSIFYLINE = itype END SELECT ELSE 'look for Roman numeral X, I, or V (I don't have that many headers) isroman = 1 'assume it's a Roman numeral FOR n = 1 TO i - 1 a$ = MID$(x$, n, 1) 'get the character SELECT CASE a$ CASE IS = "I" 'okay, keep looking CASE IS = "V" 'okay, keep looking CASE IS = "X" 'okay, keep looking CASE ELSE isroman = 0 EXIT FOR END SELECT NEXT n IF isroman = 1 THEN ICLASSIFYLINE = 1 'yes, it's a Roman numeral ELSE 'check for cases 2-5 SELECT CASE LEFT$(x$, 29) CASE IS = "This Week With My Coleco ADAM" ICLASSIFYLINE = 3 CASE IS = "by Richard F. Drushel (drushe" ICLASSIFYLINE = 4 CASE IS = "by Richard F. Drushel (drush" ICLASSIFYLINE = 4 CASE IS = "by Richard F. Drushel drushe" ICLASSIFYLINE = 4 CASE IS = "by Richard F. Drushel drush" ICLASSIFYLINE = 4 CASE ELSE GOSUB find2or5 'numeric list or paragraph? ICLASSIFYLINE = itype END SELECT END IF END IF END IF EXIT FUNCTION '**************************************************************************** find2or5: 'determine if the current line is the start of a numeric list or else just 'a regular paragraph. On entry, x$ is the current line (stripped of leading 'and trailing spaces and tabs). On exit, itype=2 if a numeric list, or 'itype=5 if a paragraph. x$ has the numeral part stripped off if it's a 'numeric list. 'numeric lists are assumed to begin like (1), (13), etc. The max numeric 'list entry detectable is (99); I'm nowhere near that! IF LEFT$(x$, 1) <> "(" THEN itype = 5 'no opening parenthesis, so it's a paragraph ELSE i = INSTR(x$, ")") 'find closing parenthesis IF i > 4 THEN itype = 5 'too far away, can't be a numeric list ELSE itype = 2 'it's a numeric list entry x$ = DELEAD$(RIGHT$(x$, LEN(x$) - i)) 'strip off the numeral part '*and* any leading spaces 'or tabs END IF END IF RETURN '**************************************************************************** END FUNCTION FUNCTION TRAPSPECIAL$ (x$) STATIC '**************************************************************************** 'trap & < > characters, which are special to HTML 'replace them with their HTML escape codes IF x$ = "" THEN TRAPSPECIAL$ = "" 'just return, nothing to do ELSE 'trap & i = INSTR(x$, "&") 'find an ampersand, if present WHILE i > 0 x1$ = LEFT$(x$, i) + "amp;" j = LEN(x$) IF j > i THEN x$ = x1$ + RIGHT$(x$, j - i) 'add on the end i = INSTR(i + 5, x$, "&") 'look again ELSE x$ = x1$ 'no end to add i = 0 'so flag that we're done END IF WEND 'trap < i = INSTR(x$, "<") 'find < if present WHILE i > 0 x1$ = LEFT$(x$, i - 1) + "<" j = LEN(x$) IF j > i THEN x$ = x1$ + RIGHT$(x$, j - i) 'add on the end i = INSTR(i + 4, x$, "<") 'look again ELSE x$ = x1$ 'no end to add i = 0 'so flag that we're done END IF WEND 'trap > i = INSTR(x$, ">") 'find > if present WHILE i > 0 x1$ = LEFT$(x$, i - 1) + ">" j = LEN(x$) IF j > i THEN x$ = x1$ + RIGHT$(x$, j - i) 'add on the end i = INSTR(i + 4, x$, ">") 'look again ELSE x$ = x1$ 'no end to add i = 0 'so flag that we're done END IF WEND 'all done! TRAPSPECIAL$ = x$ END IF '**************************************************************************** END FUNCTION