clean up a little bit main() code
git-svn-id: https://svn.musicpd.org/mpd/trunk@771 09075e82-0dd4-0310-85a5-a0d7c8717e4f
This commit is contained in:
parent
794799eaf4
commit
df3af7d4f1
@ -70,7 +70,7 @@ typedef struct _Directory {
|
||||
|
||||
Directory * mp3rootDirectory = NULL;
|
||||
|
||||
char directorydb[MAXPATHLEN+1];
|
||||
char * directorydb;
|
||||
|
||||
volatile int directory_updatePid = 0;
|
||||
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include <stdio.h>
|
||||
#include <sys/param.h>
|
||||
|
||||
extern char directorydb[MAXPATHLEN+1];
|
||||
extern char * directorydb;
|
||||
|
||||
void readDirectoryDBIfUpdateIsFinished();
|
||||
|
||||
|
55
src/main.c
55
src/main.c
@ -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) {
|
||||
|
61
src/path.c
61
src/path.c
@ -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: */
|
||||
|
@ -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: */
|
||||
|
@ -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));
|
||||
|
Loading…
Reference in New Issue
Block a user