2010-01-30 23:24:23 +00:00
|
|
|
/*
|
|
|
|
* This file is part of MPlayer.
|
|
|
|
*
|
|
|
|
* MPlayer is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* MPlayer is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with MPlayer; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*/
|
2002-01-08 01:24:25 +00:00
|
|
|
|
2006-04-25 01:26:10 +00:00
|
|
|
/// \file
|
|
|
|
/// \ingroup Playtree
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
#include "config.h"
|
2002-01-08 01:24:25 +00:00
|
|
|
#include <stdlib.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <stdio.h>
|
2002-01-08 12:10:33 +00:00
|
|
|
#include <unistd.h>
|
2002-01-17 20:24:28 +00:00
|
|
|
#include <errno.h>
|
2002-01-08 01:24:25 +00:00
|
|
|
#include <assert.h>
|
2011-07-29 03:34:04 +00:00
|
|
|
|
|
|
|
#include "talloc.h"
|
|
|
|
|
2003-03-30 17:09:17 +00:00
|
|
|
#include "m_config.h"
|
2002-01-08 01:24:25 +00:00
|
|
|
#include "playtree.h"
|
|
|
|
#include "mp_msg.h"
|
|
|
|
|
|
|
|
static int
|
|
|
|
play_tree_is_valid(play_tree_t* pt);
|
|
|
|
|
|
|
|
play_tree_t*
|
|
|
|
play_tree_new(void) {
|
2006-07-02 08:17:07 +00:00
|
|
|
play_tree_t* r = calloc(1,sizeof(play_tree_t));
|
2002-01-17 20:24:28 +00:00
|
|
|
r->entry_type = PLAY_TREE_ENTRY_NODE;
|
2002-01-08 01:24:25 +00:00
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-07-28 14:27:55 +00:00
|
|
|
play_tree_free(play_tree_t* pt, int children) {
|
2002-01-08 01:24:25 +00:00
|
|
|
play_tree_t* iter;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
if(children) {
|
2002-11-02 22:44:15 +00:00
|
|
|
for(iter = pt->child; iter != NULL; ) {
|
|
|
|
play_tree_t* nxt=iter->next;
|
2002-01-08 01:24:25 +00:00
|
|
|
play_tree_free(iter,1);
|
2002-11-02 22:44:15 +00:00
|
|
|
iter = nxt;
|
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
pt->child = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
play_tree_remove(pt,0,0);
|
|
|
|
|
|
|
|
for(iter = pt->child ; iter != NULL ; iter = iter->next)
|
|
|
|
iter->parent = NULL;
|
|
|
|
|
2011-07-29 03:34:04 +00:00
|
|
|
talloc_free(pt->params);
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt->files) {
|
|
|
|
int i;
|
|
|
|
for(i = 0 ; pt->files[i] != NULL ; i++)
|
|
|
|
free(pt->files[i]);
|
|
|
|
free(pt->files);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2007-07-28 14:27:55 +00:00
|
|
|
play_tree_free_list(play_tree_t* pt, int children) {
|
2002-01-08 01:24:25 +00:00
|
|
|
play_tree_t* iter;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
|
|
|
|
for(iter = pt ; iter->prev != NULL ; iter = iter->prev)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
2002-11-02 22:44:15 +00:00
|
|
|
while(iter) {
|
|
|
|
play_tree_t* nxt = iter->next;
|
2007-07-28 14:27:55 +00:00
|
|
|
play_tree_free(iter, children);
|
2002-11-02 22:44:15 +00:00
|
|
|
iter = nxt;
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_append_entry(play_tree_t* pt, play_tree_t* entry) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
assert(entry != NULL);
|
|
|
|
|
|
|
|
if(pt == entry)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(iter = pt ; iter->next != NULL ; iter = iter->next)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
|
|
|
entry->parent = iter->parent;
|
|
|
|
entry->prev = iter;
|
|
|
|
entry->next = NULL;
|
|
|
|
iter->next = entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
assert(entry != NULL);
|
|
|
|
|
|
|
|
for(iter = pt ; iter->prev != NULL; iter = iter->prev)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
|
|
|
entry->prev = NULL;
|
|
|
|
entry->next = iter;
|
|
|
|
entry->parent = iter->parent;
|
|
|
|
|
|
|
|
iter->prev = entry;
|
|
|
|
if(entry->parent) {
|
|
|
|
assert(entry->parent->child == iter);
|
|
|
|
entry->parent->child = entry;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry) {
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt != NULL);
|
|
|
|
assert(entry != NULL);
|
|
|
|
|
|
|
|
entry->parent = pt->parent;
|
|
|
|
entry->prev = pt;
|
|
|
|
if(pt->next) {
|
|
|
|
assert(pt->next->prev == pt);
|
|
|
|
entry->next = pt->next;
|
|
|
|
entry->next->prev = entry;
|
2009-07-06 23:26:13 +00:00
|
|
|
} else
|
2002-01-08 01:24:25 +00:00
|
|
|
entry->next = NULL;
|
|
|
|
pt->next = entry;
|
|
|
|
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
void
|
2007-07-28 14:27:55 +00:00
|
|
|
play_tree_remove(play_tree_t* pt, int free_it, int with_children) {
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
|
|
|
|
// Middle of list
|
|
|
|
if(pt->prev && pt->next) {
|
|
|
|
assert(pt->prev->next == pt);
|
|
|
|
assert(pt->next->prev == pt);
|
|
|
|
pt->prev->next = pt->next;
|
|
|
|
pt->next->prev = pt->prev;
|
|
|
|
} // End of list
|
2009-07-06 23:26:13 +00:00
|
|
|
else if(pt->prev) {
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(pt->prev->next == pt);
|
|
|
|
pt->prev->next = NULL;
|
2007-12-23 21:22:02 +00:00
|
|
|
} // Beginning of list
|
2002-01-08 01:24:25 +00:00
|
|
|
else if(pt->next) {
|
|
|
|
assert(pt->next->prev == pt);
|
|
|
|
pt->next->prev = NULL;
|
|
|
|
if(pt->parent) {
|
|
|
|
assert(pt->parent->child == pt);
|
|
|
|
pt->parent->child = pt->next;
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
} // The only one
|
|
|
|
else if(pt->parent) {
|
|
|
|
assert(pt->parent->child == pt);
|
|
|
|
pt->parent->child = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
pt->prev = pt->next = pt->parent = NULL;
|
|
|
|
if(free_it)
|
2007-07-28 14:27:55 +00:00
|
|
|
play_tree_free(pt,with_children);
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_set_child(play_tree_t* pt, play_tree_t* child) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2010-08-13 15:58:11 +00:00
|
|
|
/* Roughly validate input data. Both, pt and child are going to be
|
|
|
|
* dereferenced, hence assure they're not NULL.
|
|
|
|
*/
|
|
|
|
if (!pt || !child) {
|
|
|
|
mp_msg(MSGT_PLAYTREE, MSGL_ERR, "Internal error, attempt to add an empty child or use empty playlist\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
assert(pt->entry_type == PLAY_TREE_ENTRY_NODE);
|
2002-01-08 01:24:25 +00:00
|
|
|
|
2007-07-28 14:27:55 +00:00
|
|
|
//DEBUG_FF: Where are the children freed?
|
2003-02-05 23:02:05 +00:00
|
|
|
// Attention in using this function!
|
2002-01-08 01:24:25 +00:00
|
|
|
for(iter = pt->child ; iter != NULL ; iter = iter->next)
|
|
|
|
iter->parent = NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
// Go back to first one
|
|
|
|
for(iter = child ; iter->prev != NULL ; iter = iter->prev)
|
|
|
|
/* NOTHING */;
|
|
|
|
|
|
|
|
pt->child = iter;
|
|
|
|
|
|
|
|
for( ; iter != NULL ; iter= iter->next)
|
|
|
|
iter->parent = pt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_set_parent(play_tree_t* pt, play_tree_t* parent) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
|
|
|
|
if(pt->parent)
|
|
|
|
pt->parent->child = NULL;
|
|
|
|
|
|
|
|
for(iter = pt ; iter != NULL ; iter = iter->next)
|
|
|
|
iter->parent = parent;
|
|
|
|
|
|
|
|
if(pt->prev) {
|
|
|
|
for(iter = pt->prev ; iter->prev != NULL ; iter = iter->prev)
|
|
|
|
iter->parent = parent;
|
|
|
|
iter->parent = parent;
|
|
|
|
parent->child = iter;
|
|
|
|
} else
|
|
|
|
parent->child = pt;
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
}
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
void
|
2011-06-13 19:33:17 +00:00
|
|
|
play_tree_add_file(play_tree_t* pt,const char* file) {
|
2002-01-08 01:24:25 +00:00
|
|
|
int n = 0;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
assert(pt->child == NULL);
|
|
|
|
assert(file != NULL);
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
if(pt->entry_type != PLAY_TREE_ENTRY_NODE &&
|
2002-01-17 20:24:28 +00:00
|
|
|
pt->entry_type != PLAY_TREE_ENTRY_FILE)
|
|
|
|
return;
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt->files) {
|
|
|
|
for(n = 0 ; pt->files[n] != NULL ; n++)
|
|
|
|
/* NOTHING */;
|
|
|
|
}
|
2010-02-26 15:01:37 +00:00
|
|
|
pt->files = realloc(pt->files, (n + 2) * sizeof(char*));
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt->files ==NULL) {
|
2007-06-24 10:39:04 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
|
2002-01-08 01:24:25 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2011-05-04 20:12:55 +00:00
|
|
|
pt->files[n] = strdup(file);
|
2002-01-08 01:24:25 +00:00
|
|
|
pt->files[n+1] = NULL;
|
|
|
|
|
2003-03-30 17:09:17 +00:00
|
|
|
pt->entry_type = PLAY_TREE_ENTRY_FILE;
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-13 19:33:17 +00:00
|
|
|
play_tree_remove_file(play_tree_t* pt,const char* file) {
|
2002-01-08 01:24:25 +00:00
|
|
|
int n,f = -1;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
assert(file != NULL);
|
2002-01-17 20:24:28 +00:00
|
|
|
assert(pt->entry_type != PLAY_TREE_ENTRY_NODE);
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
for(n=0 ; pt->files[n] != NULL ; n++) {
|
|
|
|
if(strcmp(file,pt->files[n]) == 0)
|
|
|
|
f = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(f < 0) // Not found
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
free(pt->files[f]);
|
|
|
|
|
|
|
|
if(n > 1) {
|
|
|
|
memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*));
|
2010-02-26 15:01:37 +00:00
|
|
|
pt->files = realloc(pt->files, n * sizeof(char*));
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt->files == NULL) {
|
2007-06-24 10:39:04 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*(int)sizeof(char*));
|
2002-01-08 01:24:25 +00:00
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
free(pt->files);
|
|
|
|
pt->files = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2011-07-29 04:24:09 +00:00
|
|
|
play_tree_set_param(play_tree_t* pt, struct bstr name, struct bstr val) {
|
2009-10-10 10:39:05 +00:00
|
|
|
int n = 0;
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
|
2009-10-10 10:39:05 +00:00
|
|
|
if(pt->params)
|
|
|
|
for ( ; pt->params[n].name != NULL ; n++ ) { }
|
2002-01-08 01:24:25 +00:00
|
|
|
|
2011-07-29 03:34:04 +00:00
|
|
|
pt->params = talloc_realloc(NULL, pt->params, struct play_tree_param, n + 2);
|
2011-07-29 04:24:09 +00:00
|
|
|
pt->params[n].name = bstrdup0(pt->params, name);
|
|
|
|
pt->params[n].value = bstrdup0(pt->params, val);
|
2002-01-08 01:24:25 +00:00
|
|
|
memset(&pt->params[n+1],0,sizeof(play_tree_param_t));
|
|
|
|
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-06-13 19:33:17 +00:00
|
|
|
play_tree_unset_param(play_tree_t* pt, const char* name) {
|
2002-01-14 23:38:49 +00:00
|
|
|
int n,ni = -1;
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
assert(name != NULL);
|
|
|
|
assert(pt->params != NULL);
|
|
|
|
|
|
|
|
for(n = 0 ; pt->params[n].name != NULL ; n++) {
|
|
|
|
if(strcasecmp(pt->params[n].name,name) == 0)
|
|
|
|
ni = n;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(ni < 0)
|
|
|
|
return 0;
|
|
|
|
|
2011-07-29 03:34:04 +00:00
|
|
|
talloc_free(pt->params[ni].name);
|
|
|
|
talloc_free(pt->params[ni].value);
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(n > 1) {
|
|
|
|
memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t));
|
2011-07-29 03:34:04 +00:00
|
|
|
pt->params = talloc_realloc(NULL, pt->params, struct play_tree_param, n);
|
2002-01-08 01:24:25 +00:00
|
|
|
} else {
|
2011-07-29 03:34:04 +00:00
|
|
|
talloc_free(pt->params);
|
2002-01-08 01:24:25 +00:00
|
|
|
pt->params = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2002-03-20 10:27:27 +00:00
|
|
|
void
|
|
|
|
play_tree_set_params_from(play_tree_t* dest,play_tree_t* src) {
|
|
|
|
int i;
|
|
|
|
|
|
|
|
assert(dest != NULL);
|
|
|
|
assert(src != NULL);
|
|
|
|
|
|
|
|
if(!src->params)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for(i = 0; src->params[i].name != NULL ; i++)
|
2011-07-29 04:24:09 +00:00
|
|
|
play_tree_set_param(dest, bstr(src->params[i].name), bstr(src->params[i].value));
|
2003-07-08 10:45:05 +00:00
|
|
|
if(src->flags & PLAY_TREE_RND) // pass the random flag too
|
|
|
|
dest->flags |= PLAY_TREE_RND;
|
2002-03-20 10:27:27 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
2008-08-12 10:58:29 +00:00
|
|
|
static void
|
2002-11-12 23:39:35 +00:00
|
|
|
play_tree_unset_flag(play_tree_t* pt, int flags , int deep) {
|
|
|
|
play_tree_t* i;
|
|
|
|
|
|
|
|
pt->flags &= ~flags;
|
|
|
|
|
|
|
|
if(deep && pt->child) {
|
|
|
|
if(deep > 0) deep--;
|
|
|
|
for(i = pt->child ; i ; i = i->next)
|
|
|
|
play_tree_unset_flag(i,flags,deep);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//////////////////////////////////// ITERATOR //////////////////////////////////////
|
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
static void
|
2002-01-14 23:38:49 +00:00
|
|
|
play_tree_iter_push_params(play_tree_iter_t* iter) {
|
|
|
|
int n;
|
|
|
|
play_tree_t* pt;
|
|
|
|
assert(iter->config != NULL);
|
|
|
|
assert(iter->tree != NULL);
|
|
|
|
|
|
|
|
pt = iter->tree;
|
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
// We always push a config because we can set some option
|
|
|
|
// while playing
|
|
|
|
m_config_push(iter->config);
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
if(pt->params == NULL)
|
2002-01-19 22:16:47 +00:00
|
|
|
return;
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
for(n = 0; pt->params[n].name != NULL ; n++) {
|
2002-01-21 10:45:53 +00:00
|
|
|
int e;
|
2011-07-28 08:07:47 +00:00
|
|
|
if((e = m_config_set_option0(iter->config, pt->params[n].name,
|
|
|
|
pt->params[n].value, false)) < 0) {
|
2002-01-21 10:45:53 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error %d while setting option '%s' with value '%s'\n",e,
|
2009-07-06 23:26:13 +00:00
|
|
|
pt->params[n].name,pt->params[n].value);
|
2002-01-14 23:38:49 +00:00
|
|
|
}
|
|
|
|
}
|
2002-01-17 20:24:28 +00:00
|
|
|
|
|
|
|
if(!pt->child)
|
|
|
|
iter->entry_pushed = 1;
|
2002-01-14 23:38:49 +00:00
|
|
|
}
|
|
|
|
|
2011-11-30 07:28:18 +00:00
|
|
|
// Shuffle the tree if the PLAY_TREE_RND flag is set, and unset it.
|
|
|
|
// This is done recursively, but only the siblings with the same parent are
|
|
|
|
// shuffled with each other.
|
|
|
|
static void shuffle_tree(play_tree_t *pt) {
|
|
|
|
if (!pt)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int count = 0;
|
|
|
|
play_tree_t *child = pt->child;
|
|
|
|
while (child) {
|
|
|
|
// possibly shuffle children
|
|
|
|
shuffle_tree(child);
|
|
|
|
child = child->next;
|
|
|
|
count++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (pt->flags & PLAY_TREE_RND) {
|
|
|
|
// Move a random element to the front and go to the next, until no
|
|
|
|
// elements are left.
|
|
|
|
// prev = pointer to next-link to the first yet-unshuffled entry
|
|
|
|
play_tree_t** prev = &pt->child;
|
|
|
|
while (count > 1) {
|
|
|
|
int n = (int)((double)(count) * rand() / (RAND_MAX + 1.0));
|
|
|
|
// move = element that is moved to front (inserted after prev)
|
|
|
|
play_tree_t **before_move = prev;
|
|
|
|
play_tree_t *move = *before_move;
|
|
|
|
while (n > 0) {
|
|
|
|
before_move = &move->next;
|
|
|
|
move = *before_move;
|
|
|
|
n--;
|
|
|
|
}
|
|
|
|
// unlink from old list
|
|
|
|
*before_move = move->next;
|
|
|
|
// insert between prev and the following element
|
|
|
|
// note that move could be the first unshuffled element
|
|
|
|
move->next = (*prev == move) ? move->next : *prev;
|
|
|
|
*prev = move;
|
|
|
|
prev = &move->next;
|
|
|
|
count--;
|
|
|
|
}
|
|
|
|
// reconstruct prev links
|
|
|
|
child = pt->child;
|
|
|
|
play_tree_t *prev_child = NULL;
|
|
|
|
while (child) {
|
|
|
|
child->prev = prev_child;
|
|
|
|
prev_child = child;
|
|
|
|
child = child->next;
|
|
|
|
}
|
|
|
|
pt->flags = pt->flags & ~PLAY_TREE_RND;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
play_tree_iter_t*
|
2002-01-14 23:38:49 +00:00
|
|
|
play_tree_iter_new(play_tree_t* pt,m_config_t* config) {
|
2002-01-08 01:24:25 +00:00
|
|
|
play_tree_iter_t* iter;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
2002-01-14 23:38:49 +00:00
|
|
|
assert(config != NULL);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if( ! play_tree_is_valid(pt))
|
|
|
|
return NULL;
|
|
|
|
|
2006-07-02 08:17:07 +00:00
|
|
|
iter = calloc(1,sizeof(play_tree_iter_t));
|
2003-02-05 23:02:05 +00:00
|
|
|
if(! iter) {
|
2007-06-24 10:39:04 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate new iterator (%d bytes of memory)\n",(int)sizeof(play_tree_iter_t));
|
2003-02-05 23:02:05 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
iter->root = pt;
|
|
|
|
iter->tree = NULL;
|
2002-01-14 23:38:49 +00:00
|
|
|
iter->config = config;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2011-11-30 07:28:18 +00:00
|
|
|
shuffle_tree(pt);
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt->parent)
|
|
|
|
iter->loop = pt->parent->loop;
|
|
|
|
|
|
|
|
return iter;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
play_tree_iter_free(play_tree_iter_t* iter) {
|
2002-03-06 23:27:20 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter != NULL);
|
|
|
|
|
|
|
|
if(iter->status_stack) {
|
|
|
|
assert(iter->stack_size > 0);
|
|
|
|
free(iter->status_stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
free(iter);
|
|
|
|
}
|
|
|
|
|
2002-11-12 23:39:35 +00:00
|
|
|
static play_tree_t*
|
|
|
|
play_tree_rnd_step(play_tree_t* pt) {
|
|
|
|
int count = 0;
|
|
|
|
int r;
|
|
|
|
play_tree_t *i,*head;
|
|
|
|
|
|
|
|
// Count how many free choice we have
|
|
|
|
for(i = pt ; i->prev ; i = i->prev)
|
|
|
|
if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
|
|
|
|
head = i;
|
|
|
|
if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
|
|
|
|
for(i = pt->next ; i ; i = i->next)
|
|
|
|
if(!(i->flags & PLAY_TREE_RND_PLAYED)) count++;
|
|
|
|
|
|
|
|
if(!count) return NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2004-11-05 22:45:16 +00:00
|
|
|
r = (int)((float)(count) * rand() / (RAND_MAX + 1.0));
|
2002-11-12 23:39:35 +00:00
|
|
|
|
|
|
|
for(i = head ; i ; i=i->next) {
|
|
|
|
if(!(i->flags & PLAY_TREE_RND_PLAYED)) r--;
|
|
|
|
if(r < 0) return i;
|
|
|
|
}
|
|
|
|
|
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Random stepping error\n");
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
int
|
|
|
|
play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
|
|
|
play_tree_t* pt;
|
|
|
|
|
2002-04-16 17:41:29 +00:00
|
|
|
if ( !iter ) return PLAY_TREE_ITER_ENTRY;
|
|
|
|
if ( !iter->root ) return PLAY_TREE_ITER_ENTRY;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
assert(iter != NULL);
|
|
|
|
assert(iter->root != NULL);
|
|
|
|
|
|
|
|
if(iter->tree == NULL) {
|
|
|
|
iter->tree = iter->root;
|
|
|
|
return play_tree_iter_step(iter,0,with_nodes);
|
|
|
|
}
|
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
if(iter->config && iter->entry_pushed > 0) {
|
2002-02-21 13:11:31 +00:00
|
|
|
iter->entry_pushed = 0;
|
2002-01-19 22:16:47 +00:00
|
|
|
m_config_pop(iter->config);
|
|
|
|
}
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-11-12 23:39:35 +00:00
|
|
|
if(iter->tree->parent && (iter->tree->parent->flags & PLAY_TREE_RND))
|
|
|
|
iter->mode = PLAY_TREE_ITER_RND;
|
2002-01-08 01:24:25 +00:00
|
|
|
else
|
2002-11-12 23:39:35 +00:00
|
|
|
iter->mode = PLAY_TREE_ITER_NORMAL;
|
2002-01-08 01:24:25 +00:00
|
|
|
|
2002-11-12 23:39:35 +00:00
|
|
|
iter->file = -1;
|
|
|
|
if(iter->mode == PLAY_TREE_ITER_RND)
|
|
|
|
pt = play_tree_rnd_step(iter->tree);
|
|
|
|
else if( d > 0 ) {
|
|
|
|
int i;
|
|
|
|
pt = iter->tree;
|
|
|
|
for(i = d ; i > 0 && pt ; i--)
|
|
|
|
pt = pt->next;
|
|
|
|
d = i ? i : 1;
|
|
|
|
} else if(d < 0) {
|
|
|
|
int i;
|
|
|
|
pt = iter->tree;
|
|
|
|
for(i = d ; i < 0 && pt ; i++)
|
|
|
|
pt = pt->prev;
|
|
|
|
d = i ? i : -1;
|
|
|
|
} else
|
|
|
|
pt = iter->tree;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt == NULL) { // No next
|
|
|
|
// Must we loop?
|
2004-10-20 17:30:29 +00:00
|
|
|
if (iter->mode == PLAY_TREE_ITER_RND) {
|
|
|
|
if (iter->root->loop == 0)
|
|
|
|
return PLAY_TREE_ITER_END;
|
|
|
|
play_tree_unset_flag(iter->root, PLAY_TREE_RND_PLAYED, -1);
|
|
|
|
if (iter->root->loop > 0) iter->root->loop--;
|
|
|
|
// try again
|
|
|
|
return play_tree_iter_step(iter, 0, with_nodes);
|
|
|
|
} else
|
2009-07-06 23:26:13 +00:00
|
|
|
if(iter->tree->parent && iter->tree->parent->loop != 0 && ((d > 0 && iter->loop != 0) || ( d < 0 && (iter->loop < 0 || iter->loop < iter->tree->parent->loop) ) ) ) {
|
2002-01-08 01:24:25 +00:00
|
|
|
if(d > 0) { // Go back to the first one
|
|
|
|
for(pt = iter->tree ; pt->prev != NULL; pt = pt->prev)
|
|
|
|
/* NOTHNG */;
|
|
|
|
if(iter->loop > 0) iter->loop--;
|
|
|
|
} else if( d < 0 ) { // Or the last one
|
|
|
|
for(pt = iter->tree ; pt->next != NULL; pt = pt->next)
|
|
|
|
/* NOTHNG */;
|
|
|
|
if(iter->loop >= 0 && iter->loop < iter->tree->parent->loop) iter->loop++;
|
|
|
|
}
|
|
|
|
iter->tree = pt;
|
|
|
|
return play_tree_iter_step(iter,0,with_nodes);
|
|
|
|
}
|
|
|
|
// Go up one level
|
|
|
|
return play_tree_iter_up_step(iter,d,with_nodes);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2007-07-28 14:27:55 +00:00
|
|
|
// Is there any valid child?
|
2002-01-08 01:24:25 +00:00
|
|
|
if(pt->child && play_tree_is_valid(pt->child)) {
|
|
|
|
iter->tree = pt;
|
2009-07-06 23:26:13 +00:00
|
|
|
if(with_nodes) { // Stop on the node
|
2002-01-08 01:24:25 +00:00
|
|
|
return PLAY_TREE_ITER_NODE;
|
|
|
|
} else // Or follow it
|
|
|
|
return play_tree_iter_down_step(iter,d,with_nodes);
|
|
|
|
}
|
|
|
|
|
2007-07-28 14:27:55 +00:00
|
|
|
// Is it a valid entry?
|
2002-01-08 01:24:25 +00:00
|
|
|
if(! play_tree_is_valid(pt)) {
|
2003-02-05 23:02:05 +00:00
|
|
|
if(d == 0) { // Can this happen ? FF: Yes!
|
2002-01-08 01:24:25 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"What to do now ???? Infinite loop if we continue\n");
|
|
|
|
return PLAY_TREE_ITER_ERROR;
|
|
|
|
} // Not a valid entry : go to next one
|
|
|
|
return play_tree_iter_step(iter,d,with_nodes);
|
|
|
|
}
|
|
|
|
|
2002-01-14 23:38:49 +00:00
|
|
|
assert(pt->files != NULL);
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
iter->tree = pt;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
for(d = 0 ; iter->tree->files[d] != NULL ; d++)
|
|
|
|
/* NOTHING */;
|
|
|
|
iter->num_files = d;
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2002-01-19 22:16:47 +00:00
|
|
|
if(iter->config) {
|
2002-01-17 20:24:28 +00:00
|
|
|
play_tree_iter_push_params(iter);
|
2002-02-21 13:11:31 +00:00
|
|
|
iter->entry_pushed = 1;
|
2002-11-12 23:39:35 +00:00
|
|
|
if(iter->mode == PLAY_TREE_ITER_RND)
|
|
|
|
pt->flags |= PLAY_TREE_RND_PLAYED;
|
2002-01-19 22:16:47 +00:00
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
|
|
|
|
return PLAY_TREE_ITER_ENTRY;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
play_tree_is_valid(play_tree_t* pt) {
|
|
|
|
play_tree_t* iter;
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
if(pt->entry_type != PLAY_TREE_ENTRY_NODE) {
|
|
|
|
assert(pt->child == NULL);
|
2002-01-08 01:24:25 +00:00
|
|
|
return 1;
|
2002-01-17 20:24:28 +00:00
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
else if (pt->child != NULL) {
|
|
|
|
for(iter = pt->child ; iter != NULL ; iter = iter->next) {
|
|
|
|
if(play_tree_is_valid(iter))
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
|
|
|
|
|
|
|
assert(iter != NULL);
|
|
|
|
assert(iter->tree != NULL);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
iter->file = -1;
|
2002-01-08 01:24:25 +00:00
|
|
|
if(iter->tree->parent == iter->root->parent)
|
|
|
|
return PLAY_TREE_ITER_END;
|
|
|
|
|
|
|
|
assert(iter->tree->parent != NULL);
|
|
|
|
assert(iter->stack_size > 0);
|
|
|
|
assert(iter->status_stack != NULL);
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
iter->stack_size--;
|
|
|
|
iter->loop = iter->status_stack[iter->stack_size];
|
2002-04-23 20:06:00 +00:00
|
|
|
if(iter->stack_size > 0)
|
2010-02-26 15:01:37 +00:00
|
|
|
iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
|
2002-04-23 20:06:00 +00:00
|
|
|
else {
|
|
|
|
free(iter->status_stack);
|
|
|
|
iter->status_stack = NULL;
|
|
|
|
}
|
2002-01-08 01:24:25 +00:00
|
|
|
if(iter->stack_size > 0 && iter->status_stack == NULL) {
|
2007-06-24 10:39:04 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)sizeof(char*));
|
2002-01-08 01:24:25 +00:00
|
|
|
return PLAY_TREE_ITER_ERROR;
|
|
|
|
}
|
|
|
|
iter->tree = iter->tree->parent;
|
2002-01-14 23:38:49 +00:00
|
|
|
|
|
|
|
// Pop subtree params
|
2002-11-12 23:39:35 +00:00
|
|
|
if(iter->config) {
|
2002-01-19 22:16:47 +00:00
|
|
|
m_config_pop(iter->config);
|
2002-11-12 23:39:35 +00:00
|
|
|
if(iter->mode == PLAY_TREE_ITER_RND)
|
|
|
|
iter->tree->flags |= PLAY_TREE_RND_PLAYED;
|
|
|
|
}
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
return play_tree_iter_step(iter,d,with_nodes);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
int
|
|
|
|
play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes) {
|
|
|
|
|
|
|
|
assert(iter->tree->files == NULL);
|
|
|
|
assert(iter->tree->child != NULL);
|
|
|
|
assert(iter->tree->child->parent == iter->tree);
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
iter->file = -1;
|
2002-01-14 23:38:49 +00:00
|
|
|
|
|
|
|
// Push subtree params
|
|
|
|
if(iter->config)
|
|
|
|
play_tree_iter_push_params(iter);
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
iter->stack_size++;
|
2010-02-26 15:01:37 +00:00
|
|
|
iter->status_stack = realloc(iter->status_stack, iter->stack_size * sizeof(int));
|
2002-01-08 01:24:25 +00:00
|
|
|
if(iter->status_stack == NULL) {
|
2007-06-24 10:39:04 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*(int)sizeof(int));
|
2002-01-08 01:24:25 +00:00
|
|
|
return PLAY_TREE_ITER_ERROR;
|
|
|
|
}
|
|
|
|
iter->status_stack[iter->stack_size-1] = iter->loop;
|
|
|
|
// Set new status
|
|
|
|
iter->loop = iter->tree->loop-1;
|
|
|
|
if(d >= 0)
|
|
|
|
iter->tree = iter->tree->child;
|
|
|
|
else {
|
|
|
|
play_tree_t* pt;
|
|
|
|
for(pt = iter->tree->child ; pt->next != NULL ; pt = pt->next)
|
|
|
|
/*NOTING*/;
|
|
|
|
iter->tree = pt;
|
|
|
|
}
|
2002-01-14 23:38:49 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
return play_tree_iter_step(iter,0,with_nodes);
|
|
|
|
}
|
|
|
|
|
|
|
|
char*
|
|
|
|
play_tree_iter_get_file(play_tree_iter_t* iter, int d) {
|
|
|
|
assert(iter != NULL);
|
|
|
|
assert(iter->tree->child == NULL);
|
|
|
|
|
|
|
|
if(iter->tree->files == NULL)
|
|
|
|
return NULL;
|
|
|
|
|
2002-01-17 20:24:28 +00:00
|
|
|
assert(iter->num_files > 0);
|
|
|
|
|
|
|
|
if(iter->file >= iter->num_files-1 || iter->file < -1)
|
|
|
|
return NULL;
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
if(d > 0) {
|
2002-01-17 20:24:28 +00:00
|
|
|
if(iter->file >= iter->num_files - 1)
|
|
|
|
iter->file = 0;
|
|
|
|
else
|
|
|
|
iter->file++;
|
2002-01-08 01:24:25 +00:00
|
|
|
} else if(d < 0) {
|
2002-01-17 20:24:28 +00:00
|
|
|
if(iter->file <= 0)
|
|
|
|
iter->file = iter->num_files - 1;
|
|
|
|
else
|
|
|
|
iter->file--;
|
|
|
|
}
|
2003-03-30 17:09:17 +00:00
|
|
|
return iter->tree->files[iter->file];
|
2002-01-08 01:24:25 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
play_tree_t*
|
|
|
|
play_tree_cleanup(play_tree_t* pt) {
|
|
|
|
play_tree_t* iter, *tmp, *first;
|
|
|
|
|
|
|
|
assert(pt != NULL);
|
|
|
|
|
|
|
|
if( ! play_tree_is_valid(pt)) {
|
|
|
|
play_tree_remove(pt,1,1);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
first = pt->child;
|
|
|
|
|
|
|
|
for(iter = pt->child ; iter != NULL ; ) {
|
|
|
|
tmp = iter;
|
|
|
|
iter = iter->next;
|
|
|
|
if(! play_tree_is_valid(tmp)) {
|
|
|
|
play_tree_remove(tmp,1,1);
|
|
|
|
if(tmp == first) first = iter;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
for(iter = first ; iter != NULL ; ) {
|
|
|
|
tmp = iter;
|
|
|
|
iter = iter->next;
|
|
|
|
play_tree_cleanup(tmp);
|
|
|
|
}
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
return pt;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
play_tree_iter_t*
|
|
|
|
play_tree_iter_new_copy(play_tree_iter_t* old) {
|
|
|
|
play_tree_iter_t* iter;
|
|
|
|
|
|
|
|
assert(old != NULL);
|
|
|
|
|
2006-07-01 03:56:13 +00:00
|
|
|
iter = malloc(sizeof(play_tree_iter_t));
|
2002-01-08 01:24:25 +00:00
|
|
|
if(iter == NULL) {
|
2007-06-24 10:39:04 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(int)sizeof(play_tree_iter_t));
|
2002-01-08 01:24:25 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
;
|
|
|
|
memcpy(iter,old,sizeof(play_tree_iter_t));
|
|
|
|
if(old->status_stack) {
|
2006-07-01 03:56:13 +00:00
|
|
|
iter->status_stack = malloc(old->stack_size * sizeof(int));
|
2002-01-08 01:24:25 +00:00
|
|
|
if(iter->status_stack == NULL) {
|
2007-06-24 10:39:04 +00:00
|
|
|
mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",old->stack_size * (int)sizeof(int));
|
2002-01-08 01:24:25 +00:00
|
|
|
free(iter);
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
memcpy(iter->status_stack,old->status_stack,iter->stack_size*sizeof(int));
|
|
|
|
}
|
2002-01-14 23:38:49 +00:00
|
|
|
iter->config = NULL;
|
|
|
|
|
2002-01-08 01:24:25 +00:00
|
|
|
return iter;
|
|
|
|
}
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2003-02-05 23:02:05 +00:00
|
|
|
// HIGH Level API, by Fabian Franz (mplayer@fabian-franz.de)
|
|
|
|
//
|
|
|
|
play_tree_iter_t* pt_iter_create(play_tree_t** ppt, m_config_t* config)
|
|
|
|
{
|
|
|
|
play_tree_iter_t* r=NULL;
|
|
|
|
assert(*ppt!=NULL);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-02-05 23:02:05 +00:00
|
|
|
*ppt=play_tree_cleanup(*ppt);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-02-05 23:02:05 +00:00
|
|
|
if(*ppt) {
|
|
|
|
r = play_tree_iter_new(*ppt,config);
|
2009-07-06 23:26:13 +00:00
|
|
|
if (r && play_tree_iter_step(r,0,0) != PLAY_TREE_ITER_ENTRY)
|
2003-02-05 23:02:05 +00:00
|
|
|
{
|
|
|
|
play_tree_iter_free(r);
|
|
|
|
r = NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pt_iter_destroy(play_tree_iter_t** iter)
|
|
|
|
{
|
|
|
|
if (iter && *iter)
|
|
|
|
{
|
|
|
|
free(*iter);
|
|
|
|
iter=NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
char* pt_iter_get_file(play_tree_iter_t* iter, int d)
|
|
|
|
{
|
|
|
|
int i=0;
|
|
|
|
char* r;
|
|
|
|
|
|
|
|
if (iter==NULL)
|
|
|
|
return NULL;
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-02-05 23:02:05 +00:00
|
|
|
r = play_tree_iter_get_file(iter,d);
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-02-05 23:02:05 +00:00
|
|
|
while (!r && d!=0)
|
|
|
|
{
|
|
|
|
if (play_tree_iter_step(iter,d,0) != PLAY_TREE_ITER_ENTRY)
|
|
|
|
break;
|
|
|
|
r=play_tree_iter_get_file(iter,d);
|
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
|
|
|
|
void pt_iter_insert_entry(play_tree_iter_t* iter, play_tree_t* entry)
|
|
|
|
{
|
|
|
|
play_tree_t *pt = iter->tree;
|
|
|
|
assert(pt!=NULL);
|
|
|
|
assert(entry!=NULL);
|
|
|
|
assert(entry!=pt);
|
|
|
|
|
|
|
|
play_tree_insert_entry(pt, entry);
|
|
|
|
play_tree_set_params_from(entry,pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pt_iter_replace_entry(play_tree_iter_t* iter, play_tree_t* entry)
|
|
|
|
{
|
|
|
|
play_tree_t *pt = iter->tree;
|
2002-01-17 20:24:28 +00:00
|
|
|
|
2003-02-05 23:02:05 +00:00
|
|
|
pt_iter_insert_entry(iter, entry);
|
|
|
|
play_tree_remove(pt, 1, 1);
|
|
|
|
iter->tree=entry;
|
|
|
|
}
|
|
|
|
|
|
|
|
//Add a new file as a new entry
|
2011-06-13 19:33:17 +00:00
|
|
|
void pt_add_file(play_tree_t** ppt, const char* filename)
|
2003-02-05 23:02:05 +00:00
|
|
|
{
|
|
|
|
play_tree_t *pt = *ppt, *entry = play_tree_new();
|
2009-07-06 23:26:13 +00:00
|
|
|
|
2003-02-05 23:02:05 +00:00
|
|
|
play_tree_add_file(entry, filename);
|
|
|
|
if (pt)
|
|
|
|
play_tree_append_entry(pt, entry);
|
|
|
|
else
|
|
|
|
{
|
|
|
|
pt=entry;
|
|
|
|
*ppt=pt;
|
|
|
|
}
|
|
|
|
play_tree_set_params_from(entry,pt);
|
|
|
|
}
|
|
|
|
|
|
|
|
void pt_iter_goto_head(play_tree_iter_t* iter)
|
|
|
|
{
|
|
|
|
iter->tree=iter->root;
|
|
|
|
play_tree_iter_step(iter, 0, 0);
|
|
|
|
}
|