annotate gui/util/list.c @ 35362:848ca0b6d5ca

Prevent floating point exception. In case of a dynamic label with no text and width zero there will be a modulo by zero.
author ib
date Fri, 23 Nov 2012 12:30:44 +0000
parents b03481253518
children 02006c5b3b30
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
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
24 #include <stdlib.h>
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
25 #include <string.h>
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
26
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
27 #include "list.h"
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
28 #include "string.h"
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
29
34667
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
30 static plItem *plList;
34664
4df4d842d5fb Remove global variable pointing to current playlist item.
ib
parents: 34663
diff changeset
31 static plItem *plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
32
34668
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
33 static urlItem *urlList;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
34
34683
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
35 /**
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
36 * @brief Manage playlists and URL lists.
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
37 *
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
38 * @param cmd task to be performed
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
39 * @param data list item for the task
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
40 *
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
41 * @return pointer to top of list (GET command),
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
42 * pointer to current list item (ITEM command) or
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
43 * NULL (DELETE or unknown command)
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
44 *
621058eff80f Add doxygen comments to list.c.
ib
parents: 34682
diff changeset
45 */
34610
4ff933a89818 Cosmetic: Rename functions in list.c.
ib
parents: 34602
diff changeset
46 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
47 {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
48 plItem *pdat = (plItem *)data;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
49 urlItem *udat = (urlItem *)data;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
50
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
51 switch (cmd) {
34684
b03481253518 Cosmetic: Prefer C style for single line comments.
ib
parents: 34683
diff changeset
52 /* playlist */
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
53
34667
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
54 case PLAYLIST_GET:
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
55
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
56 return plList;
7c447e9db447 Remove global variable pointing to top of playlist.
ib
parents: 34664
diff changeset
57
34681
42fa91951bd2 Rename PLAYLIST_ITEM_ADD PLAYLIST_ITEM_APPEND.
ib
parents: 34680
diff changeset
58 case PLAYLIST_ITEM_APPEND:
34674
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
59
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
60 if (plList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
61 plItem *item = plList;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
62
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
63 while (item->next)
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
64 item = item->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
65
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
66 item->next = pdat;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
67 pdat->prev = item;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
68 pdat->next = NULL;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
69 } else {
34674
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
70 pdat->next = pdat->prev = NULL;
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
71 plCurrent = plList = pdat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
72 }
34674
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
73
a99f159b137d Revise listMgr() command PLAYLIST_ITEM_ADD.
ib
parents: 34673
diff changeset
74 return plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
75
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
76 case PLAYLIST_ITEM_INSERT:
34675
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
77
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
78 if (plCurrent) {
34675
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
79 pdat->next = plCurrent->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
80
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
81 if (pdat->next)
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
82 pdat->next->prev = pdat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
83
34675
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
84 pdat->prev = plCurrent;
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
85 plCurrent->next = pdat;
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
86
45b2c7bbec60 Revise listMgr() command PLAYLIST_ITEM_INSERT.
ib
parents: 34674
diff changeset
87 plCurrent = pdat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
88
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
89 return plCurrent;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
90 } else
34681
42fa91951bd2 Rename PLAYLIST_ITEM_ADD PLAYLIST_ITEM_APPEND.
ib
parents: 34680
diff changeset
91 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
92
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
93 case PLAYLIST_ITEM_SET_CURR:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
94
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
95 plCurrent = pdat;
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
96 return plCurrent;
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
97
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
98 case PLAYLIST_ITEM_GET_CURR:
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
99
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
100 return plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
101
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
102 case PLAYLIST_ITEM_GET_PREV:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
103
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
104 if (plCurrent && plCurrent->prev) {
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
105 plCurrent = plCurrent->prev;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
106 return plCurrent;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
107 }
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
108
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
109 return NULL;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
110
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
111 case PLAYLIST_ITEM_GET_NEXT:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
112
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
113 if (plCurrent && plCurrent->next) {
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
114 plCurrent = plCurrent->next;
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
115 return plCurrent;
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
116 }
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
117
34682
c3ab7bd64ab3 Cosmetic: Arrange listMgr() commands in switch statement.
ib
parents: 34681
diff changeset
118 return NULL;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
119
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
120 case PLAYLIST_ITEM_DEL_CURR:
34677
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
121
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
122 if (plCurrent) {
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
123 plItem *curr = plCurrent;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
124
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
125 if (curr->prev)
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
126 curr->prev->next = curr->next;
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
127 if (curr->next)
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
128 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
129
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
130 plCurrent = curr->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
131
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
132 if (curr == plList)
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
133 plList = plCurrent;
34677
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
134
34678
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
135 free(curr->path);
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
136 free(curr->name);
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
137 free(curr);
23f4f2104774 Cosmetic: Adjust indent.
ib
parents: 34677
diff changeset
138 }
34677
d3f65dd58eb9 Revise listMgr() command PLAYLIST_ITEM_DEL_CURR.
ib
parents: 34676
diff changeset
139
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
140 return plCurrent;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
141
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
142 case PLAYLIST_DELETE:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
143
34602
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
144 while (plList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
145 plItem *item = plList->next;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
146
34602
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
147 free(plList->path);
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
148 free(plList->name);
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
149 free(plList);
a5d0652dd1a0 Fix bug in freeing playlist items.
ib
parents: 34601
diff changeset
150
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
151 plList = item;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
152 }
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 plCurrent = NULL;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
155 return NULL;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
156
34684
b03481253518 Cosmetic: Prefer C style for single line comments.
ib
parents: 34683
diff changeset
157 /* URL list */
34668
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
158
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
159 case URLLIST_GET:
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
160
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
161 return urlList;
00e8aecfa7ff Remove global variable pointing to top of URL list.
ib
parents: 34667
diff changeset
162
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
163 case URLLIST_ITEM_ADD:
34679
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
164
33748
5860cfaff0a4 Cosmetic: Rename URLList urlList.
ib
parents: 33742
diff changeset
165 if (urlList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
166 urlItem *item = urlList;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
167
34679
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
168 while (item) {
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
169 if (strcmp(udat->url, item->url) == 0) {
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
170 free(udat->url);
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
171 free(udat);
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
172 return NULL;
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
173 }
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
174
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
175 if (item->next)
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
176 item = item->next;
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
177 else {
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
178 item->next = udat;
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
179 udat->next = NULL;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
180 break;
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
181 }
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
182 }
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
183 } else {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
184 udat->next = NULL;
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
185 urlList = udat;
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
186 }
34679
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
187
6378e3a2ffb8 Revise listMgr() command URLLIST_ITEM_ADD.
ib
parents: 34678
diff changeset
188 return udat;
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
189
34663
73a5ecb53ee2 Replace symbolic constants by enums.
ib
parents: 34627
diff changeset
190 case URLLIST_DELETE:
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
191
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
192 while (urlList) {
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
193 urlItem *item = urlList->next;
34601
f9b7f4b48fcb Fix bug in freeing URL list items.
ib
parents: 34599
diff changeset
194
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
195 free(urlList->url);
34601
f9b7f4b48fcb Fix bug in freeing URL list items.
ib
parents: 34599
diff changeset
196 free(urlList);
f9b7f4b48fcb Fix bug in freeing URL list items.
ib
parents: 34599
diff changeset
197
34673
ea1df3e51d3f Cosmetic: Rename variables in listMgr().
ib
parents: 34670
diff changeset
198 urlList = item;
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
199 }
34676
207272df4aef Cosmetic: Insert some blank lines and remove commented code.
ib
parents: 34675
diff changeset
200
34599
80246b016caf Add code to free the URL list items.
ib
parents: 33748
diff changeset
201 return NULL;
34680
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
202
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
203 default:
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
204
34680
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
205 return NULL;
f49f6501eb8b Add a default clause to listMgr()'s switch statement.
ib
parents: 34679
diff changeset
206 }
33742
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
207 }
e1539e14d60f Move purely list related parts of gtkSet() from interface.c to list.c.
ib
parents: 33741
diff changeset
208
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
209 /**
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
210 * @brief Set list to @a entry.
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
211 *
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
212 * @param list pointer to the char pointer list
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
213 * @param entry the new (and only) element of the list
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
214 *
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
215 * @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
216 */
34610
4ff933a89818 Cosmetic: Rename functions in list.c.
ib
parents: 34602
diff changeset
217 void listSet(char ***list, const char *entry)
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
218 {
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
219 if (*list) {
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
220 char **l = *list;
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
221
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
222 while (*l) {
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
223 free(*l);
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
224 l++;
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
225 }
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
226
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
227 free(*list);
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
228 }
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
229
34623
f8b848c178e5 Cosmetic: Adjust indent.
ib
parents: 34622
diff changeset
230 *list = malloc(2 * sizeof(char *));
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
231
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
232 if (*list) {
34623
f8b848c178e5 Cosmetic: Adjust indent.
ib
parents: 34622
diff changeset
233 (*list)[0] = gstrdup(entry);
f8b848c178e5 Cosmetic: Adjust indent.
ib
parents: 34622
diff changeset
234 (*list)[1] = NULL;
34622
e96ee4cac59f Revise listSet().
ib
parents: 34610
diff changeset
235 }
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
236 }
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
237
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
238 /**
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
239 * @brief Replace the first element in list that starts with @a search.
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
240 *
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
241 * @note If no such element is found, @a replace will be appended.
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
242 *
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
243 * @param list pointer to the char pointer list
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
244 * @param search element to search
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
245 * @param replace replacement element
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
246 */
34610
4ff933a89818 Cosmetic: Rename functions in list.c.
ib
parents: 34602
diff changeset
247 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
248 {
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
249 int i = 0;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
250 char **org = *list;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
251
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
252 if (!replace)
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
253 return;
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
254
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
255 if (*list) {
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
256 size_t len = (search ? strlen(search) : 0);
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
257
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
258 for (i = 0; (*list)[i]; i++) {
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
259 if (gstrncmp((*list)[i], search, len) == 0) {
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
260 free((*list)[i]);
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
261 (*list)[i] = strdup(replace);
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
262 return;
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
263 }
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
264 }
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
265
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
266 *list = realloc(*list, (i + 2) * sizeof(char *));
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
267 } else
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
268 *list = malloc(2 * sizeof(char *));
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
269
34627
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
270 if (!*list) {
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
271 *list = org;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
272 return;
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
273 }
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
274
3482045da618 Revise listRepl().
ib
parents: 34623
diff changeset
275 (*list)[i] = strdup(replace);
33741
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
276 (*list)[i + 1] = NULL;
962dc701989d Create new file list.c for list related functions.
ib
parents:
diff changeset
277 }