Mercurial > mplayer.hg
annotate playtree.c @ 4214:664984198aef
zr driver (tv-out for DC10/DC10+, iomega buz, LML33...) added - patch by Rik Snel <rsnel@cube.dyndns.org>
author | arpi |
---|---|
date | Thu, 17 Jan 2002 01:32:29 +0000 |
parents | 22fadd4022b5 |
children | fe2c20d52a25 |
rev | line source |
---|---|
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
1 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
2 #include "config.h" |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
3 #include <stdlib.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
4 #include <string.h> |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
5 #include <stdio.h> |
4050 | 6 #include <unistd.h> |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
7 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
8 #include <assert.h> |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
9 #endif |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
10 #include "playtree.h" |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
11 #include "mp_msg.h" |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
12 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
13 static int |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
14 play_tree_is_valid(play_tree_t* pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
15 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
16 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
17 play_tree_new(void) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
18 play_tree_t* r = (play_tree_t*)calloc(1,sizeof(play_tree_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
19 if(r == NULL) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
20 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",sizeof(play_tree_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
21 return r; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
22 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
23 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
24 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
25 play_tree_free(play_tree_t* pt, int childs) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
26 play_tree_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
27 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
28 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
29 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
30 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
31 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
32 if(childs) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
33 for(iter = pt->child; iter != NULL; iter = iter->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
34 play_tree_free(iter,1); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
35 pt->child = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
36 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
37 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
38 play_tree_remove(pt,0,0); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
39 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
40 for(iter = pt->child ; iter != NULL ; iter = iter->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
41 iter->parent = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
42 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
43 //if(pt->params) free(pt->params); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
44 if(pt->files) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
45 int i; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
46 for(i = 0 ; pt->files[i] != NULL ; i++) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
47 free(pt->files[i]); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
48 free(pt->files); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
49 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
50 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
51 free(pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
52 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
53 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
54 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
55 play_tree_free_list(play_tree_t* pt, int childs) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
56 play_tree_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
57 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
58 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
59 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
60 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
61 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
62 for(iter = pt ; iter->prev != NULL ; iter = iter->prev) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
63 /* NOTHING */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
64 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
65 for( ; iter != NULL ; iter = iter->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
66 play_tree_free(iter,childs); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
67 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
68 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
69 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
70 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
71 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
72 play_tree_append_entry(play_tree_t* pt, play_tree_t* entry) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
73 play_tree_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
74 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
75 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
76 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
77 assert(entry != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
78 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
79 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
80 if(pt == entry) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
81 return; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
82 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
83 for(iter = pt ; iter->next != NULL ; iter = iter->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
84 /* NOTHING */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
85 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
86 entry->parent = iter->parent; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
87 entry->prev = iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
88 entry->next = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
89 iter->next = entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
90 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
91 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
92 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
93 play_tree_prepend_entry(play_tree_t* pt, play_tree_t* entry) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
94 play_tree_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
95 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
96 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
97 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
98 assert(entry != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
99 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
100 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
101 for(iter = pt ; iter->prev != NULL; iter = iter->prev) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
102 /* NOTHING */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
103 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
104 entry->prev = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
105 entry->next = iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
106 entry->parent = iter->parent; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
107 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
108 iter->prev = entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
109 if(entry->parent) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
110 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
111 assert(entry->parent->child == iter); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
112 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
113 entry->parent->child = entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
114 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
115 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
116 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
117 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
118 play_tree_insert_entry(play_tree_t* pt, play_tree_t* entry) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
119 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
120 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
121 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
122 assert(entry != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
123 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
124 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
125 entry->parent = pt->parent; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
126 entry->prev = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
127 if(pt->next) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
128 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
129 assert(pt->next->prev == pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
130 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
131 entry->next = pt->next; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
132 entry->next->prev = entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
133 } else |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
134 entry->next = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
135 pt->next = entry; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
136 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
137 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
138 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
139 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
140 play_tree_remove(play_tree_t* pt, int free_it,int with_childs) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
141 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
142 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
143 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
144 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
145 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
146 // Middle of list |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
147 if(pt->prev && pt->next) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
148 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
149 assert(pt->prev->next == pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
150 assert(pt->next->prev == pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
151 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
152 pt->prev->next = pt->next; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
153 pt->next->prev = pt->prev; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
154 } // End of list |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
155 else if(pt->prev) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
156 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
157 assert(pt->prev->next == pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
158 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
159 pt->prev->next = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
160 } // Begining of list |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
161 else if(pt->next) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
162 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
163 assert(pt->next->prev == pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
164 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
165 pt->next->prev = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
166 if(pt->parent) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
167 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
168 assert(pt->parent->child == pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
169 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
170 pt->parent->child = pt->next; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
171 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
172 } // The only one |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
173 else if(pt->parent) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
174 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
175 assert(pt->parent->child == pt); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
176 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
177 pt->parent->child = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
178 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
179 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
180 pt->prev = pt->next = pt->parent = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
181 if(free_it) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
182 play_tree_free(pt,with_childs); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
183 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
184 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
185 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
186 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
187 play_tree_set_child(play_tree_t* pt, play_tree_t* child) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
188 play_tree_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
189 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
190 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
191 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
192 assert(pt->files == NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
193 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
194 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
195 for(iter = pt->child ; iter != NULL ; iter = iter->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
196 iter->parent = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
197 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
198 // Go back to first one |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
199 for(iter = child ; iter->prev != NULL ; iter = iter->prev) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
200 /* NOTHING */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
201 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
202 pt->child = iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
203 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
204 for( ; iter != NULL ; iter= iter->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
205 iter->parent = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
206 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
207 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
208 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
209 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
210 play_tree_set_parent(play_tree_t* pt, play_tree_t* parent) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
211 play_tree_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
212 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
213 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
214 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
215 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
216 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
217 if(pt->parent) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
218 pt->parent->child = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
219 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
220 for(iter = pt ; iter != NULL ; iter = iter->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
221 iter->parent = parent; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
222 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
223 if(pt->prev) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
224 for(iter = pt->prev ; iter->prev != NULL ; iter = iter->prev) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
225 iter->parent = parent; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
226 iter->parent = parent; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
227 parent->child = iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
228 } else |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
229 parent->child = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
230 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
231 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
232 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
233 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
234 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
235 play_tree_add_file(play_tree_t* pt,char* file) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
236 int n = 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
237 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
238 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
239 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
240 assert(pt->child == NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
241 assert(file != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
242 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
243 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
244 if(pt->files) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
245 for(n = 0 ; pt->files[n] != NULL ; n++) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
246 /* NOTHING */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
247 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
248 pt->files = (char**)realloc(pt->files,(n+2)*sizeof(char*)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
249 if(pt->files ==NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
250 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
251 return; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
252 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
253 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
254 pt->files[n] = strdup(file); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
255 pt->files[n+1] = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
256 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
257 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
258 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
259 int |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
260 play_tree_remove_file(play_tree_t* pt,char* file) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
261 int n,f = -1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
262 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
263 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
264 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
265 assert(file != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
266 assert(pt->files != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
267 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
268 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
269 for(n=0 ; pt->files[n] != NULL ; n++) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
270 if(strcmp(file,pt->files[n]) == 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
271 f = n; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
272 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
273 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
274 if(f < 0) // Not found |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
275 return 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
276 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
277 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
278 assert(n > f); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
279 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
280 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
281 free(pt->files[f]); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
282 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
283 if(n > 1) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
284 memmove(&pt->files[f],&pt->files[f+1],(n-f)*sizeof(char*)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
285 pt->files = (char**)realloc(pt->files,n*sizeof(char*)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
286 if(pt->files == NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
287 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",(n+2)*sizeof(char*)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
288 return -1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
289 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
290 } else { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
291 free(pt->files); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
292 pt->files = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
293 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
294 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
295 return 1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
296 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
297 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
298 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
299 play_tree_set_param(play_tree_t* pt, char* name, char* val) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
300 int n = 0,ni = -1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
301 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
302 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
303 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
304 assert(name != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
305 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
306 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
307 if(pt->params) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
308 for( ; pt->params[n].name != NULL ; n++) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
309 if(strcasecmp(pt->params[n].name,name) == 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
310 ni = n; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
311 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
312 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
313 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
314 if(ni > 0) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
315 if(pt->params[n].value != NULL) free(pt->params[n].value); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
316 pt->params[n].value = val; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
317 return; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
318 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
319 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
320 pt->params = (play_tree_param_t*)realloc(pt->params,(n+2)*sizeof(play_tree_param_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
321 pt->params[n].name = strdup(name); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
322 pt->params[n].value = val != NULL ? strdup(val) : NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
323 memset(&pt->params[n+1],0,sizeof(play_tree_param_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
324 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
325 return; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
326 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
327 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
328 int |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
329 play_tree_unset_param(play_tree_t* pt, char* name) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
330 int n,ni = -1; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
331 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
332 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
333 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
334 assert(name != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
335 assert(pt->params != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
336 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
337 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
338 for(n = 0 ; pt->params[n].name != NULL ; n++) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
339 if(strcasecmp(pt->params[n].name,name) == 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
340 ni = n; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
341 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
342 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
343 if(ni < 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
344 return 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
345 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
346 if(pt->params[ni].name) free(pt->params[ni].name); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
347 if(pt->params[ni].value) free(pt->params[ni].value); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
348 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
349 if(n > 1) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
350 memmove(&pt->params[ni],&pt->params[ni+1],(n-ni)*sizeof(play_tree_param_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
351 pt->params = (play_tree_param_t*)realloc(pt->params,n*sizeof(play_tree_param_t)); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
352 if(pt->params == NULL) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
353 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",n*sizeof(play_tree_param_t)); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
354 return -1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
355 } |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
356 } else { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
357 free(pt->params); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
358 pt->params = NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
359 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
360 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
361 return 1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
362 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
363 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
364 static int |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
365 play_tree_iter_push_params(play_tree_iter_t* iter) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
366 int n; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
367 play_tree_t* pt; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
368 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
369 assert(iter != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
370 assert(iter->config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
371 assert(iter->tree != NULL); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
372 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
373 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
374 pt = iter->tree; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
375 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
376 if(pt->params == NULL) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
377 return 0; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
378 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
379 m_config_push(iter->config); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
380 for(n = 0; pt->params[n].name != NULL ; n++) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
381 if(m_config_set_option(iter->config,pt->params[n].name,pt->params[n].value) < 0) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
382 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Error while setting option '%s' with value '%s'\n", |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
383 pt->params[n].name,pt->params[n].value); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
384 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
385 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
386 //printf("Param pushed\n"); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
387 return 1; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
388 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
389 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
390 static void |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
391 play_tree_iter_pop_params(play_tree_iter_t* iter) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
392 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
393 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
394 assert(iter != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
395 assert(iter->config != NULL); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
396 #endif |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
397 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
398 if(iter->tree->params == NULL) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
399 return; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
400 //printf("Poping params\n"); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
401 m_config_pop(iter->config); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
402 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
403 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
404 play_tree_iter_t* |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
405 play_tree_iter_new(play_tree_t* pt,m_config_t* config) { |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
406 play_tree_iter_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
407 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
408 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
409 assert(pt != NULL); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
410 assert(config != NULL); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
411 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
412 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
413 if( ! play_tree_is_valid(pt)) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
414 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
415 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
416 iter = (play_tree_iter_t*)calloc(1,sizeof(play_tree_iter_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
417 if(! iter) return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
418 iter->root = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
419 iter->tree = NULL; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
420 iter->config = config; |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
421 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
422 if(pt->parent) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
423 iter->loop = pt->parent->loop; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
424 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
425 return iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
426 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
427 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
428 void |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
429 play_tree_iter_free(play_tree_iter_t* iter) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
430 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
431 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
432 assert(iter != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
433 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
434 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
435 if(iter->status_stack) { |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
436 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
437 assert(iter->stack_size > 0); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
438 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
439 free(iter->status_stack); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
440 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
441 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
442 free(iter); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
443 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
444 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
445 int |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
446 play_tree_iter_step(play_tree_iter_t* iter, int d,int with_nodes) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
447 play_tree_t* pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
448 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
449 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
450 assert(iter != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
451 assert(iter->root != NULL); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
452 //printf("PT : Stepping = %d\n",d); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
453 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
454 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
455 if(iter->tree == NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
456 iter->tree = iter->root; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
457 return play_tree_iter_step(iter,0,with_nodes); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
458 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
459 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
460 if(iter->config && iter->entry_pushed) { |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
461 play_tree_iter_pop_params(iter); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
462 iter->entry_pushed = 0; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
463 } |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
464 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
465 iter->file = 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
466 if( d > 0 ) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
467 pt = iter->tree->next; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
468 else if(d < 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
469 pt = iter->tree->prev; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
470 else |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
471 pt = iter->tree; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
472 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
473 if(pt == NULL) { // No next |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
474 // Must we loop? |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
475 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) ) ) ) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
476 if(d > 0) { // Go back to the first one |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
477 for(pt = iter->tree ; pt->prev != NULL; pt = pt->prev) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
478 /* NOTHNG */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
479 if(iter->loop > 0) iter->loop--; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
480 } else if( d < 0 ) { // Or the last one |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
481 for(pt = iter->tree ; pt->next != NULL; pt = pt->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
482 /* NOTHNG */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
483 if(iter->loop >= 0 && iter->loop < iter->tree->parent->loop) iter->loop++; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
484 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
485 iter->tree = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
486 return play_tree_iter_step(iter,0,with_nodes); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
487 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
488 // Go up one level |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
489 return play_tree_iter_up_step(iter,d,with_nodes); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
490 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
491 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
492 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
493 // Is there any valid childs ? |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
494 if(pt->child && play_tree_is_valid(pt->child)) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
495 iter->tree = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
496 if(with_nodes) { // Stop on the node |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
497 return PLAY_TREE_ITER_NODE; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
498 } else // Or follow it |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
499 return play_tree_iter_down_step(iter,d,with_nodes); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
500 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
501 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
502 // Is it a valid enty ? |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
503 if(! play_tree_is_valid(pt)) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
504 if(d == 0) { // Can this happen ? |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
505 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"What to do now ???? Infinite loop if we continue\n"); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
506 return PLAY_TREE_ITER_ERROR; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
507 } // Not a valid entry : go to next one |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
508 return play_tree_iter_step(iter,d,with_nodes); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
509 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
510 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
511 #ifdef MP_DEBUG |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
512 assert(pt->files != NULL); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
513 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
514 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
515 iter->tree = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
516 for(d = 0 ; iter->tree->files[d] != NULL ; d++) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
517 /* NOTHING */; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
518 iter->num_files = d; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
519 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
520 if(iter->config) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
521 iter->entry_pushed = play_tree_iter_push_params(iter); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
522 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
523 return PLAY_TREE_ITER_ENTRY; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
524 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
525 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
526 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
527 static int |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
528 play_tree_is_valid(play_tree_t* pt) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
529 play_tree_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
530 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
531 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
532 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
533 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
534 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
535 if(pt->files != NULL) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
536 return 1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
537 else if (pt->child != NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
538 for(iter = pt->child ; iter != NULL ; iter = iter->next) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
539 if(play_tree_is_valid(iter)) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
540 return 1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
541 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
542 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
543 return 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
544 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
545 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
546 int |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
547 play_tree_iter_up_step(play_tree_iter_t* iter, int d,int with_nodes) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
548 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
549 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
550 assert(iter != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
551 assert(iter->tree != NULL); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
552 //printf("PT : Go UP\n"); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
553 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
554 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
555 iter->file = 0; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
556 if(iter->tree->parent == iter->root->parent) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
557 return PLAY_TREE_ITER_END; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
558 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
559 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
560 assert(iter->tree->parent != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
561 assert(iter->stack_size > 0); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
562 assert(iter->status_stack != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
563 #endif |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
564 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
565 iter->stack_size--; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
566 iter->loop = iter->status_stack[iter->stack_size]; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
567 iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
568 if(iter->stack_size > 0 && iter->status_stack == NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
569 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*sizeof(char*)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
570 return PLAY_TREE_ITER_ERROR; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
571 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
572 iter->tree = iter->tree->parent; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
573 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
574 // Pop subtree params |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
575 if(iter->config) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
576 play_tree_iter_pop_params(iter); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
577 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
578 return play_tree_iter_step(iter,d,with_nodes); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
579 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
580 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
581 int |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
582 play_tree_iter_down_step(play_tree_iter_t* iter, int d,int with_nodes) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
583 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
584 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
585 assert(iter->tree->files == NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
586 assert(iter->tree->child != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
587 assert(iter->tree->child->parent == iter->tree); |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
588 //printf("PT : Go DOWN\n"); |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
589 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
590 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
591 iter->file = 0; |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
592 |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
593 // Push subtree params |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
594 if(iter->config) |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
595 play_tree_iter_push_params(iter); |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
596 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
597 iter->stack_size++; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
598 iter->status_stack = (int*)realloc(iter->status_stack,iter->stack_size*sizeof(int)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
599 if(iter->status_stack == NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
600 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",iter->stack_size*sizeof(int)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
601 return PLAY_TREE_ITER_ERROR; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
602 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
603 iter->status_stack[iter->stack_size-1] = iter->loop; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
604 // Set new status |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
605 iter->loop = iter->tree->loop-1; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
606 if(d >= 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
607 iter->tree = iter->tree->child; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
608 else { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
609 play_tree_t* pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
610 for(pt = iter->tree->child ; pt->next != NULL ; pt = pt->next) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
611 /*NOTING*/; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
612 iter->tree = pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
613 } |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
614 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
615 return play_tree_iter_step(iter,0,with_nodes); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
616 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
617 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
618 char* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
619 play_tree_iter_get_file(play_tree_iter_t* iter, int d) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
620 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
621 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
622 assert(iter != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
623 assert(iter->tree->child == NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
624 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
625 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
626 if(iter->tree->files == NULL) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
627 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
628 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
629 if(d > 0) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
630 if(iter->tree->files[iter->file] == NULL) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
631 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
632 iter->file++; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
633 } else if(d < 0) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
634 if(iter->file == 0) |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
635 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
636 iter->file--; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
637 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
638 return iter->tree->files[iter->file-1]; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
639 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
640 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
641 play_tree_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
642 play_tree_cleanup(play_tree_t* pt) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
643 play_tree_t* iter, *tmp, *first; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
644 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
645 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
646 assert(pt != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
647 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
648 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
649 if( ! play_tree_is_valid(pt)) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
650 play_tree_remove(pt,1,1); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
651 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
652 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
653 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
654 first = pt->child; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
655 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
656 for(iter = pt->child ; iter != NULL ; ) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
657 tmp = iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
658 iter = iter->next; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
659 if(! play_tree_is_valid(tmp)) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
660 play_tree_remove(tmp,1,1); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
661 if(tmp == first) first = iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
662 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
663 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
664 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
665 for(iter = first ; iter != NULL ; ) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
666 tmp = iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
667 iter = iter->next; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
668 play_tree_cleanup(tmp); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
669 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
670 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
671 return pt; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
672 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
673 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
674 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
675 play_tree_iter_t* |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
676 play_tree_iter_new_copy(play_tree_iter_t* old) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
677 play_tree_iter_t* iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
678 |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
679 #ifdef MP_DEBUG |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
680 assert(old != NULL); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
681 #endif |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
682 |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
683 iter = (play_tree_iter_t*)malloc(sizeof(play_tree_iter_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
684 if(iter == NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
685 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",sizeof(play_tree_iter_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
686 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
687 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
688 ; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
689 memcpy(iter,old,sizeof(play_tree_iter_t)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
690 if(old->status_stack) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
691 iter->status_stack = (int*)malloc(old->stack_size * sizeof(int)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
692 if(iter->status_stack == NULL) { |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
693 mp_msg(MSGT_PLAYTREE,MSGL_ERR,"Can't allocate %d bytes of memory\n",old->stack_size * sizeof(int)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
694 free(iter); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
695 return NULL; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
696 } |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
697 memcpy(iter->status_stack,old->status_stack,iter->stack_size*sizeof(int)); |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
698 } |
4156
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
699 iter->config = NULL; |
22fadd4022b5
playtree-based config patch by Alban Bedel <albeu@free.fr>
arpi
parents:
4050
diff
changeset
|
700 |
4043
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
701 return iter; |
25590564842f
tree-based playlist parser code by Alban Bedel <albeu@free.fr>
arpi
parents:
diff
changeset
|
702 } |