|
List functions: thisThis is Flow control: if … then Flow control: try … thenthe Example Scripts: CGI Scripts Example Scripts: Scriptsscript which i use for Flow control: if … then Flow control: try … thenthe "Seach Site" form on little-bat.de. You will have to adapt some paths Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and it is, like all my Modes of Operation: CGI Scripts Example Scripts: CGI Scriptscgi scripts, complicated by Flow control: if … then Flow control: try … thenthe fact, that i use it for two different sites without modification. So there is some path-fiddleing in there. It also contains a 'show-my-source' part.
search.cgi
Flow control: if … then Flow control: try … thenThe Online Chat: Test links Search Site: Test link Print Environment: Test link Online Z80 Assembler: Test link Show Beautified Folder Listings: Test link Sort-of-a Shell: Test linktest link searches Flow control: if … then Flow control: try … thenthe List functions: localslocal copy of little-bat.de for Flow control: if … then Flow control: try … thenthe occurance of any List functions: words Shell Immediate Commands: wordsword you like:
#!/home/smile77/bin/vipsi
// "CGI Scripts: Search Sitesearch site" Example Scripts: CGI Scripts Example Scripts: Scriptsscript as used on my homepage
// -------------------------------------------
// please adjust paths ... B-)
// Flow control: if … then Flow control: try … thenthe search pattern passed to Flow control: if … then Flow control: try … thenthe Example Scripts: CGI Scripts Example Scripts: Scriptsscript (must Numeric functions: existsexist):
Flow control: if … thenif !Numeric functions: existsexists(pattern) Instructions: var How does VScript::Value() work?: Var*&var pattern = "" Flow control: if … then Flow control: try … thenthen
// Text functions: file Instructions: filefile system Integer numbers: Base 256base expressed as http Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Text functions: file Instructions: filefile
Instructions: var How does VScript::Value() work?: Var*&var file_root = List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.DOCUMENT_ROOT # "/"
Instructions: var How does VScript::Value() work?: Var*&var http_root = "http://" # List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SERVER_NAME # "/"
// little patch so i can use it Operators: Make Identifier "@"at home:
Flow control: if … thenif List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SERVER_NAME=="_default_"
http_root = "http://" # List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.HTTP_HOST # "/"
Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SERVER_ADDR=="127.0.0.1" || List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SERVER_ADDR=="10.0.0.4"
file_root #= "www/little-bat.de/"
http_root #= "www/little-bat.de/"
Flow control: if … then Flow control: try … thenthen
// http Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and html header:
Instructions: putput "content-type: Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/html",Constants: nlnl,Constants: nlnl
Instructions: putput "<!doctype html public \"-//w3c//dtd html 4.01 strict//en\"><html><head>"
Instructions: putput "<META http-equiv=Content-Type content='Data Types: Text Item selector "[]": Text Glossary: text, text_valtext/html; charset=UTF-8'>"
Instructions: putput "<title>search results for '"#pattern#"'</title></head>",Constants: nlnl
Instructions: putput "<body background='"#http_root#"b/hdgr.jpg' bgcolor='#CCCCCC' ",
"Data Types: Text Item selector "[]": Text Glossary: text, text_valtext=black Text functions: link Instructions: linklink=black vlink=blue alink=black>",Constants: nlnl
// test for magic parameter to show my own source:
Flow control: if … thenif Numeric functions: existsexists showsource
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)
Text functions: convert Instructions: convertconvert mysource to html
Instructions: putput "<pre>",Constants: nlnl, mysource, Constants: nlnl,"</pre></body></html>",Constants: nlnl
Flow control: end Shell Immediate Commands: exit, quit, endend
Flow control: if … then Flow control: try … thenthen
// Vipsi command syntax: Procedures Data Types: Procedures Glossary: ProcedureProcedure: Print usage Vipsi command syntax: Instructions Instructions Glossary: Instructioninstructions
Instructions: procproc DisplayHelp(errmsg)
{
Instructions: putput
"<p align=center> ",
"<br><b>",errmsg,"</b>",
"<br> ",
"<table border=1 width='95%' align=center cellpadding=2>",
"<tr><Flow control: if … then Flow control: try … thenth align=center>",
"Help for CGI Scripts: Search SiteSearch Site",
"</Flow control: if … then Flow control: try … thenth></tr>",Constants: nlnl,
"<tr><td align=center>",
"<table border=0><tr><td>",
"<ul>",
"<li>Flow control: if … then Flow control: try … thenThe search pattern must be Operators: Make Identifier "@"at least 3 characters long.</li>",
"<li>Flow control: if … then Flow control: try … thenThe search is Operators: Bitwise Not "~" Operators: Boolean Negation "!"not case sensitive.</li>",
"<li>Flow control: if … then Flow control: try … thenThe search pattern must Numeric functions: matchmatch exactly Flow control: if … then Flow control: try … thenthe Data Types: Text Item selector "[]": Text Glossary: text, text_valtext in a Text functions: file Instructions: filefile.",
"<br>Flow control: if … thenIf it contains multiple List functions: words Shell Immediate Commands: wordswords, Flow control: if … then Flow control: try … thenthen they must appear 'as written'.</li>",
"<li>Use Flow control: if … then Flow control: try … thenthe Operators: Multiply "*"wildcards '?' Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and '*' to Numeric functions: matchmatch any single character Operators: Boolean Or with Variable "||=" Operators: Bitwise Or with Variable "|=" Operators: Bitwise Or "|" Operators: Boolean Or "||"or",
"<br>any sequence of non-significant characters.</li>",
"</ul>",
"</td></tr></table>",
"</td></tr>",Constants: nlnl,
"<tr><td align=center>",
"e.g. to search for Text functions: file Instructions: filefiles which contain '<b>foo</b>' Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and '<b>bar</b>' search for '<b>foo*bar</b>'.",
"</td></tr></table>",
"<p> ",Constants: nlnl
}
// Vipsi command syntax: Procedures Data Types: Procedures Glossary: ProcedureProcedure: search all Text functions: file Instructions: filefiles in directory "path"
// Functions with varying return types: call Instructions: callcalls itself recursively for all subdirectories
Instructions: procproc Search(path)
{
Flow control: if … thenif Text functions: rightstrrightstr(path,1)!="/" path#="/" Flow control: if … then Flow control: try … thenthen
Instructions: var How does VScript::Value() work?: Var*&var folder = List functions: dir Instructions: dir Shell Immediate Commands: dirdir(file_root#path)
Instructions: var How does VScript::Value() work?: Var*&var i = 0
Flow control: do … loopdo
Flow control: whilewhile ++i<=Numeric functions: countcount(folder)
Instructions: var How does VScript::Value() work?: Var*&var item = folder[i]
Instructions: var How does VScript::Value() work?: Var*&var dir: fnamefname = item.dir: fnamefname
Flow control: if … thenif item.dir: flagsflags[1]=="d" && Text functions: rightstrrightstr(dir: fnamefname,1)!="/" dir: fnamefname#="/" Flow control: if … then Flow control: try … thenthen
Flow control: if … thenif dir: fnamefname[1]=="." Flow control: nextnext Flow control: if … then Flow control: try … thenthen // skip hidden Text functions: file Instructions: filefiles
Flow control: if … thenif dir: fnamefname=="b/" Flow control: nextnext Flow control: if … then Flow control: try … thenthen // skip images folders
Flow control: if … thenif dir: fnamefname=="stats/" Flow control: nextnext Flow control: if … then Flow control: try … thenthen // skip stats folder (Instructions: requirerequires password anyway)
Flow control: if … thenif item.dir: flagsflags[1]=="d" // recursively handle folder
Search(path#dir: fnamefname) Flow control: nextnext
Flow control: if … then Flow control: try … thenthen
Instructions: var How does VScript::Value() work?: Var*&var ext = dir: fnamefname[ Numeric functions: rfindrfind(dir: fnamefname,".") to ]
Flow control: if … thenif !Numeric functions: findfind(".html.hh.cpp.txt",ext) Flow control: nextnext Flow control: if … then Flow control: try … thenthen // no Data Types: Text Item selector "[]": Text Glossary: text, text_valtext Text functions: file Instructions: filefile
Instructions: var How does VScript::Value() work?: Var*&var datei = Text functions: lowerstrlowerstr(Text functions: file Instructions: filefile(file_root#path#dir: fnamefname))
files_scanned += 1
bytes_scanned += Numeric functions: countcount(datei)
Flow control: if … thenif !Numeric functions: matchmatch(datei,pattern) Flow control: nextnext Flow control: if … then Flow control: try … thenthen // Operators: Bitwise Not "~" Operators: Boolean Negation "!"not found
Instructions: var How does VScript::Value() work?: Var*&var a=Numeric functions: findfind(datei,"<title>") // found: display Text functions: file Instructions: filefile
Instructions: var How does VScript::Value() work?: Var*&var e=Numeric functions: findfind(datei,"</title>")
Instructions: var How does VScript::Value() work?: Var*&var title = a&&e ? datei[a+7 to e-1] : "<i>no title</i>"
Display(path,dir: fnamefname,title)
Flow control: do … looploop
}
// Vipsi command syntax: Procedures Data Types: Procedures Glossary: ProcedureProcedure: build a Text functions: link Instructions: linklink:
Instructions: procproc Text functions: link Instructions: linkLink(url,Data Types: Text Item selector "[]": Text Glossary: text, text_valtext)
{
Flow control: returnreturn "<a href='" # url # "'>" # Data Types: Text Item selector "[]": Text Glossary: text, text_valtext # "</a>"
}
// Vipsi command syntax: Procedures Data Types: Procedures Glossary: ProcedureProcedure: print table row for Text functions: file Instructions: filefile:
Instructions: procproc Display(path,dir: fnamefname,title)
{
files_found++
Text functions: convert Instructions: convertconvert path to html
Text functions: convert Instructions: convertconvert dir: fnamefname to html
Instructions: var How does VScript::Value() work?: Var*&var url = http_root # path # dir: fnamefname;
Instructions: putput "<tr><td>", Text functions: link Instructions: linkLink(url,path#dir: fnamefname), "</td><td>", title, "</td></tr>",Constants: nlnl
}
// statistics counters
Instructions: var How does VScript::Value() work?: Var*&var files_scanned = 0
Instructions: var How does VScript::Value() work?: Var*&var bytes_scanned = 0
Instructions: var How does VScript::Value() work?: Var*&var files_found = 0
// print table start
Instructions: putput
"<p> <table border=1 width='95%' align=center cellpadding=2>",
"<tr><Flow control: if … then Flow control: try … thenth bgcolor='#ffffcc' colspan=2 align=center style='font-size:150%;'>Search results for '", pattern, "'</Flow control: if … then Flow control: try … thenth></tr>",
"<tr><Flow control: if … then Flow control: try … thenth bgcolor='#00CCCC'>Text functions: file Instructions: filefile</Flow control: if … then Flow control: try … thenth><Flow control: if … then Flow control: try … thenth bgcolor='#00CCCC'>title</Flow control: if … then Flow control: try … thenth></tr>\n"
// search & print table rows
Flow control: if … thenif Numeric functions: countcount(pattern)>=3
pattern = "*" # Text functions: lowerstrlowerstr(pattern) # "*"
Search("")
Flow control: if … then Flow control: try … thenthen
// print table Flow control: end Shell Immediate Commands: exit, quit, endend
Instructions: putput "</table>",Constants: nlnl
// Flow control: if … thenif no Text functions: file Instructions: filefiles found print additional help
Flow control: if … thenif files_found
Instructions: putput
"<p align=center> ",
"<br>Scanned ",files_scanned,
" Text functions: file Instructions: filefiles (",bytes_scanned,
" bytes) Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and found <b>",files_found,
"</b> Text functions: file Instructions: filefile","s"[to files_found>1],".</p>\n"
Flow control: if … then Flow control: try … thenelse
Flow control: if … thenif Numeric functions: countcount(pattern)==0 DisplayHelp("Search failed. (no search pattern given)") Flow control: if … then Flow control: try … thenelse
Flow control: if … thenif Numeric functions: countcount(pattern)<3 DisplayHelp("Search failed. (search pattern too short)") Flow control: if … then Flow control: try … thenelse
DisplayHelp("No Text functions: file Instructions: filefiles found.");
Flow control: if … then Flow control: try … thenthen Flow control: if … then Flow control: try … thenthen
Flow control: if … then Flow control: try … thenthen
// print Text functions: info Shell Immediate Commands: infoinfo on vipsi
Instructions: putput
"<p> ",
"<table border=1 width='95%' align=center cellpadding=2>",
"<tr><td align=center>\n",
Text functions: link Instructions: linkLink( "http://" # List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.HTTP_HOST # List functions: env Shell Immediate Commands: env Shell Immediate Commands: envenv.SCRIPT_NAME # "?showsource=yes", "view Example Scripts: CGI Scripts Example Scripts: Scriptsscript" ),
" powered by vipsi - vipsi shell Operators: Boolean And with Variable "&&=" Operators: Bitwise And with Variable "&=" Operators: Bitwise And "&" Operators: Boolean And "&&"and Example Scripts: CGI Scripts Example Scripts: Scriptsscript language ",
Text functions: link Instructions: linkLink( "http://vipsi.sourceforge.net' target='_blank","Introduction: About vipsiabout vipsi" ),
"\n</td></tr></table>\n"
// print Flow control: end Shell Immediate Commands: exit, quit, endend of html page
Instructions: putput "<p> </body></html>",Constants: nlnl
Flow control: end Shell Immediate Commands: exit, quit, endend
| |