Move stylesheet deserialization to stylesheet.c
authorThomas White <taw@bitwiz.org.uk>
Thu, 10 Nov 2011 20:01:44 +0000 (21:01 +0100)
committerThomas White <taw@bitwiz.org.uk>
Thu, 10 Nov 2011 20:01:44 +0000 (21:01 +0100)
src/loadsave.c
src/loadsave.h
src/stylesheet.c
src/stylesheet.h

index 79ecc20..2d9e55f 100644 (file)
@@ -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;
index e5a1015..b5cd727 100644 (file)
@@ -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);
 
index a164029..ffbc099 100644 (file)
@@ -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;
index bdbf97e..0c021e4 100644 (file)
@@ -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 */