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
df3af7d4
Commit
df3af7d4
authored
Apr 15, 2004
by
Warren Dukes
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
clean up a little bit main() code
git-svn-id:
https://svn.musicpd.org/mpd/trunk@771
09075e82-0dd4-0310-85a5-a0d7c8717e4f
parent
794799ea
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
70 additions
and
61 deletions
+70
-61
directory.c
src/directory.c
+1
-1
directory.h
src/directory.h
+1
-1
main.c
src/main.c
+4
-51
path.c
src/path.c
+58
-3
path.h
src/path.h
+4
-3
playlist.c
src/playlist.c
+2
-2
No files found.
src/directory.c
View file @
df3af7d4
...
...
@@ -70,7 +70,7 @@ typedef struct _Directory {
Directory
*
mp3rootDirectory
=
NULL
;
char
directorydb
[
MAXPATHLEN
+
1
]
;
char
*
directorydb
;
volatile
int
directory_updatePid
=
0
;
...
...
src/directory.h
View file @
df3af7d4
...
...
@@ -27,7 +27,7 @@
#include <stdio.h>
#include <sys/param.h>
extern
char
directorydb
[
MAXPATHLEN
+
1
]
;
extern
char
*
directorydb
;
void
readDirectoryDBIfUpdateIsFinished
();
...
...
src/main.c
View file @
df3af7d4
...
...
@@ -195,7 +195,6 @@ void parseOptions(int argc, char ** argv, Options * options) {
int
main
(
int
argc
,
char
*
argv
[])
{
int
port
,
uid
,
gid
;
struct
stat
st
;
FILE
*
out
;
FILE
*
err
;
Options
options
;
...
...
@@ -301,61 +300,15 @@ int main(int argc, char * argv[]) {
return
EXIT_FAILURE
;
}
initPaths
();
initPaths
(
options
.
playlistDirArg
,
options
.
musicDirArg
);
initPermissions
();
if
(
options
.
playlistDirArg
[
0
]
==
'/'
)
{
strcpy
(
playlistDir
,
options
.
playlistDirArg
);
}
else
{
getcwd
(
playlistDir
,
MAXPATHLEN
-
strlen
(
options
.
playlistDirArg
)
-
1
);
if
(
playlistDir
[
strlen
(
playlistDir
)
-
1
]
!=
'/'
)
{
strcat
(
playlistDir
,
"/"
);
}
strcat
(
playlistDir
,
options
.
playlistDirArg
);
}
if
(
playlistDir
[
strlen
(
playlistDir
)
-
1
]
!=
'/'
)
{
strcat
(
playlistDir
,
"/"
);
}
if
((
stat
(
playlistDir
,
&
st
))
<
0
)
{
ERROR
(
"problem stat'ing
\"
%s
\"\n
"
,
options
.
playlistDirArg
);
return
EXIT_FAILURE
;
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
ERROR
(
"
\"
%s
\"
is not a directory
\n
"
,
options
.
playlistDirArg
);
return
EXIT_FAILURE
;
}
if
(
options
.
musicDirArg
[
0
]
==
'/'
)
{
strcpy
(
musicDir
,
options
.
musicDirArg
);
}
else
{
getcwd
(
musicDir
,
MAXPATHLEN
-
strlen
(
options
.
musicDirArg
)
-
1
);
if
(
musicDir
[
strlen
(
musicDir
)
-
1
]
!=
'/'
)
strcat
(
musicDir
,
"/"
);
strcat
(
musicDir
,
options
.
musicDirArg
);
}
if
(
musicDir
[
strlen
(
musicDir
)
-
1
]
!=
'/'
)
strcat
(
musicDir
,
"/"
);
if
((
stat
(
musicDir
,
&
st
))
<
0
)
{
ERROR
(
"problem stat'ing
\"
%s
\"\n
"
,
options
.
musicDirArg
);
return
EXIT_FAILURE
;
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
ERROR
(
"
\"
%s
\"
is not a directory
\n
"
,
options
.
musicDirArg
);
return
EXIT_FAILURE
;
}
initTables
();
initPlaylist
();
if
(
!
options
.
dbFile
)
{
strncpy
(
directorydb
,
playlistDir
,
MAXPATHLEN
);
directorydb
[
MAXPATHLEN
]
=
'\0'
;
strncat
(
directorydb
,
"/.mpddb"
,
MAXPATHLEN
-
strlen
(
playlistDir
));
}
else
{
strncpy
(
directorydb
,
options
.
dbFile
,
MAXPATHLEN
);
directorydb
[
MAXPATHLEN
]
=
'\0'
;
}
if
(
!
options
.
dbFile
)
directorydb
=
strdup
(
rpp2app
(
".mpddb"
));
else
directorydb
=
strdup
(
options
.
dbFile
);
if
(
options
.
createDB
>
0
||
options
.
onlyCreateDB
||
readDirectoryDB
()
<
0
)
{
if
(
options
.
createDB
<
0
)
{
...
...
src/path.c
View file @
df3af7d4
...
...
@@ -24,6 +24,9 @@
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#ifdef HAVE_LOCALE
#ifdef HAVE_LANGINFO
...
...
@@ -32,8 +35,8 @@
#endif
#endif
char
musicDir
[
MAXPATHLEN
+
1
]
;
char
playlistDir
[
MAXPATHLEN
+
1
]
;
char
*
musicDir
;
char
*
playlistDir
;
char
*
fsCharset
=
NULL
;
...
...
@@ -106,9 +109,30 @@ char * getFsCharset() {
return
fsCharset
;
}
void
initPaths
()
{
void
initPaths
(
char
*
playlistDirArg
,
char
*
musicDirArg
)
{
char
*
charset
=
NULL
;
char
*
originalLocale
;
struct
stat
st
;
playlistDir
=
prependCwdToPathDup
(
playlistDirArg
);
if
((
stat
(
playlistDir
,
&
st
))
<
0
)
{
ERROR
(
"problem stat'ing
\"
%s
\"\n
"
,
playlistDirArg
);
exit
(
EXIT_FAILURE
);
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
ERROR
(
"
\"
%s
\"
is not a directory
\n
"
,
playlistDirArg
);
exit
(
EXIT_FAILURE
);
}
musicDir
=
prependCwdToPathDup
(
musicDirArg
);
if
((
stat
(
musicDir
,
&
st
))
<
0
)
{
ERROR
(
"problem stat'ing
\"
%s
\"\n
"
,
musicDirArg
);
exit
(
EXIT_FAILURE
);
}
if
(
!
S_ISDIR
(
st
.
st_mode
))
{
ERROR
(
"
\"
%s
\"
is not a directory
\n
"
,
musicDirArg
);
exit
(
EXIT_FAILURE
);
}
if
(
getConf
()[
CONF_FS_CHARSET
])
{
charset
=
strdup
(
getConf
()[
CONF_FS_CHARSET
]);
...
...
@@ -241,4 +265,35 @@ char * sanitizePathDup(char * path) {
return
realloc
(
ret
,
len
+
1
);
}
char
*
prependCwdToPathDup
(
char
*
path
)
{
int
len
=
MAXPATHLEN
+
1
;
char
*
ret
=
malloc
(
len
);
memset
(
ret
,
0
,
len
);
len
=
0
;
if
(
path
[
0
]
==
'/'
)
{
strncpy
(
ret
,
path
,
MAXPATHLEN
);
len
=
strlen
(
ret
);
}
else
{
getcwd
(
ret
,
MAXPATHLEN
);
len
=
strlen
(
ret
);
if
(
ret
[
len
-
1
]
!=
'/'
)
{
strncat
(
ret
,
"/"
,
MAXPATHLEN
-
len
);
len
=
strlen
(
path
);
}
strncat
(
ret
,
path
,
MAXPATHLEN
-
len
);
len
=
strlen
(
ret
);
}
if
(
ret
[
len
-
1
]
!=
'/'
)
{
strncat
(
ret
,
"/"
,
MAXPATHLEN
-
len
);
len
=
strlen
(
path
);
}
return
realloc
(
ret
,
len
+
1
);
}
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
src/path.h
View file @
df3af7d4
...
...
@@ -23,10 +23,9 @@
#include <sys/param.h>
extern
char
musicDir
[
MAXPATHLEN
+
1
];
extern
char
playlistDir
[
MAXPATHLEN
+
1
];
extern
char
*
musicDir
;
void
initPaths
();
void
initPaths
(
char
*
playlistDirArg
,
char
*
musicDirArg
);
void
finishPaths
();
...
...
@@ -52,5 +51,7 @@ char * parentPath(char * path);
/* strips extra "///" and leading "/" and trailing "/" */
char
*
sanitizePathDup
(
char
*
path
);
char
*
prependCwdToPathDup
(
char
*
path
);
#endif
/* vim:set shiftwidth=4 tabstop=8 expandtab: */
src/playlist.c
View file @
df3af7d4
...
...
@@ -1053,8 +1053,8 @@ int savePlaylist(FILE * fp, char * utf8file) {
for
(
i
=
0
;
i
<
playlist
.
length
;
i
++
)
{
if
(
playlist_saveAbsolutePaths
)
{
myfprintf
(
fileP
,
"%s
%s
\n
"
,
musicDir
,
utf8ToFsCharset
((
playlist
.
songs
[
i
])
->
utf8file
));
myfprintf
(
fileP
,
"%s
\n
"
,
rmp2amp
(
utf8ToFsCharset
((
playlist
.
songs
[
i
])
->
utf8file
)
));
}
else
myfprintf
(
fileP
,
"%s
\n
"
,
utf8ToFsCharset
((
playlist
.
songs
[
i
])
->
utf8file
));
...
...
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