From: Jim Evins Date: Sun, 19 Dec 2010 04:58:02 +0000 (-0500) Subject: Coding style cleanup. X-Git-Tag: glabels-2_3_1~27 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=791f29c01c646eaebc443c5220405d399b6082cb;p=glabels Coding style cleanup. --- diff --git a/libglabels/lgl-category.c b/libglabels/lgl-category.c index a7335354..45945d67 100644 --- a/libglabels/lgl-category.c +++ b/libglabels/lgl-category.c @@ -63,13 +63,13 @@ lglCategory * lgl_category_new (gchar *id, gchar *name) { - lglCategory *category; + lglCategory *category; - category = g_new0 (lglCategory,1); - category->id = g_strdup (id); - category->name = g_strdup (name); + category = g_new0 (lglCategory,1); + category->id = g_strdup (id); + category->name = g_strdup (name); - return category; + return category; } @@ -84,16 +84,16 @@ lgl_category_new (gchar *id, */ lglCategory *lgl_category_dup (const lglCategory *orig) { - lglCategory *category; + lglCategory *category; - g_return_val_if_fail (orig, NULL); + g_return_val_if_fail (orig, NULL); - category = g_new0 (lglCategory,1); + category = g_new0 (lglCategory,1); - category->id = g_strdup (orig->id); - category->name = g_strdup (orig->name); + category->id = g_strdup (orig->id); + category->name = g_strdup (orig->name); - return category; + return category; } @@ -107,16 +107,16 @@ lglCategory *lgl_category_dup (const lglCategory *orig) void lgl_category_free (lglCategory *category) { - if ( category != NULL ) { + if ( category != NULL ) + { + g_free (category->id); + category->id = NULL; - g_free (category->id); - category->id = NULL; + g_free (category->name); + category->name = NULL; - g_free (category->name); - category->name = NULL; - - g_free (category); - } + g_free (category); + } } diff --git a/libglabels/lgl-category.h b/libglabels/lgl-category.h index 8ac35362..02853d44 100644 --- a/libglabels/lgl-category.h +++ b/libglabels/lgl-category.h @@ -31,8 +31,8 @@ G_BEGIN_DECLS typedef struct _lglCategory lglCategory; struct _lglCategory { - gchar *id; /* Unique ID of category */ - gchar *name; /* Localized name of category */ + gchar *id; /* Unique ID of category */ + gchar *name; /* Localized name of category */ }; diff --git a/libglabels/lgl-db.c b/libglabels/lgl-db.c index fed3aeec..0225a98b 100644 --- a/libglabels/lgl-db.c +++ b/libglabels/lgl-db.c @@ -112,7 +112,7 @@ static void add_to_template_cache (lglTemplate *template); static GList *read_papers (void); static GList *read_paper_files_from_dir (GList *papers, - const gchar *dirname); + const gchar *dirname); static GList *read_categories (void); static GList *read_category_files_from_dir (GList *categories, @@ -120,7 +120,7 @@ static GList *read_category_files_from_dir (GList *categories, static GList *read_vendors (void); static GList *read_vendor_files_from_dir (GList *vendors, - const gchar *dirname); + const gchar *dirname); static void read_templates (void); static void read_template_files_from_dir (const gchar *dirname); @@ -182,33 +182,33 @@ lgl_db_model_finalize (GObject *object) g_hash_table_unref (this->template_cache); - for (p = this->papers; p != NULL; p = p->next) + for (p = this->papers; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } - g_list_free (this->papers); + g_free (p->data); + p->data = NULL; + } + g_list_free (this->papers); - for (p = this->categories; p != NULL; p = p->next) + for (p = this->categories; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } - g_list_free (this->categories); + g_free (p->data); + p->data = NULL; + } + g_list_free (this->categories); - for (p = this->vendors; p != NULL; p = p->next) + for (p = this->vendors; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } - g_list_free (this->vendors); + g_free (p->data); + p->data = NULL; + } + g_list_free (this->vendors); - for (p = this->templates; p != NULL; p = p->next) + for (p = this->templates; p != NULL; p = p->next) { - lgl_template_free ((lglTemplate *)p->data); - p->data = NULL; - } - g_list_free (this->templates); + lgl_template_free ((lglTemplate *)p->data); + p->data = NULL; + } + g_list_free (this->templates); G_OBJECT_CLASS (lgl_db_model_parent_class)->finalize (object); } @@ -247,7 +247,7 @@ lgl_db_model_new (void) void lgl_db_init (void) { - lglPaper *paper_other; + lglPaper *paper_other; lglCategory *category_user_defined; lglTemplate *template; GList *page_sizes; @@ -315,10 +315,10 @@ gulong lgl_db_notify_add (lglDbNotifyFunc func, gpointer user_data) { - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } return g_signal_connect_swapped (G_OBJECT (model), "changed", G_CALLBACK (func), user_data); } @@ -352,22 +352,22 @@ lgl_db_notify_remove (gulong id) GList * lgl_db_get_paper_id_list (void) { - GList *ids = NULL; - GList *p; - lglPaper *paper; + GList *ids = NULL; + GList *p; + lglPaper *paper; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - for ( p=model->papers; p != NULL; p=p->next ) + for ( p=model->papers; p != NULL; p=p->next ) { - paper = (lglPaper *)p->data; - ids = g_list_append (ids, g_strdup (paper->id)); - } + paper = (lglPaper *)p->data; + ids = g_list_append (ids, g_strdup (paper->id)); + } - return ids; + return ids; } @@ -382,15 +382,15 @@ lgl_db_get_paper_id_list (void) void lgl_db_free_paper_id_list (GList *ids) { - GList *p; + GList *p; - for (p = ids; p != NULL; p = p->next) + for (p = ids; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } + g_free (p->data); + p->data = NULL; + } - g_list_free (ids); + g_list_free (ids); } @@ -405,22 +405,22 @@ lgl_db_free_paper_id_list (GList *ids) GList * lgl_db_get_paper_name_list (void) { - GList *names = NULL; - GList *p; - lglPaper *paper; + GList *names = NULL; + GList *p; + lglPaper *paper; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - for ( p=model->papers; p != NULL; p=p->next ) + for ( p=model->papers; p != NULL; p=p->next ) { - paper = (lglPaper *)p->data; - names = g_list_append (names, g_strdup (paper->name)); - } + paper = (lglPaper *)p->data; + names = g_list_append (names, g_strdup (paper->name)); + } - return names; + return names; } @@ -435,15 +435,15 @@ lgl_db_get_paper_name_list (void) void lgl_db_free_paper_name_list (GList *names) { - GList *p; + GList *p; - for (p = names; p != NULL; p = p->next) + for (p = names; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } + g_free (p->data); + p->data = NULL; + } - g_list_free (names); + g_list_free (names); } @@ -459,30 +459,30 @@ lgl_db_free_paper_name_list (GList *names) lglPaper * lgl_db_lookup_paper_from_name (const gchar *name) { - GList *p; - lglPaper *paper; + GList *p; + lglPaper *paper; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (name == NULL) + if (name == NULL) { - /* If no name, return first paper as a default */ - return lgl_paper_dup ((lglPaper *) model->papers->data); - } + /* If no name, return first paper as a default */ + return lgl_paper_dup ((lglPaper *) model->papers->data); + } - for (p = model->papers; p != NULL; p = p->next) + for (p = model->papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; - if (UTF8_EQUAL (paper->name, name)) + paper = (lglPaper *) p->data; + if (UTF8_EQUAL (paper->name, name)) { - return lgl_paper_dup (paper); - } - } + return lgl_paper_dup (paper); + } + } - return NULL; + return NULL; } @@ -498,30 +498,30 @@ lgl_db_lookup_paper_from_name (const gchar *name) lglPaper * lgl_db_lookup_paper_from_id (const gchar *id) { - GList *p; - lglPaper *paper; + GList *p; + lglPaper *paper; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (id == NULL) + if (id == NULL) { - /* If no id, return first paper as a default */ - return lgl_paper_dup ((lglPaper *) model->papers->data); - } + /* If no id, return first paper as a default */ + return lgl_paper_dup ((lglPaper *) model->papers->data); + } - for (p = model->papers; p != NULL; p = p->next) + for (p = model->papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; - if (ASCII_EQUAL (paper->id, id)) + paper = (lglPaper *) p->data; + if (ASCII_EQUAL (paper->id, id)) { - return lgl_paper_dup (paper); - } - } + return lgl_paper_dup (paper); + } + } - return NULL; + return NULL; } @@ -537,21 +537,21 @@ lgl_db_lookup_paper_from_id (const gchar *id) gchar * lgl_db_lookup_paper_id_from_name (const gchar *name) { - lglPaper *paper = NULL; - gchar *id = NULL; - - if (name != NULL) - { - paper = lgl_db_lookup_paper_from_name (name); - if ( paper != NULL ) - { - id = g_strdup (paper->id); - lgl_paper_free (paper); - paper = NULL; - } - } - - return id; + lglPaper *paper = NULL; + gchar *id = NULL; + + if (name != NULL) + { + paper = lgl_db_lookup_paper_from_name (name); + if ( paper != NULL ) + { + id = g_strdup (paper->id); + lgl_paper_free (paper); + paper = NULL; + } + } + + return id; } @@ -567,21 +567,21 @@ lgl_db_lookup_paper_id_from_name (const gchar *name) gchar * lgl_db_lookup_paper_name_from_id (const gchar *id) { - lglPaper *paper = NULL; - gchar *name = NULL; - - if (id != NULL) - { - paper = lgl_db_lookup_paper_from_id (id); - if ( paper != NULL ) - { - name = g_strdup (paper->name); - lgl_paper_free (paper); - paper = NULL; - } - } - - return name; + lglPaper *paper = NULL; + gchar *name = NULL; + + if (id != NULL) + { + paper = lgl_db_lookup_paper_from_id (id); + if ( paper != NULL ) + { + name = g_strdup (paper->name); + lgl_paper_free (paper); + paper = NULL; + } + } + + return name; } @@ -597,29 +597,29 @@ lgl_db_lookup_paper_name_from_id (const gchar *id) gboolean lgl_db_is_paper_id_known (const gchar *id) { - GList *p; - lglPaper *paper; + GList *p; + lglPaper *paper; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (id == NULL) + if (id == NULL) { - return FALSE; - } + return FALSE; + } - for (p = model->papers; p != NULL; p = p->next) + for (p = model->papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; - if (ASCII_EQUAL (paper->id, id)) + paper = (lglPaper *) p->data; + if (ASCII_EQUAL (paper->id, id)) { - return TRUE; - } - } + return TRUE; + } + } - return FALSE; + return FALSE; } @@ -635,88 +635,94 @@ lgl_db_is_paper_id_known (const gchar *id) gboolean lgl_db_is_paper_id_other (const gchar *id) { - if (id == NULL) + if (id == NULL) { - return FALSE; - } + return FALSE; + } - return (ASCII_EQUAL (id, "Other")); + return (ASCII_EQUAL (id, "Other")); } static GList * read_papers (void) { - gchar *data_dir; - GList *papers = NULL; + gchar *data_dir; + GList *papers = NULL; - data_dir = SYSTEM_CONFIG_DIR; - papers = read_paper_files_from_dir (papers, data_dir); - g_free (data_dir); + data_dir = SYSTEM_CONFIG_DIR; + papers = read_paper_files_from_dir (papers, data_dir); + g_free (data_dir); - data_dir = USER_CONFIG_DIR; - papers = read_paper_files_from_dir (papers, data_dir); - g_free (data_dir); + data_dir = USER_CONFIG_DIR; + papers = read_paper_files_from_dir (papers, data_dir); + g_free (data_dir); - if (papers == NULL) { - g_critical (_("Unable to locate paper size definitions. Libglabels may not be installed correctly!")); - } + if (papers == NULL) + { + g_critical (_("Unable to locate paper size definitions. Libglabels may not be installed correctly!")); + } - return papers; + return papers; } static GList * read_paper_files_from_dir (GList *papers, - const gchar *dirname) + const gchar *dirname) { - GDir *dp; - const gchar *filename, *extension; - gchar *full_filename = NULL; - GError *gerror = NULL; - GList *new_papers = NULL; + GDir *dp; + const gchar *filename, *extension; + gchar *full_filename = NULL; + GError *gerror = NULL; + GList *new_papers = NULL; - if (dirname == NULL) { - return papers; - } + if (dirname == NULL) + { + return papers; + } - if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { - return papers; - } + if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) + { + return papers; + } - dp = g_dir_open (dirname, 0, &gerror); - if (gerror != NULL) { - g_message ("cannot open data directory: %s", gerror->message ); - return papers; - } + dp = g_dir_open (dirname, 0, &gerror); + if (gerror != NULL) + { + g_message ("cannot open data directory: %s", gerror->message ); + return papers; + } - while ((filename = g_dir_read_name (dp)) != NULL) { + while ((filename = g_dir_read_name (dp)) != NULL) + { - extension = strrchr (filename, '.'); + extension = strrchr (filename, '.'); - if (extension != NULL) { + if (extension != NULL) + { - if ( ASCII_EQUAL (filename, "paper-sizes.xml") ) + if ( ASCII_EQUAL (filename, "paper-sizes.xml") ) { - full_filename = - g_build_filename (dirname, filename, NULL); - new_papers = - lgl_xml_paper_read_papers_from_file (full_filename); - g_free (full_filename); + full_filename = + g_build_filename (dirname, filename, NULL); + new_papers = + lgl_xml_paper_read_papers_from_file (full_filename); + g_free (full_filename); - papers = g_list_concat (papers, new_papers); - new_papers = NULL; + papers = g_list_concat (papers, new_papers); + new_papers = NULL; - } + } - } + } - } + } - g_dir_close (dp); + g_dir_close (dp); - return papers; + return papers; } @@ -730,22 +736,23 @@ read_paper_files_from_dir (GList *papers, void lgl_db_print_known_papers (void) { - GList *p; - lglPaper *paper; - - if (!model) { - lgl_db_init (); - } + GList *p; + lglPaper *paper; - g_print ("%s():\n", __FUNCTION__); - for (p = model->papers; p != NULL; p = p->next) { - paper = (lglPaper *) p->data; + if (!model) + { + lgl_db_init (); + } - g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n", - paper->id, paper->name, paper->width, paper->height); + g_print ("%s():\n", __FUNCTION__); + for (p = model->papers; p != NULL; p = p->next) + { + paper = (lglPaper *) p->data; - } - g_print ("\n"); + g_print ("PAPER id=\"%s\", name=\"%s\", width=%gpts, height=%gpts\n", + paper->id, paper->name, paper->width, paper->height); + } + g_print ("\n"); } @@ -765,22 +772,22 @@ lgl_db_print_known_papers (void) GList * lgl_db_get_category_id_list (void) { - GList *ids = NULL; - GList *p; - lglCategory *category; + GList *ids = NULL; + GList *p; + lglCategory *category; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - for ( p=model->categories; p != NULL; p=p->next ) + for ( p=model->categories; p != NULL; p=p->next ) { - category = (lglCategory *)p->data; - ids = g_list_append (ids, g_strdup (category->id)); - } + category = (lglCategory *)p->data; + ids = g_list_append (ids, g_strdup (category->id)); + } - return ids; + return ids; } @@ -795,15 +802,15 @@ lgl_db_get_category_id_list (void) void lgl_db_free_category_id_list (GList *ids) { - GList *p; + GList *p; - for (p = ids; p != NULL; p = p->next) + for (p = ids; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } + g_free (p->data); + p->data = NULL; + } - g_list_free (ids); + g_list_free (ids); } @@ -818,22 +825,22 @@ lgl_db_free_category_id_list (GList *ids) GList * lgl_db_get_category_name_list (void) { - GList *names = NULL; - GList *p; - lglCategory *category; + GList *names = NULL; + GList *p; + lglCategory *category; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - for ( p=model->categories; p != NULL; p=p->next ) + for ( p=model->categories; p != NULL; p=p->next ) { - category = (lglCategory *)p->data; - names = g_list_append (names, g_strdup (category->name)); - } + category = (lglCategory *)p->data; + names = g_list_append (names, g_strdup (category->name)); + } - return names; + return names; } @@ -848,15 +855,15 @@ lgl_db_get_category_name_list (void) void lgl_db_free_category_name_list (GList *names) { - GList *p; + GList *p; - for (p = names; p != NULL; p = p->next) + for (p = names; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } + g_free (p->data); + p->data = NULL; + } - g_list_free (names); + g_list_free (names); } @@ -872,30 +879,30 @@ lgl_db_free_category_name_list (GList *names) lglCategory * lgl_db_lookup_category_from_name (const gchar *name) { - GList *p; - lglCategory *category; + GList *p; + lglCategory *category; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (name == NULL) + if (name == NULL) { - /* If no name, return first category as a default */ - return lgl_category_dup ((lglCategory *) model->categories->data); - } + /* If no name, return first category as a default */ + return lgl_category_dup ((lglCategory *) model->categories->data); + } - for (p = model->categories; p != NULL; p = p->next) + for (p = model->categories; p != NULL; p = p->next) { - category = (lglCategory *) p->data; - if (UTF8_EQUAL (category->name, name)) + category = (lglCategory *) p->data; + if (UTF8_EQUAL (category->name, name)) { - return lgl_category_dup (category); - } - } + return lgl_category_dup (category); + } + } - return NULL; + return NULL; } @@ -911,30 +918,30 @@ lgl_db_lookup_category_from_name (const gchar *name) lglCategory * lgl_db_lookup_category_from_id (const gchar *id) { - GList *p; - lglCategory *category; + GList *p; + lglCategory *category; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (id == NULL) + if (id == NULL) { - /* If no id, return first category as a default */ - return lgl_category_dup ((lglCategory *) model->categories->data); - } + /* If no id, return first category as a default */ + return lgl_category_dup ((lglCategory *) model->categories->data); + } - for (p = model->categories; p != NULL; p = p->next) + for (p = model->categories; p != NULL; p = p->next) { - category = (lglCategory *) p->data; - if (ASCII_EQUAL (category->id, id)) + category = (lglCategory *) p->data; + if (ASCII_EQUAL (category->id, id)) { - return lgl_category_dup (category); - } - } + return lgl_category_dup (category); + } + } - return NULL; + return NULL; } @@ -950,21 +957,21 @@ lgl_db_lookup_category_from_id (const gchar *id) gchar * lgl_db_lookup_category_id_from_name (const gchar *name) { - lglCategory *category = NULL; - gchar *id = NULL; - - if (name != NULL) - { - category = lgl_db_lookup_category_from_name (name); - if ( category != NULL ) - { - id = g_strdup (category->id); - lgl_category_free (category); - category = NULL; - } - } - - return id; + lglCategory *category = NULL; + gchar *id = NULL; + + if (name != NULL) + { + category = lgl_db_lookup_category_from_name (name); + if ( category != NULL ) + { + id = g_strdup (category->id); + lgl_category_free (category); + category = NULL; + } + } + + return id; } @@ -980,21 +987,21 @@ lgl_db_lookup_category_id_from_name (const gchar *name) gchar * lgl_db_lookup_category_name_from_id (const gchar *id) { - lglCategory *category = NULL; - gchar *name = NULL; - - if (id != NULL) - { - category = lgl_db_lookup_category_from_id (id); - if ( category != NULL ) - { - name = g_strdup (category->name); - lgl_category_free (category); - category = NULL; - } - } - - return name; + lglCategory *category = NULL; + gchar *name = NULL; + + if (id != NULL) + { + category = lgl_db_lookup_category_from_id (id); + if ( category != NULL ) + { + name = g_strdup (category->name); + lgl_category_free (category); + category = NULL; + } + } + + return name; } @@ -1010,51 +1017,52 @@ lgl_db_lookup_category_name_from_id (const gchar *id) gboolean lgl_db_is_category_id_known (const gchar *id) { - GList *p; - lglCategory *category; + GList *p; + lglCategory *category; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (id == NULL) + if (id == NULL) { - return FALSE; - } + return FALSE; + } - for (p = model->categories; p != NULL; p = p->next) + for (p = model->categories; p != NULL; p = p->next) { - category = (lglCategory *) p->data; - if (ASCII_EQUAL (category->id, id)) + category = (lglCategory *) p->data; + if (ASCII_EQUAL (category->id, id)) { - return TRUE; - } - } + return TRUE; + } + } - return FALSE; + return FALSE; } static GList * read_categories (void) { - gchar *data_dir; - GList *categories = NULL; + gchar *data_dir; + GList *categories = NULL; - data_dir = SYSTEM_CONFIG_DIR; - categories = read_category_files_from_dir (categories, data_dir); - g_free (data_dir); + data_dir = SYSTEM_CONFIG_DIR; + categories = read_category_files_from_dir (categories, data_dir); + g_free (data_dir); - data_dir = USER_CONFIG_DIR; - categories = read_category_files_from_dir (categories, data_dir); - g_free (data_dir); + data_dir = USER_CONFIG_DIR; + categories = read_category_files_from_dir (categories, data_dir); + g_free (data_dir); - if (categories == NULL) { - g_critical (_("Unable to locate category definitions. Libglabels may not be installed correctly!")); - } + if (categories == NULL) + { + g_critical (_("Unable to locate category definitions. Libglabels may not be installed correctly!")); + } - return categories; + return categories; } @@ -1062,53 +1070,58 @@ static GList * read_category_files_from_dir (GList *categories, const gchar *dirname) { - GDir *dp; - const gchar *filename, *extension; - gchar *full_filename = NULL; - GError *gerror = NULL; - GList *new_categories = NULL; + GDir *dp; + const gchar *filename, *extension; + gchar *full_filename = NULL; + GError *gerror = NULL; + GList *new_categories = NULL; - if (dirname == NULL) { - return categories; - } + if (dirname == NULL) + { + return categories; + } - if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { - return categories; - } + if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) + { + return categories; + } - dp = g_dir_open (dirname, 0, &gerror); - if (gerror != NULL) { - g_message ("cannot open data directory: %s", gerror->message ); - return categories; - } + dp = g_dir_open (dirname, 0, &gerror); + if (gerror != NULL) + { + g_message ("cannot open data directory: %s", gerror->message ); + return categories; + } - while ((filename = g_dir_read_name (dp)) != NULL) { + while ((filename = g_dir_read_name (dp)) != NULL) + { - extension = strrchr (filename, '.'); + extension = strrchr (filename, '.'); - if (extension != NULL) { + if (extension != NULL) + { - if ( ASCII_EQUAL (filename, "categories.xml") ) + if ( ASCII_EQUAL (filename, "categories.xml") ) { - full_filename = - g_build_filename (dirname, filename, NULL); - new_categories = - lgl_xml_category_read_categories_from_file (full_filename); - g_free (full_filename); + full_filename = + g_build_filename (dirname, filename, NULL); + new_categories = + lgl_xml_category_read_categories_from_file (full_filename); + g_free (full_filename); - categories = g_list_concat (categories, new_categories); - new_categories = NULL; + categories = g_list_concat (categories, new_categories); + new_categories = NULL; - } + } - } + } - } + } - g_dir_close (dp); + g_dir_close (dp); - return categories; + return categories; } @@ -1122,21 +1135,22 @@ read_category_files_from_dir (GList *categories, void lgl_db_print_known_categories (void) { - GList *p; - lglCategory *category; - - if (!model) { - lgl_db_init (); - } + GList *p; + lglCategory *category; - g_print ("%s():\n", __FUNCTION__); - for (p = model->categories; p != NULL; p = p->next) { - category = (lglCategory *) p->data; + if (!model) + { + lgl_db_init (); + } - g_print ("CATEGORY id=\"%s\", name=\"%s\"\n", category->id, category->name); + g_print ("%s():\n", __FUNCTION__); + for (p = model->categories; p != NULL; p = p->next) + { + category = (lglCategory *) p->data; - } - g_print ("\n"); + g_print ("CATEGORY id=\"%s\", name=\"%s\"\n", category->id, category->name); + } + g_print ("\n"); } @@ -1156,22 +1170,22 @@ lgl_db_print_known_categories (void) GList * lgl_db_get_vendor_name_list (void) { - GList *names = NULL; - GList *p; - lglVendor *vendor; + GList *names = NULL; + GList *p; + lglVendor *vendor; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - for ( p=model->vendors; p != NULL; p=p->next ) + for ( p=model->vendors; p != NULL; p=p->next ) { - vendor = (lglVendor *)p->data; - names = g_list_append (names, g_strdup (vendor->name)); - } + vendor = (lglVendor *)p->data; + names = g_list_append (names, g_strdup (vendor->name)); + } - return names; + return names; } @@ -1186,15 +1200,15 @@ lgl_db_get_vendor_name_list (void) void lgl_db_free_vendor_name_list (GList *names) { - GList *p; + GList *p; - for (p = names; p != NULL; p = p->next) + for (p = names; p != NULL; p = p->next) { - g_free (p->data); - p->data = NULL; - } + g_free (p->data); + p->data = NULL; + } - g_list_free (names); + g_list_free (names); } @@ -1210,30 +1224,30 @@ lgl_db_free_vendor_name_list (GList *names) lglVendor * lgl_db_lookup_vendor_from_name (const gchar *name) { - GList *p; - lglVendor *vendor; + GList *p; + lglVendor *vendor; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (name == NULL) + if (name == NULL) { - /* If no name, return first vendor as a default */ - return lgl_vendor_dup ((lglVendor *) model->vendors->data); - } + /* If no name, return first vendor as a default */ + return lgl_vendor_dup ((lglVendor *) model->vendors->data); + } - for (p = model->vendors; p != NULL; p = p->next) + for (p = model->vendors; p != NULL; p = p->next) { - vendor = (lglVendor *) p->data; - if (UTF8_EQUAL (vendor->name, name)) + vendor = (lglVendor *) p->data; + if (UTF8_EQUAL (vendor->name, name)) { - return lgl_vendor_dup (vendor); - } - } + return lgl_vendor_dup (vendor); + } + } - return NULL; + return NULL; } @@ -1249,101 +1263,106 @@ lgl_db_lookup_vendor_from_name (const gchar *name) gboolean lgl_db_is_vendor_name_known (const gchar *name) { - GList *p; - lglVendor *vendor; + GList *p; + lglVendor *vendor; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (name == NULL) + if (name == NULL) { - return FALSE; - } + return FALSE; + } - for (p = model->vendors; p != NULL; p = p->next) + for (p = model->vendors; p != NULL; p = p->next) { - vendor = (lglVendor *) p->data; - if (UTF8_EQUAL (vendor->name, name)) + vendor = (lglVendor *) p->data; + if (UTF8_EQUAL (vendor->name, name)) { - return TRUE; - } - } + return TRUE; + } + } - return FALSE; + return FALSE; } static GList * read_vendors (void) { - gchar *data_dir; - GList *vendors = NULL; + gchar *data_dir; + GList *vendors = NULL; - data_dir = SYSTEM_CONFIG_DIR; - vendors = read_vendor_files_from_dir (vendors, data_dir); - g_free (data_dir); + data_dir = SYSTEM_CONFIG_DIR; + vendors = read_vendor_files_from_dir (vendors, data_dir); + g_free (data_dir); - data_dir = USER_CONFIG_DIR; - vendors = read_vendor_files_from_dir (vendors, data_dir); - g_free (data_dir); + data_dir = USER_CONFIG_DIR; + vendors = read_vendor_files_from_dir (vendors, data_dir); + g_free (data_dir); - return vendors; + return vendors; } static GList * read_vendor_files_from_dir (GList *vendors, - const gchar *dirname) + const gchar *dirname) { - GDir *dp; - const gchar *filename, *extension; - gchar *full_filename = NULL; - GError *gerror = NULL; - GList *new_vendors = NULL; + GDir *dp; + const gchar *filename, *extension; + gchar *full_filename = NULL; + GError *gerror = NULL; + GList *new_vendors = NULL; - if (dirname == NULL) { - return vendors; - } + if (dirname == NULL) + { + return vendors; + } - if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { - return vendors; - } + if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) + { + return vendors; + } - dp = g_dir_open (dirname, 0, &gerror); - if (gerror != NULL) { - g_message ("cannot open data directory: %s", gerror->message ); - return vendors; - } + dp = g_dir_open (dirname, 0, &gerror); + if (gerror != NULL) + { + g_message ("cannot open data directory: %s", gerror->message ); + return vendors; + } - while ((filename = g_dir_read_name (dp)) != NULL) { + while ((filename = g_dir_read_name (dp)) != NULL) + { - extension = strrchr (filename, '.'); + extension = strrchr (filename, '.'); - if (extension != NULL) { + if (extension != NULL) + { - if ( ASCII_EQUAL (filename, "vendors.xml") ) + if ( ASCII_EQUAL (filename, "vendors.xml") ) { - full_filename = - g_build_filename (dirname, filename, NULL); - new_vendors = - lgl_xml_vendor_read_vendors_from_file (full_filename); - g_free (full_filename); + full_filename = + g_build_filename (dirname, filename, NULL); + new_vendors = + lgl_xml_vendor_read_vendors_from_file (full_filename); + g_free (full_filename); - vendors = g_list_concat (vendors, new_vendors); - new_vendors = NULL; + vendors = g_list_concat (vendors, new_vendors); + new_vendors = NULL; - } + } - } + } - } + } - g_dir_close (dp); + g_dir_close (dp); - return vendors; + return vendors; } @@ -1357,22 +1376,23 @@ read_vendor_files_from_dir (GList *vendors, void lgl_db_print_known_vendors (void) { - GList *p; - lglVendor *vendor; - - if (!model) { - lgl_db_init (); - } + GList *p; + lglVendor *vendor; - g_print ("%s():\n", __FUNCTION__); - for (p = model->vendors; p != NULL; p = p->next) { - vendor = (lglVendor *) p->data; + if (!model) + { + lgl_db_init (); + } - g_print ("VENDOR name=\"%s\", url=\"%s\"\n", - vendor->name, vendor->url); + g_print ("%s():\n", __FUNCTION__); + for (p = model->vendors; p != NULL; p = p->next) + { + vendor = (lglVendor *) p->data; - } - g_print ("\n"); + g_print ("VENDOR name=\"%s\", url=\"%s\"\n", + vendor->name, vendor->url); + } + g_print ("\n"); } @@ -1397,19 +1417,19 @@ GList * lgl_db_get_brand_list (const gchar *paper_id, const gchar *category_id) { - GList *p_tmplt; - lglTemplate *template; - GList *brands = NULL; + GList *p_tmplt; + lglTemplate *template; + GList *brands = NULL; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { - template = (lglTemplate *) p_tmplt->data; - if (lgl_template_does_page_size_match (template, paper_id) && + template = (lglTemplate *) p_tmplt->data; + if (lgl_template_does_page_size_match (template, paper_id) && lgl_template_does_category_match (template, category_id)) { @@ -1420,10 +1440,10 @@ lgl_db_get_brand_list (const gchar *paper_id, g_strdup (template->brand), (GCompareFunc)lgl_str_utf8_casecmp); } - } - } + } + } - return brands; + return brands; } @@ -1438,15 +1458,15 @@ lgl_db_get_brand_list (const gchar *paper_id, void lgl_db_free_brand_list (GList *brands) { - GList *p_brand; + GList *p_brand; - for (p_brand = brands; p_brand != NULL; p_brand = p_brand->next) + for (p_brand = brands; p_brand != NULL; p_brand = p_brand->next) { - g_free (p_brand->data); - p_brand->data = NULL; - } + g_free (p_brand->data); + p_brand->data = NULL; + } - g_list_free (brands); + g_list_free (brands); } @@ -1467,7 +1487,7 @@ _lgl_db_register_template_internal (const lglTemplate *template) } else { - g_message ("Duplicate template: %s %s.", template->brand, template->part); + g_message ("Duplicate template: %s %s.", template->brand, template->part); } } @@ -1488,26 +1508,26 @@ lgl_db_register_template (const lglTemplate *template) gchar *dir, *filename, *abs_filename; gint bytes_written; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } if (lgl_db_does_template_exist (template->brand, template->part)) { return LGL_DB_REG_BRAND_PART_EXISTS; } - if (lgl_db_is_paper_id_known (template->paper_id)) + if (lgl_db_is_paper_id_known (template->paper_id)) { - dir = USER_CONFIG_DIR; - g_mkdir_with_parents (dir, 0775); /* Try to make sure directory exists. */ - filename = g_strdup_printf ("%s_%s.template", template->brand, template->part); - abs_filename = g_build_filename (dir, filename, NULL); - bytes_written = lgl_xml_template_write_template_to_file (template, abs_filename); - g_free (dir); - g_free (filename); - g_free (abs_filename); + dir = USER_CONFIG_DIR; + g_mkdir_with_parents (dir, 0775); /* Try to make sure directory exists. */ + filename = g_strdup_printf ("%s_%s.template", template->brand, template->part); + abs_filename = g_build_filename (dir, filename, NULL); + bytes_written = lgl_xml_template_write_template_to_file (template, abs_filename); + g_free (dir); + g_free (filename); + g_free (abs_filename); if (bytes_written > 0) { @@ -1522,12 +1542,12 @@ lgl_db_register_template (const lglTemplate *template) { return LGL_DB_REG_FILE_WRITE_ERROR; } - } + } else { - g_message ("Cannot register new template with unknown page size."); + g_message ("Cannot register new template with unknown page size."); return LGL_DB_REG_BAD_PAPER_ID; - } + } } @@ -1549,10 +1569,10 @@ lgl_db_delete_template_by_name (const gchar *name) gchar *dir, *filename, *abs_filename; GList *p; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } if (!lgl_db_does_template_name_exist (name)) { @@ -1562,9 +1582,9 @@ lgl_db_delete_template_by_name (const gchar *name) template = lgl_db_lookup_template_from_name (name); if ( lgl_template_does_category_match (template, "user-defined") ) { - dir = USER_CONFIG_DIR; - filename = g_strdup_printf ("%s_%s.template", template->brand, template->part); - abs_filename = g_build_filename (dir, filename, NULL); + dir = USER_CONFIG_DIR; + filename = g_strdup_printf ("%s_%s.template", template->brand, template->part); + abs_filename = g_build_filename (dir, filename, NULL); if (!g_file_test (abs_filename, G_FILE_TEST_EXISTS)) { @@ -1574,9 +1594,9 @@ lgl_db_delete_template_by_name (const gchar *name) g_unlink (abs_filename); - g_free (dir); - g_free (filename); - g_free (abs_filename); + g_free (dir); + g_free (filename); + g_free (abs_filename); for ( p=model->templates; p != NULL; p=p->next ) { @@ -1644,31 +1664,31 @@ gboolean lgl_db_does_template_exist (const gchar *brand, const gchar *part) { - GList *p_tmplt; - lglTemplate *template; + GList *p_tmplt; + lglTemplate *template; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if ((brand == NULL) || (part == NULL)) + if ((brand == NULL) || (part == NULL)) { - return FALSE; - } + return FALSE; + } - for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { - template = (lglTemplate *) p_tmplt->data; + template = (lglTemplate *) p_tmplt->data; if ( UTF8_EQUAL (brand, template->brand) && UTF8_EQUAL (part, template->part) ) { return TRUE; } - } + } - return FALSE; + return FALSE; } @@ -1684,23 +1704,23 @@ lgl_db_does_template_exist (const gchar *brand, gboolean lgl_db_does_template_name_exist (const gchar *name) { - GList *p_tmplt; + GList *p_tmplt; lglTemplate *template; gchar *candidate_name; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (name == NULL) + if (name == NULL) { - return FALSE; - } + return FALSE; + } - for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { - template = (lglTemplate *) p_tmplt->data; + template = (lglTemplate *) p_tmplt->data; candidate_name = g_strdup_printf ("%s %s", template->brand, template->part); if ( UTF8_EQUAL (candidate_name, name) ) @@ -1709,9 +1729,9 @@ lgl_db_does_template_name_exist (const gchar *name) return TRUE; } g_free (candidate_name); - } + } - return FALSE; + return FALSE; } @@ -1733,29 +1753,29 @@ lgl_db_get_template_name_list_all (const gchar *brand, const gchar *paper_id, const gchar *category_id) { - GList *p_tmplt; - lglTemplate *template; + GList *p_tmplt; + lglTemplate *template; gchar *name; - GList *names = NULL; + GList *names = NULL; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { - template = (lglTemplate *) p_tmplt->data; - if (lgl_template_does_brand_match (template, brand) && + template = (lglTemplate *) p_tmplt->data; + if (lgl_template_does_brand_match (template, brand) && lgl_template_does_page_size_match (template, paper_id) && lgl_template_does_category_match (template, category_id)) { name = g_strdup_printf ("%s %s", template->brand, template->part); names = g_list_insert_sorted (names, name, (GCompareFunc)lgl_str_part_name_cmp); - } - } + } + } - return names; + return names; } @@ -1771,16 +1791,16 @@ lgl_db_get_template_name_list_all (const gchar *brand, GList * lgl_db_get_similar_template_name_list (const gchar *name) { - GList *p_tmplt; - lglTemplate *template1; - lglTemplate *template2; + GList *p_tmplt; + lglTemplate *template1; + lglTemplate *template2; gchar *name2; - GList *names = NULL; + GList *names = NULL; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } if ( !name ) { @@ -1793,9 +1813,9 @@ lgl_db_get_similar_template_name_list (const gchar *name) return NULL; } - for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) + for (p_tmplt = model->templates; p_tmplt != NULL; p_tmplt = p_tmplt->next) { - template2 = (lglTemplate *) p_tmplt->data; + template2 = (lglTemplate *) p_tmplt->data; if ( lgl_template_are_templates_identical (template1, template2) ) { @@ -1807,10 +1827,10 @@ lgl_db_get_similar_template_name_list (const gchar *name) (GCompareFunc)lgl_str_part_name_cmp); } - } - } + } + } - return names; + return names; } @@ -1825,15 +1845,15 @@ lgl_db_get_similar_template_name_list (const gchar *name) void lgl_db_free_template_name_list (GList *names) { - GList *p_name; + GList *p_name; - for (p_name = names; p_name != NULL; p_name = p_name->next) + for (p_name = names; p_name != NULL; p_name = p_name->next) { - g_free (p_name->data); - p_name->data = NULL; - } + g_free (p_name->data); + p_name->data = NULL; + } - g_list_free (names); + g_list_free (names); } @@ -1849,19 +1869,19 @@ lgl_db_free_template_name_list (GList *names) lglTemplate * lgl_db_lookup_template_from_name (const gchar *name) { - lglTemplate *template; - lglTemplate *new_template; + lglTemplate *template; + lglTemplate *new_template; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if (name == NULL) + if (name == NULL) { - /* If no name, return first template as a default */ - return lgl_template_dup ((lglTemplate *) model->templates->data); - } + /* If no name, return first template as a default */ + return lgl_template_dup ((lglTemplate *) model->templates->data); + } template = g_hash_table_lookup (model->template_cache, name); @@ -1871,8 +1891,8 @@ lgl_db_lookup_template_from_name (const gchar *name) return new_template; } - /* No matching template has been found so return the first template */ - return lgl_template_dup ((lglTemplate *) model->templates->data); + /* No matching template has been found so return the first template */ + return lgl_template_dup ((lglTemplate *) model->templates->data); } @@ -1891,19 +1911,19 @@ lgl_db_lookup_template_from_brand_part(const gchar *brand, const gchar *part) { gchar *name; - lglTemplate *template; - lglTemplate *new_template; + lglTemplate *template; + lglTemplate *new_template; - if (!model) + if (!model) { - lgl_db_init (); - } + lgl_db_init (); + } - if ((brand == NULL) || (part == NULL)) + if ((brand == NULL) || (part == NULL)) { - /* If no name, return first template as a default */ - return lgl_template_dup ((lglTemplate *) model->templates->data); - } + /* If no name, return first template as a default */ + return lgl_template_dup ((lglTemplate *) model->templates->data); + } name = g_strdup_printf ("%s %s", brand, part); template = g_hash_table_lookup (model->template_cache, name); @@ -1914,9 +1934,9 @@ lgl_db_lookup_template_from_brand_part(const gchar *brand, return new_template; } - /* No matching template has been found so return the first template */ + /* No matching template has been found so return the first template */ g_free (name); - return lgl_template_dup ((lglTemplate *) model->templates->data); + return lgl_template_dup ((lglTemplate *) model->templates->data); } @@ -1934,16 +1954,16 @@ add_to_template_cache (lglTemplate *template) void read_templates (void) { - gchar *data_dir; + gchar *data_dir; GList *p; lglTemplate *template; /* * User defined templates. Add to user-defined category. */ - data_dir = USER_CONFIG_DIR; - read_template_files_from_dir (data_dir); - g_free (data_dir); + data_dir = USER_CONFIG_DIR; + read_template_files_from_dir (data_dir); + g_free (data_dir); for ( p=model->templates; p != NULL; p=p->next ) { template = (lglTemplate *)p->data; @@ -1953,110 +1973,110 @@ read_templates (void) /* * Alternate user defined templates. (Used for manually created templates). */ - data_dir = ALT_USER_CONFIG_DIR; - read_template_files_from_dir (data_dir); - g_free (data_dir); + data_dir = ALT_USER_CONFIG_DIR; + read_template_files_from_dir (data_dir); + g_free (data_dir); /* * System templates. */ - data_dir = SYSTEM_CONFIG_DIR; - read_template_files_from_dir (data_dir); - g_free (data_dir); + data_dir = SYSTEM_CONFIG_DIR; + read_template_files_from_dir (data_dir); + g_free (data_dir); - if (model->templates == NULL) + if (model->templates == NULL) { - g_critical (_("Unable to locate any template files. Libglabels may not be installed correctly!")); - } + g_critical (_("Unable to locate any template files. Libglabels may not be installed correctly!")); + } } void read_template_files_from_dir (const gchar *dirname) { - GDir *dp; - const gchar *filename, *extension, *extension2; - gchar *full_filename = NULL; - GError *gerror = NULL; + GDir *dp; + const gchar *filename, *extension, *extension2; + gchar *full_filename = NULL; + GError *gerror = NULL; - if (dirname == NULL) - return; + if (dirname == NULL) + return; - if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) + if (!g_file_test (dirname, G_FILE_TEST_EXISTS)) { - return; - } + return; + } - dp = g_dir_open (dirname, 0, &gerror); - if (gerror != NULL) + dp = g_dir_open (dirname, 0, &gerror); + if (gerror != NULL) { - g_message ("cannot open data directory: %s", gerror->message ); - return; - } + g_message ("cannot open data directory: %s", gerror->message ); + return; + } - while ((filename = g_dir_read_name (dp)) != NULL) + while ((filename = g_dir_read_name (dp)) != NULL) { - extension = strrchr (filename, '.'); - extension2 = strrchr (filename, '-'); + extension = strrchr (filename, '.'); + extension2 = strrchr (filename, '-'); - if ( (extension && ASCII_EQUAL (extension, ".template")) || - (extension2 && ASCII_EQUAL (extension2, "-templates.xml")) ) + if ( (extension && ASCII_EQUAL (extension, ".template")) || + (extension2 && ASCII_EQUAL (extension2, "-templates.xml")) ) { - full_filename = g_build_filename (dirname, filename, NULL); + full_filename = g_build_filename (dirname, filename, NULL); lgl_xml_template_read_templates_from_file (full_filename); - g_free (full_filename); - } + g_free (full_filename); + } - } + } - g_dir_close (dp); + g_dir_close (dp); } static lglTemplate * template_full_page (const gchar *paper_id) { - lglPaper *paper = NULL; - lglTemplate *template = NULL; - lglTemplateFrame *frame = NULL; + lglPaper *paper = NULL; + lglTemplate *template = NULL; + lglTemplateFrame *frame = NULL; gchar *part; gchar *desc; - g_return_val_if_fail (paper_id, NULL); + g_return_val_if_fail (paper_id, NULL); - paper = lgl_db_lookup_paper_from_id (paper_id); - if ( paper == NULL ) + paper = lgl_db_lookup_paper_from_id (paper_id); + if ( paper == NULL ) { - return NULL; - } + return NULL; + } - part = g_strdup_printf ("%s-Full-Page", paper->id); - desc = g_strdup_printf (_("%s full page label"), paper->name); + part = g_strdup_printf ("%s-Full-Page", paper->id); + desc = g_strdup_printf (_("%s full page label"), paper->name); - template = lgl_template_new ("Generic", part, desc, + template = lgl_template_new ("Generic", part, desc, paper_id, paper->width, paper->height); - frame = lgl_template_frame_rect_new ("0", + frame = lgl_template_frame_rect_new ("0", paper->width, paper->height, 0.0, 0.0, 0.0); - lgl_template_add_frame (template, frame); + lgl_template_add_frame (template, frame); - lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0., 0., 0., 0.)); + lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0., 0., 0., 0.)); - lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0)); + lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (9.0)); - g_free (desc); - desc = NULL; - lgl_paper_free (paper); - paper = NULL; + g_free (desc); + desc = NULL; + lgl_paper_free (paper); + paper = NULL; - return template; + return template; } @@ -2069,24 +2089,24 @@ template_full_page (const gchar *paper_id) void lgl_db_print_known_templates (void) { - GList *p; - lglTemplate *template; + GList *p; + lglTemplate *template; if (!model) { lgl_db_init (); } - g_print ("%s():\n", __FUNCTION__); - for (p=model->templates; p!=NULL; p=p->next) + g_print ("%s():\n", __FUNCTION__); + for (p=model->templates; p!=NULL; p=p->next) { - template = (lglTemplate *)p->data; + template = (lglTemplate *)p->data; - g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n", - template->brand, template->part, template->description); + g_print("TEMPLATE brand=\"%s\", part=\"%s\", description=\"%s\"\n", + template->brand, template->part, template->description); - } - g_print ("\n"); + } + g_print ("\n"); } diff --git a/libglabels/lgl-paper.c b/libglabels/lgl-paper.c index 43cca91c..0a8405d3 100644 --- a/libglabels/lgl-paper.c +++ b/libglabels/lgl-paper.c @@ -63,22 +63,22 @@ */ lglPaper * lgl_paper_new (gchar *id, - gchar *name, - gdouble width, - gdouble height, - gchar *pwg_size) + gchar *name, + gdouble width, + gdouble height, + gchar *pwg_size) { - lglPaper *paper; + lglPaper *paper; - paper = g_new0 (lglPaper,1); + paper = g_new0 (lglPaper,1); - paper->id = g_strdup (id); - paper->name = g_strdup (name); - paper->width = width; - paper->height = height; - paper->pwg_size = g_strdup (pwg_size); + paper->id = g_strdup (id); + paper->name = g_strdup (name); + paper->width = width; + paper->height = height; + paper->pwg_size = g_strdup (pwg_size); - return paper; + return paper; } @@ -93,19 +93,19 @@ lgl_paper_new (gchar *id, */ lglPaper *lgl_paper_dup (const lglPaper *orig) { - lglPaper *paper; + lglPaper *paper; - g_return_val_if_fail (orig, NULL); + g_return_val_if_fail (orig, NULL); - paper = g_new0 (lglPaper,1); + paper = g_new0 (lglPaper,1); - paper->id = g_strdup (orig->id); - paper->name = g_strdup (orig->name); - paper->width = orig->width; - paper->height = orig->height; - paper->pwg_size = g_strdup (orig->pwg_size); + paper->id = g_strdup (orig->id); + paper->name = g_strdup (orig->name); + paper->width = orig->width; + paper->height = orig->height; + paper->pwg_size = g_strdup (orig->pwg_size); - return paper; + return paper; } @@ -119,19 +119,19 @@ lglPaper *lgl_paper_dup (const lglPaper *orig) void lgl_paper_free (lglPaper *paper) { - if ( paper != NULL ) { + if ( paper != NULL ) + { + g_free (paper->id); + paper->id = NULL; - g_free (paper->id); - paper->id = NULL; + g_free (paper->name); + paper->name = NULL; - g_free (paper->name); - paper->name = NULL; + g_free (paper->pwg_size); + paper->pwg_size = NULL; - g_free (paper->pwg_size); - paper->pwg_size = NULL; - - g_free (paper); - } + g_free (paper); + } } diff --git a/libglabels/lgl-paper.h b/libglabels/lgl-paper.h index ecb5b8ee..05c1e859 100644 --- a/libglabels/lgl-paper.h +++ b/libglabels/lgl-paper.h @@ -32,11 +32,11 @@ G_BEGIN_DECLS typedef struct _lglPaper lglPaper; struct _lglPaper { - gchar *id; /* Unique ID of paper definition */ - gchar *name; /* Localized name of paper */ - gdouble width; /* Width (in points) */ - gdouble height; /* Height (in points) */ - gchar *pwg_size; /* PWG 5101.1-2002 size name */ + gchar *id; /* Unique ID of paper definition */ + gchar *name; /* Localized name of paper */ + gdouble width; /* Width (in points) */ + gdouble height; /* Height (in points) */ + gchar *pwg_size; /* PWG 5101.1-2002 size name */ }; @@ -44,10 +44,10 @@ struct _lglPaper { * Paper construction */ lglPaper *lgl_paper_new (gchar *id, - gchar *name, - gdouble width, - gdouble height, - gchar *pwg_size); + gchar *name, + gdouble width, + gdouble height, + gchar *pwg_size); lglPaper *lgl_paper_dup (const lglPaper *orig); diff --git a/libglabels/lgl-str.c b/libglabels/lgl-str.c index 4618fadf..1a25c31c 100644 --- a/libglabels/lgl-str.c +++ b/libglabels/lgl-str.c @@ -124,9 +124,9 @@ lgl_str_part_name_cmp (const gchar *s1, gboolean done; gint result; - if ( s1 == s2 ) return 0; - if (s1 == NULL) return -1; - if (s2 == NULL) return 1; + if ( s1 == s2 ) return 0; + if (s1 == NULL) return -1; + if (s2 == NULL) return 1; folded_s1 = g_utf8_casefold (s1, -1); folded_s2 = g_utf8_casefold (s2, -1); @@ -160,7 +160,7 @@ lgl_str_part_name_cmp (const gchar *s1, isnum2 = FALSE; } - if ( (strlen(chunk1) == 0) && (strlen(chunk2) == 0) ) + if ( (*chunk1 == '\0') && (*chunk2 == '\0') ) { /* Case 1: Both are empty. */ done = TRUE; @@ -233,37 +233,43 @@ span_non_digits (gchar **p) gchar * lgl_str_format_fraction (gdouble x) { - static gdouble denom[] = { 1., 2., 3., 4., 8., 16., 32., 0. }; + static gdouble denom[] = { 1., 2., 3., 4., 8., 16., 32., 0. }; static gchar *denom_string[] = { "1", "₂", "₃", "₄", "₈", "₁₆", "₃₂", NULL }; static gchar *num_string[] = { "⁰", "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹", "¹⁰", "¹¹", "¹²", "¹³", "¹⁴", "¹⁵", "¹⁶", "¹⁷", "¹⁸", "¹⁹", "²⁰", "²¹", "²²", "²³", "²⁴", "²⁵", "²⁶", "²⁷", "²⁸", "²⁹", "³⁰", "³¹" }; - gint i; - gdouble product, remainder; - gint n, d; - - for ( i=0; denom[i] != 0.0; i++ ) { - product = x * denom[i]; - remainder = fabs(product - ((gint)(product+0.5))); - if ( remainder < FRAC_EPSILON ) break; - } - - if ( denom[i] == 0.0 ) { - /* None of our denominators work. */ - return g_strdup_printf ("%.5g", x); - } - if ( denom[i] == 1.0 ) { - /* Simple integer. */ - return g_strdup_printf ("%.0f", x); - } - n = (gint)( x * denom[i] + 0.5 ); - d = (gint)denom[i]; - if ( n > d ) { - return g_strdup_printf ("%d%s/%s", (n/d), num_string[n%d], denom_string[i]); - } else { - return g_strdup_printf ("%s/%s", num_string[n%d], denom_string[i]); - } + gint i; + gdouble product, remainder; + gint n, d; + + for ( i=0; denom[i] != 0.0; i++ ) + { + product = x * denom[i]; + remainder = fabs(product - ((gint)(product+0.5))); + if ( remainder < FRAC_EPSILON ) break; + } + + if ( denom[i] == 0.0 ) + { + /* None of our denominators work. */ + return g_strdup_printf ("%.5g", x); + } + if ( denom[i] == 1.0 ) + { + /* Simple integer. */ + return g_strdup_printf ("%.0f", x); + } + n = (gint)( x * denom[i] + 0.5 ); + d = (gint)denom[i]; + if ( n > d ) + { + return g_strdup_printf ("%d%s/%s", (n/d), num_string[n%d], denom_string[i]); + } + else + { + return g_strdup_printf ("%s/%s", num_string[n%d], denom_string[i]); + } } diff --git a/libglabels/lgl-template.c b/libglabels/lgl-template.c index 11763dcf..bcaef5bf 100644 --- a/libglabels/lgl-template.c +++ b/libglabels/lgl-template.c @@ -88,18 +88,18 @@ lgl_template_new (const gchar *brand, gdouble page_width, gdouble page_height) { - lglTemplate *template; + lglTemplate *template; - template = g_new0 (lglTemplate,1); + template = g_new0 (lglTemplate,1); - template->brand = g_strdup (brand); - template->part = g_strdup (part); - template->description = g_strdup (description); - template->paper_id = g_strdup (paper_id); - template->page_width = page_width; - template->page_height = page_height; + template->brand = g_strdup (brand); + template->part = g_strdup (part); + template->description = g_strdup (description); + template->paper_id = g_strdup (paper_id); + template->page_width = page_width; + template->page_height = page_height; - return template; + return template; } @@ -156,7 +156,7 @@ lgl_template_new_from_equiv (const gchar *brand, gchar * lgl_template_get_name (const lglTemplate *template) { - g_return_val_if_fail (template, NULL); + g_return_val_if_fail (template, NULL); return g_strdup_printf ("%s %s", template->brand, template->part); } @@ -177,8 +177,8 @@ gboolean lgl_template_do_templates_match (const lglTemplate *template1, const lglTemplate *template2) { - g_return_val_if_fail (template1, FALSE); - g_return_val_if_fail (template2, FALSE); + g_return_val_if_fail (template1, FALSE); + g_return_val_if_fail (template2, FALSE); return (UTF8_EQUAL (template1->brand, template2->brand) && UTF8_EQUAL (template1->part, template2->part)); @@ -199,7 +199,7 @@ gboolean lgl_template_does_brand_match (const lglTemplate *template, const gchar *brand) { - g_return_val_if_fail (template, FALSE); + g_return_val_if_fail (template, FALSE); /* NULL matches everything. */ if (brand == NULL) @@ -225,7 +225,7 @@ gboolean lgl_template_does_page_size_match (const lglTemplate *template, const gchar *paper_id) { - g_return_val_if_fail (template, FALSE); + g_return_val_if_fail (template, FALSE); /* NULL matches everything. */ if (paper_id == NULL) @@ -253,7 +253,7 @@ lgl_template_does_category_match (const lglTemplate *template, { GList *p; - g_return_val_if_fail (template, FALSE); + g_return_val_if_fail (template, FALSE); /* NULL matches everything. */ if (category_id == NULL) @@ -391,10 +391,10 @@ void lgl_template_add_frame (lglTemplate *template, lglTemplateFrame *frame) { - g_return_if_fail (template); - g_return_if_fail (frame); + g_return_if_fail (template); + g_return_if_fail (frame); - template->frames = g_list_append (template->frames, frame); + template->frames = g_list_append (template->frames, frame); } @@ -410,10 +410,10 @@ void lgl_template_add_category (lglTemplate *template, const gchar *category_id) { - g_return_if_fail (template); - g_return_if_fail (category_id); + g_return_if_fail (template); + g_return_if_fail (category_id); - template->category_ids = g_list_append (template->category_ids, + template->category_ids = g_list_append (template->category_ids, g_strdup (category_id)); } @@ -440,20 +440,20 @@ lgl_template_frame_rect_new (const gchar *id, gdouble x_waste, gdouble y_waste) { - lglTemplateFrame *frame; + lglTemplateFrame *frame; - frame = g_new0 (lglTemplateFrame, 1); + frame = g_new0 (lglTemplateFrame, 1); - frame->shape = LGL_TEMPLATE_FRAME_SHAPE_RECT; - frame->rect.id = g_strdup (id); + frame->shape = LGL_TEMPLATE_FRAME_SHAPE_RECT; + frame->rect.id = g_strdup (id); - frame->rect.w = w; - frame->rect.h = h; - frame->rect.r = r; - frame->rect.x_waste = x_waste; - frame->rect.y_waste = y_waste; + frame->rect.w = w; + frame->rect.h = h; + frame->rect.r = r; + frame->rect.x_waste = x_waste; + frame->rect.y_waste = y_waste; - return frame; + return frame; } @@ -475,18 +475,18 @@ lgl_template_frame_ellipse_new (const gchar *id, gdouble h, gdouble waste) { - lglTemplateFrame *frame; + lglTemplateFrame *frame; - frame = g_new0 (lglTemplateFrame, 1); + frame = g_new0 (lglTemplateFrame, 1); - frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE; - frame->ellipse.id = g_strdup (id); + frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE; + frame->ellipse.id = g_strdup (id); - frame->ellipse.w = w; - frame->ellipse.h = h; - frame->ellipse.waste = waste; + frame->ellipse.w = w; + frame->ellipse.h = h; + frame->ellipse.waste = waste; - return frame; + return frame; } @@ -506,17 +506,17 @@ lgl_template_frame_round_new (const gchar *id, gdouble r, gdouble waste) { - lglTemplateFrame *frame; + lglTemplateFrame *frame; - frame = g_new0 (lglTemplateFrame, 1); + frame = g_new0 (lglTemplateFrame, 1); - frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ROUND; - frame->round.id = g_strdup (id); + frame->shape = LGL_TEMPLATE_FRAME_SHAPE_ROUND; + frame->round.id = g_strdup (id); - frame->round.r = r; - frame->round.waste = waste; + frame->round.r = r; + frame->round.waste = waste; - return frame; + return frame; } @@ -542,20 +542,20 @@ lgl_template_frame_cd_new (const gchar *id, gdouble h, gdouble waste) { - lglTemplateFrame *frame; + lglTemplateFrame *frame; - frame = g_new0 (lglTemplateFrame, 1); + frame = g_new0 (lglTemplateFrame, 1); - frame->shape = LGL_TEMPLATE_FRAME_SHAPE_CD; - frame->cd.id = g_strdup (id); + frame->shape = LGL_TEMPLATE_FRAME_SHAPE_CD; + frame->cd.id = g_strdup (id); - frame->cd.r1 = r1; - frame->cd.r2 = r2; - frame->cd.w = w; - frame->cd.h = h; - frame->cd.waste = waste; + frame->cd.r1 = r1; + frame->cd.r2 = r2; + frame->cd.w = w; + frame->cd.h = h; + frame->cd.waste = waste; - return frame; + return frame; } @@ -573,38 +573,45 @@ lgl_template_frame_get_size (const lglTemplateFrame *frame, gdouble *w, gdouble *h) { - g_return_if_fail (frame); - - switch (frame->shape) { - case LGL_TEMPLATE_FRAME_SHAPE_RECT: - *w = frame->rect.w; - *h = frame->rect.h; - break; - case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: - *w = frame->ellipse.w; - *h = frame->ellipse.h; - break; - case LGL_TEMPLATE_FRAME_SHAPE_ROUND: - *w = 2.0 * frame->round.r; - *h = 2.0 * frame->round.r; - break; - case LGL_TEMPLATE_FRAME_SHAPE_CD: - if (frame->cd.w == 0.0) { - *w = 2.0 * frame->cd.r1; - } else { - *w = frame->cd.w; - } - if (frame->cd.h == 0.0) { - *h = 2.0 * frame->cd.r1; - } else { - *h = frame->cd.h; - } - break; - default: - *w = 0.0; - *h = 0.0; - break; - } + g_return_if_fail (frame); + + switch (frame->shape) + { + case LGL_TEMPLATE_FRAME_SHAPE_RECT: + *w = frame->rect.w; + *h = frame->rect.h; + break; + case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: + *w = frame->ellipse.w; + *h = frame->ellipse.h; + break; + case LGL_TEMPLATE_FRAME_SHAPE_ROUND: + *w = 2.0 * frame->round.r; + *h = 2.0 * frame->round.r; + break; + case LGL_TEMPLATE_FRAME_SHAPE_CD: + if (frame->cd.w == 0.0) + { + *w = 2.0 * frame->cd.r1; + } + else + { + *w = frame->cd.w; + } + if (frame->cd.h == 0.0) + { + *h = 2.0 * frame->cd.r1; + } + else + { + *h = frame->cd.h; + } + break; + default: + *w = 0.0; + *h = 0.0; + break; + } } @@ -620,19 +627,20 @@ lgl_template_frame_get_size (const lglTemplateFrame *frame, gint lgl_template_frame_get_n_labels (const lglTemplateFrame *frame) { - gint n_labels = 0; - GList *p; - lglTemplateLayout *layout; + gint n_labels = 0; + GList *p; + lglTemplateLayout *layout; - g_return_val_if_fail (frame, 0); + g_return_val_if_fail (frame, 0); - for ( p=frame->all.layouts; p != NULL; p=p->next ) { - layout = (lglTemplateLayout *)p->data; + for ( p=frame->all.layouts; p != NULL; p=p->next ) + { + layout = (lglTemplateLayout *)p->data; - n_labels += layout->nx * layout->ny; - } + n_labels += layout->nx * layout->ny; + } - return n_labels; + return n_labels; } @@ -695,9 +703,12 @@ lgl_template_frame_get_size_description (const lglTemplateFrame *frame, units_string = lgl_units_get_name (units); units_per_point = lgl_units_get_units_per_point (units); - switch (frame->shape) { + switch (frame->shape) + { + case LGL_TEMPLATE_FRAME_SHAPE_RECT: - if ( units == LGL_UNITS_INCH ) { + if ( units == LGL_UNITS_INCH ) + { gchar *xstr, *ystr; xstr = lgl_str_format_fraction (frame->rect.w*units_per_point); @@ -706,15 +717,19 @@ lgl_template_frame_get_size_description (const lglTemplateFrame *frame, xstr, ystr, units_string); g_free (xstr); g_free (ystr); - } else { + } + else + { string = g_strdup_printf ("%.5g × %.5g %s", frame->rect.w*units_per_point, frame->rect.h*units_per_point, units_string); } break; + case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: - if ( units == LGL_UNITS_INCH ) { + if ( units == LGL_UNITS_INCH ) + { gchar *xstr, *ystr; xstr = lgl_str_format_fraction (frame->ellipse.w*units_per_point); @@ -723,15 +738,19 @@ lgl_template_frame_get_size_description (const lglTemplateFrame *frame, xstr, ystr, units_string); g_free (xstr); g_free (ystr); - } else { + } + else + { string = g_strdup_printf ("%.5g × %.5g %s", frame->ellipse.w*units_per_point, frame->ellipse.h*units_per_point, units_string); } break; + case LGL_TEMPLATE_FRAME_SHAPE_ROUND: - if ( units == LGL_UNITS_INCH ) { + if ( units == LGL_UNITS_INCH ) + { gchar *dstr; dstr = lgl_str_format_fraction (2.0*frame->round.r*units_per_point); @@ -739,15 +758,19 @@ lgl_template_frame_get_size_description (const lglTemplateFrame *frame, dstr, units_string, _("diameter")); g_free (dstr); - } else { + } + else + { string = g_strdup_printf ("%.5g %s %s", 2.0*frame->round.r*units_per_point, units_string, _("diameter")); } break; + case LGL_TEMPLATE_FRAME_SHAPE_CD: - if ( units == LGL_UNITS_INCH ) { + if ( units == LGL_UNITS_INCH ) + { gchar *dstr; dstr = lgl_str_format_fraction (2.0*frame->cd.r1*units_per_point); @@ -755,15 +778,19 @@ lgl_template_frame_get_size_description (const lglTemplateFrame *frame, dstr, units_string, _("diameter")); g_free (dstr); - } else { + } + else + { string = g_strdup_printf ("%.5g %s %s", 2.0*frame->cd.r1*units_per_point, units_string, _("diameter")); } break; + default: break; + } return string; @@ -785,32 +812,35 @@ lgl_template_frame_get_size_description (const lglTemplateFrame *frame, lglTemplateOrigin * lgl_template_frame_get_origins (const lglTemplateFrame *frame) { - gint i_label, n_labels, ix, iy; - lglTemplateOrigin *origins; - GList *p; - lglTemplateLayout *layout; + gint i_label, n_labels, ix, iy; + lglTemplateOrigin *origins; + GList *p; + lglTemplateLayout *layout; - g_return_val_if_fail (frame, NULL); + g_return_val_if_fail (frame, NULL); - n_labels = lgl_template_frame_get_n_labels (frame); - origins = g_new0 (lglTemplateOrigin, n_labels); + n_labels = lgl_template_frame_get_n_labels (frame); + origins = g_new0 (lglTemplateOrigin, n_labels); - i_label = 0; - for ( p=frame->all.layouts; p != NULL; p=p->next ) { - layout = (lglTemplateLayout *)p->data; + i_label = 0; + for ( p=frame->all.layouts; p != NULL; p=p->next ) + { + layout = (lglTemplateLayout *)p->data; - for (iy = 0; iy < layout->ny; iy++) { - for (ix = 0; ix < layout->nx; ix++, i_label++) { - origins[i_label].x = ix*layout->dx + layout->x0; - origins[i_label].y = iy*layout->dy + layout->y0; - } - } - } + for (iy = 0; iy < layout->ny; iy++) + { + for (ix = 0; ix < layout->nx; ix++, i_label++) + { + origins[i_label].x = ix*layout->dx + layout->x0; + origins[i_label].y = iy*layout->dy + layout->y0; + } + } + } - g_qsort_with_data (origins, n_labels, sizeof(lglTemplateOrigin), - compare_origins, NULL); + g_qsort_with_data (origins, n_labels, sizeof(lglTemplateOrigin), + compare_origins, NULL); - return origins; + return origins; } @@ -826,10 +856,10 @@ void lgl_template_frame_add_layout (lglTemplateFrame *frame, lglTemplateLayout *layout) { - g_return_if_fail (frame); - g_return_if_fail (layout); + g_return_if_fail (frame); + g_return_if_fail (layout); - frame->all.layouts = g_list_append (frame->all.layouts, layout); + frame->all.layouts = g_list_append (frame->all.layouts, layout); } @@ -845,10 +875,10 @@ void lgl_template_frame_add_markup (lglTemplateFrame *frame, lglTemplateMarkup *markup) { - g_return_if_fail (frame); - g_return_if_fail (markup); + g_return_if_fail (frame); + g_return_if_fail (markup); - frame->all.markups = g_list_append (frame->all.markups, markup); + frame->all.markups = g_list_append (frame->all.markups, markup); } @@ -874,18 +904,18 @@ lgl_template_layout_new (gint nx, gdouble dx, gdouble dy) { - lglTemplateLayout *layout; + lglTemplateLayout *layout; - layout = g_new0 (lglTemplateLayout, 1); + layout = g_new0 (lglTemplateLayout, 1); - layout->nx = nx; - layout->ny = ny; - layout->x0 = x0; - layout->y0 = y0; - layout->dx = dx; - layout->dy = dy; + layout->nx = nx; + layout->ny = ny; + layout->x0 = x0; + layout->y0 = y0; + layout->dx = dx; + layout->dy = dy; - return layout; + return layout; } @@ -901,14 +931,14 @@ lgl_template_layout_new (gint nx, lglTemplateMarkup * lgl_template_markup_margin_new (gdouble size) { - lglTemplateMarkup *markup; + lglTemplateMarkup *markup; - markup = g_new0 (lglTemplateMarkup, 1); + markup = g_new0 (lglTemplateMarkup, 1); - markup->type = LGL_TEMPLATE_MARKUP_MARGIN; - markup->margin.size = size; + markup->type = LGL_TEMPLATE_MARKUP_MARGIN; + markup->margin.size = size; - return markup; + return markup; } @@ -930,17 +960,17 @@ lgl_template_markup_line_new (gdouble x1, gdouble x2, gdouble y2) { - lglTemplateMarkup *markup; + lglTemplateMarkup *markup; - markup = g_new0 (lglTemplateMarkup, 1); + markup = g_new0 (lglTemplateMarkup, 1); - markup->type = LGL_TEMPLATE_MARKUP_LINE; - markup->line.x1 = x1; - markup->line.y1 = y1; - markup->line.x2 = x2; - markup->line.y2 = y2; + markup->type = LGL_TEMPLATE_MARKUP_LINE; + markup->line.x1 = x1; + markup->line.y1 = y1; + markup->line.x2 = x2; + markup->line.y2 = y2; - return markup; + return markup; } @@ -960,16 +990,16 @@ lgl_template_markup_circle_new (gdouble x0, gdouble y0, gdouble r) { - lglTemplateMarkup *markup; + lglTemplateMarkup *markup; - markup = g_new0 (lglTemplateMarkup, 1); + markup = g_new0 (lglTemplateMarkup, 1); - markup->type = LGL_TEMPLATE_MARKUP_CIRCLE; - markup->circle.x0 = x0; - markup->circle.y0 = y0; - markup->circle.r = r; + markup->type = LGL_TEMPLATE_MARKUP_CIRCLE; + markup->circle.x0 = x0; + markup->circle.y0 = y0; + markup->circle.r = r; - return markup; + return markup; } @@ -993,18 +1023,18 @@ lgl_template_markup_rect_new (gdouble x1, gdouble h, gdouble r) { - lglTemplateMarkup *markup; + lglTemplateMarkup *markup; - markup = g_new0 (lglTemplateMarkup, 1); + markup = g_new0 (lglTemplateMarkup, 1); - markup->type = LGL_TEMPLATE_MARKUP_RECT; - markup->rect.x1 = x1; - markup->rect.y1 = y1; - markup->rect.w = w; - markup->rect.h = h; - markup->rect.r = r; + markup->type = LGL_TEMPLATE_MARKUP_RECT; + markup->rect.x1 = x1; + markup->rect.y1 = y1; + markup->rect.w = w; + markup->rect.h = h; + markup->rect.r = r; - return markup; + return markup; } @@ -1026,17 +1056,17 @@ lgl_template_markup_ellipse_new (gdouble x1, gdouble w, gdouble h) { - lglTemplateMarkup *markup; + lglTemplateMarkup *markup; - markup = g_new0 (lglTemplateMarkup, 1); + markup = g_new0 (lglTemplateMarkup, 1); - markup->type = LGL_TEMPLATE_MARKUP_ELLIPSE; - markup->ellipse.x1 = x1; - markup->ellipse.y1 = y1; - markup->ellipse.w = w; - markup->ellipse.h = h; + markup->type = LGL_TEMPLATE_MARKUP_ELLIPSE; + markup->ellipse.x1 = x1; + markup->ellipse.y1 = y1; + markup->ellipse.w = w; + markup->ellipse.h = h; - return markup; + return markup; } @@ -1052,13 +1082,13 @@ lgl_template_markup_ellipse_new (gdouble x1, lglTemplate * lgl_template_dup (const lglTemplate *orig_template) { - lglTemplate *template; - GList *p; - lglTemplateFrame *frame; + lglTemplate *template; + GList *p; + lglTemplateFrame *frame; - g_return_val_if_fail (orig_template, NULL); + g_return_val_if_fail (orig_template, NULL); - template = lgl_template_new (orig_template->brand, + template = lgl_template_new (orig_template->brand, orig_template->part, orig_template->description, orig_template->paper_id, @@ -1069,19 +1099,19 @@ lgl_template_dup (const lglTemplate *orig_template) template->product_url = g_strdup (orig_template->product_url); - for ( p=orig_template->category_ids; p != NULL; p=p->next ) + for ( p=orig_template->category_ids; p != NULL; p=p->next ) { lgl_template_add_category (template, p->data); - } + } - for ( p=orig_template->frames; p != NULL; p=p->next ) + for ( p=orig_template->frames; p != NULL; p=p->next ) { - frame = (lglTemplateFrame *)p->data; + frame = (lglTemplateFrame *)p->data; - lgl_template_add_frame (template, lgl_template_frame_dup (frame)); - } + lgl_template_add_frame (template, lgl_template_frame_dup (frame)); + } - return template; + return template; } @@ -1095,45 +1125,44 @@ lgl_template_dup (const lglTemplate *orig_template) void lgl_template_free (lglTemplate *template) { - GList *p; - lglTemplateFrame *frame; - - if ( template != NULL ) { - - g_free (template->brand); - template->brand = NULL; - - g_free (template->part); - template->part = NULL; + GList *p; + lglTemplateFrame *frame; - g_free (template->description); - template->description = NULL; - - g_free (template->paper_id); - template->paper_id = NULL; + if ( template != NULL ) + { + g_free (template->brand); + template->brand = NULL; - for ( p=template->category_ids; p != NULL; p=p->next ) { + g_free (template->part); + template->part = NULL; - g_free (p->data); - p->data = NULL; + g_free (template->description); + template->description = NULL; - } - g_list_free (template->category_ids); - template->category_ids = NULL; + g_free (template->paper_id); + template->paper_id = NULL; - for ( p=template->frames; p != NULL; p=p->next ) { + for ( p=template->category_ids; p != NULL; p=p->next ) + { + g_free (p->data); + p->data = NULL; + } + g_list_free (template->category_ids); + template->category_ids = NULL; - frame = (lglTemplateFrame *)p->data; + for ( p=template->frames; p != NULL; p=p->next ) + { + frame = (lglTemplateFrame *)p->data; - lgl_template_frame_free (frame); - p->data = NULL; - } - g_list_free (template->frames); - template->frames = NULL; + lgl_template_frame_free (frame); + p->data = NULL; + } + g_list_free (template->frames); + template->frames = NULL; - g_free (template); + g_free (template); - } + } } @@ -1150,70 +1179,71 @@ lgl_template_free (lglTemplate *template) lglTemplateFrame * lgl_template_frame_dup (const lglTemplateFrame *orig_frame) { - lglTemplateFrame *frame; - GList *p; - lglTemplateLayout *layout; - lglTemplateMarkup *markup; + lglTemplateFrame *frame; + GList *p; + lglTemplateLayout *layout; + lglTemplateMarkup *markup; - g_return_val_if_fail (orig_frame, NULL); + g_return_val_if_fail (orig_frame, NULL); - switch (orig_frame->shape) { + switch (orig_frame->shape) + { - case LGL_TEMPLATE_FRAME_SHAPE_RECT: - frame = - lgl_template_frame_rect_new (orig_frame->all.id, + case LGL_TEMPLATE_FRAME_SHAPE_RECT: + frame = + lgl_template_frame_rect_new (orig_frame->all.id, orig_frame->rect.w, orig_frame->rect.h, orig_frame->rect.r, orig_frame->rect.x_waste, orig_frame->rect.y_waste); - break; + break; - case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: - frame = - lgl_template_frame_ellipse_new (orig_frame->all.id, + case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: + frame = + lgl_template_frame_ellipse_new (orig_frame->all.id, orig_frame->ellipse.w, orig_frame->ellipse.h, orig_frame->ellipse.waste); - break; + break; - case LGL_TEMPLATE_FRAME_SHAPE_ROUND: - frame = - lgl_template_frame_round_new (orig_frame->all.id, + case LGL_TEMPLATE_FRAME_SHAPE_ROUND: + frame = + lgl_template_frame_round_new (orig_frame->all.id, orig_frame->round.r, orig_frame->round.waste); - break; + break; - case LGL_TEMPLATE_FRAME_SHAPE_CD: - frame = - lgl_template_frame_cd_new (orig_frame->all.id, + case LGL_TEMPLATE_FRAME_SHAPE_CD: + frame = + lgl_template_frame_cd_new (orig_frame->all.id, orig_frame->cd.r1, orig_frame->cd.r2, orig_frame->cd.w, orig_frame->cd.h, orig_frame->cd.waste); - break; - - default: - return NULL; - break; - } - - for ( p=orig_frame->all.layouts; p != NULL; p=p->next ) { + break; - layout = (lglTemplateLayout *)p->data; + default: + return NULL; + break; + } - lgl_template_frame_add_layout (frame, lgl_template_layout_dup (layout)); - } + for ( p=orig_frame->all.layouts; p != NULL; p=p->next ) + { + layout = (lglTemplateLayout *)p->data; - for ( p=orig_frame->all.markups; p != NULL; p=p->next ) { + lgl_template_frame_add_layout (frame, lgl_template_layout_dup (layout)); + } - markup = (lglTemplateMarkup *)p->data; + for ( p=orig_frame->all.markups; p != NULL; p=p->next ) + { + markup = (lglTemplateMarkup *)p->data; - lgl_template_frame_add_markup (frame, lgl_template_markup_dup (markup)); - } + lgl_template_frame_add_markup (frame, lgl_template_markup_dup (markup)); + } - return frame; + return frame; } @@ -1227,38 +1257,39 @@ lgl_template_frame_dup (const lglTemplateFrame *orig_frame) void lgl_template_frame_free (lglTemplateFrame *frame) { - GList *p; - lglTemplateLayout *layout; - lglTemplateMarkup *markup; + GList *p; + lglTemplateLayout *layout; + lglTemplateMarkup *markup; - if ( frame != NULL ) { - - g_free (frame->all.id); - frame->all.id = NULL; - - for ( p=frame->all.layouts; p != NULL; p=p->next ) { + if ( frame != NULL ) + { - layout = (lglTemplateLayout *)p->data; + g_free (frame->all.id); + frame->all.id = NULL; - lgl_template_layout_free (layout); - p->data = NULL; - } - g_list_free (frame->all.layouts); - frame->all.layouts = NULL; + for ( p=frame->all.layouts; p != NULL; p=p->next ) + { + layout = (lglTemplateLayout *)p->data; - for ( p=frame->all.markups; p != NULL; p=p->next ) { + lgl_template_layout_free (layout); + p->data = NULL; + } + g_list_free (frame->all.layouts); + frame->all.layouts = NULL; - markup = (lglTemplateMarkup *)p->data; + for ( p=frame->all.markups; p != NULL; p=p->next ) + { + markup = (lglTemplateMarkup *)p->data; - lgl_template_markup_free (markup); - p->data = NULL; - } - g_list_free (frame->all.markups); - frame->all.markups = NULL; + lgl_template_markup_free (markup); + p->data = NULL; + } + g_list_free (frame->all.markups); + frame->all.markups = NULL; - g_free (frame); + g_free (frame); - } + } } @@ -1275,16 +1306,16 @@ lgl_template_frame_free (lglTemplateFrame *frame) lglTemplateLayout * lgl_template_layout_dup (const lglTemplateLayout *orig_layout) { - lglTemplateLayout *layout; + lglTemplateLayout *layout; - g_return_val_if_fail (orig_layout, NULL); + g_return_val_if_fail (orig_layout, NULL); - layout = g_new0 (lglTemplateLayout, 1); + layout = g_new0 (lglTemplateLayout, 1); - /* copy contents */ - *layout = *orig_layout; + /* copy contents */ + *layout = *orig_layout; - return layout; + return layout; } @@ -1298,7 +1329,7 @@ lgl_template_layout_dup (const lglTemplateLayout *orig_layout) void lgl_template_layout_free (lglTemplateLayout *layout) { - g_free (layout); + g_free (layout); } @@ -1314,15 +1345,15 @@ lgl_template_layout_free (lglTemplateLayout *layout) lglTemplateMarkup * lgl_template_markup_dup (const lglTemplateMarkup *orig_markup) { - lglTemplateMarkup *markup; + lglTemplateMarkup *markup; - g_return_val_if_fail (orig_markup, NULL); + g_return_val_if_fail (orig_markup, NULL); - markup = g_new0 (lglTemplateMarkup, 1); + markup = g_new0 (lglTemplateMarkup, 1); - *markup = *orig_markup; + *markup = *orig_markup; - return markup; + return markup; } @@ -1336,30 +1367,40 @@ lgl_template_markup_dup (const lglTemplateMarkup *orig_markup) void lgl_template_markup_free (lglTemplateMarkup *markup) { - g_free (markup); + g_free (markup); } static gint compare_origins (gconstpointer a, - gconstpointer b, - gpointer user_data) + gconstpointer b, + gpointer user_data) { - const lglTemplateOrigin *a_origin = a, *b_origin = b; - - if ( a_origin->y < b_origin->y ) { - return -1; - } else if ( a_origin->y > b_origin->y ) { - return +1; - } else { - if ( a_origin->x < b_origin->x ) { - return -1; - } else if ( a_origin->x > b_origin->x ) { - return +1; - } else { - return 0; /* hopefully 2 labels won't have the same origin */ - } - } + const lglTemplateOrigin *a_origin = a, *b_origin = b; + + if ( a_origin->y < b_origin->y ) + { + return -1; + } + else if ( a_origin->y > b_origin->y ) + { + return +1; + } + else + { + if ( a_origin->x < b_origin->x ) + { + return -1; + } + else if ( a_origin->x > b_origin->x ) + { + return +1; + } + else + { + return 0; /* hopefully 2 labels won't have the same origin */ + } + } } diff --git a/libglabels/lgl-template.h b/libglabels/lgl-template.h index c1439ab2..83c8f0a3 100644 --- a/libglabels/lgl-template.h +++ b/libglabels/lgl-template.h @@ -51,23 +51,23 @@ typedef struct _lglTemplateOrigin lglTemplateOrigin; */ struct _lglTemplate { - gchar *brand; + gchar *brand; gchar *part; gchar *equiv_part; - gchar *description; - gchar *paper_id; - gdouble page_width; - gdouble page_height; + gchar *description; + gchar *paper_id; + gdouble page_width; + gdouble page_height; /* Meta information. */ gchar *product_url; /* URL to manufacturer's product website. */ - GList *category_ids; /* List of (gchar *) category ids. */ + GList *category_ids; /* List of (gchar *) category ids. */ - /* List of (lglTemplateFrame *) label frame structures. - * Currently glabels only supports a single label frame per - * template. */ - GList *frames; + /* List of (lglTemplateFrame *) label frame structures. + * Currently glabels only supports a single label frame per + * template. */ + GList *frames; }; @@ -76,10 +76,10 @@ struct _lglTemplate { * Possible Frame Shapes */ typedef enum { - LGL_TEMPLATE_FRAME_SHAPE_RECT, - LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE, - LGL_TEMPLATE_FRAME_SHAPE_ROUND, - LGL_TEMPLATE_FRAME_SHAPE_CD, + LGL_TEMPLATE_FRAME_SHAPE_RECT, + LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE, + LGL_TEMPLATE_FRAME_SHAPE_ROUND, + LGL_TEMPLATE_FRAME_SHAPE_CD, } lglTemplateFrameShape; @@ -89,22 +89,22 @@ typedef enum { struct _lglTemplateFrameAll { /* Begin Common Fields */ - lglTemplateFrameShape shape; + lglTemplateFrameShape shape; - gchar *id; /* Id, currently always "0" */ - GList *layouts; /* List of lglTemplateLayouts */ - GList *markups; /* List of lglTemplateMarkups */ + gchar *id; /* Id, currently always "0" */ + GList *layouts; /* List of lglTemplateLayouts */ + GList *markups; /* List of lglTemplateMarkups */ /* End Common Fields */ }; struct _lglTemplateFrameRect { /* Begin Common Fields */ - lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_RECT. */ + lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_RECT. */ - gchar *id; /* Id, currently always "0" */ - GList *layouts; /* List of lglTemplateLayouts */ - GList *markups; /* List of lglTemplateMarkups */ + gchar *id; /* Id, currently always "0" */ + GList *layouts; /* List of lglTemplateLayouts */ + GList *markups; /* List of lglTemplateMarkups */ /* End Common Fields */ gdouble w; /* Width */ @@ -117,11 +117,11 @@ struct _lglTemplateFrameRect { struct _lglTemplateFrameEllipse { /* Begin Common Fields */ - lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE. */ + lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE. */ - gchar *id; /* Id, currently always "0" */ - GList *layouts; /* List of lglTemplateLayouts */ - GList *markups; /* List of lglTemplateMarkups */ + gchar *id; /* Id, currently always "0" */ + GList *layouts; /* List of lglTemplateLayouts */ + GList *markups; /* List of lglTemplateMarkups */ /* End Common Fields */ gdouble w; /* Width */ @@ -132,11 +132,11 @@ struct _lglTemplateFrameEllipse { struct _lglTemplateFrameRound { /* Begin Common Fields */ - lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ROUND. */ + lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_ROUND. */ - gchar *id; /* Id, currently always "0" */ - GList *layouts; /* List of lglTemplateLayouts */ - GList *markups; /* List of lglTemplateMarkups */ + gchar *id; /* Id, currently always "0" */ + GList *layouts; /* List of lglTemplateLayouts */ + GList *markups; /* List of lglTemplateMarkups */ /* End Common Fields */ gdouble r; /* Radius */ @@ -146,11 +146,11 @@ struct _lglTemplateFrameRound { struct _lglTemplateFrameCD { /* Begin Common Fields */ - lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_CD. */ + lglTemplateFrameShape shape; /* Always LGL_TEMPLATE_FRAME_SHAPE_CD. */ - gchar *id; /* Id, currently always "0" */ - GList *layouts; /* List of lglTemplateLayouts */ - GList *markups; /* List of lglTemplateMarkups */ + gchar *id; /* Id, currently always "0" */ + GList *layouts; /* List of lglTemplateLayouts */ + GList *markups; /* List of lglTemplateMarkups */ /* End Common Fields */ gdouble r1; /* Outer radius */ @@ -162,13 +162,13 @@ struct _lglTemplateFrameCD { union _lglTemplateFrame{ - lglTemplateFrameShape shape; + lglTemplateFrameShape shape; - lglTemplateFrameAll all; - lglTemplateFrameRect rect; - lglTemplateFrameEllipse ellipse; - lglTemplateFrameRound round; - lglTemplateFrameCD cd; + lglTemplateFrameAll all; + lglTemplateFrameRect rect; + lglTemplateFrameEllipse ellipse; + lglTemplateFrameRound round; + lglTemplateFrameCD cd; }; @@ -177,14 +177,14 @@ union _lglTemplateFrame{ */ struct _lglTemplateLayout { - gint nx; /* Number of labels across */ - gint ny; /* Number of labels up and down */ + gint nx; /* Number of labels across */ + gint ny; /* Number of labels up and down */ - gdouble x0; /* Left of grid from left edge of paper */ - gdouble y0; /* Top of grid from top edge of paper */ + gdouble x0; /* Left of grid from left edge of paper */ + gdouble y0; /* Top of grid from top edge of paper */ - gdouble dx; /* Horizontal pitch of grid */ - gdouble dy; /* Vertical pitch of grid */ + gdouble dx; /* Horizontal pitch of grid */ + gdouble dy; /* Vertical pitch of grid */ }; @@ -193,11 +193,11 @@ struct _lglTemplateLayout { * Possible Markup Types */ typedef enum { - LGL_TEMPLATE_MARKUP_MARGIN, - LGL_TEMPLATE_MARKUP_LINE, - LGL_TEMPLATE_MARKUP_CIRCLE, - LGL_TEMPLATE_MARKUP_RECT, - LGL_TEMPLATE_MARKUP_ELLIPSE, + LGL_TEMPLATE_MARKUP_MARGIN, + LGL_TEMPLATE_MARKUP_LINE, + LGL_TEMPLATE_MARKUP_CIRCLE, + LGL_TEMPLATE_MARKUP_RECT, + LGL_TEMPLATE_MARKUP_ELLIPSE, } lglTemplateMarkupType; @@ -206,14 +206,14 @@ typedef enum { */ struct _lglTemplateMarkupMargin { - lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_MARGIN */ + lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_MARGIN */ gdouble size; /* Margin size */ }; struct _lglTemplateMarkupLine { - lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_LINE */ + lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_LINE */ gdouble x1, y1; /* 1st endpoint */ gdouble x2, y2; /* 2nd endpoint */ @@ -221,7 +221,7 @@ struct _lglTemplateMarkupLine { struct _lglTemplateMarkupCircle { - lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_CIRCLE */ + lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_CIRCLE */ gdouble x0, y0; /* Center of circle */ gdouble r; /* Radius of circle */ @@ -229,7 +229,7 @@ struct _lglTemplateMarkupCircle { struct _lglTemplateMarkupRect { - lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_RECT */ + lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_RECT */ gdouble x1, y1; /* Upper left corner */ gdouble w, h; /* Width and height. */ @@ -238,7 +238,7 @@ struct _lglTemplateMarkupRect { struct _lglTemplateMarkupEllipse { - lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_ELLIPSE */ + lglTemplateMarkupType type; /* Always LGL_TEMPLATE_MARKUP_ELLIPSE */ gdouble x1, y1; /* Upper left corner */ gdouble w, h; /* Width and height. */ @@ -246,13 +246,13 @@ struct _lglTemplateMarkupEllipse { union _lglTemplateMarkup { - lglTemplateMarkupType type; + lglTemplateMarkupType type; - lglTemplateMarkupMargin margin; - lglTemplateMarkupLine line; - lglTemplateMarkupCircle circle; - lglTemplateMarkupRect rect; - lglTemplateMarkupEllipse ellipse; + lglTemplateMarkupMargin margin; + lglTemplateMarkupLine line; + lglTemplateMarkupCircle circle; + lglTemplateMarkupRect rect; + lglTemplateMarkupEllipse ellipse; }; @@ -261,8 +261,8 @@ union _lglTemplateMarkup { */ struct _lglTemplateOrigin { - gdouble x, y; /* Label origin relative to upper - * upper left hand corner of paper */ + gdouble x, y; /* Label origin relative to upper + * upper left hand corner of paper */ }; diff --git a/libglabels/lgl-units.c b/libglabels/lgl-units.c index 73d243d0..4c7c4022 100644 --- a/libglabels/lgl-units.c +++ b/libglabels/lgl-units.c @@ -45,9 +45,9 @@ /*========================================================*/ typedef struct { - gchar *id; - gchar *name; - gdouble points_per_unit; + gchar *id; + gchar *name; + gdouble points_per_unit; } UnitTableEntry; @@ -57,16 +57,16 @@ typedef struct { static UnitTableEntry unit_table[] = { - /* The ids are identical to the absolute length units supported in - the CSS2 Specification (Section 4.3.2) */ + /* The ids are identical to the absolute length units supported in + the CSS2 Specification (Section 4.3.2) */ - /* This table must be sorted exactly as the enumerations in lglUnits */ + /* This table must be sorted exactly as the enumerations in lglUnits */ - /* [LGL_UNITS_POINT] */ {"pt", N_("points"), POINTS_PER_POINT}, - /* [LGL_UNITS_INCH] */ {"in", N_("inches"), POINTS_PER_INCH}, - /* [LGL_UNITS_MM] */ {"mm", N_("mm"), POINTS_PER_MM}, - /* [LGL_UNITS_CM] */ {"cm", N_("cm"), POINTS_PER_CM}, - /* [LGL_UNITS_PICA] */ {"pc", N_("picas"), POINTS_PER_PICA}, + /* [LGL_UNITS_POINT] */ {"pt", N_("points"), POINTS_PER_POINT}, + /* [LGL_UNITS_INCH] */ {"in", N_("inches"), POINTS_PER_INCH}, + /* [LGL_UNITS_MM] */ {"mm", N_("mm"), POINTS_PER_MM}, + /* [LGL_UNITS_CM] */ {"cm", N_("cm"), POINTS_PER_CM}, + /* [LGL_UNITS_PICA] */ {"pc", N_("picas"), POINTS_PER_PICA}, }; @@ -117,26 +117,31 @@ lgl_units_from_id (const gchar *id) lglUnits units; /* An empty or missing id defaults to points. */ - if ( (id == NULL) || (strlen (id) == 0) ) + if ( (id == NULL) || (*id == '\0') ) { return LGL_UNITS_POINT; } - for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) { - if (g_ascii_strcasecmp (id, unit_table[units].id) == 0) { + for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) + { + if (g_ascii_strcasecmp (id, unit_table[units].id) == 0) + { return units; } } /* Try name as a fallback. (Will catch some legacy preferences.) */ - for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) { - if (g_ascii_strcasecmp (id, unit_table[units].name) == 0) { + for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) + { + if (g_ascii_strcasecmp (id, unit_table[units].name) == 0) + { return units; } } /* For compatibility with old preferences. */ - if (g_ascii_strcasecmp (id, "Millimeters") == 0) { + if (g_ascii_strcasecmp (id, "Millimeters") == 0) + { return LGL_UNITS_MM; } @@ -184,8 +189,10 @@ lgl_units_from_name (const gchar *name) { lglUnits units; - for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) { - if (g_ascii_strcasecmp (name, gettext ((char *)unit_table[units].name) ) == 0) { + for ( units = LGL_UNITS_FIRST; units <= LGL_UNITS_LAST; units++) + { + if (g_ascii_strcasecmp (name, gettext ((char *)unit_table[units].name) ) == 0) + { return units; } } diff --git a/libglabels/lgl-units.h b/libglabels/lgl-units.h index b22be074..617f8652 100644 --- a/libglabels/lgl-units.h +++ b/libglabels/lgl-units.h @@ -30,14 +30,14 @@ G_BEGIN_DECLS * Units of distance */ typedef enum { - LGL_UNITS_POINT, /* encoded as "pt" */ - LGL_UNITS_INCH, /* encoded as "in" */ - LGL_UNITS_MM, /* encoded as "mm" */ - LGL_UNITS_CM, /* encoded as "cm" */ - LGL_UNITS_PICA, /* encoded as "pc" */ - - LGL_UNITS_FIRST = LGL_UNITS_POINT, - LGL_UNITS_LAST = LGL_UNITS_PICA, + LGL_UNITS_POINT, /* encoded as "pt" */ + LGL_UNITS_INCH, /* encoded as "in" */ + LGL_UNITS_MM, /* encoded as "mm" */ + LGL_UNITS_CM, /* encoded as "cm" */ + LGL_UNITS_PICA, /* encoded as "pc" */ + + LGL_UNITS_FIRST = LGL_UNITS_POINT, + LGL_UNITS_LAST = LGL_UNITS_PICA, LGL_UNITS_INVALID = -1, } lglUnits; diff --git a/libglabels/lgl-vendor.c b/libglabels/lgl-vendor.c index 425c1b53..dc4c6f2c 100644 --- a/libglabels/lgl-vendor.c +++ b/libglabels/lgl-vendor.c @@ -59,13 +59,13 @@ lglVendor * lgl_vendor_new (gchar *name) { - lglVendor *vendor; + lglVendor *vendor; - vendor = g_new0 (lglVendor,1); + vendor = g_new0 (lglVendor,1); - vendor->name = g_strdup (name); + vendor->name = g_strdup (name); - return vendor; + return vendor; } @@ -80,16 +80,16 @@ lgl_vendor_new (gchar *name) */ lglVendor *lgl_vendor_dup (const lglVendor *orig) { - lglVendor *vendor; + lglVendor *vendor; - g_return_val_if_fail (orig, NULL); + g_return_val_if_fail (orig, NULL); - vendor = g_new0 (lglVendor,1); + vendor = g_new0 (lglVendor,1); - vendor->name = g_strdup (orig->name); - vendor->url = g_strdup (orig->url); + vendor->name = g_strdup (orig->name); + vendor->url = g_strdup (orig->url); - return vendor; + return vendor; } @@ -103,16 +103,16 @@ lglVendor *lgl_vendor_dup (const lglVendor *orig) void lgl_vendor_free (lglVendor *vendor) { - if ( vendor != NULL ) { + if ( vendor != NULL ) + { + g_free (vendor->name); + vendor->name = NULL; - g_free (vendor->name); - vendor->name = NULL; + g_free (vendor->url); + vendor->url = NULL; - g_free (vendor->url); - vendor->url = NULL; - - g_free (vendor); - } + g_free (vendor); + } } diff --git a/libglabels/lgl-vendor.h b/libglabels/lgl-vendor.h index fc0be293..e25df761 100644 --- a/libglabels/lgl-vendor.h +++ b/libglabels/lgl-vendor.h @@ -32,8 +32,8 @@ G_BEGIN_DECLS typedef struct _lglVendor lglVendor; struct _lglVendor { - gchar *name; /* Vendor name */ - gchar *url; /* Vendor URL */ + gchar *name; /* Vendor name */ + gchar *url; /* Vendor URL */ }; diff --git a/libglabels/lgl-xml-category.c b/libglabels/lgl-xml-category.c index 91822eec..50106159 100644 --- a/libglabels/lgl-xml-category.c +++ b/libglabels/lgl-xml-category.c @@ -56,31 +56,33 @@ GList * lgl_xml_category_read_categories_from_file (gchar *utf8_filename) { - gchar *filename; - GList *categories; - xmlDocPtr categories_doc; + gchar *filename; + GList *categories; + xmlDocPtr categories_doc; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); - if (!filename) { - g_message ("Utf8 filename conversion error"); - return NULL; - } + filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); + if (!filename) + { + g_message ("Utf8 filename conversion error"); + return NULL; + } - categories_doc = xmlParseFile (filename); - if (!categories_doc) { - g_message ("\"%s\" is not a glabels category file (not XML)", - filename); - return NULL; - } + categories_doc = xmlParseFile (filename); + if (!categories_doc) + { + g_message ("\"%s\" is not a glabels category file (not XML)", + filename); + return NULL; + } - categories = lgl_xml_category_parse_categories_doc (categories_doc); + categories = lgl_xml_category_parse_categories_doc (categories_doc); - g_free (filename); - xmlFreeDoc (categories_doc); + g_free (filename); + xmlFreeDoc (categories_doc); - return categories; + return categories; } @@ -97,41 +99,49 @@ lgl_xml_category_read_categories_from_file (gchar *utf8_filename) GList * lgl_xml_category_parse_categories_doc (xmlDocPtr categories_doc) { - GList *categories = NULL; - xmlNodePtr root, node; - lglCategory *category; - - LIBXML_TEST_VERSION; - - root = xmlDocGetRootElement (categories_doc); - if (!root || !root->name) { - g_message ("\"%s\" is not a glabels category file (no root node)", - categories_doc->name); - xmlFreeDoc (categories_doc); - return categories; - } - if (!lgl_xml_is_node (root, "Glabels-categories")) { - g_message ("\"%s\" is not a glabels category file (wrong root node)", - categories_doc->name); - xmlFreeDoc (categories_doc); - return categories; - } - - for (node = root->xmlChildrenNode; node != NULL; node = node->next) { - - if (lgl_xml_is_node (node, "Category")) { - category = lgl_xml_category_parse_category_node (node); - categories = g_list_append (categories, category); - } else { - if ( !xmlNodeIsText(node) ) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - } - - return categories; + GList *categories = NULL; + xmlNodePtr root, node; + lglCategory *category; + + LIBXML_TEST_VERSION; + + root = xmlDocGetRootElement (categories_doc); + if (!root || !root->name) + { + g_message ("\"%s\" is not a glabels category file (no root node)", + categories_doc->name); + xmlFreeDoc (categories_doc); + return categories; + } + if (!lgl_xml_is_node (root, "Glabels-categories")) + { + g_message ("\"%s\" is not a glabels category file (wrong root node)", + categories_doc->name); + xmlFreeDoc (categories_doc); + return categories; + } + + for (node = root->xmlChildrenNode; node != NULL; node = node->next) + { + + if (lgl_xml_is_node (node, "Category")) + { + category = lgl_xml_category_parse_category_node (node); + categories = g_list_append (categories, category); + } + else + { + if ( !xmlNodeIsText(node) ) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + } + + return categories; } @@ -147,20 +157,20 @@ lgl_xml_category_parse_categories_doc (xmlDocPtr categories_doc) lglCategory * lgl_xml_category_parse_category_node (xmlNodePtr category_node) { - lglCategory *category; - gchar *id, *name; + lglCategory *category; + gchar *id, *name; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - id = lgl_xml_get_prop_string (category_node, "id", NULL); - name = lgl_xml_get_prop_i18n_string (category_node, "name", NULL); + id = lgl_xml_get_prop_string (category_node, "id", NULL); + name = lgl_xml_get_prop_i18n_string (category_node, "name", NULL); - category = lgl_category_new (id, name); + category = lgl_category_new (id, name); - g_free (id); - g_free (name); + g_free (id); + g_free (name); - return category; + return category; } diff --git a/libglabels/lgl-xml-paper.c b/libglabels/lgl-xml-paper.c index 549f9e8a..40690deb 100644 --- a/libglabels/lgl-xml-paper.c +++ b/libglabels/lgl-xml-paper.c @@ -56,31 +56,33 @@ GList * lgl_xml_paper_read_papers_from_file (gchar *utf8_filename) { - gchar *filename; - GList *papers; - xmlDocPtr papers_doc; + gchar *filename; + GList *papers; + xmlDocPtr papers_doc; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); - if (!filename) { - g_message ("Utf8 filename conversion error"); - return NULL; - } + filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); + if (!filename) + { + g_message ("Utf8 filename conversion error"); + return NULL; + } - papers_doc = xmlParseFile (filename); - if (!papers_doc) { - g_message ("\"%s\" is not a glabels paper file (not XML)", - filename); - return NULL; - } + papers_doc = xmlParseFile (filename); + if (!papers_doc) + { + g_message ("\"%s\" is not a glabels paper file (not XML)", + filename); + return NULL; + } - papers = lgl_xml_paper_parse_papers_doc (papers_doc); + papers = lgl_xml_paper_parse_papers_doc (papers_doc); - g_free (filename); - xmlFreeDoc (papers_doc); + g_free (filename); + xmlFreeDoc (papers_doc); - return papers; + return papers; } @@ -96,41 +98,49 @@ lgl_xml_paper_read_papers_from_file (gchar *utf8_filename) GList * lgl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc) { - GList *papers = NULL; - xmlNodePtr root, node; - lglPaper *paper; - - LIBXML_TEST_VERSION; - - root = xmlDocGetRootElement (papers_doc); - if (!root || !root->name) { - g_message ("\"%s\" is not a glabels paper file (no root node)", - papers_doc->name); - xmlFreeDoc (papers_doc); - return papers; - } - if (!lgl_xml_is_node (root, "Glabels-paper-sizes")) { - g_message ("\"%s\" is not a glabels paper file (wrong root node)", - papers_doc->name); - xmlFreeDoc (papers_doc); - return papers; - } - - for (node = root->xmlChildrenNode; node != NULL; node = node->next) { - - if (lgl_xml_is_node (node, "Paper-size")) { - paper = lgl_xml_paper_parse_paper_node (node); - papers = g_list_append (papers, paper); - } else { - if ( !xmlNodeIsText(node) ) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - } - - return papers; + GList *papers = NULL; + xmlNodePtr root, node; + lglPaper *paper; + + LIBXML_TEST_VERSION; + + root = xmlDocGetRootElement (papers_doc); + if (!root || !root->name) + { + g_message ("\"%s\" is not a glabels paper file (no root node)", + papers_doc->name); + xmlFreeDoc (papers_doc); + return papers; + } + if (!lgl_xml_is_node (root, "Glabels-paper-sizes")) + { + g_message ("\"%s\" is not a glabels paper file (wrong root node)", + papers_doc->name); + xmlFreeDoc (papers_doc); + return papers; + } + + for (node = root->xmlChildrenNode; node != NULL; node = node->next) + { + + if (lgl_xml_is_node (node, "Paper-size")) + { + paper = lgl_xml_paper_parse_paper_node (node); + papers = g_list_append (papers, paper); + } + else + { + if ( !xmlNodeIsText(node) ) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + } + + return papers; } @@ -146,28 +156,28 @@ lgl_xml_paper_parse_papers_doc (xmlDocPtr papers_doc) lglPaper * lgl_xml_paper_parse_paper_node (xmlNodePtr paper_node) { - lglPaper *paper; - gchar *id, *name, *pwg_size; - gdouble width, height; + lglPaper *paper; + gchar *id, *name, *pwg_size; + gdouble width, height; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - id = lgl_xml_get_prop_string (paper_node, "id", NULL); + id = lgl_xml_get_prop_string (paper_node, "id", NULL); - name = lgl_xml_get_prop_i18n_string (paper_node, "name", NULL); + name = lgl_xml_get_prop_i18n_string (paper_node, "name", NULL); - width = lgl_xml_get_prop_length (paper_node, "width", 0); - height = lgl_xml_get_prop_length (paper_node, "height", 0); + width = lgl_xml_get_prop_length (paper_node, "width", 0); + height = lgl_xml_get_prop_length (paper_node, "height", 0); - pwg_size = lgl_xml_get_prop_string (paper_node, "pwg_size", NULL); + pwg_size = lgl_xml_get_prop_string (paper_node, "pwg_size", NULL); - paper = lgl_paper_new (id, name, width, height, pwg_size); + paper = lgl_paper_new (id, name, width, height, pwg_size); - g_free (id); - g_free (name); - g_free (pwg_size); + g_free (id); + g_free (name); + g_free (pwg_size); - return paper; + return paper; } diff --git a/libglabels/lgl-xml-template.c b/libglabels/lgl-xml-template.c index 95a2a659..883c6bef 100644 --- a/libglabels/lgl-xml-template.c +++ b/libglabels/lgl-xml-template.c @@ -44,55 +44,55 @@ /* Local function prototypes */ /*===========================================*/ static void xml_parse_meta_node (xmlNodePtr label_node, - lglTemplate *template); + lglTemplate *template); static void xml_parse_label_rectangle_node (xmlNodePtr label_node, - lglTemplate *template); + lglTemplate *template); static void xml_parse_label_ellipse_node (xmlNodePtr label_node, - lglTemplate *template); + lglTemplate *template); static void xml_parse_label_round_node (xmlNodePtr label_node, - lglTemplate *template); + lglTemplate *template); static void xml_parse_label_cd_node (xmlNodePtr label_node, - lglTemplate *template); + lglTemplate *template); static void xml_parse_layout_node (xmlNodePtr layout_node, - lglTemplateFrame *frame); + lglTemplateFrame *frame); static void xml_parse_markup_margin_node (xmlNodePtr markup_node, - lglTemplateFrame *frame); + lglTemplateFrame *frame); static void xml_parse_markup_line_node (xmlNodePtr markup_node, - lglTemplateFrame *frame); + lglTemplateFrame *frame); static void xml_parse_markup_circle_node (xmlNodePtr markup_node, - lglTemplateFrame *frame); + lglTemplateFrame *frame); static void xml_parse_markup_rect_node (xmlNodePtr markup_node, - lglTemplateFrame *frame); + lglTemplateFrame *frame); static void xml_parse_markup_ellipse_node (xmlNodePtr markup_node, - lglTemplateFrame *frame); + lglTemplateFrame *frame); static void xml_parse_alias_node (xmlNodePtr alias_node, - lglTemplate *template); + lglTemplate *template); static void xml_create_meta_node (const gchar *attr, const gchar *value, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_label_node (const lglTemplateFrame *frame, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_layout_node (const lglTemplateLayout *layout, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_markup_margin_node (const lglTemplateMarkup *margin, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_markup_line_node (const lglTemplateMarkup *line, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_markup_circle_node (const lglTemplateMarkup *circle, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_markup_rect_node (const lglTemplateMarkup *circle, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); static void xml_create_markup_ellipse_node (const lglTemplateMarkup *circle, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); /** @@ -105,28 +105,30 @@ static void xml_create_markup_ellipse_node (const lglTemplateMarkup *circl void lgl_xml_template_read_templates_from_file (const gchar *utf8_filename) { - gchar *filename; - xmlDocPtr templates_doc; + gchar *filename; + xmlDocPtr templates_doc; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); - if (!filename) { - g_message ("Utf8 filename conversion error"); - return; - } + filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); + if (!filename) + { + g_message ("Utf8 filename conversion error"); + return; + } - templates_doc = xmlParseFile (filename); - if (!templates_doc) { - g_message ("\"%s\" is not a glabels template file (not XML)", - filename); - return; - } + templates_doc = xmlParseFile (filename); + if (!templates_doc) + { + g_message ("\"%s\" is not a glabels template file (not XML)", + filename); + return; + } - lgl_xml_template_parse_templates_doc (templates_doc); + lgl_xml_template_parse_templates_doc (templates_doc); - g_free (filename); - xmlFreeDoc (templates_doc); + g_free (filename); + xmlFreeDoc (templates_doc); } @@ -140,49 +142,49 @@ lgl_xml_template_read_templates_from_file (const gchar *utf8_filename) void lgl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc) { - - xmlNodePtr root, node; - lglTemplate *template; + + xmlNodePtr root, node; + lglTemplate *template; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - root = xmlDocGetRootElement (templates_doc); - if (!root || !root->name) + root = xmlDocGetRootElement (templates_doc); + if (!root || !root->name) { - g_message ("\"%s\" is not a glabels template file (no root node)", - templates_doc->URL); - return; - } - if (!lgl_xml_is_node (root, "Glabels-templates")) + g_message ("\"%s\" is not a glabels template file (no root node)", + templates_doc->URL); + return; + } + if (!lgl_xml_is_node (root, "Glabels-templates")) { - g_message ("\"%s\" is not a glabels template file (wrong root node)", - templates_doc->URL); - return; - } + g_message ("\"%s\" is not a glabels template file (wrong root node)", + templates_doc->URL); + return; + } - for (node = root->xmlChildrenNode; node != NULL; node = node->next) + for (node = root->xmlChildrenNode; node != NULL; node = node->next) { - if (lgl_xml_is_node (node, "Template")) + if (lgl_xml_is_node (node, "Template")) { - template = lgl_xml_template_parse_template_node (node); + template = lgl_xml_template_parse_template_node (node); if (template) { _lgl_db_register_template_internal (template); lgl_template_free (template); } - } + } else { - if ( !xmlNodeIsText(node) ) + if ( !xmlNodeIsText(node) ) { - if (!lgl_xml_is_node (node,"comment")) + if (!lgl_xml_is_node (node,"comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - } + g_message ("bad node = \"%s\"",node->name); + } + } + } + } } @@ -198,22 +200,22 @@ lgl_xml_template_parse_templates_doc (const xmlDocPtr templates_doc) lglTemplate * lgl_xml_template_parse_template_node (const xmlNodePtr template_node) { - gchar *brand; + gchar *brand; gchar *part; - gchar *name; + gchar *name; gchar *equiv_part; - gchar *description; - gchar *paper_id; - gdouble page_width, page_height; - lglPaper *paper = NULL; - lglTemplate *template; - xmlNodePtr node; + gchar *description; + gchar *paper_id; + gdouble page_width, page_height; + lglPaper *paper = NULL; + lglTemplate *template; + xmlNodePtr node; gchar **v; lglTemplateFrame *frame; - brand = lgl_xml_get_prop_string (template_node, "brand", NULL); - part = lgl_xml_get_prop_string (template_node, "part", NULL); + brand = lgl_xml_get_prop_string (template_node, "brand", NULL); + part = lgl_xml_get_prop_string (template_node, "part", NULL); if (!brand || !part) { name = lgl_xml_get_prop_string (template_node, "name", NULL); @@ -228,7 +230,7 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) } else { - g_message ("Missing name or brand/part attributes."); + g_message ("Missing name or brand/part attributes."); } } @@ -236,37 +238,44 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) equiv_part = lgl_xml_get_prop_string (template_node, "equiv", NULL); - description = lgl_xml_get_prop_i18n_string (template_node, "description", NULL); - paper_id = lgl_xml_get_prop_string (template_node, "size", NULL); - - if (lgl_db_is_paper_id_other (paper_id)) { - - page_width = lgl_xml_get_prop_length (template_node, "width", 0); - page_height = lgl_xml_get_prop_length (template_node, "height", 0); - - } else { - paper = lgl_db_lookup_paper_from_id (paper_id); - if (paper == NULL) { - /* This should always be an id, but just in case a name - slips by! */ - g_message ("Unknown page size id \"%s\", trying as name", - paper_id); - paper = lgl_db_lookup_paper_from_name (paper_id); - g_free (paper_id); - paper_id = g_strdup (paper->id); - } - if (paper != NULL) { - page_width = paper->width; - page_height = paper->height; - } else { - page_width = 612; - page_height = 792; - g_message ("Unknown page size id or name \"%s\"", - paper_id); - } - lgl_paper_free (paper); - paper = NULL; - } + description = lgl_xml_get_prop_i18n_string (template_node, "description", NULL); + paper_id = lgl_xml_get_prop_string (template_node, "size", NULL); + + if (lgl_db_is_paper_id_other (paper_id)) + { + + page_width = lgl_xml_get_prop_length (template_node, "width", 0); + page_height = lgl_xml_get_prop_length (template_node, "height", 0); + + } + else + { + paper = lgl_db_lookup_paper_from_id (paper_id); + if (paper == NULL) + { + /* This should always be an id, but just in case a name + slips by! */ + g_message ("Unknown page size id \"%s\", trying as name", + paper_id); + paper = lgl_db_lookup_paper_from_name (paper_id); + g_free (paper_id); + paper_id = g_strdup (paper->id); + } + if (paper != NULL) + { + page_width = paper->width; + page_height = paper->height; + } + else + { + page_width = 612; + page_height = 792; + g_message ("Unknown page size id or name \"%s\"", + paper_id); + } + lgl_paper_free (paper); + paper = NULL; + } if (!equiv_part) @@ -280,40 +289,55 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) if (!template) { - g_message ("Forward references not supported."); + g_message ("Forward references not supported."); return NULL; } } - for (node = template_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (lgl_xml_is_node (node, "Meta")) { - xml_parse_meta_node (node, template); - } else if (lgl_xml_is_node (node, "Label-rectangle")) { - xml_parse_label_rectangle_node (node, template); - } else if (lgl_xml_is_node (node, "Label-ellipse")) { - xml_parse_label_ellipse_node (node, template); - } else if (lgl_xml_is_node (node, "Label-round")) { - xml_parse_label_round_node (node, template); - } else if (lgl_xml_is_node (node, "Label-cd")) { - xml_parse_label_cd_node (node, template); - } else if (lgl_xml_is_node (node, "Alias")) { - xml_parse_alias_node (node, template); - } else { - if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node,"comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - } - - g_free (brand); - g_free (part); - g_free (equiv_part); - g_free (description); - g_free (paper_id); + for (node = template_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (lgl_xml_is_node (node, "Meta")) + { + xml_parse_meta_node (node, template); + } + else if (lgl_xml_is_node (node, "Label-rectangle")) + { + xml_parse_label_rectangle_node (node, template); + } + else if (lgl_xml_is_node (node, "Label-ellipse")) + { + xml_parse_label_ellipse_node (node, template); + } + else if (lgl_xml_is_node (node, "Label-round")) + { + xml_parse_label_round_node (node, template); + } + else if (lgl_xml_is_node (node, "Label-cd")) + { + xml_parse_label_cd_node (node, template); + } + else if (lgl_xml_is_node (node, "Alias")) + { + xml_parse_alias_node (node, template); + } + else + { + if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node,"comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + } + + g_free (brand); + g_free (part); + g_free (equiv_part); + g_free (description); + g_free (paper_id); /* * Create a default full-page frame, if a known frame type was not found. @@ -336,7 +360,7 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) lgl_template_frame_add_layout (frame, lgl_template_layout_new (1, 1, 0, 0, 0, 0)); } - return template; + return template; } /*--------------------------------------------------------------------------*/ @@ -344,10 +368,10 @@ lgl_xml_template_parse_template_node (const xmlNodePtr template_node) /*--------------------------------------------------------------------------*/ static void xml_parse_meta_node (xmlNodePtr meta_node, - lglTemplate *template) + lglTemplate *template) { gchar *product_url; - gchar *category; + gchar *category; product_url = lgl_xml_get_prop_string (meta_node, "product_url", NULL); if ( product_url != NULL ) @@ -356,12 +380,12 @@ xml_parse_meta_node (xmlNodePtr meta_node, template->product_url = product_url; } - category = lgl_xml_get_prop_string (meta_node, "category", NULL); - if ( category != NULL ) - { - lgl_template_add_category (template, category); - g_free (category); - } + category = lgl_xml_get_prop_string (meta_node, "category", NULL); + if ( category != NULL ) + { + lgl_template_add_category (template, category); + g_free (category); + } } @@ -370,55 +394,72 @@ xml_parse_meta_node (xmlNodePtr meta_node, /*--------------------------------------------------------------------------*/ static void xml_parse_label_rectangle_node (xmlNodePtr label_node, - lglTemplate *template) + lglTemplate *template) { - gchar *id; - gchar *tmp; - gdouble x_waste, y_waste; - gdouble w, h, r; - lglTemplateFrame *frame; - xmlNodePtr node; - - id = lgl_xml_get_prop_string (label_node, "id", NULL); - - if ((tmp = lgl_xml_get_prop_string (label_node, "waste", NULL))) { - /* Handle single "waste" property. */ - x_waste = y_waste = lgl_xml_get_prop_length (label_node, "waste", 0); - g_free (tmp); - } else { - x_waste = lgl_xml_get_prop_length (label_node, "x_waste", 0); - y_waste = lgl_xml_get_prop_length (label_node, "y_waste", 0); - } - - w = lgl_xml_get_prop_length (label_node, "width", 0); - h = lgl_xml_get_prop_length (label_node, "height", 0); - r = lgl_xml_get_prop_length (label_node, "round", 0); - - frame = lgl_template_frame_rect_new ((gchar *)id, w, h, r, x_waste, y_waste); - lgl_template_add_frame (template, frame); - - for (node = label_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (lgl_xml_is_node (node, "Layout")) { - xml_parse_layout_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-margin")) { - xml_parse_markup_margin_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-line")) { - xml_parse_markup_line_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-circle")) { - xml_parse_markup_circle_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-rect")) { - xml_parse_markup_rect_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-ellipse")) { - xml_parse_markup_ellipse_node (node, frame); - } else if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - - g_free (id); + gchar *id; + gchar *tmp; + gdouble x_waste, y_waste; + gdouble w, h, r; + lglTemplateFrame *frame; + xmlNodePtr node; + + id = lgl_xml_get_prop_string (label_node, "id", NULL); + + if ((tmp = lgl_xml_get_prop_string (label_node, "waste", NULL))) + { + /* Handle single "waste" property. */ + x_waste = y_waste = lgl_xml_get_prop_length (label_node, "waste", 0); + g_free (tmp); + } + else + { + x_waste = lgl_xml_get_prop_length (label_node, "x_waste", 0); + y_waste = lgl_xml_get_prop_length (label_node, "y_waste", 0); + } + + w = lgl_xml_get_prop_length (label_node, "width", 0); + h = lgl_xml_get_prop_length (label_node, "height", 0); + r = lgl_xml_get_prop_length (label_node, "round", 0); + + frame = lgl_template_frame_rect_new ((gchar *)id, w, h, r, x_waste, y_waste); + lgl_template_add_frame (template, frame); + + for (node = label_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (lgl_xml_is_node (node, "Layout")) + { + xml_parse_layout_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-margin")) + { + xml_parse_markup_margin_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-line")) + { + xml_parse_markup_line_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-circle")) + { + xml_parse_markup_circle_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-rect")) + { + xml_parse_markup_rect_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-ellipse")) + { + xml_parse_markup_ellipse_node (node, frame); + } + else if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + + g_free (id); } @@ -429,43 +470,57 @@ static void xml_parse_label_ellipse_node (xmlNodePtr label_node, lglTemplate *template) { - gchar *id; - gdouble waste; - gdouble w, h; - lglTemplateFrame *frame; - xmlNodePtr node; + gchar *id; + gdouble waste; + gdouble w, h; + lglTemplateFrame *frame; + xmlNodePtr node; - id = lgl_xml_get_prop_string (label_node, "id", NULL); + id = lgl_xml_get_prop_string (label_node, "id", NULL); - w = lgl_xml_get_prop_length (label_node, "width", 0); - h = lgl_xml_get_prop_length (label_node, "height", 0); + w = lgl_xml_get_prop_length (label_node, "width", 0); + h = lgl_xml_get_prop_length (label_node, "height", 0); waste = lgl_xml_get_prop_length (label_node, "waste", 0); - frame = lgl_template_frame_ellipse_new ((gchar *)id, w, h, waste); - lgl_template_add_frame (template, frame); - - for (node = label_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (lgl_xml_is_node (node, "Layout")) { - xml_parse_layout_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-margin")) { - xml_parse_markup_margin_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-line")) { - xml_parse_markup_line_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-circle")) { - xml_parse_markup_circle_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-rect")) { - xml_parse_markup_rect_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-ellipse")) { - xml_parse_markup_ellipse_node (node, frame); - } else if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - - g_free (id); + frame = lgl_template_frame_ellipse_new ((gchar *)id, w, h, waste); + lgl_template_add_frame (template, frame); + + for (node = label_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (lgl_xml_is_node (node, "Layout")) + { + xml_parse_layout_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-margin")) + { + xml_parse_markup_margin_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-line")) + { + xml_parse_markup_line_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-circle")) + { + xml_parse_markup_circle_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-rect")) + { + xml_parse_markup_rect_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-ellipse")) + { + xml_parse_markup_ellipse_node (node, frame); + } + else if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + + g_free (id); } @@ -474,43 +529,57 @@ xml_parse_label_ellipse_node (xmlNodePtr label_node, /*--------------------------------------------------------------------------*/ static void xml_parse_label_round_node (xmlNodePtr label_node, - lglTemplate *template) + lglTemplate *template) { - gchar *id; - gdouble waste; - gdouble r; - lglTemplateFrame *frame; - xmlNodePtr node; - - id = lgl_xml_get_prop_string (label_node, "id", NULL); - waste = lgl_xml_get_prop_length (label_node, "waste", 0); - r = lgl_xml_get_prop_length (label_node, "radius", 0); - - frame = lgl_template_frame_round_new ((gchar *)id, r, waste); - lgl_template_add_frame (template, frame); - - for (node = label_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (lgl_xml_is_node (node, "Layout")) { - xml_parse_layout_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-margin")) { - xml_parse_markup_margin_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-line")) { - xml_parse_markup_line_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-circle")) { - xml_parse_markup_circle_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-rect")) { - xml_parse_markup_rect_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-ellipse")) { - xml_parse_markup_ellipse_node (node, frame); - } else if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - - g_free (id); + gchar *id; + gdouble waste; + gdouble r; + lglTemplateFrame *frame; + xmlNodePtr node; + + id = lgl_xml_get_prop_string (label_node, "id", NULL); + waste = lgl_xml_get_prop_length (label_node, "waste", 0); + r = lgl_xml_get_prop_length (label_node, "radius", 0); + + frame = lgl_template_frame_round_new ((gchar *)id, r, waste); + lgl_template_add_frame (template, frame); + + for (node = label_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (lgl_xml_is_node (node, "Layout")) + { + xml_parse_layout_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-margin")) + { + xml_parse_markup_margin_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-line")) + { + xml_parse_markup_line_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-circle")) + { + xml_parse_markup_circle_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-rect")) + { + xml_parse_markup_rect_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-ellipse")) + { + xml_parse_markup_ellipse_node (node, frame); + } + else if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + + g_free (id); } /*--------------------------------------------------------------------------*/ @@ -518,46 +587,60 @@ xml_parse_label_round_node (xmlNodePtr label_node, /*--------------------------------------------------------------------------*/ static void xml_parse_label_cd_node (xmlNodePtr label_node, - lglTemplate *template) + lglTemplate *template) { - gchar *id; - gdouble waste; - gdouble r1, r2, w, h; - lglTemplateFrame *frame; - xmlNodePtr node; - - id = lgl_xml_get_prop_string (label_node, "id", NULL); - waste = lgl_xml_get_prop_length (label_node, "waste", 0); - r1 = lgl_xml_get_prop_length (label_node, "radius", 0); - r2 = lgl_xml_get_prop_length (label_node, "hole", 0); - w = lgl_xml_get_prop_length (label_node, "width", 0); - h = lgl_xml_get_prop_length (label_node, "height", 0); - - frame = lgl_template_frame_cd_new ((gchar *)id, r1, r2, w, h, waste); - lgl_template_add_frame (template, frame); - - for (node = label_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (lgl_xml_is_node (node, "Layout")) { - xml_parse_layout_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-margin")) { - xml_parse_markup_margin_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-line")) { - xml_parse_markup_line_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-circle")) { - xml_parse_markup_circle_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-rect")) { - xml_parse_markup_rect_node (node, frame); - } else if (lgl_xml_is_node (node, "Markup-ellipse")) { - xml_parse_markup_ellipse_node (node, frame); - } else if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - - g_free (id); + gchar *id; + gdouble waste; + gdouble r1, r2, w, h; + lglTemplateFrame *frame; + xmlNodePtr node; + + id = lgl_xml_get_prop_string (label_node, "id", NULL); + waste = lgl_xml_get_prop_length (label_node, "waste", 0); + r1 = lgl_xml_get_prop_length (label_node, "radius", 0); + r2 = lgl_xml_get_prop_length (label_node, "hole", 0); + w = lgl_xml_get_prop_length (label_node, "width", 0); + h = lgl_xml_get_prop_length (label_node, "height", 0); + + frame = lgl_template_frame_cd_new ((gchar *)id, r1, r2, w, h, waste); + lgl_template_add_frame (template, frame); + + for (node = label_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (lgl_xml_is_node (node, "Layout")) + { + xml_parse_layout_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-margin")) + { + xml_parse_markup_margin_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-line")) + { + xml_parse_markup_line_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-circle")) + { + xml_parse_markup_circle_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-rect")) + { + xml_parse_markup_rect_node (node, frame); + } + else if (lgl_xml_is_node (node, "Markup-ellipse")) + { + xml_parse_markup_ellipse_node (node, frame); + } + else if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + + g_free (id); } /*--------------------------------------------------------------------------*/ @@ -565,31 +648,33 @@ xml_parse_label_cd_node (xmlNodePtr label_node, /*--------------------------------------------------------------------------*/ static void xml_parse_layout_node (xmlNodePtr layout_node, - lglTemplateFrame *frame) + lglTemplateFrame *frame) { - gint nx, ny; - gdouble x0, y0, dx, dy; - xmlNodePtr node; + gint nx, ny; + gdouble x0, y0, dx, dy; + xmlNodePtr node; - nx = lgl_xml_get_prop_int (layout_node, "nx", 1); - ny = lgl_xml_get_prop_int (layout_node, "ny", 1); + nx = lgl_xml_get_prop_int (layout_node, "nx", 1); + ny = lgl_xml_get_prop_int (layout_node, "ny", 1); - x0 = lgl_xml_get_prop_length (layout_node, "x0", 0); - y0 = lgl_xml_get_prop_length (layout_node, "y0", 0); + x0 = lgl_xml_get_prop_length (layout_node, "x0", 0); + y0 = lgl_xml_get_prop_length (layout_node, "y0", 0); - dx = lgl_xml_get_prop_length (layout_node, "dx", 0); - dy = lgl_xml_get_prop_length (layout_node, "dy", 0); + dx = lgl_xml_get_prop_length (layout_node, "dx", 0); + dy = lgl_xml_get_prop_length (layout_node, "dy", 0); - lgl_template_frame_add_layout (frame, lgl_template_layout_new (nx, ny, x0, y0, dx, dy)); + lgl_template_frame_add_layout (frame, lgl_template_layout_new (nx, ny, x0, y0, dx, dy)); - for (node = layout_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } + for (node = layout_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } } @@ -598,23 +683,25 @@ xml_parse_layout_node (xmlNodePtr layout_node, /*--------------------------------------------------------------------------*/ static void xml_parse_markup_margin_node (xmlNodePtr markup_node, - lglTemplateFrame *frame) + lglTemplateFrame *frame) { - gdouble size; - xmlNodePtr node; + gdouble size; + xmlNodePtr node; - size = lgl_xml_get_prop_length (markup_node, "size", 0); + size = lgl_xml_get_prop_length (markup_node, "size", 0); - lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (size)); + lgl_template_frame_add_markup (frame, lgl_template_markup_margin_new (size)); - for (node = markup_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } + for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } } @@ -623,26 +710,28 @@ xml_parse_markup_margin_node (xmlNodePtr markup_node, /*--------------------------------------------------------------------------*/ static void xml_parse_markup_line_node (xmlNodePtr markup_node, - lglTemplateFrame *frame) + lglTemplateFrame *frame) { - gdouble x1, y1, x2, y2; - xmlNodePtr node; + gdouble x1, y1, x2, y2; + xmlNodePtr node; - x1 = lgl_xml_get_prop_length (markup_node, "x1", 0); - y1 = lgl_xml_get_prop_length (markup_node, "y1", 0); - x2 = lgl_xml_get_prop_length (markup_node, "x2", 0); - y2 = lgl_xml_get_prop_length (markup_node, "y2", 0); + x1 = lgl_xml_get_prop_length (markup_node, "x1", 0); + y1 = lgl_xml_get_prop_length (markup_node, "y1", 0); + x2 = lgl_xml_get_prop_length (markup_node, "x2", 0); + y2 = lgl_xml_get_prop_length (markup_node, "y2", 0); - lgl_template_frame_add_markup (frame, lgl_template_markup_line_new (x1, y1, x2, y2)); + lgl_template_frame_add_markup (frame, lgl_template_markup_line_new (x1, y1, x2, y2)); - for (node = markup_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } + for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } } @@ -651,25 +740,27 @@ xml_parse_markup_line_node (xmlNodePtr markup_node, /*--------------------------------------------------------------------------*/ static void xml_parse_markup_circle_node (xmlNodePtr markup_node, - lglTemplateFrame *frame) + lglTemplateFrame *frame) { - gdouble x0, y0, r; - xmlNodePtr node; + gdouble x0, y0, r; + xmlNodePtr node; - x0 = lgl_xml_get_prop_length (markup_node, "x0", 0); - y0 = lgl_xml_get_prop_length (markup_node, "y0", 0); - r = lgl_xml_get_prop_length (markup_node, "radius", 0); + x0 = lgl_xml_get_prop_length (markup_node, "x0", 0); + y0 = lgl_xml_get_prop_length (markup_node, "y0", 0); + r = lgl_xml_get_prop_length (markup_node, "radius", 0); - lgl_template_frame_add_markup (frame, lgl_template_markup_circle_new (x0, y0, r)); + lgl_template_frame_add_markup (frame, lgl_template_markup_circle_new (x0, y0, r)); - for (node = markup_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } + for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } } @@ -679,27 +770,29 @@ xml_parse_markup_circle_node (xmlNodePtr markup_node, /*--------------------------------------------------------------------------*/ static void xml_parse_markup_rect_node (xmlNodePtr markup_node, - lglTemplateFrame *frame) + lglTemplateFrame *frame) { - gdouble x1, y1, w, h, r; - xmlNodePtr node; - - x1 = lgl_xml_get_prop_length (markup_node, "x1", 0); - y1 = lgl_xml_get_prop_length (markup_node, "y1", 0); - w = lgl_xml_get_prop_length (markup_node, "w", 0); - h = lgl_xml_get_prop_length (markup_node, "h", 0); - r = lgl_xml_get_prop_length (markup_node, "r", 0); - - lgl_template_frame_add_markup (frame, lgl_template_markup_rect_new (x1, y1, w, h, r)); - - for (node = markup_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } + gdouble x1, y1, w, h, r; + xmlNodePtr node; + + x1 = lgl_xml_get_prop_length (markup_node, "x1", 0); + y1 = lgl_xml_get_prop_length (markup_node, "y1", 0); + w = lgl_xml_get_prop_length (markup_node, "w", 0); + h = lgl_xml_get_prop_length (markup_node, "h", 0); + r = lgl_xml_get_prop_length (markup_node, "r", 0); + + lgl_template_frame_add_markup (frame, lgl_template_markup_rect_new (x1, y1, w, h, r)); + + for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } } @@ -711,24 +804,26 @@ static void xml_parse_markup_ellipse_node (xmlNodePtr markup_node, lglTemplateFrame *frame) { - gdouble x1, y1, w, h; - xmlNodePtr node; + gdouble x1, y1, w, h; + xmlNodePtr node; - x1 = lgl_xml_get_prop_length (markup_node, "x1", 0); - y1 = lgl_xml_get_prop_length (markup_node, "y1", 0); - w = lgl_xml_get_prop_length (markup_node, "w", 0); - h = lgl_xml_get_prop_length (markup_node, "h", 0); + x1 = lgl_xml_get_prop_length (markup_node, "x1", 0); + y1 = lgl_xml_get_prop_length (markup_node, "y1", 0); + w = lgl_xml_get_prop_length (markup_node, "w", 0); + h = lgl_xml_get_prop_length (markup_node, "h", 0); - lgl_template_frame_add_markup (frame, lgl_template_markup_ellipse_new (x1, y1, w, h)); + lgl_template_frame_add_markup (frame, lgl_template_markup_ellipse_new (x1, y1, w, h)); - for (node = markup_node->xmlChildrenNode; node != NULL; - node = node->next) { - if (!xmlNodeIsText (node)) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } + for (node = markup_node->xmlChildrenNode; node != NULL; node = node->next) + { + if (!xmlNodeIsText (node)) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } } @@ -738,7 +833,7 @@ xml_parse_markup_ellipse_node (xmlNodePtr markup_node, /*--------------------------------------------------------------------------*/ static void xml_parse_alias_node (xmlNodePtr alias_node, - lglTemplate *template) + lglTemplate *template) { g_message ("Skipping deprecated \"Alias\" node."); } @@ -758,38 +853,39 @@ gint lgl_xml_template_write_templates_to_file (GList *templates, const gchar *utf8_filename) { - xmlDocPtr doc; - xmlNsPtr ns; - gint bytes_written; - GList *p; - lglTemplate *template; - gchar *filename; - - doc = xmlNewDoc ((xmlChar *)"1.0"); - doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *)"Glabels-templates", NULL); - - ns = xmlNewNs (doc->xmlRootNode, (xmlChar *)LGL_XML_NAME_SPACE, NULL); - xmlSetNs (doc->xmlRootNode, ns); - - for (p=templates; p!=NULL; p=p->next) { - template = (lglTemplate *)p->data; - lgl_xml_template_create_template_node (template, doc->xmlRootNode, ns); - } - - filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); - if (!filename) + xmlDocPtr doc; + xmlNsPtr ns; + gint bytes_written; + GList *p; + lglTemplate *template; + gchar *filename; + + doc = xmlNewDoc ((xmlChar *)"1.0"); + doc->xmlRootNode = xmlNewDocNode (doc, NULL, (xmlChar *)"Glabels-templates", NULL); + + ns = xmlNewNs (doc->xmlRootNode, (xmlChar *)LGL_XML_NAME_SPACE, NULL); + xmlSetNs (doc->xmlRootNode, ns); + + for (p=templates; p!=NULL; p=p->next) { - g_message ("Utf8 conversion error."); + template = (lglTemplate *)p->data; + lgl_xml_template_create_template_node (template, doc->xmlRootNode, ns); + } + + filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); + if (!filename) + { + g_message ("Utf8 conversion error."); return -1; } - else + else { - xmlSetDocCompressMode (doc, 0); - bytes_written = xmlSaveFormatFile (filename, doc, TRUE); - xmlFreeDoc (doc); - g_free (filename); + xmlSetDocCompressMode (doc, 0); + bytes_written = xmlSaveFormatFile (filename, doc, TRUE); + xmlFreeDoc (doc); + g_free (filename); return bytes_written; - } + } } @@ -808,14 +904,14 @@ gint lgl_xml_template_write_template_to_file (const lglTemplate *template, const gchar *utf8_filename) { - GList *templates = NULL; - gint bytes_written; + GList *templates = NULL; + gint bytes_written; - templates = g_list_append (templates, (gpointer)template); + templates = g_list_append (templates, (gpointer)template); - bytes_written = lgl_xml_template_write_templates_to_file (templates, utf8_filename); + bytes_written = lgl_xml_template_write_templates_to_file (templates, utf8_filename); - g_list_free (templates); + g_list_free (templates); return bytes_written; } @@ -835,36 +931,36 @@ lgl_xml_template_create_template_node (const lglTemplate *template, xmlNodePtr root, const xmlNsPtr ns) { - xmlNodePtr node; - GList *p; - lglTemplateFrame *frame; + xmlNodePtr node; + GList *p; + lglTemplateFrame *frame; - node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL); + node = xmlNewChild (root, ns, (xmlChar *)"Template", NULL); - lgl_xml_set_prop_string (node, "brand", template->brand); - lgl_xml_set_prop_string (node, "part", template->part); + lgl_xml_set_prop_string (node, "brand", template->brand); + lgl_xml_set_prop_string (node, "part", template->part); - lgl_xml_set_prop_string (node, "size", template->paper_id); - if (xmlStrEqual ((xmlChar *)template->paper_id, (xmlChar *)"Other")) + lgl_xml_set_prop_string (node, "size", template->paper_id); + if (xmlStrEqual ((xmlChar *)template->paper_id, (xmlChar *)"Other")) { - lgl_xml_set_prop_length (node, "width", template->page_width); - lgl_xml_set_prop_length (node, "height", template->page_height); + lgl_xml_set_prop_length (node, "width", template->page_width); + lgl_xml_set_prop_length (node, "height", template->page_height); - } + } - lgl_xml_set_prop_string (node, "description", template->description); + lgl_xml_set_prop_string (node, "description", template->description); xml_create_meta_node ("product_url", template->product_url, node, ns ); - for ( p=template->category_ids; p != NULL; p=p->next ) + for ( p=template->category_ids; p != NULL; p=p->next ) { xml_create_meta_node ( "category", p->data, node, ns ); - } - for ( p=template->frames; p != NULL; p=p->next ) + } + for ( p=template->frames; p != NULL; p=p->next ) { - frame = (lglTemplateFrame *)p->data; - xml_create_label_node (frame, node, ns); - } + frame = (lglTemplateFrame *)p->data; + xml_create_label_node (frame, node, ns); + } } @@ -877,7 +973,7 @@ xml_create_meta_node (const gchar *attr, xmlNodePtr root, const xmlNsPtr ns) { - xmlNodePtr node; + xmlNodePtr node; if ( value != NULL ) { @@ -892,90 +988,96 @@ xml_create_meta_node (const gchar *attr, /*--------------------------------------------------------------------------*/ static void xml_create_label_node (const lglTemplateFrame *frame, - xmlNodePtr root, - const xmlNsPtr ns) + xmlNodePtr root, + const xmlNsPtr ns) { - xmlNodePtr node; - GList *p; - lglTemplateMarkup *markup; - lglTemplateLayout *layout; - - switch (frame->shape) { - - case LGL_TEMPLATE_FRAME_SHAPE_RECT: - node = xmlNewChild(root, ns, (xmlChar *)"Label-rectangle", NULL); - lgl_xml_set_prop_string (node, "id", frame->all.id); - lgl_xml_set_prop_length (node, "width", frame->rect.w); - lgl_xml_set_prop_length (node, "height", frame->rect.h); - lgl_xml_set_prop_length (node, "round", frame->rect.r); - lgl_xml_set_prop_length (node, "x_waste", frame->rect.x_waste); - lgl_xml_set_prop_length (node, "y_waste", frame->rect.y_waste); - break; - - case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: - node = xmlNewChild(root, ns, (xmlChar *)"Label-ellipse", NULL); - lgl_xml_set_prop_string (node, "id", frame->all.id); - lgl_xml_set_prop_length (node, "width", frame->ellipse.w); - lgl_xml_set_prop_length (node, "height", frame->ellipse.h); - lgl_xml_set_prop_length (node, "waste", frame->ellipse.waste); - break; - - case LGL_TEMPLATE_FRAME_SHAPE_ROUND: - node = xmlNewChild(root, ns, (xmlChar *)"Label-round", NULL); - lgl_xml_set_prop_string (node, "id", frame->all.id); - lgl_xml_set_prop_length (node, "radius", frame->round.r); - lgl_xml_set_prop_length (node, "waste", frame->round.waste); - break; - - case LGL_TEMPLATE_FRAME_SHAPE_CD: - node = xmlNewChild(root, ns, (xmlChar *)"Label-cd", NULL); - lgl_xml_set_prop_string (node, "id", frame->all.id); - lgl_xml_set_prop_length (node, "radius", frame->cd.r1); - lgl_xml_set_prop_length (node, "hole", frame->cd.r2); - if (frame->cd.w != 0.0) { - lgl_xml_set_prop_length (node, "width", frame->cd.w); - } - if (frame->cd.h != 0.0) { - lgl_xml_set_prop_length (node, "height", frame->cd.h); - } - lgl_xml_set_prop_length (node, "waste", frame->cd.waste); - break; - - default: - g_message ("Unknown label style"); - return; - break; - - } - - for ( p=frame->all.markups; p != NULL; p=p->next ) { - markup = (lglTemplateMarkup *)p->data; - switch (markup->type) { - case LGL_TEMPLATE_MARKUP_MARGIN: - xml_create_markup_margin_node (markup, node, ns); - break; - case LGL_TEMPLATE_MARKUP_LINE: - xml_create_markup_line_node (markup, node, ns); - break; - case LGL_TEMPLATE_MARKUP_CIRCLE: - xml_create_markup_circle_node (markup, node, ns); - break; - case LGL_TEMPLATE_MARKUP_RECT: - xml_create_markup_rect_node (markup, node, ns); - break; - case LGL_TEMPLATE_MARKUP_ELLIPSE: - xml_create_markup_ellipse_node (markup, node, ns); - break; - default: - g_message ("Unknown markup type"); - break; - } - } - - for ( p=frame->all.layouts; p != NULL; p=p->next ) { - layout = (lglTemplateLayout *)p->data; - xml_create_layout_node (layout, node, ns); - } + xmlNodePtr node; + GList *p; + lglTemplateMarkup *markup; + lglTemplateLayout *layout; + + switch (frame->shape) + { + + case LGL_TEMPLATE_FRAME_SHAPE_RECT: + node = xmlNewChild(root, ns, (xmlChar *)"Label-rectangle", NULL); + lgl_xml_set_prop_string (node, "id", frame->all.id); + lgl_xml_set_prop_length (node, "width", frame->rect.w); + lgl_xml_set_prop_length (node, "height", frame->rect.h); + lgl_xml_set_prop_length (node, "round", frame->rect.r); + lgl_xml_set_prop_length (node, "x_waste", frame->rect.x_waste); + lgl_xml_set_prop_length (node, "y_waste", frame->rect.y_waste); + break; + + case LGL_TEMPLATE_FRAME_SHAPE_ELLIPSE: + node = xmlNewChild(root, ns, (xmlChar *)"Label-ellipse", NULL); + lgl_xml_set_prop_string (node, "id", frame->all.id); + lgl_xml_set_prop_length (node, "width", frame->ellipse.w); + lgl_xml_set_prop_length (node, "height", frame->ellipse.h); + lgl_xml_set_prop_length (node, "waste", frame->ellipse.waste); + break; + + case LGL_TEMPLATE_FRAME_SHAPE_ROUND: + node = xmlNewChild(root, ns, (xmlChar *)"Label-round", NULL); + lgl_xml_set_prop_string (node, "id", frame->all.id); + lgl_xml_set_prop_length (node, "radius", frame->round.r); + lgl_xml_set_prop_length (node, "waste", frame->round.waste); + break; + + case LGL_TEMPLATE_FRAME_SHAPE_CD: + node = xmlNewChild(root, ns, (xmlChar *)"Label-cd", NULL); + lgl_xml_set_prop_string (node, "id", frame->all.id); + lgl_xml_set_prop_length (node, "radius", frame->cd.r1); + lgl_xml_set_prop_length (node, "hole", frame->cd.r2); + if (frame->cd.w != 0.0) + { + lgl_xml_set_prop_length (node, "width", frame->cd.w); + } + if (frame->cd.h != 0.0) + { + lgl_xml_set_prop_length (node, "height", frame->cd.h); + } + lgl_xml_set_prop_length (node, "waste", frame->cd.waste); + break; + + default: + g_message ("Unknown label style"); + return; + break; + + } + + for ( p=frame->all.markups; p != NULL; p=p->next ) + { + markup = (lglTemplateMarkup *)p->data; + switch (markup->type) + { + case LGL_TEMPLATE_MARKUP_MARGIN: + xml_create_markup_margin_node (markup, node, ns); + break; + case LGL_TEMPLATE_MARKUP_LINE: + xml_create_markup_line_node (markup, node, ns); + break; + case LGL_TEMPLATE_MARKUP_CIRCLE: + xml_create_markup_circle_node (markup, node, ns); + break; + case LGL_TEMPLATE_MARKUP_RECT: + xml_create_markup_rect_node (markup, node, ns); + break; + case LGL_TEMPLATE_MARKUP_ELLIPSE: + xml_create_markup_ellipse_node (markup, node, ns); + break; + default: + g_message ("Unknown markup type"); + break; + } + } + + for ( p=frame->all.layouts; p != NULL; p=p->next ) + { + layout = (lglTemplateLayout *)p->data; + xml_create_layout_node (layout, node, ns); + } } @@ -984,18 +1086,18 @@ xml_create_label_node (const lglTemplateFrame *frame, /*--------------------------------------------------------------------------*/ static void xml_create_layout_node (const lglTemplateLayout *layout, - xmlNodePtr root, - const xmlNsPtr ns) + xmlNodePtr root, + const xmlNsPtr ns) { - xmlNodePtr node; + xmlNodePtr node; - node = xmlNewChild(root, ns, (xmlChar *)"Layout", NULL); - lgl_xml_set_prop_int (node, "nx", layout->nx); - lgl_xml_set_prop_int (node, "ny", layout->ny); - lgl_xml_set_prop_length (node, "x0", layout->x0); - lgl_xml_set_prop_length (node, "y0", layout->y0); - lgl_xml_set_prop_length (node, "dx", layout->dx); - lgl_xml_set_prop_length (node, "dy", layout->dy); + node = xmlNewChild(root, ns, (xmlChar *)"Layout", NULL); + lgl_xml_set_prop_int (node, "nx", layout->nx); + lgl_xml_set_prop_int (node, "ny", layout->ny); + lgl_xml_set_prop_length (node, "x0", layout->x0); + lgl_xml_set_prop_length (node, "y0", layout->y0); + lgl_xml_set_prop_length (node, "dx", layout->dx); + lgl_xml_set_prop_length (node, "dy", layout->dy); } @@ -1004,14 +1106,14 @@ xml_create_layout_node (const lglTemplateLayout *layout, /*--------------------------------------------------------------------------*/ static void xml_create_markup_margin_node (const lglTemplateMarkup *markup, - xmlNodePtr root, - const xmlNsPtr ns) + xmlNodePtr root, + const xmlNsPtr ns) { - xmlNodePtr node; + xmlNodePtr node; - node = xmlNewChild(root, ns, (xmlChar *)"Markup-margin", NULL); + node = xmlNewChild(root, ns, (xmlChar *)"Markup-margin", NULL); - lgl_xml_set_prop_length (node, "size", markup->margin.size); + lgl_xml_set_prop_length (node, "size", markup->margin.size); } @@ -1020,17 +1122,17 @@ xml_create_markup_margin_node (const lglTemplateMarkup *markup, /*--------------------------------------------------------------------------*/ static void xml_create_markup_line_node (const lglTemplateMarkup *markup, - xmlNodePtr root, - const xmlNsPtr ns) + xmlNodePtr root, + const xmlNsPtr ns) { - xmlNodePtr node; + xmlNodePtr node; - node = xmlNewChild(root, ns, (xmlChar *)"Markup-line", NULL); + node = xmlNewChild(root, ns, (xmlChar *)"Markup-line", NULL); - lgl_xml_set_prop_length (node, "x1", markup->line.x1); - lgl_xml_set_prop_length (node, "y1", markup->line.y1); - lgl_xml_set_prop_length (node, "x2", markup->line.x2); - lgl_xml_set_prop_length (node, "y2", markup->line.y2); + lgl_xml_set_prop_length (node, "x1", markup->line.x1); + lgl_xml_set_prop_length (node, "y1", markup->line.y1); + lgl_xml_set_prop_length (node, "x2", markup->line.x2); + lgl_xml_set_prop_length (node, "y2", markup->line.y2); } @@ -1039,16 +1141,16 @@ xml_create_markup_line_node (const lglTemplateMarkup *markup, /*--------------------------------------------------------------------------*/ static void xml_create_markup_circle_node (const lglTemplateMarkup *markup, - xmlNodePtr root, - const xmlNsPtr ns) + xmlNodePtr root, + const xmlNsPtr ns) { - xmlNodePtr node; + xmlNodePtr node; - node = xmlNewChild(root, ns, (xmlChar *)"Markup-circle", NULL); + node = xmlNewChild(root, ns, (xmlChar *)"Markup-circle", NULL); - lgl_xml_set_prop_length (node, "x0", markup->circle.x0); - lgl_xml_set_prop_length (node, "y0", markup->circle.y0); - lgl_xml_set_prop_length (node, "radius", markup->circle.r); + lgl_xml_set_prop_length (node, "x0", markup->circle.x0); + lgl_xml_set_prop_length (node, "y0", markup->circle.y0); + lgl_xml_set_prop_length (node, "radius", markup->circle.r); } @@ -1058,18 +1160,18 @@ xml_create_markup_circle_node (const lglTemplateMarkup *markup, /*--------------------------------------------------------------------------*/ static void xml_create_markup_rect_node (const lglTemplateMarkup *markup, - xmlNodePtr root, - const xmlNsPtr ns) + xmlNodePtr root, + const xmlNsPtr ns) { - xmlNodePtr node; + xmlNodePtr node; - node = xmlNewChild(root, ns, (xmlChar *)"Markup-rect", NULL); + node = xmlNewChild(root, ns, (xmlChar *)"Markup-rect", NULL); - lgl_xml_set_prop_length (node, "x1", markup->rect.x1); - lgl_xml_set_prop_length (node, "y1", markup->rect.y1); - lgl_xml_set_prop_length (node, "w", markup->rect.w); - lgl_xml_set_prop_length (node, "h", markup->rect.h); - lgl_xml_set_prop_length (node, "r", markup->rect.r); + lgl_xml_set_prop_length (node, "x1", markup->rect.x1); + lgl_xml_set_prop_length (node, "y1", markup->rect.y1); + lgl_xml_set_prop_length (node, "w", markup->rect.w); + lgl_xml_set_prop_length (node, "h", markup->rect.h); + lgl_xml_set_prop_length (node, "r", markup->rect.r); } @@ -1082,14 +1184,14 @@ xml_create_markup_ellipse_node (const lglTemplateMarkup *markup, xmlNodePtr root, const xmlNsPtr ns) { - xmlNodePtr node; + xmlNodePtr node; - node = xmlNewChild(root, ns, (xmlChar *)"Markup-ellipse", NULL); + node = xmlNewChild(root, ns, (xmlChar *)"Markup-ellipse", NULL); - lgl_xml_set_prop_length (node, "x1", markup->ellipse.x1); - lgl_xml_set_prop_length (node, "y1", markup->ellipse.y1); - lgl_xml_set_prop_length (node, "w", markup->ellipse.w); - lgl_xml_set_prop_length (node, "h", markup->ellipse.h); + lgl_xml_set_prop_length (node, "x1", markup->ellipse.x1); + lgl_xml_set_prop_length (node, "y1", markup->ellipse.y1); + lgl_xml_set_prop_length (node, "w", markup->ellipse.w); + lgl_xml_set_prop_length (node, "h", markup->ellipse.h); } diff --git a/libglabels/lgl-xml-template.h b/libglabels/lgl-xml-template.h index 99b52d39..8dd14381 100644 --- a/libglabels/lgl-xml-template.h +++ b/libglabels/lgl-xml-template.h @@ -36,14 +36,14 @@ lglTemplate *lgl_xml_template_parse_template_node (const xmlNodePtr templ gint lgl_xml_template_write_templates_to_file (GList *templates, - const gchar *utf8_filename); + const gchar *utf8_filename); gint lgl_xml_template_write_template_to_file (const lglTemplate *template, - const gchar *utf8_filename); + const gchar *utf8_filename); void lgl_xml_template_create_template_node (const lglTemplate *template, - xmlNodePtr root, - const xmlNsPtr ns); + xmlNodePtr root, + const xmlNsPtr ns); G_END_DECLS diff --git a/libglabels/lgl-xml-vendor.c b/libglabels/lgl-xml-vendor.c index cc44bc87..0e329b2f 100644 --- a/libglabels/lgl-xml-vendor.c +++ b/libglabels/lgl-xml-vendor.c @@ -56,31 +56,33 @@ GList * lgl_xml_vendor_read_vendors_from_file (gchar *utf8_filename) { - gchar *filename; - GList *vendors; - xmlDocPtr vendors_doc; + gchar *filename; + GList *vendors; + xmlDocPtr vendors_doc; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); - if (!filename) { - g_message ("Utf8 filename conversion error"); - return NULL; - } + filename = g_filename_from_utf8 (utf8_filename, -1, NULL, NULL, NULL); + if (!filename) + { + g_message ("Utf8 filename conversion error"); + return NULL; + } - vendors_doc = xmlParseFile (filename); - if (!vendors_doc) { - g_message ("\"%s\" is not a glabels vendor file (not XML)", - filename); - return NULL; - } + vendors_doc = xmlParseFile (filename); + if (!vendors_doc) + { + g_message ("\"%s\" is not a glabels vendor file (not XML)", + filename); + return NULL; + } - vendors = lgl_xml_vendor_parse_vendors_doc (vendors_doc); + vendors = lgl_xml_vendor_parse_vendors_doc (vendors_doc); - g_free (filename); - xmlFreeDoc (vendors_doc); + g_free (filename); + xmlFreeDoc (vendors_doc); - return vendors; + return vendors; } @@ -96,41 +98,48 @@ lgl_xml_vendor_read_vendors_from_file (gchar *utf8_filename) GList * lgl_xml_vendor_parse_vendors_doc (xmlDocPtr vendors_doc) { - GList *vendors = NULL; - xmlNodePtr root, node; - lglVendor *vendor; - - LIBXML_TEST_VERSION; - - root = xmlDocGetRootElement (vendors_doc); - if (!root || !root->name) { - g_message ("\"%s\" is not a glabels vendor file (no root node)", - vendors_doc->name); - xmlFreeDoc (vendors_doc); - return vendors; - } - if (!lgl_xml_is_node (root, "Glabels-vendors")) { - g_message ("\"%s\" is not a glabels vendor file (wrong root node)", - vendors_doc->name); - xmlFreeDoc (vendors_doc); - return vendors; - } - - for (node = root->xmlChildrenNode; node != NULL; node = node->next) { - - if (lgl_xml_is_node (node, "Vendor")) { - vendor = lgl_xml_vendor_parse_vendor_node (node); - vendors = g_list_append (vendors, vendor); - } else { - if ( !xmlNodeIsText(node) ) { - if (!lgl_xml_is_node (node, "comment")) { - g_message ("bad node = \"%s\"",node->name); - } - } - } - } - - return vendors; + GList *vendors = NULL; + xmlNodePtr root, node; + lglVendor *vendor; + + LIBXML_TEST_VERSION; + + root = xmlDocGetRootElement (vendors_doc); + if (!root || !root->name) + { + g_message ("\"%s\" is not a glabels vendor file (no root node)", + vendors_doc->name); + xmlFreeDoc (vendors_doc); + return vendors; + } + if (!lgl_xml_is_node (root, "Glabels-vendors")) + { + g_message ("\"%s\" is not a glabels vendor file (wrong root node)", + vendors_doc->name); + xmlFreeDoc (vendors_doc); + return vendors; + } + + for (node = root->xmlChildrenNode; node != NULL; node = node->next) + { + if (lgl_xml_is_node (node, "Vendor")) + { + vendor = lgl_xml_vendor_parse_vendor_node (node); + vendors = g_list_append (vendors, vendor); + } + else + { + if ( !xmlNodeIsText(node) ) + { + if (!lgl_xml_is_node (node, "comment")) + { + g_message ("bad node = \"%s\"",node->name); + } + } + } + } + + return vendors; } @@ -146,20 +155,20 @@ lgl_xml_vendor_parse_vendors_doc (xmlDocPtr vendors_doc) lglVendor * lgl_xml_vendor_parse_vendor_node (xmlNodePtr vendor_node) { - lglVendor *vendor; - gchar *name; + lglVendor *vendor; + gchar *name; - LIBXML_TEST_VERSION; + LIBXML_TEST_VERSION; - name = lgl_xml_get_prop_i18n_string (vendor_node, "name", NULL); + name = lgl_xml_get_prop_i18n_string (vendor_node, "name", NULL); - vendor = lgl_vendor_new (name); + vendor = lgl_vendor_new (name); vendor->url = lgl_xml_get_prop_i18n_string (vendor_node, "url", NULL); - g_free (name); + g_free (name); - return vendor; + return vendor; } diff --git a/libglabels/lgl-xml.c b/libglabels/lgl-xml.c index 8a090198..e353271b 100644 --- a/libglabels/lgl-xml.c +++ b/libglabels/lgl-xml.c @@ -60,24 +60,26 @@ static lglUnits default_units = LGL_UNITS_POINT; */ gchar * lgl_xml_get_prop_string (xmlNodePtr node, - const gchar *property, - const gchar *default_val) + const gchar *property, + const gchar *default_val) { - gchar *val; - xmlChar *string; - - string = xmlGetProp (node, (xmlChar *)property); - if ( string != NULL ) { - val = g_strdup ((gchar *)string); - xmlFree (string); - return val; - } - - if (default_val) { - return g_strdup (default_val); - } - - return NULL; + gchar *val; + xmlChar *string; + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) + { + val = g_strdup ((gchar *)string); + xmlFree (string); + return val; + } + + if (default_val) + { + return g_strdup (default_val); + } + + return NULL; } @@ -95,37 +97,38 @@ lgl_xml_get_prop_string (xmlNodePtr node, */ gchar * lgl_xml_get_prop_i18n_string (xmlNodePtr node, - const gchar *property, - const gchar *default_val) + const gchar *property, + const gchar *default_val) { - gchar *_property; - gchar *val; - xmlChar *string; - - _property = g_strdup_printf ("_%s", property); - string = xmlGetProp (node, (xmlChar *)_property); - g_free (_property); - - if ( string != NULL ) { - - val = g_strdup (gettext ((char *)string)); - xmlFree (string); - return val; - - } - - string = xmlGetProp (node, (xmlChar *)property); - if ( string != NULL ) { - val = g_strdup ((gchar *)string); - xmlFree (string); - return val; - } - - if (default_val) { - return g_strdup (default_val); - } - - return NULL; + gchar *_property; + gchar *val; + xmlChar *string; + + _property = g_strdup_printf ("_%s", property); + string = xmlGetProp (node, (xmlChar *)_property); + g_free (_property); + + if ( string != NULL ) + { + val = g_strdup (gettext ((char *)string)); + xmlFree (string); + return val; + } + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) + { + val = g_strdup ((gchar *)string); + xmlFree (string); + return val; + } + + if (default_val) + { + return g_strdup (default_val); + } + + return NULL; } @@ -142,20 +145,21 @@ lgl_xml_get_prop_i18n_string (xmlNodePtr node, */ gdouble lgl_xml_get_prop_double (xmlNodePtr node, - const gchar *property, - gdouble default_val) + const gchar *property, + gdouble default_val) { - gdouble val; - xmlChar *string; - - string = xmlGetProp (node, (xmlChar *)property); - if ( string != NULL ) { - val = g_strtod ((gchar *)string, NULL); - xmlFree (string); - return val; - } - - return default_val; + gdouble val; + xmlChar *string; + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) + { + val = g_strtod ((gchar *)string, NULL); + xmlFree (string); + return val; + } + + return default_val; } @@ -172,21 +176,22 @@ lgl_xml_get_prop_double (xmlNodePtr node, */ gboolean lgl_xml_get_prop_boolean (xmlNodePtr node, - const gchar *property, - gboolean default_val) + const gchar *property, + gboolean default_val) { - gboolean val; - xmlChar *string; - - string = xmlGetProp (node, (xmlChar *)property); - if ( string != NULL ) { - val = !((xmlStrcasecmp (string, (xmlChar *)"false") == 0) || - xmlStrEqual (string, (xmlChar *)"0"));; - xmlFree (string); - return val; - } - - return default_val; + gboolean val; + xmlChar *string; + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) + { + val = !((xmlStrcasecmp (string, (xmlChar *)"false") == 0) || + xmlStrEqual (string, (xmlChar *)"0"));; + xmlFree (string); + return val; + } + + return default_val; } @@ -203,20 +208,21 @@ lgl_xml_get_prop_boolean (xmlNodePtr node, */ gint lgl_xml_get_prop_int (xmlNodePtr node, - const gchar *property, - gint default_val) + const gchar *property, + gint default_val) { - gint val; - xmlChar *string; - - string = xmlGetProp (node, (xmlChar *)property); - if ( string != NULL ) { - val = strtol ((char *)string, NULL, 0); - xmlFree (string); - return val; - } - - return default_val; + gint val; + xmlChar *string; + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) + { + val = strtol ((char *)string, NULL, 0); + xmlFree (string); + return val; + } + + return default_val; } @@ -233,20 +239,21 @@ lgl_xml_get_prop_int (xmlNodePtr node, */ guint lgl_xml_get_prop_uint (xmlNodePtr node, - const gchar *property, - guint default_val) + const gchar *property, + guint default_val) { - guint val; - xmlChar *string; - - string = xmlGetProp (node, (xmlChar *)property); - if ( string != NULL ) { - val = strtoul ((char *)string, NULL, 0); - xmlFree (string); - return val; - } - - return default_val; + guint val; + xmlChar *string; + + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) + { + val = strtoul ((char *)string, NULL, 0); + xmlFree (string); + return val; + } + + return default_val; } @@ -268,21 +275,23 @@ lgl_xml_get_prop_uint (xmlNodePtr node, */ gdouble lgl_xml_get_prop_length (xmlNodePtr node, - const gchar *property, - gdouble default_val) + const gchar *property, + gdouble default_val) { - gdouble val; - xmlChar *string; - xmlChar *unit_id; + gdouble val; + xmlChar *string; + xmlChar *unit_id; lglUnits units; - string = xmlGetProp (node, (xmlChar *)property); - if ( string != NULL ) { + string = xmlGetProp (node, (xmlChar *)property); + if ( string != NULL ) + { - val = g_strtod ((gchar *)string, (gchar **)&unit_id); + val = g_strtod ((gchar *)string, (gchar **)&unit_id); - if (unit_id != string) { - unit_id = (xmlChar *)g_strchug ((gchar *)unit_id); + if (unit_id != string) + { + unit_id = (xmlChar *)g_strchug ((gchar *)unit_id); units = lgl_units_from_id ((gchar *)unit_id); if (units != LGL_UNITS_INVALID) { @@ -293,16 +302,17 @@ lgl_xml_get_prop_length (xmlNodePtr node, g_message ("Line %ld, Node \"%s\", Property \"%s\": Unknown unit \"%s\", assuming points", xmlGetLineNo (node), node->name, property, unit_id); } - } - else { - val = 0.0; - } + } + else + { + val = 0.0; + } - xmlFree (string); - return val; - } + xmlFree (string); + return val; + } - return default_val; + return default_val; } @@ -317,12 +327,13 @@ lgl_xml_get_prop_length (xmlNodePtr node, */ void lgl_xml_set_prop_string (xmlNodePtr node, - const gchar *property, - const gchar *val) + const gchar *property, + const gchar *val) { - if (val != NULL) { - xmlSetProp (node, (xmlChar *)property, (xmlChar *)val); - } + if (val != NULL) + { + xmlSetProp (node, (xmlChar *)property, (xmlChar *)val); + } } @@ -337,15 +348,15 @@ lgl_xml_set_prop_string (xmlNodePtr node, */ void lgl_xml_set_prop_double (xmlNodePtr node, - const gchar *property, - gdouble val) + const gchar *property, + gdouble val) { - gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE]; + gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE]; - /* Guarantee "C" locale by use of g_ascii_formatd */ - string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val); + /* Guarantee "C" locale by use of g_ascii_formatd */ + string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val); - xmlSetProp (node, (xmlChar *)property, (xmlChar *)string); + xmlSetProp (node, (xmlChar *)property, (xmlChar *)string); } @@ -360,10 +371,10 @@ lgl_xml_set_prop_double (xmlNodePtr node, */ void lgl_xml_set_prop_boolean (xmlNodePtr node, - const gchar *property, - gboolean val) + const gchar *property, + gboolean val) { - xmlSetProp (node, (xmlChar *)property, (xmlChar *)(val ? "True" : "False")); + xmlSetProp (node, (xmlChar *)property, (xmlChar *)(val ? "True" : "False")); } /** @@ -377,14 +388,14 @@ lgl_xml_set_prop_boolean (xmlNodePtr node, */ void lgl_xml_set_prop_int (xmlNodePtr node, - const gchar *property, - gint val) + const gchar *property, + gint val) { - gchar *string; + gchar *string; - string = g_strdup_printf ("%d", val); - xmlSetProp (node, (xmlChar *)property, (xmlChar *)string); - g_free (string); + string = g_strdup_printf ("%d", val); + xmlSetProp (node, (xmlChar *)property, (xmlChar *)string); + g_free (string); } /** @@ -398,14 +409,14 @@ lgl_xml_set_prop_int (xmlNodePtr node, */ void lgl_xml_set_prop_uint_hex (xmlNodePtr node, - const gchar *property, - guint val) + const gchar *property, + guint val) { - gchar *string; + gchar *string; - string = g_strdup_printf ("0x%08x", val); - xmlSetProp (node, (xmlChar *)property, (xmlChar *)string); - g_free (string); + string = g_strdup_printf ("0x%08x", val); + xmlSetProp (node, (xmlChar *)property, (xmlChar *)string); + g_free (string); } /** @@ -422,20 +433,20 @@ lgl_xml_set_prop_uint_hex (xmlNodePtr node, */ void lgl_xml_set_prop_length (xmlNodePtr node, - const gchar *property, - gdouble val) + const gchar *property, + gdouble val) { - gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE]; - gchar *string_unit; + gchar *string, buffer[G_ASCII_DTOSTR_BUF_SIZE]; + gchar *string_unit; - /* Convert to default units */ - val *= lgl_units_get_units_per_point (default_units); + /* Convert to default units */ + val *= lgl_units_get_units_per_point (default_units); - /* Guarantee "C" locale by use of g_ascii_formatd */ - string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val); + /* Guarantee "C" locale by use of g_ascii_formatd */ + string = g_ascii_formatd (buffer, G_ASCII_DTOSTR_BUF_SIZE, "%g", val); - string_unit = g_strdup_printf ("%s%s", string, lgl_units_get_id (default_units)); - xmlSetProp (node, (xmlChar *)property, (xmlChar *)string_unit); + string_unit = g_strdup_printf ("%s%s", string, lgl_units_get_id (default_units)); + xmlSetProp (node, (xmlChar *)property, (xmlChar *)string_unit); g_free (string_unit); } @@ -451,9 +462,9 @@ lgl_xml_set_prop_length (xmlNodePtr node, */ gboolean lgl_xml_is_node (xmlNodePtr node, - const gchar *name) + const gchar *name) { - return xmlStrEqual (node->name, (xmlChar *)name); + return xmlStrEqual (node->name, (xmlChar *)name); } @@ -469,20 +480,19 @@ lgl_xml_is_node (xmlNodePtr node, gchar * lgl_xml_get_node_content (xmlNodePtr node) { - xmlChar *xml_content; - gchar *g_content; - - xml_content = xmlNodeGetContent (node); - - if (xml_content != NULL) { + xmlChar *xml_content; + gchar *g_content; - g_content = g_strdup ((gchar *)xml_content); - xmlFree (xml_content); - return g_content; + xml_content = xmlNodeGetContent (node); - } + if (xml_content != NULL) + { + g_content = g_strdup ((gchar *)xml_content); + xmlFree (xml_content); + return g_content; + } - return NULL; + return NULL; } @@ -497,9 +507,9 @@ lgl_xml_get_node_content (xmlNodePtr node) void lgl_xml_set_default_units (lglUnits units) { - g_return_if_fail ((units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST)); + g_return_if_fail ((units >= LGL_UNITS_FIRST) && (units <= LGL_UNITS_LAST)); - default_units = units; + default_units = units; } diff --git a/libglabels/lgl-xml.h b/libglabels/lgl-xml.h index 8bae2431..c4ed693b 100644 --- a/libglabels/lgl-xml.h +++ b/libglabels/lgl-xml.h @@ -34,66 +34,66 @@ G_BEGIN_DECLS * Get property functions */ gchar * lgl_xml_get_prop_string (xmlNodePtr node, - const gchar *property, - const gchar *default_val); + const gchar *property, + const gchar *default_val); gchar * lgl_xml_get_prop_i18n_string (xmlNodePtr node, - const gchar *property, - const gchar *default_val); + const gchar *property, + const gchar *default_val); gdouble lgl_xml_get_prop_double (xmlNodePtr node, - const gchar *property, - gdouble default_val); + const gchar *property, + gdouble default_val); gboolean lgl_xml_get_prop_boolean (xmlNodePtr node, - const gchar *property, - gboolean default_val); + const gchar *property, + gboolean default_val); gint lgl_xml_get_prop_int (xmlNodePtr node, - const gchar *property, - gint default_val); + const gchar *property, + gint default_val); guint lgl_xml_get_prop_uint (xmlNodePtr node, - const gchar *property, - guint default_val); + const gchar *property, + guint default_val); gdouble lgl_xml_get_prop_length (xmlNodePtr node, - const gchar *property, - gdouble default_val); + const gchar *property, + gdouble default_val); /* * Set property functions */ void lgl_xml_set_prop_string (xmlNodePtr node, - const gchar *property, - const gchar *val); + const gchar *property, + const gchar *val); void lgl_xml_set_prop_double (xmlNodePtr node, - const gchar *property, - gdouble val); + const gchar *property, + gdouble val); void lgl_xml_set_prop_boolean (xmlNodePtr node, - const gchar *property, - gboolean val); + const gchar *property, + gboolean val); void lgl_xml_set_prop_int (xmlNodePtr node, - const gchar *property, - gint val); + const gchar *property, + gint val); void lgl_xml_set_prop_uint_hex (xmlNodePtr node, - const gchar *property, - guint val); + const gchar *property, + guint val); void lgl_xml_set_prop_length (xmlNodePtr node, - const gchar *property, - gdouble val); + const gchar *property, + gdouble val); /* * Other node functions */ gboolean lgl_xml_is_node (xmlNodePtr node, - const gchar *name); + const gchar *name); gchar * lgl_xml_get_node_content (xmlNodePtr node);