'
' sdlbasic doc: html converter
'
'   name:      htmlconverter.sdlbas
'   purpose:   generate a manual html page  of sdlbasic for send at sourceforge site
'   author:   __vroby__
'   licence:    lgpl
'
'   bugs:
'
'   todo:
'
'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
makeexamples=0
cleanapi=true
apiFile="../../../sdlBasic/sdlBasic.api"
base$="../../../../../../../share/sdlBasic/sdlbasicsoftware/examples"
mkdir(base$)

inputfile$="sdlBasic.txt"
outputfile$="QuickHelp.html"
keywordlist$="keywords.txt"

open inputfile$ for input as 1
open outputfile$ for output as 2
open keywordlist$ for output as 3

print #2,"<!doctype html public '-//w3c//dtd html 4.0 transitional//en'>"
print #2,""
print #2,""
print #2,""
print #2,""
print #2,""
print #2,""
print #2,""
print #2,""
print #2,""
print #2,""
print #2,"sdlbasic quickhelp"
print #2,""
print #2,""
print #2,""
print #2,""
print #2,""
print #2,"

sdlbasic quick help

"
print #2,"
"

l=1:c=0
while eof(1)=0
	a$=""
	file input #1,a$

	a$=replacesubstr(a$,"#","" )

	'start section
	if c=1 then: t$=trim(left$(a$,len(a$))): mkdir(base$+"/"+t$): a$="<b>"+a$+"</b>": c=0: end if

	if left$(a$,5)="_____" then: a$="<hr />": c=1: end if


	if left$(trim$(a$),1)="*" and left$(trim$(a$),2)<>"**" then
		a$="<table bgcolor='#ff0000' width='100%'><tr><td>"+a$+"</td></tr></table>"
	end if

	if left$(trim$(a$),2)="**" then
		a$="<table bgcolor='#ff8000' width='100%'><tr><td>"+a$+"</td></tr></table>"
	end if

	if left$(trim$(a$),1)="?" then
		a$="<table bgcolor='#ffff00' width='100%'><tr><td>"+a$+"</td></tr></table>"
	end if

	if left$(trim$(a$),2)="->" then
		a$="<table bgcolor='#ff00ff' width='100%'><tr><td>"+a$+"</td></tr></table>"
	end if


	s=instr(a$,": ")
	if s<>0 then
		b$=left$(a$,s)
		c$=mid$(a$,s+1)
		a$="<b>"+b$+"</b>"+c$

		com$=rtrim$(left$(b$,len(b$)-1))

		if instr(com$,"[")then: com$=left$(com$,instr(com$,"[")-1):end if
		if instr(com$,"(")then: com$=left$(com$,instr(com$,"(")-1):end if
		com$=rtrim(com$)
		com$=replacesubstr(com$,chr$(9),"")
		com$=replacesubstr(com$,"?","")
		com$=replacesubstr(com$,"--","<")

		if left$(trim$(com$),1)<>"<" then
			print #3,com$ &" \\"
		end if

		if makeexamples<>0 then
			if not fileexists(base$+"/"+t$+"/"+replacesubstr$(com$,"*","")+".sdlbas") and left$(trim$(com$),1)<>"<" then
				open (base$+"/"+t$+"/"+replacesubstr$(com$,"*","")+".sdlbas") for output as 3
				print base$+"/"+t$+"/"+replacesubstr$(com$,"*","")+".sdlbas"
				print #3,"'"
				print #3,"' sdlbasic example "+t$+":"+com$
				print #3,"'"
				print #3,"'   name:      "+com$+".sdlbas"
				print #3,"'   purpose:   "+c$
				print #3,"'  author:     __vroby__    ( __vroby__@libero.it )"
				print #3,"'  licence:    lgpl"
				print #3,"'"
				print #3,"'-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------"
				close 3
			end if
		end if
	end if

	print #2,a$+"<br />"
	locate(0,0)
	prints("line"+str$(l)+"   ")
	l=l+1
	'waitvbl
end while

print #2,"
"
print #2,"
"
print #2,"generated with sdlbasic
"
print #2,"graphics zoiba
"
print #2,"
"

print #2,""
print #2,""

close 2
close 1

-------------------------------------------------- making api file for ide
if cleanapi=false then
	filecopy("sdlBasic.txt",apiFile)
else
	------------------ cleanup sdlbasic.api while copying it
	outputfile$=apiFile
	open inputfile$ for input as 1
	open outputfile$ for output as 2
	while eof(1)=0
		file input #1,a$
		for n = 1 to 10
			if instr( a$, chr(09) )<>0  then
				a$=replacesubstr( a$,chr(09),"" )
			end if
		next
		if  left$( a$, 1 )<>"#" then
			file output #2,a$
		end if
	wend
	close 2
	close 1
end if

waitkey

