Thanks for the positive feedback
If I need any help I will ask you for shure
Version 0.2 code:
Acutally there are no big visible changes right now, but the
first line interpreter(will scan each line of the html file for commands or text) is completly new. There is much more control and a very reduced code on that operation.
// =======================================================================================
// ====== Version 0.2 "It`s something!" ===============================================
// =======================================================================================
// ====== Holy and Mighty HTML Parser & Interpreter ============== AGK 2 TIER 1 =======
// =======================================================================================
// =======================================================================================
// ================== Created by Alex Schmidt ==== 2015 ============================
// =======================================================================================
// ================== Online Arts 2015 ======= www.online-arts.de ===================
// =======================================================================================
// =======================================================================================
// =======================================================================================
// =======================================================================================
// ================== Additional Credits: ============================================
// =======================================================================================
// ================== XML Parser by Red Eye ==========================================
// ================== HEXtoDEC by Kevin Picone ========================================
// =======================================================================================
// ================== Please share all your thoughts and additions ===================
// ================== On thegamecreators.com forums ==================================
// =======================================================================================
// =======================================================================================
// =======================================================================================
//Global Variable
dim xml_LinesHolder[] as string
SetWindowSize( 1280,720,1)
SetVirtualResolution(1280,720)
type web_def
// attributes
posx as integer
posy as integer
pointer_x as integer
pointer_y as integer
sizex as integer
sizey as integer
title$ as string
text_size as integer
font_r as integer
font_g as integer
font_b as integer
// media
backgnd as integer
title_text as integer
endtype
max_lines as integer
max_lines=2048
type webmed_def
num as integer
ctype as integer
px as integer
py as integer
align as integer
endtype
global webmed_max as integer
dim webscreen_media[1024] as webmed_def
dim webwindow[0] as web_def
// deafault font color
webwindow[0].font_r=0
webwindow[0].font_g=0
webwindow[0].font_b=0
dim webside_buffer[1,max_lines] as string
websitepath$ as string
websitepath$="page/testseite2.html"
global spath$ as string
spath$="page/"
// prework_website
global last_align as integer
global last_size as integer
global font_size as integer
font_size=30
// Font cache
type font_def
name$ as string
normal as integer
bold as integer
italic as integer
bolditalic as integer
endtype
dim fonts[32] as font_def
add_font("interpreter/","arial")
add_font("interpreter/","courier")
add_font("interpreter/","helvetica")
SetTextDefaultFontImage(fonts[1].normal)
SetTextDefaultExtendedFontImage(fonts[1].normal)
// Arial= Standardfont
parse_website(websitepath$,max_lines)
// load html file
xml_Load(max_lines)
// create the window
create_website(100,30,1000,680,"",font_size,4)
interpret_html_file(max_lines)
offx as integer
offy as integer
do
if GetRawKeyState(40) then offy=offy-10
if GetRawKeyState(38) then offy=offy+10
if GetRawKeyState(39) then offx=offx-10
if GetRawKeyState(37) then offx=offx+10
handle_webmedia_offset(offx,offy)
if GetRawKeyState(32)>0 then show_webside_buffer(max_lines)
if GetRawKeyState(27)>0 then end
sync()
loop
function getwsm(num)
for x=1 to webmed_max
if webscreen_media[webmed_max].num=num
num=x
exit
endif
next x
endfunction num
function add_webmedia(num,ctype,x,y)
rem 1 for text
rem 2 for images
inc webmed_max
webscreen_media[webmed_max].ctype=ctype
webscreen_media[webmed_max].num=num
webscreen_media[webmed_max].px=x
webscreen_media[webmed_max].py=y
endfunction
function check_media_align(py,tos)
enty as integer
px as integer
for x=1 to webmed_max
if webscreen_media[x].num>0
if webscreen_media[x].py=py
if webscreen_media[x].align=0
if webscreen_media[x].ctype=1
rem px=webscreen_media[x].px+GetTextTotalWidth(webscreen_media[x].num)
px=webscreen_media[x].px+GetTextTotalWidth(webscreen_media[x].num)/2+(tos/2)
webscreen_media[x].align=1
settextcolor(webscreen_media[x].num,255,0,0,255)
enty=1
endif
endif
endif
endif
next x
if enty=0
px=-(webwindow[0].posx+(webwindow[0].sizex)/2)
endif
endfunction px
function handle_webmedia_offset(ox,oy)
for x=1 to webmed_max
if webscreen_media[x].ctype=1
settextposition(webscreen_media[x].num,webscreen_media[x].px+ox,webscreen_media[x].py+oy)
endif
if webscreen_media[x].ctype=2
setspriteposition(webscreen_media[x].num,webscreen_media[x].px+ox,webscreen_media[x].py+oy)
endif
next x
endfunction
function show_webside_buffer(max_lines)
// create a dark background
bgspr=CreateSprite(0)
setspritecolor(bgspr,20,20,20,220)
setspritesize(bgspr,GetDeviceWidth(),GetDeviceHeight())
SetSpriteDepth(bgspr,0)
dim bufftxt[max_lines] as integer
ls$ as string
et$ as string
bt as integer
for i=1 to max_lines
if webside_buffer[1,i]<>""
ls$=webside_buffer[0,i]
et$=webside_buffer[1,i]
ctxt=CreateText(str(i)+" "+et$+" "+ls$+"||")
settextcolor(ctxt,255,255,255,255)
if et$="t" or et$="tu" then settextcolor(ctxt,255,100,255,255)
if et$="c" then settextcolor(ctxt,200,100,100,255)
if et$="cu" then settextcolor(ctxt,150,150,255,255)
SetTextSize(ctxt,20)
SetTextDepth(ctxt,0)
bufftxt[i]=ctxt
inc bt
endif
next i
infotext$ as string
infotext$=chr(10)+chr(10)+chr(10)+"States:"+chr(10)+"[c] - command"+chr(10)+"[cu] - command, used"+chr(10)+"[t] - text"+chr(10)+"[tu] - text, used"+chr(10)+chr(10)+chr(10)+chr(10)+chr(10)+chr(10)
ext=CreateText("HTML Parser Buffer File 'webside_buffer' 0.1"+chr(10)+chr(10)+"[num]=x in webside_buffer[1,x]"+chr(10)+"[message] webside_buffer[1,x]=command or text"+chr(10)+"[state] webside_buffer[2,x]=how processed"+chr(10)+infotext$+chr(10)+"Written by Alex Schmidt 2015 - online-arts.de"+chr(10)+"[num][state][message] move upwards for more info")
SetTextSize(ext,20)
SetTextColor(ext,0,255,0,255)
SetTextDepth(ext,0)
ox as integer
oy as integer
do
if GetRawKeyState(40) then oy=oy-10
if GetRawKeyState(38) then oy=oy+10
if GetRawKeyState(39) then ox=ox-10
if GetRawKeyState(37) then ox=ox+10
for i=1 to bt
SetTextPosition(bufftxt[i],0+ox,i*20+oy)
next i
SetTextPosition(ext,ox,oy-20*20)
if GetRawKeyState(8) then exit
sync()
loop
for i=1 to bt
deletetext(bufftxt[i])
next i
DeleteText(ext)
DeleteSprite(bgspr)
undim bufftxt[ ]
endfunction
function add_font(path$,name$)
x as integer
repeat
inc x
until fonts[x].name$=""
img1=loadimage(path$+name$+"_normal_extended.png")
img2=loadimage(path$+name$+"_bold_extended.png")
img3=loadimage(path$+name$+"_italic_extended.png")
img4=loadimage(path$+name$+"_bolditalic_extended.png")
fonts[x].name$=name$
fonts[x].normal=img1
fonts[x].bold=img2
fonts[x].italic=img3
fonts[x].bolditalic=img4
endfunction
// interpet html file
function interpret_html_file(max_lines)
title$ as string
for i=0 to max_lines-1
eleName$ = xml_getElement(i)
// element with text between
if eleName$="title"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="title"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
for x=i+2 to endc
title$=title$+webside_buffer[0,x]
webside_buffer[1,x]="tu"
next x
rem webside_buffer[1,o]="cu"
set_webside_title(title$)
endif
// element with text between
// =========================
// "h1 Tag"
if eleName$="h1" and webside_buffer[1,i+1]<>"cu"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="h1"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
text$=""
for x=i+2 to endc
text$=text$+webside_buffer[0,x]
webside_buffer[1,x]="cu"
next x
if text$<>""
add_text_to_webscreen(text$,webwindow[0].pointer_x,webwindow[0].pointer_y,font_size*1.5*-1,webwindow[0].font_r,webwindow[0].font_g,webwindow[0].font_b)
text$=""
endif
endif
// "h2 Tag"
if eleName$="h2" and webside_buffer[1,i+1]<>"cu"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="h2"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
text$=""
for x=i+2 to endc
text$=text$+webside_buffer[0,x]
webside_buffer[1,x]="cu"
next x
if text$<>""
add_text_to_webscreen(text$,webwindow[0].pointer_x,webwindow[0].pointer_y,font_size*1.3*-1,webwindow[0].font_r,webwindow[0].font_g,webwindow[0].font_b)
text$=""
endif
endif
// "h3 Tag"
if eleName$="h3" and webside_buffer[1,i+1]<>"cu"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="h3"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
text$=""
for x=i+2 to endc
text$=text$+webside_buffer[0,x]
webside_buffer[1,x]="cu"
next x
if text$<>""
add_text_to_webscreen(text$,webwindow[0].pointer_x,webwindow[0].pointer_y,font_size*1.1*-1,webwindow[0].font_r,webwindow[0].font_g,webwindow[0].font_b)
text$=""
endif
endif
// "h4 Tag"
if eleName$="h4" and webside_buffer[1,i+1]<>"cu"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="h4"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
text$=""
for x=i+2 to endc
text$=text$+webside_buffer[0,x]
webside_buffer[1,x]="cu"
next x
if text$<>""
add_text_to_webscreen(text$,webwindow[0].pointer_x,webwindow[0].pointer_y,font_size*0.9*-1,webwindow[0].font_r,webwindow[0].font_g,webwindow[0].font_b)
text$=""
endif
endif
// "h5 Tag"
if eleName$="h5" and webside_buffer[1,i+1]<>"cu"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="h5"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
text$=""
for x=i+2 to endc
text$=text$+webside_buffer[0,x]
webside_buffer[1,x]="cu"
next x
if text$<>""
add_text_to_webscreen(text$,webwindow[0].pointer_x,webwindow[0].pointer_y,font_size*0.6*-1,webwindow[0].font_r,webwindow[0].font_g,webwindow[0].font_b)
text$=""
endif
endif
// "h6 Tag"
if eleName$="h6" and webside_buffer[1,i+1]<>"cu"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="h6"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
text$=""
for x=i+2 to endc
text$=text$+webside_buffer[0,x]
webside_buffer[1,x]="cu"
webside_buffer[1,x]="cu"
next x
if text$<>""
add_text_to_webscreen(text$,webwindow[0].pointer_x,webwindow[0].pointer_y,font_size*0.5*-1,webwindow[0].font_r,webwindow[0].font_g,webwindow[0].font_b)
text$=""
endif
endif
// "a Tag"
if eleName$="a" and webside_buffer[1,i+1]<>"cu"
webside_buffer[1,i+1]="cu"
for o=i+1 to max_lines
eleName2$ = xml_getElement(o)
if eleName2$="a"
endc=o
webside_buffer[1,o+1]="cu"
exit
endif
next o
text$=""
for x=i+2 to endc
text$=text$+webside_buffer[0,x]
webside_buffer[1,x]="cu"
webside_buffer[1,x]="cu"
next x
if text$<>""
add_text_to_webscreen(text$,webwindow[0].pointer_x,webwindow[0].pointer_y,font_size,0,0,255)
text$=""
endif
endif
// switch element
// ==============
if eleName$="p"
align$=xml_getAttributeContent("align",i)
webside_buffer[1,i+1]="cu"
if align$<>"" and align$<>"NULL"
if lower(align$)="left" then last_align=0
if lower(align$)="middle" then last_align=1
if lower(align$)="right" then last_align=2
else
last_align=0
endif
endif
if eleName$="center"
webside_buffer[1,i+1]="cu"
select last_align
case 1
last_align=0
endcase
case 0
last_align=1
endcase
case 2
last_align=1
endcase
endselect
rem jump_pointer_to_next_line(last_size)
endif
if eleName$="font"
webside_buffer[1,i+1]="cu"
face$=xml_getAttributeContent("face",i)
color$=xml_getAttributeContent("color",i)
if color$<>""
if left(color$,1)="#" then color$=right(color$,len(color$)-1)
r=HexToDec(mid(color$,1,2))
g=HexToDec(mid(color$,3,2))
b=HexToDec(mid(color$,5,2))
if lower(color$)="red"
r=255
g=0
b=0
endif
if lower(color$)="green"
r=0
g=255
b=0
endif
if lower(color$)="blue"
r=0
g=0
b=255
endif
webwindow[0].font_r=r
webwindow[0].font_g=g
webwindow[0].font_b=b
endif
endif
// direct element
// ==============
// image
if eleName$="img"
source$=xml_getAttributeContent("src",i)
webside_buffer[1,i+1]="cu"
rem add_sprite_to_webscreen("",webwindow[0].posx,webwindow[0].posy,webwindow[0].sizex,webwindow[0].sizey,r,g,b)
add_image_to_webscreen(spath$+source$,webwindow[0].posx,webwindow[0].posy,20,20,255,255,255)
endif
if eleName$="body"
color$=xml_getAttributeContent("bgcolor",i)
webside_buffer[1,i+1]="cu"
if left(color$,1)="#" then color$=right(color$,len(color$)-1)
r=HexToDec(mid(color$,1,2))
g=HexToDec(mid(color$,3,2))
b=HexToDec(mid(color$,5,2))
add_sprite_to_webscreen("",webwindow[0].posx,webwindow[0].posy,webwindow[0].sizex,webwindow[0].sizey,r,g,b)
endif
if eleName$="hr"
webside_buffer[1,i+1]="cu"
webwindow[0].pointer_y=webwindow[0].pointer_y+20
webwindow[0].pointer_y=webwindow[0].pointer_y+last_size
webwindow[0].pointer_x=0
last_size=20
if webwindow[0].pointer_x=0 then webwindow[0].pointer_x=10
add_image_to_webscreen("",webwindow[0].posx+webwindow[0].pointer_x,webwindow[0].posy+webwindow[0].pointer_y,webwindow[0].sizex-20,2,255,255,255)
webwindow[0].pointer_y=webwindow[0].pointer_y+2*2
endif
if eleName$="br"
webside_buffer[1,i+1]="cu"
jump_pointer_to_next_line(last_size)
endif
if webside_buffer[1,i+1]="t"
if webside_buffer[0,i+1]<>""
webside_buffer[1,i+1]="tu"
add_text_to_webscreen(webside_buffer[0,i+1],webwindow[0].pointer_x,webwindow[0].pointer_y,font_size,webwindow[0].font_r,webwindow[0].font_g,webwindow[0].font_b)
else
webside_buffer[1,i+1]="tnu"
endif
endif
next i
endfunction
function jump_pointer_to_next_line(size)
if size=0 then size=font_size
webwindow[0].pointer_y=webwindow[0].pointer_y+size
webwindow[0].pointer_x=0
last_size=size
endfunction
function add_sprite_to_webscreen(img$,px,py,sx,sy,r,g,b)
spr=createsprite(0)
SetSpritePosition(spr,px,py)
SetSpriteSize(spr,sx,sy)
setspritecolor(spr,r,g,b,255)
SetSpriteScissor(spr,webwindow[0].posx,webwindow[0].posy,webwindow[0].posx+webwindow[0].sizex,webwindow[0].posy+webwindow[0].sizey)
endfunction
function add_image_to_webscreen(img$,px,py,sx,sy,r,g,b)
webwindow[0].pointer_y=webwindow[0].pointer_y+font_size
webwindow[0].pointer_x=0
spr=createsprite(0)
if img$<>""
img=loadimage(img$)
SetSpriteImage(spr,img)
SetSpriteSize(spr,GetImageWidth(img),GetImageHeight(img))
last_size=getimageheight(img)
if last_align=0
SetSpritePosition(spr,px,py+webwindow[0].pointer_y)
add_webmedia(spr,2,px,py+webwindow[0].pointer_y)
endif
if last_align=1
SetSpritePosition(spr,(webwindow[0].sizex+webwindow[0].posx)/2-GetImageWidth(img)/2,py+webwindow[0].pointer_y)
add_webmedia(spr,2,(webwindow[0].sizex+webwindow[0].posx)/2-GetImageWidth(img)/2,py+webwindow[0].pointer_y)
endif
if last_align=2
SetSpritePosition(spr,px+webwindow[0].sizex-GetImageWidth(img),py+webwindow[0].pointer_y)
add_webmedia(spr,2,px+webwindow[0].sizex-GetImageWidth(img),py+webwindow[0].pointer_y)
endif
webwindow[0].pointer_y=webwindow[0].pointer_y+GetImageHeight(img)
rem webwindow[0].pointer_x=(webwindow[0].sizex+webwindow[0].posx)/2+GetImageWidth(img)/2
else
SetSpritePosition(spr,px,py)
add_webmedia(spr,2,px,py)
SetSpriteSize(spr,sx,sy)
rem webwindow[0].pointer_y=webwindow[0].pointer_y+sy
endif
setspritecolor(spr,r,g,b,255)
SetSpriteScissor(spr,webwindow[0].posx,webwindow[0].posy,webwindow[0].posx+webwindow[0].sizex,webwindow[0].posy+webwindow[0].sizey)
endfunction
function add_text_to_webscreen(txt$,px,py,s,r,g,b)
txt=CreateText(txt$)
if s<0
px=0
py=py+last_size
rem webwindow[0].pointer_y=webwindow[0].pointer_y+200
decf=1
s=s*-1
endif
SetTextSize(txt,s)
if px=0 then px=10
if last_align=0
SetTextPosition(txt,webwindow[0].posx+px,webwindow[0].posy+py)
add_webmedia(txt,1,webwindow[0].posx+px,webwindow[0].posy+py)
SetTextAlignment(txt,0)
endif
if last_align=1
rem webscreen_media[getwsm(txt)].align=1
px=check_media_align(webwindow[0].posy+py,GetTextTotalWidth(txt))
for y=1 to webmed_max
if webscreen_media[y].num>0
if webscreen_media[y].py=webwindow[0].posy+py
if webscreen_media[y].align=1
webscreen_media[y].align=4
// this one should align the whole line, but I do not have the position :/ hen/egg
webscreen_media[y].px=webscreen_media[y].px- 200
rem px=px-tos
endif
endif
endif
next y
if px<0
px=px*-1
con as integer
con=1
endif
SetTextPosition(txt,px,webwindow[0].posy+py)
add_webmedia(txt,1,px,webwindow[0].posy+py)
if con=1
webscreen_media[getwsm(txt)].align=1
settextcolor(getwsm(txt),255,0,0,255)
endif
SetTextAlignment(txt,1)
ac as integer
ac=0
do
remstart
if ac=0
if GetRawKeyPressed(13)=0
ac=1
endif
endif
if ac=1
if GetRawKeyPressed(13)=1
exit
endif
endif
remend
sync()
sleep(100)
exit
loop
endif
if last_align=2
SetTextPosition(txt,webwindow[0].posx+px+webwindow[0].sizex,webwindow[0].posy+py)
add_webmedia(txt,1,webwindow[0].posx+px+webwindow[0].sizex,webwindow[0].posy+py)
SetTextAlignment(txt,2)
endif
if decf=1 and s>0 then s=s*-1
// cut the string if too big only in the main window
SetTextMaxWidth( txt,webwindow[0].sizex)
SetTextScissor(txt,webwindow[0].posx,webwindow[0].posy,webwindow[0].posx+webwindow[0].sizex,webwindow[0].posy+webwindow[0].sizey)
SetTextColor(txt,r,g,b,255)
if s>0 and decf=0
rem webwindow[0].pointer_y=webwindow[0].pointer_y+GetTextTotalHeight(txt)
webwindow[0].pointer_x=webwindow[0].pointer_x+GetTextTotalWidth(txt)
last_size=GetTextTotalHeight(txt)
else
rem webwindow[0].pointer_x=webwindow[0].pointer_x+GetTextTotalWidth(txt)
webwindow[0].pointer_x=0
webwindow[0].pointer_y=webwindow[0].pointer_y+GetTextTotalHeight(txt)
rem last_size=-s
last_size=GetTextTotalHeight(txt)
rem webwindow[0].pointer_y=webwindow[0].pointer_y-s
rem webwindow[0].pointer_x=webwindow[0].posx+GetTextTotalWidth(txt)
endif
endfunction
function set_webside_title(title$)
SetTextString(webwindow[0].title_text,title$)
rem +webwindow[0].sizex/2-GetTextTotalWidth(webwindow[0].title_text)/2
SetTextPosition(webwindow[0].title_text,webwindow[0].posx,webwindow[0].posy-font_size)
SetTextScissor(webwindow[0].title_text,webwindow[0].posx,webwindow[0].posy-GetTextTotalHeight(webwindow[0].title_text),webwindow[0].posx+webwindow[0].sizex,webwindow[0].posy+webwindow[0].sizey-GetTextTotalHeight(webwindow[0].title_text))
endfunction
function create_website(px,py,sx,sy,title$,text_size,border)
// bg grey
spr2=CreateSprite(0)
SetSpriteColor(spr2,100,100,100,255)
SetSpriteSize(spr2,sx+border*2,sy+text_size+border)
SetSpritePosition(spr2,px-border,py-text_size)
// bg white
spr=CreateSprite(0)
SetSpriteSize(spr,sx,sy)
SetSpritePosition(spr,px,py)
// title
txt=CreateText(title$)
SetTextSize(txt,text_size)
SetTextPosition(txt,px+sx/2-GetTextTotalWidth(txt)/2,py-GetTextTotalHeight(txt))
// attributes
webwindow[0].title$=title$
webwindow[0].backgnd=spr
webwindow[0].title_text=txt
webwindow[0].text_size=text_size
webwindow[0].posx=px
webwindow[0].posy=py
webwindow[0].sizex=sx
webwindow[0].sizey=sy
endfunction
//Functions
function xml_Setup(path as string)
fileid = OpenToRead(path)
xml_MaxLines = 0
while FileEOF(fileid) = 0
currentline$ = ReadLine(fileid)
inc xml_MaxLines, 1
endwhile
CloseFile(fileid)
endfunction xml_MaxLines
function xml_Load(maxLines as integer)
dim xml_LinesHolder[maxLines] as string
current = 0
for i=1 to maxLines
currentline$ = webside_buffer[0,i]
xml_LinesHolder[current] = currentline$
inc current, 1
next i
endfunction
function xml_getElement(iterator as integer)
returnValue as string
pos_a = str_find(xml_LinesHolder[iterator],"</",0)
if pos_a = -1
pos_a = str_find(xml_LinesHolder[iterator],"<",0)
inc pos_a, 1
else
inc pos_a, 2
endif
pos_b = str_find(xml_LinesHolder[iterator],">",pos_a)
if pos_b = -1
pos_b = str_find(xml_LinesHolder[iterator],"/>",pos_a)
endif
pos_c = str_find(xml_LinesHolder[iterator]," ",pos_a)
if pos_c < pos_b and pos_c > -1
pos_b = pos_c
endif
returnValue = str_substr(xml_LinesHolder[iterator],pos_a,pos_b)
endfunction returnValue
function xml_getElementContent(element as string, iterator as integer)
content as string
pos_a as integer
pos_b as integer
pos_a = str_find(xml_LinesHolder[iterator],element,0)
if pos_a = -1
content = "NULL"
else
pos_b = str_find(xml_LinesHolder[iterator],element,pos_a+1)
endif
if pos_b = -1 or pos_a = -1
content = "NULL"
else
content = str_substr(xml_LinesHolder[iterator],pos_a+len(element)+1,pos_b-2)
endif
endfunction content
function xml_getAttributeContent(attribute as string, iterator as integer)
pos_a as integer
pos_b as integer
content as string
pos_a = str_find(xml_LinesHolder[iterator],attribute,0)
if pos_a > -1
inc pos_a, len(attribute)+2
pos_b = str_find(xml_LinesHolder[iterator],chr(34),pos_a)
if pos_b = -1
pos_b = str_find(xml_LinesHolder[iterator],chr(34),pos_a)
if pos_b = -1
content = "NULL"
else
content = str_substr(xml_LinesHolder[iterator],pos_a,pos_b)
endif
else
content = str_substr(xml_LinesHolder[iterator],pos_a,pos_b)
endif
else
content = "NULL"
endif
endfunction content
function xml_isDeclaration(iterator as integer)
pos_a as integer
pos_b as integer
content as string
pos_a = str_find(xml_LinesHolder[iterator],"<?",0)
if pos_a > -1
pos_b = str_find(xml_LinesHolder[iterator]," ",pos_a)
pos_c = str_find(xml_LinesHolder[iterator],"?>",pos_a)
if pos_c<pos_b
pos_b = pos_c
endif
if pos_a > -1 and pos_b > -1
content$ = str_substr(xml_LinesHolder[iterator],pos_a+2,pos_b)
endif
else
content = "NULL"
endif
endfunction content$
//String Functions
function str_find(a as string, b as string, c as integer)
place = -1
if len(a) > 0
lengthB = len(b)
for i=c to len(a) step 1
if (mid(a,i+1,lengthB) = b)
place = i
exit
endif
next i
endif
endfunction place
function str_substr(a as string, startPos as integer, endPos as integer)
returnValue as string
if startPos=-1 or endPos=-1
returnValue = "NULL"
else
returnValue = mid(a, startPos+1, endPos-startPos)
endif
endfunction returnValue
// prework website
// ===============
// This function will load the .html file and convert them into a creation sequence. Its the parser
// HTML => interpret line for line, is it a command or text? Then make an oder for the creation of the
// text or image objects.
function parse_website(path$,maxLines)
// initial variables
parserline as integer // this is the pointer for the arrayfile
element as integer // this is to help cutting the string
// load the html file and read all the lines in
setfolder("/media")
file=opentoread(path$)
for fileline=1 to maxLines
line$=ReadLine( file )
// read all the lines and parse the commands into a giant array what will be the sequence for the creation of the website.
// But first things first.
// The main idea behind this is, that you get a hen-egg problem, if you interpret the code from the first to the last line.
// For example, if there are multiple text objects in one line, that need to be centered, you will have to know all the size
// of the diffrent text objects in order to align them correctly.
// line$ is the current line from the file
if line$<>""
// set to first element
element=0
// we have to check for bare text or commands in that line.
// so the following section will cut the text and command from each line apart.
// so we have to go though every char searching for <> or a syntax error
for fchar=1 to len(line$)
// search for < inside the line, if there is something, there could be a command
if mid(line$,fchar,1)="<"
// if < is the first all, all the text before is plaintext
// this is part of the logic to get all the plaintext in the line
if element=0
// add first plaintext
if mid(line$,1,fchar-1)<>""
webside_buffer[0,parserline]=mid(line$,1,fchar-1)
webside_buffer[1,parserline]="t"
inc parserline
endif
inc element
endif
// now seach for >
for lchar=fchar to len(line$)
if mid(line$,lchar,1)=">"
// the command should be inbetween < > , so:
command$=mid(line$,fchar,lchar-fchar+1)
// write the information inside webside_buffer array. This array is used
// to store the first "interpreter round" by dividing bare text and commands
webside_buffer[0,parserline]=command$
webside_buffer[1,parserline]="c"
inc parserline
// then exit
exit
// if this command fails, there is a missing bracket to close the operation
else
print("error. Command could not be closed at line: "+ str(fileline))
endif
next lchar
endif
// to workout all the plaintext, this will search for all text after a > bracket
if mid(line$,fchar,1)=">"
// now seach for <
for lchar=fchar to len(line$)
if mid(line$,lchar,1)="<"
// if there is some text inbetween, its plaintext!
// this is part of the logic to get all the plaintext in the line
if mid(line$,fchar+1,lchar-fchar-1)<>""
// add the text to the buffer
webside_buffer[0,parserline]=mid(line$,fchar+1,lchar-fchar-1)
webside_buffer[1,parserline]="t"
inc parserline
endif
exit
else
if lchar=len(line$)
// if there is no bracket, we expect the last part to be a plaintext
templine$=templine$+mid(line$,fchar+1,len(line$))
if mid(line$,fchar+1,len(line$))<>""
// add the text to the buffer
webside_buffer[0,parserline]=mid(line$,fchar+1,len(line$))
webside_buffer[1,parserline]="t"
inc parserline
endif
endif
endif
next lchar
endif
// if no commands where detected in this line, the whole line is plaintext
if fchar=len(line$) and element=0
if line$<>""
// if the previous entry is text, then add the current text to the last one
if webside_buffer[1,parserline-1]="t"
webside_buffer[0,parserline-1]=webside_buffer[0,parserline-1]+" "+line$
else
// add the text to the buffer
webside_buffer[0,parserline]=line$
webside_buffer[1,parserline]="t"
inc parserline
endif
endif
endif
next fchar
endif
next fileline
closefile(file)
endfunction
// endfunction parser
Function HexToDec(HexString$)
if Len(HexString$)
HexString$=Upper(HexString$)
For lp=1 to len(HexString$)
Result=Result*16
ThisChr=asc(Mid(HexString$,lp,1))
if ThisChr=>asc("0") and ThisChr<=asc("9")
Result=REsult+(ThisChr-asc("0"))
Continue
endif
if ThisChr=>asc("A") and ThisChr<=asc("F")
Result=REsult+ThisChr-(asc("A")-10)
endif
next
endif
EndFunction REsult
The next big thing will be, that the parser will set the priority and order for the rendering.