Skip to content
Snippets Groups Projects
Commit d466bdd0 authored by Fredrik Hübinette (Hubbe)'s avatar Fredrik Hübinette (Hubbe)
Browse files

smarter (less buggy) argument parser

Rev: lib/master.pike:1.16
parent c6d4411c
No related branches found
No related tags found
No related merge requests found
...@@ -198,21 +198,26 @@ void _main(string *argv, string *env) ...@@ -198,21 +198,26 @@ void _main(string *argv, string *env)
pike_library_path = q[0..sizeof(q)-2] * "/"; pike_library_path = q[0..sizeof(q)-2] * "/";
tmp=new(pike_library_path+"/include/getopt.pre.pike"); tmp=new(pike_library_path+"/include/getopt.pre.pike");
if(tmp->find_option(argv,"v","version"))
foreach(tmp->find_all_options(argv,({
({"version",({"-v","--version"})}),
({"ignore","-Dmsdatp",0,0})}),1),mixed *opts)
{
switch(opts[0])
{ {
case "version":
werror(VERSION " Copyright (C) 1994-1997 Fredrik Hübinette\n"); werror(VERSION " Copyright (C) 1994-1997 Fredrik Hübinette\n");
werror("Pike comes with ABSOLUTELY NO WARRANTY; This is free software and you are\n"); werror("Pike comes with ABSOLUTELY NO WARRANTY; This is free software and you are\n");
werror("welcome to redistribute it under certain conditions; Read the files\n"); werror("welcome to redistribute it under certain conditions; Read the files\n");
werror("COPYING and DISCLAIMER in the Pike distribution for more details.\n"); werror("COPYING and DISCLAIMER in the Pike distribution for more details.\n");
exit(0); exit(0);
} case "ignore":
destruct(tmp);
for(i=1;i<sizeof(argv);i++)
if(sizeof(argv[i]) && argv[i][0]!='-')
break; break;
}
}
argv=argv[i..]; argv=tmp->get_args(argv,1)[1..];
destruct(tmp);
if(!sizeof(argv)) if(!sizeof(argv))
{ {
...@@ -373,3 +378,4 @@ string describe_backtrace(mixed *trace) ...@@ -373,3 +378,4 @@ string describe_backtrace(mixed *trace)
return ret; return ret;
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment