vipsi - the friendly vip script interpreter

Example Scripts

Libraries

TEXT: Text Utilities

List functions: thisThis library contains some Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
utilities, like white space clipping Operators: Boolean Or with Variable "||="
Operators: Bitwise Or with Variable "|="
Operators: Bitwise Or "|"
Operators: Boolean Or "||"
or
splitting of Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
into List functions: words
Shell Immediate Commands: words
words
.

Download link

List functions: thisThis Text functions: file
Instructions: file
file
is included in every distribution.

TEXT.vl

Listing of TEXT.vl

/*
    authoritative Text functions: file
Instructions: file
file
: /pub/Develop/projects/vipsi/libs/Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.vl */ Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SpinAgain = 0 Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SpinDelay = 0.1 // animations/sec Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SpinIndex = 1 Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SpinCount = 0 Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SpinReset() { SpinCount=0 } Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SpinWheel() { Flow control: if … thenif Numeric functions: nownow>=SpinAgain SpinAgain = Numeric functions: nownow + SpinDelay SpinIndex %= 4 SpinIndex += 1 Instructions: putput "|/-\\"[SpinIndex],"\b" Flow control: if … then
Flow control: try … then
then
Flow control: returnreturn ++SpinCount } Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.CropSpaces_R ( t ) { Instructions: var
How does VScript::Value() work?: Var*&
var
j = Numeric functions: countcount t Flow control: do … loopdo Flow control: whilewhile j && t[j]<=" " j-- Flow control: do … looploop Flow control: returnreturn t[to j] } Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.CropSpaces_L ( t ) { Instructions: var
How does VScript::Value() work?: Var*&
var
j = 1 Flow control: do … loopdo Flow control: whilewhile j<=Numeric functions: countcount t && t[j]<=" " j++ Flow control: do … looploop Flow control: returnreturn t[j to] } Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.CropSpaces ( t ) { Instructions: var
How does VScript::Value() work?: Var*&
var
a=1, e=Numeric functions: countcount t Flow control: do … loopdo Flow control: whilewhile e && t[e]<=" " e-- Flow control: do … looploop Flow control: do … loopdo Flow control: whilewhile a<=e && t[a]<=" " a++ Flow control: do … looploop Flow control: returnreturn t[a to e] } /* ---- Zerlege einen Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
Text
in Worte ---------------------------------- ein: "Ein Beispielsatz." aus: { "","Ein"," ","Beispielsatz","." } // { gap, List functions: words
Shell Immediate Commands: words
word
, gap, ... gap } first Operators: Boolean And with Variable "&&="
Operators: Bitwise And with Variable "&="
Operators: Bitwise And "&"
Operators: Boolean And "&&"
and
last gap are always present but may be "". (( => Numeric functions: countcount result is always odd )) "***" -> { "***" } "" -> { "" } "a" -> { "","a","" } " a" -> { " ","a","" } "a " -> { "","a"," " } */ Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.anf = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ" # "abcdefghijklmnopqrstuvwxyzäöü" # "#<" Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.mid = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ" # "abcdefghijklmnopqrstuvwxyzäöü" # "0123456789" # "ß-_" Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.fin = "ABCDEFGHIJKLMNOPQRSTUVWXYZÄÖÜ" # "abcdefghijklmnopqrstuvwxyzäöü" # "0123456789" # "ß_>" Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SplitWordsNoTags ( Glossary: text_ref, text_vartext ) { var result = {} Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
= " " # text # " " // --> simlify Flow control: do … looploop Instructions: var
How does VScript::Value() work?: Var*&
var
wrd = 1, gap = 1 // wort == [wrd ... [gap Instructions: var
How does VScript::Value() work?: Var*&
var
len = Numeric functions: countcount Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
Flow control: do … loopdo // 1. gap: wrd = gap Flow control: do … loopdo // skip gap Flow control: whilewhile ++wrd<=len Flow control: untiluntil Numeric functions: findfind(Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.anf,Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[wrd]) Flow control: do … looploop // wrd -> word_anfang result ##= Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[gap to wrd-1] Flow control: whilewhile wrd <= len // 2. List functions: words
Shell Immediate Commands: words
word
: gap = wrd Flow control: do … loopdo // skip List functions: words
Shell Immediate Commands: words
word
Flow control: whilewhile ++gap<=len Flow control: whilewhile Numeric functions: findfind(Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.mid,Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[gap]) Flow control: do … looploop Flow control: if … thenif !Numeric functions: findfind( Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.fin,Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[gap-1] ) gap-- Flow control: if … thenelif gap<=len && Numeric functions: findfind(Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.fin,Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[gap]) gap++ Flow control: if … then
Flow control: try … then
then
// gap -> gap_anfang result ##= Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[wrd to gap-1] Flow control: do … looploop Instructions: var
How does VScript::Value() work?: Var*&
var
n = Numeric functions: countcount result result[1] = result[1][2 to] result[n] = result[n][to Numeric functions: countcount(result[n])-1 ] Flow control: returnreturn result } /* ---- Zerlege einen Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
Text
in Worte ---------------------------------- html-Tags: werden als Wort-Separator behandelt Text functions: link
Instructions: link
Links
: <a>...</a> Text functions: link
Instructions: link
Links
werden als ein einziges Wort behandelt => Verhindert den Einbau von automatischen Text functions: link
Instructions: link
Links
in den Text functions: link
Instructions: link
Link
! ein: "Ein <b>Beispielsatz</b>." aus: { "","Ein"," ","<b>","","Beispielsatz","","</b>","." } // { sep, List functions: words
Shell Immediate Commands: words
word
, sep, ... sep } */ Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SplitIntoWords ( Glossary: text_ref, text_vartext ) { var result = { "" } // Text functions: convert
Instructions: convert
convert
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
from html // &quot; -> " etc.; verändert Textlänge + Textinhalt! // da sollte ggf. die anker/link-Erzeugung _vor_ der html-konvertierung stattfinden! Instructions: procproc append_to_result ( Glossary: text_ref, text_vartext ) { var r = Numeric functions: countcount result result ##= Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SplitWordsNoTags( Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
) result[r] #= result[r+1] // List functions: join
Instructions: join
join
gaps Instructions: deldel result[r+1] } Flow control: do … loopdo Instructions: var
How does VScript::Value() work?: Var*&
var
i = Numeric functions: findfind(Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
,"<") Flow control: whilewhile i Instructions: var
How does VScript::Value() work?: Var*&
var
j = Numeric functions: findfind(Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
,">",i) Flow control: whilewhile j i = Numeric functions: rfindrfind(Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
,"<",j) append_to_result( Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[to i-1] ) // append Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
before html tag Instructions: var
How does VScript::Value() work?: Var*&
var
tag = Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[i to j] // Flow control: if … then
Flow control: try … then
the
tag "<xy>" Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
= Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[j+1 Text functions: stringto] // text after tag Flow control: if … thenif j-i >= 160 // unlikely to be really a tag append_to_result( tag ) // "<" Operators: Boolean And with Variable "&&="
Operators: Bitwise And with Variable "&="
Operators: Bitwise And "&"
Operators: Boolean And "&&"
and
">" will be handled as sep's Flow control: nextnext Flow control: if … then
Flow control: try … then
then
Instructions: var
How does VScript::Value() work?: Var*&
var
lctag = Text functions: lowerstrlowerstr(tag) Instructions: var
How does VScript::Value() work?: Var*&
var
j = 1 + (lctag[2]=="/") Flow control: do … loopdo Flow control: whilewhile lctag[++j]>="a" Flow control: do … looploop Instructions: var
How does VScript::Value() work?: Var*&
var
id = lctag[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. Flow control: if … thenif !Numeric functions: findfind(HTML.TagsAny," "#id#" ") // no html tag append_to_result( tag ) // handle '<' Operators: Boolean And with Variable "&&="
Operators: Bitwise And with Variable "&="
Operators: Bitwise And "&"
Operators: Boolean And "&&"
and
'>' as sep's Flow control: nextnext Flow control: if … then
Flow control: try … then
then
// html tag: Flow control: if … thenif id!="a" || !Numeric functions: findfind(lctag,"href=") // Operators: Bitwise Not "~"
Operators: Boolean Negation "!"
not
a <a href=""> tag ((aka 'Text functions: link
Instructions: link
link
')) result ##= tag ## "" // preserve entire html tag as List functions: words
Shell Immediate Commands: words
word
Flow control: nextnext Flow control: if … then
Flow control: try … then
then
// <a href=""> ... </a> must be kept as entity: i = Numeric functions: findfind(Text functions: lowerstrlowerstr(Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
),"</a>") Flow control: if … thenif i tag #= Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[to i+3] Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
= Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
[i+4 to] Flow control: if … then
Flow control: try … then
else
Numeric functions: log
Numeric functions: loge
Instructions: log
log
Constants: nlnl, "'</a>' missing: ", tag, " " Flow control: if … then
Flow control: try … then
then
result ##= tag ## "" Flow control: do … looploop append_to_result( Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
) Flow control: returnreturn result } Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.JoinText ( Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
, * ) // opt. Separatorsseparator { Flow control: if … thenif Numeric functions: countcount List functions: localslocals>1 Flow control: if … thenif Numeric functions: countcount Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
== 0 Flow control: returnreturn "" Flow control: if … then
Flow control: try … then
then
// dann ex. Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
[1] nicht! Instructions: renamerename List functions: localslocals[2] = "sep" Instructions: var
How does VScript::Value() work?: Var*&
var
z = Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
[1] Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
= sep # Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
// operation on whole Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
list
! Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
[1] = z Flow control: if … then
Flow control: try … then
then
Instructions: var
How does VScript::Value() work?: Var*&
var
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
= "" Instructions: var
How does VScript::Value() work?: Var*&
var
i = 0 Flow control: do … loopdo Flow control: whilewhile ++i <= Numeric functions: countcount Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
#= Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
[i] Flow control: do … looploop Flow control: returnreturn Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
text
} /* ---- Vipsi command syntax: Identifiers (names)
Identifiers, names
Operators: Make Identifier "@"
Text functions: name
Glossary: Name, Identifier
Namen
normalisieren --------------- ein: separierte Worte wie von Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.SplitIntoWords() ein: { "ein", "Anker" } aus: "ein_ank" */ Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.NormalizeName ( Glossary: list_ref, list_varliste ) { var result = "" Instructions: var
How does VScript::Value() work?: Var*&
var
i = 0 Flow control: do … loopdo Flow control: whilewhile ++i <= Numeric functions: countcount Glossary: list_ref, list_varliste var List functions: words
Shell Immediate Commands: words
word
= Text functions: lowerstrlowerstr(Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
[i]) // Flow control: if … thenif i!=1 && i!=Numeric functions: countcount(Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
) && Numeric functions: findfind(" der die das a Flow control: if … then
Flow control: try … then
the
"," "#word#" ") // Flow control: nextnext // Flow control: if … then
Flow control: try … then
then
Flow control: if … thenif Numeric functions: countcount List functions: words
Shell Immediate Commands: words
word
>=3 && Numeric functions: findfind( " er en em es ", " "#rightstr(List functions: words
Shell Immediate Commands: words
word
,2)#" " ) List functions: words
Shell Immediate Commands: words
word
= List functions: words
Shell Immediate Commands: words
word
[to Numeric functions: countcount List functions: words
Shell Immediate Commands: words
word
-2] Flow control: if … thenelif Numeric functions: countcount List functions: words
Shell Immediate Commands: words
word
>=3 && Numeric functions: findfind( "es", Text functions: rightstrrightstr(List functions: words
Shell Immediate Commands: words
word
,1) ) List functions: words
Shell Immediate Commands: words
word
= List functions: words
Shell Immediate Commands: words
word
[to Numeric functions: countcount List functions: words
Shell Immediate Commands: words
word
-1] Flow control: if … then
Flow control: try … then
then
result #= "_" # List functions: words
Shell Immediate Commands: words
word
Flow control: do … looploop Flow control: returnreturn result[2 to] } /* ---- remove odd items from Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
list
--------------------- -> removes Flow control: if … then
Flow control: try … then
the
sep's from a split-into-words Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
list
*/ Instructions: procproc Data Types: Text
Item selector "[]": Text
Glossary: text, text_val
TEXT
.RemoveOddItems ( Glossary: list_ref, list_varliste ) { var i=0 Flow control: do … loopdo Flow control: whilewhile ++i <= Numeric functions: countcount Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
Instructions: deldel Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
[i] Flow control: do … looploop Flow control: returnreturn Data Types: Lists and arrays
Item selector "[]": Lists
Glossary: list, list_val
liste
} /* for vipsi < 0.8.8 */ /* Flow control: try … thentry Instructions: procproc Text functions: spacestrspacestr(len) { Instructions: var
How does VScript::Value() work?: Var*&
var
spc = " " Flow control: do … loopdo Flow control: whilewhile Numeric functions: countcount spc < len spc #= spc[to len-count spc] Flow control: do … looploop Flow control: returnreturn spc[to len] } Flow control: if … then
Flow control: try … then
then
*/ Flow control: end
Shell Immediate Commands: exit, quit, end
end
0

Valid HTML   Valid CSS