Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
V
vlc-gpu
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Redmine
Redmine
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
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
videolan
vlc-gpu
Commits
de31f430
Commit
de31f430
authored
Mar 29, 2010
by
Rémi Denis-Courmont
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
getopt: use stack instead of global variables, fixes #3366
parent
8c390d9b
Changes
5
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
140 additions
and
160 deletions
+140
-160
src/config/cmdline.c
src/config/cmdline.c
+18
-16
src/config/configuration.h
src/config/configuration.h
+1
-1
src/config/getopt.c
src/config/getopt.c
+90
-131
src/config/vlc_getopt.h
src/config/vlc_getopt.h
+28
-7
src/libvlc.c
src/libvlc.c
+3
-5
No files found.
src/config/cmdline.c
View file @
de31f430
...
...
@@ -49,19 +49,18 @@
* @param p_this object to write command line options as variables to
* @param i_argc number of command line arguments
* @param ppsz_args commandl ine arguments [IN/OUT]
* @param b_ignore_errors whether to ignore parsing errors
* @param pindex NULL to ignore unknown options,
* otherwise index of the first non-option argument [OUT]
* @return 0 on success, -1 on error.
*
* @warning This function is not re-entrant (because of getopt_long()).
* It must be called with the module bank initialization global lock held.
*/
int
config_LoadCmdLine
(
vlc_object_t
*
p_this
,
int
i_argc
,
const
char
*
ppsz_argv
[],
bool
b_ignore_errors
)
const
char
*
ppsz_argv
[],
int
*
pindex
)
{
int
i_cmd
,
i_index
,
i_opts
,
i_shortopts
,
flag
,
i_verbose
=
0
;
module_t
*
p_parser
;
struct
vlc_option
*
p_longopts
;
const
char
**
argv_copy
=
NULL
;
#define b_ignore_errors (pindex == NULL)
/* Short options */
module_config_t
*
pp_shortopts
[
256
];
...
...
@@ -200,10 +199,11 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
/*
* Parse the command line options
*/
vlc_optind
=
0
;
/* set to 0 to tell GNU getopt to reinitialize */
vlc_getopt_t
state
;
state
.
optind
=
0
;
/* set to 0 to tell GNU getopt to reinitialize */
while
(
(
i_cmd
=
vlc_getopt_long
(
i_argc
,
(
char
**
)
ppsz_argv
,
psz_shortopts
,
p_longopts
,
&
i_index
)
)
!=
-
1
)
p_longopts
,
&
i_index
,
&
state
)
)
!=
-
1
)
{
/* A long option has been recognized */
if
(
i_cmd
==
0
)
...
...
@@ -252,21 +252,21 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
case
CONFIG_ITEM_MODULE_LIST_CAT
:
case
CONFIG_ITEM_MODULE_CAT
:
var_Create
(
p_this
,
psz_name
,
VLC_VAR_STRING
);
var_SetString
(
p_this
,
psz_name
,
vlc_
optarg
);
var_SetString
(
p_this
,
psz_name
,
state
.
optarg
);
break
;
case
CONFIG_ITEM_INTEGER
:
var_Create
(
p_this
,
psz_name
,
VLC_VAR_INTEGER
);
var_SetInteger
(
p_this
,
psz_name
,
strtol
(
vlc_
optarg
,
NULL
,
0
));
strtol
(
state
.
optarg
,
NULL
,
0
));
break
;
case
CONFIG_ITEM_FLOAT
:
var_Create
(
p_this
,
psz_name
,
VLC_VAR_FLOAT
);
var_SetFloat
(
p_this
,
psz_name
,
us_atof
(
vlc_
optarg
)
);
var_SetFloat
(
p_this
,
psz_name
,
us_atof
(
state
.
optarg
)
);
break
;
case
CONFIG_ITEM_KEY
:
var_Create
(
p_this
,
psz_name
,
VLC_VAR_INTEGER
);
var_SetInteger
(
p_this
,
psz_name
,
ConfigStringToKey
(
vlc_
optarg
)
);
ConfigStringToKey
(
state
.
optarg
)
);
break
;
case
CONFIG_ITEM_BOOL
:
var_Create
(
p_this
,
psz_name
,
VLC_VAR_BOOL
);
...
...
@@ -292,7 +292,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
case
CONFIG_ITEM_MODULE_LIST
:
case
CONFIG_ITEM_MODULE_LIST_CAT
:
var_Create
(
p_this
,
name
,
VLC_VAR_STRING
);
var_SetString
(
p_this
,
name
,
vlc_
optarg
);
var_SetString
(
p_this
,
name
,
state
.
optarg
);
break
;
case
CONFIG_ITEM_INTEGER
:
var_Create
(
p_this
,
name
,
VLC_VAR_INTEGER
);
...
...
@@ -304,7 +304,7 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
else
{
var_SetInteger
(
p_this
,
name
,
strtol
(
vlc_
optarg
,
NULL
,
0
)
);
strtol
(
state
.
optarg
,
NULL
,
0
)
);
}
break
;
case
CONFIG_ITEM_BOOL
:
...
...
@@ -321,13 +321,13 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
{
fputs
(
"vlc: unknown option"
" or missing mandatory argument "
,
stderr
);
if
(
vlc_
optopt
)
if
(
state
.
optopt
)
{
fprintf
(
stderr
,
"`-%c'
\n
"
,
vlc_
optopt
);
fprintf
(
stderr
,
"`-%c'
\n
"
,
state
.
optopt
);
}
else
{
fprintf
(
stderr
,
"`%s'
\n
"
,
ppsz_argv
[
vlc_
optind
-
1
]
);
fprintf
(
stderr
,
"`%s'
\n
"
,
ppsz_argv
[
state
.
optind
-
1
]
);
}
fputs
(
"Try `vlc --help' for more information.
\n
"
,
stderr
);
goto
out
;
...
...
@@ -335,6 +335,8 @@ int config_LoadCmdLine( vlc_object_t *p_this, int i_argc,
}
ret
=
0
;
if
(
pindex
!=
NULL
)
*
pindex
=
state
.
optind
;
out:
/* Free allocated resources */
for
(
i_index
=
0
;
p_longopts
[
i_index
].
name
;
i_index
++
)
...
...
src/config/configuration.h
View file @
de31f430
...
...
@@ -36,7 +36,7 @@ int config_AutoSaveConfigFile( vlc_object_t * );
void
config_Free
(
module_t
*
);
int
config_LoadCmdLine
(
vlc_object_t
*
,
int
,
const
char
*
[],
bool
);
int
config_LoadCmdLine
(
vlc_object_t
*
,
int
,
const
char
*
[],
int
*
);
int
config_LoadConfigFile
(
vlc_object_t
*
,
const
char
*
);
#define config_LoadCmdLine(a,b,c,d) config_LoadCmdLine(VLC_OBJECT(a),b,c,d)
#define config_LoadConfigFile(a,b) config_LoadConfigFile(VLC_OBJECT(a),b)
...
...
src/config/getopt.c
View file @
de31f430
This diff is collapsed.
Click to expand it.
src/config/vlc_getopt.h
View file @
de31f430
...
...
@@ -22,13 +22,13 @@
#ifndef VLC_GETOPT_H
#define VLC_GETOPT_H 1
typedef
struct
vlc_getopt_s
{
/* For communication from `getopt' to the caller.
When `getopt' finds an option that takes an argument,
the argument value is returned here.
Also, when `ordering' is RETURN_IN_ORDER,
each non-option ARGV-element is returned here. */
the argument value is returned here. */
extern
char
*
vlc_
optarg
;
char
*
optarg
;
/* Index in ARGV of the next element to be scanned.
This is used for communication to and from the caller
...
...
@@ -42,11 +42,31 @@ extern char *vlc_optarg;
Otherwise, `optind' communicates from one call to the next
how much of ARGV has been scanned so far. */
extern
int
vlc_
optind
;
int
optind
;
/* Set to an option character which was unrecognized. */
extern
int
vlc_optopt
;
int
optopt
;
/* The next char to be scanned in the option-element
in which the last option character we returned was found.
This allows us to pick up the scan where we left off.
If this is zero, or a null string, it means resume the scan
by advancing to the next ARGV-element. */
char
*
nextchar
;
/* Handle permutation of arguments. */
/* Describe the part of ARGV that contains non-options that have
been skipped. `first_nonopt' is the index in ARGV of the first of them;
`last_nonopt' is the index after the last of them. */
int
first_nonopt
;
int
last_nonopt
;
}
vlc_getopt_t
;
/* Describe the long-named options requested by the application.
The LONG_OPTIONS argument to getopt_long or getopt_long_only is a vector
...
...
@@ -77,6 +97,7 @@ struct vlc_option
};
extern
int
vlc_getopt_long
(
int
argc
,
char
*
const
*
argv
,
const
char
*
shortopts
,
const
struct
vlc_option
*
longopts
,
int
*
longind
);
const
struct
vlc_option
*
longopts
,
int
*
longind
,
vlc_getopt_t
*
restrict
state
);
#endif
/* VLC_GETOPT_H */
src/libvlc.c
View file @
de31f430
...
...
@@ -321,7 +321,7 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
* options) */
module_InitBank
(
p_libvlc
);
if
(
config_LoadCmdLine
(
p_libvlc
,
i_argc
,
ppsz_argv
,
true
)
)
if
(
config_LoadCmdLine
(
p_libvlc
,
i_argc
,
ppsz_argv
,
NULL
)
)
{
module_EndBank
(
p_libvlc
,
false
);
return
VLC_EGENERIC
;
...
...
@@ -534,10 +534,8 @@ int libvlc_InternalInit( libvlc_int_t *p_libvlc, int i_argc,
/*
* Override configuration with command line settings
*/
/* config_LoadCmdLine(), DBus (below) and Win32-specific use vlc_optind,
* vlc_optarg and vlc_optopt globals. This is not thread-safe!! */
#warning BUG!
if
(
config_LoadCmdLine
(
p_libvlc
,
i_argc
,
ppsz_argv
,
false
)
)
int
vlc_optind
;
if
(
config_LoadCmdLine
(
p_libvlc
,
i_argc
,
ppsz_argv
,
&
vlc_optind
)
)
{
#ifdef WIN32
ShowConsole
(
false
);
...
...
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