home *** CD-ROM | disk | FTP | other *** search
- Attribute VB_Name = "HTMLGEN"
- ' -------------------------------------------------------------------
- ' File: HTMLGEN.BAS
- ' Copyright (c) 1995 Vermeer Technologies, Inc. All rights reserved.
- ' -------------------------------------------------------------------
-
- Option Explicit
-
- Const ERR_FILE_NOT_FOUND = "*FILE-NOT-FOUND*"
-
- Sub CloseDescription(f As Integer)
-
- Print #f, "</DL>"
-
- End Sub
-
- Sub CloseDocument(f As Integer)
-
- Print #f, "</BODY>"
- Print #f, "</HTML>"
-
- End Sub
-
- Sub CloseFile(fnum As Integer)
-
- Close fnum
-
- End Sub
-
- Sub CloseForm(f As Integer)
-
- Print #f, "</FORM>"
-
- End Sub
-
- Sub CloseFormSelection(f As Integer)
-
- Print #f, "</SELECT>"
-
- End Sub
-
- Sub CloseList(f As Integer, ordered As Integer)
-
- If ordered Then
- Print #f, "</OL>"
- Else
- Print #f, "</UL>"
- End If
-
- End Sub
-
- Sub CloseLiteral(f As Integer)
-
- Print #f, "</PRE>"
-
- End Sub
-
- Sub CloseQuote(f As Integer)
-
- Print #f, "</BLOCKQUOTE>"
-
- End Sub
-
- Sub CloseTag(f As Integer, tagname As String)
-
- Print #f, "</" & tagname & ">"
-
- End Sub
-
- Sub CreateAnchor(s As String, text As String, anchorname As String)
-
- ' constructs anchor in passed string
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- If text = "" Then text = " " ' anchor must have some text to be valid
-
- s = "<A NAME=" & q & anchorname & q & ">" & text & "</A>"
-
- End Sub
-
- Sub CreateLink(s As String, text As String, URL As String)
-
- ' create link in passed string
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- s = "<A HREF=" & q & URL & q & ">" & text & "</A>"
-
- End Sub
-
- Function HTMLString(s As String) As String
-
- ' handle HTML quoting
-
- Dim i As Integer
- Dim slen As Integer
- Dim out As String
- Dim c As String
-
- out = ""
-
- slen = Len(s)
- For i = 1 To slen
- c = Mid$(s, i, 1)
- Select Case c
- Case Chr$(34) ' double quote
- out = out & """
- Case "&"
- out = out & "&"
- Case "<"
- out = out & "<"
- Case ">"
- out = out & ">"
- Case Else
- out = out & c
- End Select
- Next i
-
- HTMLString = out
-
- End Function
-
- Sub OpenDescription(f As Integer)
-
- Print #f, "<DL>"
-
- End Sub
-
- Sub OpenDocument(f As Integer, Title As String)
-
- Print #f, "<HTML>"
- Print #f, "<HEAD>"
- Print #f, "<TITLE>"; HTMLString(Title); "</TITLE>"
- Print #f, "</HEAD>"
- Print #f, "<BODY>"
-
- End Sub
-
- Function OpenFile(filename) As Integer
-
- Dim fnum As Integer
-
- fnum = FreeFile
-
- ' TODO: check for file open errors
- Open filename For Output As fnum
-
- OpenFile = fnum
-
- End Function
-
- Sub OpenForm(f As Integer, method As String, action As String)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- ' TODO: verify method as "GET" or "POST"
-
- Print #f, "<FORM METHOD=" & method & " ACTION=" & q & action & q & ">"
-
- End Sub
-
- Sub OpenFormSelection(f As Integer, fldname As String, fldsize As Integer, multiple As Integer)
-
- Dim q As String
-
- q = Chr$(34)
-
- Print #f, "<SELECT NAME="; q; fldname; q;
- If fldsize > 0 Then
- Print #f, " SIZE="; CStr(fldsize);
- End If
- If multiple Then
- Print #f, " MULTIPLE";
- End If
- Print #f, ">"
-
- End Sub
-
- Sub OpenList(f As Integer, ordered As Integer)
-
- If ordered Then
- Print #f, "<OL>"
- Else
- Print #f, "<UL>"
- End If
-
- End Sub
-
- Sub OpenLiteral(f As Integer)
-
- Print #f, "<PRE>"
-
- End Sub
-
- Sub OpenQuote(f As Integer)
-
- Print #f, "<BLOCKQUOTE>"
-
- End Sub
-
- Sub OpenTag(f As Integer, tagname As String)
-
- Print #f, "<" & tagname & ">"
-
- End Sub
-
- Function StringFromFile(filename As String) As String
-
- Dim f As Integer ' file number
- Dim out As String ' output
- Dim ln As String ' line of input
- Dim nl As String ' end of line chars
-
- ' TODO: watch out for 32K string limit
-
- On Error GoTo StringFromFileError
-
- nl = Chr$(13) & Chr$(10) ' newline
- out = "" ' initialize string
-
- f = FreeFile
-
- Open filename For Input As f
-
- Do While Not EOF(f)
- Line Input #f, ln
- out = out & ln & nl
- Loop
-
- Close f
-
- StringFromFile = out
-
- Exit Function
-
- StringFromFileError:
- ' file not found
- StringFromFile = ERR_FILE_NOT_FOUND
- Exit Function
-
- End Function
-
- Function StringFromHTMLFile(filename As String) As String
-
- Dim inp As String ' input file
- Dim inlc As String ' input file in lower case
- Dim bstart As Integer ' first char after <BODY>
- Dim bend As Integer ' last char before </BODY>
- Dim blen As Integer ' length of body
-
- inp = StringFromFile(filename)
- inlc = LCase$(inp)
-
- ' try to strip out everything between BODY tags
- ' if they exist
-
- bstart = InStr(inlc, "<body>")
- If bstart = 0 Then
- ' no body start tag
- StringFromHTMLFile = inp
- Exit Function
- End If
-
- ' step over start tag
- bstart = bstart + Len("<body>")
-
- bend = InStr(bstart, inlc, "</body>")
- If bend = 0 Then
- ' no body end tag
- StringFromHTMLFile = inp
- Exit Function
- End If
-
- ' extract body from input string (NOT lower case version)!
- blen = bend - bstart
- If blen > 0 Then
- StringFromHTMLFile = Mid$(inp, bstart, blen)
- Else
- StringFromHTMLFile = ""
- End If
-
- End Function
-
- Function StringSubstitute(inp As String, search As String, replace As String) As String
-
- Dim sloc As Integer ' current location in input
- Dim floc As Integer ' where next search string is found
- Dim out As String ' output string
- Dim xlen As Integer ' length of string to be extracted
- Dim xstr As String ' extracted string to left of found search string
- Dim slen As Integer ' length of search string
-
- out = ""
-
- If inp = "" Or search = "" Then
- StringSubstitute = inp
- Exit Function
- End If
-
- slen = Len(search)
- sloc = 1
-
- StringSubstituteAgain:
-
- floc = InStr(sloc, inp, search)
- If floc > 0 Then
- ' found match
- xlen = floc - sloc
- If xlen > 0 Then
- ' copy input to left of match to output
- xstr = Mid$(inp, sloc, xlen)
- Else
- ' nothing to copy
- xstr = ""
- End If
- out = out & xstr & replace
- sloc = floc + slen
- GoTo StringSubstituteAgain
- Else
- ' copy remaining part of string to output
- out = out & Mid$(inp, sloc)
- End If
-
- StringSubstitute = out
-
- End Function
-
- Sub WriteBreak(f As Integer)
-
- Print #f, "<BR>"
-
- End Sub
-
- Sub WriteComment(f As Integer, text As String)
-
- Print #f, "<!-- "; text; " -->"
-
- End Sub
-
- Sub WriteDescriptionItem(f As Integer, Title As String, text As String)
-
- Print #f, "<DT>"; Title; "<DD>"; text
-
- End Sub
-
- Sub WriteFormCheck(f As Integer, fldname As String, checked As Integer)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- Print #f, "<INPUT TYPE=CHECKBOX NAME="; q; fldname; q;
- If checked Then
- Print #f, " CHECKED";
- End If
- Print #f, ">"
-
- End Sub
-
- Sub WriteFormPassword(f As Integer, fldname As String, fldval As String, fldsize As Integer, fldlen As Integer)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- Print #f, "<INPUT TYPE=PASSWORD NAME="; q; fldname; q; " VALUE="; q; fldval; q;
- If fldsize > 0 Then ' 0 means use default size
- Print #f, " SIZE="; CStr(fldsize);
- End If
- If fldlen > 0 Then ' 0 means no maxlength
- Print #f, " MAXLENGTH="; CStr(fldlen);
- End If
- Print #f, ">"
-
- End Sub
-
- Sub WriteFormRadio(f As Integer, fldname As String, fldval As Integer, checked As Integer)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- Print #f, "<INPUT TYPE=RADIO NAME="; q; fldname; q; " VALUE="; q; fldval; q;
- If checked Then
- Print #f, " CHECKED";
- End If
- Print #f, ">"
-
- End Sub
-
- Sub WriteFormReset(f As Integer, txtlabel As String)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- Print #f, "<INPUT TYPE=RESET VALUE="; q; txtlabel; q; ">"
-
- End Sub
-
- Sub WriteFormSelectionItem(f As Integer, text As String, selected As Integer)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- If selected Then
- Print #f, "<OPTION SELECTED>"; text
- Else
- Print #f, "<OPTION>"; text
- End If
-
- End Sub
-
- Sub WriteFormSubmit(f As Integer, txtlabel As String)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- Print #f, "<INPUT TYPE=SUBMIT VALUE="; q; txtlabel; q; ">"
-
- End Sub
-
- Sub WriteFormTextBox(f As Integer, fldname As String, default As String, rows As Integer, cols As Integer)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- Print #f, "<TEXTAREA NAME="; q; fldname; q;
- If rows > 0 Then ' 0 means use default rows
- Print #f, " ROWS="; CStr(rows);
- End If
- If cols > 0 Then ' 0 means use default cols
- Print #f, " COLS="; CStr(cols);
- End If
- Print #f, ">";
- If default <> "" Then
- Print #f, default;
- End If
- Print #f, "</TEXTAREA>"
-
- End Sub
-
- Sub WriteFormTextLine(f As Integer, fldname As String, fldval As String, fldsize As Integer, fldlen As Integer)
-
- Dim q As String
-
- q = Chr$(34) ' double quote
-
- Print #f, "<INPUT TYPE=TEXT NAME="; q; fldname; q; " VALUE="; q; fldval; q;
- If fldsize > 0 Then ' 0 means use default size
- Print #f, " SIZE="; CStr(fldsize);
- End If
- If fldlen > 0 Then ' 0 means no maxlength
- Print #f, " MAXLENGTH="; CStr(fldlen);
- End If
- Print #f, ">"
-
- End Sub
-
- Sub WriteHeading(f As Integer, num As Integer, text As String)
-
- Dim hstr As String
-
- If num < 1 Then num = 1
- If num > 6 Then num = 6
- hstr = "H" & CStr(num)
-
- Print #f, "<" & hstr & ">";
- Print #f, text;
- Print #f, "</" & hstr & ">"
-
- End Sub
-
- Sub WriteImage(f As Integer, src As String, alt As String, align As String, ismap As Integer)
-
- Dim q As String
- q = Chr$(34) ' double quote
-
- Print #f, "<IMG SRC="; q; src; q;
- If alt <> "" Then
- Print #f, " ALT="; q; alt; q;
- End If
- If align <> "" Then
- ' TODO: check for valid alignment attributes
- Print #f, " ALIGN="; q; align; q;
- End If
- If ismap Then
- Print #f, " ISMAP";
- End If
- Print #f, ">"
-
- End Sub
-
- Sub WriteListItem(f As Integer, text As String)
-
- Print #f, "<LI>"; text
-
- End Sub
-
- Sub WriteParagraph(f As Integer, text As String)
-
- Print #f, "<P>"; text; "</P>"
-
- End Sub
-
- Sub WriteRule(f As Integer)
-
- Print #f, "<HR>"
-
- End Sub
-
- Sub WriteText(f As Integer, text As String, nonewline As Integer)
-
- If nonewline Then
- Print #f, text;
- Else
- Print #f, text
- End If
-
- End Sub
-
-