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
4ec3df03
Commit
4ec3df03
authored
Nov 11, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
implement saved memory by not storing full path
git-svn-id:
https://svn.musicpd.org/mpd/trunk@2601
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
03f02bad
Hide whitespace changes
Inline
Side-by-side
Showing
9 changed files
with
124 additions
and
67 deletions
+124
-67
dbUtils.c
src/dbUtils.c
+24
-3
dbUtils.h
src/dbUtils.h
+2
-0
directory.c
src/directory.c
+9
-9
directory.h
src/directory.h
+4
-0
main.c
src/main.c
+2
-0
player.c
src/player.c
+5
-5
playlist.c
src/playlist.c
+11
-16
song.c
src/song.c
+61
-31
song.h
src/song.h
+6
-3
No files found.
src/dbUtils.c
View file @
4ec3df03
...
...
@@ -6,6 +6,7 @@
#include "playlist.h"
#include "tag.h"
#include "tagTracker.h"
#include "log.h"
#define LOCATE_TAG_FILE_TYPE TAG_NUM_OF_ITEM_TYPES+10
#define LOCATE_TAG_FILE_KEY "filename"
...
...
@@ -76,7 +77,7 @@ static inline int strstrSearchTag(Song * song, int type, char * str) {
int
ret
=
0
;
if
(
type
==
LOCATE_TAG_FILE_TYPE
)
{
dup
=
strDupToUpper
(
song
->
utf8url
);
dup
=
strDupToUpper
(
getSongUrl
(
song
)
);
if
(
strstr
(
dup
,
str
))
ret
=
1
;
free
(
dup
);
return
ret
;
...
...
@@ -122,7 +123,7 @@ static inline int tagItemFoundAndMatches(Song * song, int type, char * str) {
int
i
;
if
(
type
==
LOCATE_TAG_FILE_TYPE
)
{
if
(
0
==
strcmp
(
str
,
song
->
utf8url
))
return
1
;
if
(
0
==
strcmp
(
str
,
getSongUrl
(
song
)
))
return
1
;
}
if
(
!
song
->
tag
)
return
0
;
...
...
@@ -217,7 +218,7 @@ void printUnvisitedTags(FILE * fp, Song * song, int tagType) {
MpdTag
*
tag
=
song
->
tag
;
if
(
tagType
==
LOCATE_TAG_FILE_TYPE
)
{
myfprintf
(
fp
,
"file: %s
\n
"
,
song
->
utf8url
);
printSongUrl
(
fp
,
song
);
return
;
}
...
...
@@ -268,3 +269,23 @@ int listAllUniqueTags(FILE * fp, int type, int numConditionals,
return
ret
;
}
int
sumSavedMemoryInDirectory
(
FILE
*
fp
,
Directory
*
dir
,
void
*
data
)
{
int
*
sum
=
data
;
if
(
!
dir
->
utf8name
)
return
0
;
*
sum
+=
(
strlen
(
dir
->
utf8name
)
+
1
-
sizeof
(
Directory
*
))
*
dir
->
songs
->
numberOfNodes
;
return
0
;
}
void
printSavedMemoryFromFilenames
()
{
int
sum
;
traverseAllIn
(
stderr
,
NULL
,
NULL
,
sumSavedMemoryInDirectory
,
(
void
*
)
&
sum
);
DEBUG
(
"saved memory from filenames: %i
\n
"
,
sum
);
}
src/dbUtils.h
View file @
4ec3df03
...
...
@@ -36,4 +36,6 @@ unsigned long sumSongTimesIn(FILE * fp, char * name);
int
listAllUniqueTags
(
FILE
*
fp
,
int
type
,
int
numConditiionals
,
LocateTagItem
*
conditionals
);
void
printSavedMemoryFromFilenames
();
#endif
src/directory.c
View file @
4ec3df03
...
...
@@ -280,8 +280,8 @@ void removeSongFromDirectory(Directory * directory, char * shortname) {
void
*
song
;
if
(
findInList
(
directory
->
songs
,
shortname
,
&
song
))
{
LOG
(
"removing: %s
\n
"
,
((
Song
*
)
song
)
->
utf8url
);
deleteFromList
(
directory
->
songs
,
shortname
);
LOG
(
"removing: %s
\n
"
,
getSongUrl
((
Song
*
)
song
)
);
deleteFromList
(
directory
->
songs
,
shortname
);
}
}
...
...
@@ -317,7 +317,7 @@ int updateInDirectory(Directory * directory, char * shortname, char * name) {
if
(
S_ISREG
(
st
.
st_mode
)
&&
hasMusicSuffix
(
name
))
{
if
(
0
==
findInList
(
directory
->
songs
,
shortname
,
&
song
))
{
addToDirectory
(
directory
,
shortname
,
name
);
addToDirectory
(
directory
,
shortname
,
name
);
return
DIRECTORY_RETURN_UPDATE
;
}
else
if
(
st
.
st_mtime
!=
((
Song
*
)
song
)
->
mtime
)
{
...
...
@@ -540,7 +540,7 @@ int updatePath(char * utf8path) {
parentDirectory
->
parent
,
parentDirectory
->
stat
->
inode
,
parentDirectory
->
stat
->
device
)
&&
song
&&
isMusic
(
song
->
utf8url
,
&
mtime
))
song
&&
isMusic
(
getSongUrl
(
song
),
&
mtime
))
{
free
(
path
);
if
(
song
->
mtime
==
mtime
)
return
0
;
...
...
@@ -553,7 +553,7 @@ int updatePath(char * utf8path) {
}
/* if updateDirectory fials, means we should delete it */
else
{
removeSongFromDirectory
(
parentDirectory
,
shortname
);
removeSongFromDirectory
(
parentDirectory
,
shortname
);
ret
=
1
;
/* don't return, path maybe a directory now*/
}
...
...
@@ -749,10 +749,10 @@ int addToDirectory(Directory * directory, char * shortname, char * name) {
if
(
S_ISREG
(
st
.
st_mode
)
&&
hasMusicSuffix
(
name
))
{
Song
*
song
;
song
=
addSongToList
(
directory
->
songs
,
shortname
,
name
,
SONG_TYPE_FILE
);
song
=
addSongToList
(
directory
->
songs
,
shortname
,
name
,
SONG_TYPE_FILE
,
directory
);
if
(
!
song
)
return
-
1
;
LOG
(
"added %s
\n
"
,
name
);
LOG
(
"added %s
\n
"
,
name
);
return
1
;
}
else
if
(
S_ISDIR
(
st
.
st_mode
))
{
...
...
@@ -935,7 +935,7 @@ void readDirectoryInfo(FILE * fp,Directory * directory) {
readDirectoryInfo
(
fp
,
subDirectory
);
}
else
if
(
0
==
strncmp
(
SONG_BEGIN
,
buffer
,
strlen
(
SONG_BEGIN
)))
{
readSongInfoIntoList
(
fp
,
directory
->
songs
);
readSongInfoIntoList
(
fp
,
directory
->
songs
,
directory
);
}
else
{
ERROR
(
"Unknown line in db: %s
\n
"
,
buffer
);
...
...
src/directory.h
View file @
4ec3df03
...
...
@@ -74,4 +74,8 @@ int traverseAllIn(FILE * fp, char * name,
int
(
*
forEachSong
)(
FILE
*
,
Song
*
,
void
*
),
int
(
*
forEachDir
)(
FILE
*
,
Directory
*
,
void
*
),
void
*
data
);
/* free the string that is returned */
char
*
catDirAndFileName
(
Directory
*
dir
,
char
*
filename
);
#endif
src/main.c
View file @
4ec3df03
...
...
@@ -36,6 +36,7 @@
#include "inputStream.h"
#include "tag.h"
#include "tagTracker.h"
#include "dbUtils.h"
#include "../config.h"
#include <stdio.h>
...
...
@@ -431,6 +432,7 @@ int main(int argc, char * argv[]) {
initInputStream
();
printMemorySavedByTagTracker
();
printSavedMemoryFromFilenames
();
daemonize
(
&
options
);
...
...
src/player.c
View file @
4ec3df03
...
...
@@ -179,7 +179,7 @@ int playerPlay(FILE * fp, Song * song) {
copyMpdTagToMetadataChunk
(
song
->
tag
,
&
(
pc
->
fileMetadataChunk
));
strncpy
(
pc
->
utf8url
,
song
->
utf8url
,
MAXPATHLEN
);
strncpy
(
pc
->
utf8url
,
getSongUrl
(
song
)
,
MAXPATHLEN
);
pc
->
utf8url
[
MAXPATHLEN
]
=
'\0'
;
pc
->
play
=
1
;
...
...
@@ -324,7 +324,7 @@ int queueSong(Song * song) {
PlayerControl
*
pc
=
&
(
getPlayerData
()
->
playerControl
);
if
(
pc
->
queueState
==
PLAYER_QUEUE_BLANK
)
{
strncpy
(
pc
->
utf8url
,
song
->
utf8url
,
MAXPATHLEN
);
strncpy
(
pc
->
utf8url
,
getSongUrl
(
song
)
,
MAXPATHLEN
);
pc
->
utf8url
[
MAXPATHLEN
]
=
'\0'
;
if
(
song
->
tag
)
pc
->
fileTime
=
song
->
tag
->
time
;
...
...
@@ -380,13 +380,13 @@ int playerSeek(FILE * fp, Song * song, float time) {
return
-
1
;
}
if
(
strcmp
(
pc
->
utf8url
,
song
->
utf8url
)
!=
0
)
{
if
(
strcmp
(
pc
->
utf8url
,
getSongUrl
(
song
)
)
!=
0
)
{
if
(
song
->
tag
)
pc
->
fileTime
=
song
->
tag
->
time
;
else
pc
->
fileTime
=
0
;
copyMpdTagToMetadataChunk
(
song
->
tag
,
&
(
pc
->
fileMetadataChunk
));
strncpy
(
pc
->
utf8url
,
song
->
utf8url
,
MAXPATHLEN
);
strncpy
(
pc
->
utf8url
,
getSongUrl
(
song
)
,
MAXPATHLEN
);
pc
->
utf8url
[
MAXPATHLEN
]
=
'\0'
;
}
...
...
@@ -476,7 +476,7 @@ Song * playerCurrentDecodeSong() {
memcpy
(
prev
,
&
(
pc
->
metadataChunk
),
sizeof
(
MetadataChunk
));
if
(
song
)
freeJustSong
(
song
);
song
=
newNullSong
();
song
->
u
tf8u
rl
=
strdup
(
pc
->
currentUrl
);
song
->
url
=
strdup
(
pc
->
currentUrl
);
song
->
tag
=
metadataChunkToMpdTagDup
(
prev
);
ret
=
song
;
resetPlayerMetadata
();
...
...
src/playlist.c
View file @
4ec3df03
...
...
@@ -245,7 +245,7 @@ int showPlaylist(FILE * fp) {
int
i
;
for
(
i
=
0
;
i
<
playlist
.
length
;
i
++
)
{
myfprintf
(
fp
,
"%i:%s
\n
"
,
i
,(
playlist
.
songs
[
i
])
->
utf8url
);
myfprintf
(
fp
,
"%i:%s
\n
"
,
i
,
getSongUrl
(
playlist
.
songs
[
i
])
);
}
return
0
;
...
...
@@ -428,12 +428,7 @@ void readPlaylistState() {
}
void
printPlaylistSongInfo
(
FILE
*
fp
,
int
song
)
{
MpdTag
*
tag
;
myfprintf
(
fp
,
"file: %s
\n
"
,
(
playlist
.
songs
[
song
])
->
utf8url
);
if
((
tag
=
(
playlist
.
songs
[
song
])
->
tag
))
{
printMpdTag
(
fp
,
tag
);
}
printSongInfo
(
fp
,
playlist
.
songs
[
song
]);
myfprintf
(
fp
,
"Pos: %i
\n
"
,
song
);
myfprintf
(
fp
,
"Id: %i
\n
"
,
playlist
.
positionToId
[
song
]);
}
...
...
@@ -523,8 +518,8 @@ void queueNextSongInPlaylist() {
playlist
.
queued
=
playlist
.
current
+
1
;
DEBUG
(
"playlist: queue song %i:
\"
%s
\"\n
"
,
playlist
.
queued
,
playlist
.
songs
[
playlist
.
order
[
playlist
.
queued
]]
->
utf8url
);
getSongUrl
(
playlist
.
songs
[
playlist
.
order
[
playlist
.
queued
]])
);
if
(
queueSong
(
playlist
.
songs
[
playlist
.
order
[
playlist
.
queued
]])
<
0
)
{
...
...
@@ -539,8 +534,8 @@ void queueNextSongInPlaylist() {
playlist
.
queued
=
0
;
DEBUG
(
"playlist: queue song %i:
\"
%s
\"\n
"
,
playlist
.
queued
,
playlist
.
songs
[
playlist
.
order
[
playlist
.
queued
]]
->
utf8url
);
getSongUrl
(
playlist
.
songs
[
playlist
.
order
[
playlist
.
queued
]])
);
if
(
queueSong
(
playlist
.
songs
[
playlist
.
order
[
playlist
.
queued
]])
<
0
)
{
...
...
@@ -603,7 +598,7 @@ int addToPlaylist(FILE * fp, char * url, int printId) {
if
((
song
=
getSongFromDB
(
url
)))
{
}
else
if
(
isValidRemoteUtf8Url
(
url
)
&&
(
song
=
newSong
(
url
,
SONG_TYPE_UR
L
)))
(
song
=
newSong
(
url
,
SONG_TYPE_URL
,
NUL
L
)))
{
}
else
{
...
...
@@ -836,7 +831,7 @@ int playPlaylistOrderNumber(FILE * fp, int orderNum) {
playlist_queueError
=
0
;
DEBUG
(
"playlist: play %i:
\"
%s
\"\n
"
,
orderNum
,
(
playlist
.
songs
[
playlist
.
order
[
orderNum
]])
->
utf8url
);
getSongUrl
(
playlist
.
songs
[
playlist
.
order
[
orderNum
]])
);
if
(
playerPlay
(
fp
,(
playlist
.
songs
[
playlist
.
order
[
orderNum
]]))
<
0
)
{
stopPlaylist
(
fp
);
...
...
@@ -917,7 +912,7 @@ void syncCurrentPlayerDecodeMetadata() {
song
=
playlist
.
songs
[
songNum
];
if
(
song
->
type
==
SONG_TYPE_URL
&&
0
==
strcmp
(
song
->
utf8url
,
songPlayer
->
utf8
url
)
&&
0
==
strcmp
(
getSongUrl
(
song
),
songPlayer
->
url
)
&&
!
mpdTagsAreEqual
(
song
->
tag
,
songPlayer
->
tag
))
{
if
(
song
->
tag
)
freeMpdTag
(
song
->
tag
);
...
...
@@ -1321,10 +1316,10 @@ int savePlaylist(FILE * fp, char * utf8file) {
playlist
.
songs
[
i
]
->
type
==
SONG_TYPE_FILE
)
{
myfprintf
(
fileP
,
"%s
\n
"
,
rmp2amp
(
utf8ToFsCharset
((
playlist
.
songs
[
i
])
->
utf8url
)));
getSongUrl
(
playlist
.
songs
[
i
]))
)));
}
else
myfprintf
(
fileP
,
"%s
\n
"
,
utf8ToFsCharset
(
(
playlist
.
songs
[
i
])
->
utf8url
));
utf8ToFsCharset
(
getSongUrl
(
playlist
.
songs
[
i
])
));
}
while
(
fclose
(
fileP
)
&&
errno
==
EINTR
);
...
...
src/song.c
View file @
4ec3df03
...
...
@@ -29,16 +29,17 @@
#define SONG_KEY "key: "
#define SONG_FILE "file: "
#define SONG_TIME "Time: "
#define SONG_MTIME "
m
time: "
#define SONG_MTIME "
M
time: "
#include <stdlib.h>
#include <string.h>
#include <assert.h>
Song
*
newNullSong
()
{
Song
*
song
=
malloc
(
sizeof
(
Song
));
song
->
tag
=
NULL
;
song
->
u
tf8u
rl
=
NULL
;
song
->
url
=
NULL
;
song
->
type
=
SONG_TYPE_FILE
;
song
->
parentDir
=
NULL
;
...
...
@@ -48,11 +49,11 @@ Song * newNullSong() {
Song
*
newSong
(
char
*
url
,
int
type
,
Directory
*
parentDir
)
{
Song
*
song
=
NULL
;
if
(
strchr
(
u
tf8u
rl
,
'\n'
))
return
NULL
;
if
(
strchr
(
url
,
'\n'
))
return
NULL
;
song
=
newNullSong
();
song
->
u
tf8url
=
strdup
(
utf8
url
);
song
->
u
rl
=
strdup
(
url
);
song
->
type
=
type
;
song
->
parentDir
=
parentDir
;
...
...
@@ -60,9 +61,9 @@ Song * newSong(char * url, int type, Directory * parentDir) {
if
(
song
->
type
==
SONG_TYPE_FILE
)
{
InputPlugin
*
plugin
;
if
((
plugin
=
isMusic
(
utf8url
,
&
(
song
->
mtime
))))
{
if
((
plugin
=
isMusic
(
getSongUrl
(
song
),
&
(
song
->
mtime
))))
{
song
->
tag
=
plugin
->
tagDupFunc
(
rmp2amp
(
utf8ToFsCharset
(
utf8url
)));
rmp2amp
(
utf8ToFsCharset
(
getSongUrl
(
song
)
)));
}
if
(
!
song
->
tag
||
song
->
tag
->
time
<
0
)
{
freeSong
(
song
);
...
...
@@ -75,13 +76,11 @@ Song * newSong(char * url, int type, Directory * parentDir) {
void
freeSong
(
Song
*
song
)
{
deleteASongFromPlaylist
(
song
);
free
(
song
->
utf8url
);
if
(
song
->
tag
)
freeMpdTag
(
song
->
tag
);
free
(
song
);
freeJustSong
(
song
);
}
void
freeJustSong
(
Song
*
song
)
{
free
(
song
->
u
tf8u
rl
);
free
(
song
->
url
);
if
(
song
->
tag
)
freeMpdTag
(
song
->
tag
);
free
(
song
);
}
...
...
@@ -90,19 +89,19 @@ SongList * newSongList() {
return
makeList
((
ListFreeDataFunc
*
)
freeSong
);
}
Song
*
addSongToList
(
SongList
*
list
,
char
*
url
,
int
songType
,
Directory
*
parentDirectory
)
Song
*
addSongToList
(
SongList
*
list
,
char
*
url
,
char
*
utf8path
,
int
songType
,
Directory
*
parentDirectory
)
{
Song
*
song
=
NULL
;
switch
(
t
ype
)
{
switch
(
songT
ype
)
{
case
SONG_TYPE_FILE
:
if
(
isMusic
(
utf8
url
,
NULL
))
{
song
=
newSong
(
url
,
t
ype
,
parentDirectory
);
if
(
isMusic
(
utf8
path
,
NULL
))
{
song
=
newSong
(
url
,
songT
ype
,
parentDirectory
);
}
break
;
case
SONG_TYPE_URL
:
song
=
newSong
(
u
tf8url
,
t
ype
,
parentDirectory
);
song
=
newSong
(
u
rl
,
songT
ype
,
parentDirectory
);
break
;
}
...
...
@@ -119,7 +118,7 @@ void freeSongList(SongList * list) {
void
printSongUrl
(
FILE
*
fp
,
Song
*
song
)
{
if
(
song
->
parentDir
)
{
myfprintf
(
fp
,
"%s%s%s
\n
"
,
SONG_FILE
,
song
->
parentDir
->
utf8name
,
myfprintf
(
fp
,
"%s%s
/
%s
\n
"
,
SONG_FILE
,
song
->
parentDir
->
utf8name
,
song
->
url
);
}
else
{
...
...
@@ -208,11 +207,10 @@ static int matchesAnMpdTagItemKey(char * buffer, int * itemType) {
return
0
;
}
void
readSongInfoIntoList
(
FILE
*
fp
,
SongList
*
list
)
{
void
readSongInfoIntoList
(
FILE
*
fp
,
SongList
*
list
,
Directory
*
parentDir
)
{
char
buffer
[
MAXPATHLEN
+
1024
];
int
bufferSize
=
MAXPATHLEN
+
1024
;
Song
*
song
=
NULL
;
char
*
key
=
NULL
;
ListNode
*
nextSongNode
=
list
->
firstNode
;
ListNode
*
nodeTemp
;
int
itemType
;
...
...
@@ -220,21 +218,25 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
while
(
myFgets
(
buffer
,
bufferSize
,
fp
)
&&
0
!=
strcmp
(
SONG_END
,
buffer
))
{
if
(
0
==
strncmp
(
SONG_KEY
,
buffer
,
strlen
(
SONG_KEY
)))
{
if
(
song
)
{
insertSongIntoList
(
list
,
&
nextSongNode
,
key
,
song
);
insertSongIntoList
(
list
,
&
nextSongNode
,
song
->
url
,
song
);
song
=
NULL
;
free
(
key
);
}
key
=
strdup
(
&
(
buffer
[
strlen
(
SONG_KEY
)]));
song
=
newNullSong
();
song
->
url
=
strdup
(
buffer
+
strlen
(
SONG_KEY
));
song
->
type
=
SONG_TYPE_FILE
;
song
->
parentDir
=
parentDir
;
}
else
if
(
0
==
strncmp
(
SONG_FILE
,
buffer
,
strlen
(
SONG_FILE
)))
{
if
(
!
song
||
song
->
utf8url
)
{
if
(
!
song
)
{
ERROR
(
"Problems reading song info
\n
"
);
exit
(
EXIT_FAILURE
);
}
song
->
utf8url
=
strdup
(
&
(
buffer
[
strlen
(
SONG_FILE
)]));
/* we don't need this info anymore
song->url = strdup(&(buffer[strlen(SONG_FILE)]));
*/
}
else
if
(
matchesAnMpdTagItemKey
(
buffer
,
&
itemType
))
{
if
(
!
song
->
tag
)
song
->
tag
=
newMpdTag
();
...
...
@@ -255,9 +257,8 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
}
if
(
song
)
{
insertSongIntoList
(
list
,
&
nextSongNode
,
key
,
song
);
insertSongIntoList
(
list
,
&
nextSongNode
,
song
->
url
,
song
);
song
=
NULL
;
free
(
key
);
}
while
(
nextSongNode
)
{
...
...
@@ -268,8 +269,6 @@ void readSongInfoIntoList(FILE * fp, SongList * list) {
}
int
updateSongInfo
(
Song
*
song
)
{
char
*
utf8url
=
song
->
utf8url
;
if
(
song
->
type
==
SONG_TYPE_FILE
)
{
InputPlugin
*
plugin
;
...
...
@@ -277,9 +276,9 @@ int updateSongInfo(Song * song) {
song
->
tag
=
NULL
;
if
((
plugin
=
isMusic
(
utf8url
,
&
(
song
->
mtime
))))
{
if
((
plugin
=
isMusic
(
getSongUrl
(
song
)
,
&
(
song
->
mtime
))))
{
song
->
tag
=
plugin
->
tagDupFunc
(
rmp2amp
(
utf8ToFsCharset
(
utf8url
)));
rmp2amp
(
getSongUrl
(
song
)));
}
if
(
!
song
->
tag
||
song
->
tag
->
time
<
0
)
return
-
1
;
}
...
...
@@ -290,10 +289,41 @@ int updateSongInfo(Song * song) {
Song
*
songDup
(
Song
*
song
)
{
Song
*
ret
=
malloc
(
sizeof
(
Song
));
ret
->
u
tf8url
=
strdup
(
song
->
utf8
url
);
ret
->
u
rl
=
strdup
(
song
->
url
);
ret
->
mtime
=
song
->
mtime
;
ret
->
tag
=
mpdTagDup
(
song
->
tag
);
ret
->
type
=
song
->
type
;
ret
->
parentDir
=
song
->
parentDir
;
return
ret
;
}
char
*
getSongUrl
(
Song
*
song
)
{
static
char
*
buffer
=
NULL
;
static
int
bufferSize
=
0
;
static
Song
*
lastSong
=
NULL
;
int
slen
;
int
dlen
;
int
size
;
if
(
!
song
->
parentDir
||
!
song
->
parentDir
->
utf8name
)
return
song
->
url
;
/* be careful with this! */
if
(
song
==
lastSong
)
return
buffer
;
slen
=
strlen
(
song
->
url
);
dlen
=
strlen
(
song
->
parentDir
->
utf8name
);
size
=
slen
+
dlen
+
2
;
if
(
size
>
bufferSize
)
{
buffer
=
realloc
(
buffer
,
size
);
bufferSize
=
size
;
}
strcpy
(
buffer
,
song
->
parentDir
->
utf8name
);
buffer
[
dlen
]
=
'/'
;
strcpy
(
buffer
+
dlen
+
1
,
song
->
url
);
return
buffer
;
}
src/song.h
View file @
4ec3df03
...
...
@@ -45,7 +45,7 @@ typedef List SongList;
Song
*
newNullSong
();
Song
*
newSong
(
char
*
u
tf8u
rl
,
int
songType
,
struct
_Directory
*
parentDir
);
Song
*
newSong
(
char
*
url
,
int
songType
,
struct
_Directory
*
parentDir
);
void
freeSong
(
Song
*
);
...
...
@@ -55,7 +55,7 @@ SongList * newSongList();
void
freeSongList
(
SongList
*
list
);
Song
*
addSongToList
(
SongList
*
list
,
char
*
key
,
char
*
utf8file
,
Song
*
addSongToList
(
SongList
*
list
,
char
*
url
,
char
*
utf8path
,
int
songType
,
struct
_Directory
*
parentDir
);
int
printSongInfo
(
FILE
*
fp
,
Song
*
song
);
...
...
@@ -64,7 +64,8 @@ int printSongInfoFromList(FILE * fp, SongList * list);
void
writeSongInfoFromList
(
FILE
*
fp
,
SongList
*
list
);
void
readSongInfoIntoList
(
FILE
*
fp
,
SongList
*
list
);
void
readSongInfoIntoList
(
FILE
*
fp
,
SongList
*
list
,
struct
_Directory
*
parent
);
int
updateSongInfo
(
Song
*
song
);
...
...
@@ -72,4 +73,6 @@ Song * songDup(Song * song);
void
printSongUrl
(
FILE
*
fp
,
Song
*
song
);
char
*
getSongUrl
(
Song
*
song
);
#endif
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