#line 667 "/home/ubuntu/felix/src/packages/program.fdoc"
class System
{
const argc:int = "ptf-> argc" requires property "needs_ptf";
const _argv:&&char= "ptf-> argv" requires property "needs_ptf";
fun argv:int -> string = '::std::string($1<0||$1>=ptf-> argc??"":ptf-> argv[$1])'
requires property "needs_ptf";
fun argv_dflt (x:int) (y:string) => match argv x with | "" => y | a => a;
fun args () => List::map (argv) (List::range argc);
proc setargs : + (+char) * size = "ptf-> argc=$2; ptf-> argv=$1;" requires property "needs_ptf";
proc setargs[N:UNITSUM] (a:string^N)
{
gen myget(i:size)=>a.i.cstr;
var x = varray[+char] (a.len,a.len,myget);
setargs (x.stl_begin,x.len);
}
gen system (cmd:string) : int => Shell::system(cmd);
gen exit: int -> any = '::std::exit($1)' requires Cxx_headers::cstdlib;
gen abort: 1 -> any =
'(fprintf(stderr,"Felix code calling abort\\n"),::std::abort())'
requires Cxx_headers::cstdlib;
_gc_pointer type ptf_t = "thread_frame_t*";
const ptf:ptf_t = "ptf" requires property "needs_ptf";
if PLAT_WIN32 do
proc pexit(e:int)
{
if e != 0 do
if e == -1 do
err := errno;
eprintln$ "Error "+err.str+" in flx: " + strerror err;
System::exit err.int;
else
eprintln$ "Unknown error in shell " + str e;
System::exit 3;
done
done
System::exit e;
}
else
proc pexit(e:int)
{
if e != 0 do
if PosixProcess::WIFEXITED e.PosixProcess::process_status_t do
err := PosixProcess::WEXITSTATUS e.PosixProcess::process_status_t;
eprintln$ "Error "+err.str+" in flx: " + strerror err.errno_t;
System::exit err;
elif PosixProcess::WIFSIGNALED e.PosixProcess::process_status_t do
sig := Process::WTERMSIG e.PosixProcess::process_status_t;
eprintln$ "Shell terminated by signal " + str sig;
System::exit 2;
else
eprintln$ "Unknown error in shell " + str e;
System::exit 3;
done
done
System::exit e;
}
done
gen get_stdout(x:string) : int * string => Shell::get_stdout x;
}