mirror of https://github.com/mpv-player/mpv
multifile support in config parser
git-svn-id: svn://svn.mplayerhq.hu/mplayer/trunk@1630 b3059339-0415-0410-9bf9-f77b7e298cf2
This commit is contained in:
parent
408f919293
commit
4f2a70c85c
32
cfgparser.c
32
cfgparser.c
|
@ -431,10 +431,11 @@ out:
|
|||
return ret;
|
||||
}
|
||||
|
||||
int parse_command_line(struct config *conf, int argc, char **argv, char **envp, char **filename)
|
||||
int parse_command_line(struct config *conf, int argc, char **argv, char **envp, char ***filenames)
|
||||
{
|
||||
int i;
|
||||
int found_filename = 0;
|
||||
char **f = NULL;
|
||||
int f_nr = 0;
|
||||
int tmp;
|
||||
char *opt;
|
||||
|
||||
|
@ -452,13 +453,8 @@ int parse_command_line(struct config *conf, int argc, char **argv, char **envp,
|
|||
|
||||
for (i = 1; i < argc; i++) {
|
||||
opt = argv[i];
|
||||
if (*opt != '-') {
|
||||
if (found_filename) {
|
||||
printf("invalid option:\n");
|
||||
goto err_out;
|
||||
}
|
||||
if (*opt != '-')
|
||||
goto filename;
|
||||
}
|
||||
|
||||
/* remove trailing '-' */
|
||||
opt++;
|
||||
|
@ -467,14 +463,12 @@ int parse_command_line(struct config *conf, int argc, char **argv, char **envp,
|
|||
|
||||
switch (tmp) {
|
||||
case ERR_NOT_AN_OPTION:
|
||||
/* opt is not an option -> treat it as a filename */
|
||||
if (found_filename) {
|
||||
/* we already have a filename */
|
||||
goto err_out;
|
||||
}
|
||||
filename:
|
||||
found_filename = 1;
|
||||
*filename = argv[i];
|
||||
/* opt is not an option -> treat it as a filename */
|
||||
if (!(f = (char **) realloc(f, sizeof(*f) * (f_nr + 2))))
|
||||
goto err_out_mem;
|
||||
|
||||
f[f_nr++] = argv[i];
|
||||
break;
|
||||
case ERR_MISSING_PARAM:
|
||||
case ERR_OUT_OF_RANGE:
|
||||
|
@ -485,8 +479,14 @@ filename:
|
|||
i += tmp;
|
||||
}
|
||||
}
|
||||
if (f)
|
||||
f[f_nr] = NULL;
|
||||
if (filenames)
|
||||
*filenames = f;
|
||||
--recursion_depth;
|
||||
return found_filename;
|
||||
return f_nr; //filenames_nr;
|
||||
err_out_mem:
|
||||
printf("can't allocate memory for filenames\n");
|
||||
err_out:
|
||||
--recursion_depth;
|
||||
printf("command line: %s\n", argv[i]);
|
||||
|
|
|
@ -47,11 +47,11 @@ typedef int (*cfg_func_t)(struct config *);
|
|||
*/
|
||||
int parse_config_file(struct config *conf, char *conffile);
|
||||
|
||||
/* parse_command_line reutrns:
|
||||
/* parse_command_line returns:
|
||||
* -1 on error (invalid option...)
|
||||
* 0 if there was no filename on command line
|
||||
* 1 if it found a filename
|
||||
* >=1 if there were filenames
|
||||
*/
|
||||
int parse_command_line(struct config *conf, int argc, char **argv, char **envp, char **filename);
|
||||
int parse_command_line(struct config *conf, int argc, char **argv, char **envp, char ***filenames);
|
||||
|
||||
#endif /* __CONFIG_H */
|
||||
|
|
10
mplayer.c
10
mplayer.c
|
@ -424,6 +424,11 @@ static demux_stream_t *d_dvdsub=NULL;
|
|||
static sh_audio_t *sh_audio=NULL;
|
||||
static sh_video_t *sh_video=NULL;
|
||||
|
||||
// for multifile support:
|
||||
char **filenames=NULL;
|
||||
int num_filenames=0;
|
||||
int curr_filename=0;
|
||||
|
||||
char* filename=NULL; //"MI2-Trailer.avi";
|
||||
stream_t* stream=NULL;
|
||||
int file_format=DEMUXER_TYPE_UNKNOWN;
|
||||
|
@ -460,7 +465,10 @@ int use_stdin=0; //int f; // filedes
|
|||
{
|
||||
#endif
|
||||
parse_cfgfiles();
|
||||
if (parse_command_line(conf, argc, argv, envp, &filename) < 0) exit(1);
|
||||
if ((num_filenames=parse_command_line(conf, argc, argv, envp, &filenames)) < 0) exit(1);
|
||||
printf("XXX num_filenames: %d\n",num_filenames);
|
||||
curr_filename=0;
|
||||
filename=(num_filenames>0)?filenames[curr_filename]:NULL;
|
||||
|
||||
mp_msg_init(verbose+MSGL_STATUS);
|
||||
|
||||
|
|
Loading…
Reference in New Issue