[devhelp: 17/36] book parser: Read and store book language
- From: Aleksander Morgado <aleksm src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [devhelp: 17/36] book parser: Read and store book language
- Date: Mon, 20 Dec 2010 14:32:51 +0000 (UTC)
commit d0de8ea5bf5bad8af05404c9011286e10735a6ab
Author: Aleksander Morgado <aleksander lanedo com>
Date: Thu Dec 9 15:36:32 2010 +0100
book parser: Read and store book language
src/dh-book.c | 23 +++++++++++++++++------
src/dh-book.h | 1 +
src/dh-parser.c | 44 ++++++++++++++++++++++++++++++--------------
src/dh-parser.h | 3 +++
4 files changed, 51 insertions(+), 20 deletions(-)
---
diff --git a/src/dh-book.c b/src/dh-book.c
index 6457628..65d9d22 100644
--- a/src/dh-book.c
+++ b/src/dh-book.c
@@ -58,6 +58,8 @@ typedef struct {
gchar *name;
/* Book title */
gchar *title;
+ /* Book language */
+ gchar *language;
/* Generated book tree */
GNode *tree;
/* Generated list of keywords in the book */
@@ -210,6 +212,9 @@ dh_book_new (const gchar *book_path)
/* Parse file storing contents in the book struct */
if (!dh_parser_read_file (book_path,
+ &priv->title,
+ &priv->name,
+ &priv->language,
&priv->tree,
&priv->keywords,
&error)) {
@@ -226,12 +231,6 @@ dh_book_new (const gchar *book_path)
/* Store path */
priv->path = g_strdup (book_path);
- /* Setup title */
- priv->title = g_strdup (dh_link_get_name ((DhLink *)priv->tree->data));
-
- /* Setup name */
- priv->name = g_strdup (dh_link_get_book_id ((DhLink *)priv->tree->data));
-
/* Setup monitor for changes */
book_path_file = g_file_new_for_path (book_path);
priv->monitor = g_file_monitor_file (book_path_file,
@@ -379,6 +378,18 @@ dh_book_get_title (DhBook *book)
}
const gchar *
+dh_book_get_language (DhBook *book)
+{
+ DhBookPriv *priv;
+
+ g_return_val_if_fail (DH_IS_BOOK (book), NULL);
+
+ priv = GET_PRIVATE (book);
+
+ return priv->language;
+}
+
+const gchar *
dh_book_get_path (DhBook *book)
{
DhBookPriv *priv;
diff --git a/src/dh-book.h b/src/dh-book.h
index c7ec7e8..3e28276 100644
--- a/src/dh-book.h
+++ b/src/dh-book.h
@@ -52,6 +52,7 @@ GList *dh_book_get_keywords (DhBook *book);
GNode *dh_book_get_tree (DhBook *book);
const gchar *dh_book_get_name (DhBook *book);
const gchar *dh_book_get_title (DhBook *book);
+const gchar *dh_book_get_language (DhBook *book);
const gchar *dh_book_get_path (DhBook *book);
gboolean dh_book_get_enabled (DhBook *book);
void dh_book_set_enabled (DhBook *book,
diff --git a/src/dh-parser.c b/src/dh-parser.c
index 9530c54..ecafc48 100644
--- a/src/dh-parser.c
+++ b/src/dh-parser.c
@@ -39,6 +39,11 @@ typedef struct {
const gchar *path;
+ /* Primary metadata of the book */
+ gchar **book_title;
+ gchar **book_name;
+ gchar **book_language;
+
/* Top node of book */
GNode *book_node;
@@ -77,11 +82,11 @@ parser_start_node_book (DhParser *parser,
{
gint i, j;
gint line, col;
- gchar *title = NULL;
- gchar *base = NULL;
- const gchar *name = NULL;
+ gchar *base = NULL;
const gchar *uri = NULL;
- const gchar *lang = NULL;
+ const gchar *title = NULL;
+ const gchar *name = NULL;
+ const gchar *language = NULL;
DhLink *link;
if (g_ascii_strcasecmp (node_name, "book") != 0) {
@@ -116,19 +121,17 @@ parser_start_node_book (DhParser *parser,
name = attribute_values[i];
}
else if (g_ascii_strcasecmp (attribute_names[i], "title") == 0) {
- title = g_strdup(attribute_values[i]);
- for (j = 0; title[j]; j++) {
- if (title[j] == '\n') title[j] = ' ';
- }
+ title = attribute_values[i];
}
else if (g_ascii_strcasecmp (attribute_names[i], "base") == 0) {
+ /* Dup this one */
base = g_strdup (attribute_values[i]);
- }
+ }
else if (g_ascii_strcasecmp (attribute_names[i], "link") == 0) {
uri = attribute_values[i];
}
else if (g_ascii_strcasecmp (attribute_names[i], "language") == 0) {
- lang = attribute_values[i];
+ language = attribute_values[i];
}
}
@@ -140,18 +143,26 @@ parser_start_node_book (DhParser *parser,
_("\"title\", \"name\" and \"link\" elements are "
"required at line %d, column %d"),
line, col);
- g_free (title);
return;
}
+ /* Store book metadata */
+ *(parser->book_title) = g_strdup (title);
+ for (j = 0; (*(parser->book_title))[j]; j++) {
+ if ((*(parser->book_title))[j] == '\n')
+ (*(parser->book_title))[j] = ' ';
+ }
+ *(parser->book_name) = g_strdup (name);
+ *(parser->book_language) = language ? g_strdup (language) : NULL;
+
if (!base) {
base = g_path_get_dirname (parser->path);
}
link = dh_link_new (DH_LINK_TYPE_BOOK,
base,
- name,
- title,
+ *(parser->book_name),
+ *(parser->book_title),
NULL,
NULL,
uri);
@@ -162,7 +173,6 @@ parser_start_node_book (DhParser *parser,
parser->book_node = g_node_new (dh_link_ref (link));
*parser->book_tree = parser->book_node;
parser->parent = parser->book_node;
- g_free (title);
dh_link_unref (link);
}
@@ -523,6 +533,9 @@ parser_read_gz_file (DhParser *parser,
gboolean
dh_parser_read_file (const gchar *path,
+ gchar **book_title,
+ gchar **book_name,
+ gchar **book_language,
GNode **book_tree,
GList **keywords,
GError **error)
@@ -563,6 +576,9 @@ dh_parser_read_file (const gchar *path,
parser->path = path;
parser->book_tree = book_tree;
parser->keywords = keywords;
+ parser->book_title = book_title;
+ parser->book_name = book_name;
+ parser->book_language = book_language;
if (gz) {
if (!parser_read_gz_file (parser,
diff --git a/src/dh-parser.h b/src/dh-parser.h
index 9de1409..ac1dc6a 100644
--- a/src/dh-parser.h
+++ b/src/dh-parser.h
@@ -27,6 +27,9 @@
G_BEGIN_DECLS
gboolean dh_parser_read_file (const gchar *path,
+ gchar **book_title,
+ gchar **book_name,
+ gchar **book_language,
GNode **book_tree,
GList **keywords,
GError **error);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]