heber.bas 1.69 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55
#! /usr/bin/scriba
' Sample ScriptBasic external preprocessor
'
' This preprocessor converts heb (Html Embedded Basic) files to BASIC
'
' You can embed basic code between
'                          <% basic program %>
' which is executed
'
' <%= basic expression %>
'
cmdlin = command()
split cmdlin by " " to InputFile,OutputFile
open InputFile for input as 1
InputText = input(lof(1),1)
close 1
if Mid$(InputText,1,3) = "#!/" then
  FirstLineLength = InStr(InputText,"\n")
  InputText = Mid$(InputText,FirstLineLength+1)
end if
' import the heb.bas file to get access to the cgi functions
OutputText = "import heb.bas\n"

while  len(InputText) > 0
  StringPosition = InStr(InputText,"<%")
  if not IsDefined(StringPosition) then goto Finished
  AppendString = Mid$(InputText,1,StringPosition-1)
  InputText = Mid$(InputText,StringPosition+2)
  if len(AppendString) > 0 Then
    AppendString = Replace(AppendString,"\\","\\\\")
    AppendString = Replace(AppendString,"\"","\\\"")
    OutputText = OutputText & "print \"\"\"" & AppendString & "\"\"\"\n"
  end if
  StringPosition = InStr(InputText,"%>")
  if not IsDefined(StringPosition) then error(1)
  AppendString = Mid$(InputText,1,StringPosition-1)
  InputText = Mid$(InputText,StringPosition+2)
  if len(AppendString) > 0 then
    if Mid$(AppendString,1,1) = "=" then
      AppendString = "print " & Mid$(AppendString,2)
    end if
    OutputText = OutputText & AppendString & "\n"
  end if
wend

Finished:

if len(InputText) > 0 then
  InputText = Replace(InputText,"\"","\\\"")
  OutputText = OutputText & "print \"\"\"" & InputText & "\"\"\"\n"
end if

open OutputFile for output as 1
print#1,OutputText
close 1