X-Git-Url: https://git.m6w6.name/?a=blobdiff_plain;ds=sidebyside;f=psi.d%2Fgetopt.psi;h=42b5ee5763d32564e4b016fe0a08665caf6a2332;hb=8d1d1243a8a42b0046ac670808913b3bb06c994b;hp=5f5bae6fcb67d6ac3224e55b94837d8b6589a502;hpb=a107dfcca2dfd0fc5a2779a8d679f778cb8f3290;p=m6w6%2Fext-psi diff --git a/psi.d/getopt.psi b/psi.d/getopt.psi index 5f5bae6..42b5ee5 100644 --- a/psi.d/getopt.psi +++ b/psi.d/getopt.psi @@ -1,24 +1,40 @@ -function psi\opterr() : int { - return to_int(opterr); +#include + +function psi\opterr(int $value) : void { + let opterr = intval($value); + return opterr_set(opterr) as void(opterr_set); +} +function psi\optind\get() : int { + return optind_get() as to_int(optind_get); } -function psi\optind() : int { - return to_int(optind); +function psi\optind\set(int $v) : void { + let optind = intval($v); + return optind_set(optind) as void(optind_set); } function psi\optopt() : int { - return to_int(optopt); + return optopt() as to_int(optopt); } function psi\optarg() : string { - return to_string(optarg); + return optarg() as to_string(optarg); +} + +#ifdef _OPTRESET +function psi\optreset() : void { + let _v = 1; + return optreset_set(_v) as void(optreset_set); } +#endif -function psi\getopt(array &$argv, string $options) : int { +static function psi\getopt(array &$argv, string $options) : int { let argc = count($argv); let argv = &arrval($argv, *argv = strval($argv) ); let optstring = strval($options); - return to_int(getopt); - set $argv = to_array(argv, - to_string(argv) + return getopt(argc, argv, optstring) as to_int(getopt); + set $argv = to_array( + *argv, + argc, + to_string(*argv) ); }