Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
M
MariaDB
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
nexedi
MariaDB
Commits
cd8c55c1
Commit
cd8c55c1
authored
Jun 09, 2002
by
unknown
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some enhancements in my_getopt. Made code more readable and better
optimized in some places.
parent
474f8070
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
29 additions
and
24 deletions
+29
-24
mysys/my_getopt.c
mysys/my_getopt.c
+29
-24
No files found.
mysys/my_getopt.c
View file @
cd8c55c1
...
@@ -34,18 +34,24 @@ static void init_variables(const struct my_option *options);
...
@@ -34,18 +34,24 @@ static void init_variables(const struct my_option *options);
static
int
setval
(
const
struct
my_option
*
opts
,
char
*
argument
,
static
int
setval
(
const
struct
my_option
*
opts
,
char
*
argument
,
my_bool
set_maximum_value
);
my_bool
set_maximum_value
);
#define DISABLE_OPTION_COUNT 2
/* currently 'skip' and 'disable' below */
/*
The following three variables belong to same group and the number and
/* 'disable'-option prefixes must be in the beginning, DISABLE_OPTION_COUNT
order of their arguments must correspond to each other.
is the number of disabling prefixes
*/
*/
static
const
char
*
special_opt_prefix
[]
=
static
const
char
*
special_opt_prefix
[]
=
{
"skip"
,
"disable"
,
"enable"
,
"maximum"
,
"loose"
,
0
};
{
"skip"
,
"disable"
,
"enable"
,
"maximum"
,
"loose"
,
0
};
static
const
uint
special_opt_prefix_lengths
[]
=
{
4
,
7
,
6
,
7
,
5
,
0
};
enum
enum_special_opt
{
OPT_SKIP
,
OPT_DISABLE
,
OPT_ENABLE
,
OPT_MAXIMUM
,
OPT_LOOSE
};
char
*
disabled_my_option
=
(
char
*
)
"0"
;
char
*
disabled_my_option
=
(
char
*
)
"0"
;
/* This is a flag that can be set in client programs. 0 means that
/*
This is a flag that can be set in client programs. 0 means that
my_getopt will not print error messages, but the client should do
my_getopt will not print error messages, but the client should do
it by itself */
it by itself
*/
my_bool
my_getopt_print_errors
=
1
;
my_bool
my_getopt_print_errors
=
1
;
...
@@ -66,7 +72,7 @@ int handle_options(int *argc, char ***argv,
...
@@ -66,7 +72,7 @@ int handle_options(int *argc, char ***argv,
const
struct
my_option
*
,
const
struct
my_option
*
,
char
*
))
char
*
))
{
{
uint
opt_found
,
argvpos
=
0
,
length
,
spec_len
,
i
;
uint
opt_found
,
argvpos
=
0
,
length
,
i
;
my_bool
end_of_options
=
0
,
must_be_var
,
set_maximum_value
,
special_used
,
my_bool
end_of_options
=
0
,
must_be_var
,
set_maximum_value
,
special_used
,
option_is_loose
,
option_used
=
0
;
option_is_loose
,
option_used
=
0
;
char
*
progname
=
*
(
*
argv
),
**
pos
,
*
optend
,
*
prev_found
;
char
*
progname
=
*
(
*
argv
),
**
pos
,
*
optend
,
*
prev_found
;
...
@@ -111,15 +117,9 @@ int handle_options(int *argc, char ***argv,
...
@@ -111,15 +117,9 @@ int handle_options(int *argc, char ***argv,
(
*
argc
)
--
;
(
*
argc
)
--
;
}
}
}
}
else
if
(
!
compare_strings
(
cur_arg
,
"-set-variable"
,
13
)
||
else
if
(
!
compare_strings
(
cur_arg
,
"-set-variable"
,
13
))
!
compare_strings
(
cur_arg
,
"-loose-set-variable"
,
19
))
{
{
must_be_var
=
1
;
must_be_var
=
1
;
if
(
cur_arg
[
1
]
==
'l'
)
{
option_is_loose
=
1
;
cur_arg
+=
6
;
}
if
(
cur_arg
[
13
]
==
'='
)
if
(
cur_arg
[
13
]
==
'='
)
{
{
cur_arg
+=
14
;
cur_arg
+=
14
;
...
@@ -183,18 +183,19 @@ int handle_options(int *argc, char ***argv,
...
@@ -183,18 +183,19 @@ int handle_options(int *argc, char ***argv,
must_be_var
=
1
;
/* option is followed by an argument */
must_be_var
=
1
;
/* option is followed by an argument */
for
(
i
=
0
;
special_opt_prefix
[
i
];
i
++
)
for
(
i
=
0
;
special_opt_prefix
[
i
];
i
++
)
{
{
spec_len
=
strlen
(
special_opt_prefix
[
i
]);
if
(
!
compare_strings
(
special_opt_prefix
[
i
],
cur_arg
,
if
(
!
compare_strings
(
special_opt_prefix
[
i
],
cur_arg
,
spec_len
)
&&
special_opt_prefix_lengths
[
i
]
)
&&
cur_arg
[
spec
_len
]
==
'-'
)
cur_arg
[
spec
ial_opt_prefix_lengths
[
i
]
]
==
'-'
)
{
{
/*
/*
We were called with a special prefix, we can reuse opt_found
We were called with a special prefix, we can reuse opt_found
*/
*/
special_used
=
1
;
special_used
=
1
;
cur_arg
+=
(
spec
_len
+
1
);
cur_arg
+=
(
spec
ial_opt_prefix_lengths
[
i
]
+
1
);
if
(
!
compare_strings
(
special_opt_prefix
[
i
],
"loose"
,
5
)
)
if
(
i
==
OPT_LOOSE
)
option_is_loose
=
1
;
option_is_loose
=
1
;
if
((
opt_found
=
findopt
(
cur_arg
,
length
-
(
spec_len
+
1
),
if
((
opt_found
=
findopt
(
cur_arg
,
length
-
(
special_opt_prefix_lengths
[
i
]
+
1
),
&
optp
,
&
prev_found
)))
&
optp
,
&
prev_found
)))
{
{
if
(
opt_found
>
1
)
if
(
opt_found
>
1
)
...
@@ -206,14 +207,18 @@ int handle_options(int *argc, char ***argv,
...
@@ -206,14 +207,18 @@ int handle_options(int *argc, char ***argv,
special_opt_prefix
[
i
],
prev_found
);
special_opt_prefix
[
i
],
prev_found
);
return
EXIT_AMBIGUOUS_OPTION
;
return
EXIT_AMBIGUOUS_OPTION
;
}
}
if
(
i
<
DISABLE_OPTION_COUNT
)
switch
(
i
)
{
case
OPT_SKIP
:
case
OPT_DISABLE
:
/* fall through */
optend
=
disabled_my_option
;
optend
=
disabled_my_option
;
else
if
(
!
compare_strings
(
special_opt_prefix
[
i
],
"enable"
,
6
))
break
;
case
OPT_ENABLE
:
optend
=
(
char
*
)
"1"
;
optend
=
(
char
*
)
"1"
;
else
if
(
!
compare_strings
(
special_opt_prefix
[
i
],
"maximum"
,
7
))
break
;
{
case
OPT_MAXIMUM
:
set_maximum_value
=
1
;
set_maximum_value
=
1
;
must_be_var
=
1
;
must_be_var
=
1
;
break
;
}
}
break
;
/* break from the inner loop, main loop continues */
break
;
/* break from the inner loop, main loop continues */
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment