File:  [parser3project] / parser3 / tests / 171.html
Revision 1.5: download - view: text, annotated - select for diffs - revision graph
Mon Feb 13 17:15:56 2017 UTC (9 years, 3 months ago) by moko
Branches: MAIN
CVS tags: release_3_5_1, release_3_5_0, release_3_4_6, release_3_4_5, HEAD
cat-windows.sh support added

@main[]
$request:charset[windows-1251]
$response:charset[$request:charset]
$sScript[./cat^os[-windows].sh]

$tData[^table::create{sType	sFormat	sContentType	sFileName	iStatus	sText	sCharset
exec		text/plain	notfound.txt	1
exec	text	text/plain	notfound.txt	2
cgi	text	text/plain	notfound.txt	3	тест
exec	binary	image/gif	notfound.gif	4
cgi	text	text/plain	161_windows1251.txt	0	тест	$request:charset
exec	text	text/plain	161_utf8.txt	0	тест	UTF-8
cgi	binary	image/gif	019paf2001.gif	0
#old style
exec		text/plain	161_windows1251.txt	0	тест
cgi		text/plain	161_windows1251.txt	0
}]

^tData.menu{
	Get ^if(-f $tData.sFileName){file '$tData.sFileName' as ^if($tData.sFormat eq "binary"){binary}{text}^if(def $tData.sText){ with additional text '$tData.sText'}}{not existing file '$tData.sFileName'} ^if(def $tData.sCharset){in $tData.sCharset}{without ^$.charset option} (^if(def $tData.sFormat){^^file::${tData.sType}[$tData.sFormat^;script^;...]}{^^file::${tData.sType}[script^;...]}):
	^if(def $tData.sFormat){
		^rem{ *** new style where in 1st param we can specify 'text' or 'binary' format *** }
		^switch[$tData.sType]{
			^case[exec]{
				$f[^file::exec[$tData.sFormat;$sScript;^if(def $tData.sCharset){$.charset[$tData.sCharset]};exec;$tData.sContentType;$tData.sFileName;$tData.iStatus;$tData.sText]]
			}
			^case[cgi]{
				$f[^file::cgi[$tData.sFormat;$sScript;^if(def $tData.sCharset){$.charset[$tData.sCharset]};cgi;$tData.sContentType;$tData.sFileName;$tData.iStatus;$tData.sText]]
			}
		}
	}{
		^rem{ *** old style: 1st param can be path to script only *** }
		^switch[$tData.sType]{
			^case[exec]{
				$f[^file::exec[$sScript;^if(def $tData.sCharset){$.charset[$tData.sCharset]};exec;$tData.sContentType;$tData.sFileName;$tData.iStatus;$tData.sText]]
			}
			^case[cgi]{
				$f[^file::cgi[$sScript;^if(def $tData.sCharset){$.charset[$tData.sCharset]};cgi;$tData.sContentType;$tData.sFileName;$tData.iStatus;$tData.sText]]
			}
		}
	}
	^print[$tData.sType;$f]
	^if($f is "file" && !$f.status){
		^f.save[^if($tData.sFormat eq "binary"){binary}{text};171_dir/^tData.line[].^file:justext[$tData.sFileName]]
	}
}


$f[]
Calling cgi which don't get back CGI headers:
^try{
	$f[^file::cgi[$sScript;;exec;text/plain;161_windows1251.txt;0]]
}{
	$exception.handled(1)
}
^print[cgi;$f]

@print[sType;f]
^if($f is "file"){
	^$f.status: ^if($f.status){!=0}{==0}
	^$f.text: '$f.text'
	^$f.size: ^if(def $f.size){$f.size}{-}
	^$f.text.length: ^if(def $f.text){^f.text.length[]}{-}
	^if($sType eq "cgi"){^$f.CONTENT-TYPE: ^if(def ${f.CONTENT-TYPE}){${f.CONTENT-TYPE}}{-}}
}{
	Variable is not a file, can't analyze it.
}
^taint[as-is][^#0A]

E-mail: