コード例 #1
0
void*
m_config_get_option_ptr(m_config_t *config, char* arg) {
  m_option_t* conf;

#ifdef MP_DEBUG
  assert(config != NULL);
  assert(arg != NULL);
#endif

  conf = m_config_get_option(config,arg);
  if(!conf) return NULL;
  return conf->p;
}
コード例 #2
0
ファイル: asxparser.c プロジェクト: BOTCrusher/sagetv
static void
asx_parse_param(ASX_Parser_t* parser, char** attribs, play_tree_t* pt) {
  char *name,*val;
  
  name = asx_get_attrib("NAME",attribs);
  if(!name) {
    asx_warning_attrib_required(parser,"PARAM" ,"NAME" );
    return;
  }
  val = asx_get_attrib("VALUE",attribs);
  if(m_config_get_option(mconfig,name) == NULL) {
    mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Found unknown param in asx: %s",name);
    if(val)
      mp_msg(MSGT_PLAYTREE,MSGL_WARN,"=%s\n",val);
    else
      mp_msg(MSGT_PLAYTREE,MSGL_WARN,"\n");
    return;
  }
  play_tree_set_param(pt,name,val);
  free(name);
  if(val) free(val);
}
コード例 #3
0
ファイル: asxparser.c プロジェクト: basinilya/mplayer
static void
asx_parse_param(ASX_Parser_t* parser, char** attribs, play_tree_t* pt) {
  char *name = NULL,*val = NULL;

  name = asx_get_attrib("NAME",attribs);
  if(!name) {
    asx_warning_attrib_required(parser,"PARAM" ,"NAME" );
    return;
  }
  val = asx_get_attrib("VALUE",attribs);
  if(m_config_get_option(mconfig,name) == NULL) {
    mp_msg(MSGT_PLAYTREE,MSGL_WARN,"Found unknown param in asx: %s",name);
    if(val)
      mp_msg(MSGT_PLAYTREE,MSGL_WARN,"=%s\n",val);
    else
      mp_msg(MSGT_PLAYTREE,MSGL_WARN,"\n");
    goto err_out;
  }
  mp_msg(MSGT_PLAYTREE, MSGL_ERR, "Support for specifying parameters in playlists has been disabled.\n");
//  play_tree_set_param(pt,name,val);
err_out:
  free(name);
  free(val);
}
コード例 #4
0
m_entry_t*
m_config_parse_me_command_line(m_config_t *config, int argc, char **argv)
{
  int i,nf = 0,no = 0;
  int tmp;
  char *opt;
  int no_more_opts = 0;
  int opt_exit = 0;
  m_entry_t *lst = NULL, *entry = NULL;

#ifdef MP_DEBUG
  assert(config != NULL);
  assert(argv != NULL);
  assert(argc >= 1);
#endif

  config->mode = M_COMMAND_LINE;

  lst = calloc(1,sizeof(m_entry_t));

  for (i = 1; i < argc; i++) {
    //next:
    opt = argv[i];
    /* check for -- (no more options id.) except --help! */
    if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0))
      {
	no_more_opts = 1;
	if (i+1 >= argc)
	  {
	    mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NoFileGivenOnCommandLine);
	    goto err_out;
	  }
	continue;
      }

    if ((no_more_opts == 0) && (*opt == '-') && (*(opt+1) != 0)) /* option */
      {
	const m_option_t* mp_opt = NULL;
	/* remove trailing '-' */
	opt++;
	mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt);
	mp_opt = m_config_get_option(config,opt);
	if(!mp_opt) {
	  tmp = M_OPT_UNKNOWN;
	  mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NotAnMEncoderOption, opt);
	  goto err_out;
	}
	if(!entry || (mp_opt->flags & M_OPT_GLOBAL)){
	  tmp = m_config_set_option(config, opt, argv[i + 1]);
	  if (tmp <= M_OPT_EXIT) {
	    opt_exit = 1;
	    tmp = M_OPT_EXIT - tmp;
	  }
	  else
	  if(tmp < 0){
//	    mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
	    mp_msg(MSGT_CFGPARSER, MSGL_FATAL, MSGTR_ErrorParsingOptionOnCommandLine, opt);
	    goto err_out;
	  }
	} else {
	  tmp = m_config_check_option(config, opt, argv[i + 1]);
	  if (tmp <= M_OPT_EXIT) {
	    opt_exit = 1;
	    tmp = M_OPT_EXIT - tmp;
	  }
	  if(tmp >= 0) {
	    entry->opts = realloc(entry->opts,(no+2)*2*sizeof(char*));
	    entry->opts[2*no] = strdup(opt);
	    entry->opts[2*no+1] = argv[i + 1] ? strdup(argv[i + 1]) : NULL;
	    entry->opts[2*no+2] =  entry->opts[2*no+3] = NULL;
	    no++;
	  } else {
//	    mp_msg(MSGT_CFGPARSER, MSGL_ERR, "m_config_set_option() failed (%d)\n",tmp);
	    goto err_out;
	  }
	}
	i += tmp;
      } else  {/* filename */
	mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]);
	lst = realloc(lst,(nf+2)*sizeof(m_entry_t));
	lst[nf].name = strdup(argv[i]);
	lst[nf].opts = calloc(2,sizeof(char*));
	entry = &lst[nf];
	no = 0;
	memset(&lst[nf+1],0,sizeof(m_entry_t));
	nf++;
      }
  }

  if (opt_exit)
    exit(0);
  if(nf == 0) {
    m_entry_list_free(lst);
    mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NoFileGiven);
    return NULL;
  }
  return lst;

 err_out:
   m_entry_list_free(lst);
  return NULL;
}
コード例 #5
0
/** \ingroup ConfigParsers
 */
play_tree_t*
m_config_parse_mp_command_line(m_config_t *config, int argc, char **argv)
{
  int i,j,start_title=-1,end_title=-1;
  char *opt,*splitpos=NULL;
  char entbuf[15];
  int no_more_opts = 0;
  int opt_exit = 0; // flag indicating whether mplayer should exit without playing anything
  play_tree_t *last_parent, *last_entry = NULL, *root;

#ifdef MP_DEBUG
  assert(config != NULL);
  assert(argv != NULL);
  assert(argc >= 1);
#endif

  config->mode = M_COMMAND_LINE;
  mode = GLOBAL;
#ifdef CONFIG_MACOSX_FINDER
  root=macosx_finder_args(config, argc, argv);
  if(root)
  	return root;
#endif

  last_parent = root = play_tree_new();

  for (i = 1; i < argc; i++) {
    //next:
    opt = argv[i];
    /* check for -- (no more options id.) except --help! */
    if ((*opt == '-') && (*(opt+1) == '-') && (*(opt+2) == 0))
      {
	no_more_opts = 1;
	if (i+1 >= argc)
	  {
	    mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_NoFileGivenOnCommandLine);
	    goto err_out;
	  }
	continue;
      }
    if((opt[0] == '{') && (opt[1] == '\0'))
      {
	play_tree_t* entry = play_tree_new();
	UNSET_GLOBAL;
	if(last_parent->flags & PLAY_TREE_RND)
	  entry->flags |= PLAY_TREE_RND;
	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 */
      {
	int tmp = 0;
	/* remove trailing '-' */
	opt++;

	mp_msg(MSGT_CFGPARSER, MSGL_DBG3, "this_opt = option: %s\n", opt);
	// We handle here some specific option
	// Loop option when it apply to a group
	if(strcasecmp(opt,"loop") == 0 &&
		  (! last_entry || last_entry->child) ) {
	  int l;
	  char* end = NULL;
	  l = (i+1<argc) ? strtol(argv[i+1],&end,0) : 0;
	  if(!end || *end != '\0') {
	    mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_TheLoopOptionMustBeAnInteger, argv[i+1]);
	    tmp = ERR_OUT_OF_RANGE;
	  } else {
	    play_tree_t* pt = last_entry ? last_entry : last_parent;
	    l = l <= 0 ? -1 : l;
	    pt->loop = l;
	    tmp = 1;
	  }
	} else if(strcasecmp(opt,"shuffle") == 0) {
	  if(last_entry && last_entry->child)
	    last_entry->flags |= PLAY_TREE_RND;
	  else
	    last_parent->flags |= PLAY_TREE_RND;
	} else if(strcasecmp(opt,"noshuffle") == 0) {
	  if(last_entry && last_entry->child)
	    last_entry->flags &= ~PLAY_TREE_RND;
	  else
	    last_parent->flags &= ~PLAY_TREE_RND;
	} else {
	  const m_option_t* mp_opt = NULL;
	  play_tree_t* entry = NULL;

	  tmp = is_entry_option(opt,(i+1<argc) ? argv[i + 1] : NULL,&entry);
	  if(tmp > 0)  { // It's an entry
	    if(entry) {
	      add_entry(&last_parent,&last_entry,entry);
	      if((last_parent->flags & PLAY_TREE_RND) && entry->child)
		entry->flags |= PLAY_TREE_RND;
	      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))
                tmp = (i+1<argc) ? m_config_set_option(config, opt, argv[i + 1])
				 : m_config_set_option(config, opt, NULL);
	      else {
		tmp = m_config_check_option(config, opt, (i+1<argc) ? argv[i + 1] : NULL);
		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 {
	      tmp = M_OPT_UNKNOWN;
	      mp_msg(MSGT_CFGPARSER, MSGL_ERR, MSGTR_UnknownOptionOnCommandLine, opt);
	    }
	  }
	}

	if (tmp <= M_OPT_EXIT) {
	  opt_exit = 1;
	  tmp = M_OPT_EXIT - tmp;
	} else
	if (tmp < 0) {
	  mp_msg(MSGT_CFGPARSER, MSGL_FATAL, MSGTR_ErrorParsingOptionOnCommandLine, opt);
	  goto err_out;
	}
	i += tmp;
      }
    else /* filename */
      {
        int is_dvdnav = strstr(argv[i],"dvdnav://") != NULL;
	play_tree_t* entry = play_tree_new();
	mp_msg(MSGT_CFGPARSER, MSGL_DBG2,"Adding file %s\n",argv[i]);
        // if required expand DVD filename entries like dvd://1-3 into component titles
        if ( strstr(argv[i],"dvd://") != NULL || is_dvdnav)
	{
             int offset = is_dvdnav ? 9 : 6;
             splitpos=strstr(argv[i]+offset,"-");
             if(splitpos != NULL)
             {
               start_title=strtol(argv[i]+offset,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,sizeof(entbuf),is_dvdnav ? "dvdnav://%d" : "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, MSGTR_InvalidPlayEntry, argv[i]);
               }

	     } else { // dvd:// or dvd://x entry
                play_tree_add_file(entry,argv[i]);
             }
        } else {
	play_tree_add_file(entry,argv[i]);
	}

	// Lock stdin if it will be used as input
	if(strcasecmp(argv[i],"-") == 0)
	  m_config_set_option(config,"noconsolecontrols",NULL);
	add_entry(&last_parent,&last_entry,entry);
	UNSET_GLOBAL; // We start entry specific options

      }
  }

  if (opt_exit)
    goto err_out;
  if(last_parent != root)
    mp_msg(MSGT_CFGPARSER, MSGL_ERR,"Missing }- ?\n");
  return root;

 err_out:
  play_tree_free(root,1);
  return NULL;
}
コード例 #6
0
ファイル: parser-mpcmd.c プロジェクト: kax4/mpv
// Returns 0 if a valid option/file is available, <0 on error, 1 on end of args.
static int split_opt_silent(struct parse_state *p)
{
    assert(!p->error);

    if (p->argc < 1)
        return 1;

    p->mp_opt = NULL;
    p->arg = bstr0(p->argv[0]);
    p->param = bstr0(NULL);

    p->argc--;
    p->argv++;

    if (p->no_more_opts || !bstr_startswith0(p->arg, "-") || p->arg.len == 1)
        return 0;

    if (bstrcmp0(p->arg, "--") == 0) {
        p->no_more_opts = true;
        return split_opt_silent(p);
    }

    bool old_syntax = !bstr_startswith0(p->arg, "--");
    if (old_syntax) {
        p->arg = bstr_cut(p->arg, 1);
    } else {
        p->arg = bstr_cut(p->arg, 2);
        int idx = bstrchr(p->arg, '=');
        if (idx > 0) {
            p->param = bstr_cut(p->arg, idx + 1);
            p->arg = bstr_splice(p->arg, 0, idx);
        }
    }

    p->mp_opt = m_config_get_option(p->config, p->arg);
    if (!p->mp_opt) {
        // Automagic "no-" arguments: "--no-bla" turns into "--bla=no".
        if (!bstr_startswith0(p->arg, "no-"))
            return -1;

        struct bstr s = bstr_cut(p->arg, 3);
        p->mp_opt = m_config_get_option(p->config, s);
        if (!p->mp_opt || p->mp_opt->type != &m_option_type_flag)
            return -1;
        // Avoid allowing "--no-no-bla".
        if (bstr_startswith(bstr0(p->mp_opt->name), bstr0("no-")))
            return -1;
        // Flag options never have parameters.
        old_syntax = false;
        if (p->param.len)
            return -2;
        p->arg = s;
        p->param = bstr0("no");
    }

    if (bstr_endswith0(p->arg, "-clr"))
        old_syntax = false;

    if (old_syntax && !(p->mp_opt->type->flags & M_OPT_TYPE_OLD_SYNTAX_NO_PARAM))
    {
        if (p->argc < 1)
            return -3;
        p->param = bstr0(p->argv[0]);
        p->argc--;
        p->argv++;
    }

    return 0;
}