Mercurial > mplayer.hg
changeset 1629:13aeaa05ac5e
multifile support in config parser
author | arpi |
---|---|
date | Wed, 22 Aug 2001 19:29:47 +0000 |
parents | bd1ef18cdf33 |
children | 919d085c3205 |
files | cfgparser.c cfgparser.h mplayer.c |
diffstat | 3 files changed, 28 insertions(+), 20 deletions(-) [+] |
line wrap: on
line diff
--- a/cfgparser.c Wed Aug 22 19:03:15 2001 +0000 +++ b/cfgparser.c Wed Aug 22 19:29:47 2001 +0000 @@ -431,10 +431,11 @@ 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 @@ 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 @@ switch (tmp) { case ERR_NOT_AN_OPTION: +filename: /* 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]; + 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 @@ 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]);
--- a/cfgparser.h Wed Aug 22 19:03:15 2001 +0000 +++ b/cfgparser.h Wed Aug 22 19:29:47 2001 +0000 @@ -47,11 +47,11 @@ */ 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 */
--- a/mplayer.c Wed Aug 22 19:03:15 2001 +0000 +++ b/mplayer.c Wed Aug 22 19:29:47 2001 +0000 @@ -424,6 +424,11 @@ 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 @@ { #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);