[Goodies-commits] r5750 - in xfbib/branches/gobject: . src
David Gustafsson
tssj at xfce.org
Wed Oct 22 22:03:12 CEST 2008
Author: tssj
Date: 2008-10-22 20:03:12 +0000 (Wed, 22 Oct 2008)
New Revision: 5750
Modified:
xfbib/branches/gobject/configure.ac.in
xfbib/branches/gobject/src/main.c
xfbib/branches/gobject/src/xfbib-bibtex-comment.c
xfbib/branches/gobject/src/xfbib-bibtex-comment.h
xfbib/branches/gobject/src/xfbib-bibtex-entry.c
xfbib/branches/gobject/src/xfbib-bibtex-entry.h
xfbib/branches/gobject/src/xfbib-bibtex-field.c
xfbib/branches/gobject/src/xfbib-bibtex-preamble.c
xfbib/branches/gobject/src/xfbib-bibtex-preamble.h
xfbib/branches/gobject/src/xfbib-bibtex-string.c
xfbib/branches/gobject/src/xfbib-bibtex-string.h
xfbib/branches/gobject/src/xfbib-bibtex-value.c
xfbib/branches/gobject/src/xfbib-bibtex.c
xfbib/branches/gobject/src/xfbib-bibtex.h
xfbib/branches/gobject/src/xfbib-file-io.c
xfbib/branches/gobject/src/xfbib-file-io.h
xfbib/branches/gobject/src/xfbib-input-dialog.c
xfbib/branches/gobject/src/xfbib-integer.c
xfbib/branches/gobject/src/xfbib-menu-bar.c
xfbib/branches/gobject/src/xfbib-multiple-input.c
xfbib/branches/gobject/src/xfbib-string.c
xfbib/branches/gobject/src/xfbib-string.h
xfbib/branches/gobject/src/xfbib-toolbar.c
Log:
Replaced all calls to free() with g_free() and fixed a bug in the parser.
Modified: xfbib/branches/gobject/configure.ac.in
===================================================================
--- xfbib/branches/gobject/configure.ac.in 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/configure.ac.in 2008-10-22 20:03:12 UTC (rev 5750)
@@ -73,11 +73,11 @@
dnl check for debugging support
XDT_FEATURE_DEBUG
-dnl if test "x$enable_debug" = "xfull"; then
-dnl if test "x$CC" = "xgcc"; then
-dnl CFLAGS="$CFLAGS -fno-strict-aliasing"
-dnl fi
-dnl fi
+ if test "x$enable_debug" = "xfull"; then
+ if test "x$CC" = "xgcc"; then
+ CFLAGS="$CFLAGS -fno-strict-aliasing -pg"
+ fi
+ fi
AC_OUTPUT([
Makefile
Modified: xfbib/branches/gobject/src/main.c
===================================================================
--- xfbib/branches/gobject/src/main.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/main.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -32,7 +32,6 @@
gboolean
cb_window_destroy_event (GtkWidget *widget, GdkEvent *event, gpointer user_data)
{
- g_fprintf(stderr, "destroy-event\n");
gtk_main_quit();
return FALSE;
}
Modified: xfbib/branches/gobject/src/xfbib-bibtex-comment.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-comment.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-comment.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -58,7 +58,7 @@
static void
xfbib_bibtex_comment_finalize(GObject *obj)
{
- free(XFBIB_BIBTEX_COMMENT(obj)->str);
+ g_free(XFBIB_BIBTEX_COMMENT(obj)->str);
G_OBJECT_CLASS(xfbib_bibtex_comment_parent_class)->finalize(obj);
}
@@ -70,3 +70,10 @@
comment->str = g_strdup(str);
return comment;
}
+
+gchar *
+xfbib_bibtex_comment_get(XfbibBibtexComment *comment)
+{
+ g_return_val_if_fail(XFBIB_IS_BIBTEX_COMMENT(comment), NULL);
+ return comment->str;
+}
Modified: xfbib/branches/gobject/src/xfbib-bibtex-comment.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-comment.h 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-comment.h 2008-10-22 20:03:12 UTC (rev 5750)
@@ -36,6 +36,7 @@
GType xfbib_bibtex_comment_get_type() G_GNUC_CONST;
XfbibBibtexComment *xfbib_bibtex_comment_new(const gchar *);
+gchar *xfbib_bibtex_comment_get(XfbibBibtexComment *);
G_END_DECLS
Modified: xfbib/branches/gobject/src/xfbib-bibtex-entry.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-entry.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-entry.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -31,6 +31,7 @@
{
GObject parent;
gchar *bibtype;
+ gchar separator;
gchar *key;
GList *fields;
};
@@ -66,8 +67,8 @@
xfbib_bibtex_entry_finalize(GObject *obj)
{
XfbibBibtexEntry *entry = XFBIB_BIBTEX_ENTRY(obj);
- free(entry->key);
- free(entry->bibtype);
+ g_free(entry->key);
+ g_free(entry->bibtype);
g_list_foreach (entry->fields, (GFunc) g_object_unref, NULL);
g_list_free (entry->fields);
G_OBJECT_CLASS(xfbib_bibtex_entry_parent_class)->finalize(obj);
@@ -98,13 +99,16 @@
tmp = g_strndup(str, len);
/* Parse entry type */
- for (i = 0; i < len && tmp[i] != '{' && tmp[i] != '('; i++)
+ for (i = 1; i < len && tmp[i] != '{' && tmp[i] != '('; i++)
buf = g_string_append_c(buf, tmp[i]);
entry->bibtype = g_strdup(buf->str);
if (i == len) {
return FALSE;
}
+
+ /* Separator */
+ entry->separator = tmp[i];
buf = g_string_erase(buf, 0, -1);
/* Parse the entry key */
@@ -126,7 +130,7 @@
brackets++;
} else if (tmp[i] == '}' || tmp[i] == ')') {
brackets--;
- } else if (tmp[i] == '"') {
+ } else if (tmp[i] == '"' && tmp[i-1] != '\\') {
quotes++;
}
buf = g_string_append_c(buf, tmp[i]);
@@ -146,7 +150,6 @@
}
g_string_free(buf, TRUE);
-// g_object_unref(G_OBJECT(buf));
g_free(tmp);
return TRUE;
@@ -180,7 +183,7 @@
xfbib_bibtex_entry_set_key(XfbibBibtexEntry *entry, const gchar *key)
{
g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
- free(entry->key);
+ g_free(entry->key);
entry->key = g_strdup(key);
}
@@ -196,7 +199,13 @@
xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *entry, const gchar *bibtype)
{
g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
- free(entry->bibtype);
+ g_free(entry->bibtype);
entry->bibtype = g_strdup(bibtype);
}
+gchar
+xfbib_bibtex_entry_get_separator(XfbibBibtexEntry *entry)
+{
+ g_return_val_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry), '\0');
+ return entry->separator;
+}
Modified: xfbib/branches/gobject/src/xfbib-bibtex-entry.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-entry.h 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-entry.h 2008-10-22 20:03:12 UTC (rev 5750)
@@ -45,6 +45,8 @@
void xfbib_bibtex_entry_set_key(XfbibBibtexEntry *, const gchar *);
gchar *xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *);
void xfbib_bibtex_entry_set_bibtype(XfbibBibtexEntry *, const gchar *);
+gchar xfbib_bibtex_entry_get_separator(XfbibBibtexEntry *);
+
#if 0
XfbibBibtexField *xfbib_bibtex_entry_get_field_by_column(XfbibBibtexEntry *, gint);
XfbibStrbuf *xfbib_bibtex_entry_get_bibtype(XfbibBibtexEntry *);
Modified: xfbib/branches/gobject/src/xfbib-bibtex-field.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-field.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-field.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -61,7 +61,7 @@
static void
xfbib_bibtex_field_finalize(GObject *obj)
{
- free(XFBIB_BIBTEX_FIELD(obj)->variable);
+ g_free(XFBIB_BIBTEX_FIELD(obj)->variable);
G_OBJECT_CLASS(xfbib_bibtex_field_parent_class)->finalize(obj);
}
@@ -89,7 +89,7 @@
}
/* Variable */
- free(field->variable);
+ g_free(field->variable);
g_strstrip(split[0]);
field->variable = g_strdup(split[0]);
@@ -115,7 +115,7 @@
{
g_return_if_fail(XFBIB_IS_BIBTEX_FIELD(field));
- free(field->variable);
+ g_free(field->variable);
field->variable = g_strdup(str);
}
Modified: xfbib/branches/gobject/src/xfbib-bibtex-preamble.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-preamble.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-preamble.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -76,6 +76,7 @@
xfbib_bibtex_preamble_parse(XfbibBibtexPreamble *preamble, const gchar *s)
{
gchar *str, *tmp;
+ g_return_val_if_fail(XFBIB_IS_BIBTEX_PREAMBLE(preamble), FALSE);
str = g_strdup(s + 9);
g_strstrip(str);
@@ -84,12 +85,26 @@
tmp = g_strndup(str + 1, strlen(str) - 2);
if (!xfbib_bibtex_value_parse(preamble->value, tmp)) {
- free(tmp);
- free(str);
+ g_free(tmp);
+ g_free(str);
return FALSE;
}
- free(tmp);
- free(str);
+ g_free(tmp);
+ g_free(str);
return TRUE;
}
+gchar
+xfbib_bibtex_preamble_get_separator(XfbibBibtexPreamble *preamble)
+{
+ g_return_val_if_fail(XFBIB_IS_BIBTEX_PREAMBLE(preamble), '\0');
+ return preamble->separator;
+}
+
+XfbibBibtexValue *
+xfbib_bibtex_preamble_get_value(XfbibBibtexPreamble *preamble)
+{
+ g_return_val_if_fail(XFBIB_IS_BIBTEX_PREAMBLE(preamble), NULL);
+ return preamble->value;
+}
+
Modified: xfbib/branches/gobject/src/xfbib-bibtex-preamble.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-preamble.h 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-preamble.h 2008-10-22 20:03:12 UTC (rev 5750)
@@ -21,6 +21,7 @@
#define __XFBIB_BIBTEX_PREAMBLE_H
#include <glib-object.h>
+#include "xfbib-bibtex-value.h"
#define XFBIB_TYPE_BIBTEX_PREAMBLE (xfbib_bibtex_preamble_get_type())
#define XFBIB_BIBTEX_PREAMBLE(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_BIBTEX_PREAMBLE, XfbibBibtexPreamble))
@@ -37,6 +38,8 @@
XfbibBibtexPreamble *xfbib_bibtex_preamble_new();
gboolean xfbib_bibtex_preamble_parse(XfbibBibtexPreamble *, const gchar *);
+gchar xfbib_bibtex_preamble_get_separator(XfbibBibtexPreamble *);
+XfbibBibtexValue *xfbib_bibtex_preamble_get_value(XfbibBibtexPreamble *);
G_END_DECLS
Modified: xfbib/branches/gobject/src/xfbib-bibtex-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-string.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-string.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -29,6 +29,7 @@
struct _XfbibBibtexString
{
GObject parent;
+ gchar separator;
gchar *variable;
XfbibBibtexValue *value;
};
@@ -55,6 +56,9 @@
static void
xfbib_bibtex_string_init(XfbibBibtexString *instance)
{
+ instance->separator = '\0';
+ instance->variable = NULL;
+ instance->value = xfbib_bibtex_value_new();
}
static void
@@ -68,10 +72,6 @@
{
XfbibBibtexString *string;
string = g_object_new(XFBIB_TYPE_BIBTEX_STRING, NULL);
-
- string->variable = NULL;
- string->value = xfbib_bibtex_value_new();
-
return string;
}
@@ -84,7 +84,7 @@
void
xfbib_bibtex_string_set_variable(XfbibBibtexString *string, const gchar *variable)
{
- free(string->variable);
+ g_free(string->variable);
string->variable = g_strdup(variable);
}
@@ -114,20 +114,31 @@
return FALSE;
}
- /* Variable */
- free(string->variable);
+ g_free(string->variable);
g_strstrip(split[0] + 7);
- string->variable = g_strdup(split[0] + 8);
+ /* Separator */
+ string->separator = split[0][8];
+
+ /* Variable */
+ string->variable = g_strdup(split[0] + 9);
+
/* Value */
tmp = g_strndup(split[1], strlen(split[1]) - 1);
if (!xfbib_bibtex_value_parse(string->value, tmp)) {
- free(tmp);
+ g_free(tmp);
g_strfreev(split);
return FALSE;
}
- free(tmp);
+ g_free(tmp);
g_strfreev(split);
return TRUE;
}
+
+gchar
+xfbib_bibtex_string_get_separator(XfbibBibtexString *string)
+{
+ g_return_val_if_fail(XFBIB_IS_BIBTEX_STRING(string), '\0');
+ return string->separator;
+}
Modified: xfbib/branches/gobject/src/xfbib-bibtex-string.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-string.h 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-string.h 2008-10-22 20:03:12 UTC (rev 5750)
@@ -21,6 +21,7 @@
#define __XFBIB_BIBTEX_STRING_H
#include <glib-object.h>
+#include "xfbib-bibtex-value.h"
#define XFBIB_TYPE_BIBTEX_STRING (xfbib_bibtex_string_get_type())
#define XFBIB_BIBTEX_STRING(obj) (G_TYPE_CHECK_INSTANCE_CAST((obj), XFBIB_TYPE_BIBTEX_STRING, XfbibBibtexString))
@@ -38,7 +39,10 @@
XfbibBibtexString *xfbib_bibtex_string_new();
const gchar *xfbib_bibtex_string_get_variable(XfbibBibtexString *);
void xfbib_bibtex_string_set_variable(XfbibBibtexString *, const gchar *);
+XfbibBibtexValue *xfbib_bibtex_string_get_value(XfbibBibtexString *);
+void xfbib_bibtex_string_set_value(XfbibBibtexString *, XfbibBibtexValue *);
gboolean xfbib_bibtex_string_parse(XfbibBibtexString *, const gchar *);
+gchar xfbib_bibtex_string_get_separator(XfbibBibtexString *);
G_END_DECLS
Modified: xfbib/branches/gobject/src/xfbib-bibtex-value.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex-value.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex-value.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -45,7 +45,7 @@
xfbib_bibtex_value_finalize(GObject *obj)
{
XfbibBibtexValue *value;
- g_return_if_fail(XFBIB_IS_BIBTEX_VALUE(value));
+ g_return_if_fail(XFBIB_IS_BIBTEX_VALUE(obj));
value = XFBIB_BIBTEX_VALUE(obj);
g_list_foreach (value->list, (GFunc) g_object_unref, NULL);
@@ -67,7 +67,6 @@
xfbib_bibtex_value_parse(XfbibBibtexValue *value, const gchar *str)
{
gint i, j, len, braces;
- GList *list;
gchar **split = NULL;
GObject *obj;
@@ -123,7 +122,7 @@
}
obj = G_OBJECT(xfbib_string_new());
- xfbib_string_set(XFBIB_STRING(obj), split[i]);
+ xfbib_string_parse(XFBIB_STRING(obj), split[i]);
value->list = g_list_prepend(value->list, obj);
} else if(g_ascii_isalpha(split[i][0])) {
/* Variable */
Modified: xfbib/branches/gobject/src/xfbib-bibtex.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -10,7 +10,11 @@
#include "xfbib-bibtex-preamble.h"
#include "xfbib-bibtex-string.h"
+#ifndef G_SEQUENCE
+#define G_SEQUENCE GLIB_CHECK_VERSION (2, 14, 0)
+#endif
+
#define CURLY_BRACKET 0
#define ROUND_BRACKET 1
@@ -18,9 +22,9 @@
{
GObject parent;
gint n_entries;
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
GSequence *seq;
-#elif
+#else
GList *list;
#endif
};
@@ -47,9 +51,9 @@
static void
xfbib_bibtex_init(XfbibBibtex *instance)
{
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
instance->seq = g_sequence_new(g_object_unref);
-#elif
+#else
instance->list = NULL;
#endif
instance->n_entries = 0;
@@ -59,7 +63,8 @@
static void
xfbib_bibtex_finalize(GObject *obj)
{
- /* TODO: Free the Bibtex List/Sequence */
+ /* Free the Bibtex List/Sequence */
+ xfbib_bibtex_remove_all(XFBIB_BIBTEX(obj));
G_OBJECT_CLASS(xfbib_bibtex_parent_class)->finalize(obj);
}
@@ -139,9 +144,9 @@
if (buf->len > 0) {
/* The comment ended put it in the list */
obj = G_OBJECT(xfbib_bibtex_comment_new(buf->str));
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
g_sequence_append(elements->seq, obj);
-#elif
+#else
elements->list = g_list_append(elements->list, obj);
#endif
buf = g_string_erase(buf, 0, -1);
@@ -155,9 +160,9 @@
buf = g_string_append_c(buf, str[i]);
obj = G_OBJECT(xfbib_bibtex_comment_new(buf->str));
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
g_sequence_append(elements->seq, obj);
-#elif
+#else
elements->list = g_list_append(elements->list, obj);
#endif
buf = g_string_erase(buf, 0, -1);
@@ -166,9 +171,9 @@
if (parse_balanced_brackets(buf, str, &i)) {
obj = G_OBJECT(xfbib_bibtex_preamble_new());
if (xfbib_bibtex_preamble_parse(XFBIB_BIBTEX_PREAMBLE(obj), buf->str)) {
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
g_sequence_append(elements->seq, obj);
-#elif
+#else
elements->list = g_list_append(elements->list, obj);
#endif
}
@@ -179,9 +184,9 @@
if (parse_balanced_brackets(buf, str, &i)) {
obj = G_OBJECT(xfbib_bibtex_string_new());
if (xfbib_bibtex_string_parse(XFBIB_BIBTEX_STRING(obj), buf->str)) {
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
g_sequence_append(elements->seq, obj);
-#elif
+#else
elements->list = g_list_append(elements->list, obj);
#endif
}
@@ -193,9 +198,9 @@
obj = G_OBJECT(xfbib_bibtex_entry_new());
if (xfbib_bibtex_entry_parse(XFBIB_BIBTEX_ENTRY(obj), buf->str)) {
elements->n_entries++;
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
g_sequence_append(elements->seq, obj);
-#elif
+#else
elements->list = g_list_append(elements->list, obj);
#endif
}
@@ -217,6 +222,17 @@
return TRUE;
}
+void
+xfbib_bibtex_foreach(XfbibBibtex *elements, GFunc func, gpointer data)
+{
+ g_return_if_fail(XFBIB_IS_BIBTEX(elements) && func != NULL);
+#if G_SEQUENCE
+ g_sequence_foreach(elements->seq, func, data);
+#else
+ g_list_foreach(elements->list, func, data);
+#endif
+}
+
gint
xfbib_bibtex_get_n_entries(XfbibBibtex *elements)
{
@@ -234,7 +250,7 @@
&& n < elements->n_entries, NULL);
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
GSequenceIter *iter;
for (iter = g_sequence_get_begin_iter(elements->seq), found = -1;
!g_sequence_iter_is_end(iter); iter = g_sequence_iter_next(iter)) {
@@ -246,7 +262,7 @@
}
}
if (g_sequence_iter_is_end(iter))
-#elif
+#else
gint i, len;
len = g_list_length(elements->list);
for (i = 0, found = -1; i < len; i++) {
@@ -269,7 +285,7 @@
gint n;
g_return_val_if_fail(XFBIB_IS_BIBTEX(elements), -1);
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
GSequenceIter *iter;
for (iter = g_sequence_get_begin_iter(elements->seq), n = -1;
!g_sequence_iter_is_end(iter); iter = g_sequence_iter_next(iter)) {
@@ -281,7 +297,7 @@
}
}
}
-#elif
+#else
gint i, len;
len = g_list_length(elements->list);
for (i = 0, n = -1; i < len; i++) {
@@ -303,7 +319,7 @@
GObject *obj;
g_return_val_if_fail(XFBIB_IS_BIBTEX(elements), NULL);
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
GSequenceIter *iter;
for (iter = g_sequence_get_begin_iter(elements->seq);
!g_sequence_iter_is_end(iter); iter = g_sequence_iter_next(iter)) {
@@ -318,7 +334,7 @@
}
}
}
-#elif
+#else
gint i, len;
len = g_list_length(elements->list);
for (i = 0; i < len; i++) {
@@ -342,7 +358,7 @@
{
GObject *obj;
g_return_if_fail(XFBIB_IS_BIBTEX(elements));
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
GSequenceIter *iter;
for (iter = g_sequence_get_begin_iter(elements->seq);
!g_sequence_iter_is_end(iter); iter = g_sequence_iter_next(iter)) {
@@ -352,7 +368,7 @@
g_sequence_remove(iter);
}
}
-#elif
+#else
gint i, len;
len = g_list_length(elements->list);
for (i = 0; i < len; i++) {
@@ -370,11 +386,11 @@
xfbib_bibtex_remove_all(XfbibBibtex *elements)
{
g_return_if_fail(XFBIB_IS_BIBTEX(elements));
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
g_sequence_remove_range(g_sequence_get_begin_iter(elements->seq),
g_sequence_get_end_iter(elements->seq));
elements->seq = g_sequence_new(g_object_unref);
-#elif
+#else
g_list_foreach (elements->list, (GFunc) g_object_unref, NULL);
g_list_free (elements->list);
elements->list = NULL;
@@ -388,9 +404,9 @@
g_return_if_fail(XFBIB_IS_BIBTEX(elements));
g_return_if_fail(XFBIB_IS_BIBTEX_ENTRY(entry));
-#if GLIB_CHECK_VERSION (2, 14, 0)
+#if G_SEQUENCE
g_sequence_append(elements->seq, G_OBJECT(entry));
-#elif
+#else
elements->list = g_list_append(elements->list, G_OBJECT(entry));
#endif
elements->n_entries++;
Modified: xfbib/branches/gobject/src/xfbib-bibtex.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-bibtex.h 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-bibtex.h 2008-10-22 20:03:12 UTC (rev 5750)
@@ -19,6 +19,7 @@
XfbibBibtex *xfbib_bibtex_new();
gboolean xfbib_bibtex_parse(XfbibBibtex *, const gchar *);
+void xfbib_bibtex_foreach(XfbibBibtex *, GFunc, gpointer);
gint xfbib_bibtex_get_n_entries(XfbibBibtex *);
XfbibBibtexEntry *xfbib_bibtex_get_nth_entry(XfbibBibtex *, gint);
gint xfbib_bibtex_get_entry_position(XfbibBibtex *, XfbibBibtexEntry *);
Modified: xfbib/branches/gobject/src/xfbib-file-io.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-file-io.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -20,15 +20,30 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
#include <gtk/gtk.h>
#include <libxfcegui4/libxfcegui4.h>
#include "xfbib-file-io.h"
#include "xfbib-state.h"
#include "xfbib-bibtex.h"
+#include "xfbib-bibtex-entry.h"
+#include "xfbib-bibtex-comment.h"
+#include "xfbib-bibtex-preamble.h"
+#include "xfbib-bibtex-string.h"
+#include "xfbib-bibtex-field.h"
+#include "xfbib-bibtex-value.h"
+#include "xfbib-string.h"
+#include "xfbib-integer.h"
#include "xfbib-window.h"
#include "xfbib-list-store.h"
+static void foreach_bibtex_element(gpointer, gpointer);
+static void foreach_field(gpointer, gpointer);
+static void foreach_value(GList *, GString *);
+
/*
* Opens a file and returns NULL if something went wrong otherwise it returns
* the filename of the file that was parsed
@@ -55,7 +70,7 @@
name = filename;
if (name == NULL) {
- dialog = gtk_file_chooser_dialog_new("Open BibTeX file",
+ dialog = gtk_file_chooser_dialog_new("Open",
GTK_WINDOW(xfbib_state_get_window(state)),
GTK_FILE_CHOOSER_ACTION_OPEN,
GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
@@ -80,6 +95,7 @@
if (!g_file_get_contents(name, &contents, &length, &err)) {
xfce_err("An error occured when opening the file: %s\n", err->message);
g_error_free(err);
+ return NULL;
} else {
n = xfbib_bibtex_get_n_entries(elements);
/* Parse the file and update the tree view */
@@ -89,20 +105,154 @@
}
}
- return filename;
+ return name;
}
gboolean
-xfbib_file_io_save(void)
+xfbib_file_io_save(gchar *name)
{
- /* TODO: Write the function */
+ FILE *fd;
+ XfbibState *state;
+ XfbibBibtex *elements;
+ GString *str;
+
+ if (name == NULL) {
+ /* No filename, redirect to save as */
+ return xfbib_file_io_save_as();
+ }
+
+ state = xfbib_state_new();
+ elements = xfbib_state_get_bibtex_elements(state);
+
+ str = g_string_new("");
+
+ xfbib_bibtex_foreach(elements, foreach_bibtex_element, str);
+
+ if ((fd = fopen(name, "w")) == NULL) {
+ xfce_err("An error occured when opening the file: %s\n", strerror(errno));
+ return FALSE;
+ }
+
+ if (fputs(str->str, fd) == EOF) {
+ xfce_err("An error occured when writing to the file: %s\n", name);
+ return FALSE;
+ }
+
+ g_string_free(str, TRUE);
return TRUE;
}
+
gboolean
xfbib_file_io_save_as(void)
{
- /* TODO: Write the function */
+ GtkWidget *dialog;
+ gchar *name;
+ XfbibState *state;
+ g_print("Save as\n");
+
+
+ state = xfbib_state_new();
+
+ dialog = gtk_file_chooser_dialog_new("Save As",
+ GTK_WINDOW(xfbib_state_get_window(state)),
+ GTK_FILE_CHOOSER_ACTION_SAVE,
+ GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
+ GTK_STOCK_SAVE, GTK_RESPONSE_OK,
+ NULL);
+
+ if (gtk_dialog_run(GTK_DIALOG(dialog)) == GTK_RESPONSE_OK) {
+ name = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(dialog));
+ if (xfbib_file_io_save(name)) {
+ xfbib_state_set_filename(state, name);
+ xfbib_window_set_title(XFBIB_WINDOW(xfbib_state_get_window(state)), name);
+ }
+ }
+
+ gtk_widget_destroy(dialog);
return TRUE;
}
+
+
+static void
+foreach_bibtex_element(gpointer _obj, gpointer _str)
+{
+ GObject *obj = _obj;
+ GString *str = _str;
+ gchar separator;
+
+ if (XFBIB_IS_BIBTEX_ENTRY(obj)) {
+ separator = xfbib_bibtex_entry_get_separator(XFBIB_BIBTEX_ENTRY(obj));
+ g_string_append_c(str, '@');
+ g_string_append(str, xfbib_bibtex_entry_get_bibtype(XFBIB_BIBTEX_ENTRY(obj)));
+ g_string_append_c(str, separator);
+ g_string_append(str, xfbib_bibtex_entry_get_key(XFBIB_BIBTEX_ENTRY(obj)));
+ g_string_append(str, ",\n");
+ /* XfbibBibtexField */
+ g_list_foreach(xfbib_bibtex_entry_get_fields(XFBIB_BIBTEX_ENTRY(obj)), foreach_field, str);
+ g_string_append_c(str, (separator == '{') ? '}' : ')');
+ g_string_append_c(str, '\n');
+ } else if (XFBIB_IS_BIBTEX_STRING(obj)) {
+ separator = xfbib_bibtex_string_get_separator(XFBIB_BIBTEX_STRING(obj));
+ g_string_append(str, "@string ");
+ g_string_append_c(str, separator);
+ g_string_append(str, xfbib_bibtex_string_get_variable(XFBIB_BIBTEX_STRING(obj)));
+ g_string_append(str, " = ");
+ /* XfbibBibtexValue */
+ foreach_value(xfbib_bibtex_value_get(xfbib_bibtex_string_get_value(XFBIB_BIBTEX_STRING(obj))), str);
+ g_string_append_c(str, (separator == '{') ? '}' : ')');
+ g_string_append_c(str, '\n');
+ } else if (XFBIB_IS_BIBTEX_COMMENT(obj)) {
+ g_string_append(str, xfbib_bibtex_comment_get(XFBIB_BIBTEX_COMMENT(obj)));
+ } else if (XFBIB_IS_BIBTEX_PREAMBLE(obj)) {
+ separator = xfbib_bibtex_preamble_get_separator(XFBIB_BIBTEX_PREAMBLE(obj));
+ g_string_append(str, "@preamble ");
+ g_string_append_c(str, separator);
+ /* XfbibBibtexValue */
+ foreach_value(xfbib_bibtex_value_get(xfbib_bibtex_preamble_get_value(XFBIB_BIBTEX_PREAMBLE(obj))), str);
+ g_string_append_c(str, (separator == '{') ? '}' : ')');
+ g_string_append_c(str, '\n');
+ }
+}
+
+
+static void
+foreach_field(gpointer obj, gpointer _str)
+{
+ XfbibBibtexField *field = obj;
+ GString *str = _str;
+
+ g_string_append_c(str, '\t');
+ g_string_append(str, xfbib_bibtex_field_get_variable(XFBIB_BIBTEX_FIELD(obj)));
+ g_string_append(str, " = ");
+ /* XfbibBibtexValue */
+ foreach_value(xfbib_bibtex_value_get(xfbib_bibtex_field_get_value(field)), str);
+ g_string_append(str, ",\n");
+}
+
+
+static void
+foreach_value(GList *list, GString *str)
+{
+ GList *obj;
+ gchar separator;
+
+ for (obj = g_list_first(list); obj != NULL; obj = g_list_next(obj)) {
+ if (XFBIB_IS_STRING(obj->data)) {
+ separator = xfbib_string_get_separator(XFBIB_STRING(obj->data));
+ g_string_append_c(str, separator);
+ g_string_append(str, xfbib_string_get(XFBIB_STRING(obj->data)));
+ g_string_append_c(str, (separator == '{') ? '}' : '"');
+ } else if (XFBIB_IS_INTEGER(obj->data)) {
+ g_string_append(str, xfbib_integer_get(XFBIB_INTEGER(obj->data)));
+ } else if (XFBIB_IS_BIBTEX_STRING(obj->data)) {
+ g_string_append(str, xfbib_bibtex_string_get_variable(XFBIB_BIBTEX_STRING(obj->data)));
+ }
+
+ if (g_list_last(list) != obj) {
+ g_string_append(str, " # ");
+ }
+ }
+}
+
Modified: xfbib/branches/gobject/src/xfbib-file-io.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-file-io.h 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-file-io.h 2008-10-22 20:03:12 UTC (rev 5750)
@@ -25,7 +25,7 @@
G_BEGIN_DECLS
gchar *xfbib_file_io_open(gchar *);
-gboolean xfbib_file_io_save(void);
+gboolean xfbib_file_io_save(gchar *);
gboolean xfbib_file_io_save_as(void);
G_END_DECLS
Modified: xfbib/branches/gobject/src/xfbib-input-dialog.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-input-dialog.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-input-dialog.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -132,7 +132,7 @@
//lbl = g_strdup_printf("%s:", label);
//gtk_label_set_text(GTK_LABEL(input_dialog->label), lbl);
- //free(lbl);
+ //g_free(lbl);
return GTK_WIDGET(input_dialog);
}
Modified: xfbib/branches/gobject/src/xfbib-integer.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-integer.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-integer.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -78,6 +78,6 @@
void
xfbib_integer_set(XfbibInteger *integer, const gchar *str)
{
- free(integer->str);
+ g_free(integer->str);
integer->str = g_strdup(str);
}
Modified: xfbib/branches/gobject/src/xfbib-menu-bar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-menu-bar.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-menu-bar.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -78,28 +78,23 @@
xfbib_state_set_filename(state, filename);
xfbib_window_set_title(XFBIB_WINDOW(xfbib_state_get_window(state)), filename);
}
-
- /*
- if (xfbib_file_io_open_dialog())
- {
- //TODO: What happens to the previous FileIo object?
- //TODO: Should these two lines be located here or in xfbib-file-io.c ?
- xfbib_window_set_file_io(window, file_io);
- //xfbib_window_set_title(window, filename;
- }
- */
}
static void
cb_file_save_activate (GtkMenuItem *menuitem, gpointer user_data)
{
+ XfbibState *state;
g_printf("File/Save\n");
+ state = xfbib_state_new();
+
+ xfbib_file_io_save(xfbib_state_get_filename(state));
}
static void
cb_file_save_as_activate (GtkMenuItem *menuitem, gpointer user_data)
{
g_printf("File/Save As\n");
+ xfbib_file_io_save_as();
}
static void
@@ -359,7 +354,7 @@
for (i = 0; i < XFBIB_FIELD_N_FIELDS; i++) {
str = g_strdup_printf("Show %s", xfbib_field_get_column_name(i));
item = gtk_check_menu_item_new_with_mnemonic(str);
- free(str);
+ g_free(str);
gtk_menu_shell_append(GTK_MENU_SHELL (instance->view_columns), item);
}
*/
Modified: xfbib/branches/gobject/src/xfbib-multiple-input.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-multiple-input.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-multiple-input.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -28,6 +28,7 @@
#include "xfbib-bibtex-string.h"
#include "xfbib-bibtex-value.h"
#include "xfbib-string.h"
+#include "xfbib-integer.h"
struct _XfbibMultipleInput
{
@@ -253,7 +254,7 @@
} else if(XFBIB_IS_BIBTEX_STRING(obj)){
gtk_list_store_set(GTK_LIST_STORE (model), &iter, 0, xfbib_bibtex_string_get_variable(XFBIB_BIBTEX_STRING(obj)),
1, xfbib_bibtex_value_get_str(xfbib_bibtex_string_get_value(XFBIB_BIBTEX_STRING(obj))), -1);
- } else if(XFBIB_IS_BIBTEX_INTEGER(obj)) {
+ } else if(XFBIB_IS_INTEGER(obj)) {
gtk_list_store_set(GTK_LIST_STORE (model), &iter, 0, xfbib_integer_get(XFBIB_INTEGER(obj)), -1);
}
}
Modified: xfbib/branches/gobject/src/xfbib-string.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-string.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -20,6 +20,7 @@
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif
+#include <string.h>
#include <gtk/gtk.h>
#include "xfbib-string.h"
@@ -27,6 +28,7 @@
struct _XfbibString
{
GObject parent;
+ gchar separator;
gchar *str;
};
@@ -52,6 +54,7 @@
static void
xfbib_string_init(XfbibString *instance)
{
+ instance->separator = '\0';
instance->str = NULL;
}
@@ -69,6 +72,14 @@
return string;
}
+gboolean
+xfbib_string_parse(XfbibString *string, const gchar *str)
+{
+ string->separator = str[0];
+ string->str = g_strndup(str+1, strlen(str)-2);
+ return TRUE;
+}
+
gchar *
xfbib_string_get(XfbibString *string)
{
@@ -78,7 +89,14 @@
void
xfbib_string_set(XfbibString *string, const gchar *str)
{
- free(string->str);
+ g_free(string->str);
+ g_printf("Setting string: <%s>\n", str);
string->str = g_strdup(str);
}
+gchar
+xfbib_string_get_separator(XfbibString *string)
+{
+ /* TODO: Return something clever if string->separator is '\0' */
+ return string->separator;
+}
Modified: xfbib/branches/gobject/src/xfbib-string.h
===================================================================
--- xfbib/branches/gobject/src/xfbib-string.h 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-string.h 2008-10-22 20:03:12 UTC (rev 5750)
@@ -36,9 +36,12 @@
GType xfbib_string_get_type() G_GNUC_CONST;
XfbibString *xfbib_string_new();
+gboolean xfbib_string_parse(XfbibString *, const gchar *);
gchar *xfbib_string_get(XfbibString *);
void xfbib_string_set(XfbibString *, const gchar *);
+gchar xfbib_string_get_separator(XfbibString *);
+
G_END_DECLS
#endif //__XFBIB_STRING_H
Modified: xfbib/branches/gobject/src/xfbib-toolbar.c
===================================================================
--- xfbib/branches/gobject/src/xfbib-toolbar.c 2008-10-22 20:01:59 UTC (rev 5749)
+++ xfbib/branches/gobject/src/xfbib-toolbar.c 2008-10-22 20:03:12 UTC (rev 5750)
@@ -62,17 +62,16 @@
xfbib_state_set_filename(state, filename);
xfbib_window_set_title(XFBIB_WINDOW(xfbib_state_get_window(state)), filename);
}
+}
+static void
+cb_save_clicked (GtkButton *buttonitem, gpointer user_data)
+{
+ XfbibState *state;
+ g_printf("Toolbar_Save\n");
+ state = xfbib_state_new();
- /*
- if (xfbib_file_io_open_dialog(file_io, window))
- {
- //TODO: What happens to the previous FileIo object?
- //TODO: Should these two lines be located here or in xfbib-file-io.c ?
- xfbib_window_set_file_io(window, file_io);
- //xfbib_window_set_title(window, filename;
- }
- */
+ xfbib_file_io_save(xfbib_state_get_filename(state));
}
GType
@@ -118,6 +117,7 @@
instance->save = gtk_tool_button_new_from_stock(GTK_STOCK_SAVE);
gtk_toolbar_insert (GTK_TOOLBAR (instance), instance->save, -1);
+ g_signal_connect (G_OBJECT (instance->save), "clicked", G_CALLBACK (cb_save_clicked), NULL);
}
static void
More information about the Goodies-commits
mailing list