aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2011-11-10 21:01:44 +0100
committerThomas White <taw@bitwiz.org.uk>2011-11-10 21:01:44 +0100
commit5482598ad1ee3f42333d63b74b12aaa43f6ac963 (patch)
tree4f34a7ae2ad160af5e2733e0343a86834706a049
parentb3dba22613de912b01ae27ba30c73dfe4c05a340 (diff)
Move stylesheet deserialization to stylesheet.c
-rw-r--r--src/loadsave.c78
-rw-r--r--src/loadsave.h2
-rw-r--r--src/stylesheet.c77
-rw-r--r--src/stylesheet.h2
4 files changed, 81 insertions, 78 deletions
diff --git a/src/loadsave.c b/src/loadsave.c
index 79ecc20..2d9e55f 100644
--- a/src/loadsave.c
+++ b/src/loadsave.c
@@ -121,7 +121,7 @@ static void UNUSED show_tree(struct ds_node *root, const char *path)
}
-static struct ds_node *find_node(struct ds_node *root, const char *path)
+struct ds_node *find_node(struct ds_node *root, const char *path)
{
size_t start, len;
char element[1024];
@@ -407,82 +407,6 @@ int get_field_s(struct ds_node *root, const char *key, char **val)
}
-static int read_style(struct style *sty, struct ds_node *root)
-{
- char *align;
-
- get_field_f(root, "margin_left", &sty->margin_left);
- get_field_f(root, "margin_right", &sty->margin_right);
- get_field_f(root, "margin_top", &sty->margin_top);
- get_field_f(root, "margin_bottom", &sty->margin_bottom);
-
- get_field_i(root, "use_max_width", &sty->use_max_width);
- get_field_f(root, "max_width", &sty->max_width);
-
- get_field_f(root, "offset_x", &sty->offset_x);
- get_field_f(root, "offset_y", &sty->offset_y);
-
- get_field_s(root, "font", &sty->font);
- get_field_s(root, "colour", &sty->colour);
- get_field_f(root, "alpha", &sty->alpha);
-
- get_field_s(root, "halign", &align);
- sty->halign = str_to_halign(align);
- free(align);
- get_field_s(root, "valign", &align);
- sty->valign = str_to_valign(align);
- free(align);
-
- return 0;
-}
-
-
-static StyleSheet *tree_to_stylesheet(struct ds_node *root)
-{
- StyleSheet *ss;
- struct ds_node *node;
- int i;
-
- ss = new_stylesheet();
- if ( ss == NULL ) return NULL;
-
- node = find_node(root, "styles");
- if ( node == NULL ) {
- fprintf(stderr, "Couldn't find styles\n");
- free_stylesheet(ss);
- return NULL;
- }
-
- for ( i=0; i<node->n_children; i++ ) {
-
- struct style *ns;
- char *v;
-
- get_field_s(node->children[i], "name", &v);
- if ( v == NULL ) {
- fprintf(stderr, "No name for style '%s'\n",
- node->children[i]->key);
- continue;
- }
-
- ns = new_style(ss, v);
- if ( ns == NULL ) {
- fprintf(stderr, "Couldn't create style for '%s'\n",
- node->children[i]->key);
- continue;
- }
-
- if ( read_style(ns, node->children[i]) ) {
- fprintf(stderr, "Couldn't read style '%s'\n", v);
- continue;
- }
-
- }
-
- return ss;
-}
-
-
static enum objtype text_to_type(const char *t)
{
if ( strcmp(t, "text") == 0 ) return OBJ_TEXT;
diff --git a/src/loadsave.h b/src/loadsave.h
index e5a1015..b5cd727 100644
--- a/src/loadsave.h
+++ b/src/loadsave.h
@@ -61,6 +61,8 @@ extern int get_field_f(struct ds_node *root, const char *key, double *val);
extern int get_field_i(struct ds_node *root, const char *key, int *val);
extern int get_field_s(struct ds_node *root, const char *key, char **val);
+extern struct ds_node *find_node(struct ds_node *root, const char *path);
+
extern int load_presentation(struct presentation *p, const char *filename);
extern int save_presentation(struct presentation *p, const char *filename);
diff --git a/src/stylesheet.c b/src/stylesheet.c
index a164029..ffbc099 100644
--- a/src/stylesheet.c
+++ b/src/stylesheet.c
@@ -586,6 +586,83 @@ void default_stylesheet(StyleSheet *ss)
}
+static int read_style(struct style *sty, struct ds_node *root)
+{
+ char *align;
+
+ get_field_f(root, "margin_left", &sty->margin_left);
+ get_field_f(root, "margin_right", &sty->margin_right);
+ get_field_f(root, "margin_top", &sty->margin_top);
+ get_field_f(root, "margin_bottom", &sty->margin_bottom);
+
+ get_field_i(root, "use_max_width", &sty->use_max_width);
+ get_field_f(root, "max_width", &sty->max_width);
+
+ get_field_f(root, "offset_x", &sty->offset_x);
+ get_field_f(root, "offset_y", &sty->offset_y);
+
+ get_field_s(root, "font", &sty->font);
+ get_field_s(root, "colour", &sty->colour);
+ get_field_f(root, "alpha", &sty->alpha);
+
+ get_field_s(root, "halign", &align);
+ sty->halign = str_to_halign(align);
+ free(align);
+ get_field_s(root, "valign", &align);
+ sty->valign = str_to_valign(align);
+ free(align);
+
+ return 0;
+}
+
+
+StyleSheet *tree_to_stylesheet(struct ds_node *root)
+{
+ StyleSheet *ss;
+ struct ds_node *node;
+ int i;
+
+ ss = new_stylesheet();
+ if ( ss == NULL ) return NULL;
+
+ node = find_node(root, "styles");
+ if ( node == NULL ) {
+ fprintf(stderr, "Couldn't find styles\n");
+ free_stylesheet(ss);
+ return NULL;
+ }
+
+ for ( i=0; i<node->n_children; i++ ) {
+
+ struct style *ns;
+ char *v;
+
+ get_field_s(node->children[i], "name", &v);
+ if ( v == NULL ) {
+ fprintf(stderr, "No name for style '%s'\n",
+ node->children[i]->key);
+ continue;
+ }
+
+ ns = new_style(ss, v);
+ if ( ns == NULL ) {
+ fprintf(stderr, "Couldn't create style for '%s'\n",
+ node->children[i]->key);
+ continue;
+ }
+
+ if ( read_style(ns, node->children[i]) ) {
+ fprintf(stderr, "Couldn't read style '%s'\n", v);
+ continue;
+ }
+
+ }
+
+ return ss;
+}
+
+
+
StyleSheet *new_stylesheet()
{
StyleSheet *ss;
diff --git a/src/stylesheet.h b/src/stylesheet.h
index bdbf97e..0c021e4 100644
--- a/src/stylesheet.h
+++ b/src/stylesheet.h
@@ -131,7 +131,7 @@ extern struct style *find_style(StyleSheet *ss, const char *name);
extern enum justify str_to_halign(char *halign);
extern enum vert_pos str_to_valign(char *valign);
-
+extern StyleSheet *tree_to_stylesheet(struct ds_node *root);
extern void write_stylesheet(StyleSheet *ss, struct serializer *ser);
#endif /* STYLESHEET_H */