Select Git revision
-
Henrik (Grubba) Grubbström authored
Rev: src/acconfig.h:1.19 Rev: src/alloca.c:1.2 Rev: src/array.c:1.31 Rev: src/array.h:1.12 Rev: src/backend.h:1.6 Rev: src/build_modlist_h:1.2 Rev: src/builtin_functions.h:1.7 Rev: src/callback.c:1.14 Rev: src/callback.h:1.7 Rev: src/compilation.h:1.8 Rev: src/constants.c:1.13 Rev: src/constants.h:1.6 Rev: src/cpp.c:1.21 Rev: src/cpp.h:1.4 Rev: src/crypt.c:1.2 Rev: src/cyclic.c:1.3 Rev: src/cyclic.h:1.3 Rev: src/dmalloc.h:1.5 Rev: src/docode.h:1.5 Rev: src/dynamic_buffer.c:1.8 Rev: src/dynamic_buffer.h:1.6 Rev: src/dynamic_load.c:1.25 Rev: src/dynamic_load.h:1.3 Rev: src/efun.h:1.3 Rev: src/encode.c:1.18 Rev: src/encode.h:1.2 Rev: src/error.c:1.14 Rev: src/error.h:1.14 Rev: src/fd_control.c:1.17 Rev: src/fd_control.h:1.3 Rev: src/fdlib.c:1.16 Rev: src/fdlib.h:1.13 Rev: src/fsort.c:1.9 Rev: src/fsort.h:1.2 Rev: src/fsort_template.h:1.3 Rev: src/gc.c:1.30 Rev: src/gc.h:1.16 Rev: src/global.h:1.20 Rev: src/hashtable.c:1.4 Rev: src/hashtable.h:1.5 Rev: src/install-sh:1.4 Rev: src/interpret.h:1.20 Rev: src/las.h:1.13 Rev: src/lex.h:1.10 Rev: src/main.h:1.7 Rev: src/mapping.h:1.10 Rev: src/module.c:1.8 Rev: src/module.h:1.4 Rev: src/module_support.c:1.9 Rev: src/module_support.h:1.6 Rev: src/modules/Gdbm/Makefile.in:1.3 Rev: src/modules/Gdbm/configure.in:1.2 Rev: src/modules/Gdbm/testsuite.in:1.4 Rev: src/modules/Gmp/Makefile.in:1.8 Rev: src/modules/Gmp/configure.in:1.2 Rev: src/modules/Gmp/gmp_machine.h.in:1.2 Rev: src/modules/Gmp/my_gmp.h:1.3 Rev: src/modules/Gmp/next_prime.c:1.6 Rev: src/modules/Gmp/prime_table.c:1.3 Rev: src/modules/Gmp/testsuite.in:1.12 Rev: src/modules/Gz/Makefile.in:1.3 Rev: src/modules/Gz/configure.in:1.10 Rev: src/modules/Gz/testsuite.in:1.4 Rev: src/modules/Image/Makefile:1.8 Rev: src/modules/Image/Makefile.in:1.14 Rev: src/modules/Image/configure.in:1.8 Rev: src/modules/Image/encodings/Makefile.in:1.14 Rev: src/modules/Image/encodings/configure.in:1.4 Rev: src/modules/Image/testsuite.in:1.5 Rev: src/modules/MIME/Makefile.in:1.2 Rev: src/modules/MIME/acconfig.h:1.2 Rev: src/modules/MIME/configure.in:1.3 Rev: src/modules/MIME/testsuite.in:1.5 Rev: src/modules/Msql/Makefile.in:1.3 Rev: src/modules/Msql/test_msqlmod.pike:1.2 Rev: src/modules/Mysql/dummy.c:1.4 Rev: src/modules/Pipe/Makefile.in:1.3 Rev: src/modules/Pipe/configure.in:1.4 Rev: src/modules/Postgres/extras/test_notify.pike:1.2 Rev: src/modules/Postgres/extras/test_schema.pike:1.2 Rev: src/modules/Postgres/pg_types.h:1.3 Rev: src/modules/Postgres/pgresult.c:1.5 Rev: src/modules/Postgres/pgresult.h:1.2 Rev: src/modules/Regexp/Makefile.in:1.5 Rev: src/modules/Regexp/configure.in:1.5 Rev: src/modules/Regexp/glue.c:1.10 Rev: src/modules/Regexp/pike_regexp.c:1.12 Rev: src/modules/Regexp/pike_regexp.h:1.3 Rev: src/modules/Regexp/testsuite.in:1.3 Rev: src/modules/Ssleay/Makefile.in:1.3 Rev: src/modules/Ssleay/acconfig.h:1.2 Rev: src/modules/Ssleay/configure.in:1.4 Rev: src/modules/Yp/Makefile.in:1.3 Rev: src/modules/Yp/configure.in:1.5 Rev: src/modules/Yp/yp.c:1.12 Rev: src/modules/_Crypto/.build_lobotomized_crypto:1.6 Rev: src/modules/_Crypto/.exportable_files:1.3 Rev: src/modules/_Crypto/Makefile.in:1.16 Rev: src/modules/_Crypto/configure.in:1.5 Rev: src/modules/_Crypto/include/.exportable_files:1.2 Rev: src/modules/_Crypto/include/RCSID.h:1.6 Rev: src/modules/_Crypto/include/cast.h:1.2 Rev: src/modules/_Crypto/include/crypto_types.h:1.5 Rev: src/modules/_Crypto/include/idea.h:1.4 Rev: src/modules/_Crypto/include/md5.h:1.2 Rev: src/modules/_Crypto/include/rc4.h:1.3 Rev: src/modules/_Crypto/include/sha.h:1.4 Rev: src/modules/_Crypto/lib/.exportable_files:1.2 Rev: src/modules/_Crypto/lib/cast.c:1.2 Rev: src/modules/_Crypto/lib/cast_sboxes.h:1.2 Rev: src/modules/_Crypto/precompiled_crypto.h:1.17 Rev: src/modules/_Crypto/sha.c:1.10 Rev: src/modules/_Image_PNG/Makefile.in:1.2 Rev: src/modules/_Image_PNG/configure.in:1.2 Rev: src/modules/_Image_PNG/testsuite.in:1.3 Rev: src/modules/_Image_XFace/Makefile.in:1.2 Rev: src/modules/_Image_XFace/configure.in:1.2 Rev: src/modules/_Image_XFace/testsuite.in:1.2 Rev: src/modules/configure.in:1.5 Rev: src/modules/module_configure.in:1.5 Rev: src/modules/module_makefile:1.3 Rev: src/multiset.c:1.10 Rev: src/multiset.h:1.7 Rev: src/object.h:1.17 Rev: src/opcodes.c:1.16 Rev: src/opcodes.h:1.4 Rev: src/operators.h:1.4 Rev: src/otable.h:1.2 Rev: src/peep.c:1.19 Rev: src/peep.h:1.4 Rev: src/peep.in:1.12 Rev: src/pike_macros.h:1.6 Rev: src/pike_memory.c:1.18 Rev: src/pike_memory.h:1.4 Rev: src/pike_types.h:1.11 Rev: src/port.c:1.15 Rev: src/port.h:1.18 Rev: src/program.h:1.35 Rev: src/run_autoconfig:1.21 Rev: src/rusage.c:1.10 Rev: src/rusage.h:1.3 Rev: src/signal_handler.c:1.41 Rev: src/signal_handler.h:1.6 Rev: src/stralloc.c:1.30 Rev: src/stralloc.h:1.15 Rev: src/stuff.c:1.6 Rev: src/stuff.h:1.5 Rev: src/svalue.c:1.21 Rev: src/svalue.h:1.14 Rev: src/threads.h:1.40 Rev: src/time_stuff.h:1.8 Rev: src/ualarm.c:1.2 Rev: src/version.c:1.34 Rev: src/version.h:1.3
Henrik (Grubba) Grubbström authoredRev: src/acconfig.h:1.19 Rev: src/alloca.c:1.2 Rev: src/array.c:1.31 Rev: src/array.h:1.12 Rev: src/backend.h:1.6 Rev: src/build_modlist_h:1.2 Rev: src/builtin_functions.h:1.7 Rev: src/callback.c:1.14 Rev: src/callback.h:1.7 Rev: src/compilation.h:1.8 Rev: src/constants.c:1.13 Rev: src/constants.h:1.6 Rev: src/cpp.c:1.21 Rev: src/cpp.h:1.4 Rev: src/crypt.c:1.2 Rev: src/cyclic.c:1.3 Rev: src/cyclic.h:1.3 Rev: src/dmalloc.h:1.5 Rev: src/docode.h:1.5 Rev: src/dynamic_buffer.c:1.8 Rev: src/dynamic_buffer.h:1.6 Rev: src/dynamic_load.c:1.25 Rev: src/dynamic_load.h:1.3 Rev: src/efun.h:1.3 Rev: src/encode.c:1.18 Rev: src/encode.h:1.2 Rev: src/error.c:1.14 Rev: src/error.h:1.14 Rev: src/fd_control.c:1.17 Rev: src/fd_control.h:1.3 Rev: src/fdlib.c:1.16 Rev: src/fdlib.h:1.13 Rev: src/fsort.c:1.9 Rev: src/fsort.h:1.2 Rev: src/fsort_template.h:1.3 Rev: src/gc.c:1.30 Rev: src/gc.h:1.16 Rev: src/global.h:1.20 Rev: src/hashtable.c:1.4 Rev: src/hashtable.h:1.5 Rev: src/install-sh:1.4 Rev: src/interpret.h:1.20 Rev: src/las.h:1.13 Rev: src/lex.h:1.10 Rev: src/main.h:1.7 Rev: src/mapping.h:1.10 Rev: src/module.c:1.8 Rev: src/module.h:1.4 Rev: src/module_support.c:1.9 Rev: src/module_support.h:1.6 Rev: src/modules/Gdbm/Makefile.in:1.3 Rev: src/modules/Gdbm/configure.in:1.2 Rev: src/modules/Gdbm/testsuite.in:1.4 Rev: src/modules/Gmp/Makefile.in:1.8 Rev: src/modules/Gmp/configure.in:1.2 Rev: src/modules/Gmp/gmp_machine.h.in:1.2 Rev: src/modules/Gmp/my_gmp.h:1.3 Rev: src/modules/Gmp/next_prime.c:1.6 Rev: src/modules/Gmp/prime_table.c:1.3 Rev: src/modules/Gmp/testsuite.in:1.12 Rev: src/modules/Gz/Makefile.in:1.3 Rev: src/modules/Gz/configure.in:1.10 Rev: src/modules/Gz/testsuite.in:1.4 Rev: src/modules/Image/Makefile:1.8 Rev: src/modules/Image/Makefile.in:1.14 Rev: src/modules/Image/configure.in:1.8 Rev: src/modules/Image/encodings/Makefile.in:1.14 Rev: src/modules/Image/encodings/configure.in:1.4 Rev: src/modules/Image/testsuite.in:1.5 Rev: src/modules/MIME/Makefile.in:1.2 Rev: src/modules/MIME/acconfig.h:1.2 Rev: src/modules/MIME/configure.in:1.3 Rev: src/modules/MIME/testsuite.in:1.5 Rev: src/modules/Msql/Makefile.in:1.3 Rev: src/modules/Msql/test_msqlmod.pike:1.2 Rev: src/modules/Mysql/dummy.c:1.4 Rev: src/modules/Pipe/Makefile.in:1.3 Rev: src/modules/Pipe/configure.in:1.4 Rev: src/modules/Postgres/extras/test_notify.pike:1.2 Rev: src/modules/Postgres/extras/test_schema.pike:1.2 Rev: src/modules/Postgres/pg_types.h:1.3 Rev: src/modules/Postgres/pgresult.c:1.5 Rev: src/modules/Postgres/pgresult.h:1.2 Rev: src/modules/Regexp/Makefile.in:1.5 Rev: src/modules/Regexp/configure.in:1.5 Rev: src/modules/Regexp/glue.c:1.10 Rev: src/modules/Regexp/pike_regexp.c:1.12 Rev: src/modules/Regexp/pike_regexp.h:1.3 Rev: src/modules/Regexp/testsuite.in:1.3 Rev: src/modules/Ssleay/Makefile.in:1.3 Rev: src/modules/Ssleay/acconfig.h:1.2 Rev: src/modules/Ssleay/configure.in:1.4 Rev: src/modules/Yp/Makefile.in:1.3 Rev: src/modules/Yp/configure.in:1.5 Rev: src/modules/Yp/yp.c:1.12 Rev: src/modules/_Crypto/.build_lobotomized_crypto:1.6 Rev: src/modules/_Crypto/.exportable_files:1.3 Rev: src/modules/_Crypto/Makefile.in:1.16 Rev: src/modules/_Crypto/configure.in:1.5 Rev: src/modules/_Crypto/include/.exportable_files:1.2 Rev: src/modules/_Crypto/include/RCSID.h:1.6 Rev: src/modules/_Crypto/include/cast.h:1.2 Rev: src/modules/_Crypto/include/crypto_types.h:1.5 Rev: src/modules/_Crypto/include/idea.h:1.4 Rev: src/modules/_Crypto/include/md5.h:1.2 Rev: src/modules/_Crypto/include/rc4.h:1.3 Rev: src/modules/_Crypto/include/sha.h:1.4 Rev: src/modules/_Crypto/lib/.exportable_files:1.2 Rev: src/modules/_Crypto/lib/cast.c:1.2 Rev: src/modules/_Crypto/lib/cast_sboxes.h:1.2 Rev: src/modules/_Crypto/precompiled_crypto.h:1.17 Rev: src/modules/_Crypto/sha.c:1.10 Rev: src/modules/_Image_PNG/Makefile.in:1.2 Rev: src/modules/_Image_PNG/configure.in:1.2 Rev: src/modules/_Image_PNG/testsuite.in:1.3 Rev: src/modules/_Image_XFace/Makefile.in:1.2 Rev: src/modules/_Image_XFace/configure.in:1.2 Rev: src/modules/_Image_XFace/testsuite.in:1.2 Rev: src/modules/configure.in:1.5 Rev: src/modules/module_configure.in:1.5 Rev: src/modules/module_makefile:1.3 Rev: src/multiset.c:1.10 Rev: src/multiset.h:1.7 Rev: src/object.h:1.17 Rev: src/opcodes.c:1.16 Rev: src/opcodes.h:1.4 Rev: src/operators.h:1.4 Rev: src/otable.h:1.2 Rev: src/peep.c:1.19 Rev: src/peep.h:1.4 Rev: src/peep.in:1.12 Rev: src/pike_macros.h:1.6 Rev: src/pike_memory.c:1.18 Rev: src/pike_memory.h:1.4 Rev: src/pike_types.h:1.11 Rev: src/port.c:1.15 Rev: src/port.h:1.18 Rev: src/program.h:1.35 Rev: src/run_autoconfig:1.21 Rev: src/rusage.c:1.10 Rev: src/rusage.h:1.3 Rev: src/signal_handler.c:1.41 Rev: src/signal_handler.h:1.6 Rev: src/stralloc.c:1.30 Rev: src/stralloc.h:1.15 Rev: src/stuff.c:1.6 Rev: src/stuff.h:1.5 Rev: src/svalue.c:1.21 Rev: src/svalue.h:1.14 Rev: src/threads.h:1.40 Rev: src/time_stuff.h:1.8 Rev: src/ualarm.c:1.2 Rev: src/version.c:1.34 Rev: src/version.h:1.3
Getopt.pmod 5.85 KiB
// startpid = (int)find_arg(argv, "s", ({ "start-script-pid" }),
// ({ "ROXEN_START_SCRIPT_PID"}));
// configuration_dir = find_arg(argv, "d", ({ "config-dir",
// "configurations",
// "configuration-directory" }),
// ({ "ROXEN_CONFIGDIR", "CONFIGURATIONS" }),
// "../configurations");
string|int find_option(array argv,
array|string shortform,
array|string|void longform,
array|string|void envvars,
mixed|void def,
int|void throw_errors)
{
mixed value;
int i,hasarg;
hasarg=query_num_arg() > 4;
if(!arrayp(longform)) longform=({longform});
if(!arrayp(shortform)) shortform=({shortform});
if(!arrayp(envvars)) envvars=({envvars});
for(i=1; i<sizeof(argv); i++)
{
if(argv[i] && strlen(argv[i]) > 1)
{
if(argv[i][0] == '-')
{
if(argv[i][1] == '-')
{
string tmp;
int nf;
if(argv[i]=="--") break;
sscanf(tmp=argv[i], "%s=%s", tmp, value);
if(search(longform, tmp[2..]) != -1)
{
argv[i]=0;
if(hasarg)
{
if(!value)
{
if(i == sizeof(argv)-1)
{
if (throw_errors) {
throw(({ "No argument to option "+tmp+".\n",
backtrace() }));
} else {
werror("No argument to option "+tmp+".\n");
exit(1);
}
}
value=argv[i+1];
argv[i+1]=0;
}
return value;
} else {
return value || 1;
}
}
} else {
int j;
for(j=1;j<strlen(argv[i]);j++)
{
string opt;
int pos;
if(search(shortform, opt=argv[i][j..j]) != -1)
{
string arg;
arg=argv[i][j+1..];
if(hasarg)
{
if(arg=="")
{
if(i == sizeof(argv)-1)
{
if (throw_errors) {
throw(({ "No argument to option -"+argv[i][j..j]+".\n",
backtrace() }));
} else {
werror("No argument to option -"+argv[i][j..j]+".\n");
exit(1);
}
}
value=argv[i+1];
argv[i+1] = 0;
} else {
value=arg;
arg="";
}
} else {
value=1;
}
argv[i]=argv[i][..j-1]+arg;
if(argv[i]=="-") argv[i]=0;
return value;
}
}
}
}
}
}
if(arrayp(envvars))
foreach(envvars, value)
if(value && (value=getenv(value)))
return value;
return def;
}
/*
* ({ "name", type, ({aliases}), env_var, default })
*/
constant HAS_ARG=1;
constant NO_ARG=2;
constant MAY_HAVE_ARG=3;
#define NAME 0
#define TYPE 1
#define ALIASES 2
#define ENV 3
#define DEF 4
mixed *find_all_options(string *argv, mixed *options,
void|int posix_me_harder, void|int throw_errors)
{
mapping quick=([]);
foreach(options, mixed opt)
{
mixed aliases=opt[ALIASES];
if(!arrayp(aliases)) aliases=({aliases});
foreach(aliases, mixed optname)
{
if(optname[0..1]=="--")
{
quick[optname]=opt;
}else{
foreach(optname[1..]/"",string optletter)
{
quick["-"+optletter]=opt;
}
}
}
}
mixed *ret=({});
for(int e=1;e<sizeof(argv);e++)
{
if(!argv[e]) continue;
if(strlen(argv[e]) && argv[e][0]=='-')
{
if(strlen(argv[e])>1 && argv[e][1]=='-')
{
string opt=argv[e];
if(opt=="--") break;
string arg;
sscanf(opt,"%s=%s",opt, arg);
if(mixed *option=quick[opt])
{
argv[e]=0;
if(!arg && option[TYPE]==HAS_ARG)
{
if(e==sizeof(argv)-1)
{
if (throw_errors) {
throw(({ "No argument to option "+opt+".\n",
backtrace() }));
} else {
werror("No argument to option "+opt+".\n");
exit(1);
}
}
arg=argv[e+1];
argv[e+1]=0;
}
ret+=({ ({ option[0], arg || 1 }) });
}
}else{
string *foo=argv[e]/"";
for(int j=1;j<strlen(foo);j++)
{
string opt="-"+foo[j];
if(mixed *option=quick[opt])
{
foo[j]=0;
string arg;
if(option[TYPE]!=NO_ARG)
{
arg=argv[e][j+1..];
if(option[TYPE]==HAS_ARG && arg=="")
{
if(e==sizeof(argv)-1)
{
if (throw_errors) {
throw(({ "No argument to option "+opt+".\n",
backtrace() }));
} else {
werror("No argument to option "+opt+".\n");
exit(1);
}
}
arg=argv[e+1];
argv[e+1]=0;
}else{
foo=foo[..j];
}
}
ret+=({ ({ option[0], arg || 1 }) });
}
}
argv[e]=foo*"";
if(argv[e]=="-") argv[e]=0;
}
}else{
if(posix_me_harder || getenv("POSIX_ME_HARDER"))
break;
}
}
multiset done=mkmultiset(column(ret, 0));
foreach(options, string *option)
{
string name=option[NAME];
if(done[name]) continue;
if(sizeof(option) > ENV)
{
mixed foo=option[ENV];
if(!foo) continue;
if(stringp(foo)) foo=({foo});
foreach(foo, foo)
{
if(foo=getenv(foo))
{
ret+=({ ({name, foo}) });
done[name]=1;
break;
}
}
if(!done && sizeof(option)>3 && option[3])
{
ret+=({ ({name, option[3]}) });
done[name]=1;
}
}
}
return ret;
}
string *get_args(string *argv, void|int posix_me_harder, void|int throw_errors)
{
int i;
for(i=1;i<sizeof(argv);i++)
{
if(argv[i] && strlen(argv[i])>1 && argv[i][0]=='-')
{
if(argv[i][1]=='-')
{
if(argv[i]=="--")
{
argv[i]=0;
break;
}else{
if (throw_errors) {
throw(({ "Unknown option "+argv[i]+".\n",
backtrace() }));
} else {
werror("Unknown option "+argv[i]+".\n");
exit(1);
}
}
}else{
if(strlen(argv[i]) == 2) {
if (throw_errors) {
throw(({ "Unknown option "+argv[i]+".\n",
backtrace() }));
} else {
werror("Unknown option "+argv[i]+".\n");
}
} else {
if (throw_errors) {
throw(({ "Unknown options "+argv[i]+".\n",
backtrace() }));
} else {
werror("Unknown options "+argv[i]+".\n");
}
}
exit(1);
}
}else{
if(posix_me_harder || getenv("POSIX_ME_HARDER"))
break;
}
}
argv-=({0,1});
return argv;
}