Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
pike
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
pikelang
pike
Commits
1a95de11
Commit
1a95de11
authored
27 years ago
by
Henrik (Grubba) Grubbström
Browse files
Options
Downloads
Patches
Plain Diff
Added optional extra argument "throw_errors" to all functions able to call exit().
Rev: lib/modules/Getopt.pmod:1.4
parent
29abe684
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/modules/Getopt.pmod
+56
-18
56 additions, 18 deletions
lib/modules/Getopt.pmod
with
56 additions
and
18 deletions
lib/modules/Getopt.pmod
+
56
−
18
View file @
1a95de11
...
@@ -12,7 +12,8 @@ string|int find_option(array argv,
...
@@ -12,7 +12,8 @@ string|int find_option(array argv,
array|string shortform,
array|string shortform,
array|string|void longform,
array|string|void longform,
array|string|void envvars,
array|string|void envvars,
mixed|void def)
mixed|void def,
int|void throw_errors)
{
{
mixed value;
mixed value;
int i,hasarg;
int i,hasarg;
...
@@ -46,8 +47,13 @@ string|int find_option(array argv,
...
@@ -46,8 +47,13 @@ string|int find_option(array argv,
{
{
if(i == sizeof(argv)-1)
if(i == sizeof(argv)-1)
{
{
werror("No argument to option "+tmp+".\n");
if (throw_errors) {
exit(1);
throw(({ "No argument to option "+tmp+".\n",
backtrace() }));
} else {
werror("No argument to option "+tmp+".\n");
exit(1);
}
}
}
value=argv[i+1];
value=argv[i+1];
argv[i+1]=0;
argv[i+1]=0;
...
@@ -74,9 +80,14 @@ string|int find_option(array argv,
...
@@ -74,9 +80,14 @@ string|int find_option(array argv,
{
{
if(i == sizeof(argv)-1)
if(i == sizeof(argv)-1)
{
{
werror("No argument to option -"+argv[i][j..j]+".\n");
if (throw_errors) {
exit(1);
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];
value=argv[i+1];
argv[i+1] = 0;
argv[i+1] = 0;
...
@@ -120,7 +131,8 @@ constant MAY_HAVE_ARG=3;
...
@@ -120,7 +131,8 @@ constant MAY_HAVE_ARG=3;
#define ENV 3
#define ENV 3
#define DEF 4
#define DEF 4
mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder)
mixed *find_all_options(string *argv, mixed *options,
void|int posix_me_harder, void|int throw_errors)
{
{
mapping quick=([]);
mapping quick=([]);
foreach(options, mixed opt)
foreach(options, mixed opt)
...
@@ -162,8 +174,13 @@ mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder)
...
@@ -162,8 +174,13 @@ mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder)
{
{
if(e==sizeof(argv)-1)
if(e==sizeof(argv)-1)
{
{
werror("No argument to option "+opt+".\n");
if (throw_errors) {
exit(1);
throw(({ "No argument to option "+opt+".\n",
backtrace() }));
} else {
werror("No argument to option "+opt+".\n");
exit(1);
}
}
}
arg=argv[e+1];
arg=argv[e+1];
argv[e+1]=0;
argv[e+1]=0;
...
@@ -187,8 +204,13 @@ mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder)
...
@@ -187,8 +204,13 @@ mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder)
{
{
if(e==sizeof(argv)-1)
if(e==sizeof(argv)-1)
{
{
werror("No argument to option "+opt+".\n");
if (throw_errors) {
exit(1);
throw(({ "No argument to option "+opt+".\n",
backtrace() }));
} else {
werror("No argument to option "+opt+".\n");
exit(1);
}
}
}
arg=argv[e+1];
arg=argv[e+1];
argv[e+1]=0;
argv[e+1]=0;
...
@@ -240,7 +262,7 @@ mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder)
...
@@ -240,7 +262,7 @@ mixed *find_all_options(string *argv, mixed *options, void|int posix_me_harder)
}
}
string *get_args(string *argv, void|int posix_me_harder)
string *get_args(string *argv, void|int posix_me_harder
, void|int throw_errors
)
{
{
int i;
int i;
for(i=1;i<sizeof(argv);i++)
for(i=1;i<sizeof(argv);i++)
...
@@ -254,14 +276,30 @@ string *get_args(string *argv, void|int posix_me_harder)
...
@@ -254,14 +276,30 @@ string *get_args(string *argv, void|int posix_me_harder)
argv[i]=0;
argv[i]=0;
break;
break;
}else{
}else{
werror("Unknown option "+argv[i]+".\n");
if (throw_errors) {
exit(1);
throw(({ "Unknown option "+argv[i]+".\n",
backtrace() }));
} else {
werror("Unknown option "+argv[i]+".\n");
exit(1);
}
}
}
}else{
}else{
if(strlen(argv[i]) == 2)
if(strlen(argv[i]) == 2) {
werror("Unknown option "+argv[i]+".\n");
if (throw_errors) {
else
throw(({ "Unknown option "+argv[i]+".\n",
werror("Unknown options "+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);
exit(1);
}
}
}else{
}else{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment