#include <fcntl.h>
#include <string.h>
#include <glib.h>
+#include <glib/gstdio.h>
#include <glib-object.h>
#include "plist.h"
} break;
case P_STRING:
{
- gval = ghb_string_value_new(g_strdup(pd->value));
+ gval = ghb_string_value_new(pd->value);
} break;
case P_DATE:
{
static void
destroy_notify(gpointer data)
{ // Do nothing
- g_debug("destroy parser");
+ //g_debug("destroy parser");
}
GValue*
g_markup_parse_context_parse(ctx, buf, len, &err);
g_markup_parse_context_end_parse(ctx, &err);
g_markup_parse_context_free(ctx);
+ if (pd.key) g_free(pd.key);
+ if (pd.value) g_free(pd.value);
g_queue_free(pd.stack);
g_queue_free(pd.tag_stack);
return pd.plist;
}
GValue*
-ghb_plist_parse_file(FILE *fd)
+ghb_plist_parse_file(const gchar *filename)
{
gchar *buffer;
size_t size;
GValue *gval;
+ FILE *fd;
+ fd = g_fopen(filename, "r");
if (fd == NULL)
+ {
+ g_warning("Plist parse: failed to open %s", filename);
return NULL;
+ }
fseek(fd, 0, SEEK_END);
size = ftell(fd);
fseek(fd, 0, SEEK_SET);
- buffer = g_malloc(size);
+ buffer = g_malloc(size+1);
size = fread(buffer, 1, size, fd);
buffer[size] = 0;
gval = ghb_plist_parse(buffer, (gssize)size);
g_free(buffer);
+ fclose(fd);
return gval;
}
gint val = g_value_get_int64(gval);
indent_fprintf(file, indent, "<integer>%d</integer>\n", val);
}
+ else if (gtype == G_TYPE_INT)
+ {
+ gint val = g_value_get_int(gval);
+ indent_fprintf(file, indent, "<integer>%d</integer>\n", val);
+ }
else if (gtype == G_TYPE_STRING)
{
const gchar *str = g_value_get_string(gval);