2006-04-25 03:26:10 +02:00
|
|
|
|
|
|
|
/// \file
|
|
|
|
/// \ingroup ConfigParsers Playtree
|
|
|
|
|
2002-11-12 02:56:42 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <errno.h>
|
|
|
|
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
#include <assert.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#include "mp_msg.h"
|
|
|
|
#include "m_option.h"
|
|
|
|
#include "m_config.h"
|
|
|
|
#include "playtree.h"
|
|
|
|
|
|
|
|
static int recursion_depth = 0;
|
|
|
|
static int mode = 0;
|
|
|
|
|
|
|
|
#define GLOBAL 0
|
|
|
|
#define LOCAL 1
|
|
|
|
#define DROP_LOCAL 2
|
|
|
|
|
2004-06-07 20:58:08 +02:00
|
|
|
#define dvd_range(a) (a>0 && a<256)
|
2002-11-12 02:56:42 +01:00
|
|
|
#define UNSET_GLOBAL (mode = LOCAL)
|
|
|
|
// Use this 1 if you want to have only global option (no per file option)
|
|
|
|
// #define UNSET_GLOBAL (mode = GLOBAL)
|
|
|
|
|
|
|
|
|
|
|
|
static int is_entry_option(char *opt, char *param, play_tree_t** ret) {
|
|
|
|
play_tree_t* entry = NULL;
|
|
|
|
|
|
|
|
*ret = NULL;
|
|
|
|
|
|
|
|
if(strcasecmp(opt,"playlist") == 0) { // We handle playlist here
|
|
|
|
if(!param)
|
|
|
|
return M_OPT_MISSING_PARAM;
|
2004-04-24 15:15:31 +02:00
|
|
|
|
2002-11-12 02:56:42 +01:00
|
|
|
entry = parse_playlist_file(param);
|
|
|
|
if(!entry)
|
2004-04-24 15:15:31 +02:00
|
|
|
return -1;
|
|
|
|
else {
|
|
|
|
*ret=entry;
|
|
|
|
return 1;
|
|
|
|
}
|
2002-11-12 02:56:42 +01:00
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2003-08-08 22:07:38 +02:00
|
|
|
static inline void add_entry(play_tree_t **last_parentp,
|
|
|
|
play_tree_t **last_entryp, play_tree_t *entry) {
|
|
|
|
if(*last_entryp == NULL)
|
|
|
|
play_tree_set_child(*last_parentp,entry);
|
2003-08-03 19:42:43 +02:00
|
|
|
else
|
2003-08-08 22:07:38 +02:00
|
|
|
play_tree_append_entry(*last_entryp,entry);
|
|
|
|
*last_entryp = entry;
|
2003-08-03 19:42:43 +02:00
|
|
|
}
|
|
|
|
|
2006-04-25 03:26:10 +02:00
|
|
|
/// Setup the \ref Config from command line arguments and build a playtree.
|
|
|
|
/** \ingroup ConfigParsers
|
|
|
|
*/
|
2002-11-12 02:56:42 +01:00
|
|
|
play_tree_t*
|
|
|
|
m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv)
|
|
|
|
{
|
2004-06-07 20:58:08 +02:00
|
|
|
int i,j,start_title=-1,end_title=-1;
|
|
|
|
char *opt,*splitpos=NULL;
|
|
|
|
char entbuf[10];
|
2002-11-12 02:56:42 +01:00
|
|
|
int no_more_opts = 0;
|
2005-09-02 10:29:30 +02:00
|
|
|
int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything
|
2002-11-12 02:56:42 +01:00
|
|
|
play_tree_t *last_parent, *last_entry = NULL, *root;
|
2004-11-10 17:43:40 +01:00
|
|
|
#ifdef MACOSX_FINDER_SUPPORT
|
|
|
|
extern play_tree_t *macosx_finder_args(m_config_t *, int , char **);
|
|
|
|
#endif
|
2002-11-12 02:56:42 +01:00
|
|
|
|
|
|
|
#ifdef MP_DEBUG
|
|
|
|
assert(config != NULL);
|
|
|
|
assert(argv != NULL);
|
|
|
|
assert(argc >= 1);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
config->mode = M_COMMAND_LINE;
|
|
|
|
mode = GLOBAL;
|
2004-11-10 17:43:40 +01:00
|
|
|
#ifdef MACOSX_FINDER_SUPPORT
|
|
|
|
root=macosx_finder_args(config, argc, argv);
|
|
|
|
if(root)
|
|
|
|
return root;
|
|
|
|
#endif
|
|
|
|
|
2002-11-12 02:56:42 +01:00
|
|
|
last_parent = root = play_tree_new();
|
|
|
|
/* in order to work recursion detection properly in parse_config_file */
|
|
|
|
++recursion_depth;
|
|
|
|
|
|
|
|
for (i = 1; i < argc; i++) {
|
|
|
|
//next:
|
|
|
|
opt = argv[i];
|
|
|
|
/* check for -- (no more options id.) except --help! */
|
2005-04-23 22:41:19 +02:00
|
|
|
if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0))
|
2002-11-12 02:56:42 +01:00
|
|
|
{
|
|
|
|
no_more_opts = 1;
|
|
|
|
if (i+1 >= argc)
|
|
|
|
{
|
2005-01-19 19:24:53 +01:00
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "'--' indicates no more options, but no filename was given on the command line.\n");
|
2002-11-12 02:56:42 +01:00
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
if((opt[0] == '{') && (opt[1] == '\0'))
|
|
|
|
{
|
|
|
|
play_tree_t* entry = play_tree_new();
|
|
|
|
UNSET_GLOBAL;
|
2002-11-13 00:41:32 +01:00
|
|
|
if(last_parent->flags & PLAY_TREE_RND)
|
|
|
|
entry->flags |= PLAY_TREE_RND;
|
2002-11-12 02:56:42 +01:00
|
|
|
if(last_entry == NULL) {
|
|
|
|
play_tree_set_child(last_parent,entry);
|
|
|
|
} else {
|
|
|
|
play_tree_append_entry(last_entry,entry);
|
|
|
|
last_entry = NULL;
|
|
|
|
}
|
|
|
|
last_parent = entry;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if((opt[0] == '}') && (opt[1] == '\0'))
|
|
|
|
{
|
|
|
|
if( ! last_parent || ! last_parent->parent) {
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "too much }-\n");
|
|
|
|
goto err_out;
|
|
|
|
}
|
|
|
|
last_entry = last_parent;
|
|
|
|
last_parent = last_entry->parent;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
|
|
|
|
{
|
2004-11-14 12:09:56 +01:00
|
|
|
int tmp = 0;
|
2002-11-12 02:56:42 +01:00
|
|
|
/* remove trailing '-' */
|
|
|
|
opt++;
|
|
|
|
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt);
|
|
|
|
// We handle here some specific option
|
2006-01-24 12:34:24 +01:00
|
|
|
// Loop option when it apply to a group
|
|
|
|
if(strcasecmp(opt,"loop") == 0 &&
|
2002-11-12 02:56:42 +01:00
|
|
|
(! last_entry || last_entry->child) ) {
|
|
|
|
int l;
|
2006-04-14 23:51:45 +02:00
|
|
|
char* end = NULL;
|
2002-12-07 21:59:33 +01:00
|
|
|
l = (i+1<argc) ? strtol(argv[i+1],&end,0) : 0;
|
2006-04-14 23:51:45 +02:00
|
|
|
if(!end || *end != '\0') {
|
2003-01-26 17:11:35 +01:00
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "The loop option must be an integer: %s\n",argv[i+1]);
|
2002-11-12 02:56:42 +01:00
|
|
|
tmp = ERR_OUT_OF_RANGE;
|
2003-01-26 17:11:35 +01:00
|
|
|
} else {
|
2002-11-12 02:56:42 +01:00
|
|
|
play_tree_t* pt = last_entry ? last_entry : last_parent;
|
|
|
|
l = l <= 0 ? -1 : l;
|
|
|
|
pt->loop = l;
|
|
|
|
tmp = 1;
|
|
|
|
}
|
2002-12-15 05:47:32 +01:00
|
|
|
} else if(strcasecmp(opt,"shuffle") == 0) {
|
2002-11-13 00:41:32 +01:00
|
|
|
if(last_entry && last_entry->child)
|
|
|
|
last_entry->flags |= PLAY_TREE_RND;
|
|
|
|
else
|
|
|
|
last_parent->flags |= PLAY_TREE_RND;
|
2002-12-15 05:47:32 +01:00
|
|
|
} else if(strcasecmp(opt,"noshuffle") == 0) {
|
2002-11-13 00:41:32 +01:00
|
|
|
if(last_entry && last_entry->child)
|
|
|
|
last_entry->flags &= ~PLAY_TREE_RND;
|
|
|
|
else
|
|
|
|
last_parent->flags &= ~PLAY_TREE_RND;
|
2002-11-12 02:56:42 +01:00
|
|
|
} else {
|
|
|
|
m_option_t* mp_opt = NULL;
|
|
|
|
play_tree_t* entry = NULL;
|
|
|
|
|
2002-12-15 18:05:35 +01:00
|
|
|
tmp = is_entry_option(opt,(i+1<argc) ? argv[i + 1] : NULL,&entry);
|
2002-11-12 02:56:42 +01:00
|
|
|
if(tmp > 0) { // It's an entry
|
|
|
|
if(entry) {
|
2003-08-08 22:07:38 +02:00
|
|
|
add_entry(&last_parent,&last_entry,entry);
|
2002-11-13 00:41:32 +01:00
|
|
|
if((last_parent->flags & PLAY_TREE_RND) && entry->child)
|
|
|
|
entry->flags |= PLAY_TREE_RND;
|
2002-11-12 02:56:42 +01:00
|
|
|
UNSET_GLOBAL;
|
|
|
|
} else if(mode == LOCAL) // Entry is empty we have to drop his params
|
|
|
|
mode = DROP_LOCAL;
|
|
|
|
} else if(tmp == 0) { // 'normal' options
|
|
|
|
mp_opt = m_config_get_option(config,opt);
|
|
|
|
if (mp_opt != NULL) { // Option exist
|
|
|
|
if(mode == GLOBAL || (mp_opt->flags & M_OPT_GLOBAL))
|
2002-12-11 21:56:37 +01:00
|
|
|
tmp = (i+1<argc) ? m_config_set_option(config, opt, argv[i + 1])
|
|
|
|
: m_config_set_option(config, opt, NULL);
|
2002-11-12 02:56:42 +01:00
|
|
|
else {
|
2002-12-15 18:05:35 +01:00
|
|
|
tmp = m_config_check_option(config, opt, (i+1<argc) ? argv[i + 1] : NULL);
|
2002-11-12 02:56:42 +01:00
|
|
|
if(tmp >= 0 && mode != DROP_LOCAL) {
|
|
|
|
play_tree_t* pt = last_entry ? last_entry : last_parent;
|
|
|
|
play_tree_set_param(pt,opt, argv[i + 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2003-08-13 18:45:02 +02:00
|
|
|
tmp = M_OPT_UNKNOWN;
|
2005-06-17 10:11:56 +02:00
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR, "Unknown option on the command line: -%s\n",opt);
|
2002-11-12 02:56:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-02 10:29:30 +02:00
|
|
|
if (tmp <= M_OPT_EXIT) {
|
|
|
|
opt_exit = 1;
|
|
|
|
tmp = M_OPT_EXIT - tmp;
|
|
|
|
} else
|
2003-04-02 18:13:16 +02:00
|
|
|
if (tmp < 0) {
|
2006-04-22 23:30:34 +02:00
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_FATAL, "Error parsing option on the command line: -%s\n",opt);
|
2002-11-12 02:56:42 +01:00
|
|
|
goto err_out;
|
2003-04-02 18:13:16 +02:00
|
|
|
}
|
2002-11-12 02:56:42 +01:00
|
|
|
i += tmp;
|
|
|
|
}
|
|
|
|
else /* filename */
|
|
|
|
{
|
|
|
|
play_tree_t* entry = play_tree_new();
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]);
|
2004-06-07 20:58:08 +02:00
|
|
|
// if required expand DVD filename entries like dvd://1-3 into component titles
|
|
|
|
if ( strstr(argv[i],"dvd://") != NULL )
|
|
|
|
{
|
|
|
|
splitpos=strstr(argv[i]+6,"-");
|
|
|
|
if(splitpos != NULL)
|
|
|
|
{
|
|
|
|
start_title=strtol(argv[i]+6,NULL,10);
|
|
|
|
if (start_title<0) { //entries like dvd://-2 start title implied 1
|
|
|
|
end_title=abs(start_title);
|
|
|
|
start_title=1;
|
|
|
|
} else {
|
|
|
|
end_title=strtol(splitpos+1,NULL,10);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (dvd_range(start_title) && dvd_range(end_title) && (start_title<end_title))
|
|
|
|
{
|
|
|
|
for (j=start_title;j<=end_title;j++)
|
|
|
|
{
|
|
|
|
if (j!=start_title)
|
|
|
|
entry=play_tree_new();
|
|
|
|
snprintf(entbuf,9,"dvd://%d",j);
|
|
|
|
play_tree_add_file(entry,entbuf);
|
|
|
|
add_entry(&last_parent,&last_entry,entry);
|
|
|
|
last_entry = entry;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Invalid play entry %s\n",argv[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
} else { // dvd:// or dvd://x entry
|
|
|
|
play_tree_add_file(entry,argv[i]);
|
|
|
|
}
|
|
|
|
} else {
|
2002-11-12 02:56:42 +01:00
|
|
|
play_tree_add_file(entry,argv[i]);
|
2004-06-07 20:58:08 +02:00
|
|
|
}
|
|
|
|
|
2002-11-12 02:56:42 +01:00
|
|
|
// Lock stdin if it will be used as input
|
|
|
|
if(strcasecmp(argv[i],"-") == 0)
|
2004-07-14 11:27:04 +02:00
|
|
|
m_config_set_option(config,"noconsolecontrols",NULL);
|
2003-08-08 22:07:38 +02:00
|
|
|
add_entry(&last_parent,&last_entry,entry);
|
2002-11-12 02:56:42 +01:00
|
|
|
UNSET_GLOBAL; // We start entry specific options
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-09-02 10:29:30 +02:00
|
|
|
if (opt_exit)
|
|
|
|
goto err_out;
|
2002-11-12 02:56:42 +01:00
|
|
|
--recursion_depth;
|
|
|
|
if(last_parent != root)
|
|
|
|
mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n");
|
|
|
|
return root;
|
|
|
|
|
|
|
|
err_out:
|
|
|
|
--recursion_depth;
|
|
|
|
play_tree_free(root,1);
|
|
|
|
return NULL;
|
|
|
|
}
|