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
08237111
Commit
08237111
authored
Aug 07, 2012
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
locate: add a per-item "fold_case" flag
Merge locate_song_search() and locate_song_match().
parent
860e9eb8
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
55 additions
and
179 deletions
+55
-179
DatabaseCommands.cxx
src/DatabaseCommands.cxx
+5
-5
DatabasePlaylist.cxx
src/DatabasePlaylist.cxx
+1
-1
DatabasePrint.cxx
src/DatabasePrint.cxx
+3
-25
DatabasePrint.hxx
src/DatabasePrint.hxx
+0
-6
DatabaseQueue.cxx
src/DatabaseQueue.cxx
+1
-22
DatabaseQueue.hxx
src/DatabaseQueue.hxx
+0
-5
command.c
src/command.c
+1
-1
locate.c
src/locate.c
+41
-75
locate.h
src/locate.h
+2
-8
playlist_print.c
src/playlist_print.c
+0
-7
playlist_print.h
src/playlist_print.h
+0
-7
queue_print.c
src/queue_print.c
+1
-13
queue_print.h
src/queue_print.h
+0
-4
No files found.
src/DatabaseCommands.cxx
View file @
08237111
...
...
@@ -110,7 +110,7 @@ handle_search(struct client *client, int argc, char *argv[])
}
GError
*
error
=
NULL
;
enum
command_return
ret
=
searchFor
SongsIn
(
client
,
""
,
list
,
&
error
)
enum
command_return
ret
=
find
SongsIn
(
client
,
""
,
list
,
&
error
)
?
COMMAND_RETURN_OK
:
print_error
(
client
,
error
);
...
...
@@ -131,8 +131,8 @@ handle_searchadd(struct client *client, int argc, char *argv[])
}
GError
*
error
=
NULL
;
enum
command_return
ret
=
search_add_songs
(
client
->
player_control
,
""
,
list
,
&
error
)
enum
command_return
ret
=
findAddIn
(
client
->
player_control
,
""
,
list
,
&
error
)
?
COMMAND_RETURN_OK
:
print_error
(
client
,
error
);
...
...
@@ -205,9 +205,9 @@ enum command_return
handle_list
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
struct
locate_item_list
*
conditionals
;
int
tagType
=
locate_parse_type
(
argv
[
1
]);
unsigned
tagType
=
locate_parse_type
(
argv
[
1
]);
if
(
tagType
<
0
)
{
if
(
tagType
==
TAG_NUM_OF_ITEM_TYPES
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"
\"
%s
\"
is not known"
,
argv
[
1
]);
return
COMMAND_RETURN_ERROR
;
}
...
...
src/DatabasePlaylist.cxx
View file @
08237111
...
...
@@ -55,7 +55,7 @@ SearchAddSong(const char *playlist_path_utf8,
const
struct
locate_item_list
*
criteria
,
song
&
song
,
GError
**
error_r
)
{
return
!
locate_
song_sear
ch
(
&
song
,
criteria
)
||
return
!
locate_
list_song_mat
ch
(
&
song
,
criteria
)
||
spl_append_song
(
playlist_path_utf8
,
&
song
,
error_r
);
}
...
...
src/DatabasePrint.cxx
View file @
08237111
...
...
@@ -139,32 +139,10 @@ db_selection_print(struct client *client, const DatabaseSelection &selection,
}
static
bool
SearchPrintSong
(
struct
client
*
client
,
const
struct
locate_item_list
*
criteria
,
song
&
song
)
{
if
(
locate_song_search
(
&
song
,
criteria
))
song_print_info
(
client
,
&
song
);
return
true
;
}
bool
searchForSongsIn
(
struct
client
*
client
,
const
char
*
uri
,
const
struct
locate_item_list
*
criteria
,
GError
**
error_r
)
{
const
DatabaseSelection
selection
(
uri
,
true
);
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
SearchPrintSong
,
client
,
criteria
,
_1
);
return
GetDatabase
()
->
Visit
(
selection
,
f
,
error_r
);
}
static
bool
MatchPrintSong
(
struct
client
*
client
,
const
struct
locate_item_list
*
criteria
,
song
&
song
)
{
if
(
locate_song_match
(
&
song
,
criteria
))
if
(
locate_
list_
song_match
(
&
song
,
criteria
))
song_print_info
(
client
,
&
song
);
return
true
;
...
...
@@ -197,7 +175,7 @@ static bool
stats_visitor_song
(
SearchStats
&
stats
,
const
struct
locate_item_list
*
criteria
,
song
&
song
)
{
if
(
locate_song_match
(
&
song
,
criteria
))
{
if
(
locate_
list_
song_match
(
&
song
,
criteria
))
{
stats
.
numberOfSongs
++
;
stats
.
playTime
+=
song_get_duration
(
&
song
);
}
...
...
@@ -282,7 +260,7 @@ unique_tags_visitor_song(struct client *client,
const
struct
locate_item_list
*
criteria
,
StringSet
&
set
,
song
&
song
)
{
if
(
locate_song_match
(
&
song
,
criteria
))
if
(
locate_
list_
song_match
(
&
song
,
criteria
))
visitTag
(
client
,
set
,
song
,
tag_type
);
return
true
;
...
...
src/DatabasePrint.hxx
View file @
08237111
...
...
@@ -46,12 +46,6 @@ printInfoForAllIn(struct client *client, const char *uri_utf8,
gcc_nonnull
(
1
,
2
,
3
)
bool
searchForSongsIn
(
struct
client
*
client
,
const
char
*
name
,
const
struct
locate_item_list
*
criteria
,
GError
**
error_r
);
gcc_nonnull
(
1
,
2
,
3
)
bool
findSongsIn
(
struct
client
*
client
,
const
char
*
name
,
const
struct
locate_item_list
*
criteria
,
GError
**
error_r
);
...
...
src/DatabaseQueue.cxx
View file @
08237111
...
...
@@ -61,7 +61,7 @@ MatchAddSong(struct player_control *pc,
const
struct
locate_item_list
*
criteria
,
song
&
song
,
GError
**
error_r
)
{
return
!
locate_song_match
(
&
song
,
criteria
)
||
return
!
locate_
list_
song_match
(
&
song
,
criteria
)
||
AddToQueue
(
pc
,
song
,
error_r
);
}
...
...
@@ -75,24 +75,3 @@ findAddIn(struct player_control *pc, const char *uri,
const
auto
f
=
std
::
bind
(
MatchAddSong
,
pc
,
criteria
,
_1
,
_2
);
return
GetDatabase
()
->
Visit
(
selection
,
f
,
error_r
);
}
static
bool
SearchAddSong
(
struct
player_control
*
pc
,
const
struct
locate_item_list
*
criteria
,
song
&
song
,
GError
**
error_r
)
{
return
!
locate_song_search
(
&
song
,
criteria
)
||
AddToQueue
(
pc
,
song
,
error_r
);
}
bool
search_add_songs
(
struct
player_control
*
pc
,
const
char
*
uri
,
const
struct
locate_item_list
*
criteria
,
GError
**
error_r
)
{
const
DatabaseSelection
selection
(
uri
,
true
);
using
namespace
std
::
placeholders
;
const
auto
f
=
std
::
bind
(
SearchAddSong
,
pc
,
criteria
,
_1
,
_2
);
return
GetDatabase
()
->
Visit
(
selection
,
f
,
error_r
);
}
src/DatabaseQueue.hxx
View file @
08237111
...
...
@@ -31,9 +31,4 @@ bool
findAddIn
(
struct
player_control
*
pc
,
const
char
*
name
,
const
struct
locate_item_list
*
criteria
,
GError
**
error_r
);
gcc_nonnull
(
1
,
2
,
3
)
bool
search_add_songs
(
struct
player_control
*
pc
,
const
char
*
uri
,
const
struct
locate_item_list
*
criteria
,
GError
**
error_r
);
#endif
src/command.c
View file @
08237111
...
...
@@ -702,7 +702,7 @@ handle_playlistsearch(struct client *client, int argc, char *argv[])
return
COMMAND_RETURN_ERROR
;
}
playlist_print_
search
(
client
,
&
g_playlist
,
list
);
playlist_print_
find
(
client
,
&
g_playlist
,
list
);
locate_item_list_free
(
list
);
...
...
src/locate.c
View file @
08237111
...
...
@@ -25,6 +25,7 @@
#include <glib.h>
#include <assert.h>
#include <stdlib.h>
#define LOCATE_TAG_FILE_KEY "file"
...
...
@@ -34,6 +35,9 @@
/* struct used for search, find, list queries */
struct
locate_item
{
uint8_t
tag
;
bool
fold_case
;
/* what we are looking for */
char
*
needle
;
};
...
...
@@ -72,6 +76,7 @@ locate_item_init(struct locate_item *item,
if
(
item
->
tag
==
TAG_NUM_OF_ITEM_TYPES
)
return
false
;
item
->
fold_case
=
fold_case
;
item
->
needle
=
fold_case
?
g_utf8_casefold
(
needle
,
-
1
)
:
g_strdup
(
needle
);
...
...
@@ -104,6 +109,7 @@ locate_item_list_new_single(unsigned tag, const char *needle)
{
struct
locate_item_list
*
list
=
locate_item_list_new
(
1
);
list
->
items
[
0
].
tag
=
tag
;
list
->
items
[
0
].
fold_case
=
false
;
list
->
items
[
0
].
needle
=
g_strdup
(
needle
);
return
list
;
}
...
...
@@ -129,39 +135,39 @@ locate_item_list_parse(char *argv[], unsigned argc, bool fold_case)
gcc_pure
static
bool
locate_
tag_search
(
const
struct
song
*
song
,
enum
tag_type
type
,
const
char
*
str
)
locate_
string_match
(
const
struct
locate_item
*
item
,
const
char
*
value
)
{
bool
ret
=
false
;
if
(
type
==
LOCATE_TAG_FILE_TYPE
||
type
==
LOCATE_TAG_ANY_TYPE
)
{
char
*
uri
=
song_get_uri
(
song
);
char
*
p
=
g_utf8_casefold
(
uri
,
-
1
);
g_free
(
uri
);
assert
(
item
!=
NULL
);
assert
(
value
!=
NULL
);
if
(
strstr
(
p
,
str
))
ret
=
true
;
if
(
item
->
fold_case
)
{
char
*
p
=
g_utf8_casefold
(
value
,
-
1
);
const
bool
result
=
strstr
(
p
,
item
->
needle
)
!=
NULL
;
g_free
(
p
);
if
(
ret
==
1
||
type
==
LOCATE_TAG_FILE_TYPE
)
return
ret
;
return
result
;
}
else
{
return
strcmp
(
value
,
item
->
needle
)
==
0
;
}
}
if
(
!
song
->
tag
)
return
false
;
gcc_pure
static
bool
locate_tag_match
(
const
struct
locate_item
*
item
,
const
struct
tag
*
tag
)
{
assert
(
item
!=
NULL
);
assert
(
tag
!=
NULL
);
bool
visited_types
[
TAG_NUM_OF_ITEM_TYPES
];
memset
(
visited_types
,
0
,
sizeof
(
visited_types
));
for
(
unsigned
i
=
0
;
i
<
song
->
tag
->
num_items
&&
!
ret
;
i
++
)
{
visited_types
[
song
->
tag
->
items
[
i
]
->
type
]
=
true
;
if
(
type
!=
LOCATE_TAG_ANY_TYPE
&&
song
->
tag
->
items
[
i
]
->
type
!=
type
)
{
for
(
unsigned
i
=
0
;
i
<
tag
->
num_items
;
i
++
)
{
visited_types
[
tag
->
items
[
i
]
->
type
]
=
true
;
if
(
item
->
tag
!=
LOCATE_TAG_ANY_TYPE
&&
tag
->
items
[
i
]
->
type
!=
item
->
tag
)
continue
;
}
char
*
duplicate
=
g_utf8_casefold
(
song
->
tag
->
items
[
i
]
->
value
,
-
1
);
if
(
*
str
&&
strstr
(
duplicate
,
str
))
ret
=
true
;
g_free
(
duplicate
);
if
(
locate_string_match
(
item
,
tag
->
items
[
i
]
->
value
))
return
true
;
}
/** If the search critieron was not visited during the sweep
...
...
@@ -170,76 +176,36 @@ locate_tag_search(const struct song *song, enum tag_type type, const char *str)
* empty (first char is a \0), then it's a match as well and
* we should return true.
*/
if
(
!*
str
&&
!
visited_types
[
type
])
if
(
*
item
->
needle
==
0
&&
item
->
tag
!=
LOCATE_TAG_ANY_TYPE
&&
!
visited_types
[
item
->
tag
])
return
true
;
return
ret
;
}
bool
locate_song_search
(
const
struct
song
*
song
,
const
struct
locate_item_list
*
criteria
)
{
for
(
unsigned
i
=
0
;
i
<
criteria
->
length
;
i
++
)
if
(
!
locate_tag_search
(
song
,
criteria
->
items
[
i
].
tag
,
criteria
->
items
[
i
].
needle
))
return
false
;
return
true
;
return
false
;
}
gcc_pure
static
bool
locate_
tag_match
(
const
struct
song
*
song
,
enum
tag_type
type
,
const
char
*
str
)
locate_
song_match
(
const
struct
locate_item
*
item
,
const
struct
song
*
song
)
{
if
(
type
==
LOCATE_TAG_FILE_TYPE
||
type
==
LOCATE_TAG_ANY_TYPE
)
{
if
(
item
->
tag
==
LOCATE_TAG_FILE_TYPE
||
item
->
tag
==
LOCATE_TAG_ANY_TYPE
)
{
char
*
uri
=
song_get_uri
(
song
);
bool
matches
=
strcmp
(
str
,
uri
)
==
0
;
const
bool
result
=
locate_string_match
(
item
,
uri
)
;
g_free
(
uri
);
if
(
matches
)
return
true
;
if
(
type
==
LOCATE_TAG_FILE_TYPE
)
return
false
;
}
if
(
!
song
->
tag
)
return
false
;
bool
visited_types
[
TAG_NUM_OF_ITEM_TYPES
];
memset
(
visited_types
,
0
,
sizeof
(
visited_types
));
for
(
unsigned
i
=
0
;
i
<
song
->
tag
->
num_items
;
i
++
)
{
visited_types
[
song
->
tag
->
items
[
i
]
->
type
]
=
true
;
if
(
type
!=
LOCATE_TAG_ANY_TYPE
&&
song
->
tag
->
items
[
i
]
->
type
!=
type
)
{
continue
;
}
if
(
0
==
strcmp
(
str
,
song
->
tag
->
items
[
i
]
->
value
))
return
true
;
if
(
result
||
item
->
tag
==
LOCATE_TAG_FILE_TYPE
)
return
result
;
}
/** If the search critieron was not visited during the sweep
* through the song's tag, it means this field is absent from
* the tag or empty. Thus, if the searched string is also
* empty (first char is a \0), then it's a match as well and
* we should return true.
*/
if
(
!*
str
&&
!
visited_types
[
type
])
return
true
;
return
false
;
return
song
->
tag
!=
NULL
&&
locate_tag_match
(
item
,
song
->
tag
);
}
bool
locate_song_match
(
const
struct
song
*
song
,
const
struct
locate_item_list
*
criteria
)
locate_
list_
song_match
(
const
struct
song
*
song
,
const
struct
locate_item_list
*
criteria
)
{
for
(
unsigned
i
=
0
;
i
<
criteria
->
length
;
i
++
)
if
(
!
locate_tag_match
(
song
,
criteria
->
items
[
i
].
tag
,
criteria
->
items
[
i
].
needle
))
if
(
!
locate_song_match
(
&
criteria
->
items
[
i
],
song
))
return
false
;
return
true
;
...
...
src/locate.h
View file @
08237111
...
...
@@ -54,13 +54,7 @@ locate_item_list_free(struct locate_item_list *list);
gcc_pure
gcc_nonnull
(
1
,
2
)
bool
locate_song_search
(
const
struct
song
*
song
,
const
struct
locate_item_list
*
criteria
);
gcc_pure
gcc_nonnull
(
1
,
2
)
bool
locate_song_match
(
const
struct
song
*
song
,
const
struct
locate_item_list
*
criteria
);
locate_list_song_match
(
const
struct
song
*
song
,
const
struct
locate_item_list
*
criteria
);
#endif
src/playlist_print.c
View file @
08237111
...
...
@@ -94,13 +94,6 @@ playlist_print_find(struct client *client, const struct playlist *playlist,
}
void
playlist_print_search
(
struct
client
*
client
,
const
struct
playlist
*
playlist
,
const
struct
locate_item_list
*
list
)
{
queue_search
(
client
,
&
playlist
->
queue
,
list
);
}
void
playlist_print_changes_info
(
struct
client
*
client
,
const
struct
playlist
*
playlist
,
uint32_t
version
)
...
...
src/playlist_print.h
View file @
08237111
...
...
@@ -69,13 +69,6 @@ playlist_print_find(struct client *client, const struct playlist *playlist,
const
struct
locate_item_list
*
list
);
/**
* Search for songs in the playlist.
*/
void
playlist_print_search
(
struct
client
*
client
,
const
struct
playlist
*
playlist
,
const
struct
locate_item_list
*
list
);
/**
* Print detailed changes since the specified playlist version.
*/
void
...
...
src/queue_print.c
View file @
08237111
...
...
@@ -92,25 +92,13 @@ queue_print_changes_position(struct client *client, const struct queue *queue,
}
void
queue_search
(
struct
client
*
client
,
const
struct
queue
*
queue
,
const
struct
locate_item_list
*
criteria
)
{
for
(
unsigned
i
=
0
;
i
<
queue_length
(
queue
);
i
++
)
{
const
struct
song
*
song
=
queue_get
(
queue
,
i
);
if
(
locate_song_search
(
song
,
criteria
))
queue_print_song_info
(
client
,
queue
,
i
);
}
}
void
queue_find
(
struct
client
*
client
,
const
struct
queue
*
queue
,
const
struct
locate_item_list
*
criteria
)
{
for
(
unsigned
i
=
0
;
i
<
queue_length
(
queue
);
i
++
)
{
const
struct
song
*
song
=
queue_get
(
queue
,
i
);
if
(
locate_song_match
(
song
,
criteria
))
if
(
locate_
list_
song_match
(
song
,
criteria
))
queue_print_song_info
(
client
,
queue
,
i
);
}
}
src/queue_print.h
View file @
08237111
...
...
@@ -48,10 +48,6 @@ queue_print_changes_position(struct client *client, const struct queue *queue,
uint32_t
version
);
void
queue_search
(
struct
client
*
client
,
const
struct
queue
*
queue
,
const
struct
locate_item_list
*
criteria
);
void
queue_find
(
struct
client
*
client
,
const
struct
queue
*
queue
,
const
struct
locate_item_list
*
criteria
);
...
...
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