administrativa
[m6w6/ext-psi] / psi.d / getopt.psi
1 #include <getopt.h>
2
3 function psi\opterr(int $value) : void {
4 let opterr = intval($value);
5 return opterr_set(opterr) as void(opterr_set);
6 }
7 function psi\optind\get() : int {
8 return optind_get() as to_int(optind_get);
9 }
10 function psi\optind\set(int $v) : void {
11 let optind = intval($v);
12 return optind_set(optind) as void(optind_set);
13 }
14 function psi\optopt() : int {
15 return optopt_get() as to_int(optopt_get);
16 }
17 function psi\optarg() : string {
18 return optarg_get() as to_string(optarg_get);
19 }
20
21 #ifdef _OPTRESET
22 function psi\optreset() : void {
23 let _v = 1;
24 return optreset_set(_v) as void(optreset_set);
25 }
26 #endif
27
28 static function psi\getopt(array &$argv, string $options) : int {
29 let argc = count($argv);
30 let argv = &arrval($argv,
31 *argv = strval($argv)
32 );
33 let optstring = strval($options);
34 return getopt(argc, argv, optstring) as to_int(getopt);
35 set $argv = to_array(
36 *argv,
37 argc,
38 to_string(*argv)
39 );
40 }