configure.ac: Don't allow UNIX IPC to be configured for a native Windows build.
[mpd-mk.git] / src / queue_save.c
blob4eb095a59856f5f19acb9bedcd3bf07a1a878584
1 /*
2 * Copyright (C) 2003-2010 The Music Player Daemon Project
3 * http://www.musicpd.org
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License along
16 * with this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 #include "config.h"
21 #include "queue_save.h"
22 #include "queue.h"
23 #include "song.h"
24 #include "uri.h"
25 #include "database.h"
27 #include <stdlib.h>
29 void
30 queue_save(FILE *fp, const struct queue *queue)
32 for (unsigned i = 0; i < queue_length(queue); i++) {
33 const struct song *song = queue_get(queue, i);
34 char *uri = song_get_uri(song);
36 fprintf(fp, "%i:%s\n", i, uri);
37 g_free(uri);
41 static struct song *
42 get_song(const char *uri)
44 struct song *song;
46 song = db_get_song(uri);
47 if (song != NULL)
48 return song;
50 if (uri_has_scheme(uri))
51 return song_remote_new(uri);
53 return NULL;
56 int
57 queue_load_song(struct queue *queue, const char *line)
59 long ret;
60 char *endptr;
61 struct song *song;
63 if (queue_is_full(queue))
64 return -1;
66 ret = strtol(line, &endptr, 10);
67 if (ret < 0 || *endptr != ':' || endptr[1] == 0) {
68 g_warning("Malformed playlist line in state file");
69 return -1;
72 line = endptr + 1;
74 song = get_song(line);
75 if (song == NULL)
76 return -1;
78 queue_append(queue, song);
79 return ret;