|
One of Flow control: if … then Flow control: try … thenthe most basic Example Scripts: CGI Scripts Example Scripts: Scriptsscripts used everywhere. Numeric functions: nowNow also available as a vip Example Scripts: CGI Scripts Example Scripts: Scriptsscript. It shows Flow control: if … then Flow control: try … thenthe command line Vipsi command syntax: Arguments Glossary: Argumentsarguments, cgi Vipsi command syntax: Arguments Glossary: Argumentsarguments, environment Glossary: Variable, var_refvariables Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallists some bin directories.
test.cgi
/cgi-bin/test.cgi
#!/home/smile77/bin/vipsi
/* --------------------------------------------------------------------------------------------
Modes of Operation: CGI Scripts Example Scripts: CGI Scriptscgi scripts:
method "Instructions: getGET":
Vipsi command syntax: Arguments Glossary: Argumentsarguments are passed in Flow control: if … then Flow control: try … thenthe environment Glossary: Variable, var_refvariable "QUERY_STRING".
method "POST":
Vipsi command syntax: Arguments Glossary: Argumentsarguments are passed via Constants: stdinstdin. size of input data is passed in "CONTENT_LENGTH".
common:
Flow control: if … then Flow control: try … thenthe Vipsi command syntax: Arguments Glossary: Argumentsargument Data Types: Text Text functions: stringstring consists of multiple fields which are separated by ampersands "&".
each field has (should have) Flow control: if … then Flow control: try … thenthe form: "Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername=Glossary: Valuevalue".
Flow control: if … then Flow control: try … thenthe data is encoded according to mime type "application/x-www-form-urlencoded".
List functions: thisthis means: spaces " " are replaced by Operators: Add "+"plus signs "+" Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and special characters are
represented by their Text functions: hexstrhex code a la "%AF".
Flow control: if … then Flow control: try … thenthe Modes of Operation: CGI Scripts Example Scripts: CGI Scriptscgi script must Instructions: writewrite a Text functions: file Instructions: filefile to Constants: stdoutstdout.
in Flow control: if … then Flow control: try … thenthe most common case List functions: thisthis is a html Text functions: file Instructions: filefile:
step 1: http-header:
"content-type: Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/html\n\n"
Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or
"content-type: Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/html; charset=utf-8\n\n"
Flow control: if … then Flow control: try … thenthen Flow control: if … then Flow control: try … thenthe html page itself. it has Flow control: if … then Flow control: try … thenthe following basic layout:
<!doctype html public "-//w3c//dtd html 4.01 transitional//en">
<html>
<head>
<title>Titel der Seite ist Pflicht</title>
<META http-equiv=Content-Type content="Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/html; charset=UTF-8"> ((opt.))
</head>
<body>
<!-- Contents of page here -->
</body>
</html>
--------------------------------------------------------------------------------------------- */
// print all Flow control: if … then Flow control: try … thenthe headers:
// http header
// head section of html page Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and
// start body section
Instructions: putput
"content-type: Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/html; charset=utf-8\n\n",
"<!doctype html public \"-//w3c//dtd html 4.01 transitional//en\">\n",
"<html>\n",
"<head>\n",
"<META http-equiv=Content-Type content=\"Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/html; charset=UTF-8\">\n",
"<title>vipsi test Example Scripts: CGI Scripts Example Scripts: Scriptsscript for cgi'</title>\n",
"</head>\n",
"<body style='font-family:sans-serif;'>\n",
"<h2>*** vipsi *** cgi test Example Scripts: CGI Scripts Example Scripts: Scriptsscript</h2>\n"
// check whether Flow control: if … then Flow control: try … thenthe "magic parameter" is passed to show my own source:
// List functions: thisthis magic parameter is see_source=yes
// Flow control: if … thenif so, show source as preformatted Data Types: Text Item selector "[]": Text Glossary: text, text_valtext Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Shell Immediate Commands: exit, quit, endquit
Flow control: if … thenif Numeric functions: existsexists see_source
Flow control: if … thenif see_source[1]=="y" || see_source[1]=="1"
Flow control: if … thenif Numeric functions: existsexists List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SCRIPT_FILENAME
Instructions: var How does VScript::Value() work?: Var*&var myfile = List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SCRIPT_FILENAME
Instructions: var How does VScript::Value() work?: Var*&var mysource = Text functions: file Instructions: filefile(myfile)
Flow control: if … then Flow control: try … thenelse
Instructions: var How does VScript::Value() work?: Var*&var mysource = "erm ... error error ... SCRIPT_FILENAME is Operators: Bitwise Not "~" Operators: Boolean Negation "!"not set in Flow control: if … then Flow control: try … thenthe process environment ..."
Flow control: if … then Flow control: try … thenthen
Text functions: convert Instructions: convertconvert mysource to html
Instructions: putput "<pre>\n", mysource, "\n</pre></body></html>\n"
Flow control: end Shell Immediate Commands: exit, quit, endend
Flow control: if … then Flow control: try … thenthen
Flow control: if … then Flow control: try … thenthen
// print notification on what Flow control: if … then Flow control: try … thenthe Example Scripts: CGI Scripts Example Scripts: Scriptsscript Flow control: do … loopdoes
// how to Functions with varying return types: call Instructions: callcall it Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and
// how to Functions with varying return types: call Instructions: callcall it so that it print's it's own source
Flow control: if … thenif Numeric functions: existsexists List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SERVER_NAME && Numeric functions: existsexists List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SCRIPT_NAME
{
Instructions: var How does VScript::Value() work?: Var*&var mydomain = List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SERVER_NAME
Instructions: var How does VScript::Value() work?: Var*&var myurlpath = List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SCRIPT_NAME
Instructions: var How does VScript::Value() work?: Var*&var myurl = "http://" # mydomain # myurlpath
Instructions: putput
"<p>List functions: thisthis Example Scripts: CGI Scripts Example Scripts: Scriptsscript Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallists environment Glossary: Variable, var_refvariables, command line Vipsi command syntax: Arguments Glossary: Argumentsarguments Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Instructions: getget/post cgi parameters.",
"<p>to see Flow control: if … then Flow control: try … thenthe source <a href='test.cgi?see_source=yes'>click here</a>.",
"<p>you can Functions with varying return types: call Instructions: callcall it directly: ", myurl,
"<br>Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or with some Vipsi command syntax: Arguments Glossary: Argumentsarguments: ", myurl, "?anton=123&berta=wetter",
"<br>Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or you can Instructions: writewrite an own page with a form which Functions with varying return types: call Instructions: callcalls List functions: thisthis Example Scripts: CGI Scripts Example Scripts: Scriptsscript ;-)."
}
Flow control: if … then Flow control: try … thenthen
// print List functions: globals Shell Immediate Commands: globalsglobal Glossary: Variable, var_refvariables
// Flow control: if … then Flow control: try … thenthe Example Scripts: CGI Scripts Example Scripts: Scriptsscript can access all List functions: globals Shell Immediate Commands: globalsglobal Glossary: Variable, var_refvariables unknowing their Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiernames by accessing Flow control: if … then Flow control: try … thenthe Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallist Glossary: Variable, var_refvariable "List functions: globals Shell Immediate Commands: globalsglobals".
// command line Vipsi command syntax: Arguments Glossary: Argumentsarguments passed to Flow control: if … then Flow control: try … thenthe Example Scripts: CGI Scripts Example Scripts: Scriptsscript come first Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and are unnamed
// (a Modes of Operation: CGI Scripts Example Scripts: CGI Scriptscgi script is normally Operators: Bitwise Not "~" Operators: Boolean Negation "!"not passed any command line Vipsi command syntax: Arguments Glossary: Argumentsarguments)
// data from Flow control: if … then Flow control: try … thenthe CGI Instructions: getGET/POST request come Flow control: nextnext Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and are named Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and already unencoded
// Flow control: if … thenif bogus data is passed vipsi - the friendly one.: The namethe names may be weird Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or unnamed
// typically a Modes of Operation: CGI Scripts Example Scripts: CGI Scriptscgi script should already know vipsi - the friendly one.: The namethe names of Vipsi command syntax: Arguments Glossary: Argumentsarguments passed to it
// but List functions: thisthis cgi test Example Scripts: CGI Scripts Example Scripts: Scriptsscript Flow control: do … loopdoes Operators: Bitwise Not "~" Operators: Boolean Negation "!"not Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and must examine Flow control: if … then Flow control: try … thenthe Glossary: Variable, var_refvariable Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiernames 'by hand'.
Instructions: var How does VScript::Value() work?: Var*&var argc = Numeric functions: countcount globals-1
Flow control: if … thenif argc
{
Instructions: putput
"<h4>argv[] Vipsi command syntax: Arguments Glossary: Argumentsarguments</h4>\n",
"<table border width='100%'><tr><td width='10%'><b>Numeric functions: indexindex</b></td>",
"<td width='20%'><b>Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername</b></td><td><b>Glossary: Valuevalue</b></td></tr>\n"
Instructions: var How does VScript::Value() work?: Var*&var i = 0
Flow control: do … loopdo
Flow control: whilewhile ++i<=argc
Instructions: var How does VScript::Value() work?: Var*&var gname = Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername List functions: globals Shell Immediate Commands: globalsglobals[i]
Instructions: var How does VScript::Value() work?: Var*&var gdata = List functions: globals Shell Immediate Commands: globalsglobals[i]
Text functions: convert Instructions: convertconvert gname to printable; Text functions: convert Instructions: convertconvert gname to html
Text functions: convert Instructions: convertconvert gdata to printable; Text functions: convert Instructions: convertconvert gdata to html
Instructions: putput "<tr>"
Instructions: putput "<td>List functions: globals Shell Immediate Commands: globalsglobals[",i,"]</td>"
Instructions: putput "<td>", gname=="" ? "<i>unnamed Glossary: Variable, var_refvariable</i>" : gname, "</td>"
Instructions: putput "<td>", gdata, "</td>"
Instructions: putput "</tr>"
Flow control: do … looploop
Instructions: putput "</table>\n"
}
Flow control: if … then Flow control: try … thenthen
// CGI Scripts: Print Environmentprint environment Glossary: Variable, var_refvariables
// Flow control: if … then Flow control: try … thenthe Example Scripts: CGI Scripts Example Scripts: Scriptsscript can request Flow control: if … then Flow control: try … thenthe process environment Glossary: Variable, var_refvariables with Flow control: if … then Flow control: try … thenthe built-in Vipsi command syntax: Functions Functions Glossary: Functionfunction List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.
// Flow control: if … then Flow control: try … thenthe returned Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallist contains one named item per environment Glossary: Variable, var_refvariable
// Flow control: if … then Flow control: try … thenthe CGI Instructions: getGET Vipsi command syntax: Arguments Glossary: Argumentsarguments can be found in Flow control: if … then Flow control: try … thenthe Glossary: Variable, var_refvariable "QUERY_STRING"
{
Instructions: putput
"<h4>List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv environment Glossary: Variable, var_refvariables</h4>\n",
"<table border width='100%'><tr><td width='10%'><b>Numeric functions: indexindex</b></td>",
"<td width='20%'><b>Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername</b></td><td><b>Glossary: Valuevalue</b></td></tr>\n"
// in order to Instructions: sortsort by Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername we Text functions: convert Instructions: convertconvert Flow control: if … then Flow control: try … thenthe named items of List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv
// into sub-lists of form { Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername, data }
Instructions: var How does VScript::Value() work?: Var*&var env_var = List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv
Instructions: var How does VScript::Value() work?: Var*&var i = 0
Flow control: do … loopdo
Flow control: whilewhile ++i <= Numeric functions: countcount env_var
env_var[i] = { Vipsi command syntax: Identifiers (names) Identifiers, names Operators: Make Identifier "@" Text functions: name Glossary: Name, Identifiername env_var[i], env_var[i] }
Flow control: do … looploop
Instructions: sortsort env_var // Instructions: sortsort Flow control: if … then Flow control: try … thenthe Data Types: Lists and arrays Item selector "[]": Lists Glossary: list, list_vallist
Text functions: convert Instructions: convertconvert env_var to printable // escape control characters et.al.
Text functions: convert Instructions: convertconvert env_var to html // Text functions: convert Instructions: convertconvert '<' to '<' etc.
Instructions: var How does VScript::Value() work?: Var*&var i = 0
Flow control: do … loopdo
Flow control: whilewhile ++i <= Numeric functions: countcount env_var
Instructions: var How does VScript::Value() work?: Var*&var ename = env_var[i,1]
Instructions: var How does VScript::Value() work?: Var*&var edata = env_var[i,2]
Instructions: putput "<tr>"
Instructions: putput "<td>List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv[",i,"]</td>"
Instructions: putput "<td>", ename=="" ? "<i>unnamed Glossary: Variable, var_refvariable</i>" : ename, "</td>"
Instructions: putput "<td>", edata, "</td>"
Instructions: putput "</tr>\n"
Flow control: do … looploop
Instructions: putput "</table>\n"
}
// print misc. Text functions: info Shell Immediate Commands: infoinfo
Instructions: putput "<h4>/bin/*</h4>\n"
Instructions: putput "<pre>"
Text functions: sys Instructions: syssys "ls","-l","/bin"
Instructions: putput "<h4>/usr/bin/*</h4>\n"
Instructions: putput "<pre>"
Text functions: sys Instructions: syssys "ls","-l","/usr/bin"
Instructions: putput "<h4>misc. tests</h4>"
Instructions: putput "<pre>"
Text functions: sys Instructions: syssys "which","gcc"
Text functions: sys Instructions: syssys "which","make"
// Flow control: if … then Flow control: try … thenthe final closing tags
// be nice Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and terminate Flow control: if … then Flow control: try … thenthe last line with a line ending character
Instructions: putput "</body></html>\n"
Flow control: end Shell Immediate Commands: exit, quit, endend
| |