这是indexloc提供的服务,不要输入任何密码
Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions commands.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,11 +413,8 @@ cmd_new(int argc, char *argv[])
}

/* create & setup playlist */
p = playlist_new();
p = playlist_new(filename, name);
p->needs_saving = true;
p->filename = filename;
if ((p->name = strdup(name)) == NULL)
err(1, "cmd_new: strdup(3) failed");

/* add playlist to media library and update ui */
medialib_playlist_add(p);
Expand All @@ -429,6 +426,7 @@ cmd_new(int argc, char *argv[])
paint_library();
paint_message("playlist \"%s\" added", name);

free(filename);
return 0;
}

Expand Down
12 changes: 2 additions & 10 deletions medialib.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,8 @@ medialib_load(const char *db_file, const char *playlist_dir)
err(1, "failed to strdup db file and playlist dir in medialib_init");

/* setup pseudo-playlists */
mdb.library = playlist_new();
mdb.library->filename = NULL;
mdb.library->name = strdup("--LIBRARY--");

mdb.filter_results = playlist_new();
mdb.filter_results->filename = NULL;
mdb.filter_results->name = strdup("--FILTER--");

if (mdb.library->name == NULL || mdb.filter_results->name == NULL)
err(1, "failed to strdup pseudo-names in medialib_load");
mdb.library = playlist_new(NULL, "--LIBRARY--");
mdb.filter_results = playlist_new(NULL, "--FILTER--");

/* load the actual database */
medialib_db_load(db_file);
Expand Down
39 changes: 19 additions & 20 deletions playlist.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ playlist_increase_capacity(playlist *p)
* structure must be free(2)'d using playlist_free().
*/
playlist *
playlist_new(void)
playlist_new(const char *filename, const char *name)
{
playlist *p;

Expand All @@ -55,6 +55,15 @@ playlist_new(void)
p->hist_present = -1;
p->needs_saving = false;

if (filename != NULL) {
if ((p->filename = strdup(filename)) == NULL)
err(1, "%s: strdup(3) failed", __FUNCTION__);
}
if (name != NULL) {
if ((p->name = strdup(name)) == NULL)
err(1, "%s: strdup(3) failed", __FUNCTION__);
}

return p;
}

Expand All @@ -81,19 +90,10 @@ playlist_dup(const playlist *original, const char *filename,
int i;

/* create new playlist and copy simple members */
newplist = playlist_new();
newplist = playlist_new(filename, name);
newplist->nfiles = original->nfiles;
newplist->capacity = original->nfiles;

if (name != NULL) {
if ((newplist->name = strdup(name)) == NULL)
err(1, "playlist_dup: strdup name failed");
}
if (filename != NULL) {
if ((newplist->filename = strdup(filename)) == NULL)
err(1, "playlist_dup: strdup filename failed");
}

/* copy all of the files */
newplist->files = calloc(original->nfiles, sizeof(meta_info*));
if (newplist->files == NULL)
Expand Down Expand Up @@ -203,20 +203,19 @@ playlist *
playlist_load(const char *filename, meta_info **db, int ndb)
{
meta_info *mi, **mit;
FILE *fin;
char *period;
char entry[PATH_MAX + 1];
FILE *fin;
char *name, *period;
char entry[PATH_MAX + 1];

/* open file */
if ((fin = fopen(filename, "r")) == NULL)
err(1, "playlist_load: failed to open playlist '%s'", filename);

if ((name = basename(filename)) == NULL)
err(1, "%s: basename(3) failed", __FUNCTION__);

/* create playlist and setup */
playlist *p = playlist_new();
p->filename = strdup(filename);
p->name = strdup(basename(p->filename));
if (p->filename == NULL || p->name == NULL)
err(1, "playlist_load: failed to allocate info for playlist '%s'", filename);
playlist *p = playlist_new(filename, name);

/* hack to remove '.playlist' from name */
period = strrchr(p->name, '.');
Expand Down Expand Up @@ -309,7 +308,7 @@ playlist_filter(const playlist *p, bool m)
if (!mi_query_isset())
return NULL;

results = playlist_new();
results = playlist_new(NULL, NULL);
for (i = 0; i < p->nfiles; i++) {
if (mi_match(p->files[i])) {
if (m) playlist_files_append(results, &(p->files[i]), 1, false);
Expand Down
2 changes: 1 addition & 1 deletion playlist.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ typedef struct {
*/

/* create/destroy/duplicate playlist structs */
playlist *playlist_new(void);
playlist *playlist_new(const char *filename, const char *name);
void playlist_free(playlist *p);
playlist *playlist_dup(const playlist *original, const char *filename,
const char* name);
Expand Down