|
Flow control: if … then Flow control: try … thenThe html library contains tools to easily enclose Data Types: Text Item selector "[]": Text Glossary: text, text_valtext in html tags Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or url-encode Text functions: link Instructions: linklinks Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and html encode source Data Types: Text Item selector "[]": Text Glossary: text, text_valtext with a lot of intelligence added.
List functions: thisThis Text functions: file Instructions: filefile is included in every distribution.
HTML.vl
/*
authoritative Text functions: file Instructions: filefile: /pub/Develop/projects/vipsi/libs/HTML.vl
2008-01-24 added HTML.Numeric functions: log Numeric functions: loge Instructions: logLOG(*) for error logging: uses List functions: globals Shell Immediate Commands: globalsglobals.Numeric functions: log Numeric functions: loge Instructions: logLOG(*) Flow control: if … thenif Numeric functions: existsexists
2008-01-30 added <font>…</font> to Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallist of known tags
2008-04-13 added Glossary: Variable, var_refvariable for "identify" path
*/
Instructions: var How does VScript::Value() work?: Var*&var HTML.identify_exe = "/opt/List functions: localslocal/bin/identify" // 2008-04-13
/* ---- Operators: Add to Variable "+=" Operators: Add "+"add <tag> around Data Types: Text Item selector "[]": Text Glossary: text, text_valtext --------------------------------------
optionally with attributes
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = entagged( tag, Data Types: Text Item selector "[]": Text Glossary: text, text_valtext )
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = entagged( tag, attr, Data Types: Text Item selector "[]": Text Glossary: text, text_valtext )
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = entagged( tag, { Data Types: Text Item selector "[]": Text Glossary: text, text_valtext} )
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = entagged( tag, {attr, Data Types: Text Item selector "[]": Text Glossary: text, text_valtext} )
*/
Instructions: procproc entagged ( tag,a,* )
{
Flow control: if … thenif Numeric functions: islistislist(a)
Flow control: if … thenif Numeric functions: countcount(a)==1 Flow control: returnreturn ("<" #tag# ">") # a[1] # ("</" #tag# ">")
Flow control: if … then Flow control: try … thenelse Flow control: returnreturn ("<" #tag# " " #a[1]# ">") # a[2] # ("</" #tag# ">")
Flow control: if … then Flow control: try … thenthen
Flow control: if … then Flow control: try … thenelse
Flow control: if … thenif Numeric functions: countcount(List functions: localslocals)==2 Flow control: returnreturn ("<" #tag# ">") # List functions: localslocals[2] # ("</" #tag# ">")
Flow control: if … then Flow control: try … thenelse Flow control: returnreturn ("<" #tag# " " #locals[2]# ">") # List functions: localslocals[3] # ("</" #tag# ">")
Flow control: if … then Flow control: try … thenthen
Flow control: if … then Flow control: try … thenthen
}
/* ---- Operators: Add to Variable "+=" Operators: Add "+"add <table> around Data Types: Text Item selector "[]": Text Glossary: text, text_valtext ---------------------------
optionally with attributes
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = TABLE( Data Types: Text Item selector "[]": Text Glossary: text, text_valtext )
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = TABLE( attr, Data Types: Text Item selector "[]": Text Glossary: text, text_valtext )
similar for TR, TD, P, PRE, etc.
*/
Instructions: procproc HTML.HEAD ( a,* ) { Flow control: returnreturn entagged( "head", List functions: localslocals ) }
Instructions: procproc HTML.BODY ( a,* ) { Flow control: returnreturn entagged( "body", List functions: localslocals ) }
Instructions: procproc HTML.TABLE ( a,* ) { Flow control: returnreturn entagged( "table", List functions: localslocals ) }
Instructions: procproc HTML.TR ( a,* ) { Flow control: returnreturn entagged( "tr", List functions: localslocals ) }
Instructions: procproc HTML.TD ( a,* ) { Flow control: returnreturn entagged( "td", List functions: localslocals ) }
Instructions: procproc HTML.Flow control: if … then Flow control: try … thenTH ( a,* ) { Flow control: returnreturn entagged( "Flow control: if … then Flow control: try … thenth", List functions: localslocals ) }
Instructions: procproc HTML.P ( a,* ) { Flow control: returnreturn entagged( "p", List functions: localslocals ) }
Instructions: procproc HTML.PRE ( a,* ) { Flow control: returnreturn entagged( "pre", List functions: localslocals ) }
Instructions: procproc HTML.DIV ( a,* ) { Flow control: returnreturn entagged( "div", List functions: localslocals ) }
Instructions: procproc HTML.OL ( a,* ) { Flow control: returnreturn entagged( "ol", List functions: localslocals ) }
Instructions: procproc HTML.UL ( a,* ) { Flow control: returnreturn entagged( "ul", List functions: localslocals ) }
Instructions: procproc HTML.LI ( a,* ) { Flow control: returnreturn entagged( "li", List functions: localslocals ) }
Instructions: procproc HTML.LH ( a,* ) { Flow control: returnreturn entagged( "lh", List functions: localslocals ) }
Instructions: procproc HTML.H1 ( a,* ) { Flow control: returnreturn entagged( "h1", List functions: localslocals ) }
Instructions: procproc HTML.H2 ( a,* ) { Flow control: returnreturn entagged( "h2", List functions: localslocals ) }
Instructions: procproc HTML.H3 ( a,* ) { Flow control: returnreturn entagged( "h3", List functions: localslocals ) }
Instructions: procproc HTML.H4 ( a,* ) { Flow control: returnreturn entagged( "h4", List functions: localslocals ) }
Instructions: procproc HTML.H5 ( a,* ) { Flow control: returnreturn entagged( "h5", List functions: localslocals ) }
Instructions: procproc HTML.H6 ( a,* ) { Flow control: returnreturn entagged( "h6", List functions: localslocals ) }
Instructions: procproc HTML.SPAN ( a,* ) { Flow control: returnreturn entagged( "span", List functions: localslocals ) }
Instructions: procproc HTML.B ( a,* ) { Flow control: returnreturn entagged( "b", List functions: localslocals ) }
Instructions: procproc HTML.I ( a,* ) { Flow control: returnreturn entagged( "i", List functions: localslocals ) }
Instructions: procproc HTML.HR ( * ) { Flow control: returnreturn Numeric functions: countcount(List functions: localslocals) ? "<hr "#locals[1]#">" : "<hr>" }
Instructions: procproc HTML.ANKER ( Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Glossary: Name, Identifieridf ) { Flow control: returnreturn «<a Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername="» #idf# «"></a>» }
/* ---- entag Text functions: link Instructions: linklink --------------------------------------
*/
Instructions: procproc HTML.Text functions: link Instructions: linkLINK ( url, label, * ) // [attr,] url, label
{
Flow control: if … thenif Numeric functions: countcount(List functions: localslocals) == 2
Flow control: returnreturn «<a href="» #url# «">» #label# "</a>"
Flow control: if … then Flow control: try … thenelse
Flow control: returnreturn "<a " #locals[1]# « href="» #locals[2]# «">» #locals[3]# "</a>"
Flow control: if … then Flow control: try … thenthen
}
/* ---- urlencode urls -----------------
intelligent encoding
preserves delimiters for: protocol, user, password, host/path, fragment Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and query
e.g. http://kio:mypasswd@10.0.0.1/tools.cgi?action=reset&Instructions: waitwait=0"
*/
Instructions: procproc HTML.UrlEncode ( path )
{
Instructions: var How does VScript::Value() work?: Var*&var i,j,k,l, proto="",user="",query=""
i = Numeric functions: findfind(path,":")
j = Text functions: lowerstrlowerstr(path[to i])
Flow control: if … thenif j=="http:" || j=="https:" || j=="ftp:" || j=="mailto:" || j=="javascript:"
proto = j
path = path[i+1 to]
Flow control: if … then Flow control: try … thenthen
i = Numeric functions: findfind(path#":",":")
j = Numeric functions: findfind(path#"@","@")
k = Numeric functions: findfind(path#"?","?")
l = Numeric functions: findfind(path#"#","#")
Flow control: if … thenif j && proto=="" && !( i||k||l||Numeric functions: findfind(path,"/") )
proto = "mailto:"
Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif j<k&&j<l // "@" Numeric functions: existsexists?
Flow control: if … thenif i<j // ":" Numeric functions: existsexists?
user = Text functions: convert Instructions: convertconvert(path[to i-1] to url) # ":" #
Text functions: convert Instructions: convertconvert(path[i+1 to j-1] to url) # "@"
Flow control: if … then Flow control: try … thenelse
user = Text functions: convert Instructions: convertconvert(path[to j-1] to url) # "@"
Flow control: if … then Flow control: try … thenthen
k-=j
l-=j
path=path[j+1 to]
Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif l<k // "#" Numeric functions: existsexists?
query = "#" # Text functions: convert Instructions: convertconvert(path[l+1 to] to url) // fragment
path = path[to l-1]
Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif k<l // "?" Numeric functions: existsexists?
query = path[k+1 to]
path = path[to k-1]
Instructions: var How does VScript::Value() work?: Var*&var z = query
List functions: split Instructions: splitsplit z,"&"
List functions: split Instructions: splitsplit z,"="
Text functions: convert Instructions: convertconvert z to url
i = 0
query = ""
Flow control: do … loopdo
Flow control: whilewhile ++i <= Numeric functions: countcount z
Flow control: if … thenif Numeric functions: countcount z[i]==2 query #= "&" # z[i,1] # "=" # z[i,2] // proper
Flow control: if … thenelif Numeric functions: countcount z[i]==1 query #= "&" # z[i,1] // unnamed ?!?
Flow control: if … then Flow control: try … thenelse // really bogus
Numeric functions: log Numeric functions: loge Instructions: logLOG( "HTML.UrlEncode(): path broken",Text functions: convert Instructions: convertconvert(path to quoted) )
Flow control: if … then Flow control: try … thenthen
Flow control: do … looploop
query = "?" # query[2 to]
Flow control: if … then Flow control: try … thenthen
Text functions: convert Instructions: convertconvert path to url
Flow control: returnreturn proto # user # path # query
}
/* ---- konvertiere Data Types: Text Item selector "[]": Text Glossary: text, text_valText nach Html ---------------
preserve tags (from HTML.TagsHtml)
intelligent HTML.UrlEncode(urls)
img: tries to identify image Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Operators: Add to Variable "+=" Operators: Add "+"adds 'width', 'height' Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and 'alt' properties
TODO: preserve <Example Scripts: CGI Scripts Example Scripts: Scriptsscript type="Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/javascript> ... </Example Scripts: CGI Scripts Example Scripts: Scriptsscript>"
*/
Instructions: var How does VScript::Value() work?: Var*&var HTML.TagsStart = " i b tt a table tr td Flow control: if … then Flow control: try … thenth map p span div Example Scripts: CGI Scripts Example Scripts: Scriptsscript form ul ol li center font noscript " # "area "
Instructions: var How does VScript::Value() work?: Var*&var HTML.TagsEnd = " /i /b /tt /a /table /tr /td /Flow control: if … then Flow control: try … thenth /map /p /span /div /Example Scripts: CGI Scripts Example Scripts: Scriptsscript /form /ul /ol /li /center /font /noscript "
Instructions: var How does VScript::Value() work?: Var*&var HTML.TagsSingle = " br hr img input "
Instructions: var How does VScript::Value() work?: Var*&var HTML.TagsUrl = " http https ftp mailto " // --> Text functions: replace Instructions: replacereplace <url> with <a href="url">url</a>
Instructions: var How does VScript::Value() work?: Var*&var HTML.TagsNoEnd = HTML.TagsStart # HTML.TagsSingle[2 to] // start + single
Instructions: var How does VScript::Value() work?: Var*&var HTML.TagsHtml = HTML.TagsNoEnd # HTML.TagsEnd[2 to] // start + single + Flow control: end Shell Immediate Commands: exit, quit, endend
Instructions: var How does VScript::Value() work?: Var*&var HTML.TagsAny = HTML.TagsHtml # HTML.TagsUrl[2 to] // start + single + Flow control: end Shell Immediate Commands: exit, quit, endend + url
Instructions: procproc HTML.GetTagnameFromTag(tag) // --> "pre" oder "/a" etc.
{
Flow control: if … thenif Numeric functions: countcount(tag)>160 || Text functions: leftstrleftstr(tag,1)!="<" || Text functions: rightstrrightstr(tag,1)!=">" Flow control: returnreturn "" Flow control: if … then Flow control: try … thenthen
tag = Text functions: lowerstrlowerstr(tag)
Instructions: var How does VScript::Value() work?: Var*&var j = 1 + (tag[2]=="/")
Flow control: do … loopdo Flow control: whilewhile tag[++j]>="a" Flow control: do … looploop
Flow control: returnreturn tag[2 to j-1] // id := "a" Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or "/a" Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or "pre" etc.
}
Instructions: procproc HTML.IsHtmlTag(tag)
{
Flow control: if … thenif Numeric functions: countcount(tag)>160 || Text functions: leftstrleftstr(tag,1)!="<" || Text functions: rightstrrightstr(tag,1)!=">" Flow control: returnreturn 0 Flow control: if … then Flow control: try … thenthen
tag = Text functions: lowerstrlowerstr(tag)
Instructions: var How does VScript::Value() work?: Var*&var j = 1 + (tag[2]=="/")
Flow control: do … loopdo Flow control: whilewhile tag[++j]>="a" Flow control: do … looploop
Flow control: returnreturn Numeric functions: findfind( TagsHtml, " "#tag[2 to j-1]#" " ) != 0
}
Instructions: procproc HTML.IsAnyTag(tag)
{
Flow control: if … thenif Numeric functions: countcount(tag)>160 || Text functions: leftstrleftstr(tag,1)!="<" || Text functions: rightstrrightstr(tag,1)!=">" Flow control: returnreturn 0 Flow control: if … then Flow control: try … thenthen
tag = Text functions: lowerstrlowerstr(tag)
Instructions: var How does VScript::Value() work?: Var*&var j = 1 + (tag[2]=="/")
Flow control: do … loopdo Flow control: whilewhile tag[++j]>="a" Flow control: do … looploop
Flow control: returnreturn Numeric functions: findfind( TagsAny, " "#tag[2 to j-1]#" " ) != 0
}
Flow control: if … thenif HTML.IsAnyTag("") Numeric functions: log Numeric functions: loge Instructions: loglog " MIST! " Flow control: end Shell Immediate Commands: exit, quit, endend 1 Flow control: if … then Flow control: try … thenthen
Instructions: procproc HTML.Convert2Html( Glossary: text_ref, text_vartext )
{
var i,j,result = ""
Flow control: do … loopdo
i = Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,"&" ) Flow control: whilewhile i
j = Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,";",i) Flow control: whilewhile j
i = Numeric functions: rfindrfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,"&",j)
Flow control: if … thenif (j-i>=3 && j-i<=5) && Numeric functions: findfind(" "&<>",Text functions: lowerstrlowerstr(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[i to j]))
result #= Text functions: convert Instructions: convertconvert(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[to i-1] to html) # Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[i to j]
Flow control: if … then Flow control: try … thenelse
result #= Text functions: convert Instructions: convertconvert(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[to j] to html)
Flow control: if … then Flow control: try … thenthen
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[j+1 to]
Flow control: do … looploop
Flow control: returnreturn result # Text functions: convert Instructions: convertconvert(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext to html)
}
Instructions: procproc HTML.ConvertToHtml ( Glossary: text_ref, text_vartext )
{
var z = "" // collector for converted Glossary: text_ref, text_vartext
var i,j
Flow control: do … loopdo
i = Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,"<") Flow control: whilewhile i
j = Numeric functions: findfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,">",i) Flow control: whilewhile j
i = Numeric functions: rfindrfind(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext,"<",j)
z #= Convert2Html( Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[to i-1] )
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[i to]
j -= i-1
Instructions: var How does VScript::Value() work?: Var*&var uctag = Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[to j] // "<all Flow control: if … then Flow control: try … thenthe stuff>"
Data Types: Text Item selector "[]": Text Glossary: text, text_valtext = Data Types: Text Item selector "[]": Text Glossary: text, text_valtext[j+1 to]
Instructions: var How does VScript::Value() work?: Var*&var tag = HTML.GetTagnameFromTag(uctag)
Flow control: if … thenif !Numeric functions: findfind( HTML.TagsAny, " "#tag#" " )
z #= Convert2Html( uctag )
Flow control: nextnext
Flow control: if … then Flow control: try … thenthen
//Flow control: if … thenif Numeric functions: existsexists verbose && verbose Instructions: putput uctag," " Flow control: if … then Flow control: try … thenthen // zur Text functions: info Shell Immediate Commands: infoinfo!
Instructions: var How does VScript::Value() work?: Var*&var lctag = Text functions: lowerstrlowerstr(uctag)
Flow control: if … thenif tag=="a" || tag=="img" || tag=="area"
i = Numeric functions: findfind( lctag, tag=="a"?"href":"src" )
i = Numeric functions: minmin( Numeric functions: findfind(lctag#"\"","\"",i), Numeric functions: findfind(lctag#"'","'" ,i) )
j = Numeric functions: findfind(lctag,lctag[i],i+1)
Flow control: if … thenif j
Instructions: var How does VScript::Value() work?: Var*&var url = uctag[i+1 to j-1]
uctag = uctag[to i] # HTML.UrlEncode(url) # uctag[j to]
Flow control: if … thenif tag=="img"
Flow control: if … thenif !Numeric functions: findfind(lctag,"width") && !Numeric functions: findfind(lctag,"height")
Flow control: try … thentry
{
Instructions: var How does VScript::Value() work?: Var*&var t = Text functions: sys Instructions: syssys( identify_exe, url[1]=="/"?BaseDir#url[2 to]:TargetDir#url )
Instructions: var How does VScript::Value() work?: Var*&var i = Numeric functions: findfind(t," GIF ") i=i?i:Numeric functions: findfind(t,"JPEG ") i=i?i:Numeric functions: findfind(t," PNG ")
Flow control: if … thenif i
Instructions: var How does VScript::Value() work?: Var*&var w = i+5
Instructions: var How does VScript::Value() work?: Var*&var x = Numeric functions: findfind(t,"x",w)
Instructions: var How does VScript::Value() work?: Var*&var h = Numeric functions: minmin( Numeric functions: findfind(t," ",x), Numeric functions: findfind(t#"+","+",x), Numeric functions: findfind(t#"-","-",x) )
w = t[w to x-1]
h = t[x+1 to h-1]
uctag = uctag[to Numeric functions: countcount uctag-1] # " width=" # w # " height=" # h # ">"
Flow control: if … then Flow control: try … thenelse
Numeric functions: log Numeric functions: loge Instructions: logLOG("HTML.ConvertToHtml","Unknown image format",t)
Flow control: if … then Flow control: try … thenthen
}
Flow control: if … then Flow control: try … thenelse
Numeric functions: log Numeric functions: loge Instructions: logLOG( "HTML.ConvertToHtml", url, errorstr )
Flow control: if … then Flow control: try … thenthen
Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif !Numeric functions: findfind(lctag,"alt")
uctag = uctag[to Numeric functions: countcount uctag-1] # « alt="»
# Convert2Html(url[Numeric functions: rfindrfind(url,"/")+1 to]) # «">»
Flow control: if … then Flow control: try … thenthen
Flow control: if … then Flow control: try … thenthen
Flow control: if … then Flow control: try … thenelse
Numeric functions: log Numeric functions: loge Instructions: logLOG( "HTML.ConvertToHtml", "tag <"#tag#"> broken!" )
Flow control: if … then Flow control: try … thenthen
Flow control: if … thenelif Numeric functions: findfind( HTML.TagsUrl, " "#tag#" " )
// tag = "http"
// uctag = "<http://www.worldofspectrum.org/faq/>"
uctag = uctag[2 to Numeric functions: countcount uctag-1]
Instructions: var How does VScript::Value() work?: Var*&var txt = uctag
//Flow control: if … thenif txt[Numeric functions: countcount txt]=="/" txt = txt[to Numeric functions: countcount txt-1] Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif Text functions: lowerstrlowerstr(txt[to 5])=="http:" txt=txt[6 to] Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif txt[to 2]=="//" txt=txt[3 to] Flow control: if … then Flow control: try … thenthen
uctag = Text functions: link Instructions: linkLINK( HTML.UrlEncode(uctag), Convert2Html(txt) )
Flow control: if … then Flow control: try … thenthen
z #= uctag
Flow control: do … looploop
Flow control: returnreturn z # Convert2Html(Data Types: Text Item selector "[]": Text Glossary: text, text_valtext)
}
/* Error logging
2008-01-24
*/
Instructions: procproc HTML.Numeric functions: log Numeric functions: loge Instructions: logLOG ( * )
{
Flow control: try … thentry
List functions: globals Shell Immediate Commands: globalsglobals.Numeric functions: log Numeric functions: loge Instructions: logLOG ( List functions: localslocals )
Flow control: if … then Flow control: try … thenelse
Flow control: do … loopdo
Flow control: whilewhile Numeric functions: countcount List functions: localslocals>1
Numeric functions: log Numeric functions: loge Instructions: loglog List functions: localslocals[1], ": "
Instructions: deldel List functions: localslocals[1]
Flow control: do … looploop
Numeric functions: log Numeric functions: loge Instructions: loglog List functions: localslocals[1], Constants: nlnl
Flow control: if … then Flow control: try … thenthen
}
Flow control: end Shell Immediate Commands: exit, quit, endend 0
| |