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
ba7c9962
Commit
ba7c9962
authored
Jan 24, 2009
by
Max Kellermann
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
locate: added struct locate_item_list
Instead of passing two parameters around (number of items, array of items), combine both in a variable size struct.
parent
e1001491
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
111 additions
and
87 deletions
+111
-87
command.c
src/command.c
+53
-48
dbUtils.c
src/dbUtils.c
+6
-5
locate.c
src/locate.c
+26
-26
locate.h
src/locate.h
+21
-3
queue_print.c
src/queue_print.c
+5
-5
No files found.
src/command.c
View file @
ba7c9962
...
...
@@ -833,22 +833,23 @@ static enum command_return
handle_find
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
int
ret
;
struct
locate_item
*
items
;
int
numItems
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
,
&
items
);
struct
locate_item_list
*
list
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
);
if
(
list
==
NULL
||
list
->
length
==
0
)
{
if
(
list
!=
NULL
)
locate_item_list_free
(
list
);
if
(
numItems
<=
0
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"incorrect arguments"
);
return
COMMAND_RETURN_ERROR
;
}
ret
=
findSongsIn
(
client
,
NULL
,
numItems
,
items
);
ret
=
findSongsIn
(
client
,
NULL
,
list
->
length
,
list
->
items
);
if
(
ret
==
-
1
)
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"directory or file not found"
);
locate_item_list_free
(
numItems
,
items
);
locate_item_list_free
(
list
);
return
ret
;
}
...
...
@@ -857,22 +858,23 @@ static enum command_return
handle_search
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
int
ret
;
struct
locate_item
*
items
;
int
numItems
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
,
&
items
);
struct
locate_item_list
*
list
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
);
if
(
list
==
NULL
||
list
->
length
==
0
)
{
if
(
list
!=
NULL
)
locate_item_list_free
(
list
);
if
(
numItems
<=
0
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"incorrect arguments"
);
return
COMMAND_RETURN_ERROR
;
}
ret
=
searchForSongsIn
(
client
,
NULL
,
numItems
,
items
);
ret
=
searchForSongsIn
(
client
,
NULL
,
list
->
length
,
list
->
items
);
if
(
ret
==
-
1
)
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"directory or file not found"
);
locate_item_list_free
(
numItems
,
items
);
locate_item_list_free
(
list
);
return
ret
;
}
...
...
@@ -881,22 +883,23 @@ static enum command_return
handle_count
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
int
ret
;
struct
locate_item
*
items
;
int
numItems
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
,
&
items
);
struct
locate_item_list
*
list
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
);
if
(
list
==
NULL
||
list
->
length
==
0
)
{
if
(
list
!=
NULL
)
locate_item_list_free
(
list
);
if
(
numItems
<=
0
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"incorrect arguments"
);
return
COMMAND_RETURN_ERROR
;
}
ret
=
searchStatsForSongsIn
(
client
,
NULL
,
numItems
,
items
);
ret
=
searchStatsForSongsIn
(
client
,
NULL
,
list
->
length
,
list
->
items
);
if
(
ret
==
-
1
)
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
"directory or file not found"
);
locate_item_list_free
(
numItems
,
items
);
locate_item_list_free
(
list
);
return
ret
;
}
...
...
@@ -904,19 +907,20 @@ handle_count(struct client *client, int argc, char *argv[])
static
enum
command_return
handle_playlistfind
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
struct
locate_item
*
items
;
int
numItems
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
,
&
items
);
struct
locate_item_list
*
list
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
);
if
(
list
==
NULL
||
list
->
length
==
0
)
{
if
(
list
!=
NULL
)
locate_item_list_free
(
list
);
if
(
numItems
<=
0
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"incorrect arguments"
);
return
COMMAND_RETURN_ERROR
;
}
queue_find
(
client
,
playlist_get_queue
(),
numItems
,
items
);
queue_find
(
client
,
playlist_get_queue
(),
list
->
length
,
list
->
items
);
locate_item_list_free
(
numItems
,
items
);
locate_item_list_free
(
list
);
return
COMMAND_RETURN_OK
;
}
...
...
@@ -924,19 +928,20 @@ handle_playlistfind(struct client *client, int argc, char *argv[])
static
enum
command_return
handle_playlistsearch
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
struct
locate_item
*
items
;
int
numItems
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
,
&
items
);
struct
locate_item_list
*
list
=
locate_item_list_parse
(
argv
+
1
,
argc
-
1
);
if
(
list
==
NULL
||
list
->
length
==
0
)
{
if
(
list
!=
NULL
)
locate_item_list_free
(
list
);
if
(
numItems
<=
0
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"incorrect arguments"
);
return
COMMAND_RETURN_ERROR
;
}
queue_search
(
client
,
playlist_get_queue
(),
numItems
,
items
);
queue_search
(
client
,
playlist_get_queue
(),
list
->
length
,
list
->
items
);
locate_item_list_free
(
numItems
,
items
);
locate_item_list_free
(
list
);
return
COMMAND_RETURN_OK
;
}
...
...
@@ -1111,8 +1116,7 @@ handle_clearerror(G_GNUC_UNUSED struct client *client,
static
enum
command_return
handle_list
(
struct
client
*
client
,
int
argc
,
char
*
argv
[])
{
int
numConditionals
;
struct
locate_item
*
conditionals
=
NULL
;
struct
locate_item_list
*
conditionals
;
int
tagType
=
locate_parse_type
(
argv
[
1
]);
int
ret
;
...
...
@@ -1135,25 +1139,26 @@ handle_list(struct client *client, int argc, char *argv[])
mpdTagItemKeys
[
TAG_ITEM_ALBUM
]);
return
COMMAND_RETURN_ERROR
;
}
conditionals
=
locate_item_new
(
mpdTagItemKeys
[
TAG_ITEM_ARTIST
],
argv
[
2
]);
numConditionals
=
1
;
}
else
{
numConditionals
=
locate_item_list_parse
(
argv
+
2
,
argc
-
2
,
&
conditionals
);
if
(
numConditionals
<
0
)
{
locate_item_list_parse
(
argv
+
1
,
argc
-
1
);
conditionals
=
locate_item_list_new
(
1
);
conditionals
->
items
[
0
].
tag
=
TAG_ITEM_ARTIST
;
conditionals
->
items
[
0
].
needle
=
g_strdup
(
argv
[
2
]);
}
else
{
conditionals
=
locate_item_list_parse
(
argv
+
2
,
argc
-
2
);
if
(
conditionals
==
NULL
)
{
command_error
(
client
,
ACK_ERROR_ARG
,
"not able to parse args"
);
return
COMMAND_RETURN_ERROR
;
}
}
ret
=
listAllUniqueTags
(
client
,
tagType
,
numConditionals
,
conditionals
);
ret
=
listAllUniqueTags
(
client
,
tagType
,
conditionals
->
length
,
conditionals
->
items
);
if
(
conditionals
)
locate_item_list_free
(
numConditionals
,
conditionals
);
locate_item_list_free
(
conditionals
);
if
(
ret
==
-
1
)
command_error
(
client
,
ACK_ERROR_NO_EXIST
,
...
...
src/dbUtils.c
View file @
ba7c9962
...
...
@@ -92,20 +92,21 @@ searchForSongsIn(struct client *client, const char *name,
{
int
ret
;
int
i
;
struct
locate_item
*
new_items
=
g_memdup
(
items
,
sizeof
(
items
[
0
])
*
numItems
);
struct
locate_item_list
*
new_list
;
struct
search_data
data
;
new_list
=
locate_item_list_new
(
numItems
);
for
(
i
=
0
;
i
<
numItems
;
i
++
)
new_items
[
i
].
needle
=
g_utf8_casefold
(
new_items
[
i
].
needle
,
-
1
);
new_list
->
items
[
i
].
needle
=
g_utf8_casefold
(
items
[
i
].
needle
,
-
1
);
data
.
client
=
client
;
data
.
array
.
numItems
=
numItems
;
data
.
array
.
items
=
new_items
;
data
.
array
.
items
=
new_
list
->
items
;
ret
=
db_walk
(
name
,
searchInDirectory
,
NULL
,
&
data
);
locate_item_list_free
(
n
umItems
,
new_items
);
locate_item_list_free
(
n
ew_list
);
return
ret
;
}
...
...
src/locate.c
View file @
ba7c9962
...
...
@@ -76,45 +76,45 @@ locate_item_new(const char *type_string, const char *needle)
}
void
locate_item_list_free
(
int
count
,
struct
locate_item
*
array
)
locate_item_list_free
(
struct
locate_item_list
*
list
)
{
int
i
;
for
(
i
=
0
;
i
<
count
;
i
++
)
free
(
array
[
i
].
needle
);
for
(
unsigned
i
=
0
;
i
<
list
->
length
;
++
i
)
g_free
(
list
->
items
[
i
].
needle
);
free
(
array
);
g_free
(
list
);
}
int
locate_item_list_
parse
(
char
*
argv
[],
int
argc
,
struct
locate_item
**
arrayRet
)
struct
locate_item_list
*
locate_item_list_
new
(
unsigned
length
)
{
int
i
,
j
;
struct
locate_item
*
item
;
struct
locate_item_list
*
list
;
if
(
argc
==
0
)
return
0
;
list
=
g_malloc0
(
sizeof
(
*
list
)
-
sizeof
(
list
->
items
[
0
])
+
length
*
sizeof
(
list
->
items
[
0
]));
list
->
length
=
length
;
if
(
argc
%
2
!=
0
)
return
-
1
;
return
list
;
}
*
arrayRet
=
g_new
(
struct
locate_item
,
argc
/
2
);
struct
locate_item_list
*
locate_item_list_parse
(
char
*
argv
[],
int
argc
)
{
struct
locate_item_list
*
list
;
for
(
i
=
0
,
item
=
*
arrayRet
;
i
<
argc
/
2
;
i
++
,
item
++
)
{
if
(
!
locate_item_init
(
item
,
argv
[
i
*
2
],
argv
[
i
*
2
+
1
]))
goto
fail
;
}
if
(
argc
%
2
!=
0
)
return
NULL
;
return
argc
/
2
;
list
=
locate_item_list_new
(
argc
/
2
)
;
fail:
for
(
j
=
0
;
j
<
i
;
j
++
)
{
free
((
*
arrayRet
)[
j
].
needle
);
for
(
unsigned
i
=
0
;
i
<
list
->
length
;
++
i
)
{
if
(
!
locate_item_init
(
&
list
->
items
[
i
],
argv
[
i
*
2
],
argv
[
i
*
2
+
1
]))
{
locate_item_list_free
(
list
);
return
NULL
;
}
}
free
(
*
arrayRet
);
*
arrayRet
=
NULL
;
return
-
1
;
return
list
;
}
void
...
...
src/locate.h
View file @
ba7c9962
...
...
@@ -34,6 +34,17 @@ struct locate_item {
char
*
needle
;
};
/**
* An array of struct locate_item objects.
*/
struct
locate_item_list
{
/** number of items */
unsigned
length
;
/** this is a variable length array */
struct
locate_item
items
[
1
];
};
int
locate_parse_type
(
const
char
*
str
);
...
...
@@ -41,12 +52,19 @@ locate_parse_type(const char *str);
struct
locate_item
*
locate_item_new
(
const
char
*
type_string
,
const
char
*
needle
);
/**
* Allocates a new struct locate_item_list, and initializes all
* members with zero bytes.
*/
struct
locate_item_list
*
locate_item_list_new
(
unsigned
length
);
/* return number of items or -1 on error */
int
locate_item_list_parse
(
char
*
argv
[],
int
argc
,
struct
locate_item
**
arrayRet
);
struct
locate_item_list
*
locate_item_list_parse
(
char
*
argv
[],
int
argc
);
void
locate_item_list_free
(
int
count
,
struct
locate_item
*
array
);
locate_item_list_free
(
struct
locate_item_list
*
list
);
void
locate_item_free
(
struct
locate_item
*
item
);
...
...
src/queue_print.c
View file @
ba7c9962
...
...
@@ -84,20 +84,20 @@ queue_search(struct client *client, const struct queue *queue,
unsigned
num_items
,
const
struct
locate_item
*
items
)
{
unsigned
i
;
struct
locate_item
*
new_items
=
g_memdup
(
items
,
sizeof
(
items
[
0
])
*
num_items
);
struct
locate_item_list
*
new_list
=
locate_item_list_new
(
num_items
);
for
(
i
=
0
;
i
<
num_items
;
i
++
)
new_items
[
i
].
needle
=
g_utf8_casefold
(
new_items
[
i
].
needle
,
-
1
);
new_list
->
items
[
i
].
needle
=
g_utf8_casefold
(
items
[
i
].
needle
,
-
1
);
for
(
i
=
0
;
i
<
queue_length
(
queue
);
i
++
)
{
const
struct
song
*
song
=
queue_get
(
queue
,
i
);
if
(
locate_song_search
(
song
,
num_items
,
new_items
))
if
(
locate_song_search
(
song
,
num_items
,
new_
list
->
items
))
queue_print_song_info
(
client
,
queue
,
i
);
}
locate_item_list_free
(
n
um_items
,
new_items
);
locate_item_list_free
(
n
ew_list
);
}
void
...
...
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