Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
M
mpd
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Иван Мажукин
mpd
Commits
ac3ad452
Commit
ac3ad452
authored
Feb 12, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
playlist_vector: use the list_head library
parent
027c0151
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
57 additions
and
80 deletions
+57
-80
db_print.c
src/db_print.c
+1
-0
directory.c
src/directory.c
+5
-5
directory.h
src/directory.h
+8
-3
playlist_database.c
src/playlist_database.c
+4
-4
playlist_database.h
src/playlist_database.h
+3
-3
playlist_vector.c
src/playlist_vector.c
+18
-37
playlist_vector.h
src/playlist_vector.h
+14
-22
update_db.c
src/update_db.c
+1
-0
update_walk.c
src/update_walk.c
+3
-6
No files found.
src/db_print.c
View file @
ac3ad452
...
...
@@ -27,6 +27,7 @@
#include "client.h"
#include "song.h"
#include "song_print.h"
#include "playlist_vector.h"
#include "tag.h"
#include "strset.h"
...
...
src/directory.c
View file @
ac3ad452
...
...
@@ -21,6 +21,7 @@
#include "directory.h"
#include "song.h"
#include "song_sort.h"
#include "playlist_vector.h"
#include "path.h"
#include "util/list_sort.h"
#include "db_visitor.h"
...
...
@@ -45,11 +46,11 @@ directory_new(const char *path, struct directory *parent)
sizeof
(
directory
->
path
)
+
pathlen
+
1
);
INIT_LIST_HEAD
(
&
directory
->
children
);
INIT_LIST_HEAD
(
&
directory
->
songs
);
INIT_LIST_HEAD
(
&
directory
->
playlists
);
directory
->
parent
=
parent
;
memcpy
(
directory
->
path
,
path
,
pathlen
+
1
);
playlist_vector_init
(
&
directory
->
playlists
);
return
directory
;
}
...
...
@@ -282,9 +283,8 @@ directory_walk(const struct directory *directory, bool recursive,
}
if
(
visitor
->
playlist
!=
NULL
)
{
const
struct
playlist_vector
*
pv
=
&
directory
->
playlists
;
for
(
const
struct
playlist_metadata
*
i
=
pv
->
head
;
i
!=
NULL
;
i
=
i
->
next
)
struct
playlist_metadata
*
i
;
directory_for_each_playlist
(
i
,
directory
)
if
(
!
visitor
->
playlist
(
i
,
directory
,
ctx
,
error_r
))
return
false
;
}
...
...
src/directory.h
View file @
ac3ad452
...
...
@@ -22,7 +22,6 @@
#include "check.h"
#include "util/list.h"
#include "playlist_vector.h"
#include <glib.h>
#include <stdbool.h>
...
...
@@ -45,6 +44,12 @@
#define directory_for_each_song_safe(pos, n, directory) \
list_for_each_entry_safe(pos, n, &directory->songs, siblings)
#define directory_for_each_playlist(pos, directory) \
list_for_each_entry(pos, &directory->playlists, siblings)
#define directory_for_each_playlist_safe(pos, n, directory) \
list_for_each_entry_safe(pos, n, &directory->playlists, siblings)
struct
song
;
struct
db_visitor
;
...
...
@@ -75,7 +80,7 @@ struct directory {
*/
struct
list_head
songs
;
struct
playlist_vector
playlists
;
struct
list_head
playlists
;
struct
directory
*
parent
;
time_t
mtime
;
...
...
@@ -129,7 +134,7 @@ directory_is_empty(const struct directory *directory)
{
return
list_empty
(
&
directory
->
children
)
&&
list_empty
(
&
directory
->
songs
)
&&
playlist_vector_is
_empty
(
&
directory
->
playlists
);
list
_empty
(
&
directory
->
playlists
);
}
static
inline
const
char
*
...
...
src/playlist_database.c
View file @
ac3ad452
...
...
@@ -33,10 +33,10 @@ playlist_database_quark(void)
}
void
playlist_vector_save
(
FILE
*
fp
,
const
struct
playlist_vector
*
pv
)
playlist_vector_save
(
FILE
*
fp
,
const
struct
list_head
*
pv
)
{
for
(
const
struct
playlist_metadata
*
pm
=
pv
->
head
;
pm
!=
NULL
;
pm
=
pm
->
next
)
struct
playlist_metadata
*
pm
;
playlist_vector_for_each
(
pm
,
pv
)
fprintf
(
fp
,
PLAYLIST_META_BEGIN
"%s
\n
"
"mtime: %li
\n
"
"playlist_end
\n
"
,
...
...
@@ -44,7 +44,7 @@ playlist_vector_save(FILE *fp, const struct playlist_vector *pv)
}
bool
playlist_metadata_load
(
FILE
*
fp
,
struct
playlist_vector
*
pv
,
const
char
*
name
,
playlist_metadata_load
(
FILE
*
fp
,
struct
list_head
*
pv
,
const
char
*
name
,
GString
*
buffer
,
GError
**
error_r
)
{
struct
playlist_metadata
pm
=
{
...
...
src/playlist_database.h
View file @
ac3ad452
...
...
@@ -28,13 +28,13 @@
#define PLAYLIST_META_BEGIN "playlist_begin: "
struct
playlist_vector
;
struct
list_head
;
void
playlist_vector_save
(
FILE
*
fp
,
const
struct
playlist_vector
*
pv
);
playlist_vector_save
(
FILE
*
fp
,
const
struct
list_head
*
pv
);
bool
playlist_metadata_load
(
FILE
*
fp
,
struct
playlist_vector
*
pv
,
const
char
*
name
,
playlist_metadata_load
(
FILE
*
fp
,
struct
list_head
*
pv
,
const
char
*
name
,
GString
*
buffer
,
GError
**
error_r
);
#endif
src/playlist_vector.c
View file @
ac3ad452
...
...
@@ -46,60 +46,43 @@ playlist_metadata_free(struct playlist_metadata *pm)
}
void
playlist_vector_deinit
(
struct
playlist_vector
*
pv
)
playlist_vector_deinit
(
struct
list_head
*
pv
)
{
assert
(
pv
!=
NULL
);
while
(
pv
->
head
!=
NULL
)
{
struct
playlist_metadata
*
pm
=
pv
->
head
;
pv
->
head
=
pm
->
next
;
struct
playlist_metadata
*
pm
,
*
n
;
playlist_vector_for_each_safe
(
pm
,
n
,
pv
)
playlist_metadata_free
(
pm
);
}
}
st
atic
struct
playlist_metadata
*
*
playlist_vector_find
_p
(
struct
playlist_vector
*
pv
,
const
char
*
name
)
st
ruct
playlist_metadata
*
playlist_vector_find
(
struct
list_head
*
pv
,
const
char
*
name
)
{
assert
(
pv
!=
NULL
);
assert
(
name
!=
NULL
);
struct
playlist_metadata
**
pmp
=
&
pv
->
head
;
for
(;;)
{
struct
playlist_metadata
*
pm
=
*
pmp
;
if
(
pm
==
NULL
)
return
NULL
;
struct
playlist_metadata
*
pm
;
playlist_vector_for_each
(
pm
,
pv
)
if
(
strcmp
(
pm
->
name
,
name
)
==
0
)
return
pmp
;
pmp
=
&
pm
->
next
;
}
}
return
pm
;
struct
playlist_metadata
*
playlist_vector_find
(
struct
playlist_vector
*
pv
,
const
char
*
name
)
{
struct
playlist_metadata
**
pmp
=
playlist_vector_find_p
(
pv
,
name
);
return
pmp
!=
NULL
?
*
pmp
:
NULL
;
return
NULL
;
}
void
playlist_vector_add
(
struct
playlist_vector
*
pv
,
playlist_vector_add
(
struct
list_head
*
pv
,
const
char
*
name
,
time_t
mtime
)
{
struct
playlist_metadata
*
pm
=
playlist_metadata_new
(
name
,
mtime
);
pm
->
next
=
pv
->
head
;
pv
->
head
=
pm
;
list_add
(
&
pm
->
siblings
,
pv
);
}
bool
playlist_vector_update_or_add
(
struct
playlist_vector
*
pv
,
playlist_vector_update_or_add
(
struct
list_head
*
pv
,
const
char
*
name
,
time_t
mtime
)
{
struct
playlist_metadata
**
pmp
=
playlist_vector_find_p
(
pv
,
name
);
if
(
pmp
!=
NULL
)
{
struct
playlist_metadata
*
pm
=
*
pmp
;
struct
playlist_metadata
*
pm
=
playlist_vector_find
(
pv
,
name
);
if
(
pm
!=
NULL
)
{
if
(
mtime
==
pm
->
mtime
)
return
false
;
...
...
@@ -111,15 +94,13 @@ playlist_vector_update_or_add(struct playlist_vector *pv,
}
bool
playlist_vector_remove
(
struct
playlist_vector
*
pv
,
const
char
*
name
)
playlist_vector_remove
(
struct
list_head
*
pv
,
const
char
*
name
)
{
struct
playlist_metadata
*
*
pmp
=
playlist_vector_find_p
(
pv
,
name
);
if
(
pm
p
==
NULL
)
struct
playlist_metadata
*
pm
=
playlist_vector_find
(
pv
,
name
);
if
(
pm
==
NULL
)
return
false
;
struct
playlist_metadata
*
pm
=
*
pmp
;
*
pmp
=
pm
->
next
;
list_del
(
&
pm
->
siblings
);
playlist_metadata_free
(
pm
);
return
true
;
}
src/playlist_vector.h
View file @
ac3ad452
...
...
@@ -20,15 +20,23 @@
#ifndef MPD_PLAYLIST_VECTOR_H
#define MPD_PLAYLIST_VECTOR_H
#include "util/list.h"
#include <stdbool.h>
#include <stddef.h>
#include <sys/time.h>
#define playlist_vector_for_each(pos, head) \
list_for_each_entry(pos, head, siblings)
#define playlist_vector_for_each_safe(pos, n, head) \
list_for_each_entry_safe(pos, n, head, siblings)
/**
* A directory entry pointing to a playlist file.
*/
struct
playlist_metadata
{
struct
playlist_metadata
*
next
;
struct
list_head
siblings
;
/**
* The UTF-8 encoded name of the playlist file.
...
...
@@ -38,40 +46,24 @@ struct playlist_metadata {
time_t
mtime
;
};
struct
playlist_vector
{
struct
playlist_metadata
*
head
;
};
static
inline
void
playlist_vector_init
(
struct
playlist_vector
*
pv
)
{
pv
->
head
=
NULL
;
}
void
playlist_vector_deinit
(
struct
playlist_vector
*
pv
);
static
inline
bool
playlist_vector_is_empty
(
const
struct
playlist_vector
*
pv
)
{
return
pv
->
head
==
NULL
;
}
playlist_vector_deinit
(
struct
list_head
*
pv
);
struct
playlist_metadata
*
playlist_vector_find
(
struct
playlist_vector
*
pv
,
const
char
*
name
);
playlist_vector_find
(
struct
list_head
*
pv
,
const
char
*
name
);
void
playlist_vector_add
(
struct
playlist_vector
*
pv
,
playlist_vector_add
(
struct
list_head
*
pv
,
const
char
*
name
,
time_t
mtime
);
/**
* @return true if the vector or one of its items was modified
*/
bool
playlist_vector_update_or_add
(
struct
playlist_vector
*
pv
,
playlist_vector_update_or_add
(
struct
list_head
*
pv
,
const
char
*
name
,
time_t
mtime
);
bool
playlist_vector_remove
(
struct
playlist_vector
*
pv
,
const
char
*
name
);
playlist_vector_remove
(
struct
list_head
*
pv
,
const
char
*
name
);
#endif
/* SONGVEC_H */
src/update_db.c
View file @
ac3ad452
...
...
@@ -22,6 +22,7 @@
#include "update_remove.h"
#include "directory.h"
#include "song.h"
#include "playlist_vector.h"
#include "db_lock.h"
#include <glib.h>
...
...
src/update_walk.c
View file @
ac3ad452
...
...
@@ -26,6 +26,7 @@
#include "exclude.h"
#include "directory.h"
#include "song.h"
#include "playlist_vector.h"
#include "uri.h"
#include "mapper.h"
#include "path.h"
...
...
@@ -159,14 +160,10 @@ removeDeletedFromDirectory(struct directory *directory)
g_free
(
path
);
}
for
(
const
struct
playlist_metadata
*
pm
=
directory
->
playlists
.
head
;
pm
!=
NULL
;)
{
const
struct
playlist_metadata
*
next
=
pm
->
next
;
struct
playlist_metadata
*
pm
,
*
np
;
directory_for_each_playlist_safe
(
pm
,
np
,
directory
)
{
if
(
!
directory_child_is_regular
(
directory
,
pm
->
name
))
playlist_vector_remove
(
&
directory
->
playlists
,
pm
->
name
);
pm
=
next
;
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment