annotate gui/util/list.c @ 37185:917a3c4c2d39

lavf: fix AVSEEK_SIZE when STREAM_CTRL_GET_SIZE is not implemented. Would set the size to an uninitialized value before.
author reimar
date Wed, 17 Sep 2014 17:49:54 +0000
parents ae4f30c4ef02
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
1 /*
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
2 * This file is part of MPlayer.
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
3 *
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
4 * MPlayer is free software; you can redistribute it and/or modify
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
5 * it under the terms of the GNU General Public License as published by
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
6 * the Free Software Foundation; either version 2 of the License, or
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
7 * (at your option) any later version.
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
8 *
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
9 * MPlayer is distributed in the hope that it will be useful,
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
12 * GNU General Public License for more details.
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
13 *
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License along
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
15 * with MPlayer; if not, write to the Free Software Foundation, Inc.,
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
17 */
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
18
34683
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
19 /**
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
20 * @file
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
21 * @brief List management
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
22 */
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
23
36772
0da6c7ff95d2 Revise code of listMgr() command PLAYLIST_ITEM_GET_POS.
ib
parents: 36155
diff changeset
24 #include <stdint.h>
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
25 #include <stdlib.h>
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
26 #include <string.h>
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
27
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
28 #include "list.h"
37066
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
29 #include "mem.h"
35530
cc6e25e348ee Cosmetic: Rearrange #includes.
ib
parents: 35525
diff changeset
30 #include "string.h"
35525
e27855a45128 Rebuild GUI directory structure.
ib
parents: 35493
diff changeset
31 #include "gui/app/gui.h"
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
32
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
33 #include "mp_msg.h"
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
34 #include "path.h"
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
35
34667
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
36 static plItem *plList;
34664
4df4d842d5fb Remove global variable pointing to current playlist item.
ib
parents: 34663
diff changeset
37 static plItem *plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
38
34668
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
39 static urlItem *urlList;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
40
34683
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
41 /**
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
42 * @brief Manage playlists and URL lists.
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
43 *
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
44 * @param cmd task to be performed
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
45 * @param data list item for the task
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
46 *
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
47 * @return pointer to top of list (GET command),
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
48 * pointer to current list item (ITEM command) or
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
49 * NULL (DELETE or unknown command)
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
50 *
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 36773
diff changeset
51 * @note PLAYLIST_ITEM_GET_POS returns the position number as pointer value
35487
58a221f73d75 Enhance PLAYLIST_ITEM_GET_POS to provide total number of items.
ib
parents: 35460
diff changeset
52 * (if @a data is NULL the last position number, i.e. number of items),
35458
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
53 * and position 0 means "not found"
34683
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
54 */
34610
4ff933a89818 Cosmetic: Rename functions in list.c.
ib
parents: 34602
diff changeset
55 void *listMgr(int cmd, void *data)
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
56 {
36772
0da6c7ff95d2 Revise code of listMgr() command PLAYLIST_ITEM_GET_POS.
ib
parents: 36155
diff changeset
57 uintptr_t pos;
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
58 plItem *pdat = (plItem *)data;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
59 urlItem *udat = (urlItem *)data;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
60
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
61 switch (cmd) {
34684
b03481253518 Cosmetic: Prefer C style for single line comments.
ib
parents: 34683
diff changeset
62 /* playlist */
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
63
34667
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
64 case PLAYLIST_GET:
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
65
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
66 return plList;
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
67
34681
42fa91951bd2 Rename PLAYLIST_ITEM_ADD PLAYLIST_ITEM_APPEND.
ib
parents: 34680
diff changeset
68 case PLAYLIST_ITEM_APPEND:
34674
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
69
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
70 if (plList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
71 plItem *item = plList;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
72
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
73 while (item->next)
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
74 item = item->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
75
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
76 item->next = pdat;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
77 pdat->prev = item;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
78 pdat->next = NULL;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
79 } else {
34674
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
80 pdat->next = pdat->prev = NULL;
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
81 plCurrent = plList = pdat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
82 }
34674
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
83
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
84 return plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
85
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
86 case PLAYLIST_ITEM_INSERT:
34675
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
87
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
88 if (plCurrent) {
34675
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
89 pdat->next = plCurrent->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
90
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
91 if (pdat->next)
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
92 pdat->next->prev = pdat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
93
34675
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
94 pdat->prev = plCurrent;
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
95 plCurrent->next = pdat;
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
96
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
97 plCurrent = pdat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
98
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
99 return plCurrent;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
100 } else
34681
42fa91951bd2 Rename PLAYLIST_ITEM_ADD PLAYLIST_ITEM_APPEND.
ib
parents: 34680
diff changeset
101 return listMgr(PLAYLIST_ITEM_APPEND, pdat);
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
102
35460
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
103 case PLAYLIST_ITEM_FIND:
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
104
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
105 if (plList) {
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
106 plItem *item = plList;
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
107
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
108 do {
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
109 if (gstrcmp(item->path, pdat->path) == 0 && gstrcmp(item->name, pdat->name) == 0)
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
110 return item;
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
111
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
112 item = item->next;
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
113 } while (item);
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
114 }
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
115
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
116 return NULL;
7d1d7f783975 Add listMgr command PLAYLIST_ITEM_FIND.
ib
parents: 35458
diff changeset
117
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
118 case PLAYLIST_ITEM_SET_CURR:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
119
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
120 plCurrent = pdat;
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
121 return plCurrent;
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
122
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
123 case PLAYLIST_ITEM_GET_CURR:
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
124
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
125 return plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
126
35458
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
127 case PLAYLIST_ITEM_GET_POS:
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
128
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
129 pos = 0;
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
130
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
131 if (plList) {
36772
0da6c7ff95d2 Revise code of listMgr() command PLAYLIST_ITEM_GET_POS.
ib
parents: 36155
diff changeset
132 uintptr_t i = 0;
36773
1d094f299aa0 Cosmetic: Adjust indent.
ib
parents: 36772
diff changeset
133 plItem *item = plList;
35458
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
134
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
135 do {
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
136 i++;
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
137
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
138 if (item == pdat) {
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
139 pos = i;
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
140 break;
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
141 }
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
142
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
143 item = item->next;
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
144 } while (item);
35487
58a221f73d75 Enhance PLAYLIST_ITEM_GET_POS to provide total number of items.
ib
parents: 35460
diff changeset
145
58a221f73d75 Enhance PLAYLIST_ITEM_GET_POS to provide total number of items.
ib
parents: 35460
diff changeset
146 if (!pdat)
58a221f73d75 Enhance PLAYLIST_ITEM_GET_POS to provide total number of items.
ib
parents: 35460
diff changeset
147 pos = i;
35458
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
148 }
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
149
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
150 return (void *)pos;
2a6113c08e20 Add listMgr command PLAYLIST_ITEM_GET_CURR_POS.
ib
parents: 35386
diff changeset
151
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
152 case PLAYLIST_ITEM_GET_PREV:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
153
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
154 if (plCurrent && plCurrent->prev) {
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
155 plCurrent = plCurrent->prev;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
156 return plCurrent;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
157 }
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
158
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
159 return NULL;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
160
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
161 case PLAYLIST_ITEM_GET_NEXT:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
162
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
163 if (plCurrent && plCurrent->next) {
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
164 plCurrent = plCurrent->next;
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
165 return plCurrent;
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
166 }
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
167
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
168 return NULL;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
169
35962
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
170 case PLAYLIST_ITEM_GET_LAST:
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
171
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
172 if (plList) {
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
173 plItem *item = plList;
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
174
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
175 while (item->next)
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
176 item = item->next;
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
177
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
178 return item;
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
179 }
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
180
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
181 return NULL;
df731f25759e Add new listMgr command PLAYLIST_ITEM_GET_LAST.
ib
parents: 35530
diff changeset
182
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
183 case PLAYLIST_ITEM_DEL_CURR:
34677
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
184
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
185 if (plCurrent) {
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
186 plItem *curr = plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
187
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
188 if (curr->prev)
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
189 curr->prev->next = curr->next;
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
190 if (curr->next)
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
191 curr->next->prev = curr->prev;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
192
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
193 plCurrent = curr->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
194
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
195 if (curr == plList)
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
196 plList = plCurrent;
34677
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
197
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
198 free(curr->path);
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
199 free(curr->name);
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
200 free(curr);
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
201 }
34677
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
202
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
203 return plCurrent;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
204
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
205 case PLAYLIST_DELETE:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
206
34602
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
207 while (plList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
208 plItem *item = plList->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
209
34602
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
210 free(plList->path);
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
211 free(plList->name);
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
212 free(plList);
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
213
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
214 plList = item;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
215 }
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
216
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
217 plCurrent = NULL;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
218 return NULL;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
219
34684
b03481253518 Cosmetic: Prefer C style for single line comments.
ib
parents: 34683
diff changeset
220 /* URL list */
34668
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
221
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
222 case URLLIST_GET:
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
223
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
224 return urlList;
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
225
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
226 case URLLIST_ITEM_ADD:
34679
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
227
33748
5860cfaff0a4 Cosmetic: Rename URLList urlList.
ib
parents: 33742
diff changeset
228 if (urlList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
229 urlItem *item = urlList;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
230
34679
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
231 while (item) {
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
232 if (strcmp(udat->url, item->url) == 0) {
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
233 free(udat->url);
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
234 free(udat);
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
235 return NULL;
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
236 }
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
237
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
238 if (item->next)
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
239 item = item->next;
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
240 else {
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
241 item->next = udat;
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
242 udat->next = NULL;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
243 break;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
244 }
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
245 }
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
246 } else {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
247 udat->next = NULL;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
248 urlList = udat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
249 }
34679
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
250
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
251 return udat;
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
252
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
253 case URLLIST_DELETE:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
254
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
255 while (urlList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
256 urlItem *item = urlList->next;
34601
f9b7f4b48fcb Fix bug in freeing URL list items.
ib
parents: 34599
diff changeset
257
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
258 free(urlList->url);
34601
f9b7f4b48fcb Fix bug in freeing URL list items.
ib
parents: 34599
diff changeset
259 free(urlList);
f9b7f4b48fcb Fix bug in freeing URL list items.
ib
parents: 34599
diff changeset
260
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
261 urlList = item;
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
262 }
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
263
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
264 return NULL;
34680
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
265
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
266 default:
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
267
34680
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
268 return NULL;
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
269 }
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
270 }
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
271
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
272 /**
37066
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
273 * @brief Free a string list.
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
274 *
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
275 * @param list pointer to the string list
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
276 */
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
277 void listFree(char ***list)
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
278 {
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
279 if (*list) {
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
280 char **l = *list;
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
281
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
282 while (*l) {
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
283 free(*l);
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
284 l++;
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
285 }
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
286
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
287 nfree(*list);
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
288 }
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
289 }
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
290
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
291 /**
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 36773
diff changeset
292 * @brief Set string list to @a entry.
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
293 *
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 36773
diff changeset
294 * @param list pointer to the string list
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
295 * @param entry the new (and only) element of the list
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
296 *
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
297 * @note Actually, a new list will be created and the old list will be freed.
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
298 */
34610
4ff933a89818 Cosmetic: Rename functions in list.c.
ib
parents: 34602
diff changeset
299 void listSet(char ***list, const char *entry)
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
300 {
37066
1843c6aaae4d Add listFree().
ib
parents: 37065
diff changeset
301 listFree(list);
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
302
34623
f8b848c178e5 Cosmetic: Adjust indent.
ib
parents: 34622
diff changeset
303 *list = malloc(2 * sizeof(char *));
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
304
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
305 if (*list) {
34623
f8b848c178e5 Cosmetic: Adjust indent.
ib
parents: 34622
diff changeset
306 (*list)[0] = gstrdup(entry);
f8b848c178e5 Cosmetic: Adjust indent.
ib
parents: 34622
diff changeset
307 (*list)[1] = NULL;
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
308 }
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
309 }
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
310
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
311 /**
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 36773
diff changeset
312 * @brief Replace the first element in a string list that starts with @a search.
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
313 *
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
314 * @note If no such element is found, @a replace will be appended.
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
315 *
37065
b28b632efeef Cosmetic: Revise a few comments.
ib
parents: 36773
diff changeset
316 * @param list pointer to the string list
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
317 * @param search element to search
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
318 * @param replace replacement element
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
319 */
34610
4ff933a89818 Cosmetic: Rename functions in list.c.
ib
parents: 34602
diff changeset
320 void listRepl(char ***list, const char *search, const char *replace)
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
321 {
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
322 int i = 0;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
323 char **org = *list;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
324
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
325 if (!replace)
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
326 return;
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
327
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
328 if (*list) {
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
329 size_t len = (search ? strlen(search) : 0);
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
330
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
331 for (i = 0; (*list)[i]; i++) {
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
332 if (gstrncmp((*list)[i], search, len) == 0) {
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
333 free((*list)[i]);
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
334 (*list)[i] = strdup(replace);
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
335 return;
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
336 }
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
337 }
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
338
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
339 *list = realloc(*list, (i + 2) * sizeof(char *));
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
340 } else
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
341 *list = malloc(2 * sizeof(char *));
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
342
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
343 if (!*list) {
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
344 *list = org;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
345 return;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
346 }
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
347
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
348 (*list)[i] = strdup(replace);
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
349 (*list)[i + 1] = NULL;
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
350 }
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
351
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
352 /**
37067
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
353 * @brief Duplicate a string list (by allocating new memory).
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
354 *
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
355 * @note The list must be NULL-terminated.
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
356 *
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
357 * @param list string list to be duplicated
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
358 *
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
359 * @return duplicated list
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
360 */
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
361 char **listDup(const char *const *list)
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
362 {
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
363 char **dup = NULL;
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
364
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
365 if (list) {
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
366 int i = 0;
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
367
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
368 while (list[i])
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
369 i++;
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
370
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
371 dup = calloc(i + 1, sizeof(char *));
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
372
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
373 if (dup) {
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
374 while (--i >= 0)
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
375 dup[i] = strdup(list[i]);
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
376 }
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
377 }
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
378
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
379 return dup;
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
380 }
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
381
b03e0fd957fd Add listDup().
ib
parents: 37066
diff changeset
382 /**
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
383 * @brief Append or insert a file to the playlist.
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
384 *
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
385 * @param what file to be added
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
386 * @param how command (#PLAYLIST_ITEM_APPEND or #PLAYLIST_ITEM_INSERT) to be performed
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
387 *
35493
411875efca3f Introduce boolean symbolic constants.
ib
parents: 35487
diff changeset
388 * @return #True (ok) or #False (error)
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
389 */
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
390 int add_to_gui_playlist(const char *what, int how)
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
391 {
35378
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
392 const char *file;
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
393 char *path;
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
394 plItem *item;
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
395
35386
ef2d3b306d6e Check for a non-empty filename.
ib
parents: 35378
diff changeset
396 if (!what || !*what || (how != PLAYLIST_ITEM_APPEND && how != PLAYLIST_ITEM_INSERT))
35493
411875efca3f Introduce boolean symbolic constants.
ib
parents: 35487
diff changeset
397 return False;
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
398
35378
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
399 file = mp_basename(what);
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
400 path = strdup(what);
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
401
36154
319cbb4d0967 Check return value to avoid segmentation fault.
ib
parents: 35962
diff changeset
402 if (!path)
319cbb4d0967 Check return value to avoid segmentation fault.
ib
parents: 35962
diff changeset
403 return False;
319cbb4d0967 Check return value to avoid segmentation fault.
ib
parents: 35962
diff changeset
404
35378
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
405 if (file > what)
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
406 path[file - what - 1] = 0;
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
407 else
35378
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
408 strcpy(path, ".");
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
409
37083
ae4f30c4ef02 Determine size from variable declaration.
ib
parents: 37067
diff changeset
410 item = calloc(1, sizeof(*item));
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
411
36155
29c690aefc6f Fix resource leak.
ib
parents: 36154
diff changeset
412 if (!item) {
29c690aefc6f Fix resource leak.
ib
parents: 36154
diff changeset
413 free(path);
35493
411875efca3f Introduce boolean symbolic constants.
ib
parents: 35487
diff changeset
414 return False;
36155
29c690aefc6f Fix resource leak.
ib
parents: 36154
diff changeset
415 }
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
416
35378
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
417 mp_msg(MSGT_GPLAYER, MSGL_DBG2, "[list] adding %s/%s\n", path, file);
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
418
35378
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
419 item->name = strdup(file);
e900dc6b8d66 Improve add_to_gui_playlist().
ib
parents: 35376
diff changeset
420 item->path = path;
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
421
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
422 listMgr(how, item);
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
423
35493
411875efca3f Introduce boolean symbolic constants.
ib
parents: 35487
diff changeset
424 return True;
35376
02006c5b3b30 Move add_to_gui_playlist() to util/list.c.
ib
parents: 34684
diff changeset
425 }