From 94f1a410a3d257124c3131b41ccaa883ccabb9c3 Mon Sep 17 00:00:00 2001 From: Dodji Seketeli Date: Sun, 7 Mar 2004 13:22:49 +0000 Subject: re-indented the source files to make'em comply with gnome indentation 2004-03-07 Dodji Seketeli * src/*.c: re-indented the source files to make'em comply with gnome indentation rules. * libcroco-indent: added this indentation script. --- ChangeLog | 6 + libcroco-indent | 102 + src/cr-additional-sel.c | 399 ++-- src/cr-attr-sel.c | 187 +- src/cr-cascade.c | 188 +- src/cr-declaration.c | 1109 +++++----- src/cr-doc-handler.c | 173 +- src/cr-enc-handler.c | 175 +- src/cr-fonts.c | 708 +++--- src/cr-input.c | 878 ++++---- src/cr-num.c | 224 +- src/cr-om-parser.c | 1327 ++++++------ src/cr-parser.c | 5533 +++++++++++++++++++++-------------------------- src/cr-prop-list.c | 412 ++-- src/cr-pseudo.c | 155 +- src/cr-rgb.c | 607 +++--- src/cr-sel-eng.c | 1993 ++++++++--------- src/cr-selector.c | 347 ++- src/cr-simple-sel.c | 250 +-- src/cr-statement.c | 3183 +++++++++++++-------------- src/cr-style.c | 3352 +++++++++++++--------------- src/cr-stylesheet.c | 101 +- src/cr-term.c | 608 +++--- src/cr-tknzr.c | 3087 ++++++++++++-------------- src/cr-token.c | 578 +++-- src/cr-utils.c | 1792 +++++++-------- tests/cr-test-utils.c | 42 +- tests/test0-main.c | 184 +- tests/test1-main.c | 178 +- tests/test2-main.c | 737 +++---- tests/test3-main.c | 741 +++---- tests/test4-main.c | 559 +++-- tests/test5-main.c | 291 ++- tests/test6-main.c | 49 +- tests/test7-main.c | 277 ++- 35 files changed, 13837 insertions(+), 16695 deletions(-) create mode 100755 libcroco-indent diff --git a/ChangeLog b/ChangeLog index 57e2767..4df1fef 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2004-03-07 Dodji Seketeli + + * src/*.c: re-indented the source files to make'em comply + with gnome indentation rules. + * libcroco-indent: added this indentation script. + 2004-03-07 Dodji Seketeli * src/cr-style.c: applied a patch from diff --git a/libcroco-indent b/libcroco-indent new file mode 100755 index 0000000..c6477ab --- /dev/null +++ b/libcroco-indent @@ -0,0 +1,102 @@ +#!/bin/sh +#This is just a smallish indent script to indent mlview +#to indent all the sources correctly (before commiting for ex), +#type: +#./indent-mlview src/*.[ch] + +#Here go some explanations of the indent options: +# +#-bad: forces a blank line after every block of declaration +#============================================================= +#-bap: forces a blank line after every procedure body +#============================================================= +#-bbb: forces a blank line before every boxed comment. +#============================================================= +#-sob: forces indent to swallow every optional blank line. +#============================================================= +#-bl -bli2 formats braces like this: +#if (x > 2) +# { +# x-- ; +# } +#============================================================= +#-nce formats the "else" not to cudle up to the +#immediately preceding }: +#if (x > 2) +# { +# x-- ; +# } +#else +# { +# x++ ; +# } +#============================== +#-ce is the contrary of -nce +#============================================================= +#-ss: put a space before a semi colon that is at the same line as a +#for. +#============================================================= +#-pcs: puts a space between the name of a procedure being called +#and the '('. +#============================================================= +#-bs: puts a space between the sizeof operator and its argument. +#============================================================= +#-saf: puts a space between a for an the following parenthesis. +#============================================================= +#-sai: puts a space between an if and its arguments +#============================================================= +#-saw: puts a space between a while and its arguments +#============================================================= +#-psl: causes the type of a procedure being defined to be placed +#on the line before the name of the procedure. +#============================================================= +#-bls: formats braces in struct declarations like this: +#struct foo +#{ +# int x; +#}; +#-brs: formats braces in struct decls like this: +#struct foo { +# int x; +#}; +#============================================================= +#-bc: forces a newline after each comma in a declaration. +#============================================================= +#-i2: puts indentation at 2 blank chars. +#============================================================= +#-lp: +#without -lp the code looks like this: +#p1 = first_procedure (second_procedure (p2, p3), +# third_procedure (p4, p5)); +#with -lp the code looks like this: +#p1 = first_procedure (second_procedure (p2, p3), +# third_procedure (p4, p5)); +#============================================================= +#-ppi2: indents preprocessor directives using 2 spaces. +#============================================================= +#============================================================= +#-ts2:set tabs spaces to 2 blank chars. +#============================================================= +#-l60 == --line-length60 +#============================================================= +#-bbo: break long lines before boolean operators when found. +#============================================================= + +INDENT=`which indent` +GREP=`which grep` +if test x$INDENT = x ; then + echo "Argh !!! Could not find indent in your PATH. Exited." + exit -1 + if test x$GREP = x ; then + echo "Argh!!! Could not find grep in you PATH. Exited." + exit -1 ; + fi + is_gnu=`$INDENT -version | $GREP gnu` + if test x$is_gnu = x ; then + echo "Found a indent that is not the GNU one. Exited." + exit -1 ; + fi +fi + +exec $INDENT -bad -bap -nbbb -br -ce -ss -pcs -bs -saf -sai \ +-cdw -saw -psl -brs -bc -i8 -ppi0 -lp -ts0 -bbo -sob $@ diff --git a/src/cr-additional-sel.c b/src/cr-additional-sel.c index 53e0f8f..c1fe960 100644 --- a/src/cr-additional-sel.c +++ b/src/cr-additional-sel.c @@ -34,22 +34,20 @@ CRAdditionalSel * cr_additional_sel_new (void) { - CRAdditionalSel *result = NULL ; + CRAdditionalSel *result = NULL; - result = g_try_malloc (sizeof (CRAdditionalSel)) ; + result = g_try_malloc (sizeof (CRAdditionalSel)); - if (result == NULL) - { - cr_utils_trace_debug ("Out of memory") ; - return NULL ; - } + if (result == NULL) { + cr_utils_trace_debug ("Out of memory"); + return NULL; + } - memset (result, 0, sizeof (CRAdditionalSel)) ; + memset (result, 0, sizeof (CRAdditionalSel)); - return result ; + return result; } - /** *Constructor of #CRAdditionalSel. *@param a_sel_type the type of the newly built instance @@ -59,15 +57,15 @@ cr_additional_sel_new (void) CRAdditionalSel * cr_additional_sel_new_with_type (enum AddSelectorType a_sel_type) { - CRAdditionalSel * result = NULL ; + CRAdditionalSel *result = NULL; - result = cr_additional_sel_new () ; + result = cr_additional_sel_new (); - g_return_val_if_fail (result, NULL) ; + g_return_val_if_fail (result, NULL); - result->type = a_sel_type ; + result->type = a_sel_type; - return result ; + return result; } /** @@ -79,18 +77,16 @@ cr_additional_sel_new_with_type (enum AddSelectorType a_sel_type) * */ void -cr_additional_sel_set_class_name (CRAdditionalSel *a_this, - GString *a_class_name) +cr_additional_sel_set_class_name (CRAdditionalSel * a_this, + GString * a_class_name) { - g_return_if_fail (a_this - && a_this->type == CLASS_ADD_SELECTOR) ; - - if (a_this->content.class_name) - { - g_string_free (a_this->content.class_name, TRUE) ; - } - - a_this->content.class_name = a_class_name ; + g_return_if_fail (a_this && a_this->type == CLASS_ADD_SELECTOR); + + if (a_this->content.class_name) { + g_string_free (a_this->content.class_name, TRUE); + } + + a_this->content.class_name = a_class_name; } /** @@ -101,18 +97,15 @@ cr_additional_sel_set_class_name (CRAdditionalSel *a_this, *@param a_id the new id to set. */ void -cr_additional_sel_set_id_name (CRAdditionalSel *a_this, - GString *a_id) +cr_additional_sel_set_id_name (CRAdditionalSel * a_this, GString * a_id) { - g_return_if_fail (a_this - && a_this->type == ID_ADD_SELECTOR) ; - - if (a_this->content.id_name) - { - g_string_free (a_this->content.id_name, TRUE) ; - } - - a_this->content.id_name = a_id ; + g_return_if_fail (a_this && a_this->type == ID_ADD_SELECTOR); + + if (a_this->content.id_name) { + g_string_free (a_this->content.id_name, TRUE); + } + + a_this->content.id_name = a_id; } /** @@ -123,18 +116,16 @@ cr_additional_sel_set_id_name (CRAdditionalSel *a_this, *@param a_pseudo the new pseudo to set. */ void -cr_additional_sel_set_pseudo (CRAdditionalSel *a_this, - CRPseudo *a_pseudo) +cr_additional_sel_set_pseudo (CRAdditionalSel * a_this, CRPseudo * a_pseudo) { - g_return_if_fail (a_this - && a_this->type == PSEUDO_CLASS_ADD_SELECTOR) ; + g_return_if_fail (a_this + && a_this->type == PSEUDO_CLASS_ADD_SELECTOR); - if (a_this->content.pseudo) - { - cr_pseudo_destroy (a_this->content.pseudo) ; - } + if (a_this->content.pseudo) { + cr_pseudo_destroy (a_this->content.pseudo); + } - a_this->content.pseudo = a_pseudo ; + a_this->content.pseudo = a_pseudo; } /** @@ -145,18 +136,15 @@ cr_additional_sel_set_pseudo (CRAdditionalSel *a_this, *@param a_sel the new instance of #CRAttrSel to set. */ void -cr_additional_sel_set_attr_sel (CRAdditionalSel *a_this, - CRAttrSel *a_sel) +cr_additional_sel_set_attr_sel (CRAdditionalSel * a_this, CRAttrSel * a_sel) { - g_return_if_fail (a_this - && a_this->type == ATTRIBUTE_ADD_SELECTOR) ; - - if (a_this->content.attr_sel) - { - cr_attr_sel_destroy (a_this->content.attr_sel) ; - } - - a_this->content.attr_sel = a_sel ; + g_return_if_fail (a_this && a_this->type == ATTRIBUTE_ADD_SELECTOR); + + if (a_this->content.attr_sel) { + cr_attr_sel_destroy (a_this->content.attr_sel); + } + + a_this->content.attr_sel = a_sel; } /** @@ -168,31 +156,28 @@ cr_additional_sel_set_attr_sel (CRAdditionalSel *a_this, *@return the new list of CRAdditionalSel or NULL if an error arises. */ CRAdditionalSel * -cr_additional_sel_append (CRAdditionalSel *a_this, - CRAdditionalSel *a_sel) +cr_additional_sel_append (CRAdditionalSel * a_this, CRAdditionalSel * a_sel) { - CRAdditionalSel *cur_sel = NULL ; + CRAdditionalSel *cur_sel = NULL; + + g_return_val_if_fail (a_sel, NULL); + + if (a_this == NULL) { + return a_sel; + } - g_return_val_if_fail (a_sel, NULL) ; + if (a_sel == NULL) + return NULL; - if (a_this == NULL) - { - return a_sel ; - } + for (cur_sel = a_this; + cur_sel && cur_sel->next; cur_sel = cur_sel->next) ; - if (a_sel == NULL) - return NULL ; - - for (cur_sel = a_this ; - cur_sel && cur_sel->next ; - cur_sel = cur_sel->next) ; + g_return_val_if_fail (cur_sel != NULL, NULL); - g_return_val_if_fail (cur_sel != NULL, NULL) ; + cur_sel->next = a_sel; + a_sel->prev = cur_sel; - cur_sel->next = a_sel ; - a_sel->prev = cur_sel ; - - return a_this ; + return a_this; } /** @@ -204,131 +189,121 @@ cr_additional_sel_append (CRAdditionalSel *a_this, *@return the new list of CRAdditionalSel or NULL if an error arises. */ CRAdditionalSel * -cr_additional_sel_prepend (CRAdditionalSel *a_this, - CRAdditionalSel *a_sel) +cr_additional_sel_prepend (CRAdditionalSel * a_this, CRAdditionalSel * a_sel) { - g_return_val_if_fail (a_sel, NULL) ; + g_return_val_if_fail (a_sel, NULL); - if (a_this == NULL) - { - return a_sel ; - } + if (a_this == NULL) { + return a_sel; + } - a_sel->next = a_this ; - a_this->prev = a_sel ; + a_sel->next = a_this; + a_this->prev = a_sel; - return a_sel ; + return a_sel; } - guchar * -cr_additional_sel_to_string (CRAdditionalSel *a_this) +cr_additional_sel_to_string (CRAdditionalSel * a_this) { - guchar * result = NULL ; - GString * str_buf = NULL ; - CRAdditionalSel *cur = NULL ; + guchar *result = NULL; + GString *str_buf = NULL; + CRAdditionalSel *cur = NULL; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - str_buf = g_string_new (NULL) ; + str_buf = g_string_new (NULL); - for (cur = a_this ;cur ; cur = cur->next) - { - switch (cur->type) - { + for (cur = a_this; cur; cur = cur->next) { + switch (cur->type) { case CLASS_ADD_SELECTOR: - { - guchar * name = NULL ; - if (cur->content.class_name) { - name = g_strndup - (cur->content.class_name->str, - cur->content.class_name->len); - - if (name) - { - g_string_append_printf - (str_buf, ".%s", name) ; - g_free (name) ; - name = NULL ; + guchar *name = NULL; + + if (cur->content.class_name) { + name = g_strndup + (cur->content.class_name->str, + cur->content.class_name-> + len); + + if (name) { + g_string_append_printf + (str_buf, ".%s", + name); + g_free (name); + name = NULL; + } } } - } - break ; + break; case ID_ADD_SELECTOR: - { - guchar * name = NULL ; - if (cur->content.class_name) { - name = g_strndup - (cur->content.id_name->str, - cur->content.id_name->len); - - if (name) - { - g_string_append_printf - (str_buf, "#%s", name) ; - g_free (name) ; - name = NULL ; + guchar *name = NULL; + + if (cur->content.class_name) { + name = g_strndup + (cur->content.id_name->str, + cur->content.id_name->len); + + if (name) { + g_string_append_printf + (str_buf, "#%s", + name); + g_free (name); + name = NULL; + } } } - } - - break ; + + break; case PSEUDO_CLASS_ADD_SELECTOR: - { - if (cur->content.pseudo) { - guchar *tmp_str = NULL ; - - tmp_str = cr_pseudo_to_string - (cur->content.pseudo) ; - if (tmp_str) - { - g_string_append_printf - (str_buf, ":%s", - tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + if (cur->content.pseudo) { + guchar *tmp_str = NULL; + + tmp_str = cr_pseudo_to_string + (cur->content.pseudo); + if (tmp_str) { + g_string_append_printf + (str_buf, ":%s", + tmp_str); + g_free (tmp_str); + tmp_str = NULL; + } } } - } - break ; - + break; + case ATTRIBUTE_ADD_SELECTOR: - if (cur->content.attr_sel) - { - guchar *tmp_str = NULL ; - - g_string_append_printf (str_buf,"[") ; - tmp_str = cr_attr_sel_to_string - (cur->content.attr_sel) ; - if (tmp_str) - { - g_string_append_printf - (str_buf, "%s]", - tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + if (cur->content.attr_sel) { + guchar *tmp_str = NULL; + + g_string_append_printf (str_buf, "["); + tmp_str = cr_attr_sel_to_string + (cur->content.attr_sel); + if (tmp_str) { + g_string_append_printf + (str_buf, "%s]", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } } - break ; + break; default: - break ; + break; } } - if (str_buf) - { - result = str_buf->str ; - g_string_free (str_buf, FALSE) ; - str_buf = NULL ; + if (str_buf) { + result = str_buf->str; + g_string_free (str_buf, FALSE); + str_buf = NULL; } - return result ; + return result; } /** @@ -338,20 +313,18 @@ cr_additional_sel_to_string (CRAdditionalSel *a_this) *@param a_fp the destination file. */ void -cr_additional_sel_dump (CRAdditionalSel *a_this, FILE *a_fp) +cr_additional_sel_dump (CRAdditionalSel * a_this, FILE * a_fp) { - guchar *tmp_str = NULL ; - - g_return_if_fail (a_fp) ; - - if (a_this) - { - tmp_str = cr_additional_sel_to_string (a_this) ; - if (tmp_str) - { - fprintf (a_fp, "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + guchar *tmp_str = NULL; + + g_return_if_fail (a_fp); + + if (a_this) { + tmp_str = cr_additional_sel_to_string (a_this); + if (tmp_str) { + fprintf (a_fp, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } } } @@ -362,40 +335,38 @@ cr_additional_sel_dump (CRAdditionalSel *a_this, FILE *a_fp) *of #CRAdditionalSel . */ void -cr_additional_sel_destroy (CRAdditionalSel *a_this) +cr_additional_sel_destroy (CRAdditionalSel * a_this) { - g_return_if_fail (a_this) ; - - switch (a_this->type) - { - case CLASS_ADD_SELECTOR: - g_string_free (a_this->content.class_name, TRUE) ; - a_this->content.class_name = NULL ; - break ; - - case PSEUDO_CLASS_ADD_SELECTOR: - cr_pseudo_destroy (a_this->content.pseudo) ; - a_this->content.pseudo = NULL ; - break ; - - case ID_ADD_SELECTOR: - g_string_free (a_this->content.id_name, TRUE) ; - a_this->content.id_name = NULL ; - break ; - - case ATTRIBUTE_ADD_SELECTOR: - cr_attr_sel_destroy (a_this->content.attr_sel) ; - a_this->content.attr_sel = NULL ; - break ; - - default : - break ; - } - - if (a_this->next) - { - cr_additional_sel_destroy (a_this->next) ; - } - - g_free (a_this) ; + g_return_if_fail (a_this); + + switch (a_this->type) { + case CLASS_ADD_SELECTOR: + g_string_free (a_this->content.class_name, TRUE); + a_this->content.class_name = NULL; + break; + + case PSEUDO_CLASS_ADD_SELECTOR: + cr_pseudo_destroy (a_this->content.pseudo); + a_this->content.pseudo = NULL; + break; + + case ID_ADD_SELECTOR: + g_string_free (a_this->content.id_name, TRUE); + a_this->content.id_name = NULL; + break; + + case ATTRIBUTE_ADD_SELECTOR: + cr_attr_sel_destroy (a_this->content.attr_sel); + a_this->content.attr_sel = NULL; + break; + + default: + break; + } + + if (a_this->next) { + cr_additional_sel_destroy (a_this->next); + } + + g_free (a_this); } diff --git a/src/cr-attr-sel.c b/src/cr-attr-sel.c index 9c1f2e6..4deb63c 100644 --- a/src/cr-attr-sel.c +++ b/src/cr-attr-sel.c @@ -35,7 +35,6 @@ *css2 spec [5] . */ - /** *The constructor of #CRAttrSel. *@return the newly allocated instance @@ -44,10 +43,11 @@ CRAttrSel * cr_attr_sel_new (void) { - CRAttrSel *result = NULL ; - result = g_malloc0 (sizeof (CRAttrSel)) ; + CRAttrSel *result = NULL; + + result = g_malloc0 (sizeof (CRAttrSel)); - return result ; + return result; } /** @@ -60,19 +60,18 @@ cr_attr_sel_new (void) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_attr_sel_append_attr_sel (CRAttrSel *a_this, CRAttrSel *a_attr_sel) +cr_attr_sel_append_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel) { - CRAttrSel * cur_sel = NULL ; - - g_return_val_if_fail (a_this && a_attr_sel, - CR_BAD_PARAM_ERROR) ; - - for (cur_sel = a_this ; cur_sel->next ; cur_sel = cur_sel->next) ; - - cur_sel->next = a_attr_sel ; - a_attr_sel->prev = cur_sel ; - - return CR_OK ; + CRAttrSel *cur_sel = NULL; + + g_return_val_if_fail (a_this && a_attr_sel, CR_BAD_PARAM_ERROR); + + for (cur_sel = a_this; cur_sel->next; cur_sel = cur_sel->next) ; + + cur_sel->next = a_attr_sel; + a_attr_sel->prev = cur_sel; + + return CR_OK; } /** @@ -85,97 +84,85 @@ cr_attr_sel_append_attr_sel (CRAttrSel *a_this, CRAttrSel *a_attr_sel) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_attr_sel_prepend_attr_sel (CRAttrSel *a_this, CRAttrSel *a_attr_sel) +cr_attr_sel_prepend_attr_sel (CRAttrSel * a_this, CRAttrSel * a_attr_sel) { g_return_val_if_fail (a_this && a_attr_sel, CR_BAD_PARAM_ERROR); - a_attr_sel->next = a_this ; - a_this->prev = a_attr_sel ; + a_attr_sel->next = a_this; + a_this->prev = a_attr_sel; - return CR_OK ; + return CR_OK; } guchar * -cr_attr_sel_to_string (CRAttrSel *a_this) +cr_attr_sel_to_string (CRAttrSel * a_this) { - CRAttrSel *cur = NULL ; - guchar * result = NULL ; - GString *str_buf = NULL ; + CRAttrSel *cur = NULL; + guchar *result = NULL; + GString *str_buf = NULL; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - str_buf = g_string_new (NULL) ; + str_buf = g_string_new (NULL); - for (cur = a_this ; cur ; cur = cur->next) - { - if (cur->prev) - { - g_string_append_printf (str_buf," ") ; + for (cur = a_this; cur; cur = cur->next) { + if (cur->prev) { + g_string_append_printf (str_buf, " "); } - if (cur->name) - { - guchar *name = NULL ; - - name = g_strndup (cur->name->str, - cur->name->len) ; - if (name) - { - g_string_append_printf (str_buf, - "%s", name) ; - g_free (name) ; - name = NULL ; + if (cur->name) { + guchar *name = NULL; + + name = g_strndup (cur->name->str, cur->name->len); + if (name) { + g_string_append_printf (str_buf, "%s", name); + g_free (name); + name = NULL; } } - - if (cur->value) - { - guchar *value = NULL ; - - value = g_strndup (cur->value->str, - cur->value->len) ; - if (value) - { - switch (cur->match_way) - { + + if (cur->value) { + guchar *value = NULL; + + value = g_strndup (cur->value->str, cur->value->len); + if (value) { + switch (cur->match_way) { case SET: - break ; + break; case EQUALS: - g_string_append_printf - (str_buf,"=") ; - break ; + g_string_append_printf (str_buf, "="); + break; case INCLUDES: - g_string_append_printf - (str_buf,"~=") ; - break ; + g_string_append_printf + (str_buf, "~="); + break; case DASHMATCH: - g_string_append_printf - (str_buf,"|=") ; - break ; + g_string_append_printf + (str_buf, "|="); + break; default: - break ; + break; } - - g_string_append_printf - (str_buf,"\"%s\"",value) ; - g_free (value) ; - value = NULL ; + g_string_append_printf + (str_buf, "\"%s\"", value); + + g_free (value); + value = NULL; } } } - if (str_buf) - { - result = str_buf->str ; - g_string_free (str_buf, FALSE) ; + if (str_buf) { + result = str_buf->str; + g_string_free (str_buf, FALSE); } - return result ; + return result; } /** @@ -185,23 +172,21 @@ cr_attr_sel_to_string (CRAttrSel *a_this) *@param a_fp the destination file. */ void -cr_attr_sel_dump (CRAttrSel *a_this, FILE *a_fp) +cr_attr_sel_dump (CRAttrSel * a_this, FILE * a_fp) { - guchar * tmp_str = NULL ; + guchar *tmp_str = NULL; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - tmp_str = cr_attr_sel_to_string (a_this) ; + tmp_str = cr_attr_sel_to_string (a_this); - if (tmp_str) - { - fprintf (a_fp, "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + if (tmp_str) { + fprintf (a_fp, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } } - /** *Destroys the current instance of #CRAttrSel. *Frees all the fields if they are non null. @@ -209,31 +194,27 @@ cr_attr_sel_dump (CRAttrSel *a_this, FILE *a_fp) *instance of #CRAttrSel. */ void -cr_attr_sel_destroy (CRAttrSel *a_this) +cr_attr_sel_destroy (CRAttrSel * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - if (a_this->name) - { - g_string_free (a_this->name, TRUE) ; - a_this->name = NULL ; + if (a_this->name) { + g_string_free (a_this->name, TRUE); + a_this->name = NULL; } - if (a_this->value) - { - g_string_free (a_this->value, TRUE) ; - a_this->value = NULL ; + if (a_this->value) { + g_string_free (a_this->value, TRUE); + a_this->value = NULL; } - if (a_this->next) - { - cr_attr_sel_destroy (a_this->next) ; - a_this->next = NULL ; + if (a_this->next) { + cr_attr_sel_destroy (a_this->next); + a_this->next = NULL; } - if (a_this) - { - g_free (a_this) ; - a_this = NULL ; + if (a_this) { + g_free (a_this); + a_this = NULL; } } diff --git a/src/cr-cascade.c b/src/cr-cascade.c index a9b579b..ccb32c2 100644 --- a/src/cr-cascade.c +++ b/src/cr-cascade.c @@ -31,19 +31,17 @@ #define PRIVATE(a_this) ((a_this)->priv) -struct _CRCascadePriv -{ - /** +struct _CRCascadePriv { + /** *the 3 style sheets of the cascade: *author, user, and useragent sheet. *Intended to be addressed by *sheets[ORIGIN_AUTHOR] or sheets[ORIGIN_USER] *of sheets[ORIGIN_UA] ; */ - CRStyleSheet *sheets[3] ; - guint ref_count ; -} ; - + CRStyleSheet *sheets[3]; + guint ref_count; +}; /** *Constructor of the #CRCascade class. @@ -60,45 +58,36 @@ struct _CRCascadePriv *an error arose during constrution. */ CRCascade * -cr_cascade_new (CRStyleSheet *a_author_sheet, - CRStyleSheet *a_user_sheet, - CRStyleSheet *a_ua_sheet) +cr_cascade_new (CRStyleSheet * a_author_sheet, + CRStyleSheet * a_user_sheet, CRStyleSheet * a_ua_sheet) { - CRCascade *result = NULL ; - - result = g_try_malloc (sizeof (CRCascade)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRCascade)) ; - - PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv)) ; - if (!PRIVATE (result)) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (PRIVATE (result), 0, sizeof (CRCascadePriv)) ; - - if (a_author_sheet) - { - cr_cascade_set_sheet (result, a_author_sheet, - ORIGIN_AUTHOR) ; - } - if (a_user_sheet) - { - cr_cascade_set_sheet (result, a_user_sheet, - ORIGIN_USER) ; - } - if (a_ua_sheet) - { - cr_cascade_set_sheet (result, a_ua_sheet, - ORIGIN_UA) ; - } - - return result ; + CRCascade *result = NULL; + + result = g_try_malloc (sizeof (CRCascade)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + memset (result, 0, sizeof (CRCascade)); + + PRIVATE (result) = g_try_malloc (sizeof (CRCascadePriv)); + if (!PRIVATE (result)) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + memset (PRIVATE (result), 0, sizeof (CRCascadePriv)); + + if (a_author_sheet) { + cr_cascade_set_sheet (result, a_author_sheet, ORIGIN_AUTHOR); + } + if (a_user_sheet) { + cr_cascade_set_sheet (result, a_user_sheet, ORIGIN_USER); + } + if (a_ua_sheet) { + cr_cascade_set_sheet (result, a_ua_sheet, ORIGIN_UA); + } + + return result; } /** @@ -115,18 +104,15 @@ cr_cascade_new (CRStyleSheet *a_author_sheet, *exist. */ CRStyleSheet * -cr_cascade_get_sheet (CRCascade *a_this, - enum CRStyleOrigin a_origin) +cr_cascade_get_sheet (CRCascade * a_this, enum CRStyleOrigin a_origin) { - g_return_val_if_fail (a_this - && a_origin >= ORIGIN_UA - && a_origin < NB_ORIGINS, - NULL) ; + g_return_val_if_fail (a_this + && a_origin >= ORIGIN_UA + && a_origin < NB_ORIGINS, NULL); - return PRIVATE (a_this)->sheets[a_origin] ; + return PRIVATE (a_this)->sheets[a_origin]; } - /** *Sets a stylesheet in the cascade *@param a_this the current instance of #CRCascade. @@ -136,23 +122,20 @@ cr_cascade_get_sheet (CRCascade *a_this, *code otherwise. */ enum CRStatus -cr_cascade_set_sheet (CRCascade *a_this, - CRStyleSheet *a_sheet, - enum CRStyleOrigin a_origin) +cr_cascade_set_sheet (CRCascade * a_this, + CRStyleSheet * a_sheet, enum CRStyleOrigin a_origin) { - g_return_val_if_fail (a_this - && a_sheet - && a_origin >= ORIGIN_UA - && a_origin < NB_ORIGINS, - CR_BAD_PARAM_ERROR) ; - - if (PRIVATE (a_this)->sheets[a_origin]) - cr_stylesheet_unref - (PRIVATE (a_this)->sheets[a_origin]) ; - PRIVATE (a_this)->sheets[a_origin] = a_sheet ; - cr_stylesheet_ref (a_sheet) ; - a_sheet->origin = a_origin ; - return CR_OK ; + g_return_val_if_fail (a_this + && a_sheet + && a_origin >= ORIGIN_UA + && a_origin < NB_ORIGINS, CR_BAD_PARAM_ERROR); + + if (PRIVATE (a_this)->sheets[a_origin]) + cr_stylesheet_unref (PRIVATE (a_this)->sheets[a_origin]); + PRIVATE (a_this)->sheets[a_origin] = a_sheet; + cr_stylesheet_ref (a_sheet); + a_sheet->origin = a_origin; + return CR_OK; } /** @@ -162,11 +145,11 @@ cr_cascade_set_sheet (CRCascade *a_this, * */ void -cr_cascade_ref (CRCascade *a_this) +cr_cascade_ref (CRCascade * a_this) { - g_return_if_fail (a_this && PRIVATE (a_this)) ; - - PRIVATE (a_this)->ref_count++ ; + g_return_if_fail (a_this && PRIVATE (a_this)); + + PRIVATE (a_this)->ref_count++; } /** @@ -177,16 +160,15 @@ cr_cascade_ref (CRCascade *a_this) *@param a_this the current instance of *#CRCascade. */ -void -cr_cascade_unref (CRCascade *a_this) +void +cr_cascade_unref (CRCascade * a_this) { - g_return_if_fail (a_this && PRIVATE (a_this)) ; + g_return_if_fail (a_this && PRIVATE (a_this)); if (PRIVATE (a_this)->ref_count) - PRIVATE (a_this)->ref_count -- ; - if (!PRIVATE (a_this)->ref_count) - { - cr_cascade_destroy (a_this) ; + PRIVATE (a_this)->ref_count--; + if (!PRIVATE (a_this)->ref_count) { + cr_cascade_destroy (a_this); } } @@ -194,32 +176,24 @@ cr_cascade_unref (CRCascade *a_this) *Destructor of #CRCascade. */ void -cr_cascade_destroy (CRCascade *a_this) +cr_cascade_destroy (CRCascade * a_this) { - g_return_if_fail (a_this) ; - - if (PRIVATE (a_this)) - { - gulong i = 0 ; - - for (i = 0 ; - PRIVATE (a_this)->sheets - && i < NB_ORIGINS ; - i++) - { - if (PRIVATE (a_this)->sheets[i]) - { - if (cr_stylesheet_unref - (PRIVATE (a_this)->sheets[i]) - == TRUE) - { - PRIVATE (a_this)->sheets[i] = - NULL ; - } - } - } - g_free (PRIVATE (a_this)) ; - PRIVATE (a_this) = NULL ; - } - g_free (a_this) ; + g_return_if_fail (a_this); + + if (PRIVATE (a_this)) { + gulong i = 0; + + for (i = 0; PRIVATE (a_this)->sheets && i < NB_ORIGINS; i++) { + if (PRIVATE (a_this)->sheets[i]) { + if (cr_stylesheet_unref + (PRIVATE (a_this)->sheets[i]) + == TRUE) { + PRIVATE (a_this)->sheets[i] = NULL; + } + } + } + g_free (PRIVATE (a_this)); + PRIVATE (a_this) = NULL; + } + g_free (a_this); } diff --git a/src/cr-declaration.c b/src/cr-declaration.c index 743e450..2e5986e 100644 --- a/src/cr-declaration.c +++ b/src/cr-declaration.c @@ -41,18 +41,18 @@ *@param a_indent the number of indentation white char. */ static void -dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent) +dump (CRDeclaration * a_this, FILE * a_fp, glong a_indent) { - guchar *str = NULL ; - g_return_if_fail (a_this) ; - - str = cr_declaration_to_string (a_this, a_indent) ; - if (str) - { - fprintf (a_fp,"%s", str) ; - g_free (str) ; - str = NULL ; - } + guchar *str = NULL; + + g_return_if_fail (a_this); + + str = cr_declaration_to_string (a_this, a_indent); + if (str) { + fprintf (a_fp, "%s", str); + g_free (str); + str = NULL; + } } /** @@ -63,43 +63,37 @@ dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent) *case of error. */ CRDeclaration * -cr_declaration_new (CRStatement *a_statement, - GString *a_property, - CRTerm *a_value) +cr_declaration_new (CRStatement * a_statement, + GString * a_property, CRTerm * a_value) { - CRDeclaration *result = NULL ; - - g_return_val_if_fail (a_property, NULL) ; - - if (a_statement) - g_return_val_if_fail (a_statement - && ((a_statement->type - == RULESET_STMT) - || (a_statement->type - == AT_FONT_FACE_RULE_STMT) - || (a_statement->type - == AT_PAGE_RULE_STMT)), - NULL) ; - - result = g_try_malloc (sizeof (CRDeclaration)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRDeclaration)) ; - result->property = a_property ; - result->value = a_value ; - - if (a_value) - { - cr_term_ref (a_value) ; - } - result->parent_statement = a_statement ; - return result ; + CRDeclaration *result = NULL; + + g_return_val_if_fail (a_property, NULL); + + if (a_statement) + g_return_val_if_fail (a_statement + && ((a_statement->type == RULESET_STMT) + || (a_statement->type + == AT_FONT_FACE_RULE_STMT) + || (a_statement->type + == AT_PAGE_RULE_STMT)), NULL); + + result = g_try_malloc (sizeof (CRDeclaration)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + memset (result, 0, sizeof (CRDeclaration)); + result->property = a_property; + result->value = a_value; + + if (a_value) { + cr_term_ref (a_value); + } + result->parent_statement = a_statement; + return result; } - /** *Parses a text buffer that contains *a css declaration. @@ -112,65 +106,58 @@ cr_declaration_new (CRStatement *a_statement, *@return the parsed declaration, or NULL in case of error. */ CRDeclaration * -cr_declaration_parse_from_buf (CRStatement *a_statement, - const guchar *a_str, - enum CREncoding a_enc) +cr_declaration_parse_from_buf (CRStatement * a_statement, + const guchar * a_str, enum CREncoding a_enc) { - enum CRStatus status = CR_OK ; - CRTerm *value = NULL ; - GString *property = NULL; - CRDeclaration *result = NULL ; - CRParser * parser = NULL ; - gboolean important = FALSE ; - - g_return_val_if_fail (a_str, NULL) ; - if (a_statement) - g_return_val_if_fail (a_statement->type == RULESET_STMT, - NULL); - - parser = cr_parser_new_from_buf (a_str, - strlen (a_str), - a_enc, FALSE) ; - g_return_val_if_fail (parser, NULL) ; - - status = cr_parser_try_to_skip_spaces_and_comments (parser) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_parser_parse_declaration (parser, &property, - &value, &important) ; - if (status != CR_OK || !property) - goto cleanup ; - - result = cr_declaration_new (a_statement, property, value) ; - if (result) - { - property = NULL ; - value = NULL ; - result->important = important ; - } - - cleanup: - - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; - } - - if (value) - { - cr_term_destroy (value) ; - value = NULL ; - } - - return result ; + enum CRStatus status = CR_OK; + CRTerm *value = NULL; + GString *property = NULL; + CRDeclaration *result = NULL; + CRParser *parser = NULL; + gboolean important = FALSE; + + g_return_val_if_fail (a_str, NULL); + if (a_statement) + g_return_val_if_fail (a_statement->type == RULESET_STMT, + NULL); + + parser = cr_parser_new_from_buf (a_str, strlen (a_str), a_enc, FALSE); + g_return_val_if_fail (parser, NULL); + + status = cr_parser_try_to_skip_spaces_and_comments (parser); + if (status != CR_OK) + goto cleanup; + + status = cr_parser_parse_declaration (parser, &property, + &value, &important); + if (status != CR_OK || !property) + goto cleanup; + + result = cr_declaration_new (a_statement, property, value); + if (result) { + property = NULL; + value = NULL; + result->important = important; + } + + cleanup: + + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + + if (property) { + g_string_free (property, TRUE); + property = NULL; + } + + if (value) { + cr_term_destroy (value); + value = NULL; + } + + return result; } /** @@ -181,125 +168,108 @@ cr_declaration_parse_from_buf (CRStatement *a_statement, *@return the parsed list of declaration, NULL if parsing failed. */ CRDeclaration * -cr_declaration_parse_list_from_buf (const guchar *a_str, enum CREncoding a_enc) +cr_declaration_parse_list_from_buf (const guchar * a_str, + enum CREncoding a_enc) { - enum CRStatus status = CR_OK ; - CRTerm *value = NULL ; - GString *property = NULL; - CRDeclaration *result = NULL, *cur_decl = NULL ; - CRParser * parser = NULL ; - CRTknzr *tokenizer = NULL ; - gboolean important = FALSE ; - - g_return_val_if_fail (a_str, NULL) ; - - parser = cr_parser_new_from_buf (a_str, - strlen (a_str), - a_enc, FALSE) ; - g_return_val_if_fail (parser, NULL) ; - status = cr_parser_get_tknzr (parser, &tokenizer) ; - if (status != CR_OK || !tokenizer) - { - if (status == CR_OK) - status = CR_ERROR ; - goto cleanup ; - } - status = cr_parser_try_to_skip_spaces_and_comments (parser) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_parser_parse_declaration (parser, &property, - &value, &important) ; - if (status != CR_OK || !property) - { - if (status != CR_OK) - status = CR_ERROR ; - goto cleanup ; - } - result = cr_declaration_new (NULL, property, value) ; - if (result) - { - property = NULL ; - value = NULL ; - result->important = important ; - } - /*now, go parse the other declarations*/ - for (;;) - { - guint32 c = 0 ; - cr_parser_try_to_skip_spaces_and_comments (parser) ; - status = cr_tknzr_peek_char (tokenizer, &c) ; - if (status != CR_OK) - { - if (status == CR_END_OF_INPUT_ERROR) - status = CR_OK ; - goto cleanup ; - } - if (c == ';') - { - status = cr_tknzr_read_char (tokenizer, &c) ; - } - else - { - break ; - } - important = FALSE ; - cr_parser_try_to_skip_spaces_and_comments (parser) ; - status = cr_parser_parse_declaration (parser, &property, - &value, &important) ; - if (status != CR_OK || !property) - { - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; - } - break ; - } - cur_decl = cr_declaration_new (NULL, property, value) ; - if (cur_decl) - { - cur_decl->important = important ; - result = cr_declaration_append (result, cur_decl) ; - property = NULL ; - value = NULL ; - cur_decl = NULL; - } - else - { - break ; - } - } - - cleanup: - - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; - } - - if (value) - { - cr_term_destroy (value) ; - value = NULL ; - } - - if (status != CR_OK && result) - { - cr_declaration_destroy (result) ; - result = NULL ; - } - return result ; + enum CRStatus status = CR_OK; + CRTerm *value = NULL; + GString *property = NULL; + CRDeclaration *result = NULL, + *cur_decl = NULL; + CRParser *parser = NULL; + CRTknzr *tokenizer = NULL; + gboolean important = FALSE; + + g_return_val_if_fail (a_str, NULL); + + parser = cr_parser_new_from_buf (a_str, strlen (a_str), a_enc, FALSE); + g_return_val_if_fail (parser, NULL); + status = cr_parser_get_tknzr (parser, &tokenizer); + if (status != CR_OK || !tokenizer) { + if (status == CR_OK) + status = CR_ERROR; + goto cleanup; + } + status = cr_parser_try_to_skip_spaces_and_comments (parser); + if (status != CR_OK) + goto cleanup; + + status = cr_parser_parse_declaration (parser, &property, + &value, &important); + if (status != CR_OK || !property) { + if (status != CR_OK) + status = CR_ERROR; + goto cleanup; + } + result = cr_declaration_new (NULL, property, value); + if (result) { + property = NULL; + value = NULL; + result->important = important; + } + /*now, go parse the other declarations */ + for (;;) { + guint32 c = 0; + + cr_parser_try_to_skip_spaces_and_comments (parser); + status = cr_tknzr_peek_char (tokenizer, &c); + if (status != CR_OK) { + if (status == CR_END_OF_INPUT_ERROR) + status = CR_OK; + goto cleanup; + } + if (c == ';') { + status = cr_tknzr_read_char (tokenizer, &c); + } else { + break; + } + important = FALSE; + cr_parser_try_to_skip_spaces_and_comments (parser); + status = cr_parser_parse_declaration (parser, &property, + &value, &important); + if (status != CR_OK || !property) { + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + } + break; + } + cur_decl = cr_declaration_new (NULL, property, value); + if (cur_decl) { + cur_decl->important = important; + result = cr_declaration_append (result, cur_decl); + property = NULL; + value = NULL; + cur_decl = NULL; + } else { + break; + } + } + + cleanup: + + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + + if (property) { + g_string_free (property, TRUE); + property = NULL; + } + + if (value) { + cr_term_destroy (value); + value = NULL; + } + + if (status != CR_OK && result) { + cr_declaration_destroy (result); + result = NULL; + } + return result; } - /** *Appends a new declaration to the current declarations list. *@param a_this the current declaration list. @@ -308,21 +278,21 @@ cr_declaration_parse_list_from_buf (const guchar *a_str, enum CREncoding a_enc) *in case of error. */ CRDeclaration * -cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) +cr_declaration_append (CRDeclaration * a_this, CRDeclaration * a_new) { - CRDeclaration *cur = NULL ; + CRDeclaration *cur = NULL; + + g_return_val_if_fail (a_new, NULL); - g_return_val_if_fail (a_new, NULL) ; + if (!a_this) + return a_new; - if (!a_this) - return a_new ; + for (cur = a_this; cur && cur->next; cur = cur->next) ; - for (cur = a_this ; cur && cur->next ; cur = cur->next) ; - - cur->next = a_new ; - a_new->prev = cur ; + cur->next = a_new; + a_new->prev = cur; - return a_this ; + return a_this; } /** @@ -334,80 +304,70 @@ cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) CRDeclaration * cr_declaration_unlink (CRDeclaration * a_decl) { - CRDeclaration *result = a_decl ; - - g_return_val_if_fail (result, NULL) ; - - /* - *some sanity checks first - */ - if (a_decl->prev) - { - g_return_val_if_fail (a_decl->prev->next == a_decl, NULL) ; - - } - if (a_decl->next) - { - g_return_val_if_fail (a_decl->next->prev == a_decl, NULL) ; - } - - /* - *now, the real unlinking job. - */ - if (a_decl->prev) - { - a_decl->prev->next = a_decl->next ; - } - if (a_decl->next) - { - a_decl->next->prev = a_decl->prev ; - } - if (a_decl->parent_statement) - { - CRDeclaration **children_decl_ptr = NULL ; - switch (a_decl->parent_statement->type) - { - case RULESET_STMT: - if (a_decl->parent_statement->kind.ruleset) - { - children_decl_ptr = - &a_decl->parent_statement-> - kind.ruleset->decl_list ; - } - - break ; - - case AT_FONT_FACE_RULE_STMT: - if (a_decl->parent_statement->kind.font_face_rule) - { - children_decl_ptr = - &a_decl->parent_statement-> - kind.font_face_rule->decl_list ; - } - break ; - case AT_PAGE_RULE_STMT: - if (a_decl->parent_statement->kind.page_rule) - { - children_decl_ptr = - &a_decl->parent_statement-> - kind.page_rule->decl_list ; - } - - default: - break ; - } - if (children_decl_ptr - && *children_decl_ptr - && *children_decl_ptr == a_decl) - *children_decl_ptr = - (*children_decl_ptr)->next ; - } - - a_decl->next = NULL ; - a_decl->prev = NULL ; - a_decl->parent_statement = NULL ; - - return result ; + CRDeclaration *result = a_decl; + + g_return_val_if_fail (result, NULL); + + /* + *some sanity checks first + */ + if (a_decl->prev) { + g_return_val_if_fail (a_decl->prev->next == a_decl, NULL); + + } + if (a_decl->next) { + g_return_val_if_fail (a_decl->next->prev == a_decl, NULL); + } + + /* + *now, the real unlinking job. + */ + if (a_decl->prev) { + a_decl->prev->next = a_decl->next; + } + if (a_decl->next) { + a_decl->next->prev = a_decl->prev; + } + if (a_decl->parent_statement) { + CRDeclaration **children_decl_ptr = NULL; + + switch (a_decl->parent_statement->type) { + case RULESET_STMT: + if (a_decl->parent_statement->kind.ruleset) { + children_decl_ptr = + &a_decl->parent_statement-> + kind.ruleset->decl_list; + } + + break; + + case AT_FONT_FACE_RULE_STMT: + if (a_decl->parent_statement->kind.font_face_rule) { + children_decl_ptr = + &a_decl->parent_statement-> + kind.font_face_rule->decl_list; + } + break; + case AT_PAGE_RULE_STMT: + if (a_decl->parent_statement->kind.page_rule) { + children_decl_ptr = + &a_decl->parent_statement-> + kind.page_rule->decl_list; + } + + default: + break; + } + if (children_decl_ptr + && *children_decl_ptr && *children_decl_ptr == a_decl) + *children_decl_ptr = (*children_decl_ptr)->next; + } + + a_decl->next = NULL; + a_decl->prev = NULL; + a_decl->parent_statement = NULL; + + return result; } /** @@ -417,21 +377,21 @@ cr_declaration_unlink (CRDeclaration * a_decl) *@return the list with a_new prepended or NULL in case of error. */ CRDeclaration * -cr_declaration_prepend (CRDeclaration *a_this, CRDeclaration *a_new) +cr_declaration_prepend (CRDeclaration * a_this, CRDeclaration * a_new) { - CRDeclaration *cur = NULL ; + CRDeclaration *cur = NULL; - g_return_val_if_fail (a_new, NULL) ; + g_return_val_if_fail (a_new, NULL); - if (!a_this) - return a_new ; + if (!a_this) + return a_new; - a_this->prev = a_new ; - a_new->next = a_this ; + a_this->prev = a_new; + a_new->next = a_this; - for (cur = a_new ; cur && cur->prev ; cur = cur->prev) ; + for (cur = a_new; cur && cur->prev; cur = cur->prev) ; - return cur ; + return cur; } /** @@ -443,25 +403,21 @@ cr_declaration_prepend (CRDeclaration *a_this, CRDeclaration *a_new) *case of an error. */ CRDeclaration * -cr_declaration_append2 (CRDeclaration *a_this, - GString *a_prop, - CRTerm *a_value) +cr_declaration_append2 (CRDeclaration * a_this, + GString * a_prop, CRTerm * a_value) { - CRDeclaration *new_elem = NULL ; - - if (a_this) - { - new_elem = cr_declaration_new (a_this->parent_statement, - a_prop, a_value) ; - } - else - { - new_elem = cr_declaration_new (NULL, a_prop, a_value) ; - } - - g_return_val_if_fail (new_elem, NULL) ; - - return cr_declaration_append (a_this, new_elem) ; + CRDeclaration *new_elem = NULL; + + if (a_this) { + new_elem = cr_declaration_new (a_this->parent_statement, + a_prop, a_value); + } else { + new_elem = cr_declaration_new (NULL, a_prop, a_value); + } + + g_return_val_if_fail (new_elem, NULL); + + return cr_declaration_append (a_this, new_elem); } /** @@ -471,24 +427,22 @@ cr_declaration_append2 (CRDeclaration *a_this, *@param a_indent the number of indentation white char. */ void -cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent, - gboolean a_one_per_line) +cr_declaration_dump (CRDeclaration * a_this, FILE * a_fp, glong a_indent, + gboolean a_one_per_line) { - CRDeclaration *cur = NULL ; - - g_return_if_fail (a_this) ; - - for (cur = a_this ; cur ; cur = cur->next) - { - if (cur->prev) - { - if (a_one_per_line == TRUE) - fprintf (a_fp,";\n") ; - else - fprintf (a_fp,"; ") ; - } - dump (cur, a_fp, a_indent) ; - } + CRDeclaration *cur = NULL; + + g_return_if_fail (a_this); + + for (cur = a_this; cur; cur = cur->next) { + if (cur->prev) { + if (a_one_per_line == TRUE) + fprintf (a_fp, ";\n"); + else + fprintf (a_fp, "; "); + } + dump (cur, a_fp, a_indent); + } } /** @@ -498,12 +452,11 @@ cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent, *@param a_indent the number of indentation white char. */ void -cr_declaration_dump_one (CRDeclaration *a_this, - FILE *a_fp, glong a_indent) +cr_declaration_dump_one (CRDeclaration * a_this, FILE * a_fp, glong a_indent) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - dump (a_this, a_fp, a_indent) ; + dump (a_this, a_fp, a_indent); } /** @@ -513,71 +466,61 @@ cr_declaration_dump_one (CRDeclaration *a_this, *to put before the actual serialisation. */ gchar * -cr_declaration_to_string (CRDeclaration *a_this, - gulong a_indent) +cr_declaration_to_string (CRDeclaration * a_this, gulong a_indent) { - GString *stringue = NULL ; - - guchar *str = NULL, *result = NULL ; - g_return_val_if_fail (a_this, NULL) ; - - stringue = g_string_new (NULL) ; - - if (a_this->property && a_this->property->str) - { - str = g_strndup (a_this->property->str, - a_this->property->len) ; - if (str) - { - cr_utils_dump_n_chars2 (' ', stringue, - a_indent) ; - g_string_append_printf (stringue, "%s", - str) ; - g_free (str) ; - str = NULL ; - } - else - goto error ; - - if (a_this->value) - { - guchar *value_str = NULL ; - - value_str = cr_term_to_string (a_this->value) ; - if (value_str) - { - g_string_append_printf (stringue, " : %s", - value_str) ; - g_free (value_str) ; - } - else - goto error ; - } - if (a_this->important == TRUE) - { - g_string_append_printf (stringue, " %s", "!important") ; - } - } - if (stringue && stringue->str) - { - result = stringue->str ; - g_string_free (stringue, FALSE) ; - } - return result ; - - error: - if (stringue) - { - g_string_free (stringue, TRUE) ; - stringue = NULL ; - } - if (str) - { - g_free (str) ; - str = NULL ; - } - - return result ; + GString *stringue = NULL; + + guchar *str = NULL, + *result = NULL; + + g_return_val_if_fail (a_this, NULL); + + stringue = g_string_new (NULL); + + if (a_this->property && a_this->property->str) { + str = g_strndup (a_this->property->str, + a_this->property->len); + if (str) { + cr_utils_dump_n_chars2 (' ', stringue, a_indent); + g_string_append_printf (stringue, "%s", str); + g_free (str); + str = NULL; + } else + goto error; + + if (a_this->value) { + guchar *value_str = NULL; + + value_str = cr_term_to_string (a_this->value); + if (value_str) { + g_string_append_printf (stringue, " : %s", + value_str); + g_free (value_str); + } else + goto error; + } + if (a_this->important == TRUE) { + g_string_append_printf (stringue, " %s", + "!important"); + } + } + if (stringue && stringue->str) { + result = stringue->str; + g_string_free (stringue, FALSE); + } + return result; + + error: + if (stringue) { + g_string_free (stringue, TRUE); + stringue = NULL; + } + if (str) { + g_free (str); + str = NULL; + } + + return result; } /** @@ -587,35 +530,31 @@ cr_declaration_to_string (CRDeclaration *a_this, *to put before the actual serialisation. */ guchar * -cr_declaration_list_to_string (CRDeclaration *a_this, - gulong a_indent) +cr_declaration_list_to_string (CRDeclaration * a_this, gulong a_indent) { - CRDeclaration *cur = NULL ; - GString *stringue = NULL ; - guchar *str = NULL, *result = NULL ; - - g_return_val_if_fail (a_this, NULL) ; - - stringue = g_string_new (NULL) ; - - for (cur = a_this ; cur ; cur = cur->next) - { - str = cr_declaration_to_string (cur, a_indent) ; - if (str) - { - g_string_append_printf (stringue, "%s;", str) ; - g_free (str) ; - } - else - break; - } - if (stringue && stringue->str) - { - result = stringue->str ; - g_string_free (stringue, FALSE) ; - } - - return result ; + CRDeclaration *cur = NULL; + GString *stringue = NULL; + guchar *str = NULL, + *result = NULL; + + g_return_val_if_fail (a_this, NULL); + + stringue = g_string_new (NULL); + + for (cur = a_this; cur; cur = cur->next) { + str = cr_declaration_to_string (cur, a_indent); + if (str) { + g_string_append_printf (stringue, "%s;", str); + g_free (str); + } else + break; + } + if (stringue && stringue->str) { + result = stringue->str; + g_string_free (stringue, FALSE); + } + + return result; } /** @@ -625,51 +564,46 @@ cr_declaration_list_to_string (CRDeclaration *a_this, *to put before the actual serialisation. */ guchar * -cr_declaration_list_to_string2 (CRDeclaration *a_this, - gulong a_indent, - gboolean a_one_decl_per_line) +cr_declaration_list_to_string2 (CRDeclaration * a_this, + gulong a_indent, gboolean a_one_decl_per_line) { - CRDeclaration *cur = NULL ; - GString *stringue = NULL ; - guchar *str = NULL, *result = NULL ; - - g_return_val_if_fail (a_this, NULL) ; - - stringue = g_string_new (NULL) ; - - for (cur = a_this ; cur ; cur = cur->next) - { - str = cr_declaration_to_string (cur, a_indent) ; - if (str) - { - if (a_one_decl_per_line == TRUE) - { - if (cur->next) - g_string_append_printf (stringue, - "%s;\n", str) ; - else - g_string_append_printf (stringue, - "%s", str) ; - } - else - { - if (cur->next) - g_string_append_printf (stringue, "%s;", str) ; - else - g_string_append_printf (stringue, "%s", str) ; - } - g_free (str) ; - } - else - break; - } - if (stringue && stringue->str) - { - result = stringue->str ; - g_string_free (stringue, FALSE) ; - } - - return result ; + CRDeclaration *cur = NULL; + GString *stringue = NULL; + guchar *str = NULL, + *result = NULL; + + g_return_val_if_fail (a_this, NULL); + + stringue = g_string_new (NULL); + + for (cur = a_this; cur; cur = cur->next) { + str = cr_declaration_to_string (cur, a_indent); + if (str) { + if (a_one_decl_per_line == TRUE) { + if (cur->next) + g_string_append_printf (stringue, + "%s;\n", str); + else + g_string_append_printf (stringue, + "%s", str); + } else { + if (cur->next) + g_string_append_printf (stringue, + "%s;", str); + else + g_string_append_printf (stringue, + "%s", str); + } + g_free (str); + } else + break; + } + if (stringue && stringue->str) { + result = stringue->str; + g_string_free (stringue, FALSE); + } + + return result; } /** @@ -678,16 +612,16 @@ cr_declaration_list_to_string2 (CRDeclaration *a_this, *@return number of properties in the declaration list. */ gint -cr_declaration_nr_props (CRDeclaration *a_this) +cr_declaration_nr_props (CRDeclaration * a_this) { - CRDeclaration *cur = NULL ; - int nr = 0; + CRDeclaration *cur = NULL; + int nr = 0; - g_return_val_if_fail (a_this, -1) ; + g_return_val_if_fail (a_this, -1); - for (cur = a_this ; cur ; cur = cur->next) - nr ++; - return nr; + for (cur = a_this; cur; cur = cur->next) + nr++; + return nr; } /** @@ -698,17 +632,17 @@ cr_declaration_nr_props (CRDeclaration *a_this) *it will return NULL. */ CRDeclaration * -cr_declaration_get_from_list (CRDeclaration *a_this, int itemnr) +cr_declaration_get_from_list (CRDeclaration * a_this, int itemnr) { - CRDeclaration *cur = NULL ; - int nr = 0; + CRDeclaration *cur = NULL; + int nr = 0; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - for (cur = a_this ; cur ; cur = cur->next) - if (nr++ == itemnr) - return cur; - return NULL; + for (cur = a_this; cur; cur = cur->next) + if (nr++ == itemnr) + return cur; + return NULL; } /** @@ -718,29 +652,30 @@ cr_declaration_get_from_list (CRDeclaration *a_this, int itemnr) *@return CRDeclaration with property name a_prop, or NULL if not found. */ CRDeclaration * -cr_declaration_get_by_prop_name (CRDeclaration *a_this, const guchar *a_prop) +cr_declaration_get_by_prop_name (CRDeclaration * a_this, + const guchar * a_prop) { - CRDeclaration *cur = NULL ; + CRDeclaration *cur = NULL; - g_return_val_if_fail (a_this, NULL) ; - g_return_val_if_fail (a_prop, NULL) ; + g_return_val_if_fail (a_this, NULL); + g_return_val_if_fail (a_prop, NULL); - for (cur = a_this ; cur ; cur = cur->next) - if (!strcmp (cur->property->str, a_prop)) - return cur; - return NULL; + for (cur = a_this; cur; cur = cur->next) + if (!strcmp (cur->property->str, a_prop)) + return cur; + return NULL; } /** *Increases the ref count of the current instance of #CRDeclaration. *@param a_this the current instance of #CRDeclaration. */ -void -cr_declaration_ref (CRDeclaration *a_this) +void +cr_declaration_ref (CRDeclaration * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - a_this->ref_count ++ ; + a_this->ref_count++; } /** @@ -752,93 +687,81 @@ cr_declaration_ref (CRDeclaration *a_this) *(ref count reached zero), FALSE otherwise. */ gboolean -cr_declaration_unref (CRDeclaration *a_this) +cr_declaration_unref (CRDeclaration * a_this) { - g_return_val_if_fail (a_this, FALSE) ; - - if (a_this->ref_count) - { - a_this->ref_count -- ; - } - - if (a_this->ref_count == 0) - { - cr_declaration_destroy (a_this) ; - return TRUE ; - } - return FALSE ; -} + g_return_val_if_fail (a_this, FALSE); + + if (a_this->ref_count) { + a_this->ref_count--; + } + if (a_this->ref_count == 0) { + cr_declaration_destroy (a_this); + return TRUE; + } + return FALSE; +} /** *Destructor of the declaration list. *@param a_this the current instance of #CRDeclaration. */ void -cr_declaration_destroy (CRDeclaration *a_this) +cr_declaration_destroy (CRDeclaration * a_this) { - CRDeclaration *cur = NULL ; - g_return_if_fail (a_this) ; - - /* - *Go get the tail of the list. - *Meanwhile, free each property/value pair contained in the list. - */ - for (cur = a_this ; cur && cur->next; cur = cur->next) - { - if (cur->property) - { - g_string_free (cur->property, TRUE) ; - cur->property = NULL ; - } - - if (cur->value) - { - cr_term_destroy (cur->value) ; - cur->value = NULL ; - } - } - - if (cur) - { - if (cur->property) - { - g_string_free (cur->property, TRUE) ; - cur->property = NULL ; - } - - if (cur->value) - { - cr_term_destroy (cur->value) ; - cur->value = NULL ; - } - } - - /*in case the list contains only one element*/ - if (cur && !cur->prev) - { - g_free (cur) ; - return ; - } - - /*walk backward the list and free each "next" element*/ - for (cur = cur->prev ; cur && cur->prev ; cur = cur->prev) - { - if (cur->next) - { - g_free (cur->next) ; - cur->next = NULL ; - } - } - - if (!cur) - return ; - - if (cur->next) - { - g_free (cur->next) ; - cur->next = NULL ; - } - - g_free (cur) ; + CRDeclaration *cur = NULL; + + g_return_if_fail (a_this); + + /* + *Go get the tail of the list. + *Meanwhile, free each property/value pair contained in the list. + */ + for (cur = a_this; cur && cur->next; cur = cur->next) { + if (cur->property) { + g_string_free (cur->property, TRUE); + cur->property = NULL; + } + + if (cur->value) { + cr_term_destroy (cur->value); + cur->value = NULL; + } + } + + if (cur) { + if (cur->property) { + g_string_free (cur->property, TRUE); + cur->property = NULL; + } + + if (cur->value) { + cr_term_destroy (cur->value); + cur->value = NULL; + } + } + + /*in case the list contains only one element */ + if (cur && !cur->prev) { + g_free (cur); + return; + } + + /*walk backward the list and free each "next" element */ + for (cur = cur->prev; cur && cur->prev; cur = cur->prev) { + if (cur->next) { + g_free (cur->next); + cur->next = NULL; + } + } + + if (!cur) + return; + + if (cur->next) { + g_free (cur->next); + cur->next = NULL; + } + + g_free (cur); } diff --git a/src/cr-doc-handler.c b/src/cr-doc-handler.c index 165e5da..de8fb74 100644 --- a/src/cr-doc-handler.c +++ b/src/cr-doc-handler.c @@ -20,7 +20,6 @@ * USA */ - #include "cr-doc-handler.h" #include @@ -32,9 +31,8 @@ *to custom values. */ -struct _CRDocHandlerPriv -{ - /** +struct _CRDocHandlerPriv { + /** *This pointer is to hold an application parsing context. *For example, it used by the Object Model parser to *store it parsing context. #CRParser does not touch it, but @@ -42,46 +40,43 @@ struct _CRDocHandlerPriv *the beginning of the css document, and frees it at the end *of the document. */ - gpointer context ; + gpointer context; - /** + /** *The place where #CROMParser puts the result of its parsing, if *any. */ - gpointer result ; -} ; - + gpointer result; +}; /** *Constructor of #CRDocHandler. *@return the newly built instance of *#CRDocHandler */ -CRDocHandler * +CRDocHandler * cr_doc_handler_new (void) { - CRDocHandler * result = NULL ; + CRDocHandler *result = NULL; - result = g_try_malloc (sizeof (CRDocHandler)) ; + result = g_try_malloc (sizeof (CRDocHandler)); - g_return_val_if_fail (result, NULL) ; + g_return_val_if_fail (result, NULL); - memset (result, 0, sizeof (CRDocHandler)) ; + memset (result, 0, sizeof (CRDocHandler)); - result->priv = g_try_malloc (sizeof (CRDocHandlerPriv)) ; - if (!result->priv) - { - cr_utils_trace_info ("Out of memory exception") ; - g_free (result) ; - return NULL ; - } - - cr_doc_handler_ref (result) ; - cr_doc_handler_set_default_sac_handler (result) ; + result->priv = g_try_malloc (sizeof (CRDocHandlerPriv)); + if (!result->priv) { + cr_utils_trace_info ("Out of memory exception"); + g_free (result); + return NULL; + } - return result ; -} + cr_doc_handler_ref (result); + cr_doc_handler_set_default_sac_handler (result); + return result; +} /** *Returns the private parsing context. @@ -92,14 +87,13 @@ cr_doc_handler_new (void) *@return the parsing context, or NULL if an error occured. */ enum CRStatus -cr_doc_handler_get_ctxt (CRDocHandler *a_this, gpointer * a_ctxt) +cr_doc_handler_get_ctxt (CRDocHandler * a_this, gpointer * a_ctxt) { - g_return_val_if_fail (a_this && a_this->priv, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR); - *a_ctxt = a_this->priv->context ; + *a_ctxt = a_this->priv->context; - return CR_OK ; + return CR_OK; } /** @@ -110,12 +104,11 @@ cr_doc_handler_get_ctxt (CRDocHandler *a_this, gpointer * a_ctxt) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt) +cr_doc_handler_set_ctxt (CRDocHandler * a_this, gpointer a_ctxt) { - g_return_val_if_fail (a_this && a_this->priv, - CR_BAD_PARAM_ERROR) ; - a_this->priv->context = a_ctxt ; - return CR_OK ; + g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR); + a_this->priv->context = a_ctxt; + return CR_OK; } /** @@ -126,14 +119,13 @@ cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_doc_handler_get_result (CRDocHandler *a_this, gpointer * a_result) +cr_doc_handler_get_result (CRDocHandler * a_this, gpointer * a_result) { - g_return_val_if_fail (a_this && a_this->priv, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR); - *a_result = a_this->priv->result ; + *a_result = a_this->priv->result; - return CR_OK ; + return CR_OK; } /** @@ -144,12 +136,11 @@ cr_doc_handler_get_result (CRDocHandler *a_this, gpointer * a_result) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result) +cr_doc_handler_set_result (CRDocHandler * a_this, gpointer a_result) { - g_return_val_if_fail (a_this && a_this->priv, - CR_BAD_PARAM_ERROR) ; - a_this->priv->result = a_result ; - return CR_OK ; + g_return_val_if_fail (a_this && a_this->priv, CR_BAD_PARAM_ERROR); + a_this->priv->result = a_result; + return CR_OK; } /** @@ -163,40 +154,40 @@ cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_doc_handler_set_default_sac_handler (CRDocHandler *a_this) +cr_doc_handler_set_default_sac_handler (CRDocHandler * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - a_this->start_document = NULL; - a_this->end_document = NULL ; - a_this->import_style = NULL ; - a_this->namespace_declaration = NULL ; - a_this->comment = NULL ; - a_this->start_selector = NULL ; - a_this->end_selector = NULL ; - a_this->property = NULL ; - a_this->start_font_face = NULL ; - a_this->end_font_face = NULL ; - a_this->start_media = NULL ; - a_this->end_media = NULL ; - a_this->start_page = NULL ; - a_this->end_page = NULL ; - a_this->ignorable_at_rule = NULL ; - a_this->error = NULL ; - a_this->unrecoverable_error = NULL ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + a_this->start_document = NULL; + a_this->end_document = NULL; + a_this->import_style = NULL; + a_this->namespace_declaration = NULL; + a_this->comment = NULL; + a_this->start_selector = NULL; + a_this->end_selector = NULL; + a_this->property = NULL; + a_this->start_font_face = NULL; + a_this->end_font_face = NULL; + a_this->start_media = NULL; + a_this->end_media = NULL; + a_this->start_page = NULL; + a_this->end_page = NULL; + a_this->ignorable_at_rule = NULL; + a_this->error = NULL; + a_this->unrecoverable_error = NULL; + return CR_OK; } /** *Increases the reference count of the doc handler *@param a_this the current instance of #CRDocHandler. */ -void -cr_doc_handler_ref (CRDocHandler *a_this) +void +cr_doc_handler_ref (CRDocHandler * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - a_this->ref_count++ ; + a_this->ref_count++; } /** @@ -206,39 +197,35 @@ cr_doc_handler_ref (CRDocHandler *a_this) *@return TRUE if the instance as been destroyed, FALSE otherwise. */ gboolean -cr_doc_handler_unref (CRDocHandler *a_this) +cr_doc_handler_unref (CRDocHandler * a_this) { - g_return_val_if_fail (a_this, FALSE) ; + g_return_val_if_fail (a_this, FALSE); - if (a_this->ref_count > 0) - { - a_this->ref_count -- ; - } + if (a_this->ref_count > 0) { + a_this->ref_count--; + } - if (a_this->ref_count == 0) - { - cr_doc_handler_destroy (a_this) ; - return TRUE ; - } + if (a_this->ref_count == 0) { + cr_doc_handler_destroy (a_this); + return TRUE; + } - return FALSE ; + return FALSE; } - /** *The destructor of the #CRDocHandler class. *@param a_this the instance of #CRDocHandler to *destroy. */ void -cr_doc_handler_destroy (CRDocHandler *a_this) +cr_doc_handler_destroy (CRDocHandler * a_this) { - g_return_if_fail (a_this) ; - - if (a_this->priv) - { - g_free (a_this->priv) ; - a_this->priv = NULL ; - } - g_free (a_this) ; + g_return_if_fail (a_this); + + if (a_this->priv) { + g_free (a_this->priv); + a_this->priv = NULL; + } + g_free (a_this); } diff --git a/src/cr-enc-handler.c b/src/cr-enc-handler.c index 4789aa5..216ca47 100644 --- a/src/cr-enc-handler.c +++ b/src/cr-enc-handler.c @@ -29,54 +29,49 @@ *The definition of the #CREncHandler class. */ - #include "cr-enc-handler.h" #include "cr-utils.h" #include struct CREncAlias { - const gchar * name ; - enum CREncoding encoding ; -} ; - -static struct CREncAlias gv_default_aliases[] = -{ - {"UTF-8", CR_UTF_8}, - {"UTF_8", CR_UTF_8}, - {"UTF8", CR_UTF_8}, - {"UTF-16", CR_UTF_16}, - {"UTF_16", CR_UTF_16}, - {"UTF16", CR_UTF_16}, - {"UCS1", CR_UCS_1}, - {"UCS-1", CR_UCS_1}, - {"UCS_1", CR_UCS_1}, - {"ISO-8859-1", CR_UCS_1}, - {"ISO_8859-1", CR_UCS_1}, - {"UCS-1", CR_UCS_1}, - {"UCS_1", CR_UCS_1}, - {"UCS4", CR_UCS_4}, - {"UCS-4", CR_UCS_4}, - {"UCS_4", CR_UCS_4}, - {"ASCII", CR_ASCII}, - {0, 0} -} ; - - -static CREncHandler gv_default_enc_handlers[] = -{ - {CR_UCS_1, cr_utils_ucs1_to_utf8, cr_utils_utf8_to_ucs1, - cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1}, + const gchar *name; + enum CREncoding encoding; +}; + +static struct CREncAlias gv_default_aliases[] = { + {"UTF-8", CR_UTF_8}, + {"UTF_8", CR_UTF_8}, + {"UTF8", CR_UTF_8}, + {"UTF-16", CR_UTF_16}, + {"UTF_16", CR_UTF_16}, + {"UTF16", CR_UTF_16}, + {"UCS1", CR_UCS_1}, + {"UCS-1", CR_UCS_1}, + {"UCS_1", CR_UCS_1}, + {"ISO-8859-1", CR_UCS_1}, + {"ISO_8859-1", CR_UCS_1}, + {"UCS-1", CR_UCS_1}, + {"UCS_1", CR_UCS_1}, + {"UCS4", CR_UCS_4}, + {"UCS-4", CR_UCS_4}, + {"UCS_4", CR_UCS_4}, + {"ASCII", CR_ASCII}, + {0, 0} +}; + +static CREncHandler gv_default_enc_handlers[] = { + {CR_UCS_1, cr_utils_ucs1_to_utf8, cr_utils_utf8_to_ucs1, + cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1}, {CR_ISO_8859_1, cr_utils_ucs1_to_utf8, cr_utils_utf8_to_ucs1, - cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1}, + cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1}, {CR_ASCII, cr_utils_ucs1_to_utf8, cr_utils_utf8_to_ucs1, cr_utils_ucs1_str_len_as_utf8, cr_utils_utf8_str_len_as_ucs1}, {0, NULL, NULL, NULL, NULL} -} ; - +}; /** *Gets the instance of encoding handler. @@ -87,22 +82,18 @@ static CREncHandler gv_default_enc_handlers[] = CREncHandler * cr_enc_handler_get_instance (enum CREncoding a_enc) { - gulong i = 0 ; - - for (i = 0 ;gv_default_enc_handlers[i].encoding ; i++) - { - if (gv_default_enc_handlers[i].encoding == a_enc) - { - return - (CREncHandler *) - &gv_default_enc_handlers[i].encoding ; + gulong i = 0; + + for (i = 0; gv_default_enc_handlers[i].encoding; i++) { + if (gv_default_enc_handlers[i].encoding == a_enc) { + return (CREncHandler *) + & gv_default_enc_handlers[i].encoding; } } - return NULL ; + return NULL; } - /** *Given an encoding name (called an alias name) *the function returns the matching encoding type. @@ -112,31 +103,28 @@ cr_enc_handler_get_instance (enum CREncoding a_enc) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_enc_handler_resolve_enc_alias (const guchar *a_alias_name, - enum CREncoding *a_enc) +cr_enc_handler_resolve_enc_alias (const guchar * a_alias_name, + enum CREncoding *a_enc) { - gulong i = 0 ; - guchar * alias_name_up = NULL ; - enum CRStatus status = CR_ENCODING_NOT_FOUND_ERROR ; - - g_return_val_if_fail (a_alias_name != NULL, CR_BAD_PARAM_ERROR) ; - - alias_name_up = g_strdup (a_alias_name) ; - g_ascii_strup (alias_name_up, -1) ; - - for (i = 0 ; gv_default_aliases[i].name ; i++) - { - if (!strcmp (gv_default_aliases[i].name, alias_name_up)) - { - *a_enc = gv_default_aliases[i].encoding ; - status = CR_OK ; - break ; - } - } - - return status ; -} + gulong i = 0; + guchar *alias_name_up = NULL; + enum CRStatus status = CR_ENCODING_NOT_FOUND_ERROR; + + g_return_val_if_fail (a_alias_name != NULL, CR_BAD_PARAM_ERROR); + + alias_name_up = g_strdup (a_alias_name); + g_ascii_strup (alias_name_up, -1); + + for (i = 0; gv_default_aliases[i].name; i++) { + if (!strcmp (gv_default_aliases[i].name, alias_name_up)) { + *a_enc = gv_default_aliases[i].encoding; + status = CR_OK; + break; + } + } + return status; +} /** *Converts a raw input buffer into an utf8 buffer. @@ -151,44 +139,39 @@ cr_enc_handler_resolve_enc_alias (const guchar *a_alias_name, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_enc_handler_convert_input (CREncHandler *a_this, - const guchar *a_in, - gulong *a_in_len, - guchar **a_out, - gulong *a_out_len) +cr_enc_handler_convert_input (CREncHandler * a_this, + const guchar * a_in, + gulong * a_in_len, + guchar ** a_out, gulong * a_out_len) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; g_return_val_if_fail (a_this && a_in && a_in_len && a_out, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); - if (a_this->decode_input == NULL) return CR_OK ; + if (a_this->decode_input == NULL) + return CR_OK; - if (a_this->enc_str_len_as_utf8) - { - status = - a_this->enc_str_len_as_utf8 (a_in, - &a_in[*a_in_len -1], - a_out_len) ; + if (a_this->enc_str_len_as_utf8) { + status = a_this->enc_str_len_as_utf8 (a_in, + &a_in[*a_in_len - 1], + a_out_len); - g_return_val_if_fail (status == CR_OK, status) ; - } - else - { - *a_out_len = *a_in_len ; + g_return_val_if_fail (status == CR_OK, status); + } else { + *a_out_len = *a_in_len; } - *a_out = g_malloc0 (*a_out_len) ; + *a_out = g_malloc0 (*a_out_len); - status = a_this->decode_input (a_in, a_in_len, *a_out, a_out_len) ; + status = a_this->decode_input (a_in, a_in_len, *a_out, a_out_len); - if (status != CR_OK) - { - g_free (*a_out) ; - *a_out = NULL ; + if (status != CR_OK) { + g_free (*a_out); + *a_out = NULL; } - g_return_val_if_fail (status == CR_OK, status) ; + g_return_val_if_fail (status == CR_OK, status); - return CR_OK ; + return CR_OK; } diff --git a/src/cr-fonts.c b/src/cr-fonts.c index 9a52dde..a99396f 100644 --- a/src/cr-fonts.c +++ b/src/cr-fonts.c @@ -26,288 +26,255 @@ #include "cr-fonts.h" #include - static enum CRStatus -cr_font_family_to_string_real (CRFontFamily *a_this, - gboolean a_walk_list, - GString **a_string) +cr_font_family_to_string_real (CRFontFamily * a_this, + gboolean a_walk_list, GString ** a_string) { - guchar * name = NULL ; - enum CRStatus result = CR_OK ; + guchar *name = NULL; + enum CRStatus result = CR_OK; - if (!*a_string) - { - *a_string = g_string_new (NULL) ; + if (!*a_string) { + *a_string = g_string_new (NULL); g_return_val_if_fail (*a_string, - CR_INSTANCIATION_FAILED_ERROR) ; + CR_INSTANCIATION_FAILED_ERROR); } - - if (!a_this) - { - g_string_append_printf (*a_string, "NULL") ; - return CR_OK ; + + if (!a_this) { + g_string_append_printf (*a_string, "NULL"); + return CR_OK; } - switch (a_this->type) - { + switch (a_this->type) { case FONT_FAMILY_SANS_SERIF: - name = (guchar*) "sans-serif" ; - break ; + name = (guchar *) "sans-serif"; + break; case FONT_FAMILY_SERIF: - name = (guchar*) "sans-serif" ; - break ; + name = (guchar *) "sans-serif"; + break; case FONT_FAMILY_CURSIVE: - name = (guchar*) "cursive" ; - break ; + name = (guchar *) "cursive"; + break; case FONT_FAMILY_FANTASY: - name = (guchar*) "fantasy" ; - break ; + name = (guchar *) "fantasy"; + break; case FONT_FAMILY_MONOSPACE: - name = (guchar*) "monospace" ; - break ; + name = (guchar *) "monospace"; + break; case FONT_FAMILY_NON_GENERIC: - name = (guchar*) a_this->name; - break ; + name = (guchar *) a_this->name; + break; default: - name = (guchar*) NULL ; - break ; + name = (guchar *) NULL; + break; } - if (name) - { - if (a_this->prev) - { - g_string_append_printf (*a_string, ", %s", name) ; - } - else - { - g_string_append (*a_string, name) ; + if (name) { + if (a_this->prev) { + g_string_append_printf (*a_string, ", %s", name); + } else { + g_string_append (*a_string, name); } } - if (a_walk_list == TRUE && a_this->next) - { + if (a_walk_list == TRUE && a_this->next) { result = cr_font_family_to_string_real (a_this->next, - TRUE, a_string) ; + TRUE, a_string); } - return result ; + return result; } static const gchar * -cr_predefined_absolute_font_size_to_string (enum CRPredefinedAbsoluteFontSize a_code) +cr_predefined_absolute_font_size_to_string (enum CRPredefinedAbsoluteFontSize + a_code) { - gchar *str = NULL ; - switch (a_code) - { + gchar *str = NULL; + + switch (a_code) { case FONT_SIZE_XX_SMALL: - str = (gchar*)"font-size-xx-small" ; - break ; + str = (gchar *) "font-size-xx-small"; + break; case FONT_SIZE_X_SMALL: - str = (gchar*)"font-size-x-small" ; - break ; + str = (gchar *) "font-size-x-small"; + break; case FONT_SIZE_SMALL: - str = (gchar*)"font-size-small" ; - break ; + str = (gchar *) "font-size-small"; + break; case FONT_SIZE_MEDIUM: - str = (gchar*)"font-size-medium" ; - break ; + str = (gchar *) "font-size-medium"; + break; case FONT_SIZE_LARGE: - str = (gchar*)"font-size-large" ; - break ; + str = (gchar *) "font-size-large"; + break; case FONT_SIZE_X_LARGE: - str = (gchar*)"font-size-x-large" ; - break ; + str = (gchar *) "font-size-x-large"; + break; case FONT_SIZE_XX_LARGE: - str = (gchar*)"font-size-xx-large" ; - break ; + str = (gchar *) "font-size-xx-large"; + break; default: - str = (gchar*) "unknown predefined absolute font size value"; + str = (gchar *) "unknown predefined absolute font size value"; } - return str ; + return str; } static const gchar * cr_relative_font_size_to_string (enum CRRelativeFontSize a_code) { - gchar *str = NULL ; + gchar *str = NULL; - switch (a_code) - { + switch (a_code) { case FONT_SIZE_LARGER: - str = (gchar*)"font-size-larger" ; - break ; + str = (gchar *) "font-size-larger"; + break; case FONT_SIZE_SMALLER: - str = (gchar*)"font-size-smaller" ; - break ; + str = (gchar *) "font-size-smaller"; + break; default: - str = (gchar*)"unknown relative font size value" ; - break ; + str = (gchar *) "unknown relative font size value"; + break; } - return str ; + return str; } CRFontFamily * -cr_font_family_new (enum CRFontFamilyType a_type, guchar *a_name) +cr_font_family_new (enum CRFontFamilyType a_type, guchar * a_name) { - CRFontFamily *result = NULL ; + CRFontFamily *result = NULL; - result = g_try_malloc (sizeof (CRFontFamily)) ; + result = g_try_malloc (sizeof (CRFontFamily)); - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - memset (result, 0, sizeof (CRFontFamily)) ; - result->type = a_type ; + memset (result, 0, sizeof (CRFontFamily)); + result->type = a_type; - cr_font_family_set_name (result, a_name) ; + cr_font_family_set_name (result, a_name); - return result ; + return result; } - guchar * -cr_font_family_to_string (CRFontFamily *a_this, +cr_font_family_to_string (CRFontFamily * a_this, gboolean a_walk_font_family_list) { - enum CRStatus status = CR_OK ; - guchar *result = NULL ; - GString *stringue = NULL ; - - if (!a_this) - { - result = g_strdup ("NULL") ; - g_return_val_if_fail (result, NULL) ; - return result ; - } + enum CRStatus status = CR_OK; + guchar *result = NULL; + GString *stringue = NULL; + + if (!a_this) { + result = g_strdup ("NULL"); + g_return_val_if_fail (result, NULL); + return result; + } status = cr_font_family_to_string_real (a_this, a_walk_font_family_list, - &stringue) ; - - if (status == CR_OK && stringue) - { - result = stringue->str ; - g_string_free (stringue, FALSE) ; - stringue = NULL ; - - } - else - { - if (stringue) - { - g_string_free (stringue, TRUE) ; - stringue = NULL ; + &stringue); + + if (status == CR_OK && stringue) { + result = stringue->str; + g_string_free (stringue, FALSE); + stringue = NULL; + + } else { + if (stringue) { + g_string_free (stringue, TRUE); + stringue = NULL; } } - return result ; + return result; } enum CRStatus -cr_font_family_set_name (CRFontFamily *a_this, guchar *a_name) +cr_font_family_set_name (CRFontFamily * a_this, guchar * a_name) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - /* - *only non generic font families can have a name - */ - - if (a_this->type != FONT_FAMILY_NON_GENERIC) - { - return CR_BAD_PARAM_ERROR ; - } - - if (a_this->name) - { - g_free (a_this->name) ; - a_this->name = NULL ; - } - - a_this->name = a_name ; - return CR_OK ; -} + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + /* + *only non generic font families can have a name + */ + + if (a_this->type != FONT_FAMILY_NON_GENERIC) { + return CR_BAD_PARAM_ERROR; + } + + if (a_this->name) { + g_free (a_this->name); + a_this->name = NULL; + } + + a_this->name = a_name; + return CR_OK; +} CRFontFamily * -cr_font_family_append (CRFontFamily *a_this, - CRFontFamily *a_family_to_append) +cr_font_family_append (CRFontFamily * a_this, + CRFontFamily * a_family_to_append) { - CRFontFamily *cur_ff = NULL ; + CRFontFamily *cur_ff = NULL; - g_return_val_if_fail (a_family_to_append, - NULL) ; + g_return_val_if_fail (a_family_to_append, NULL); + + if (!a_this) + return a_family_to_append; - if (!a_this) - return a_family_to_append ; + for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ; - for (cur_ff = a_this ; - cur_ff && cur_ff->next; - cur_ff = cur_ff->next ) ; - - cur_ff->next = a_family_to_append; - a_family_to_append->prev = cur_ff ; + cur_ff->next = a_family_to_append; + a_family_to_append->prev = cur_ff; - return a_this ; + return a_this; - } CRFontFamily * -cr_font_family_prepend (CRFontFamily *a_this, - CRFontFamily *a_family_to_prepend) +cr_font_family_prepend (CRFontFamily * a_this, + CRFontFamily * a_family_to_prepend) { - g_return_val_if_fail (a_this && a_family_to_prepend, - NULL) ; + g_return_val_if_fail (a_this && a_family_to_prepend, NULL); - if (!a_this) - return a_family_to_prepend ; + if (!a_this) + return a_family_to_prepend; - a_family_to_prepend->next = a_this ; - a_this->prev = a_family_to_prepend ; + a_family_to_prepend->next = a_this; + a_this->prev = a_family_to_prepend; - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_font_family_destroy (CRFontFamily *a_this) +cr_font_family_destroy (CRFontFamily * a_this) { - CRFontFamily *cur_ff = NULL ; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - for (cur_ff = a_this ; - cur_ff && cur_ff->next ; - cur_ff = cur_ff->next) - ; - - for (; cur_ff ; cur_ff = cur_ff->prev) - { - if (a_this->name) - { - g_free (a_this->name) ; - a_this->name = NULL ; - } - - if (cur_ff->next) - { - g_free (cur_ff->next) ; - - } - - if (cur_ff->prev == NULL) - { - g_free (a_this) ; - } - } - - return CR_OK ; + CRFontFamily *cur_ff = NULL; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + for (cur_ff = a_this; cur_ff && cur_ff->next; cur_ff = cur_ff->next) ; + + for (; cur_ff; cur_ff = cur_ff->prev) { + if (a_this->name) { + g_free (a_this->name); + a_this->name = NULL; + } + + if (cur_ff->next) { + g_free (cur_ff->next); + + } + + if (cur_ff->prev == NULL) { + g_free (a_this); + } + } + + return CR_OK; } /*************************************************** @@ -317,303 +284,287 @@ cr_font_family_destroy (CRFontFamily *a_this) CRFontSize * cr_font_size_new (void) { - CRFontSize *result = NULL ; + CRFontSize *result = NULL; - result = g_try_malloc (sizeof (CRFontSize)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; + result = g_try_malloc (sizeof (CRFontSize)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; } - memset (result, 0, sizeof (CRFontSize)) ; + memset (result, 0, sizeof (CRFontSize)); - return result ; + return result; } enum CRStatus -cr_font_size_clear (CRFontSize *a_this) +cr_font_size_clear (CRFontSize * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - switch (a_this->type) - { + switch (a_this->type) { case PREDEFINED_ABSOLUTE_FONT_SIZE: case RELATIVE_FONT_SIZE: case INHERITED_FONT_SIZE: - memset (a_this, 0, sizeof (CRFontSize)) ; - break ; + memset (a_this, 0, sizeof (CRFontSize)); + break; case ABSOLUTE_FONT_SIZE: - if (a_this->value.absolute) - { - cr_num_destroy (a_this->value.absolute) ; + if (a_this->value.absolute) { + cr_num_destroy (a_this->value.absolute); } - memset (a_this, 0, sizeof (CRFontSize)) ; - break ; + memset (a_this, 0, sizeof (CRFontSize)); + break; default: - return CR_UNKNOWN_TYPE_ERROR ; + return CR_UNKNOWN_TYPE_ERROR; } - return CR_OK ; + return CR_OK; } enum CRStatus -cr_font_size_copy (CRFontSize *a_dst, CRFontSize *a_src) +cr_font_size_copy (CRFontSize * a_dst, CRFontSize * a_src) { - g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_dst && a_src, CR_BAD_PARAM_ERROR); - switch (a_src->type) - { + switch (a_src->type) { case PREDEFINED_ABSOLUTE_FONT_SIZE: case RELATIVE_FONT_SIZE: case INHERITED_FONT_SIZE: - cr_font_size_clear (a_dst) ; - memcpy (a_dst, a_src, sizeof (CRFontSize)) ; - break ; - - case ABSOLUTE_FONT_SIZE: - if (a_src->value.absolute) - { - cr_font_size_clear (a_dst) ; - if (!a_dst->value.absolute) - { - a_dst->value.absolute = cr_num_new () ; + cr_font_size_clear (a_dst); + memcpy (a_dst, a_src, sizeof (CRFontSize)); + break; + + case ABSOLUTE_FONT_SIZE: + if (a_src->value.absolute) { + cr_font_size_clear (a_dst); + if (!a_dst->value.absolute) { + a_dst->value.absolute = cr_num_new (); } cr_num_copy (a_dst->value.absolute, - a_src->value.absolute) ; - a_dst->type = a_src->type ; + a_src->value.absolute); + a_dst->type = a_src->type; } - break ; + break; default: - return CR_UNKNOWN_TYPE_ERROR ; + return CR_UNKNOWN_TYPE_ERROR; } - return CR_OK ; + return CR_OK; } -gchar* -cr_font_size_to_string (CRFontSize *a_this) +gchar * +cr_font_size_to_string (CRFontSize * a_this) { - gchar *str = NULL ; - - if (!a_this) - { - str = g_strdup ("NULL") ; - g_return_val_if_fail (str, NULL) ; - return str ; + gchar *str = NULL; + + if (!a_this) { + str = g_strdup ("NULL"); + g_return_val_if_fail (str, NULL); + return str; } - switch (a_this->type) - { + switch (a_this->type) { case PREDEFINED_ABSOLUTE_FONT_SIZE: str = g_strdup (cr_predefined_absolute_font_size_to_string - (a_this->value.predefined)) ; - break ; + (a_this->value.predefined)); + break; case ABSOLUTE_FONT_SIZE: - str = cr_num_to_string (a_this->value.absolute) ; - break ; + str = cr_num_to_string (a_this->value.absolute); + break; case RELATIVE_FONT_SIZE: str = g_strdup (cr_relative_font_size_to_string - (a_this->value.relative)) ; - break ; + (a_this->value.relative)); + break; case INHERITED_FONT_SIZE: - str = g_strdup ("inherited") ; - break ; + str = g_strdup ("inherited"); + break; default: - break ; + break; } - return str ; + return str; } - gchar * -cr_font_size_adjust_to_string (CRFontSizeAdjust *a_this) +cr_font_size_adjust_to_string (CRFontSizeAdjust * a_this) { - gchar *str = NULL ; + gchar *str = NULL; - if (!a_this) - { - str = g_strdup ("NULL") ; - g_return_val_if_fail (str, NULL) ; - return str ; + if (!a_this) { + str = g_strdup ("NULL"); + g_return_val_if_fail (str, NULL); + return str; } - switch (a_this->type) - { + switch (a_this->type) { case FONT_SIZE_ADJUST_NONE: - str = g_strdup ("font-size-adjust-none") ; - break ; + str = g_strdup ("font-size-adjust-none"); + break; case FONT_SIZE_ADJUST_NUMBER: if (a_this->num) - str = cr_num_to_string (a_this->num) ; + str = cr_num_to_string (a_this->num); else - str = g_strdup ("font-size-adjust-NULL") ; - break ; + str = g_strdup ("font-size-adjust-NULL"); + break; case FONT_SIZE_ADJUST_INHERIT: - str = g_strdup ("font-size-adjust-inherit") ; + str = g_strdup ("font-size-adjust-inherit"); } - return str ; + return str; } const gchar * cr_font_style_to_string (enum CRFontStyle a_code) { - gchar *str = NULL ; + gchar *str = NULL; - switch (a_code) - { + switch (a_code) { case FONT_STYLE_NORMAL: - str = (gchar*)"font-style-normal" ; - break ; + str = (gchar *) "font-style-normal"; + break; case FONT_STYLE_ITALIC: - str = (gchar*)"font-style-italic" ; - break ; + str = (gchar *) "font-style-italic"; + break; case FONT_STYLE_OBLIQUE: - str = (gchar*)"font-style-oblique" ; - break ; + str = (gchar *) "font-style-oblique"; + break; case FONT_STYLE_INHERIT: - str = (gchar*)"font-style-inherit" ; - break ; + str = (gchar *) "font-style-inherit"; + break; default: - str = (gchar*)"font-style" ; - break ; + str = (gchar *) "font-style"; + break; } - return str ; + return str; } const gchar * cr_font_variant_to_string (enum CRFontVariant a_code) { - gchar *str = NULL ; - - switch (a_code) - { + gchar *str = NULL; + + switch (a_code) { case FONT_VARIANT_NORMAL: - str = (gchar*) "font-variant-normal"; - break ; + str = (gchar *) "font-variant-normal"; + break; case FONT_VARIANT_SMALL_CAPS: - str = (gchar*) "font-variant-small-caps" ; - break ; + str = (gchar *) "font-variant-small-caps"; + break; case FONT_VARIANT_INHERIT: - str = (gchar*) "font-variant-inherent" ; - break ; + str = (gchar *) "font-variant-inherent"; + break; } - return str ; + return str; } const gchar * -cr_font_weight_to_string (enum CRFontWeight a_code) +cr_font_weight_to_string (enum CRFontWeight a_code) { - gchar *str = NULL ; - - switch (a_code) - { + gchar *str = NULL; + + switch (a_code) { case FONT_WEIGHT_NORMAL: - str = (gchar*) "font-weight-normal"; - break ; + str = (gchar *) "font-weight-normal"; + break; case FONT_WEIGHT_BOLD: - str = (gchar*) "font-weight-bold"; - break ; + str = (gchar *) "font-weight-bold"; + break; case FONT_WEIGHT_BOLDER: - str = (gchar*) "font-weight-bolder"; - break ; + str = (gchar *) "font-weight-bolder"; + break; case FONT_WEIGHT_LIGHTER: - str = (gchar*) "font-weight-lighter"; - break ; + str = (gchar *) "font-weight-lighter"; + break; case FONT_WEIGHT_100: - str = (gchar*) "font-weight-100"; - break ; + str = (gchar *) "font-weight-100"; + break; case FONT_WEIGHT_200: - str = (gchar*) "font-weight-200"; - break ; + str = (gchar *) "font-weight-200"; + break; case FONT_WEIGHT_300: - str = (gchar*) "font-weight-300"; - break ; + str = (gchar *) "font-weight-300"; + break; case FONT_WEIGHT_400: - str = (gchar*) "font-weight-400"; - break ; + str = (gchar *) "font-weight-400"; + break; case FONT_WEIGHT_500: - str = (gchar*) "font-weight-500"; - break ; + str = (gchar *) "font-weight-500"; + break; case FONT_WEIGHT_600: - str = (gchar*) "font-weight-600"; - break ; + str = (gchar *) "font-weight-600"; + break; case FONT_WEIGHT_700: - str = (gchar*) "font-weight-700"; - break ; + str = (gchar *) "font-weight-700"; + break; case FONT_WEIGHT_800: - str = (gchar*) "font-weight-800"; - break ; + str = (gchar *) "font-weight-800"; + break; case FONT_WEIGHT_900: - str = (gchar*) "font-weight-900"; - break ; + str = (gchar *) "font-weight-900"; + break; case FONT_WEIGHT_INHERIT: - str = (gchar*) "font-weight-inherit"; - break ; + str = (gchar *) "font-weight-inherit"; + break; default: - str = (gchar*) "unknown font-weight property value"; - break ; + str = (gchar *) "unknown font-weight property value"; + break; } - return str ; + return str; } const gchar * cr_font_stretch_to_string (enum CRFontStretch a_code) { - gchar *str = NULL ; + gchar *str = NULL; - switch (a_code) - { + switch (a_code) { case FONT_STRETCH_NORMAL: - str = (gchar*)"font-stretch-normal" ; - break ; + str = (gchar *) "font-stretch-normal"; + break; case FONT_STRETCH_WIDER: - str = (gchar*)"font-stretch-wider" ; - break ; + str = (gchar *) "font-stretch-wider"; + break; case FONT_STRETCH_NARROWER: - str = (gchar*)"font-stretch-narrower" ; - break ; + str = (gchar *) "font-stretch-narrower"; + break; case FONT_STRETCH_ULTRA_CONDENSED: - str = (gchar*)"font-stretch-ultra-condensed" ; - break ; + str = (gchar *) "font-stretch-ultra-condensed"; + break; case FONT_STRETCH_EXTRA_CONDENSED: - str = (gchar*)"font-stretch-extra-condensed" ; - break ; + str = (gchar *) "font-stretch-extra-condensed"; + break; case FONT_STRETCH_CONDENSED: - str = (gchar*)"font-stretch-condensed" ; - break ; + str = (gchar *) "font-stretch-condensed"; + break; case FONT_STRETCH_SEMI_CONDENSED: - str = (gchar*)"font-stretch-semi-condensed" ; - break ; + str = (gchar *) "font-stretch-semi-condensed"; + break; case FONT_STRETCH_SEMI_EXPANDED: - str = (gchar*)"font-stretch-semi-expanded" ; - break ; + str = (gchar *) "font-stretch-semi-expanded"; + break; case FONT_STRETCH_EXPANDED: - str = (gchar*)"font-stretch-expanded" ; - break ; + str = (gchar *) "font-stretch-expanded"; + break; case FONT_STRETCH_EXTRA_EXPANDED: - str = (gchar*)"font-stretch-extra-expaned" ; - break ; + str = (gchar *) "font-stretch-extra-expaned"; + break; case FONT_STRETCH_ULTRA_EXPANDED: - str = (gchar*)"font-stretch-ultra-expanded" ; - break ; + str = (gchar *) "font-stretch-ultra-expanded"; + break; case FONT_STRETCH_INHERIT: - str = (gchar*)"font-stretch-inherit" ; - break ; + str = (gchar *) "font-stretch-inherit"; + break; } - return str ; + return str; } void -cr_font_size_destroy (CRFontSize *a_font_size) +cr_font_size_destroy (CRFontSize * a_font_size) { - g_return_if_fail (a_font_size) ; + g_return_if_fail (a_font_size); if (a_font_size->type == ABSOLUTE_FONT_SIZE - && a_font_size->value.absolute) - { - cr_num_destroy (a_font_size->value.absolute) ; - a_font_size->value.absolute = NULL ; + && a_font_size->value.absolute) { + cr_num_destroy (a_font_size->value.absolute); + a_font_size->value.absolute = NULL; } } @@ -624,28 +575,25 @@ cr_font_size_destroy (CRFontSize *a_font_size) CRFontSizeAdjust * cr_font_size_adjust_new (void) { - CRFontSizeAdjust *result = NULL ; + CRFontSizeAdjust *result = NULL; - result = g_try_malloc (sizeof (CRFontSizeAdjust)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; + result = g_try_malloc (sizeof (CRFontSizeAdjust)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; } - memset (result, 0, sizeof (CRFontSizeAdjust)) ; + memset (result, 0, sizeof (CRFontSizeAdjust)); - return result ; + return result; } void -cr_font_size_adjust_destroy (CRFontSizeAdjust *a_this) +cr_font_size_adjust_destroy (CRFontSizeAdjust * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - if (a_this->type == FONT_SIZE_ADJUST_NUMBER - && a_this->num) - { - cr_num_destroy (a_this->num) ; - a_this->num = NULL ; + if (a_this->type == FONT_SIZE_ADJUST_NUMBER && a_this->num) { + cr_num_destroy (a_this->num); + a_this->num = NULL; } } diff --git a/src/cr-input.c b/src/cr-input.c index 70f81f7..6d3d639 100644 --- a/src/cr-input.c +++ b/src/cr-input.c @@ -24,13 +24,11 @@ *$Id$ */ - #include "stdio.h" #include #include "cr-input.h" #include "cr-enc-handler.h" - /** *@file *The definition of the #CRInput class. @@ -40,92 +38,82 @@ *Private type defs *******************/ - /** *The private attributes of *the #CRInputPriv class. */ -struct _CRInputPriv -{ +struct _CRInputPriv { /* *The input buffer */ - guchar *in_buf ; - gulong in_buf_size ; + guchar *in_buf; + gulong in_buf_size; - gulong nb_bytes ; + gulong nb_bytes; /* *The index of the next byte *to be read. */ - gulong next_byte_index ; + gulong next_byte_index; /* *The current line number */ - gulong line ; + gulong line; /* *The current col number. */ - gulong col ; + gulong col; - gboolean end_of_line ; - gboolean end_of_input ; + gboolean end_of_line; + gboolean end_of_input; /* *the reference count of this *instance. */ - guint ref_count ; - gboolean free_in_buf ; -} ; - + guint ref_count; + gboolean free_in_buf; +}; #define PRIVATE(object) (object)->priv - /*************************** *private constants **************************/ #define CR_INPUT_MEM_CHUNK_SIZE 1024 * 4 -static CRInput * -cr_input_new_real (void) ; - +static CRInput *cr_input_new_real (void); static CRInput * cr_input_new_real (void) { - CRInput *result = NULL ; + CRInput *result = NULL; - result = g_try_malloc (sizeof (CRInput)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; + result = g_try_malloc (sizeof (CRInput)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; } - memset (result, 0, sizeof (CRInput)) ; - - PRIVATE (result) = g_try_malloc (sizeof (CRInputPriv)) ; - if (!PRIVATE (result)) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } - memset (PRIVATE (result), 0, sizeof (CRInputPriv)) ; - PRIVATE (result)->free_in_buf = TRUE ; - return result ; -} + memset (result, 0, sizeof (CRInput)); + PRIVATE (result) = g_try_malloc (sizeof (CRInputPriv)); + if (!PRIVATE (result)) { + cr_utils_trace_info ("Out of memory"); + g_free (result); + return NULL; + } + memset (PRIVATE (result), 0, sizeof (CRInputPriv)); + PRIVATE (result)->free_in_buf = TRUE; + return result; +} /**************** *Public methods ***************/ - /** *Creates a new input stream from a memory buffer. *@param a_buf the memory buffer to create the input stream from. @@ -137,59 +125,54 @@ cr_input_new_real (void) *@return the newly built instance of #CRInput. */ CRInput * -cr_input_new_from_buf (const guchar *a_buf, +cr_input_new_from_buf (const guchar * a_buf, gulong a_len, - enum CREncoding a_enc, - gboolean a_free_buf) + enum CREncoding a_enc, gboolean a_free_buf) { CRInput *result = NULL; - enum CRStatus status = CR_OK ; - CREncHandler *enc_handler = NULL ; - gulong len = a_len ; - g_return_val_if_fail (a_buf, NULL) ; - - result = cr_input_new_real () ; - g_return_val_if_fail (result, NULL) ; - - /*transform the encoding in utf8*/ - if (a_enc != CR_UTF_8) - { - enc_handler = cr_enc_handler_get_instance (a_enc) ; - if (!enc_handler) - { - goto error ; + enum CRStatus status = CR_OK; + CREncHandler *enc_handler = NULL; + gulong len = a_len; + + g_return_val_if_fail (a_buf, NULL); + + result = cr_input_new_real (); + g_return_val_if_fail (result, NULL); + + /*transform the encoding in utf8 */ + if (a_enc != CR_UTF_8) { + enc_handler = cr_enc_handler_get_instance (a_enc); + if (!enc_handler) { + goto error; } status = cr_enc_handler_convert_input (enc_handler, a_buf, &len, &PRIVATE (result)->in_buf, - &PRIVATE (result)->in_buf_size) ; + &PRIVATE (result)->in_buf_size); if (status != CR_OK) - goto error ; + goto error; - PRIVATE (result)->line = 1 ; - PRIVATE (result)->nb_bytes = PRIVATE (result)->in_buf_size ; - } - else - { - PRIVATE (result)->in_buf = (guchar *) a_buf ; - PRIVATE (result)->in_buf_size = a_len ; - PRIVATE (result)->nb_bytes = a_len ; + PRIVATE (result)->line = 1; + PRIVATE (result)->nb_bytes = PRIVATE (result)->in_buf_size; + } else { + PRIVATE (result)->in_buf = (guchar *) a_buf; + PRIVATE (result)->in_buf_size = a_len; + PRIVATE (result)->nb_bytes = a_len; } - PRIVATE (result)->free_in_buf = a_free_buf ; + PRIVATE (result)->free_in_buf = a_free_buf; - return result ; + return result; - error: - if (result) - { - cr_input_destroy (result) ; - result = NULL ; + error: + if (result) { + cr_input_destroy (result); + result = NULL; } - return NULL ; + return NULL; } /** @@ -205,94 +188,80 @@ cr_input_new_from_buf (const guchar *a_buf, */ CRInput * -cr_input_new_from_uri (const gchar *a_file_uri, enum CREncoding a_enc) +cr_input_new_from_uri (const gchar * a_file_uri, enum CREncoding a_enc) { - CRInput * result = NULL ; - enum CRStatus status = CR_OK ; - FILE * file_ptr = NULL ; - guchar tmp_buf[CR_INPUT_MEM_CHUNK_SIZE] = {0} ; - gulong nb_read = 0, len = 0, buf_size = 0 ; - gboolean loop = TRUE ; - guchar *buf = NULL ; + CRInput *result = NULL; + enum CRStatus status = CR_OK; + FILE *file_ptr = NULL; + guchar tmp_buf[CR_INPUT_MEM_CHUNK_SIZE] = { 0 }; + gulong nb_read = 0, + len = 0, + buf_size = 0; + gboolean loop = TRUE; + guchar *buf = NULL; - g_return_val_if_fail (a_file_uri, NULL) ; + g_return_val_if_fail (a_file_uri, NULL); - file_ptr = fopen (a_file_uri, "r") ; + file_ptr = fopen (a_file_uri, "r"); - if (file_ptr == NULL) - { + if (file_ptr == NULL) { #ifdef CR_DEBUG - cr_utils_trace_debug ("could not open file") ; + cr_utils_trace_debug ("could not open file"); #endif - g_warning ("Could not open file %s\n", a_file_uri) ; - - return NULL ; + g_warning ("Could not open file %s\n", a_file_uri); + + return NULL; } - /*load the file*/ - while (loop) - { - nb_read = - fread (tmp_buf, 1/*read bytes*/, - CR_INPUT_MEM_CHUNK_SIZE/*nb of bytes*/, - file_ptr) ; - - if (nb_read != CR_INPUT_MEM_CHUNK_SIZE) - { - /*we read less chars than we wanted*/ - if (feof (file_ptr)) - { - /*we reached eof*/ - loop = FALSE ; - } - else - { - /*a pb occured !!*/ - cr_utils_trace_debug - ("an io error occured") ; - status = CR_ERROR ; - goto cleanup ; + /*load the file */ + while (loop) { + nb_read = fread (tmp_buf, 1 /*read bytes */ , + CR_INPUT_MEM_CHUNK_SIZE /*nb of bytes */ , + file_ptr); + + if (nb_read != CR_INPUT_MEM_CHUNK_SIZE) { + /*we read less chars than we wanted */ + if (feof (file_ptr)) { + /*we reached eof */ + loop = FALSE; + } else { + /*a pb occured !! */ + cr_utils_trace_debug ("an io error occured"); + status = CR_ERROR; + goto cleanup; } } - if (status == CR_OK) - { - /*read went well*/ - buf = g_realloc - (buf, len + CR_INPUT_MEM_CHUNK_SIZE) ; - memcpy (buf + len, tmp_buf, nb_read) ; - len += nb_read ; - buf_size += CR_INPUT_MEM_CHUNK_SIZE ; + if (status == CR_OK) { + /*read went well */ + buf = g_realloc (buf, len + CR_INPUT_MEM_CHUNK_SIZE); + memcpy (buf + len, tmp_buf, nb_read); + len += nb_read; + buf_size += CR_INPUT_MEM_CHUNK_SIZE; } } - - if (status == CR_OK) - { - result = cr_input_new_from_buf (buf, len, a_enc, - TRUE) ; - if (!result) - { - goto cleanup ; - } + if (status == CR_OK) { + result = cr_input_new_from_buf (buf, len, a_enc, TRUE); + if (!result) { + goto cleanup; + } } -cleanup: + cleanup: - if (file_ptr) - { - fclose (file_ptr) ; - file_ptr = NULL ; + if (file_ptr) { + fclose (file_ptr); + file_ptr = NULL; } - if (buf) - { - g_free (buf) ; - buf = NULL ; + if (buf) { + g_free (buf); + buf = NULL; } - return result ; + return result; } /** @@ -300,41 +269,36 @@ cleanup: *@param a_this the current instance of #CRInput. */ void -cr_input_destroy (CRInput *a_this) +cr_input_destroy (CRInput * a_this) { if (a_this == NULL) - return ; - - if (PRIVATE (a_this)) - { - if (PRIVATE (a_this)->in_buf - && PRIVATE (a_this)->free_in_buf) - { - g_free (PRIVATE (a_this)->in_buf) ; - PRIVATE (a_this)->in_buf = NULL ; + return; + + if (PRIVATE (a_this)) { + if (PRIVATE (a_this)->in_buf && PRIVATE (a_this)->free_in_buf) { + g_free (PRIVATE (a_this)->in_buf); + PRIVATE (a_this)->in_buf = NULL; } - g_free (PRIVATE (a_this)) ; - PRIVATE (a_this) = NULL ; + g_free (PRIVATE (a_this)); + PRIVATE (a_this) = NULL; } - g_free (a_this) ; + g_free (a_this); } - /** *Increments the reference count of the current *instance of #CRInput. *@param a_this the current instance of #CRInput. */ -void -cr_input_ref (CRInput *a_this) +void +cr_input_ref (CRInput * a_this) { - g_return_if_fail (a_this && PRIVATE (a_this)) ; - - PRIVATE (a_this)->ref_count ++ ; -} + g_return_if_fail (a_this && PRIVATE (a_this)); + PRIVATE (a_this)->ref_count++; +} /** *Decrements the reference count of this instance @@ -342,26 +306,23 @@ cr_input_ref (CRInput *a_this) *zero, this instance is destroyed. *@param a_this the current instance of #CRInput. * - */ + */ gboolean -cr_input_unref (CRInput *a_this) +cr_input_unref (CRInput * a_this) { - g_return_val_if_fail (a_this && PRIVATE (a_this), FALSE) ; - - if (PRIVATE (a_this)->ref_count) - { - PRIVATE (a_this)->ref_count -- ; + g_return_val_if_fail (a_this && PRIVATE (a_this), FALSE); + + if (PRIVATE (a_this)->ref_count) { + PRIVATE (a_this)->ref_count--; } - if (PRIVATE (a_this)->ref_count == 0) - { - cr_input_destroy (a_this) ; - return TRUE ; + if (PRIVATE (a_this)->ref_count == 0) { + cr_input_destroy (a_this); + return TRUE; } - return FALSE ; + return FALSE; } - /** *Tests wether the current instance of *#CRInput has reached its input buffer. @@ -374,18 +335,17 @@ cr_input_unref (CRInput *a_this) *and only if this method returns CR_OK. */ enum CRStatus -cr_input_end_of_input (CRInput *a_this, gboolean *a_end_of_input) +cr_input_end_of_input (CRInput * a_this, gboolean * a_end_of_input) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_end_of_input, CR_BAD_PARAM_ERROR) ; + && a_end_of_input, CR_BAD_PARAM_ERROR); - *a_end_of_input = (PRIVATE (a_this)->next_byte_index - >= PRIVATE (a_this)->in_buf_size)? TRUE : FALSE ; + *a_end_of_input = (PRIVATE (a_this)->next_byte_index + >= PRIVATE (a_this)->in_buf_size) ? TRUE : FALSE; - return CR_OK ; + return CR_OK; } - /** *Returns the number of bytes left in the input stream *before the end. @@ -393,21 +353,19 @@ cr_input_end_of_input (CRInput *a_this, gboolean *a_end_of_input) *@return the number of characters left or -1 in case of error. */ glong -cr_input_get_nb_bytes_left (CRInput *a_this) +cr_input_get_nb_bytes_left (CRInput * a_this) { - g_return_val_if_fail (a_this && PRIVATE (a_this), -1) ; - g_return_val_if_fail (PRIVATE (a_this)->nb_bytes - <= PRIVATE (a_this)->in_buf_size, -1) ; - g_return_val_if_fail (PRIVATE (a_this)->next_byte_index - <= PRIVATE (a_this)->nb_bytes, -1) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), -1); + g_return_val_if_fail (PRIVATE (a_this)->nb_bytes + <= PRIVATE (a_this)->in_buf_size, -1); + g_return_val_if_fail (PRIVATE (a_this)->next_byte_index + <= PRIVATE (a_this)->nb_bytes, -1); if (PRIVATE (a_this)->end_of_input) - return 0 ; - - return PRIVATE (a_this)->nb_bytes - - PRIVATE (a_this)->next_byte_index ; -} + return 0; + return PRIVATE (a_this)->nb_bytes - PRIVATE (a_this)->next_byte_index; +} /** *Returns the next byte of the input. @@ -422,38 +380,29 @@ cr_input_get_nb_bytes_left (CRInput *a_this) *and only if this method returns CR_OK. */ enum CRStatus -cr_input_read_byte (CRInput *a_this, guchar *a_byte) +cr_input_read_byte (CRInput * a_this, guchar * a_byte) { - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_byte, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_byte, CR_BAD_PARAM_ERROR); - g_return_val_if_fail (PRIVATE (a_this)->next_byte_index <= - PRIVATE (a_this)->nb_bytes, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (PRIVATE (a_this)->next_byte_index <= + PRIVATE (a_this)->nb_bytes, CR_BAD_PARAM_ERROR); if (PRIVATE (a_this)->end_of_input == TRUE) - return CR_END_OF_INPUT_ERROR ; + return CR_END_OF_INPUT_ERROR; - *a_byte = - PRIVATE - (a_this)->in_buf[PRIVATE (a_this)->next_byte_index] ; + *a_byte = PRIVATE (a_this)->in_buf[PRIVATE (a_this)->next_byte_index]; if (PRIVATE (a_this)->nb_bytes - - PRIVATE (a_this)->next_byte_index < 2) - { - PRIVATE (a_this)->end_of_input = TRUE ; - } - else - { - PRIVATE (a_this)->next_byte_index ++ ; + PRIVATE (a_this)->next_byte_index < 2) { + PRIVATE (a_this)->end_of_input = TRUE; + } else { + PRIVATE (a_this)->next_byte_index++; } - return CR_OK ; + return CR_OK; } - /** *Reads an unicode character from the current instance of *#CRInput. @@ -463,59 +412,52 @@ cr_input_read_byte (CRInput *a_this, guchar *a_byte) *otherwise. */ enum CRStatus -cr_input_read_char (CRInput *a_this, guint32 *a_char) +cr_input_read_char (CRInput * a_this, guint32 * a_char) { - enum CRStatus status = CR_OK ; - gulong consumed = 0, nb_bytes_left = 0 ; - + enum CRStatus status = CR_OK; + gulong consumed = 0, + nb_bytes_left = 0; + g_return_val_if_fail (a_this && PRIVATE (a_this) && a_char, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); if (PRIVATE (a_this)->end_of_input == TRUE) - return CR_END_OF_INPUT_ERROR ; + return CR_END_OF_INPUT_ERROR; - nb_bytes_left = cr_input_get_nb_bytes_left (a_this) ; + nb_bytes_left = cr_input_get_nb_bytes_left (a_this); - if (nb_bytes_left < 1) - { - return CR_END_OF_INPUT_ERROR ; + if (nb_bytes_left < 1) { + return CR_END_OF_INPUT_ERROR; } - status = - cr_utils_read_char_from_utf8_buf - (PRIVATE (a_this)->in_buf - + + status = cr_utils_read_char_from_utf8_buf + (PRIVATE (a_this)->in_buf + + PRIVATE (a_this)->next_byte_index, - nb_bytes_left, a_char, &consumed) ; - - if (status == CR_OK) - { - /*update next byte index*/ - PRIVATE (a_this)->next_byte_index += consumed ; - - /*update line and column number*/ - if (PRIVATE (a_this)->end_of_line == TRUE) - { - PRIVATE (a_this)->col = 1 ; - PRIVATE (a_this)->line ++ ; - PRIVATE (a_this)->end_of_line = FALSE ; - } - else if (*a_char != '\n') - { - PRIVATE (a_this)->col ++ ; + nb_bytes_left, a_char, &consumed); + + if (status == CR_OK) { + /*update next byte index */ + PRIVATE (a_this)->next_byte_index += consumed; + + /*update line and column number */ + if (PRIVATE (a_this)->end_of_line == TRUE) { + PRIVATE (a_this)->col = 1; + PRIVATE (a_this)->line++; + PRIVATE (a_this)->end_of_line = FALSE; + } else if (*a_char != '\n') { + PRIVATE (a_this)->col++; } - - if (*a_char == '\n') - { - PRIVATE (a_this)->end_of_line = TRUE ; + + if (*a_char == '\n') { + PRIVATE (a_this)->end_of_line = TRUE; } } - return status ; + return status; } - /** *Setter of the current line number. *@param a_this the "this pointer" of the current instance of @@ -524,17 +466,15 @@ cr_input_read_char (CRInput *a_this, guint32 *a_char) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_set_line_num (CRInput *a_this, glong a_line_num) +cr_input_set_line_num (CRInput * a_this, glong a_line_num) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->line = a_line_num ; + PRIVATE (a_this)->line = a_line_num; - return CR_OK ; + return CR_OK; } - /** *Getter of the current line number. *@param a_this the "this pointer" of the current instance of @@ -543,17 +483,15 @@ cr_input_set_line_num (CRInput *a_this, glong a_line_num) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_get_line_num (CRInput *a_this, glong *a_line_num) +cr_input_get_line_num (CRInput * a_this, glong * a_line_num) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_line_num, - CR_BAD_PARAM_ERROR) ; - - *a_line_num = PRIVATE (a_this)->line ; + && a_line_num, CR_BAD_PARAM_ERROR); - return CR_OK ; -} + *a_line_num = PRIVATE (a_this)->line; + return CR_OK; +} /** *Setter of the current column number. @@ -563,17 +501,15 @@ cr_input_get_line_num (CRInput *a_this, glong *a_line_num) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_set_column_num (CRInput *a_this, glong a_col) +cr_input_set_column_num (CRInput * a_this, glong a_col) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->col = a_col ; + PRIVATE (a_this)->col = a_col; - return CR_OK ; + return CR_OK; } - /** *Getter of the current column number. *@param a_this the "this pointer" of the current instance of @@ -582,16 +518,15 @@ cr_input_set_column_num (CRInput *a_this, glong a_col) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_get_column_num (CRInput *a_this, glong *a_col) +cr_input_get_column_num (CRInput * a_this, glong * a_col) { g_return_val_if_fail (a_this && PRIVATE (a_this) && a_col, - CR_BAD_PARAM_ERROR) ; - - *a_col = PRIVATE (a_this)->col ; + CR_BAD_PARAM_ERROR); - return CR_OK ; -} + *a_col = PRIVATE (a_this)->col; + return CR_OK; +} /** *Increments the current line number. @@ -600,16 +535,14 @@ cr_input_get_column_num (CRInput *a_this, glong *a_col) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_increment_line_num (CRInput *a_this, glong a_increment) +cr_input_increment_line_num (CRInput * a_this, glong a_increment) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - PRIVATE (a_this)->line += a_increment ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - return CR_OK ; -} + PRIVATE (a_this)->line += a_increment; + return CR_OK; +} /** *Increments the current column number. @@ -618,18 +551,15 @@ cr_input_increment_line_num (CRInput *a_this, glong a_increment) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_increment_col_num (CRInput *a_this, glong a_increment) +cr_input_increment_col_num (CRInput * a_this, glong a_increment) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->col += a_increment ; + PRIVATE (a_this)->col += a_increment; - return CR_OK ; + return CR_OK; } - - /** *Consumes the next character of the input stream if *and only if that character equals a_char. @@ -641,32 +571,26 @@ cr_input_increment_col_num (CRInput *a_this, glong a_increment) *next char is different from a_char, an other error code otherwise */ enum CRStatus -cr_input_consume_char (CRInput *a_this, guint32 a_char) +cr_input_consume_char (CRInput * a_this, guint32 a_char) { - guint32 c ; - enum CRStatus status ; + guint32 c; + enum CRStatus status; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - if ((status = cr_input_peek_char (a_this, &c)) != CR_OK) - { - return status ; + if ((status = cr_input_peek_char (a_this, &c)) != CR_OK) { + return status; } - if (c == a_char || a_char == 0) - { - status = cr_input_read_char (a_this, &c) ; - } - else - { - return CR_PARSING_ERROR ; + if (c == a_char || a_char == 0) { + status = cr_input_read_char (a_this, &c); + } else { + return CR_PARSING_ERROR; } - return status ; + return status; } - /** *Consumes up to a_nb_char occurences of the next contiguous characters *which equal a_char. Note that the next character of the input stream @@ -686,35 +610,33 @@ cr_input_consume_char (CRInput *a_this, guint32 a_char) *otherwise. */ enum CRStatus -cr_input_consume_chars (CRInput *a_this, guint32 a_char, gulong *a_nb_char) +cr_input_consume_chars (CRInput * a_this, guint32 a_char, gulong * a_nb_char) { - enum CRStatus status = CR_OK ; - gulong nb_consumed = 0 ; + enum CRStatus status = CR_OK; + gulong nb_consumed = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_nb_char, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); g_return_val_if_fail (a_char != 0 || a_nb_char != NULL, - CR_BAD_PARAM_ERROR) ; - - for (nb_consumed = 0 ; - ((status == CR_OK) - && (*a_nb_char > 0 && nb_consumed < *a_nb_char)) ; - nb_consumed ++) - { - status = cr_input_consume_char (a_this, a_char) ; + CR_BAD_PARAM_ERROR); + + for (nb_consumed = 0; ((status == CR_OK) + && (*a_nb_char > 0 + && nb_consumed < *a_nb_char)); + nb_consumed++) { + status = cr_input_consume_char (a_this, a_char); } - *a_nb_char = nb_consumed ; + *a_nb_char = nb_consumed; - if ((nb_consumed > 0) - && ((status == CR_PARSING_ERROR) - || (status == CR_END_OF_INPUT_ERROR))) - { - status = CR_OK ; + if ((nb_consumed > 0) + && ((status == CR_PARSING_ERROR) + || (status == CR_END_OF_INPUT_ERROR))) { + status = CR_OK; } - return status ; + return status; } /** @@ -727,41 +649,40 @@ cr_input_consume_chars (CRInput *a_this, guint32 a_char, gulong *a_nb_char) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_consume_white_spaces (CRInput *a_this, gulong *a_nb_chars) +cr_input_consume_white_spaces (CRInput * a_this, gulong * a_nb_chars) { - enum CRStatus status = CR_OK ; - guint32 cur_char = 0, nb_consumed = 0 ; + enum CRStatus status = CR_OK; + guint32 cur_char = 0, + nb_consumed = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_nb_chars, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); for (nb_consumed = 0; - ((*a_nb_chars > 0) && (nb_consumed < *a_nb_chars)) ; - nb_consumed ++) - { - status = cr_input_peek_char (a_this, &cur_char) ; - if (status != CR_OK) break ; - - /*if the next char is a white space, consume it !*/ - if (cr_utils_is_white_space (cur_char) == TRUE) - { - status = cr_input_read_char (a_this, &cur_char) ; - if (status != CR_OK) break ; - continue ; + ((*a_nb_chars > 0) && (nb_consumed < *a_nb_chars)); + nb_consumed++) { + status = cr_input_peek_char (a_this, &cur_char); + if (status != CR_OK) + break; + + /*if the next char is a white space, consume it ! */ + if (cr_utils_is_white_space (cur_char) == TRUE) { + status = cr_input_read_char (a_this, &cur_char); + if (status != CR_OK) + break; + continue; } - - break ; - + + break; + } - if (nb_consumed && status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; + if (nb_consumed && status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; } - - return status ; -} + return status; +} /** *Same as cr_input_read_char() but does not update the @@ -774,38 +695,34 @@ cr_input_consume_white_spaces (CRInput *a_this, gulong *a_nb_chars) *otherwise. */ enum CRStatus -cr_input_peek_char (CRInput *a_this, guint32 *a_char) +cr_input_peek_char (CRInput * a_this, guint32 * a_char) { - enum CRStatus status = CR_OK ; - glong consumed = 0, nb_bytes_left = 0 ; + enum CRStatus status = CR_OK; + glong consumed = 0, + nb_bytes_left = 0; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_char, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_char, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->next_byte_index >= - PRIVATE (a_this)->in_buf_size) - { - return CR_END_OF_INPUT_ERROR ; + if (PRIVATE (a_this)->next_byte_index >= + PRIVATE (a_this)->in_buf_size) { + return CR_END_OF_INPUT_ERROR; } - nb_bytes_left = cr_input_get_nb_bytes_left (a_this) ; + nb_bytes_left = cr_input_get_nb_bytes_left (a_this); - if (nb_bytes_left < 1) - { - return CR_END_OF_INPUT_ERROR ; + if (nb_bytes_left < 1) { + return CR_END_OF_INPUT_ERROR; } - status = - cr_utils_read_char_from_utf8_buf - (PRIVATE (a_this)->in_buf + + status = cr_utils_read_char_from_utf8_buf + (PRIVATE (a_this)->in_buf + PRIVATE (a_this)->next_byte_index, - nb_bytes_left, a_char, &consumed) ; + nb_bytes_left, a_char, &consumed); - return status ; + return status; } - - /** *Gets a byte from the input stream, *starting from the current position in the input stream. @@ -828,45 +745,40 @@ cr_input_peek_char (CRInput *a_this, guint32 *a_char) * */ enum CRStatus -cr_input_peek_byte (CRInput *a_this, enum CRSeekPos a_origin, - gulong a_offset, guchar *a_byte) +cr_input_peek_byte (CRInput * a_this, enum CRSeekPos a_origin, + gulong a_offset, guchar * a_byte) { - gulong abs_offset = 0 ; + gulong abs_offset = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_byte, - CR_BAD_PARAM_ERROR) ; - + && a_byte, CR_BAD_PARAM_ERROR); switch (a_origin) { case CR_SEEK_CUR: - abs_offset = - PRIVATE (a_this)->next_byte_index - 1 + a_offset ; - break ; + abs_offset = PRIVATE (a_this)->next_byte_index - 1 + a_offset; + break; case CR_SEEK_BEGIN: - abs_offset = a_offset ; - break ; + abs_offset = a_offset; + break; case CR_SEEK_END: - abs_offset = - PRIVATE (a_this)->in_buf_size - 1 - a_offset ; + abs_offset = PRIVATE (a_this)->in_buf_size - 1 - a_offset; break; default: - return CR_BAD_PARAM_ERROR ; + return CR_BAD_PARAM_ERROR; } if (abs_offset < PRIVATE (a_this)->in_buf_size) { - *a_byte = - PRIVATE (a_this)->in_buf[abs_offset] ; + *a_byte = PRIVATE (a_this)->in_buf[abs_offset]; - return CR_OK ; + return CR_OK; } else { - return CR_END_OF_INPUT_ERROR ; + return CR_END_OF_INPUT_ERROR; } } @@ -881,30 +793,26 @@ cr_input_peek_byte (CRInput *a_this, enum CRSeekPos a_origin, *in account. *@return the read byte or 0 if something bad happened. */ -guchar -cr_input_peek_byte2 (CRInput *a_this, gulong a_offset, - gboolean *a_eof) +guchar +cr_input_peek_byte2 (CRInput * a_this, gulong a_offset, gboolean * a_eof) { - guchar result = 0 ; - enum CRStatus status = CR_ERROR ; + guchar result = 0; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this && PRIVATE (a_this), - 0) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), 0); - if (a_eof) - *a_eof = FALSE ; + if (a_eof) + *a_eof = FALSE; - status = cr_input_peek_byte (a_this, CR_SEEK_CUR, a_offset, - &result) ; + status = cr_input_peek_byte (a_this, CR_SEEK_CUR, a_offset, &result); if ((status == CR_END_OF_INPUT_ERROR) && a_eof) - *a_eof = TRUE ; + *a_eof = TRUE; - return result ; + return result; } - /** *Returns the memory address of the byte located at a given offset *in the input stream. @@ -914,17 +822,15 @@ cr_input_peek_byte2 (CRInput *a_this, gulong a_offset, *@return the address, otherwise NULL if an error occured. */ guchar * -cr_input_get_byte_addr (CRInput *a_this, - gulong a_offset) +cr_input_get_byte_addr (CRInput * a_this, gulong a_offset) { - g_return_val_if_fail (a_this && PRIVATE (a_this), NULL) ; - - if (a_offset >= PRIVATE (a_this)->nb_bytes) - { - return NULL ; + g_return_val_if_fail (a_this && PRIVATE (a_this), NULL); + + if (a_offset >= PRIVATE (a_this)->nb_bytes) { + return NULL; } - return &PRIVATE (a_this)->in_buf[a_offset] ; + return &PRIVATE (a_this)->in_buf[a_offset]; } /** @@ -934,20 +840,19 @@ cr_input_get_byte_addr (CRInput *a_this, *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_get_cur_byte_addr (CRInput *a_this, guchar ** a_offset) +cr_input_get_cur_byte_addr (CRInput * a_this, guchar ** a_offset) { g_return_val_if_fail (a_this && PRIVATE (a_this) && a_offset, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); - if (!PRIVATE (a_this)->next_byte_index) - { - return CR_START_OF_INPUT_ERROR ; + if (!PRIVATE (a_this)->next_byte_index) { + return CR_START_OF_INPUT_ERROR; } - *a_offset = cr_input_get_byte_addr - (a_this, PRIVATE (a_this)->next_byte_index -1) ; + *a_offset = cr_input_get_byte_addr + (a_this, PRIVATE (a_this)->next_byte_index - 1); - return CR_OK ; + return CR_OK; } /** @@ -970,47 +875,43 @@ cr_input_get_cur_byte_addr (CRInput *a_this, guchar ** a_offset) * */ enum CRStatus -cr_input_seek_index (CRInput *a_this, enum CRSeekPos a_origin, gint a_pos) +cr_input_seek_index (CRInput * a_this, enum CRSeekPos a_origin, gint a_pos) { - glong abs_offset = 0 ; + glong abs_offset = 0; - g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - switch (a_origin) { case CR_SEEK_CUR: - abs_offset = - PRIVATE (a_this)->next_byte_index - 1 + a_pos ; - break ; + abs_offset = PRIVATE (a_this)->next_byte_index - 1 + a_pos; + break; case CR_SEEK_BEGIN: - abs_offset = a_pos ; - break ; + abs_offset = a_pos; + break; case CR_SEEK_END: - abs_offset = - PRIVATE (a_this)->in_buf_size - 1 - a_pos ; - break ; + abs_offset = PRIVATE (a_this)->in_buf_size - 1 - a_pos; + break; default: - return CR_BAD_PARAM_ERROR ; + return CR_BAD_PARAM_ERROR; } if ((abs_offset > 0) && (gulong) abs_offset < PRIVATE (a_this)->nb_bytes) { - /*update the input stream's internal state*/ - PRIVATE (a_this)->next_byte_index = abs_offset + 1 ; + /*update the input stream's internal state */ + PRIVATE (a_this)->next_byte_index = abs_offset + 1; - return CR_OK ; + return CR_OK; } - return CR_OUT_OF_BOUNDS_ERROR ; + return CR_OUT_OF_BOUNDS_ERROR; } - /** *Gets the position of the "current byte index" which *is basically the position of the last returned byte in the @@ -1031,20 +932,19 @@ cr_input_seek_index (CRInput *a_this, enum CRSeekPos a_origin, gint a_pos) *function returns CR_OK. */ enum CRStatus -cr_input_get_cur_pos (CRInput *a_this, CRInputPos * a_pos) +cr_input_get_cur_pos (CRInput * a_this, CRInputPos * a_pos) { g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pos, - CR_BAD_PARAM_ERROR) ; - - a_pos->next_byte_index = PRIVATE (a_this)->next_byte_index ; - a_pos->line = PRIVATE (a_this)->line ; - a_pos->col = PRIVATE (a_this)->col ; - a_pos->end_of_line = PRIVATE (a_this)->end_of_line ; - a_pos->end_of_file = PRIVATE (a_this)->end_of_input ; - - return CR_OK ; -} + CR_BAD_PARAM_ERROR); + a_pos->next_byte_index = PRIVATE (a_this)->next_byte_index; + a_pos->line = PRIVATE (a_this)->line; + a_pos->col = PRIVATE (a_this)->col; + a_pos->end_of_line = PRIVATE (a_this)->end_of_line; + a_pos->end_of_file = PRIVATE (a_this)->end_of_input; + + return CR_OK; +} /** *Getter of the next byte index. @@ -1057,18 +957,16 @@ cr_input_get_cur_pos (CRInput *a_this, CRInputPos * a_pos) *otherwise. */ enum CRStatus -cr_input_get_cur_index (CRInput *a_this, glong *a_index) +cr_input_get_cur_index (CRInput * a_this, glong * a_index) { - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_index, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_index, CR_BAD_PARAM_ERROR); - *a_index = PRIVATE (a_this)->next_byte_index ; + *a_index = PRIVATE (a_this)->next_byte_index; - return CR_OK ; + return CR_OK; } - /** *Setter of the next byte index. *It sets the index of the next byte to be read. @@ -1078,16 +976,14 @@ cr_input_get_cur_index (CRInput *a_this, glong *a_index) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_set_cur_index (CRInput *a_this, glong a_index) +cr_input_set_cur_index (CRInput * a_this, glong a_index) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - PRIVATE (a_this)->next_byte_index = a_index ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - return CR_OK ; -} + PRIVATE (a_this)->next_byte_index = a_index; + return CR_OK; +} /** *Sets the end of file flag. @@ -1096,14 +992,13 @@ cr_input_set_cur_index (CRInput *a_this, glong a_index) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_set_end_of_file (CRInput *a_this, gboolean a_eof) +cr_input_set_end_of_file (CRInput * a_this, gboolean a_eof) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->end_of_input = a_eof ; + PRIVATE (a_this)->end_of_input = a_eof; - return CR_OK ; + return CR_OK; } /** @@ -1114,18 +1009,16 @@ cr_input_set_end_of_file (CRInput *a_this, gboolean a_eof) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_input_get_end_of_file (CRInput *a_this, gboolean *a_eof) +cr_input_get_end_of_file (CRInput * a_this, gboolean * a_eof) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_eof, - CR_BAD_PARAM_ERROR) ; + && a_eof, CR_BAD_PARAM_ERROR); - *a_eof = PRIVATE (a_this)->end_of_input ; + *a_eof = PRIVATE (a_this)->end_of_input; - return CR_OK ; + return CR_OK; } - /** *Sets the end of line flag. *@param a_this the current instance of #CRInput. @@ -1134,14 +1027,13 @@ cr_input_get_end_of_file (CRInput *a_this, gboolean *a_eof) *otherwise. */ enum CRStatus -cr_input_set_end_of_line (CRInput *a_this, gboolean a_eol) +cr_input_set_end_of_line (CRInput * a_this, gboolean a_eol) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->end_of_line = a_eol ; + PRIVATE (a_this)->end_of_line = a_eol; - return CR_OK ; + return CR_OK; } /** @@ -1153,18 +1045,16 @@ cr_input_set_end_of_line (CRInput *a_this, gboolean a_eol) *otherwise. */ enum CRStatus -cr_input_get_end_of_line (CRInput *a_this, gboolean *a_eol) +cr_input_get_end_of_line (CRInput * a_this, gboolean * a_eol) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_eol, - CR_BAD_PARAM_ERROR) ; + && a_eol, CR_BAD_PARAM_ERROR); - *a_eol = PRIVATE (a_this)->end_of_line ; + *a_eol = PRIVATE (a_this)->end_of_line; - return CR_OK ; + return CR_OK; } - /** *Sets the current position in the input stream. * @@ -1173,16 +1063,16 @@ cr_input_get_end_of_line (CRInput *a_this, gboolean *a_eol) *@param a_pos the new position. */ enum CRStatus -cr_input_set_cur_pos (CRInput *a_this, CRInputPos *a_pos) +cr_input_set_cur_pos (CRInput * a_this, CRInputPos * a_pos) { g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pos, - CR_BAD_PARAM_ERROR) ; - - cr_input_set_column_num (a_this, a_pos->col) ; - cr_input_set_line_num (a_this, a_pos->line) ; - cr_input_set_cur_index (a_this, a_pos->next_byte_index) ; - cr_input_set_end_of_line (a_this, a_pos->end_of_line) ; - cr_input_set_end_of_file (a_this, a_pos->end_of_file) ; - - return CR_OK ; + CR_BAD_PARAM_ERROR); + + cr_input_set_column_num (a_this, a_pos->col); + cr_input_set_line_num (a_this, a_pos->line); + cr_input_set_cur_index (a_this, a_pos->next_byte_index); + cr_input_set_end_of_line (a_this, a_pos->end_of_line); + cr_input_set_end_of_file (a_this, a_pos->end_of_file); + + return CR_OK; } diff --git a/src/cr-num.c b/src/cr-num.c index 3678c10..374a5da 100644 --- a/src/cr-num.c +++ b/src/cr-num.c @@ -33,7 +33,6 @@ #include "cr-num.h" #include "string.h" - /** *The default constructor of *#CRNum. @@ -43,21 +42,19 @@ CRNum * cr_num_new (void) { - CRNum * result = NULL ; - - result = g_try_malloc (sizeof (CRNum)) ; + CRNum *result = NULL; - if (result == NULL) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + result = g_try_malloc (sizeof (CRNum)); - memset (result, 0, sizeof (CRNum)) ; + if (result == NULL) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - return result ; -} + memset (result, 0, sizeof (CRNum)); + return result; +} /** *A constructor of #CRNum. @@ -72,19 +69,18 @@ cr_num_new (void) *NULL if an error arises. */ CRNum * -cr_num_new_with_val (gdouble a_val, - enum CRNumType a_type) +cr_num_new_with_val (gdouble a_val, enum CRNumType a_type) { - CRNum * result = NULL ; + CRNum *result = NULL; + + result = cr_num_new (); - result = cr_num_new () ; - - g_return_val_if_fail (result, NULL) ; + g_return_val_if_fail (result, NULL); - result->val = a_val ; - result->type = a_type ; + result->val = a_val; + result->type = a_type; - return result ; + return result; } /** @@ -97,108 +93,103 @@ cr_num_new_with_val (gdouble a_val, *free the returned string. */ guchar * -cr_num_to_string (CRNum *a_this) +cr_num_to_string (CRNum * a_this) { - gdouble test_val = 0.0 ; + gdouble test_val = 0.0; + + guchar *tmp_char1 = NULL, + *tmp_char2 = NULL, + *result = NULL; - guchar *tmp_char1 = NULL, * tmp_char2 = NULL, *result = NULL ; + g_return_val_if_fail (a_this, NULL); - g_return_val_if_fail (a_this, NULL) ; - - test_val = a_this->val - (glong) a_this->val ; + test_val = a_this->val - (glong) a_this->val; - if (!test_val) - { - tmp_char1 = g_strdup_printf ("%ld", (glong)a_this->val) ; - } - else - { - tmp_char1 = g_strdup_printf ("%.3f", a_this->val) ; + if (!test_val) { + tmp_char1 = g_strdup_printf ("%ld", (glong) a_this->val); + } else { + tmp_char1 = g_strdup_printf ("%.3f", a_this->val); } - - g_return_val_if_fail (tmp_char1, NULL) ; - switch (a_this->type) - { - case NUM_LENGTH_EM: - tmp_char2 = (guchar*) "em"; - break ; + g_return_val_if_fail (tmp_char1, NULL); + + switch (a_this->type) { + case NUM_LENGTH_EM: + tmp_char2 = (guchar *) "em"; + break; case NUM_LENGTH_EX: - tmp_char2 = (guchar*) "ex"; - break ; - + tmp_char2 = (guchar *) "ex"; + break; + case NUM_LENGTH_PX: - tmp_char2 = (guchar*) "px"; - break ; + tmp_char2 = (guchar *) "px"; + break; case NUM_LENGTH_IN: - tmp_char2 = (guchar*) "in"; - break ; - + tmp_char2 = (guchar *) "in"; + break; + case NUM_LENGTH_CM: - tmp_char2 = (guchar*) "cm"; - break ; + tmp_char2 = (guchar *) "cm"; + break; case NUM_LENGTH_MM: - tmp_char2 = (guchar*) "mm"; - break ; + tmp_char2 = (guchar *) "mm"; + break; case NUM_LENGTH_PT: - tmp_char2 = (guchar*) "pt"; - break ; + tmp_char2 = (guchar *) "pt"; + break; case NUM_LENGTH_PC: - tmp_char2 = (guchar*) "pc"; - break ; - + tmp_char2 = (guchar *) "pc"; + break; + case NUM_ANGLE_DEG: - tmp_char2 = (guchar*) "deg"; - break ; + tmp_char2 = (guchar *) "deg"; + break; case NUM_ANGLE_RAD: - tmp_char2 = (guchar*) "rad"; - break ; + tmp_char2 = (guchar *) "rad"; + break; case NUM_ANGLE_GRAD: - tmp_char2 = (guchar*) "grad"; - break ; + tmp_char2 = (guchar *) "grad"; + break; case NUM_TIME_MS: - tmp_char2 = (guchar*) "ms"; - break ; + tmp_char2 = (guchar *) "ms"; + break; case NUM_TIME_S: - tmp_char2 = (guchar*) "s"; - break ; + tmp_char2 = (guchar *) "s"; + break; case NUM_FREQ_HZ: - tmp_char2 = (guchar*) "Hz"; - break ; + tmp_char2 = (guchar *) "Hz"; + break; case NUM_FREQ_KHZ: - tmp_char2 = (guchar*) "KHz"; - break ; + tmp_char2 = (guchar *) "KHz"; + break; case NUM_PERCENTAGE: - tmp_char2 = (guchar*) "%"; - break ; + tmp_char2 = (guchar *) "%"; + break; default: - break ; + break; } - if (tmp_char2) - { - result = g_strconcat (tmp_char1, tmp_char2, NULL) ; - g_free (tmp_char1) ; - } - else - { - result = tmp_char1 ; + if (tmp_char2) { + result = g_strconcat (tmp_char1, tmp_char2, NULL); + g_free (tmp_char1); + } else { + result = tmp_char1; } - return result ; + return result; } /** @@ -211,17 +202,15 @@ cr_num_to_string (CRNum *a_this) *error code otherwise. */ enum CRStatus -cr_num_copy (CRNum *a_dest, CRNum *a_src) +cr_num_copy (CRNum * a_dest, CRNum * a_src) { - g_return_val_if_fail (a_dest && a_src, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_dest && a_src, CR_BAD_PARAM_ERROR); - memcpy (a_dest, a_src, sizeof (CRNum)) ; + memcpy (a_dest, a_src, sizeof (CRNum)); - return CR_OK ; + return CR_OK; } - /** *Duplicates an instance of #CRNum *@param a_this the instance of #CRNum to duplicate. @@ -229,20 +218,20 @@ cr_num_copy (CRNum *a_dest, CRNum *a_src) *Must be freed by cr_num_destroy(). */ CRNum * -cr_num_dup (CRNum *a_this) +cr_num_dup (CRNum * a_this) { - CRNum *result = NULL ; - enum CRStatus status = CR_OK ; + CRNum *result = NULL; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - result = cr_num_new () ; - g_return_val_if_fail (result, NULL) ; + result = cr_num_new (); + g_return_val_if_fail (result, NULL); - status = cr_num_copy (result, a_this) ; - g_return_val_if_fail (status == CR_OK, NULL) ; + status = cr_num_copy (result, a_this); + g_return_val_if_fail (status == CR_OK, NULL); - return result ; + return result; } /** @@ -253,14 +242,14 @@ cr_num_dup (CRNum *a_this) *@param a_type the new type of #CRNum. */ enum CRStatus -cr_num_set (CRNum *a_this, gdouble a_val, enum CRNumType a_type) +cr_num_set (CRNum * a_this, gdouble a_val, enum CRNumType a_type) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - a_this->val= a_val ; - a_this->type = a_type ; + a_this->val = a_val; + a_this->type = a_type; - return CR_OK ; + return CR_OK; } /** @@ -272,23 +261,22 @@ cr_num_set (CRNum *a_this, gdouble a_val, enum CRNumType a_type) *FALSE otherwise. */ gboolean -cr_num_is_fixed_length (CRNum *a_this) +cr_num_is_fixed_length (CRNum * a_this) { - gboolean result = FALSE ; + gboolean result = FALSE; - g_return_val_if_fail (a_this, FALSE) ; + g_return_val_if_fail (a_this, FALSE); - switch (a_this->type) - { - case NUM_LENGTH_EM ... NUM_LENGTH_PC: - result = TRUE ; - break ; + switch (a_this->type) { + case NUM_LENGTH_EM...NUM_LENGTH_PC: + result = TRUE; + break; default: - result = FALSE ; - break ; + result = FALSE; + break; } - return result ; + return result; } /** @@ -297,9 +285,9 @@ cr_num_is_fixed_length (CRNum *a_this) *the current instance of #CRNum. */ void -cr_num_destroy (CRNum *a_this) +cr_num_destroy (CRNum * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - g_free (a_this) ; + g_free (a_this); } diff --git a/src/cr-om-parser.c b/src/cr-om-parser.c index 077ef37..d1b85e3 100644 --- a/src/cr-om-parser.c +++ b/src/cr-om-parser.c @@ -35,10 +35,9 @@ *in cr-parser.h and cr-doc-handler.h */ -struct _CROMParserPriv -{ - CRParser *parser ; -} ; +struct _CROMParserPriv { + CRParser *parser; +}; #define PRIVATE(a_this) ((a_this)->priv) @@ -46,76 +45,67 @@ struct _CROMParserPriv *Forward declaration of a type defined later *in this file. */ -struct _ParsingContext ; -typedef struct _ParsingContext ParsingContext ; +struct _ParsingContext; +typedef struct _ParsingContext ParsingContext; -static ParsingContext * -new_parsing_context (void) ; +static ParsingContext *new_parsing_context (void); static void -destroy_context (ParsingContext *a_ctxt) ; + destroy_context (ParsingContext * a_ctxt); static void -unrecoverable_error (CRDocHandler *a_this) ; + unrecoverable_error (CRDocHandler * a_this); static void -error (CRDocHandler *a_this) ; + error (CRDocHandler * a_this); static void -property (CRDocHandler *a_this, - GString *a_name, - CRTerm *a_expression, - gboolean a_important) ; + property (CRDocHandler * a_this, + GString * a_name, CRTerm * a_expression, gboolean a_important); static void -end_selector (CRDocHandler *a_this, - CRSelector *a_selector_list) ; + end_selector (CRDocHandler * a_this, CRSelector * a_selector_list); static void -start_selector (CRDocHandler *a_this, - CRSelector *a_selector_list) ; + start_selector (CRDocHandler * a_this, CRSelector * a_selector_list); static void -start_font_face (CRDocHandler *a_this) ; + start_font_face (CRDocHandler * a_this); static void -end_font_face (CRDocHandler *a_this) ; - -static void -end_document (CRDocHandler *a_this) ; + end_font_face (CRDocHandler * a_this); static void -start_document (CRDocHandler *a_this) ; + end_document (CRDocHandler * a_this); static void -charset (CRDocHandler *a_this, GString *a_charset) ; + start_document (CRDocHandler * a_this); static void -start_page (CRDocHandler *a_this, GString *a_page, - GString *a_pseudo_page) ; + charset (CRDocHandler * a_this, GString * a_charset); static void -end_page (CRDocHandler *a_this, GString *a_page, - GString *a_pseudo_page) ; + start_page (CRDocHandler * a_this, GString * a_page, + GString * a_pseudo_page); static void -start_media (CRDocHandler *a_this, GList *a_media_list) ; + end_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo_page); static void -end_media (CRDocHandler *a_this, GList *a_media_list) ; + start_media (CRDocHandler * a_this, GList * a_media_list); static void -import_style (CRDocHandler *a_this, GList *a_media_list, - GString *a_uri, GString *a_uri_default_ns) ; + end_media (CRDocHandler * a_this, GList * a_media_list); +static void + import_style (CRDocHandler * a_this, GList * a_media_list, + GString * a_uri, GString * a_uri_default_ns); -struct _ParsingContext -{ - CRStyleSheet *stylesheet ; - CRStatement *cur_stmt ; - CRStatement *cur_media_stmt ; -} ; - +struct _ParsingContext { + CRStyleSheet *stylesheet; + CRStatement *cur_stmt; + CRStatement *cur_media_stmt; +}; /******************************************** *Private methods @@ -124,704 +114,635 @@ struct _ParsingContext static ParsingContext * new_parsing_context (void) { - ParsingContext *result = NULL ; + ParsingContext *result = NULL; - result = g_try_malloc (sizeof (ParsingContext)) ; - if (!result) - { - cr_utils_trace_info ("Out of Memory") ; - return NULL ; + result = g_try_malloc (sizeof (ParsingContext)); + if (!result) { + cr_utils_trace_info ("Out of Memory"); + return NULL; } - memset (result, 0, sizeof (ParsingContext)) ; - return result ; + memset (result, 0, sizeof (ParsingContext)); + return result; } static void -destroy_context (ParsingContext *a_ctxt) +destroy_context (ParsingContext * a_ctxt) { - g_return_if_fail (a_ctxt) ; - - if (a_ctxt->stylesheet) - { - cr_stylesheet_destroy (a_ctxt->stylesheet) ; - a_ctxt->stylesheet = NULL ; + g_return_if_fail (a_ctxt); + + if (a_ctxt->stylesheet) { + cr_stylesheet_destroy (a_ctxt->stylesheet); + a_ctxt->stylesheet = NULL; } - if (a_ctxt->cur_stmt) - { - cr_statement_destroy (a_ctxt->cur_stmt) ; - a_ctxt->cur_stmt = NULL ; + if (a_ctxt->cur_stmt) { + cr_statement_destroy (a_ctxt->cur_stmt); + a_ctxt->cur_stmt = NULL; } - g_free (a_ctxt) ; + g_free (a_ctxt); } - static enum CRStatus -cr_om_parser_init_default_sac_handler (CROMParser *a_this) +cr_om_parser_init_default_sac_handler (CROMParser * a_this) { - CRDocHandler *sac_handler = NULL ; - gboolean free_hdlr_if_error = FALSE ; - enum CRStatus status = CR_OK ; + CRDocHandler *sac_handler = NULL; + gboolean free_hdlr_if_error = FALSE; + enum CRStatus status = CR_OK; g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->parser, - CR_BAD_PARAM_ERROR) ; - + CR_BAD_PARAM_ERROR); + status = cr_parser_get_sac_handler (PRIVATE (a_this)->parser, - &sac_handler) ; - g_return_val_if_fail (status == CR_OK, status) ; + &sac_handler); + g_return_val_if_fail (status == CR_OK, status); - if (!sac_handler) - { + if (!sac_handler) { sac_handler = cr_doc_handler_new (); - free_hdlr_if_error = TRUE ; + free_hdlr_if_error = TRUE; } /* *initialyze here the sac handler. */ - sac_handler->start_document = start_document ; - sac_handler->end_document = end_document ; - sac_handler->start_selector = start_selector ; + sac_handler->start_document = start_document; + sac_handler->end_document = end_document; + sac_handler->start_selector = start_selector; sac_handler->end_selector = end_selector; - sac_handler->property = property ; - sac_handler->start_font_face = start_font_face ; - sac_handler->end_font_face = end_font_face ; - sac_handler->error = error ; - sac_handler->unrecoverable_error = unrecoverable_error ; - sac_handler->charset = charset ; - sac_handler->start_page = start_page ; - sac_handler->end_page = end_page ; - sac_handler->start_media = start_media ; - sac_handler->end_media = end_media ; - sac_handler->import_style = import_style ; + sac_handler->property = property; + sac_handler->start_font_face = start_font_face; + sac_handler->end_font_face = end_font_face; + sac_handler->error = error; + sac_handler->unrecoverable_error = unrecoverable_error; + sac_handler->charset = charset; + sac_handler->start_page = start_page; + sac_handler->end_page = end_page; + sac_handler->start_media = start_media; + sac_handler->end_media = end_media; + sac_handler->import_style = import_style; status = cr_parser_set_sac_handler (PRIVATE (a_this)->parser, - sac_handler) ; - if (status == CR_OK) - { + sac_handler); + if (status == CR_OK) { return CR_OK; } - if (sac_handler && free_hdlr_if_error == TRUE) - { - cr_doc_handler_destroy (sac_handler) ; - sac_handler = NULL ; + if (sac_handler && free_hdlr_if_error == TRUE) { + cr_doc_handler_destroy (sac_handler); + sac_handler = NULL; } - return status ; + return status; } static void -start_document (CRDocHandler *a_this) +start_document (CRDocHandler * a_this) { - ParsingContext *ctxt = NULL ; - CRStyleSheet * stylesheet = NULL ; - - g_return_if_fail (a_this) ; - - ctxt = new_parsing_context () ; - g_return_if_fail (ctxt) ; - - stylesheet = cr_stylesheet_new (NULL) ; - ctxt->stylesheet = stylesheet ; - cr_doc_handler_set_ctxt (a_this, ctxt) ; + ParsingContext *ctxt = NULL; + CRStyleSheet *stylesheet = NULL; + + g_return_if_fail (a_this); + + ctxt = new_parsing_context (); + g_return_if_fail (ctxt); + + stylesheet = cr_stylesheet_new (NULL); + ctxt->stylesheet = stylesheet; + cr_doc_handler_set_ctxt (a_this, ctxt); } static void -start_font_face (CRDocHandler *a_this) +start_font_face (CRDocHandler * a_this) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this) ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + + g_return_if_fail (a_this); - g_return_if_fail (a_this) ; - status = cr_doc_handler_get_ctxt (a_this, (gpointer*) &ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail (ctxt->cur_stmt == NULL) ; + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt == NULL); - ctxt->cur_stmt = - cr_statement_new_at_font_face_rule - (ctxt->stylesheet, NULL) ; + ctxt->cur_stmt = + cr_statement_new_at_font_face_rule (ctxt->stylesheet, NULL); - g_return_if_fail (ctxt->cur_stmt) ; + g_return_if_fail (ctxt->cur_stmt); } static void -end_font_face (CRDocHandler *a_this) +end_font_face (CRDocHandler * a_this) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - CRStatement *stmts = NULL ; - - g_return_if_fail (a_this) ; - - g_return_if_fail (a_this) ; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*) &ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail - (ctxt->cur_stmt + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + CRStatement *stmts = NULL; + + g_return_if_fail (a_this); + + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail + (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT - && ctxt->stylesheet) ; - + && ctxt->stylesheet); + stmts = cr_statement_append (ctxt->stylesheet->statements, - ctxt->cur_stmt) ; + ctxt->cur_stmt); if (!stmts) - goto error ; + goto error; + + ctxt->stylesheet->statements = stmts; + stmts = NULL; + ctxt->cur_stmt = NULL; - ctxt->stylesheet->statements = stmts ; - stmts = NULL ; - ctxt->cur_stmt = NULL ; + return; - return ; - - error: + error: - if (ctxt->cur_stmt) - { - cr_statement_destroy (ctxt->cur_stmt) ; - ctxt->cur_stmt = NULL ; + if (ctxt->cur_stmt) { + cr_statement_destroy (ctxt->cur_stmt); + ctxt->cur_stmt = NULL; } - if (!stmts) - { - cr_statement_destroy (stmts) ; + if (!stmts) { + cr_statement_destroy (stmts); stmts = NULL; - } + } } - -static void -end_document (CRDocHandler *a_this) +static void +end_document (CRDocHandler * a_this) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; - g_return_if_fail (a_this) ; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); if (!ctxt->stylesheet || ctxt->cur_stmt) - goto error ; + goto error; - status = cr_doc_handler_set_result (a_this, ctxt->stylesheet) ; - g_return_if_fail (status == CR_OK) ; - - ctxt->stylesheet = NULL ; - destroy_context (ctxt) ; - cr_doc_handler_set_ctxt (a_this, NULL) ; + status = cr_doc_handler_set_result (a_this, ctxt->stylesheet); + g_return_if_fail (status == CR_OK); - return ; + ctxt->stylesheet = NULL; + destroy_context (ctxt); + cr_doc_handler_set_ctxt (a_this, NULL); - error: - if (ctxt) - { - destroy_context (ctxt) ; + return; + + error: + if (ctxt) { + destroy_context (ctxt); } } static void -charset (CRDocHandler *a_this, GString *a_charset) +charset (CRDocHandler * a_this, GString * a_charset) { - enum CRStatus status = CR_OK ; - CRStatement *stmt = NULL, *stmt2 = NULL ; - GString * charset = NULL ; - - ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this) ; - - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail (ctxt->stylesheet) ; - - charset = g_string_new_len (a_charset->str, - a_charset->len) ; - - stmt = cr_statement_new_at_charset_rule - (ctxt->stylesheet, charset) ; - g_return_if_fail (stmt) ; - - stmt2 = cr_statement_append (ctxt->stylesheet->statements, - stmt) ; - if (!stmt2) - { - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + enum CRStatus status = CR_OK; + CRStatement *stmt = NULL, + *stmt2 = NULL; + GString *charset = NULL; + + ParsingContext *ctxt = NULL; + + g_return_if_fail (a_this); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->stylesheet); + + charset = g_string_new_len (a_charset->str, a_charset->len); + + stmt = cr_statement_new_at_charset_rule (ctxt->stylesheet, charset); + g_return_if_fail (stmt); + + stmt2 = cr_statement_append (ctxt->stylesheet->statements, stmt); + if (!stmt2) { + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - if (charset) - { - g_string_free (charset, TRUE) ; + if (charset) { + g_string_free (charset, TRUE); } - return ; + return; } - ctxt->stylesheet->statements = stmt2 ; - stmt2 = NULL ; + ctxt->stylesheet->statements = stmt2; + stmt2 = NULL; } static void -start_page (CRDocHandler *a_this, GString *a_page, - GString *a_pseudo) +start_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail (ctxt->cur_stmt == NULL) ; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt == NULL); - ctxt->cur_stmt = cr_statement_new_at_page_rule - (ctxt->stylesheet, NULL, NULL, NULL) ; + ctxt->cur_stmt = cr_statement_new_at_page_rule + (ctxt->stylesheet, NULL, NULL, NULL); - if (a_page) - { - ctxt->cur_stmt->kind.page_rule->name = - g_string_new_len (a_page->str, a_page->len) ; + if (a_page) { + ctxt->cur_stmt->kind.page_rule->name = + g_string_new_len (a_page->str, a_page->len); - if (!ctxt->cur_stmt->kind.page_rule->name) - { - goto error ; - } + if (!ctxt->cur_stmt->kind.page_rule->name) { + goto error; + } } - - if (a_pseudo) - { + + if (a_pseudo) { ctxt->cur_stmt->kind.page_rule->pseudo = - g_string_new_len (a_pseudo->str, a_pseudo->len) ; + g_string_new_len (a_pseudo->str, a_pseudo->len); - if (!ctxt->cur_stmt->kind.page_rule->pseudo) - { - goto error ; + if (!ctxt->cur_stmt->kind.page_rule->pseudo) { + goto error; } } - return ; + return; - error: - if (ctxt->cur_stmt) - { - cr_statement_destroy (ctxt->cur_stmt) ; - ctxt->cur_stmt = NULL ; + error: + if (ctxt->cur_stmt) { + cr_statement_destroy (ctxt->cur_stmt); + ctxt->cur_stmt = NULL; } } - static void -end_page (CRDocHandler *a_this, GString *a_page, - GString *a_pseudo_page) +end_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo_page) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - CRStatement *stmt = NULL ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + CRStatement *stmt = NULL; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail (ctxt->cur_stmt + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_PAGE_RULE_STMT - && ctxt->stylesheet) ; + && ctxt->stylesheet); stmt = cr_statement_append (ctxt->stylesheet->statements, - ctxt->cur_stmt) ; + ctxt->cur_stmt); - if (stmt) - { - ctxt->stylesheet->statements = stmt ; - stmt = NULL ; - ctxt->cur_stmt = NULL ; + if (stmt) { + ctxt->stylesheet->statements = stmt; + stmt = NULL; + ctxt->cur_stmt = NULL; } - - if (ctxt->cur_stmt) - { - cr_statement_destroy (ctxt->cur_stmt) ; - ctxt->cur_stmt = NULL ; + + if (ctxt->cur_stmt) { + cr_statement_destroy (ctxt->cur_stmt); + ctxt->cur_stmt = NULL; } - a_page = NULL ; /*keep compiler happy*/ - a_pseudo_page = NULL ; /*keep compiler happy*/ + a_page = NULL; /*keep compiler happy */ + a_pseudo_page = NULL; /*keep compiler happy */ } static void -start_media (CRDocHandler *a_this, GList *a_media_list) +start_media (CRDocHandler * a_this, GList * a_media_list) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - GList * media_list = NULL ; - - g_return_if_fail (a_this) ; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - - g_return_if_fail (ctxt + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + GList *media_list = NULL; + + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + + g_return_if_fail (ctxt && ctxt->cur_stmt == NULL && ctxt->cur_media_stmt == NULL - && ctxt->stylesheet) ; + && ctxt->stylesheet); - if (a_media_list) - { - /*duplicate the media_list*/ - media_list = cr_dup_glist_of_string (a_media_list) ; + if (a_media_list) { + /*duplicate the media_list */ + media_list = cr_dup_glist_of_string (a_media_list); } - ctxt->cur_media_stmt = - cr_statement_new_at_media_rule - (ctxt->stylesheet, NULL, media_list) ; - + ctxt->cur_media_stmt = + cr_statement_new_at_media_rule + (ctxt->stylesheet, NULL, media_list); + } static void -end_media (CRDocHandler *a_this, GList *a_media_list) +end_media (CRDocHandler * a_this, GList * a_media_list) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - CRStatement * stmts = NULL ; - - g_return_if_fail (a_this) ; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail (ctxt + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + CRStatement *stmts = NULL; + + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt && ctxt->cur_media_stmt && ctxt->cur_media_stmt->type == AT_MEDIA_RULE_STMT - && ctxt->stylesheet) ; + && ctxt->stylesheet); stmts = cr_statement_append (ctxt->stylesheet->statements, - ctxt->cur_media_stmt) ; - if (!stmts) - { - cr_statement_destroy (ctxt->cur_media_stmt) ; - ctxt->cur_media_stmt = NULL ; + ctxt->cur_media_stmt); + if (!stmts) { + cr_statement_destroy (ctxt->cur_media_stmt); + ctxt->cur_media_stmt = NULL; } - - ctxt->stylesheet->statements = stmts ; - stmts = NULL ; - - a_media_list = NULL ; /*compiler happy*/ -} + ctxt->stylesheet->statements = stmts; + stmts = NULL; + + a_media_list = NULL; /*compiler happy */ +} static void -import_style (CRDocHandler *a_this, GList *a_media_list, - GString *a_uri, GString *a_uri_default_ns) +import_style (CRDocHandler * a_this, GList * a_media_list, + GString * a_uri, GString * a_uri_default_ns) { - enum CRStatus status = CR_OK ; - GString *uri = NULL ; - CRStatement *stmt = NULL, *stmt2 = NULL ; - ParsingContext *ctxt = NULL ; - GList *media_list = NULL, *cur = NULL ; - - g_return_if_fail (a_this) ; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail (ctxt->stylesheet) ; - - uri = g_string_new_len (a_uri->str, a_uri->len) ; - - for (cur = a_media_list ; cur; cur = cur->next) - { - if (cur->data) - { - GString *str1 = NULL, *str2 = NULL ; - str1 = (GString*)cur->data ; - str2 = g_string_new_len (str1->str, str1->len) ; - - media_list = g_list_append (media_list, - str2); + enum CRStatus status = CR_OK; + GString *uri = NULL; + CRStatement *stmt = NULL, + *stmt2 = NULL; + ParsingContext *ctxt = NULL; + GList *media_list = NULL, + *cur = NULL; + + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->stylesheet); + + uri = g_string_new_len (a_uri->str, a_uri->len); + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data) { + GString *str1 = NULL, + *str2 = NULL; + + str1 = (GString *) cur->data; + str2 = g_string_new_len (str1->str, str1->len); + + media_list = g_list_append (media_list, str2); } } - stmt = cr_statement_new_at_import_rule - (ctxt->stylesheet, uri, media_list, NULL) ; - if (!stmt) - goto error ; - - if (ctxt->cur_stmt) - { - stmt2 = cr_statement_append (ctxt->cur_stmt, stmt) ; + stmt = cr_statement_new_at_import_rule + (ctxt->stylesheet, uri, media_list, NULL); + if (!stmt) + goto error; + + if (ctxt->cur_stmt) { + stmt2 = cr_statement_append (ctxt->cur_stmt, stmt); if (!stmt2) - goto error ; - ctxt->cur_stmt = stmt2 ; - stmt2 = NULL ; - stmt = NULL ; - } - else - { + goto error; + ctxt->cur_stmt = stmt2; + stmt2 = NULL; + stmt = NULL; + } else { stmt2 = cr_statement_append (ctxt->stylesheet->statements, - stmt) ; + stmt); if (!stmt2) - goto error ; - ctxt->stylesheet->statements = stmt2 ; - stmt2 = NULL ; - stmt = NULL ; + goto error; + ctxt->stylesheet->statements = stmt2; + stmt2 = NULL; + stmt = NULL; } - return ; + return; - error: - if (uri) - { - g_string_free (uri, TRUE) ; + error: + if (uri) { + g_string_free (uri, TRUE); } - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - a_uri_default_ns = NULL ; /*keep compiler happy*/ + a_uri_default_ns = NULL; /*keep compiler happy */ } static void -start_selector (CRDocHandler *a_this, - CRSelector *a_selector_list) +start_selector (CRDocHandler * a_this, CRSelector * a_selector_list) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this) ; - - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - if (ctxt->cur_stmt) - { - /*hmm, this should be NULL so free it*/ - cr_statement_destroy (ctxt->cur_stmt) ; - ctxt->cur_stmt = NULL ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + + g_return_if_fail (a_this); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + if (ctxt->cur_stmt) { + /*hmm, this should be NULL so free it */ + cr_statement_destroy (ctxt->cur_stmt); + ctxt->cur_stmt = NULL; } - ctxt->cur_stmt =cr_statement_new_ruleset - (ctxt->stylesheet, a_selector_list,NULL, NULL) ; + ctxt->cur_stmt = cr_statement_new_ruleset + (ctxt->stylesheet, a_selector_list, NULL, NULL); } - static void -end_selector (CRDocHandler *a_this, - CRSelector *a_selector_list) +end_selector (CRDocHandler * a_this, CRSelector * a_selector_list) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this) ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - g_return_if_fail (ctxt->cur_stmt - && ctxt->stylesheet) ; + g_return_if_fail (a_this); - if (ctxt->cur_stmt) - { - CRStatement *stmts = NULL ; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + g_return_if_fail (ctxt->cur_stmt && ctxt->stylesheet); - if (ctxt->cur_media_stmt) - { - CRAtMediaRule *media_rule = NULL ; + if (ctxt->cur_stmt) { + CRStatement *stmts = NULL; - media_rule = ctxt->cur_media_stmt->kind.media_rule ; + if (ctxt->cur_media_stmt) { + CRAtMediaRule *media_rule = NULL; - stmts = cr_statement_append - (media_rule->rulesets, ctxt->cur_stmt) ; + media_rule = ctxt->cur_media_stmt->kind.media_rule; - if (!stmts) - { - cr_utils_trace_info + stmts = cr_statement_append + (media_rule->rulesets, ctxt->cur_stmt); + + if (!stmts) { + cr_utils_trace_info ("Could not append a new statement"); - cr_statement_destroy - (media_rule->rulesets) ; + cr_statement_destroy (media_rule->rulesets); ctxt->cur_media_stmt-> - kind.media_rule->rulesets = NULL ; - return ; + kind.media_rule->rulesets = NULL; + return; } - media_rule->rulesets = stmts ; - ctxt->cur_stmt = NULL ; - } - else - { - stmts = cr_statement_append + media_rule->rulesets = stmts; + ctxt->cur_stmt = NULL; + } else { + stmts = cr_statement_append (ctxt->stylesheet->statements, - ctxt->cur_stmt) ; - if (!stmts) - { - cr_utils_trace_info + ctxt->cur_stmt); + if (!stmts) { + cr_utils_trace_info ("Could not append a new statement"); - cr_statement_destroy (ctxt->cur_stmt) ; - ctxt->cur_stmt = NULL ; - return ; + cr_statement_destroy (ctxt->cur_stmt); + ctxt->cur_stmt = NULL; + return; } - ctxt->stylesheet->statements = stmts ; - ctxt->cur_stmt = NULL ; + ctxt->stylesheet->statements = stmts; + ctxt->cur_stmt = NULL; } - + } - a_selector_list = NULL ; /*keep compiler happy*/ + a_selector_list = NULL; /*keep compiler happy */ } static void -property (CRDocHandler *a_this, - GString *a_name, - CRTerm *a_expression, - gboolean a_important) +property (CRDocHandler * a_this, + GString * a_name, CRTerm * a_expression, gboolean a_important) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - CRDeclaration *decl = NULL, *decl2 = NULL ; - GString *str = NULL ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + CRDeclaration *decl = NULL, + *decl2 = NULL; + GString *str = NULL; - g_return_if_fail (a_this) ; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); /* *make sure a current ruleset statement has been allocated *already. */ - g_return_if_fail - (ctxt->cur_stmt - && + g_return_if_fail + (ctxt->cur_stmt + && (ctxt->cur_stmt->type == RULESET_STMT || ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT || ctxt->cur_stmt->type == AT_PAGE_RULE_STMT)); - if (a_name) - { - str = g_string_new_len (a_name->str, - a_name->len) ; - g_return_if_fail (str) ; - } - - /*instanciates a new declaration*/ - decl = cr_declaration_new (ctxt->cur_stmt, - str, a_expression) ; - g_return_if_fail (decl) ; - str = NULL ; - decl->important = a_important ; + if (a_name) { + str = g_string_new_len (a_name->str, a_name->len); + g_return_if_fail (str); + } + + /*instanciates a new declaration */ + decl = cr_declaration_new (ctxt->cur_stmt, str, a_expression); + g_return_if_fail (decl); + str = NULL; + decl->important = a_important; /* *add the new declaration to the current statement *being build. */ - switch (ctxt->cur_stmt->type) - { + switch (ctxt->cur_stmt->type) { case RULESET_STMT: - decl2 = cr_declaration_append - (ctxt->cur_stmt->kind.ruleset->decl_list, - decl) ; - if (!decl2) - { - cr_declaration_destroy (decl) ; - cr_utils_trace_info + decl2 = cr_declaration_append + (ctxt->cur_stmt->kind.ruleset->decl_list, decl); + if (!decl2) { + cr_declaration_destroy (decl); + cr_utils_trace_info ("Could not append decl to ruleset"); - goto error ; + goto error; } - ctxt->cur_stmt->kind.ruleset->decl_list = decl2 ; - decl = NULL ; decl2 = NULL ; - break ; + ctxt->cur_stmt->kind.ruleset->decl_list = decl2; + decl = NULL; + decl2 = NULL; + break; case AT_FONT_FACE_RULE_STMT: - decl2 = cr_declaration_append + decl2 = cr_declaration_append (ctxt->cur_stmt->kind.font_face_rule->decl_list, - decl) ; - if (!decl2) - { - cr_declaration_destroy (decl) ; - cr_utils_trace_info + decl); + if (!decl2) { + cr_declaration_destroy (decl); + cr_utils_trace_info ("Could not append decl to ruleset"); - goto error ; + goto error; } - ctxt->cur_stmt->kind.font_face_rule->decl_list = decl2 ; - decl = NULL ; decl2 = NULL ; - break ; + ctxt->cur_stmt->kind.font_face_rule->decl_list = decl2; + decl = NULL; + decl2 = NULL; + break; case AT_PAGE_RULE_STMT: - decl2 = cr_declaration_append - (ctxt->cur_stmt->kind.page_rule->decl_list, - decl) ; - if (!decl2) - { - cr_declaration_destroy (decl) ; - cr_utils_trace_info + decl2 = cr_declaration_append + (ctxt->cur_stmt->kind.page_rule->decl_list, decl); + if (!decl2) { + cr_declaration_destroy (decl); + cr_utils_trace_info ("Could not append decl to ruleset"); - goto error ; + goto error; } - ctxt->cur_stmt->kind.page_rule->decl_list = decl2 ; - decl = NULL ; decl2 = NULL ; - break ; + ctxt->cur_stmt->kind.page_rule->decl_list = decl2; + decl = NULL; + decl2 = NULL; + break; default: - goto error ; - break ; + goto error; + break; } - return ; + return; - error: - if (str) - { - g_free (str) ; - str = NULL ; + error: + if (str) { + g_free (str); + str = NULL; } - if (decl) - { - cr_declaration_destroy (decl) ; - decl = NULL ; + if (decl) { + cr_declaration_destroy (decl); + decl = NULL; } } static void -error (CRDocHandler *a_this) +error (CRDocHandler * a_this) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this) ; - - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK && ctxt) ; - - if (ctxt->cur_stmt) - { - cr_statement_destroy (ctxt->cur_stmt) ; - ctxt->cur_stmt = NULL ; - } -} + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + + g_return_if_fail (a_this); + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK && ctxt); + if (ctxt->cur_stmt) { + cr_statement_destroy (ctxt->cur_stmt); + ctxt->cur_stmt = NULL; + } +} static void -unrecoverable_error (CRDocHandler *a_this) +unrecoverable_error (CRDocHandler * a_this) { - enum CRStatus status = CR_OK ; - ParsingContext *ctxt = NULL ; - - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&ctxt) ; - g_return_if_fail (status == CR_OK) ; - - if (ctxt) - { - if (ctxt->stylesheet) - { - status = cr_doc_handler_set_result - (a_this, ctxt->stylesheet) ; - g_return_if_fail (status == CR_OK) ; + enum CRStatus status = CR_OK; + ParsingContext *ctxt = NULL; + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & ctxt); + g_return_if_fail (status == CR_OK); + + if (ctxt) { + if (ctxt->stylesheet) { + status = cr_doc_handler_set_result + (a_this, ctxt->stylesheet); + g_return_if_fail (status == CR_OK); } - g_free (ctxt) ; - cr_doc_handler_set_ctxt (a_this, NULL) ; + g_free (ctxt); + cr_doc_handler_set_ctxt (a_this, NULL); } } - /******************************************** *Public methods ********************************************/ @@ -832,58 +753,52 @@ unrecoverable_error (CRDocHandler *a_this) *@return the newly built instance of #CROMParser. */ CROMParser * -cr_om_parser_new (CRInput *a_input) +cr_om_parser_new (CRInput * a_input) { - CROMParser *result = NULL ; - enum CRStatus status = CR_OK ; + CROMParser *result = NULL; + enum CRStatus status = CR_OK; - result = g_try_malloc (sizeof (CROMParser)) ; + result = g_try_malloc (sizeof (CROMParser)); - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - memset (result, 0, sizeof (CROMParser)) ; - PRIVATE (result) = g_try_malloc (sizeof (CROMParserPriv)) ; + memset (result, 0, sizeof (CROMParser)); + PRIVATE (result) = g_try_malloc (sizeof (CROMParserPriv)); - if (!PRIVATE (result)) - { - cr_utils_trace_info ("Out of memory") ; - goto error ; + if (!PRIVATE (result)) { + cr_utils_trace_info ("Out of memory"); + goto error; } - memset (PRIVATE (result), 0, sizeof (CROMParserPriv)) ; + memset (PRIVATE (result), 0, sizeof (CROMParserPriv)); PRIVATE (result)->parser = cr_parser_new_from_input (a_input); - if (!PRIVATE (result)->parser) - { - cr_utils_trace_info ("parsing instanciation failed") ; - goto error ; + if (!PRIVATE (result)->parser) { + cr_utils_trace_info ("parsing instanciation failed"); + goto error; } - status = cr_om_parser_init_default_sac_handler (result) ; + status = cr_om_parser_init_default_sac_handler (result); - if (status != CR_OK) - { - goto error ; + if (status != CR_OK) { + goto error; } - return result ; + return result; - error: + error: - if (result) - { - cr_om_parser_destroy (result) ; + if (result) { + cr_om_parser_destroy (result); } - return NULL ; + return NULL; } - /** *Parses the content of an in memory buffer. *@param a_this the current instance of #CROMParser. @@ -894,43 +809,40 @@ cr_om_parser_new (CRInput *a_input) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_om_parser_parse_buf (CROMParser *a_this, - const guchar *a_buf, +cr_om_parser_parse_buf (CROMParser * a_this, + const guchar * a_buf, gulong a_len, - enum CREncoding a_enc, - CRStyleSheet **a_result) + enum CREncoding a_enc, CRStyleSheet ** a_result) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && a_result, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_result, CR_BAD_PARAM_ERROR); - if (!PRIVATE (a_this)->parser) - { - PRIVATE (a_this)->parser = cr_parser_new (NULL) ; + if (!PRIVATE (a_this)->parser) { + PRIVATE (a_this)->parser = cr_parser_new (NULL); } status = cr_parser_parse_buf (PRIVATE (a_this)->parser, - a_buf, a_len, a_enc) ; + a_buf, a_len, a_enc); - if (status == CR_OK) - { - CRStyleSheet *result = NULL ; - CRDocHandler *sac_handler = NULL ; + if (status == CR_OK) { + CRStyleSheet *result = NULL; + CRDocHandler *sac_handler = NULL; cr_parser_get_sac_handler (PRIVATE (a_this)->parser, - &sac_handler) ; - g_return_val_if_fail (sac_handler, CR_ERROR) ; + &sac_handler); + g_return_val_if_fail (sac_handler, CR_ERROR); - status = cr_doc_handler_get_result (sac_handler, - (gpointer*)&result) ; - g_return_val_if_fail (status == CR_OK, status) ; + status = cr_doc_handler_get_result (sac_handler, + (gpointer *) & result); + g_return_val_if_fail (status == CR_OK, status); if (result) - *a_result = result ; + *a_result = result; } - return status ; + return status; } /** @@ -942,32 +854,30 @@ cr_om_parser_parse_buf (CROMParser *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_om_parser_simply_parse_buf (const guchar *a_buf, +cr_om_parser_simply_parse_buf (const guchar * a_buf, gulong a_len, enum CREncoding a_enc, - CRStyleSheet **a_result) + CRStyleSheet ** a_result) { - CROMParser *parser = NULL ; - enum CRStatus status = CR_OK ; - - parser = cr_om_parser_new (NULL) ; - if (!parser) - { - cr_utils_trace_info ("Could not create om parser") ; - cr_utils_trace_info ("System possibly out of memory") ; - return CR_ERROR ; + CROMParser *parser = NULL; + enum CRStatus status = CR_OK; + + parser = cr_om_parser_new (NULL); + if (!parser) { + cr_utils_trace_info ("Could not create om parser"); + cr_utils_trace_info ("System possibly out of memory"); + return CR_ERROR; } status = cr_om_parser_parse_buf (parser, a_buf, a_len, - a_enc, a_result) ; + a_enc, a_result); - if (parser) - { - cr_om_parser_destroy (parser) ; - parser = NULL ; + if (parser) { + cr_om_parser_destroy (parser); + parser = NULL; } - - return status ; + + return status; } /** @@ -983,46 +893,41 @@ cr_om_parser_simply_parse_buf (const guchar *a_buf, *otherwise. */ enum CRStatus -cr_om_parser_parse_file (CROMParser *a_this, - const guchar *a_file_uri, - enum CREncoding a_enc, - CRStyleSheet **a_result) +cr_om_parser_parse_file (CROMParser * a_this, + const guchar * a_file_uri, + enum CREncoding a_enc, CRStyleSheet ** a_result) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && a_file_uri && a_result, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_file_uri && a_result, + CR_BAD_PARAM_ERROR); - if (!PRIVATE (a_this)->parser) - { - PRIVATE (a_this)->parser = cr_parser_new_from_file - (a_file_uri, a_enc) ; + if (!PRIVATE (a_this)->parser) { + PRIVATE (a_this)->parser = cr_parser_new_from_file + (a_file_uri, a_enc); } status = cr_parser_parse_file (PRIVATE (a_this)->parser, - a_file_uri, a_enc) ; + a_file_uri, a_enc); - if (status == CR_OK) - { - CRStyleSheet *result = NULL ; - CRDocHandler *sac_handler = NULL ; + if (status == CR_OK) { + CRStyleSheet *result = NULL; + CRDocHandler *sac_handler = NULL; cr_parser_get_sac_handler (PRIVATE (a_this)->parser, - &sac_handler) ; - g_return_val_if_fail (sac_handler, CR_ERROR) ; + &sac_handler); + g_return_val_if_fail (sac_handler, CR_ERROR); - status = cr_doc_handler_get_result - (sac_handler, - (gpointer *)&result) ; - g_return_val_if_fail (status == CR_OK, status) ; + status = cr_doc_handler_get_result + (sac_handler, (gpointer *) & result); + g_return_val_if_fail (status == CR_OK, status); if (result) - *a_result = result ; + *a_result = result; } - return status ; + return status; } - /** *The simpler method to parse a css2 file. *@param a_file_path the css2 local file path. @@ -1034,30 +939,28 @@ cr_om_parser_parse_file (CROMParser *a_this, *have the same return values. */ enum CRStatus -cr_om_parser_simply_parse_file (const guchar *a_file_path, +cr_om_parser_simply_parse_file (const guchar * a_file_path, enum CREncoding a_enc, - CRStyleSheet **a_result) + CRStyleSheet ** a_result) { - CROMParser * parser = NULL ; - enum CRStatus status = CR_OK ; - - parser = cr_om_parser_new (NULL) ; - if (!parser) - { - cr_utils_trace_info ("Could not allocate om parser") ; - cr_utils_trace_info ("System may be out of memory") ; - return CR_ERROR ; + CROMParser *parser = NULL; + enum CRStatus status = CR_OK; + + parser = cr_om_parser_new (NULL); + if (!parser) { + cr_utils_trace_info ("Could not allocate om parser"); + cr_utils_trace_info ("System may be out of memory"); + return CR_ERROR; } - + status = cr_om_parser_parse_file (parser, a_file_path, - a_enc, a_result) ; - if (parser) - { - cr_om_parser_destroy (parser) ; - parser = NULL ; + a_enc, a_result); + if (parser) { + cr_om_parser_destroy (parser); + parser = NULL; } - return status ; + return status; } /** @@ -1071,54 +974,49 @@ cr_om_parser_simply_parse_file (const guchar *a_file_path, *@return CR_OK upon successful completion, an error code otherwise */ enum CRStatus -cr_om_parser_parse_paths_to_cascade (CROMParser *a_this, - const guchar *a_author_path, - const guchar *a_user_path, - const guchar *a_ua_path, +cr_om_parser_parse_paths_to_cascade (CROMParser * a_this, + const guchar * a_author_path, + const guchar * a_user_path, + const guchar * a_ua_path, enum CREncoding a_encoding, CRCascade ** a_result) { - enum CRStatus status = CR_OK ; - /*0->author sheet, 1->user sheet, 2->UA sheet*/ - CRStyleSheet *sheets[3] ; - guchar * paths[3] ; - CRCascade *result = NULL ; - gint i = 0 ; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - memset (sheets, 0, sizeof (CRStyleSheet) * 3) ; - paths[0] = (guchar*) a_author_path ; - paths[1] = (guchar*) a_user_path ; - paths[2] = (guchar*) a_ua_path ; - - for (i=0 ;i < 3; i++) - { - status = cr_om_parser_parse_file (a_this, paths[i], - a_encoding, - &sheets[i]) ; - if (status != CR_OK) - { - if (sheets[i]) - { - cr_stylesheet_unref (sheets[i]) ; - sheets[i] = NULL ; + enum CRStatus status = CR_OK; + + /*0->author sheet, 1->user sheet, 2->UA sheet */ + CRStyleSheet *sheets[3]; + guchar *paths[3]; + CRCascade *result = NULL; + gint i = 0; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + memset (sheets, 0, sizeof (CRStyleSheet) * 3); + paths[0] = (guchar *) a_author_path; + paths[1] = (guchar *) a_user_path; + paths[2] = (guchar *) a_ua_path; + + for (i = 0; i < 3; i++) { + status = cr_om_parser_parse_file (a_this, paths[i], + a_encoding, &sheets[i]); + if (status != CR_OK) { + if (sheets[i]) { + cr_stylesheet_unref (sheets[i]); + sheets[i] = NULL; } - continue ; + continue; } } - result = cr_cascade_new (sheets[0], sheets[1], sheets[2]) ; - if (!result) - { - for (i=0 ; i < 3 ; i++) - { - cr_stylesheet_unref (sheets[i]) ; - sheets[i] = 0 ; + result = cr_cascade_new (sheets[0], sheets[1], sheets[2]); + if (!result) { + for (i = 0; i < 3; i++) { + cr_stylesheet_unref (sheets[i]); + sheets[i] = 0; } - return CR_ERROR ; + return CR_ERROR; } - *a_result = result ; - return CR_OK ; + *a_result = result; + return CR_OK; } /** @@ -1131,34 +1029,31 @@ cr_om_parser_parse_paths_to_cascade (CROMParser *a_this, *@return CR_OK upon successful completion, an error code otherwise */ enum CRStatus -cr_om_parser_simply_parse_paths_to_cascade (const guchar *a_author_path, - const guchar *a_user_path, - const guchar *a_ua_path, +cr_om_parser_simply_parse_paths_to_cascade (const guchar * a_author_path, + const guchar * a_user_path, + const guchar * a_ua_path, enum CREncoding a_encoding, CRCascade ** a_result) { - enum CRStatus status = CR_OK ; - CROMParser *parser = NULL ; - - parser = cr_om_parser_new (NULL) ; - if (!parser) - { - cr_utils_trace_info ("could not allocated om parser") ; - cr_utils_trace_info ("System may be out of memory") ; - return CR_ERROR ; + enum CRStatus status = CR_OK; + CROMParser *parser = NULL; + + parser = cr_om_parser_new (NULL); + if (!parser) { + cr_utils_trace_info ("could not allocated om parser"); + cr_utils_trace_info ("System may be out of memory"); + return CR_ERROR; } - status = cr_om_parser_parse_paths_to_cascade (parser, + status = cr_om_parser_parse_paths_to_cascade (parser, a_author_path, a_user_path, a_ua_path, - a_encoding, - a_result) ; - if (parser) - { - cr_om_parser_destroy (parser) ; - parser = NULL ; + a_encoding, a_result); + if (parser) { + cr_om_parser_destroy (parser); + parser = NULL; } - return status ; + return status; } /** @@ -1166,26 +1061,22 @@ cr_om_parser_simply_parse_paths_to_cascade (const guchar *a_author_path, *@param a_this the current instance of #CROMParser. */ void -cr_om_parser_destroy (CROMParser *a_this) +cr_om_parser_destroy (CROMParser * a_this) { - g_return_if_fail (a_this && PRIVATE (a_this)) ; + g_return_if_fail (a_this && PRIVATE (a_this)); - if (PRIVATE (a_this)->parser) - { - cr_parser_destroy (PRIVATE (a_this)->parser) ; - PRIVATE (a_this)->parser = NULL ; + if (PRIVATE (a_this)->parser) { + cr_parser_destroy (PRIVATE (a_this)->parser); + PRIVATE (a_this)->parser = NULL; } - if (PRIVATE (a_this)) - { - g_free (PRIVATE (a_this)) ; - PRIVATE (a_this) = NULL ; - } - - if (a_this) - { - g_free (a_this) ; - a_this = NULL ; - } -} + if (PRIVATE (a_this)) { + g_free (PRIVATE (a_this)); + PRIVATE (a_this) = NULL; + } + if (a_this) { + g_free (a_this); + a_this = NULL; + } +} diff --git a/src/cr-parser.c b/src/cr-parser.c index 67e51be..9e51695 100644 --- a/src/cr-parser.c +++ b/src/cr-parser.c @@ -73,26 +73,21 @@ *cr_parser_parse__core (...) ; */ - - -typedef struct _CRParserError CRParserError ; +typedef struct _CRParserError CRParserError; /** *An abstraction of an error reported by by the *parsing routines. */ -struct _CRParserError -{ - guchar * msg ; - enum CRStatus status ; - glong line ; - glong column ; - glong byte_num ; -} ; - - -enum CRParserState -{ +struct _CRParserError { + guchar *msg; + enum CRStatus status; + glong line; + glong column; + glong byte_num; +}; + +enum CRParserState { READY_STATE = 0, TRY_PARSE_CHARSET_STATE, CHARSET_PARSED_STATE, @@ -106,26 +101,24 @@ enum CRParserState PAGE_PARSED_STATE, TRY_PARSE_FONT_FACE_STATE, FONT_FACE_PARSED_STATE -} ; - +}; /** *The private attributes of *#CRParser. */ -struct _CRParserPriv -{ +struct _CRParserPriv { /** *The tokenizer */ - CRTknzr *tknzr ; + CRTknzr *tknzr; /** *The sac handlers to call *to notify the parsing of *the css2 constructions. */ - CRDocHandler *sac_handler ; + CRDocHandler *sac_handler; /** *A stack of errors reported @@ -133,14 +126,13 @@ struct _CRParserPriv *Contains instance of #CRParserError. *This pointer is the top of the stack. */ - GList *err_stack ; - - enum CRParserState state ; - gboolean resolve_import ; - gboolean is_case_sensitive ; - gboolean use_core_grammar ; -} ; + GList *err_stack; + enum CRParserState state; + gboolean resolve_import; + gboolean is_case_sensitive; + gboolean use_core_grammar; +}; #define PRIVATE(obj) ((obj)->priv) @@ -171,7 +163,6 @@ if ((status) != CR_OK) \ goto error ; \ } - /** *same as CHECK_PARSING_STATUS() but this one pushes an error *on the parser error stack when an error arises. @@ -193,7 +184,6 @@ if ((a_status) != CR_OK) \ goto error ; \ } - /** *Peeks the next char from the input stream of the current parser *by invoking cr_tknzr_input_peek_char(). @@ -211,8 +201,6 @@ status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ CHECK_PARSING_STATUS (status, TRUE) \ } - - /** *Reads the next char from the input stream of the current parser. *In case of error, jumps to the "error:" label located in the @@ -225,7 +213,6 @@ CHECK_PARSING_STATUS (status, TRUE) \ status = cr_tknzr_read_char (PRIVATE (a_this)->tknzr, a_to_char) ; \ CHECK_PARSING_STATUS (status, TRUE) - /** *Gets information about the current position in *the input of the parser. @@ -241,7 +228,6 @@ status = cr_tknzr_get_cur_pos (PRIVATE \ (a_this)->tknzr, a_pos) ; \ g_return_val_if_fail (status == CR_OK, status) - /** *Gets the address of the current byte inside the *parser input. @@ -254,7 +240,6 @@ status = cr_tknzr_get_cur_byte_addr \ (PRIVATE (a_this)->tknzr, a_addr) ; \ CHECK_PARSING_STATUS (status, TRUE) - /** *Peeks a byte from the topmost parser input at *a given offset from the current position. @@ -286,7 +271,6 @@ cr_tknzr_peek_byte2 (PRIVATE (a_this)->tknzr, a_offset, a_eof) status = cr_tknzr_read_byte (PRIVATE (a_this)->tknzr, a_byte_ptr) ; \ CHECK_PARSING_STATUS (status, TRUE) ; - /** *Skips a given number of byte in the topmost *parser input. Don't update line and column number. @@ -300,7 +284,6 @@ status = cr_tknzr_seek_index (PRIVATE (a_this)->tknzr, \ CR_SEEK_CUR, a_nb_bytes) ; \ CHECK_PARSING_STATUS (status, TRUE) ; - /** *Skip utf8 encoded characters. *Updates line and column numbers. @@ -316,7 +299,6 @@ status = cr_tknzr_consume_chars \ CHECK_PARSING_STATUS (status, TRUE) ; \ } - /** *Tests the condition and if it is false, sets *status to "CR_PARSING_ERROR" and goto the 'error' @@ -326,8 +308,6 @@ CHECK_PARSING_STATUS (status, TRUE) ; \ #define ENSURE_PARSING_COND(condition) \ if (! (condition)) {status = CR_PARSING_ERROR; goto error ;} - - #define ENSURE_PARSING_COND_ERR(a_this, a_condition, \ a_err_msg, a_err_status) \ if (! (a_condition)) \ @@ -337,112 +317,93 @@ if (! (a_condition)) \ goto error ; \ } - #define GET_NEXT_TOKEN(a_this, a_token_ptr) \ status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, \ a_token_ptr) ; \ ENSURE_PARSING_COND (status == CR_OK) ; - #ifdef WITH_UNICODE_ESCAPE_AND_RANGE -static enum CRStatus -cr_parser_parse_unicode_escape (CRParser *a_this, - guint32 *a_unicode) ; -static enum CRStatus -cr_parser_parse_escape (CRParser *a_this, guint32 *a_esc_code) ; - -static enum CRStatus -cr_parser_parse_unicode_range (CRParser *a_this, - GString **a_inf, - GString **a_sup) ; +static enum CRStatus cr_parser_parse_unicode_escape (CRParser * a_this, + guint32 * a_unicode); +static enum CRStatus cr_parser_parse_escape (CRParser * a_this, + guint32 * a_esc_code); + +static enum CRStatus cr_parser_parse_unicode_range (CRParser * a_this, + GString ** a_inf, + GString ** a_sup); #endif -static enum CRStatus -cr_parser_parse_stylesheet_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_stylesheet_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_atrule_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_atrule_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_ruleset_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_ruleset_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_selector_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_selector_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_declaration_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_declaration_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_any_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_any_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_block_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_block_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_value_core (CRParser *a_this) ; +static enum CRStatus cr_parser_parse_value_core (CRParser * a_this); -static enum CRStatus -cr_parser_parse_string (CRParser *a_this, GString **a_str) ; +static enum CRStatus cr_parser_parse_string (CRParser * a_this, + GString ** a_str); -static enum CRStatus -cr_parser_parse_ident (CRParser *a_this, GString **a_str) ; +static enum CRStatus cr_parser_parse_ident (CRParser * a_this, + GString ** a_str); -static enum CRStatus -cr_parser_parse_vendor_specific_ident (CRParser *a_this, GString **a_str) ; +static enum CRStatus cr_parser_parse_vendor_specific_ident (CRParser * a_this, + GString ** a_str); -static enum CRStatus -cr_parser_parse_uri (CRParser *a_this, GString **a_str) ; +static enum CRStatus cr_parser_parse_uri (CRParser * a_this, + GString ** a_str); -static enum CRStatus -cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) ; +static enum CRStatus cr_parser_parse_term (CRParser * a_this, + CRTerm ** a_term); -static enum CRStatus -cr_parser_parse_function (CRParser *a_this, GString **a_func_name, - CRTerm **a_expr) ; -static enum CRStatus -cr_parser_parse_property (CRParser *a_this, GString **a_property) ; +static enum CRStatus cr_parser_parse_function (CRParser * a_this, + GString ** a_func_name, + CRTerm ** a_expr); +static enum CRStatus cr_parser_parse_property (CRParser * a_this, + GString ** a_property); -static enum CRStatus -cr_parser_parse_attribute_selector (CRParser *a_this, CRAttrSel **a_sel) ; +static enum CRStatus cr_parser_parse_attribute_selector (CRParser * a_this, + CRAttrSel ** a_sel); -static enum CRStatus -cr_parser_parse_simple_selector (CRParser *a_this, CRSimpleSel **a_sel) ; +static enum CRStatus cr_parser_parse_simple_selector (CRParser * a_this, + CRSimpleSel ** a_sel); -static enum CRStatus -cr_parser_parse_simple_sels (CRParser *a_this, CRSimpleSel **a_sel) ; +static enum CRStatus cr_parser_parse_simple_sels (CRParser * a_this, + CRSimpleSel ** a_sel); -static CRParserError * -cr_parser_error_new (const guchar * a_msg, enum CRStatus) ; +static CRParserError *cr_parser_error_new (const guchar * a_msg, + enum CRStatus); -static void -cr_parser_error_set_msg (CRParserError *a_this, const guchar *a_msg) ; +static void cr_parser_error_set_msg (CRParserError * a_this, + const guchar * a_msg); -static void -cr_parser_error_dump (CRParserError *a_this) ; +static void cr_parser_error_dump (CRParserError * a_this); -static void -cr_parser_error_set_status (CRParserError *a_this, - enum CRStatus a_status) ; +static void cr_parser_error_set_status (CRParserError * a_this, + enum CRStatus a_status); +static void cr_parser_error_set_pos (CRParserError * a_this, + glong a_line, + glong a_column, glong a_byte_num); static void -cr_parser_error_set_pos (CRParserError *a_this, - glong a_line, - glong a_column, - glong a_byte_num) ; -static void -cr_parser_error_destroy (CRParserError *a_this) ; + cr_parser_error_destroy (CRParserError * a_this); -static enum CRStatus -cr_parser_push_error (CRParser *a_this, - const guchar * a_msg, - enum CRStatus a_status) ; +static enum CRStatus cr_parser_push_error (CRParser * a_this, + const guchar * a_msg, + enum CRStatus a_status); +static enum CRStatus cr_parser_dump_err_stack (CRParser * a_this, + gboolean a_clear_errs); static enum CRStatus -cr_parser_dump_err_stack (CRParser *a_this, - gboolean a_clear_errs) ; -static enum CRStatus -cr_parser_clear_errors (CRParser *a_this) ; - + cr_parser_clear_errors (CRParser * a_this); /***************************** *error managemet methods @@ -457,22 +418,21 @@ cr_parser_clear_errors (CRParser *a_this) ; static CRParserError * cr_parser_error_new (const guchar * a_msg, enum CRStatus a_status) { - CRParserError * result = NULL ; + CRParserError *result = NULL; - result = g_try_malloc (sizeof (CRParserError)) ; + result = g_try_malloc (sizeof (CRParserError)); - if (result == NULL) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; + if (result == NULL) { + cr_utils_trace_info ("Out of memory"); + return NULL; } - memset (result, 0, sizeof (CRParserError)) ; + memset (result, 0, sizeof (CRParserError)); - cr_parser_error_set_msg (result, a_msg) ; - cr_parser_error_set_status (result, a_status) ; + cr_parser_error_set_msg (result, a_msg); + cr_parser_error_set_status (result, a_status); - return result ; + return result; } /** @@ -481,19 +441,17 @@ cr_parser_error_new (const guchar * a_msg, enum CRStatus a_status) *@param a_msg the new message. */ static void -cr_parser_error_set_msg (CRParserError *a_this, const guchar *a_msg) +cr_parser_error_set_msg (CRParserError * a_this, const guchar * a_msg) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - if (a_this->msg) - { - g_free (a_this->msg) ; + if (a_this->msg) { + g_free (a_this->msg); } - a_this->msg = g_strdup (a_msg) ; + a_this->msg = g_strdup (a_msg); } - /** *Sets the error status. *@param a_this the current instance of #CRParserError. @@ -501,12 +459,11 @@ cr_parser_error_set_msg (CRParserError *a_this, const guchar *a_msg) * */ static void -cr_parser_error_set_status (CRParserError *a_this, - enum CRStatus a_status) +cr_parser_error_set_status (CRParserError * a_this, enum CRStatus a_status) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - a_this->status = a_status ; + a_this->status = a_status; } /** @@ -517,50 +474,43 @@ cr_parser_error_set_status (CRParserError *a_this, *@param a_byte_num the byte number. */ static void -cr_parser_error_set_pos (CRParserError *a_this, - glong a_line, - glong a_column, - glong a_byte_num) +cr_parser_error_set_pos (CRParserError * a_this, + glong a_line, glong a_column, glong a_byte_num) { - g_return_if_fail (a_this) ; - - a_this->line = a_line ; - a_this->column = a_column ; - a_this->byte_num = a_byte_num ; -} + g_return_if_fail (a_this); + a_this->line = a_line; + a_this->column = a_column; + a_this->byte_num = a_byte_num; +} static void -cr_parser_error_dump (CRParserError *a_this) +cr_parser_error_dump (CRParserError * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - g_printerr ("parsing error: %ld:%ld:", a_this->line, - a_this->column) ; + g_printerr ("parsing error: %ld:%ld:", a_this->line, a_this->column); - g_printerr ("%s\n", a_this->msg) ; + g_printerr ("%s\n", a_this->msg); } - /** *The destructor of #CRParserError. *@param a_this the current instance of #CRParserError. */ static void -cr_parser_error_destroy (CRParserError *a_this) +cr_parser_error_destroy (CRParserError * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - if (a_this->msg) - { - g_free (a_this->msg) ; - a_this->msg = NULL ; + if (a_this->msg) { + g_free (a_this->msg); + a_this->msg = NULL; } - g_free (a_this) ; + g_free (a_this); } - /** *Pushes an error on the parser error stack. *@param a_this the current instance of #CRParser. @@ -569,48 +519,42 @@ cr_parser_error_destroy (CRParserError *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_push_error (CRParser *a_this, - const guchar * a_msg, - enum CRStatus a_status) +cr_parser_push_error (CRParser * a_this, + const guchar * a_msg, enum CRStatus a_status) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - CRParserError *error = NULL ; - CRInputPos pos ; + CRParserError *error = NULL; + CRInputPos pos; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_msg, - CR_BAD_PARAM_ERROR) ; - - error = cr_parser_error_new (a_msg, a_status) ; + && a_msg, CR_BAD_PARAM_ERROR); - g_return_val_if_fail (error, CR_ERROR) ; + error = cr_parser_error_new (a_msg, a_status); - RECORD_INITIAL_POS (a_this, &pos) ; + g_return_val_if_fail (error, CR_ERROR); - cr_parser_error_set_pos - (error, pos.line, - pos.col, - pos.next_byte_index - 1); + RECORD_INITIAL_POS (a_this, &pos); + cr_parser_error_set_pos + (error, pos.line, pos.col, pos.next_byte_index - 1); - PRIVATE (a_this)->err_stack = - g_list_prepend (PRIVATE (a_this)->err_stack, - error) ; + PRIVATE (a_this)->err_stack = + g_list_prepend (PRIVATE (a_this)->err_stack, error); - if (PRIVATE (a_this)->err_stack == NULL) goto error ; + if (PRIVATE (a_this)->err_stack == NULL) + goto error; - return CR_OK ; + return CR_OK; - error: + error: - if (error) - { - cr_parser_error_destroy (error) ; - error = NULL ; + if (error) { + cr_parser_error_destroy (error); + error = NULL; } - return status ; + return status; } /** @@ -622,32 +566,25 @@ cr_parser_push_error (CRParser *a_this, *otherwise. */ static enum CRStatus -cr_parser_dump_err_stack (CRParser *a_this, - gboolean a_clear_errs) +cr_parser_dump_err_stack (CRParser * a_this, gboolean a_clear_errs) { - GList *cur = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - if (PRIVATE (a_this)->err_stack == NULL) - return CR_OK ; - - for (cur = PRIVATE (a_this)->err_stack ; - cur; - cur = cur->next) - { - cr_parser_error_dump ((CRParserError*)cur->data) ; - } - - if (a_clear_errs == TRUE) - { - cr_parser_clear_errors (a_this) ; - } - - return CR_OK ; -} + GList *cur = NULL; + + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); + if (PRIVATE (a_this)->err_stack == NULL) + return CR_OK; + + for (cur = PRIVATE (a_this)->err_stack; cur; cur = cur->next) { + cr_parser_error_dump ((CRParserError *) cur->data); + } + + if (a_clear_errs == TRUE) { + cr_parser_clear_errors (a_this); + } + + return CR_OK; +} /** *Clears all the errors contained in the parser error stack. @@ -655,31 +592,25 @@ cr_parser_dump_err_stack (CRParser *a_this, *@param a_this the current instance of #CRParser. */ static enum CRStatus -cr_parser_clear_errors (CRParser *a_this) +cr_parser_clear_errors (CRParser * a_this) { - GList *cur = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - for (cur = PRIVATE (a_this)->err_stack ; - cur ; - cur = cur->next) - { - if (cur->data) - { - cr_parser_error_destroy ((CRParserError*) - cur->data) ; + GList *cur = NULL; + + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); + + for (cur = PRIVATE (a_this)->err_stack; cur; cur = cur->next) { + if (cur->data) { + cr_parser_error_destroy ((CRParserError *) + cur->data); } } - if (PRIVATE (a_this)->err_stack) - { - g_list_free (PRIVATE (a_this)->err_stack) ; - PRIVATE (a_this)->err_stack = NULL ; + if (PRIVATE (a_this)->err_stack) { + g_list_free (PRIVATE (a_this)->err_stack); + PRIVATE (a_this)->err_stack = NULL; } - return CR_OK ; + return CR_OK; } /** @@ -690,42 +621,39 @@ cr_parser_clear_errors (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) +cr_parser_try_to_skip_spaces_and_comments (CRParser * a_this) { - enum CRStatus status = CR_ERROR ; - CRToken *token = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr, - CR_BAD_PARAM_ERROR) ; - do - { - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + enum CRStatus status = CR_ERROR; + CRToken *token = NULL; + + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR); + do { + if (token) { + cr_token_destroy (token); + token = NULL; } status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status != CR_OK) goto error ; + &token); + if (status != CR_OK) + goto error; } while ((token != NULL) - && (token->type == COMMENT_TK || token->type == S_TK)) ; + && (token->type == COMMENT_TK || token->type == S_TK)); - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); - return status ; + return status; - error: + error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - return status ; + return status; } /*************************************** @@ -743,123 +671,107 @@ cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_unicode_range (CRParser *a_this, GString **a_inf, - GString **a_sup) +cr_parser_parse_unicode_range (CRParser * a_this, + GString ** a_inf, GString ** a_sup) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; CRInputPos init_pos; - glong i = 0 ; + glong i = 0; gboolean min_str_needs_free = FALSE, - sup_str_needs_free = FALSE ; - guint32 cur_char = 0, next_char = 0 ; + sup_str_needs_free = FALSE; + guint32 cur_char = 0, + next_char = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr - && a_inf && a_sup, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->tknzr + && a_inf && a_sup, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - ENSURE_PARSING_COND_ERR - (a_this, cur_char == 'U', + ENSURE_PARSING_COND_ERR + (a_this, cur_char == 'U', "while parsing an unicode range: unicode range must start with an U", - CR_SYNTAX_ERROR) ; - - READ_NEXT_CHAR (a_this, &cur_char) ; + CR_SYNTAX_ERROR); - ENSURE_PARSING_COND_ERR + READ_NEXT_CHAR (a_this, &cur_char); + + ENSURE_PARSING_COND_ERR (a_this, cur_char == '+', "while parsing an unicode range: there must be a + after the U", - CR_SYNTAX_ERROR) ; + CR_SYNTAX_ERROR); - if (*a_inf == NULL) - { - *a_inf = g_string_new (NULL) ; - min_str_needs_free = TRUE ; + if (*a_inf == NULL) { + *a_inf = g_string_new (NULL); + min_str_needs_free = TRUE; } - for (i = 0 ;i < 6 ; i++) - { - PEEK_NEXT_CHAR (a_this, &next_char) ; + for (i = 0; i < 6; i++) { + PEEK_NEXT_CHAR (a_this, &next_char); if (cr_utils_is_hexa_char (next_char) == TRUE - || next_char == '?') - { - READ_NEXT_CHAR (a_this, &cur_char) ; - g_string_append_unichar (*a_inf, cur_char) ; - } - else - { - break ; + || next_char == '?') { + READ_NEXT_CHAR (a_this, &cur_char); + g_string_append_unichar (*a_inf, cur_char); + } else { + break; } } - - if (i < 1) - { - status = CR_PARSING_ERROR ; - cr_parser_push_error (a_this, + + if (i < 1) { + status = CR_PARSING_ERROR; + cr_parser_push_error (a_this, "No unicode range expressed", - CR_SYNTAX_ERROR) ; - goto error ; + CR_SYNTAX_ERROR); + goto error; } - if (next_char != '-') - { - return CR_OK ; + if (next_char != '-') { + return CR_OK; } - READ_NEXT_CHAR (a_this, &cur_char) ; - /*we are sure that cur_char == '-'*/ - - if (*a_sup == NULL) - { - *a_sup = g_string_new (NULL) ; - sup_str_needs_free = TRUE ; - } + READ_NEXT_CHAR (a_this, &cur_char); + /*we are sure that cur_char == '-' */ + if (*a_sup == NULL) { + *a_sup = g_string_new (NULL); + sup_str_needs_free = TRUE; + } - for (i = 0 ;i < 6 ; i++) - { - PEEK_NEXT_CHAR (a_this, &next_char) ; + for (i = 0; i < 6; i++) { + PEEK_NEXT_CHAR (a_this, &next_char); - if (cr_utils_is_hexa_char (next_char) == TRUE) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - if (*a_sup == NULL) - { - *a_sup = g_string_new (NULL) ; - sup_str_needs_free = TRUE ; + if (cr_utils_is_hexa_char (next_char) == TRUE) { + READ_NEXT_CHAR (a_this, &cur_char); + if (*a_sup == NULL) { + *a_sup = g_string_new (NULL); + sup_str_needs_free = TRUE; } - g_string_append_unichar (*a_sup, cur_char) ; - } - else - { - break ; + g_string_append_unichar (*a_sup, cur_char); + } else { + break; } } - cr_parser_clear_errors (a_this) ; - return CR_OK ; + cr_parser_clear_errors (a_this); + return CR_OK; - error: - - if (min_str_needs_free == TRUE && *a_inf) - { - g_free (*a_inf) ; - *a_inf = NULL ; + error: + + if (min_str_needs_free == TRUE && *a_inf) { + g_free (*a_inf); + *a_inf = NULL; } - if (sup_str_needs_free == TRUE && *a_sup) - { - g_free (*a_sup) ; - *a_sup = NULL ; + if (sup_str_needs_free == TRUE && *a_sup) { + g_free (*a_sup); + *a_sup = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -879,77 +791,63 @@ cr_parser_parse_unicode_range (CRParser *a_this, GString **a_inf, *lower level error occured. */ static enum CRStatus -cr_parser_parse_unicode_escape (CRParser *a_this, - guint32 *a_unicode) +cr_parser_parse_unicode_escape (CRParser * a_this, guint32 * a_unicode) { - guint32 cur_char ; - CRInputPos init_pos ; - glong occur = 0 ; - guint32 unicode = 0 ; - guchar *tmp_char_ptr1 = NULL, *tmp_char_ptr2 = NULL ; - enum CRStatus status = CR_OK ; + guint32 cur_char; + CRInputPos init_pos; + glong occur = 0; + guint32 unicode = 0; + guchar *tmp_char_ptr1 = NULL, + *tmp_char_ptr2 = NULL; + enum CRStatus status = CR_OK; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_unicode, - CR_BAD_PARAM_ERROR) ; - - /*first, let's backup the current position pointer*/ - RECORD_INITIAL_POS (a_this, &init_pos) ; - - READ_NEXT_CHAR (a_this, &cur_char) ; - - if (cur_char != '\\') - { - status = CR_PARSING_ERROR ; - goto error ; - } - - READ_NEXT_CHAR (a_this, &cur_char) ; - - for (occur = 0, unicode = 0 ; - ((cur_char >= '0' && cur_char <= '9') - || (cur_char >= 'a' && cur_char <= 'f') - || (cur_char >= 'A' && cur_char <= 'F')) && occur < 6 ; - occur ++) - { - gint cur_char_val = 0 ; - - if ((cur_char >= '0' && cur_char <= '9')) - { - cur_char_val = (cur_char - '0') ; - } - else if ((cur_char >= 'a' && cur_char <= 'f')) - { - cur_char_val = 10 + (cur_char - 'a') ; - } - else if ((cur_char >= 'A' && cur_char <= 'F')) - { - cur_char_val = 10 + (cur_char - 'A') ; - } + && a_unicode, CR_BAD_PARAM_ERROR); + + /*first, let's backup the current position pointer */ + RECORD_INITIAL_POS (a_this, &init_pos); - unicode = unicode * 10 + cur_char_val ; + READ_NEXT_CHAR (a_this, &cur_char); - READ_NEXT_CHAR (a_this, &cur_char) ; + if (cur_char != '\\') { + status = CR_PARSING_ERROR; + goto error; } + READ_NEXT_CHAR (a_this, &cur_char); + + for (occur = 0, unicode = 0; ((cur_char >= '0' && cur_char <= '9') + || (cur_char >= 'a' && cur_char <= 'f') + || (cur_char >= 'A' && cur_char <= 'F')) + && occur < 6; occur++) { + gint cur_char_val = 0; + + if ((cur_char >= '0' && cur_char <= '9')) { + cur_char_val = (cur_char - '0'); + } else if ((cur_char >= 'a' && cur_char <= 'f')) { + cur_char_val = 10 + (cur_char - 'a'); + } else if ((cur_char >= 'A' && cur_char <= 'F')) { + cur_char_val = 10 + (cur_char - 'A'); + } + + unicode = unicode * 10 + cur_char_val; + + READ_NEXT_CHAR (a_this, &cur_char); + } - if (occur == 5) - { + if (occur == 5) { /* *the unicode escape is 6 digit length */ - + /* *parse one space that may *appear just after the unicode *escape. */ - cr_parser_parse_w (a_this, &tmp_char_ptr1, - &tmp_char_ptr2) ; - status = CR_OK ; - } - else - { + cr_parser_parse_w (a_this, &tmp_char_ptr1, &tmp_char_ptr2); + status = CR_OK; + } else { /* *The unicode escape is less than *6 digit length. The character @@ -957,118 +855,101 @@ cr_parser_parse_unicode_escape (CRParser *a_this, *must be a white space. */ status = cr_parser_parse_w (a_this, &tmp_char_ptr1, - &tmp_char_ptr2) ; + &tmp_char_ptr2); CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, - "next char expected to be a space", - CR_SYNTAX_ERROR) ; + "next char expected to be a space", CR_SYNTAX_ERROR); + } + + if (status == CR_OK) { + *a_unicode = unicode; + cr_parser_clear_errors (a_this); + return CR_OK; } - - if (status == CR_OK) - { - *a_unicode = unicode ; - cr_parser_clear_errors (a_this) ; - return CR_OK ; - } - error: + error: /* *restore the initial position pointer backuped at *the beginning of this function. */ - cr_tknzr_set_cur_pos (PRIVATE (a_this)tknzr, - &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this) tknzr, &init_pos); - return status ; + return status; } - /** *parses an escape sequence as defined by the css spec: *escape ::= {unicode}|\\[ -~\200-\4177777] *@param a_this the current instance of #CRParser . */ static enum CRStatus -cr_parser_parse_escape (CRParser *a_this, guint32 *a_esc_code) +cr_parser_parse_escape (CRParser * a_this, guint32 * a_esc_code) { - enum CRStatus status = CR_OK ; - guint32 cur_char = 0 ; - CRInputPos init_pos ; - guchar next_chars[2] ; + enum CRStatus status = CR_OK; + guint32 cur_char = 0; + CRInputPos init_pos; + guchar next_chars[2]; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_esc_code, CR_BAD_PARAM_ERROR) ; + && a_esc_code, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - PEEK_BYTE (a_this, 1, &next_chars[0]) ; - PEEK_BYTE (a_this, 2, &next_chars[1]) ; + PEEK_BYTE (a_this, 1, &next_chars[0]); + PEEK_BYTE (a_this, 2, &next_chars[1]); - if (next_chars[0] != '\\') - { - status = CR_PARSING_ERROR ; - cr_parser_push_error + if (next_chars[0] != '\\') { + status = CR_PARSING_ERROR; + cr_parser_push_error (a_this, - "next char expected to be a '\\'", - CR_SYNTAX_ERROR) ; + "next char expected to be a '\\'", CR_SYNTAX_ERROR); - goto error ; + goto error; } - + if ((next_chars[1] >= '0' && next_chars[1] <= '9') - || (next_chars[1] >= 'a' && next_chars[1] <='z') - || (next_chars[1] >= 'A' && next_chars[1] <='Z')) - { - status = - cr_parser_parse_unicode_escape (a_this, - a_esc_code); + || (next_chars[1] >= 'a' && next_chars[1] <= 'z') + || (next_chars[1] >= 'A' && next_chars[1] <= 'Z')) { + status = cr_parser_parse_unicode_escape (a_this, a_esc_code); if (status != CR_OK - && cr_parser_errors_exist (a_this) == TRUE) - { - cr_parser_clear_errors (a_this) ; + && cr_parser_errors_exist (a_this) == TRUE) { + cr_parser_clear_errors (a_this); } - } - else - { - /*consume the '\' char*/ - READ_NEXT_CHAR (a_this, &cur_char) ; - - /*then read the char after the '\'*/ - READ_NEXT_CHAR (a_this, &cur_char) ; - - if (cur_char != ' ' - && (cur_char < 200 || cur_char > 4177777)) - { - status = CR_PARSING_ERROR ; - - cr_parser_push_error - (a_this, + } else { + /*consume the '\' char */ + READ_NEXT_CHAR (a_this, &cur_char); + + /*then read the char after the '\' */ + READ_NEXT_CHAR (a_this, &cur_char); + + if (cur_char != ' ' && (cur_char < 200 || cur_char > 4177777)) { + status = CR_PARSING_ERROR; + + cr_parser_push_error + (a_this, "next char expected to be a space", - CR_SYNTAX_ERROR) ; + CR_SYNTAX_ERROR); - goto error ; + goto error; } - *a_esc_code = cur_char ; + *a_esc_code = cur_char; } - if (status == CR_OK) - { - cr_parser_clear_errors (a_this) ; - return CR_OK ; + if (status == CR_OK) { + cr_parser_clear_errors (a_this); + return CR_OK; } - error: + error: - cr_tknzr_set_cur_pos (PRIVATE (a_this)tknzr, - &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this) tknzr, &init_pos); - return status ; + return status; } -#endif /*WITH_UNICODE_ESCAPE_AND_RANGE*/ - +#endif /*WITH_UNICODE_ESCAPE_AND_RANGE */ /************************************* *Non trivial terminal productions @@ -1086,92 +967,77 @@ cr_parser_parse_escape (CRParser *a_this, guint32 *a_esc_code) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_stylesheet_core (CRParser *a_this) +cr_parser_parse_stylesheet_core (CRParser * a_this) { - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - continue_parsing: + continue_parsing: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; - goto done ; - } - else if (status != CR_OK) - { - goto error ; - } - - switch (token->type) - { - + cr_parser_try_to_skip_spaces_and_comments (a_this); + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + goto done; + } else if (status != CR_OK) { + goto error; + } + + switch (token->type) { + case CDO_TK: case CDC_TK: - goto continue_parsing ; - break ; + goto continue_parsing; + break; default: - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token = NULL ; - status = cr_parser_parse_statement_core (a_this) ; - cr_parser_clear_errors (a_this) ; - if (status == CR_OK) - { - goto continue_parsing ; - } - else if (status == CR_END_OF_INPUT_ERROR) - { - goto done ; - } - else - { - goto error ; + status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, + token); + CHECK_PARSING_STATUS (status, TRUE); + token = NULL; + status = cr_parser_parse_statement_core (a_this); + cr_parser_clear_errors (a_this); + if (status == CR_OK) { + goto continue_parsing; + } else if (status == CR_END_OF_INPUT_ERROR) { + goto done; + } else { + goto error; } } - done: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + done: + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_parser_clear_errors (a_this) ; - return CR_OK ; - error: + cr_parser_clear_errors (a_this); + return CR_OK; + error: - cr_parser_push_error - (a_this, "could not recognize next production", - CR_ERROR) ; + cr_parser_push_error + (a_this, "could not recognize next production", CR_ERROR); - cr_parser_dump_err_stack (a_this, TRUE) ; + cr_parser_dump_err_stack (a_this, TRUE); - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -1183,77 +1049,68 @@ cr_parser_parse_stylesheet_core (CRParser *a_this) *otherwise. */ static enum CRStatus -cr_parser_parse_atrule_core (CRParser *a_this) +cr_parser_parse_atrule_core (CRParser * a_this) { - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && - (token->type == ATKEYWORD_TK - ||token->type == IMPORT_SYM_TK - ||token->type == PAGE_SYM_TK - ||token->type == MEDIA_SYM_TK - ||token->type == FONT_FACE_SYM_TK - ||token->type == CHARSET_SYM_TK)) ; - - cr_token_destroy (token) ; token = NULL ; - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; - do - { - status = cr_parser_parse_any_core (a_this) ; - } while (status == CR_OK) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token) ; - ENSURE_PARSING_COND (status == CR_OK && token) ; - - if (token->type == CBO_TK) - { - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - status = cr_parser_parse_block_core (a_this) ; - CHECK_PARSING_STATUS (status, FALSE) ; - goto done ; - } - else if (token->type == SEMICOLON_TK) - { - goto done ; - } - else - { - goto error ; - } + RECORD_INITIAL_POS (a_this, &init_pos); - done: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK + && token + && + (token->type == ATKEYWORD_TK + || token->type == IMPORT_SYM_TK + || token->type == PAGE_SYM_TK + || token->type == MEDIA_SYM_TK + || token->type == FONT_FACE_SYM_TK + || token->type == CHARSET_SYM_TK)); + + cr_token_destroy (token); + token = NULL; + + cr_parser_try_to_skip_spaces_and_comments (a_this); + + do { + status = cr_parser_parse_any_core (a_this); + } while (status == CR_OK); + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); + + if (token->type == CBO_TK) { + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); + token = NULL; + status = cr_parser_parse_block_core (a_this); + CHECK_PARSING_STATUS (status, FALSE); + goto done; + } else if (token->type == SEMICOLON_TK) { + goto done; + } else { + goto error; + } + + done: + if (token) { + cr_token_destroy (token); + token = NULL; } - return CR_OK ; + return CR_OK; - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + error: + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -1264,95 +1121,84 @@ cr_parser_parse_atrule_core (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_ruleset_core (CRParser *a_this) +cr_parser_parse_ruleset_core (CRParser * a_this) { - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - RECORD_INITIAL_POS (a_this, &init_pos) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_parser_parse_selector_core (a_this) ; + status = cr_parser_parse_selector_core (a_this); - ENSURE_PARSING_COND (status == CR_OK + ENSURE_PARSING_COND (status == CR_OK || status == CR_PARSING_ERROR - || status == CR_END_OF_INPUT_ERROR) ; + || status == CR_END_OF_INPUT_ERROR); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == CBO_TK) ; - cr_token_destroy (token) ; token = NULL ; - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - status = cr_parser_parse_declaration_core (a_this) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token + && token->type == CBO_TK); + cr_token_destroy (token); + token = NULL; - parse_declaration_list: - if (token) - { - cr_token_destroy (token) ; token = NULL ; + cr_parser_try_to_skip_spaces_and_comments (a_this); + status = cr_parser_parse_declaration_core (a_this); + + parse_declaration_list: + if (token) { + cr_token_destroy (token); + token = NULL; } - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token) ; - if (token->type == CBC_TK) - { - goto done ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); + if (token->type == CBC_TK) { + goto done; } ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == SEMICOLON_TK) ; - - cr_token_destroy (token) ; token = NULL ; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - status = cr_parser_parse_declaration_core (a_this) ; - cr_parser_clear_errors (a_this) ; - ENSURE_PARSING_COND (status == CR_OK - || status == CR_PARSING_ERROR) ; - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK && token) ; - if (token->type == CBC_TK) - { - cr_token_destroy (token) ; token = NULL ; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - goto done ; - } - else - { - status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; - goto parse_declaration_list ; - } - - done: - if (token) - { - cr_token_destroy (token) ; token = NULL ; + && token && token->type == SEMICOLON_TK); + + cr_token_destroy (token); + token = NULL; + cr_parser_try_to_skip_spaces_and_comments (a_this); + status = cr_parser_parse_declaration_core (a_this); + cr_parser_clear_errors (a_this); + ENSURE_PARSING_COND (status == CR_OK || status == CR_PARSING_ERROR); + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); + if (token->type == CBC_TK) { + cr_token_destroy (token); + token = NULL; + cr_parser_try_to_skip_spaces_and_comments (a_this); + goto done; + } else { + status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, + token); + token = NULL; + goto parse_declaration_list; } - if (status == CR_OK) - { - return CR_OK ; + done: + if (token) { + cr_token_destroy (token); + token = NULL; } - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (status == CR_OK) { + return CR_OK; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + error: + if (token) { + cr_token_destroy (token); + token = NULL; + } + + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -1364,38 +1210,35 @@ cr_parser_parse_ruleset_core (CRParser *a_this) *otherwise. */ static enum CRStatus -cr_parser_parse_selector_core (CRParser *a_this) +cr_parser_parse_selector_core (CRParser * a_this) { - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_parser_parse_any_core (a_this) ; - CHECK_PARSING_STATUS (status, FALSE) ; + status = cr_parser_parse_any_core (a_this); + CHECK_PARSING_STATUS (status, FALSE); - do - { - status = cr_parser_parse_any_core (a_this) ; + do { + status = cr_parser_parse_any_core (a_this); - }while (status == CR_OK) ; + } while (status == CR_OK); - return CR_OK ; + return CR_OK; - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + error: + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -1406,138 +1249,121 @@ cr_parser_parse_selector_core (CRParser *a_this) *FIXME: code this function. */ static enum CRStatus -cr_parser_parse_block_core (CRParser *a_this) +cr_parser_parse_block_core (CRParser * a_this) { - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == CBO_TK) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token + && token->type == CBO_TK); - parse_block_content: + parse_block_content: - if (token) - { - cr_token_destroy (token) ; token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; + } + + cr_parser_try_to_skip_spaces_and_comments (a_this); + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); + + if (token->type == CBC_TK) { + cr_parser_try_to_skip_spaces_and_comments (a_this); + goto done; + } else if (token->type == SEMICOLON_TK) { + goto parse_block_content; + } else if (token->type == ATKEYWORD_TK) { + cr_parser_try_to_skip_spaces_and_comments (a_this); + goto parse_block_content; + } else if (token->type == CBO_TK) { + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); + token = NULL; + status = cr_parser_parse_block_core (a_this); + CHECK_PARSING_STATUS (status, FALSE); + goto parse_block_content; + } else { + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); + token = NULL; + status = cr_parser_parse_any_core (a_this); + CHECK_PARSING_STATUS (status, FALSE); + goto parse_block_content; + } + + done: + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK && token) ; + if (status == CR_OK) + return CR_OK; - if (token->type == CBC_TK) - { - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - goto done ; - } - else if (token->type == SEMICOLON_TK) - { - goto parse_block_content ; - } - else if (token->type == ATKEYWORD_TK) - { - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - goto parse_block_content ; - } - else if (token->type == CBO_TK) - { - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - status = cr_parser_parse_block_core (a_this) ; - CHECK_PARSING_STATUS (status, FALSE) ; - goto parse_block_content ; - } - else - { - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - status = cr_parser_parse_any_core (a_this) ; - CHECK_PARSING_STATUS (status, FALSE) ; - goto parse_block_content ; + error: + if (token) { + cr_token_destroy (token); + token = NULL; } - done: - if (token) - { - cr_token_destroy (token) ; token = NULL ; - } + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - if (status == CR_OK) return CR_OK ; + return status; +} - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } +static enum CRStatus +cr_parser_parse_declaration_core (CRParser * a_this) +{ + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; + GString *prop = NULL; - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - return status ; -} + RECORD_INITIAL_POS (a_this, &init_pos); + status = cr_parser_parse_property (a_this, &prop); + CHECK_PARSING_STATUS (status, FALSE); + cr_parser_clear_errors (a_this); + ENSURE_PARSING_COND (status == CR_OK && prop); + g_string_free (prop, TRUE); + prop = NULL; -static enum CRStatus -cr_parser_parse_declaration_core (CRParser *a_this) -{ - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; - GString *prop = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_parser_parse_property (a_this, &prop) ; - CHECK_PARSING_STATUS (status, FALSE) ; - cr_parser_clear_errors (a_this) ; - ENSURE_PARSING_COND (status == CR_OK && prop) ; - g_string_free (prop, TRUE) ; prop = NULL ; - - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token); - ENSURE_PARSING_COND (status == CR_OK + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token && token->type == DELIM_TK - && token->u.unichar == ':' ) ; - cr_token_destroy (token) ; token = NULL ; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - status = cr_parser_parse_value_core (a_this) ; - CHECK_PARSING_STATUS (status, FALSE) ; + && token->u.unichar == ':'); + cr_token_destroy (token); + token = NULL; + cr_parser_try_to_skip_spaces_and_comments (a_this); + status = cr_parser_parse_value_core (a_this); + CHECK_PARSING_STATUS (status, FALSE); - return CR_OK ; + return CR_OK; - error: + error: - if (prop) - { - g_string_free (prop, TRUE) ; - prop = NULL ; + if (prop) { + g_string_free (prop, TRUE); + prop = NULL; } - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -1548,86 +1374,76 @@ cr_parser_parse_declaration_core (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_value_core (CRParser *a_this) +cr_parser_parse_value_core (CRParser * a_this) { - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; - glong ref = 0 ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - RECORD_INITIAL_POS (a_this, &init_pos) ; + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; + glong ref = 0; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); + RECORD_INITIAL_POS (a_this, &init_pos); - continue_parsing: + continue_parsing: - if (token) - { - cr_token_destroy (token) ; token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK && token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); - switch (token->type) - { + switch (token->type) { case CBO_TK: status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; - status = cr_parser_parse_block_core (a_this) ; - CHECK_PARSING_STATUS (status, FALSE) ; - ref ++ ; - goto continue_parsing ; + token); + token = NULL; + status = cr_parser_parse_block_core (a_this); + CHECK_PARSING_STATUS (status, FALSE); + ref++; + goto continue_parsing; case ATKEYWORD_TK: - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - ref ++ ; - goto continue_parsing ; + cr_parser_try_to_skip_spaces_and_comments (a_this); + ref++; + goto continue_parsing; - default : + default: status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; - status = cr_parser_parse_any_core (a_this) ; - if (status == CR_OK) - { - ref ++ ; - goto continue_parsing ; - } - else if (status == CR_PARSING_ERROR) - { - status = CR_OK ; - goto done ; - } - else - { - goto error ; + token); + token = NULL; + status = cr_parser_parse_any_core (a_this); + if (status == CR_OK) { + ref++; + goto continue_parsing; + } else if (status == CR_PARSING_ERROR) { + status = CR_OK; + goto done; + } else { + goto error; } } - done: - if (token) - { - cr_token_destroy (token) ; token = NULL ; + done: + if (token) { + cr_token_destroy (token); + token = NULL; } if (status == CR_OK && ref) - return CR_OK ; - error: - if (token) - { - cr_token_destroy (token) ; token = NULL ; + return CR_OK; + error: + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - /** *Parses an "any" as defined by the css core grammar in the *css2 spec in chapter 4.1. @@ -1639,23 +1455,22 @@ cr_parser_parse_value_core (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_any_core (CRParser *a_this) +cr_parser_parse_any_core (CRParser * a_this) { - CRToken *token1 = NULL, *token2 = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; + CRToken *token1 = NULL, + *token2 = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token1) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token1); - ENSURE_PARSING_COND (status == CR_OK && token1) ; + ENSURE_PARSING_COND (status == CR_OK && token1); - switch (token1->type) - { + switch (token1->type) { case IDENT_TK: case NUMBER_TK: case RGB_TK: @@ -1677,8 +1492,8 @@ cr_parser_parse_any_core (CRParser *a_this) case S_TK: case IMPORTANT_SYM_TK: case SEMICOLON_TK: - status = CR_OK ; - break ; + status = CR_OK; + break; case FUNCTION_TK: /* *this case isn't specified by the spec but it @@ -1686,123 +1501,105 @@ cr_parser_parse_any_core (CRParser *a_this) *We must consider function with parameters. *We consider parameter as being an "any*" production. */ - do - { - status = cr_parser_parse_any_core (a_this) ; - } while (status == CR_OK) ; - - ENSURE_PARSING_COND (status == CR_PARSING_ERROR) ; + do { + status = cr_parser_parse_any_core (a_this); + } while (status == CR_OK); + + ENSURE_PARSING_COND (status == CR_PARSING_ERROR); status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token2) ; - ENSURE_PARSING_COND (status == CR_OK - && token2 - && token2->type == PC_TK) ; - break ; + &token2); + ENSURE_PARSING_COND (status == CR_OK + && token2 && token2->type == PC_TK); + break; case PO_TK: status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token2) ; - ENSURE_PARSING_COND (status == CR_OK && token2) ; - - if (token2->type == PC_TK) - { - cr_token_destroy (token2) ; - token2 = NULL ; - goto done ; - } - else - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token2) ; - token2 = NULL ; + &token2); + ENSURE_PARSING_COND (status == CR_OK && token2); + + if (token2->type == PC_TK) { + cr_token_destroy (token2); + token2 = NULL; + goto done; + } else { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token2); + token2 = NULL; } - do - { - status = cr_parser_parse_any_core (a_this) ; - } while (status == CR_OK) ; + do { + status = cr_parser_parse_any_core (a_this); + } while (status == CR_OK); - ENSURE_PARSING_COND (status == CR_PARSING_ERROR) ; + ENSURE_PARSING_COND (status == CR_PARSING_ERROR); status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token2) ; - ENSURE_PARSING_COND (status == CR_OK - && token2 - && token2->type == PC_TK) ; - status = CR_OK ; - break ; + &token2); + ENSURE_PARSING_COND (status == CR_OK + && token2 && token2->type == PC_TK); + status = CR_OK; + break; case BO_TK: status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token2) ; - ENSURE_PARSING_COND (status == CR_OK && token2) ; - - if (token2->type == BC_TK) - { - cr_token_destroy (token2) ; - token2 = NULL ; - goto done ; - } - else - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token2) ; - token2 = NULL ; + &token2); + ENSURE_PARSING_COND (status == CR_OK && token2); + + if (token2->type == BC_TK) { + cr_token_destroy (token2); + token2 = NULL; + goto done; + } else { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token2); + token2 = NULL; } - do - { - status = cr_parser_parse_any_core (a_this) ; - } while (status == CR_OK) ; + do { + status = cr_parser_parse_any_core (a_this); + } while (status == CR_OK); - ENSURE_PARSING_COND (status == CR_PARSING_ERROR) ; + ENSURE_PARSING_COND (status == CR_PARSING_ERROR); status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token2) ; - ENSURE_PARSING_COND (status == CR_OK - && token2 - && token2->type == BC_TK) ; - status = CR_OK ; - break ; + &token2); + ENSURE_PARSING_COND (status == CR_OK + && token2 && token2->type == BC_TK); + status = CR_OK; + break; default: - status = CR_PARSING_ERROR ; - goto error ; + status = CR_PARSING_ERROR; + goto error; } - done: - if (token1) - { - cr_token_destroy (token1) ; - token1 = NULL ; + done: + if (token1) { + cr_token_destroy (token1); + token1 = NULL; } - if (token2) - { - cr_token_destroy (token2) ; - token2 = NULL ; + if (token2) { + cr_token_destroy (token2); + token2 = NULL; } - return CR_OK ; + return CR_OK; - error: + error: - if (token1) - { - cr_token_destroy (token1) ; - token1 = NULL ; + if (token1) { + cr_token_destroy (token1); + token1 = NULL; } - if (token2) - { - cr_token_destroy (token2) ; - token2 = NULL ; + if (token2) { + cr_token_destroy (token2); + token2 = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - return status ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); + return status; } - - /** *Parses an attribute selector as defined in the css2 spec in *appendix D.1: @@ -1815,157 +1612,124 @@ cr_parser_parse_any_core (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_attribute_selector (CRParser *a_this, CRAttrSel **a_sel) +cr_parser_parse_attribute_selector (CRParser * a_this, CRAttrSel ** a_sel) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - CRToken *token = NULL ; - CRAttrSel *result = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + CRToken *token = NULL; + CRAttrSel *result = NULL; - g_return_val_if_fail (a_this && a_sel, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_sel, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == BO_TK) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token + && token->type == BO_TK); - cr_token_destroy (token) ; - token = NULL ; + cr_token_destroy (token); + token = NULL; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - result = cr_attr_sel_new () ; + result = cr_attr_sel_new (); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == IDENT_TK) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == IDENT_TK); - result->name = token->u.str ; - token->u.str = NULL ; - cr_token_destroy (token) ; - token = NULL ; + result->name = token->u.str; + token->u.str = NULL; + cr_token_destroy (token); + token = NULL; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); - if (token->type == INCLUDES_TK) - { - result->match_way = INCLUDES ; - goto parse_right_part ; - } - else if (token->type == DASHMATCH_TK) - { - result->match_way = DASHMATCH ; - goto parse_right_part ; - } - else if (token->type == DELIM_TK && token->u.unichar == '=') - { - result->match_way = EQUALS ; - goto parse_right_part ; - } - else if (token->type == BC_TK) - { - result->match_way = SET ; - goto done ; + if (token->type == INCLUDES_TK) { + result->match_way = INCLUDES; + goto parse_right_part; + } else if (token->type == DASHMATCH_TK) { + result->match_way = DASHMATCH; + goto parse_right_part; + } else if (token->type == DELIM_TK && token->u.unichar == '=') { + result->match_way = EQUALS; + goto parse_right_part; + } else if (token->type == BC_TK) { + result->match_way = SET; + goto done; } - parse_right_part: - - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + parse_right_part: + + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - ENSURE_PARSING_COND (status == CR_OK - && token) ; + ENSURE_PARSING_COND (status == CR_OK && token); - if (token->type == IDENT_TK) - { - result->value = token->u.str ; - token->u.str = NULL ; - } - else if (token->type == STRING_TK) - { - result->value = token->u.str ; - token->u.str = NULL ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + if (token->type == IDENT_TK) { + result->value = token->u.str; + token->u.str = NULL; + } else if (token->type == STRING_TK) { + result->value = token->u.str; + token->u.str = NULL; + } else { + status = CR_PARSING_ERROR; + goto error; } - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == BC_TK) ; - done: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - if (*a_sel) - { - status = cr_attr_sel_append_attr_sel (*a_sel, - result) ; - CHECK_PARSING_STATUS (status, FALSE) ; + ENSURE_PARSING_COND (status == CR_OK && token + && token->type == BC_TK); + done: + if (token) { + cr_token_destroy (token); + token = NULL; } - else - { - *a_sel = result ; + + if (*a_sel) { + status = cr_attr_sel_append_attr_sel (*a_sel, result); + CHECK_PARSING_STATUS (status, FALSE); + } else { + *a_sel = result; } - cr_parser_clear_errors (a_this) ; - return CR_OK ; + cr_parser_clear_errors (a_this); + return CR_OK; + + error: - error: - - if (result) - { - cr_attr_sel_destroy (result) ; - result = NULL ; + if (result) { + cr_attr_sel_destroy (result); + result = NULL; } - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - - /** *Parses a "property" as specified by the css2 spec at [4.1.1]: *property : IDENT S*; @@ -1980,36 +1744,34 @@ cr_parser_parse_attribute_selector (CRParser *a_this, CRAttrSel **a_sel) *next construction was not a "property", or an error code. */ static enum CRStatus -cr_parser_parse_property (CRParser *a_this, GString **a_property) +cr_parser_parse_property (CRParser * a_this, GString ** a_property) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->tknzr - && a_property, - CR_BAD_PARAM_ERROR) ; + && a_property, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_parser_parse_ident (a_this, a_property) ; + status = cr_parser_parse_ident (a_this, a_property); if (status != CR_OK) - status = cr_parser_parse_vendor_specific_ident - (a_this, a_property) ; - CHECK_PARSING_STATUS (status, TRUE) ; + status = cr_parser_parse_vendor_specific_ident + (a_this, a_property); + CHECK_PARSING_STATUS (status, TRUE); - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - cr_parser_clear_errors (a_this) ; - return CR_OK ; - - error: + cr_parser_clear_errors (a_this); + return CR_OK; - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - - return status ; -} + error: + + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); + return status; +} /** *Parses a "term" as defined in the css2 spec, appendix D.1: @@ -2023,156 +1785,125 @@ cr_parser_parse_property (CRParser *a_this, GString **a_property) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) +cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term) { - enum CRStatus status = CR_PARSING_ERROR ; - CRInputPos init_pos ; + enum CRStatus status = CR_PARSING_ERROR; + CRInputPos init_pos; CRTerm *result = NULL; - CRTerm *param = NULL ; - CRToken * token = NULL ; - GString *func_name = NULL ; - - g_return_val_if_fail (a_this && a_term, CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - result = cr_term_new () ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status != CR_OK || !token) goto error ; - - if (token->type == DELIM_TK && token->u.unichar == '+') - { - result->unary_op = PLUS_UOP ; - } - else if (token->type - == DELIM_TK && token->u.unichar == '-') - { - result->unary_op = MINUS_UOP ; - } - else if (token->type == EMS_TK - || token->type == EXS_TK - || token->type == LENGTH_TK - || token->type == ANGLE_TK - || token->type == TIME_TK - || token->type == FREQ_TK - || token->type == PERCENTAGE_TK - || token->type == NUMBER_TK) - { - status = cr_term_set_number (result, token->u.num) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token->u.num = NULL ; - status = CR_OK ; - } - else if (token && token->type == FUNCTION_TK) - { + CRTerm *param = NULL; + CRToken *token = NULL; + GString *func_name = NULL; + + g_return_val_if_fail (a_this && a_term, CR_BAD_PARAM_ERROR); + + RECORD_INITIAL_POS (a_this, &init_pos); + + result = cr_term_new (); + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + if (status != CR_OK || !token) + goto error; + + if (token->type == DELIM_TK && token->u.unichar == '+') { + result->unary_op = PLUS_UOP; + } else if (token->type == DELIM_TK && token->u.unichar == '-') { + result->unary_op = MINUS_UOP; + } else if (token->type == EMS_TK + || token->type == EXS_TK + || token->type == LENGTH_TK + || token->type == ANGLE_TK + || token->type == TIME_TK + || token->type == FREQ_TK + || token->type == PERCENTAGE_TK + || token->type == NUMBER_TK) { + status = cr_term_set_number (result, token->u.num); + CHECK_PARSING_STATUS (status, TRUE); + token->u.num = NULL; + status = CR_OK; + } else if (token && token->type == FUNCTION_TK) { status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; - status = cr_parser_parse_function - (a_this, &func_name, ¶m) ; + token); + token = NULL; + status = cr_parser_parse_function (a_this, &func_name, + ¶m); - if (status == CR_OK) - { + if (status == CR_OK) { status = cr_term_set_function (result, func_name, - param) ; - CHECK_PARSING_STATUS (status, TRUE) ; + param); + CHECK_PARSING_STATUS (status, TRUE); } - } - else if (token && token->type == STRING_TK) - { - status = cr_term_set_string (result, token->u.str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token->u.str = NULL ; - } - else if (token && token->type == IDENT_TK) - { - status = cr_term_set_ident (result, token->u.str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token->u.str = NULL ; - } - else if (token && token->type == URI_TK) - { - status = cr_term_set_uri (result, token->u.str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token->u.str = NULL ; - } - else if (token && token->type == RGB_TK) - { - status = cr_term_set_rgb (result, token->u.rgb) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token->u.rgb = NULL ; - } - else if (token && token->type == UNICODERANGE_TK) - { - result->type = TERM_UNICODERANGE ; - status = CR_PARSING_ERROR ; - } - else if (token && token->type == HASH_TK) - { - status = cr_term_set_hash (result, token->u.str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token->u.str = NULL ; - } - else - { - status = CR_PARSING_ERROR ; - } - - if (status != CR_OK) - { - goto error ; - } - - *a_term = cr_term_append_term (*a_term, result) ; - - result = NULL ; - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - if (token) - { + } else if (token && token->type == STRING_TK) { + status = cr_term_set_string (result, token->u.str); + CHECK_PARSING_STATUS (status, TRUE); + token->u.str = NULL; + } else if (token && token->type == IDENT_TK) { + status = cr_term_set_ident (result, token->u.str); + CHECK_PARSING_STATUS (status, TRUE); + token->u.str = NULL; + } else if (token && token->type == URI_TK) { + status = cr_term_set_uri (result, token->u.str); + CHECK_PARSING_STATUS (status, TRUE); + token->u.str = NULL; + } else if (token && token->type == RGB_TK) { + status = cr_term_set_rgb (result, token->u.rgb); + CHECK_PARSING_STATUS (status, TRUE); + token->u.rgb = NULL; + } else if (token && token->type == UNICODERANGE_TK) { + result->type = TERM_UNICODERANGE; + status = CR_PARSING_ERROR; + } else if (token && token->type == HASH_TK) { + status = cr_term_set_hash (result, token->u.str); + CHECK_PARSING_STATUS (status, TRUE); + token->u.str = NULL; + } else { + status = CR_PARSING_ERROR; + } + + if (status != CR_OK) { + goto error; + } + + *a_term = cr_term_append_term (*a_term, result); + + result = NULL; + + cr_parser_try_to_skip_spaces_and_comments (a_this); + + if (token) { cr_token_destroy (token); - token = NULL ; + token = NULL; } - cr_parser_clear_errors (a_this) ; - return CR_OK ; + cr_parser_clear_errors (a_this); + return CR_OK; - error: + error: - if (result) - { - cr_term_destroy (result) ; - result = NULL ; + if (result) { + cr_term_destroy (result); + result = NULL; } - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - if (param) - { - cr_term_destroy (param) ; - param = NULL ; + if (param) { + cr_term_destroy (param); + param = NULL; } - if (func_name) - { - g_string_free (func_name, TRUE) ; - func_name = NULL ; + if (func_name) { + g_string_free (func_name, TRUE); + func_name = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - - /** *Parses a "simple_selector" as defined by the css2 spec in appendix D.1 : *element_name? [ HASH | class | attrib | pseudo ]* S* @@ -2185,279 +1916,239 @@ cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_simple_selector (CRParser *a_this, CRSimpleSel **a_sel) +cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel) { - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - CRToken *token = NULL ; - CRSimpleSel * sel = NULL ; - CRAdditionalSel *add_sel_list = NULL ; - gboolean found_sel = FALSE ; - guint32 cur_char = 0 ; - - g_return_val_if_fail (a_this && a_sel, CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status != CR_OK) goto error ; - - sel = cr_simple_sel_new () ; - ENSURE_PARSING_COND (sel) ; - - if (token && token->type == DELIM_TK && token->u.unichar == '*') - { - sel->type_mask |= UNIVERSAL_SELECTOR ; - sel->name = g_string_new ("*") ; - found_sel = TRUE ; - } - else if (token && token->type == IDENT_TK) - { - sel->name = token->u.str ; - sel->type_mask |= TYPE_SELECTOR ; - token->u.str = NULL ; - found_sel = TRUE ; - - } - else - { + enum CRStatus status = CR_ERROR; + CRInputPos init_pos; + CRToken *token = NULL; + CRSimpleSel *sel = NULL; + CRAdditionalSel *add_sel_list = NULL; + gboolean found_sel = FALSE; + guint32 cur_char = 0; + + g_return_val_if_fail (a_this && a_sel, CR_BAD_PARAM_ERROR); + + RECORD_INITIAL_POS (a_this, &init_pos); + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + if (status != CR_OK) + goto error; + + sel = cr_simple_sel_new (); + ENSURE_PARSING_COND (sel); + + if (token && token->type == DELIM_TK && token->u.unichar == '*') { + sel->type_mask |= UNIVERSAL_SELECTOR; + sel->name = g_string_new ("*"); + found_sel = TRUE; + } else if (token && token->type == IDENT_TK) { + sel->name = token->u.str; + sel->type_mask |= TYPE_SELECTOR; + token->u.str = NULL; + found_sel = TRUE; + + } else { status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; + token); + token = NULL; } - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - for (;;) - { - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + for (;;) { + if (token) { + cr_token_destroy (token); + token = NULL; } status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status != CR_OK) goto error ; + &token); + if (status != CR_OK) + goto error; - if (token && token->type == HASH_TK) - { - /*we parsed an attribute id*/ - CRAdditionalSel *add_sel = NULL ; + if (token && token->type == HASH_TK) { + /*we parsed an attribute id */ + CRAdditionalSel *add_sel = NULL; - add_sel = cr_additional_sel_new_with_type - (ID_ADD_SELECTOR) ; + add_sel = cr_additional_sel_new_with_type + (ID_ADD_SELECTOR); - add_sel->content.id_name = token->u.str ; - token->u.str = NULL ; - - add_sel_list = - cr_additional_sel_append - (add_sel_list, add_sel) ; + add_sel->content.id_name = token->u.str; + token->u.str = NULL; - found_sel = TRUE ; - } - else if (token - && (token->type == DELIM_TK) - && (token->u.unichar == '.')) - { - cr_token_destroy (token) ; - token = NULL ; + add_sel_list = + cr_additional_sel_append + (add_sel_list, add_sel); - status = cr_tknzr_get_next_token - (PRIVATE (a_this)->tknzr, &token) ; - if (status != CR_OK) goto error ; + found_sel = TRUE; + } else if (token && (token->type == DELIM_TK) + && (token->u.unichar == '.')) { + cr_token_destroy (token); + token = NULL; + + status = cr_tknzr_get_next_token + (PRIVATE (a_this)->tknzr, &token); + if (status != CR_OK) + goto error; - if (token && token->type == IDENT_TK) - { - CRAdditionalSel *add_sel = NULL ; + if (token && token->type == IDENT_TK) { + CRAdditionalSel *add_sel = NULL; add_sel = cr_additional_sel_new_with_type - (CLASS_ADD_SELECTOR) ; + (CLASS_ADD_SELECTOR); - add_sel->content.class_name = token->u.str ; - token->u.str = NULL ; + add_sel->content.class_name = token->u.str; + token->u.str = NULL; - add_sel_list = - cr_additional_sel_append - (add_sel_list, add_sel) ; - found_sel = TRUE ; - } - else - { - status = CR_OK ; - goto error ; + add_sel_list = + cr_additional_sel_append + (add_sel_list, add_sel); + found_sel = TRUE; + } else { + status = CR_OK; + goto error; } - } - else if (token - && token->type == BO_TK) - { - CRAttrSel *attr_sel = NULL ; - CRAdditionalSel *add_sel = NULL ; + } else if (token && token->type == BO_TK) { + CRAttrSel *attr_sel = NULL; + CRAdditionalSel *add_sel = NULL; - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - if (status != CR_OK) goto error ; - token = NULL ; + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + if (status != CR_OK) + goto error; + token = NULL; - status = cr_parser_parse_attribute_selector - (a_this, &attr_sel) ; - CHECK_PARSING_STATUS (status, FALSE) ; + status = cr_parser_parse_attribute_selector + (a_this, &attr_sel); + CHECK_PARSING_STATUS (status, FALSE); add_sel = cr_additional_sel_new_with_type - (ATTRIBUTE_ADD_SELECTOR) ; + (ATTRIBUTE_ADD_SELECTOR); - ENSURE_PARSING_COND (add_sel != NULL) ; + ENSURE_PARSING_COND (add_sel != NULL); - add_sel->content.attr_sel = attr_sel ; + add_sel->content.attr_sel = attr_sel; - add_sel_list = - cr_additional_sel_append - (add_sel_list, add_sel) ; - found_sel = TRUE ; - } - else if (token - && (token->type == DELIM_TK) - && (token->u.unichar == ':')) - { - CRPseudo *pseudo = NULL ; - - /*try to parse a pseudo*/ - - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } + add_sel_list = + cr_additional_sel_append + (add_sel_list, add_sel); + found_sel = TRUE; + } else if (token && (token->type == DELIM_TK) + && (token->u.unichar == ':')) { + CRPseudo *pseudo = NULL; - pseudo = cr_pseudo_new () ; + /*try to parse a pseudo */ - status = cr_tknzr_get_next_token - (PRIVATE (a_this)->tknzr, &token) ; - - ENSURE_PARSING_COND (status == CR_OK - && token) ; - - if (token->type == IDENT_TK) - { - pseudo->type = IDENT_PSEUDO ; - pseudo->name = token->u.str ; - token->u.str = NULL ; - found_sel = TRUE ; - } - else if (token->type == FUNCTION_TK) - { - pseudo->name = token->u.str ; - token->u.str = NULL ; - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - status = cr_parser_parse_ident - (a_this, &pseudo->extra) ; - - ENSURE_PARSING_COND (status == CR_OK) ; - READ_NEXT_CHAR (a_this, &cur_char) ; - ENSURE_PARSING_COND (cur_char == ')') ; - pseudo->type = FUNCTION_PSEUDO ; - found_sel = TRUE ; + if (token) { + cr_token_destroy (token); + token = NULL; } - else - { - status = CR_PARSING_ERROR ; - goto error ; + + pseudo = cr_pseudo_new (); + + status = cr_tknzr_get_next_token + (PRIVATE (a_this)->tknzr, &token); + + ENSURE_PARSING_COND (status == CR_OK && token); + + if (token->type == IDENT_TK) { + pseudo->type = IDENT_PSEUDO; + pseudo->name = token->u.str; + token->u.str = NULL; + found_sel = TRUE; + } else if (token->type == FUNCTION_TK) { + pseudo->name = token->u.str; + token->u.str = NULL; + cr_parser_try_to_skip_spaces_and_comments + (a_this); + status = cr_parser_parse_ident + (a_this, &pseudo->extra); + + ENSURE_PARSING_COND (status == CR_OK); + READ_NEXT_CHAR (a_this, &cur_char); + ENSURE_PARSING_COND (cur_char == ')'); + pseudo->type = FUNCTION_PSEUDO; + found_sel = TRUE; + } else { + status = CR_PARSING_ERROR; + goto error; } - if (status == CR_OK) - { - CRAdditionalSel *add_sel = NULL ; + if (status == CR_OK) { + CRAdditionalSel *add_sel = NULL; add_sel = cr_additional_sel_new_with_type - (PSEUDO_CLASS_ADD_SELECTOR) ; + (PSEUDO_CLASS_ADD_SELECTOR); - add_sel->content.pseudo = pseudo ; + add_sel->content.pseudo = pseudo; add_sel_list = - cr_additional_sel_append - (add_sel_list, add_sel) ; + cr_additional_sel_append + (add_sel_list, add_sel); - status = CR_OK ; + status = CR_OK; } - } - else - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - break ; + } else { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + token = NULL; + break; } } - if (status == CR_OK && found_sel == TRUE) - { - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + if (status == CR_OK && found_sel == TRUE) { + cr_parser_try_to_skip_spaces_and_comments (a_this); - sel->add_sel = add_sel_list ; - add_sel_list = NULL ; + sel->add_sel = add_sel_list; + add_sel_list = NULL; - if (*a_sel == NULL) - { - *a_sel = sel ; - } - else - { - cr_simple_sel_append_simple_sel (*a_sel, sel) ; + if (*a_sel == NULL) { + *a_sel = sel; + } else { + cr_simple_sel_append_simple_sel (*a_sel, sel); } - sel = NULL ; + sel = NULL; - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_parser_clear_errors (a_this) ; - return CR_OK ; - } - else - { - status = CR_PARSING_ERROR ; + cr_parser_clear_errors (a_this); + return CR_OK; + } else { + status = CR_PARSING_ERROR; } - - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } - - if (add_sel_list) - { - cr_additional_sel_destroy (add_sel_list) ; - add_sel_list = NULL ; + error: + + if (token) { + cr_token_destroy (token); + token = NULL; } - if (sel) - { - cr_simple_sel_destroy (sel) ; - sel = NULL ; + if (add_sel_list) { + cr_additional_sel_destroy (add_sel_list); + add_sel_list = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + if (sel) { + cr_simple_sel_destroy (sel); + sel = NULL; + } - return status ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); + return status; } - /** *Parses a "selector" as defined by the css2 spec in appendix D.1: *selector ::= simple_selector [ combinator simple_selector ]* @@ -2471,196 +2162,165 @@ cr_parser_parse_simple_selector (CRParser *a_this, CRSimpleSel **a_sel) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_simple_sels (CRParser *a_this, CRSimpleSel **a_sel) +cr_parser_parse_simple_sels (CRParser * a_this, CRSimpleSel ** a_sel) { - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - CRSimpleSel *sel = NULL ; - guint32 cur_char = 0 ; + enum CRStatus status = CR_ERROR; + CRInputPos init_pos; + CRSimpleSel *sel = NULL; + guint32 cur_char = 0; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_parser_parse_simple_selector (a_this, &sel) ; - CHECK_PARSING_STATUS (status, FALSE) ; + status = cr_parser_parse_simple_selector (a_this, &sel); + CHECK_PARSING_STATUS (status, FALSE); - *a_sel = cr_simple_sel_append_simple_sel (*a_sel, sel) ; + *a_sel = cr_simple_sel_append_simple_sel (*a_sel, sel); - for (;;) - { - guint32 next_char = 0 ; - enum Combinator comb = 0 ; + for (;;) { + guint32 next_char = 0; + enum Combinator comb = 0; - sel = NULL ; + sel = NULL; - PEEK_NEXT_CHAR (a_this, &next_char) ; + PEEK_NEXT_CHAR (a_this, &next_char); - if (next_char == '+') - { - READ_NEXT_CHAR (a_this, &cur_char) ; - comb = COMB_PLUS ; - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; + if (next_char == '+') { + READ_NEXT_CHAR (a_this, &cur_char); + comb = COMB_PLUS; + cr_parser_try_to_skip_spaces_and_comments (a_this); + } else if (next_char == '>') { + READ_NEXT_CHAR (a_this, &cur_char); + comb = COMB_GT; + cr_parser_try_to_skip_spaces_and_comments (a_this); + } else { + comb = COMB_WS; } - else if (next_char == '>') - { - READ_NEXT_CHAR (a_this, &cur_char) ; - comb = COMB_GT ; - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - } - else - { - comb = COMB_WS ; - } - - status = cr_parser_parse_simple_selector (a_this, &sel) ; - if (status != CR_OK) break ; - - if (comb) - { - sel->combinator = comb ; - comb = 0 ; + + status = cr_parser_parse_simple_selector (a_this, &sel); + if (status != CR_OK) + break; + + if (comb) { + sel->combinator = comb; + comb = 0; } - *a_sel = cr_simple_sel_append_simple_sel (*a_sel, sel) ; + *a_sel = cr_simple_sel_append_simple_sel (*a_sel, sel); } - cr_parser_clear_errors (a_this) ; - return CR_OK ; + cr_parser_clear_errors (a_this); + return CR_OK; - error: + error: - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - - static enum CRStatus -cr_parser_parse_selector (CRParser *a_this, CRSelector **a_selector) +cr_parser_parse_selector (CRParser * a_this, CRSelector ** a_selector) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - guint32 cur_char = 0, next_char = 0 ; - CRSimpleSel * simple_sels = NULL ; - CRSelector *selector = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + guint32 cur_char = 0, + next_char = 0; + CRSimpleSel *simple_sels = NULL; + CRSelector *selector = NULL; - g_return_val_if_fail (a_this && a_selector, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_selector, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_parser_parse_simple_sels (a_this, &simple_sels) ; + status = cr_parser_parse_simple_sels (a_this, &simple_sels); - CHECK_PARSING_STATUS (status, FALSE) ; + CHECK_PARSING_STATUS (status, FALSE); - if (simple_sels) - { - selector = cr_selector_append_simple_sel - (selector, simple_sels) ; - simple_sels = NULL ; + if (simple_sels) { + selector = cr_selector_append_simple_sel + (selector, simple_sels); + simple_sels = NULL; } - status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, - &next_char) ; - if (status != CR_OK) - { - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; - goto okay ; - } - else - { - goto error ; + status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, &next_char); + if (status != CR_OK) { + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + goto okay; + } else { + goto error; } } - if (next_char == ',') - { - for (;;) - { - simple_sels = NULL ; + if (next_char == ',') { + for (;;) { + simple_sels = NULL; status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, - &next_char) ; - if (status != CR_OK) - { - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; - break ; - } - else - { - goto error ; + &next_char); + if (status != CR_OK) { + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + break; + } else { + goto error; } } - - if (next_char != ',') break ; - /*consume the ',' char*/ - READ_NEXT_CHAR (a_this, &cur_char) ; + if (next_char != ',') + break; - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; + /*consume the ',' char */ + READ_NEXT_CHAR (a_this, &cur_char); - status = cr_parser_parse_simple_sels - (a_this, &simple_sels) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - CHECK_PARSING_STATUS (status, FALSE) ; + status = cr_parser_parse_simple_sels + (a_this, &simple_sels); - if (simple_sels) - { - selector = - cr_selector_append_simple_sel - (selector, simple_sels) ; + CHECK_PARSING_STATUS (status, FALSE); - simple_sels = NULL ; + if (simple_sels) { + selector = + cr_selector_append_simple_sel + (selector, simple_sels); + + simple_sels = NULL; } } } - okay: - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + okay: + cr_parser_try_to_skip_spaces_and_comments (a_this); - if (!*a_selector) - { - *a_selector = selector ; - } - else - { - *a_selector = cr_selector_append (*a_selector, - selector) ; + if (!*a_selector) { + *a_selector = selector; + } else { + *a_selector = cr_selector_append (*a_selector, selector); } - selector = NULL ; - return CR_OK ; + selector = NULL; + return CR_OK; - error: - - if (simple_sels) - { - cr_simple_sel_destroy (simple_sels) ; - simple_sels = NULL ; + error: + + if (simple_sels) { + cr_simple_sel_destroy (simple_sels); + simple_sels = NULL; } - if (selector) - { - cr_selector_unref (selector) ; - selector = NULL ; + if (selector) { + cr_selector_unref (selector); + selector = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - /** *Parses a "function" as defined in css spec at appendix D.1: *function ::= FUNCTION S* expr ')' S* @@ -2674,97 +2334,86 @@ cr_parser_parse_selector (CRParser *a_this, CRSelector **a_selector) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_function (CRParser *a_this, GString **a_func_name, - CRTerm **a_expr) +cr_parser_parse_function (CRParser * a_this, + GString ** a_func_name, CRTerm ** a_expr) { - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; - CRToken *token = NULL ; - CRTerm *expr = NULL ; + CRInputPos init_pos; + enum CRStatus status = CR_OK; + CRToken *token = NULL; + CRTerm *expr = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_func_name, - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; + && a_func_name, CR_BAD_PARAM_ERROR); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status != CR_OK) goto error ; + RECORD_INITIAL_POS (a_this, &init_pos); - if (token && token->type == FUNCTION_TK) - { - *a_func_name = token->u.str ; - token->u.str = NULL ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + if (status != CR_OK) + goto error; + + if (token && token->type == FUNCTION_TK) { + *a_func_name = token->u.str; + token->u.str = NULL; + } else { + status = CR_PARSING_ERROR; + goto error; } - cr_token_destroy (token) ; - token = NULL ; + cr_token_destroy (token); + token = NULL; + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + if (status != CR_OK) + goto error; - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status != CR_OK) goto error ; + ENSURE_PARSING_COND (token && token->type == PO_TK); - ENSURE_PARSING_COND (token && token->type == PO_TK) ; + cr_token_destroy (token); + token = NULL; - cr_token_destroy (token) ; - token = NULL ; - - status = cr_parser_parse_term (a_this, &expr) ; + status = cr_parser_parse_term (a_this, &expr); - CHECK_PARSING_STATUS (status, FALSE) ; + CHECK_PARSING_STATUS (status, FALSE); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - if (status != CR_OK) goto error ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + if (status != CR_OK) + goto error; - ENSURE_PARSING_COND (token && token->type == PC_TK) ; + ENSURE_PARSING_COND (token && token->type == PC_TK); - cr_token_destroy (token) ; - token = NULL ; + cr_token_destroy (token); + token = NULL; - if (expr) - { - *a_expr = cr_term_append_term (*a_expr, expr) ; - expr = NULL ; + if (expr) { + *a_expr = cr_term_append_term (*a_expr, expr); + expr = NULL; } - cr_parser_clear_errors (a_this) ; - return CR_OK ; + cr_parser_clear_errors (a_this); + return CR_OK; - error: + error: - if (*a_func_name) - { - g_string_free (*a_func_name, TRUE) ; - *a_func_name = NULL ; + if (*a_func_name) { + g_string_free (*a_func_name, TRUE); + *a_func_name = NULL; } - if (expr) - { - cr_term_destroy (expr) ; - expr = NULL ; + if (expr) { + cr_term_destroy (expr); + expr = NULL; } - if (token) - { - cr_token_destroy (token) ; - + if (token) { + cr_token_destroy (token); + } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - - - /** *Parses an uri as defined by the css spec [4.1.1]: * URI ::= url\({w}{string}{w}\) @@ -2775,22 +2424,19 @@ cr_parser_parse_function (CRParser *a_this, GString **a_func_name, *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_uri (CRParser *a_this, GString **a_str) +cr_parser_parse_uri (CRParser * a_this, GString ** a_str) { - enum CRStatus status = CR_PARSING_ERROR ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr, - CR_BAD_PARAM_ERROR) ; + enum CRStatus status = CR_PARSING_ERROR; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR); status = cr_tknzr_parse_token (PRIVATE (a_this)->tknzr, - URI_TK, NO_ET, a_str, NULL) ; - return status ; + URI_TK, NO_ET, a_str, NULL); + return status; } - /** *Parses a string type as defined in css spec [4.1.1]: * @@ -2807,18 +2453,17 @@ cr_parser_parse_uri (CRParser *a_this, GString **a_str) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_string (CRParser *a_this, GString **a_str) +cr_parser_parse_string (CRParser * a_this, GString ** a_str) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->tknzr - && a_str, - CR_BAD_PARAM_ERROR) ; + && a_str, CR_BAD_PARAM_ERROR); status = cr_tknzr_parse_token (PRIVATE (a_this)->tknzr, - STRING_TK, NO_ET, a_str, NULL) ; - return status ; + STRING_TK, NO_ET, a_str, NULL); + return status; } /** @@ -2836,18 +2481,17 @@ cr_parser_parse_string (CRParser *a_this, GString **a_str) *otherwise. */ static enum CRStatus -cr_parser_parse_ident (CRParser *a_this, GString **a_str) +cr_parser_parse_ident (CRParser * a_this, GString ** a_str) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; + + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->tknzr + && a_str, CR_BAD_PARAM_ERROR); - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr - && a_str, - CR_BAD_PARAM_ERROR) ; - status = cr_tknzr_parse_token (PRIVATE (a_this)->tknzr, - IDENT_TK, NO_ET, a_str, NULL) ; - return status ; + IDENT_TK, NO_ET, a_str, NULL); + return status; } /** @@ -2865,18 +2509,18 @@ cr_parser_parse_ident (CRParser *a_this, GString **a_str) *otherwise. */ static enum CRStatus -cr_parser_parse_vendor_specific_ident (CRParser *a_this, GString **a_str) +cr_parser_parse_vendor_specific_ident (CRParser * a_this, GString ** a_str) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; + + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->tknzr + && a_str, CR_BAD_PARAM_ERROR); - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr - && a_str, - CR_BAD_PARAM_ERROR) ; - status = cr_tknzr_parse_token (PRIVATE (a_this)->tknzr, - VENDOR_SPECIFIC_IDENT_TK, NO_ET, a_str, NULL) ; - return status ; + VENDOR_SPECIFIC_IDENT_TK, NO_ET, a_str, + NULL); + return status; } /** @@ -2897,150 +2541,129 @@ cr_parser_parse_vendor_specific_ident (CRParser *a_this, GString **a_str) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_parser_parse_stylesheet (CRParser *a_this) +cr_parser_parse_stylesheet (CRParser * a_this) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - CRToken * token = NULL ; - GString *charset = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + CRToken *token = NULL; + GString *charset = NULL; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - PRIVATE (a_this)->state = READY_STATE ; + PRIVATE (a_this)->state = READY_STATE; if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->start_document) - { - PRIVATE (a_this)->sac_handler->start_document - (PRIVATE (a_this)->sac_handler) ; + && PRIVATE (a_this)->sac_handler->start_document) { + PRIVATE (a_this)->sac_handler->start_document + (PRIVATE (a_this)->sac_handler); } /* parse_charset:*/ - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - if (status == CR_END_OF_INPUT_ERROR) goto done ; - CHECK_PARSING_STATUS (status, TRUE) ; + if (status == CR_END_OF_INPUT_ERROR) + goto done; + CHECK_PARSING_STATUS (status, TRUE); - if (token && token->type == CHARSET_SYM_TK) - { + if (token && token->type == CHARSET_SYM_TK) { status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token = NULL ; + token); + CHECK_PARSING_STATUS (status, TRUE); + token = NULL; - status = cr_parser_parse_charset (a_this, &charset) ; + status = cr_parser_parse_charset (a_this, &charset); - if (status == CR_OK && charset) - { + if (status == CR_OK && charset) { if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->charset) - { - PRIVATE (a_this)->sac_handler->charset + && PRIVATE (a_this)->sac_handler->charset) { + PRIVATE (a_this)->sac_handler->charset (PRIVATE (a_this)->sac_handler, - charset) ; + charset); } - } - else if (status != CR_END_OF_INPUT_ERROR) - { - status = cr_parser_parse_atrule_core (a_this) ; - CHECK_PARSING_STATUS (status, FALSE) ; + } else if (status != CR_END_OF_INPUT_ERROR) { + status = cr_parser_parse_atrule_core (a_this); + CHECK_PARSING_STATUS (status, FALSE); } - if (charset) - { - g_string_free (charset, TRUE) ; - charset = NULL ; + if (charset) { + g_string_free (charset, TRUE); + charset = NULL; } - } - else if (token - && (token->type == S_TK || token->type == COMMENT_TK)) - { + } else if (token + && (token->type == S_TK || token->type == COMMENT_TK)) { status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; - CHECK_PARSING_STATUS (status, TRUE) ; + token); + token = NULL; + CHECK_PARSING_STATUS (status, TRUE); - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - } - else if (token) - { + cr_parser_try_to_skip_spaces_and_comments (a_this); + } else if (token) { status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; - CHECK_PARSING_STATUS (status, TRUE) ; + token); + token = NULL; + CHECK_PARSING_STATUS (status, TRUE); } - /* parse_imports:*/ - do - { - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + do { + if (token) { + cr_token_destroy (token); + token = NULL; } - status = cr_tknzr_get_next_token - (PRIVATE (a_this)->tknzr, &token) ; - - if (status == CR_END_OF_INPUT_ERROR) goto done ; - CHECK_PARSING_STATUS (status, TRUE) ; - } while (token - && (token->type == S_TK - || token->type == CDO_TK - || token->type == CDC_TK)) ; - - if (token) - { + status = cr_tknzr_get_next_token + (PRIVATE (a_this)->tknzr, &token); + + if (status == CR_END_OF_INPUT_ERROR) + goto done; + CHECK_PARSING_STATUS (status, TRUE); + } while (token + && (token->type == S_TK + || token->type == CDO_TK || token->type == CDC_TK)); + + if (token) { status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; + token); + token = NULL; } - for (;;) - { - status = cr_tknzr_get_next_token - (PRIVATE (a_this)->tknzr, &token) ; - if (status == CR_END_OF_INPUT_ERROR) goto done ; - CHECK_PARSING_STATUS (status, TRUE) ; + for (;;) { + status = cr_tknzr_get_next_token + (PRIVATE (a_this)->tknzr, &token); + if (status == CR_END_OF_INPUT_ERROR) + goto done; + CHECK_PARSING_STATUS (status, TRUE); - if (token && token->type == IMPORT_SYM_TK) - { - GList *media_list = NULL ; - GString *import_string = NULL ; + if (token && token->type == IMPORT_SYM_TK) { + GList *media_list = NULL; + GString *import_string = NULL; - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - CHECK_PARSING_STATUS (status, TRUE) ; + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + token = NULL; + CHECK_PARSING_STATUS (status, TRUE); status = cr_parser_parse_import (a_this, &media_list, - &import_string) ; + &import_string); - if (status == CR_OK) - { - if (import_string + if (status == CR_OK) { + if (import_string && PRIVATE (a_this)->sac_handler - && PRIVATE(a_this)->sac_handler-> - import_style) - { + && PRIVATE (a_this)->sac_handler-> + import_style) { PRIVATE (a_this)->sac_handler-> import_style (PRIVATE (a_this)-> sac_handler, - media_list, - import_string, - NULL) ; + media_list, + import_string, + NULL); if ((PRIVATE (a_this)->sac_handler-> - resolve_import == TRUE) ) - { + resolve_import == TRUE)) { /* *TODO: resolve the *import rule. @@ -3048,34 +2671,27 @@ cr_parser_parse_stylesheet (CRParser *a_this) } if ((PRIVATE (a_this)->sac_handler-> - import_style_result)) - { + import_style_result)) { PRIVATE (a_this)-> - sac_handler-> - import_style_result - (PRIVATE (a_this)-> - sac_handler, - media_list, - import_string, - NULL, - NULL) ; + sac_handler-> + import_style_result + (PRIVATE (a_this)-> + sac_handler, + media_list, + import_string, + NULL, NULL); } } - } - else if (status != CR_END_OF_INPUT_ERROR) - { + } else if (status != CR_END_OF_INPUT_ERROR) { if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler-> - error) - { + && PRIVATE (a_this)->sac_handler->error) { PRIVATE (a_this)->sac_handler-> error - (PRIVATE - (a_this)->sac_handler) ; + (PRIVATE (a_this)-> + sac_handler); } - status = cr_parser_parse_atrule_core - (a_this) ; + status = cr_parser_parse_atrule_core (a_this); } /* @@ -3083,374 +2699,287 @@ cr_parser_parse_stylesheet (CRParser *a_this) *SAC handler, free *the media_list and import_string. */ - if (media_list) - { - GList * cur = NULL ; - - /*free the medium list*/ - for (cur = media_list ; - cur ; cur = cur->next) - { - if (cur->data) - { - g_string_free - (cur->data, - TRUE) ; + if (media_list) { + GList *cur = NULL; + + /*free the medium list */ + for (cur = media_list; cur; cur = cur->next) { + if (cur->data) { + g_string_free (cur->data, + TRUE); } } - g_list_free (media_list) ; - media_list = NULL ; + g_list_free (media_list); + media_list = NULL; } - if (import_string) - { - g_string_free (import_string, - TRUE) ; - import_string = NULL ; + if (import_string) { + g_string_free (import_string, TRUE); + import_string = NULL; } - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - } - else if (token - && (token->type == S_TK - || token->type == CDO_TK - || token->type == CDC_TK)) - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - - do - { - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + cr_parser_try_to_skip_spaces_and_comments (a_this); + } else if (token + && (token->type == S_TK + || token->type == CDO_TK + || token->type == CDC_TK)) { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + token = NULL; + + do { + if (token) { + cr_token_destroy (token); + token = NULL; } - status = cr_tknzr_get_next_token + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - if (status == CR_END_OF_INPUT_ERROR) - goto done ; - CHECK_PARSING_STATUS (status, TRUE) ; - } while (token - && (token->type == S_TK + if (status == CR_END_OF_INPUT_ERROR) + goto done; + CHECK_PARSING_STATUS (status, TRUE); + } while (token + && (token->type == S_TK || token->type == CDO_TK - || token->type == CDC_TK)) ; - } - else - { - if (token) - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; + || token->type == CDC_TK)); + } else { + if (token) { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + token = NULL; } - goto parse_ruleset_and_others ; + goto parse_ruleset_and_others; } } - parse_ruleset_and_others: + parse_ruleset_and_others: - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - for (;;) - { - status = cr_tknzr_get_next_token - (PRIVATE (a_this)->tknzr, &token) ; + for (;;) { + status = cr_tknzr_get_next_token + (PRIVATE (a_this)->tknzr, &token); if (status == CR_END_OF_INPUT_ERROR) - goto done ; - CHECK_PARSING_STATUS (status, TRUE) ; + goto done; + CHECK_PARSING_STATUS (status, TRUE); - if (token + if (token && (token->type == S_TK - || token->type == CDO_TK - || token->type == CDC_TK)) - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - - do - { - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + || token->type == CDO_TK || token->type == CDC_TK)) { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + token = NULL; + + do { + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - status = cr_tknzr_get_next_token + cr_parser_try_to_skip_spaces_and_comments + (a_this); + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - }while (token - && (token->type == S_TK - || token->type == COMMENT_TK - || token->type == CDO_TK - || token->type == CDC_TK)) ; - if (token) - { - cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; + } while (token + && (token->type == S_TK + || token->type == COMMENT_TK + || token->type == CDO_TK + || token->type == CDC_TK)); + if (token) { + cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + token = NULL; } - } - else if (token - && (token->type == HASH_TK - || (token->type == DELIM_TK - && token->u.unichar == '.') - || (token->type == DELIM_TK - && token->u.unichar == ':') - || (token->type == DELIM_TK - && token->u.unichar == '*') - || (token->type == BO_TK) - || token->type == IDENT_TK)) - { + } else if (token + && (token->type == HASH_TK + || (token->type == DELIM_TK + && token->u.unichar == '.') + || (token->type == DELIM_TK + && token->u.unichar == ':') + || (token->type == DELIM_TK + && token->u.unichar == '*') + || (token->type == BO_TK) + || token->type == IDENT_TK)) { /* *Try to parse a CSS2 ruleset. *if the parsing fails, try to parse *a css core ruleset. */ - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token = NULL ; + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + CHECK_PARSING_STATUS (status, TRUE); + token = NULL; - status = cr_parser_parse_ruleset (a_this) ; + status = cr_parser_parse_ruleset (a_this); - if (status == CR_OK) - { - continue ; - } - else - { + if (status == CR_OK) { + continue; + } else { if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler-> - error) - { + && PRIVATE (a_this)->sac_handler->error) { PRIVATE (a_this)->sac_handler-> - error - (PRIVATE - (a_this)->sac_handler) ; + error + (PRIVATE (a_this)-> + sac_handler); } - status = cr_parser_parse_ruleset_core - (a_this) ; + status = cr_parser_parse_ruleset_core + (a_this); - if (status == CR_OK) - { - continue ; + if (status == CR_OK) { + continue; + } else { + break; } - else - { - break ; - } - } - } - else if (token && token->type == MEDIA_SYM_TK) - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token = NULL ; - - status = cr_parser_parse_media (a_this) ; - if (status == CR_OK) - { - continue ; } - else - { + } else if (token && token->type == MEDIA_SYM_TK) { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + CHECK_PARSING_STATUS (status, TRUE); + token = NULL; + + status = cr_parser_parse_media (a_this); + if (status == CR_OK) { + continue; + } else { if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler-> - error) - { + && PRIVATE (a_this)->sac_handler->error) { PRIVATE (a_this)->sac_handler-> - error - (PRIVATE - (a_this)->sac_handler) ; + error + (PRIVATE (a_this)-> + sac_handler); } - status = cr_parser_parse_atrule_core - (a_this) ; + status = cr_parser_parse_atrule_core (a_this); - if (status == CR_OK) - { - continue ; + if (status == CR_OK) { + continue; + } else { + break; } - else - { - break ; - } - } - - } - else if (token && token->type == PAGE_SYM_TK) - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token = NULL ; - status = cr_parser_parse_page (a_this) ; - - if (status == CR_OK) - { - continue ; } - else - { + + } else if (token && token->type == PAGE_SYM_TK) { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + CHECK_PARSING_STATUS (status, TRUE); + token = NULL; + status = cr_parser_parse_page (a_this); + + if (status == CR_OK) { + continue; + } else { if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler-> - error) - { + && PRIVATE (a_this)->sac_handler->error) { PRIVATE (a_this)->sac_handler-> - error - (PRIVATE - (a_this)->sac_handler) ; + error + (PRIVATE (a_this)-> + sac_handler); } - status = cr_parser_parse_atrule_core - (a_this) ; + status = cr_parser_parse_atrule_core (a_this); - if (status == CR_OK) - { - continue ; + if (status == CR_OK) { + continue; + } else { + break; } - else - { - break ; - } - } - } - else if (token && token->type == FONT_FACE_SYM_TK) - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token = NULL ; - status = cr_parser_parse_font_face (a_this) ; - - if (status == CR_OK) - { - continue ; } - else - { + } else if (token && token->type == FONT_FACE_SYM_TK) { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + CHECK_PARSING_STATUS (status, TRUE); + token = NULL; + status = cr_parser_parse_font_face (a_this); + + if (status == CR_OK) { + continue; + } else { if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler-> - error) - { + && PRIVATE (a_this)->sac_handler->error) { PRIVATE (a_this)->sac_handler-> - error - (PRIVATE - (a_this)->sac_handler) ; + error + (PRIVATE (a_this)-> + sac_handler); } - status = cr_parser_parse_atrule_core - (a_this) ; + status = cr_parser_parse_atrule_core (a_this); - if (status == CR_OK) - { - continue ; - } - else - { - break ; + if (status == CR_OK) { + continue; + } else { + break; } } - } - else - { - status = cr_tknzr_unget_token - (PRIVATE (a_this)->tknzr, token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - token = NULL ; - status = cr_parser_parse_statement_core - (a_this) ; - - if (status == CR_OK) - { - continue ; - } - else - { - break ; - } + } else { + status = cr_tknzr_unget_token + (PRIVATE (a_this)->tknzr, token); + CHECK_PARSING_STATUS (status, TRUE); + token = NULL; + status = cr_parser_parse_statement_core (a_this); + + if (status == CR_OK) { + continue; + } else { + break; + } } } - done: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + done: + if (token) { + cr_token_destroy (token); + token = NULL; } - if (status == CR_END_OF_INPUT_ERROR - || status == CR_OK) - { + if (status == CR_END_OF_INPUT_ERROR || status == CR_OK) { if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->end_document) - { + && PRIVATE (a_this)->sac_handler->end_document) { PRIVATE (a_this)->sac_handler->end_document - (PRIVATE (a_this)->sac_handler) ; + (PRIVATE (a_this)->sac_handler); } - return CR_OK ; + return CR_OK; } - cr_parser_push_error - (a_this, "could not recognize next production", - CR_ERROR) ; + cr_parser_push_error + (a_this, "could not recognize next production", CR_ERROR); if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler-> - unrecoverable_error) - { + && PRIVATE (a_this)->sac_handler->unrecoverable_error) { PRIVATE (a_this)->sac_handler-> - unrecoverable_error - (PRIVATE - (a_this)->sac_handler) ; + unrecoverable_error (PRIVATE (a_this)->sac_handler); } - cr_parser_dump_err_stack (a_this, TRUE) ; + cr_parser_dump_err_stack (a_this, TRUE); - return status ; + return status; - error: - - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + error: + + if (token) { + cr_token_destroy (token); + token = NULL; } if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler-> - unrecoverable_error) - { + && PRIVATE (a_this)->sac_handler->unrecoverable_error) { PRIVATE (a_this)->sac_handler-> - unrecoverable_error - (PRIVATE - (a_this)->sac_handler) ; + unrecoverable_error (PRIVATE (a_this)->sac_handler); } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, - &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - /**************************************** *Public CRParser Methods ****************************************/ - /** *Creates a new parser to parse data *coming the input stream given in parameter. @@ -3462,26 +2991,24 @@ cr_parser_parse_stylesheet (CRParser *a_this) *or NULL if an error occured. */ CRParser * -cr_parser_new (CRTknzr *a_tknzr) +cr_parser_new (CRTknzr * a_tknzr) { - CRParser * result = NULL ; - enum CRStatus status = CR_OK ; + CRParser *result = NULL; + enum CRStatus status = CR_OK; - result = g_malloc0 (sizeof (CRParser)) ; + result = g_malloc0 (sizeof (CRParser)); - PRIVATE (result) = g_malloc0 (sizeof (CRParserPriv)) ; + PRIVATE (result) = g_malloc0 (sizeof (CRParserPriv)); - if (a_tknzr) - { - status = cr_parser_set_tknzr (result, a_tknzr) ; + if (a_tknzr) { + status = cr_parser_set_tknzr (result, a_tknzr); } - g_return_val_if_fail (status == CR_OK, NULL) ; + g_return_val_if_fail (status == CR_OK, NULL); - return result ; + return result; } - /** *Instanciates a new parser from a memory buffer. *@param a_buf the buffer to parse. @@ -3494,67 +3021,60 @@ cr_parser_new (CRTknzr *a_tknzr) *@return the newly built parser, or NULL if an error arises. */ CRParser * -cr_parser_new_from_buf (const guchar *a_buf, +cr_parser_new_from_buf (const guchar * a_buf, gulong a_len, - enum CREncoding a_enc, - gboolean a_free_buf) + enum CREncoding a_enc, gboolean a_free_buf) { - CRParser * result = NULL ; - CRInput *input = NULL ; - g_return_val_if_fail (a_buf && a_len, NULL) ; - - input = cr_input_new_from_buf (a_buf, a_len, a_enc, - a_free_buf) ; - g_return_val_if_fail (input, NULL) ; - - result = cr_parser_new_from_input (input) ; - if (!result) - { - cr_input_destroy (input) ; - input = NULL ; - return NULL ; - } - return result ; + CRParser *result = NULL; + CRInput *input = NULL; + + g_return_val_if_fail (a_buf && a_len, NULL); + + input = cr_input_new_from_buf (a_buf, a_len, a_enc, a_free_buf); + g_return_val_if_fail (input, NULL); + + result = cr_parser_new_from_input (input); + if (!result) { + cr_input_destroy (input); + input = NULL; + return NULL; + } + return result; } CRParser * -cr_parser_new_from_input (CRInput *a_input) +cr_parser_new_from_input (CRInput * a_input) { - CRParser *result = NULL ; - CRTknzr *tokenizer = NULL ; + CRParser *result = NULL; + CRTknzr *tokenizer = NULL; - if (a_input) - { - tokenizer = cr_tknzr_new (a_input) ; - g_return_val_if_fail (tokenizer, NULL) ; + if (a_input) { + tokenizer = cr_tknzr_new (a_input); + g_return_val_if_fail (tokenizer, NULL); } - result = cr_parser_new (tokenizer) ; - g_return_val_if_fail (result, NULL) ; + result = cr_parser_new (tokenizer); + g_return_val_if_fail (result, NULL); - return result ; + return result; } - CRParser * -cr_parser_new_from_file (const guchar *a_file_uri, - enum CREncoding a_enc) +cr_parser_new_from_file (const guchar * a_file_uri, enum CREncoding a_enc) { - CRParser *result = NULL ; - CRTknzr *tokenizer = NULL ; - - tokenizer = cr_tknzr_new_from_uri (a_file_uri, a_enc) ; - if (!tokenizer) - { - cr_utils_trace_info ("Could not open input file") ; - return NULL ; - } - - result = cr_parser_new (tokenizer) ; - g_return_val_if_fail (result, NULL) ; - return result ; -} + CRParser *result = NULL; + CRTknzr *tokenizer = NULL; + + tokenizer = cr_tknzr_new_from_uri (a_file_uri, a_enc); + if (!tokenizer) { + cr_utils_trace_info ("Could not open input file"); + return NULL; + } + result = cr_parser_new (tokenizer); + g_return_val_if_fail (result, NULL); + return result; +} /** *Sets a SAC document handler to the parser. @@ -3563,22 +3083,20 @@ cr_parser_new_from_file (const guchar *a_file_uri, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_set_sac_handler (CRParser *a_this, CRDocHandler *a_handler) +cr_parser_set_sac_handler (CRParser * a_this, CRDocHandler * a_handler) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->sac_handler) - { - cr_doc_handler_unref (PRIVATE (a_this)->sac_handler) ; + if (PRIVATE (a_this)->sac_handler) { + cr_doc_handler_unref (PRIVATE (a_this)->sac_handler); } - PRIVATE (a_this)->sac_handler = a_handler ; - cr_doc_handler_ref (a_handler) ; + PRIVATE (a_this)->sac_handler = a_handler; + cr_doc_handler_ref (a_handler); - return CR_OK ; + return CR_OK; } - /** *Gets the SAC document handler. *@param a_this the "this pointer" of the current instance of @@ -3588,16 +3106,15 @@ cr_parser_set_sac_handler (CRParser *a_this, CRDocHandler *a_handler) *otherwise. */ enum CRStatus -cr_parser_get_sac_handler (CRParser *a_this, CRDocHandler **a_handler) +cr_parser_get_sac_handler (CRParser * a_this, CRDocHandler ** a_handler) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - *a_handler = PRIVATE (a_this)->sac_handler ; + *a_handler = PRIVATE (a_this)->sac_handler; - return CR_OK ; + return CR_OK; } - /** *Sets the SAC handler associated to the current instance *of #CRParser to the default SAC handler. @@ -3605,52 +3122,47 @@ cr_parser_get_sac_handler (CRParser *a_this, CRDocHandler **a_handler) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_set_default_sac_handler (CRParser *a_this) +cr_parser_set_default_sac_handler (CRParser * a_this) { - CRDocHandler *default_sac_handler = NULL ; - enum CRStatus status = CR_ERROR ; + CRDocHandler *default_sac_handler = NULL; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - default_sac_handler = cr_doc_handler_new () ; + default_sac_handler = cr_doc_handler_new (); - cr_doc_handler_set_default_sac_handler (default_sac_handler) ; + cr_doc_handler_set_default_sac_handler (default_sac_handler); - status = cr_parser_set_sac_handler (a_this, default_sac_handler) ; + status = cr_parser_set_sac_handler (a_this, default_sac_handler); - if (status != CR_OK) - { - cr_doc_handler_destroy (default_sac_handler) ; - default_sac_handler = NULL ; + if (status != CR_OK) { + cr_doc_handler_destroy (default_sac_handler); + default_sac_handler = NULL; } - return status ; + return status; } - enum CRStatus -cr_parser_set_use_core_grammar (CRParser *a_this, +cr_parser_set_use_core_grammar (CRParser * a_this, gboolean a_use_core_grammar) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->use_core_grammar = a_use_core_grammar ; + PRIVATE (a_this)->use_core_grammar = a_use_core_grammar; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_parser_get_use_core_grammar (CRParser *a_this, - gboolean *a_use_core_grammar) +cr_parser_get_use_core_grammar (CRParser * a_this, + gboolean * a_use_core_grammar) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - *a_use_core_grammar = PRIVATE (a_this)->use_core_grammar ; + *a_use_core_grammar = PRIVATE (a_this)->use_core_grammar; - return CR_OK ; + return CR_OK; } /** @@ -3661,27 +3173,25 @@ cr_parser_get_use_core_grammar (CRParser *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_file (CRParser *a_this, - const guchar *a_file_uri, - enum CREncoding a_enc) +cr_parser_parse_file (CRParser * a_this, + const guchar * a_file_uri, enum CREncoding a_enc) { - enum CRStatus status = CR_ERROR ; - CRTknzr *tknzr = NULL ; + enum CRStatus status = CR_ERROR; + CRTknzr *tknzr = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_file_uri, - CR_BAD_PARAM_ERROR) ; + && a_file_uri, CR_BAD_PARAM_ERROR); - tknzr = cr_tknzr_new_from_uri (a_file_uri, a_enc) ; + tknzr = cr_tknzr_new_from_uri (a_file_uri, a_enc); - g_return_val_if_fail (tknzr != NULL, CR_ERROR) ; + g_return_val_if_fail (tknzr != NULL, CR_ERROR); - status = cr_parser_set_tknzr (a_this, tknzr) ; - g_return_val_if_fail (status == CR_OK, CR_ERROR) ; + status = cr_parser_set_tknzr (a_this, tknzr); + g_return_val_if_fail (status == CR_OK, CR_ERROR); - status = cr_parser_parse (a_this) ; + status = cr_parser_parse (a_this); - return status ; + return status; } /** @@ -3690,109 +3200,97 @@ cr_parser_parse_file (CRParser *a_this, *expr: term [ operator term ]* */ enum CRStatus -cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) +cr_parser_parse_expr (CRParser * a_this, CRTerm ** a_expr) { - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - CRTerm *expr = NULL, *expr2 = NULL ; - guchar next_byte = 0 ; - gulong nb_terms = 0 ; + enum CRStatus status = CR_ERROR; + CRInputPos init_pos; + CRTerm *expr = NULL, + *expr2 = NULL; + guchar next_byte = 0; + gulong nb_terms = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_expr, - CR_BAD_PARAM_ERROR) ; + && a_expr, CR_BAD_PARAM_ERROR); + + RECORD_INITIAL_POS (a_this, &init_pos); - RECORD_INITIAL_POS (a_this, &init_pos) ; + status = cr_parser_parse_term (a_this, &expr); - status = cr_parser_parse_term (a_this, &expr) ; + CHECK_PARSING_STATUS (status, FALSE); + + for (;;) { + guchar operator = 0; - CHECK_PARSING_STATUS (status, FALSE) ; - - for (;;) - { - guchar operator = 0 ; status = cr_tknzr_peek_byte (PRIVATE (a_this)->tknzr, - 1, &next_byte) ; - if (status != CR_OK) - { - if (status == CR_END_OF_INPUT_ERROR) - { + 1, &next_byte); + if (status != CR_OK) { + if (status == CR_END_OF_INPUT_ERROR) { /* - if (!nb_terms) - { - goto error ; - } - */ - status = CR_OK ; - break ; - } - else - { - goto error ; + if (!nb_terms) + { + goto error ; + } + */ + status = CR_OK; + break; + } else { + goto error; } } - if (next_byte == '/' || next_byte == ',') - { - READ_NEXT_BYTE (a_this, &operator) ; + if (next_byte == '/' || next_byte == ',') { + READ_NEXT_BYTE (a_this, &operator); } - - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - status = cr_parser_parse_term (a_this, &expr2) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - if (status != CR_OK || expr2 == NULL) - { - status = CR_OK ; - break ; + status = cr_parser_parse_term (a_this, &expr2); + + if (status != CR_OK || expr2 == NULL) { + status = CR_OK; + break; } - - switch (operator) - { + + switch (operator) { case '/': - expr2->the_operator = DIVIDE ; - break ; + expr2->the_operator = DIVIDE; + break; case ',': - expr2->the_operator = COMMA ; + expr2->the_operator = COMMA; default: - break ; + break; } - expr = cr_term_append_term (expr, expr2) ; - expr2 = NULL ; - operator = 0 ; - nb_terms ++ ; + expr = cr_term_append_term (expr, expr2); + expr2 = NULL; + operator = 0; + nb_terms++; } - if (status == CR_OK) - { - *a_expr = cr_term_append_term (*a_expr, expr) ; - expr = NULL ; + if (status == CR_OK) { + *a_expr = cr_term_append_term (*a_expr, expr); + expr = NULL; - cr_parser_clear_errors (a_this) ; - return CR_OK ; + cr_parser_clear_errors (a_this); + return CR_OK; } - error: + error: - if (expr) - { - cr_term_destroy (expr) ; - expr = NULL ; + if (expr) { + cr_term_destroy (expr); + expr = NULL; } - if (expr2) - { - cr_term_destroy (expr2) ; - expr2 = NULL ; + if (expr2) { + cr_term_destroy (expr2); + expr2 = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, - &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -3805,45 +3303,39 @@ cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) *priority is defined by css2. */ enum CRStatus -cr_parser_parse_prio (CRParser *a_this, GString **a_prio) +cr_parser_parse_prio (CRParser * a_this, GString ** a_prio) { - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - CRToken *token = NULL ; + enum CRStatus status = CR_ERROR; + CRInputPos init_pos; + CRToken *token = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_prio && *a_prio == NULL, - CR_BAD_PARAM_ERROR) ; + && a_prio + && *a_prio == NULL, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_get_next_token - (PRIVATE (a_this)->tknzr, - &token) ; - if (status == CR_END_OF_INPUT_ERROR) - { - goto error ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + if (status == CR_END_OF_INPUT_ERROR) { + goto error; } - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == IMPORTANT_SYM_TK) ; - - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - *a_prio = g_string_new ("!important") ; - cr_token_destroy (token) ; - token = NULL ; - return CR_OK ; - - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - - return status ; + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == IMPORTANT_SYM_TK); + + cr_parser_try_to_skip_spaces_and_comments (a_this); + *a_prio = g_string_new ("!important"); + cr_token_destroy (token); + token = NULL; + return CR_OK; + + error: + if (token) { + cr_token_destroy (token); + token = NULL; + } + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); + + return status; } /** @@ -3860,96 +3352,86 @@ cr_parser_parse_prio (CRParser *a_this, GString **a_prio) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_declaration (CRParser *a_this, GString **a_property, - CRTerm **a_expr, gboolean *a_important) +cr_parser_parse_declaration (CRParser * a_this, + GString ** a_property, + CRTerm ** a_expr, gboolean * a_important) { - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - guint32 cur_char = 0 ; - CRTerm *expr = NULL ; - GString *prio = NULL ; + enum CRStatus status = CR_ERROR; + CRInputPos init_pos; + guint32 cur_char = 0; + CRTerm *expr = NULL; + GString *prio = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_property && a_expr - && a_important, - CR_BAD_PARAM_ERROR) ; + && a_important, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_parser_parse_property (a_this, a_property) ; + status = cr_parser_parse_property (a_this, a_property); if (status == CR_END_OF_INPUT_ERROR) - goto error ; - CHECK_PARSING_STATUS_ERR + goto error; + CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, "while parsing declaration: next property is malformed", - CR_SYNTAX_ERROR) ; + CR_SYNTAX_ERROR); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - if (cur_char != ':') - { - status = CR_PARSING_ERROR ; - cr_parser_push_error + if (cur_char != ':') { + status = CR_PARSING_ERROR; + cr_parser_push_error (a_this, "while parsing declaration: this char must be ':'", - CR_SYNTAX_ERROR) ; - goto error ; + CR_SYNTAX_ERROR); + goto error; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_parser_parse_expr (a_this, &expr) ; + status = cr_parser_parse_expr (a_this, &expr); - CHECK_PARSING_STATUS_ERR + CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, "while parsing declaration: next expression is malformed", - CR_SYNTAX_ERROR) ; + CR_SYNTAX_ERROR); - cr_parser_try_to_skip_spaces_and_comments - (a_this) ; - status = cr_parser_parse_prio (a_this, &prio) ; - if (prio) - { - g_string_free (prio, TRUE) ; - prio = NULL ; - *a_important = TRUE ; + cr_parser_try_to_skip_spaces_and_comments (a_this); + status = cr_parser_parse_prio (a_this, &prio); + if (prio) { + g_string_free (prio, TRUE); + prio = NULL; + *a_important = TRUE; + } else { + *a_important = FALSE; } - else - { - *a_important = FALSE ; - } - if (*a_expr) - { - cr_term_append_term (*a_expr, expr) ; - expr = NULL ; - } - else - { - *a_expr = expr ; - expr = NULL ; + if (*a_expr) { + cr_term_append_term (*a_expr, expr); + expr = NULL; + } else { + *a_expr = expr; + expr = NULL; } - cr_parser_clear_errors (a_this) ; - return CR_OK ; + cr_parser_clear_errors (a_this); + return CR_OK; - error: + error: - if (expr) - { - cr_term_destroy (expr) ; - expr = NULL ; + if (expr) { + cr_term_destroy (expr); + expr = NULL; } - if (*a_property) - { - g_string_free (*a_property, TRUE) ; - *a_property = NULL ; + if (*a_property) { + g_string_free (*a_property, TRUE); + *a_property = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - - return status ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); + + return status; } /** @@ -3960,56 +3442,52 @@ cr_parser_parse_declaration (CRParser *a_this, GString **a_property, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_statement_core (CRParser *a_this) +cr_parser_parse_statement_core (CRParser * a_this) { - CRToken *token = NULL ; - CRInputPos init_pos ; - enum CRStatus status = CR_ERROR ; + CRToken *token = NULL; + CRInputPos init_pos; + enum CRStatus status = CR_ERROR; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - ENSURE_PARSING_COND (status == CR_OK && token) ; + ENSURE_PARSING_COND (status == CR_OK && token); - switch (token->type) - { + switch (token->type) { case ATKEYWORD_TK: case IMPORT_SYM_TK: case PAGE_SYM_TK: case MEDIA_SYM_TK: case FONT_FACE_SYM_TK: case CHARSET_SYM_TK: - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - status = cr_parser_parse_atrule_core (a_this) ; - CHECK_PARSING_STATUS (status, TRUE) ; - break ; + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); + token = NULL; + status = cr_parser_parse_atrule_core (a_this); + CHECK_PARSING_STATUS (status, TRUE); + break; default: - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; - status = cr_parser_parse_ruleset_core (a_this) ; - cr_parser_clear_errors (a_this) ; - CHECK_PARSING_STATUS (status, TRUE) ; + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); + token = NULL; + status = cr_parser_parse_ruleset_core (a_this); + cr_parser_clear_errors (a_this); + CHECK_PARSING_STATUS (status, TRUE); } - return CR_OK ; + return CR_OK; - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + error: + if (token) { + cr_token_destroy (token); + token = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -4025,202 +3503,183 @@ cr_parser_parse_statement_core (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_ruleset (CRParser *a_this) +cr_parser_parse_ruleset (CRParser * a_this) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - guint32 cur_char = 0, next_char = 0 ; - GString * property = NULL ; - CRTerm *expr = NULL ; - CRSimpleSel * simple_sels = NULL ; - CRSelector *selector = NULL ; - gboolean start_selector = FALSE, is_important = FALSE ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + guint32 cur_char = 0, + next_char = 0; + GString *property = NULL; + CRTerm *expr = NULL; + CRSimpleSel *simple_sels = NULL; + CRSelector *selector = NULL; + gboolean start_selector = FALSE, + is_important = FALSE; - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_parser_parse_selector (a_this, &selector) ; - CHECK_PARSING_STATUS (status, FALSE) ; + status = cr_parser_parse_selector (a_this, &selector); + CHECK_PARSING_STATUS (status, FALSE); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - ENSURE_PARSING_COND_ERR + ENSURE_PARSING_COND_ERR (a_this, cur_char == '{', "while parsing rulset: current char should be '{'", - CR_SYNTAX_ERROR) ; + CR_SYNTAX_ERROR); if (PRIVATE (a_this)->sac_handler - &&PRIVATE (a_this)->sac_handler->start_selector) - { + && PRIVATE (a_this)->sac_handler->start_selector) { /* *the selector if ref counted so that the parser's user *can choose to keep it. */ - if (selector) - { - cr_selector_ref (selector) ; + if (selector) { + cr_selector_ref (selector); } - PRIVATE (a_this)->sac_handler->start_selector - (PRIVATE (a_this)->sac_handler, selector) ; - start_selector = TRUE ; + PRIVATE (a_this)->sac_handler->start_selector + (PRIVATE (a_this)->sac_handler, selector); + start_selector = TRUE; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - PRIVATE (a_this)->state = TRY_PARSE_RULESET_STATE ; + PRIVATE (a_this)->state = TRY_PARSE_RULESET_STATE; - status = cr_parser_parse_declaration (a_this, &property, - &expr, &is_important) ; + status = cr_parser_parse_declaration (a_this, &property, + &expr, &is_important); - if (expr) - { - cr_term_ref (expr) ; + if (expr) { + cr_term_ref (expr); } - if ( status == CR_OK - && PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->property) - { - PRIVATE (a_this)->sac_handler->property + if (status == CR_OK + && PRIVATE (a_this)->sac_handler + && PRIVATE (a_this)->sac_handler->property) { + PRIVATE (a_this)->sac_handler->property (PRIVATE (a_this)->sac_handler, property, expr, - is_important) ; + is_important); } - if (status == CR_OK) - { + if (status == CR_OK) { /* *free the allocated *'property' and 'term' before parsing *next declarations. */ - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; + if (property) { + g_string_free (property, TRUE); + property = NULL; } - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; + if (expr) { + cr_term_unref (expr); + expr = NULL; } } CHECK_PARSING_STATUS_ERR (a_this, status, FALSE, "while parsing ruleset: next construction should be a declaration", - CR_SYNTAX_ERROR) ; + CR_SYNTAX_ERROR); - for (;;) - { - PEEK_NEXT_CHAR (a_this, &next_char) ; - if (next_char != ';') break ; + for (;;) { + PEEK_NEXT_CHAR (a_this, &next_char); + if (next_char != ';') + break; - /*consume the ';' char*/ - READ_NEXT_CHAR (a_this, &cur_char) ; - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + /*consume the ';' char */ + READ_NEXT_CHAR (a_this, &cur_char); + + cr_parser_try_to_skip_spaces_and_comments (a_this); status = cr_parser_parse_declaration (a_this, &property, - &expr, &is_important) ; + &expr, &is_important); - if (expr) - { - cr_term_ref (expr) ; + if (expr) { + cr_term_ref (expr); } - if (status == CR_OK + if (status == CR_OK && PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->property) - { - PRIVATE (a_this)->sac_handler->property - (PRIVATE (a_this)->sac_handler, - property, expr, is_important) ; + && PRIVATE (a_this)->sac_handler->property) { + PRIVATE (a_this)->sac_handler->property + (PRIVATE (a_this)->sac_handler, + property, expr, is_important); } - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; + if (property) { + g_string_free (property, TRUE); + property = NULL; } - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; + if (expr) { + cr_term_unref (expr); + expr = NULL; } } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - ENSURE_PARSING_COND_ERR + ENSURE_PARSING_COND_ERR (a_this, cur_char == '}', "while parsing rulset: current char must be a '}'", - CR_SYNTAX_ERROR) ; + CR_SYNTAX_ERROR); if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->end_selector) - { - PRIVATE (a_this)->sac_handler->end_selector - (PRIVATE (a_this)->sac_handler, selector) ; - start_selector = FALSE ; + && PRIVATE (a_this)->sac_handler->end_selector) { + PRIVATE (a_this)->sac_handler->end_selector + (PRIVATE (a_this)->sac_handler, selector); + start_selector = FALSE; } - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; + if (expr) { + cr_term_unref (expr); + expr = NULL; } - if (simple_sels) - { - cr_simple_sel_destroy (simple_sels) ; - simple_sels = NULL ; + if (simple_sels) { + cr_simple_sel_destroy (simple_sels); + simple_sels = NULL; } - if (selector) - { - cr_selector_unref (selector) ; - selector = NULL ; + if (selector) { + cr_selector_unref (selector); + selector = NULL; } - cr_parser_clear_errors (a_this) ; - PRIVATE (a_this)->state = RULESET_PARSED_STATE ; + cr_parser_clear_errors (a_this); + PRIVATE (a_this)->state = RULESET_PARSED_STATE; - return CR_OK ; + return CR_OK; - error: + error: if (start_selector == TRUE && PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->error) - { - PRIVATE (a_this)->sac_handler->error - (PRIVATE (a_this)->sac_handler) ; + && PRIVATE (a_this)->sac_handler->error) { + PRIVATE (a_this)->sac_handler->error + (PRIVATE (a_this)->sac_handler); } - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; + if (expr) { + cr_term_unref (expr); + expr = NULL; } - if (simple_sels) - { - cr_simple_sel_destroy (simple_sels) ; - simple_sels = NULL ; + if (simple_sels) { + cr_simple_sel_destroy (simple_sels); + simple_sels = NULL; } - if (property) - { - g_string_free (property, TRUE) ; + if (property) { + g_string_free (property, TRUE); } - if (selector) - { - cr_selector_unref (selector) ; - selector = NULL ; + if (selector) { + cr_selector_unref (selector); + selector = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - /** *Parses an 'import' declaration as defined in the css2 spec *in appendix D.1: @@ -4247,128 +3706,109 @@ cr_parser_parse_ruleset (CRParser *a_this) *@return CR_OK upon sucessfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_import (CRParser *a_this, GList ** a_media_list, - GString **a_import_string) +cr_parser_parse_import (CRParser * a_this, + GList ** a_media_list, GString ** a_import_string) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - guint32 cur_char = 0, next_char = 0 ; - GString *medium = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + guint32 cur_char = 0, + next_char = 0; + GString *medium = NULL; - g_return_val_if_fail (a_this - && a_import_string + g_return_val_if_fail (a_this + && a_import_string && (*a_import_string == NULL), - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; - - if (BYTE (a_this, 1, NULL) == '@' + RECORD_INITIAL_POS (a_this, &init_pos); + + if (BYTE (a_this, 1, NULL) == '@' && BYTE (a_this, 2, NULL) == 'i' && BYTE (a_this, 3, NULL) == 'm' && BYTE (a_this, 4, NULL) == 'p' && BYTE (a_this, 5, NULL) == 'o' && BYTE (a_this, 6, NULL) == 'r' - && BYTE (a_this, 7, NULL) == 't') - { - SKIP_CHARS (a_this, 7) ; - status = CR_OK ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + && BYTE (a_this, 7, NULL) == 't') { + SKIP_CHARS (a_this, 7); + status = CR_OK; + } else { + status = CR_PARSING_ERROR; + goto error; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - PRIVATE (a_this)->state = TRY_PARSE_IMPORT_STATE ; + PRIVATE (a_this)->state = TRY_PARSE_IMPORT_STATE; - PEEK_NEXT_CHAR (a_this, &next_char) ; + PEEK_NEXT_CHAR (a_this, &next_char); - if (next_char == '"' || next_char == '\'') - { - status = cr_parser_parse_string - (a_this, a_import_string) ; - - CHECK_PARSING_STATUS (status, FALSE) ; - } - else - { - status = cr_parser_parse_uri - (a_this, a_import_string) ; + if (next_char == '"' || next_char == '\'') { + status = cr_parser_parse_string (a_this, a_import_string); + + CHECK_PARSING_STATUS (status, FALSE); + } else { + status = cr_parser_parse_uri (a_this, a_import_string); - CHECK_PARSING_STATUS (status, FALSE) ; + CHECK_PARSING_STATUS (status, FALSE); } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_parser_parse_ident (a_this, &medium) ; + status = cr_parser_parse_ident (a_this, &medium); - if (status == CR_OK && medium) - { - *a_media_list = g_list_append (*a_media_list, - medium) ; - medium = NULL ; + if (status == CR_OK && medium) { + *a_media_list = g_list_append (*a_media_list, medium); + medium = NULL; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - for (;status == CR_OK;) - { - if ( (status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, - &next_char)) != CR_OK) - { - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; - goto okay ; + for (; status == CR_OK;) { + if ((status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, + &next_char)) != CR_OK) { + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + goto okay; } - goto error ; + goto error; } - - if (next_char == ',') - { - READ_NEXT_CHAR (a_this, &cur_char) ; - } - else - { - break ; + if (next_char == ',') { + READ_NEXT_CHAR (a_this, &cur_char); + } else { + break; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - status = cr_parser_parse_ident (a_this, - &medium) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + status = cr_parser_parse_ident (a_this, &medium); - if ((status == CR_OK) && medium) - { - *a_media_list = g_list_append - (*a_media_list, medium) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - medium = NULL ; + if ((status == CR_OK) && medium) { + *a_media_list = g_list_append (*a_media_list, medium); + + medium = NULL; } - CHECK_PARSING_STATUS (status, FALSE) ; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + CHECK_PARSING_STATUS (status, FALSE); + cr_parser_try_to_skip_spaces_and_comments (a_this); } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - READ_NEXT_CHAR (a_this, &cur_char) ; - ENSURE_PARSING_COND (cur_char == ';') ; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - okay: - cr_parser_clear_errors (a_this) ; - PRIVATE (a_this)->state = IMPORT_PARSED_STATE ; + cr_parser_try_to_skip_spaces_and_comments (a_this); + READ_NEXT_CHAR (a_this, &cur_char); + ENSURE_PARSING_COND (cur_char == ';'); + cr_parser_try_to_skip_spaces_and_comments (a_this); + okay: + cr_parser_clear_errors (a_this); + PRIVATE (a_this)->state = IMPORT_PARSED_STATE; + + return CR_OK; - return CR_OK ; + error: - error: + if (*a_media_list) { + GList *cur = NULL; - if (*a_media_list) - { - GList *cur = NULL ; /* *free each element of *a_media_list. *Note that each element of *a_medium list *must* @@ -4379,33 +3819,29 @@ cr_parser_parse_import (CRParser *a_this, GList ** a_media_list, *type checking mecanism (through STL containers) would *have prevented us to go through this hassle. */ - for (cur = *a_media_list; cur ; cur = cur->next) - { - if (cur->data) - { - g_string_free (cur->data, TRUE) ; + for (cur = *a_media_list; cur; cur = cur->next) { + if (cur->data) { + g_string_free (cur->data, TRUE); } } - g_list_free (*a_media_list) ; - *a_media_list = NULL ; + g_list_free (*a_media_list); + *a_media_list = NULL; } - if (*a_import_string) - { - g_string_free (*a_import_string, TRUE) ; - *a_import_string = NULL ; + if (*a_import_string) { + g_string_free (*a_import_string, TRUE); + *a_import_string = NULL; } - if (medium) - { - g_string_free (medium, TRUE) ; - medium = NULL ; + if (medium) { + g_string_free (medium, TRUE); + medium = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } /** @@ -4421,175 +3857,153 @@ cr_parser_parse_import (CRParser *a_this, GList ** a_media_list, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_media (CRParser *a_this) +cr_parser_parse_media (CRParser * a_this) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - CRToken * token = NULL ; - guint32 next_char = 0, cur_char = 0 ; - GString * medium = NULL ; - GList *media_list = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + CRToken *token = NULL; + guint32 next_char = 0, + cur_char = 0; + GString *medium = NULL; + GList *media_list = NULL; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == MEDIA_SYM_TK) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == MEDIA_SYM_TK); - cr_token_destroy (token) ; - token = NULL ; + cr_token_destroy (token); + token = NULL; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); ENSURE_PARSING_COND (status == CR_OK - && token && token->type == IDENT_TK) ; - - medium = token->u.str ; - token->u.str = NULL ; - cr_token_destroy (token) ; - token = NULL ; - - if (medium) - { - media_list = g_list_append (media_list, medium) ; - medium = NULL ; - } - - for (;status == CR_OK;) - { - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - PEEK_NEXT_CHAR (a_this, &next_char) ; - - if (next_char == ',') - { - READ_NEXT_CHAR (a_this, &cur_char) ; - } - else - { - break ; + && token && token->type == IDENT_TK); + + medium = token->u.str; + token->u.str = NULL; + cr_token_destroy (token); + token = NULL; + + if (medium) { + media_list = g_list_append (media_list, medium); + medium = NULL; + } + + for (; status == CR_OK;) { + cr_parser_try_to_skip_spaces_and_comments (a_this); + PEEK_NEXT_CHAR (a_this, &next_char); + + if (next_char == ',') { + READ_NEXT_CHAR (a_this, &cur_char); + } else { + break; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_parser_parse_ident (a_this, &medium) ; + status = cr_parser_parse_ident (a_this, &medium); - CHECK_PARSING_STATUS (status, FALSE) ; + CHECK_PARSING_STATUS (status, FALSE); - if (medium) - { - media_list = g_list_append (media_list, - medium) ; - medium = NULL ; + if (medium) { + media_list = g_list_append (media_list, medium); + medium = NULL; } } - READ_NEXT_CHAR (a_this, &cur_char) ; - - ENSURE_PARSING_COND (cur_char == '{') ; + READ_NEXT_CHAR (a_this, &cur_char); + + ENSURE_PARSING_COND (cur_char == '{'); /* *call the SAC handler api here. */ if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->start_media) - { - PRIVATE (a_this)->sac_handler->start_media - (PRIVATE (a_this)->sac_handler, media_list) ; + && PRIVATE (a_this)->sac_handler->start_media) { + PRIVATE (a_this)->sac_handler->start_media + (PRIVATE (a_this)->sac_handler, media_list); } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - PRIVATE (a_this)->state = TRY_PARSE_MEDIA_STATE ; + PRIVATE (a_this)->state = TRY_PARSE_MEDIA_STATE; - for (;status == CR_OK;) - { - status = cr_parser_parse_ruleset (a_this) ; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + for (; status == CR_OK;) { + status = cr_parser_parse_ruleset (a_this); + cr_parser_try_to_skip_spaces_and_comments (a_this); } - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - ENSURE_PARSING_COND (cur_char == '}') ; + ENSURE_PARSING_COND (cur_char == '}'); /* *call the right SAC handler api here. */ if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->end_media) - { - PRIVATE (a_this)->sac_handler->end_media - (PRIVATE (a_this)->sac_handler, - media_list) ; + && PRIVATE (a_this)->sac_handler->end_media) { + PRIVATE (a_this)->sac_handler->end_media + (PRIVATE (a_this)->sac_handler, media_list); } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); /* *Then, free the data structures passed to *the last call to the SAC handler. */ - if (medium) - { - g_string_free (medium, TRUE) ; - medium = NULL ; - } - - if (media_list) - { - GList *cur = NULL ; - - for (cur = media_list ; cur ; cur = cur->next) - { - g_string_free (cur->data, TRUE) ; + if (medium) { + g_string_free (medium, TRUE); + medium = NULL; + } + + if (media_list) { + GList *cur = NULL; + + for (cur = media_list; cur; cur = cur->next) { + g_string_free (cur->data, TRUE); } - g_list_free (media_list) ; - media_list = NULL ; + g_list_free (media_list); + media_list = NULL; } + cr_parser_clear_errors (a_this); + PRIVATE (a_this)->state = MEDIA_PARSED_STATE; - cr_parser_clear_errors (a_this) ; - PRIVATE (a_this)->state = MEDIA_PARSED_STATE ; + return CR_OK; - return CR_OK ; + error: - error: - - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - if (medium) - { - g_string_free (medium, TRUE) ; - medium = NULL ; + if (medium) { + g_string_free (medium, TRUE); + medium = NULL; } - if (media_list) - { - GList *cur = NULL ; - - for (cur = media_list ; cur ; cur = cur->next) - { - g_string_free (cur->data, TRUE) ; + if (media_list) { + GList *cur = NULL; + + for (cur = media_list; cur; cur = cur->next) { + g_string_free (cur->data, TRUE); } - g_list_free (media_list) ; - media_list = NULL ; + g_list_free (media_list); + media_list = NULL; } - + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - - return status ; + + return status; } /** @@ -4604,254 +4018,221 @@ cr_parser_parse_media (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_page (CRParser *a_this) +cr_parser_parse_page (CRParser * a_this) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - CRToken * token = NULL ; - CRTerm * css_expression = NULL ; - GString *page_selector = NULL, - *page_pseudo_class = NULL, - *property = NULL ; - gboolean important = TRUE ; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == PAGE_SYM_TK) ; - - cr_token_destroy (token) ; - token = NULL ; - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK && token) ; - - if (token->type == IDENT_TK) - { - page_selector = token->u.str ; - token->u.str = NULL ; - cr_token_destroy (token) ; - token = NULL ; - } - else - { - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, - token) ; - token = NULL ; - } - - /* - *try to parse pseudo_page - */ - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token) ; - - if (token->type == DELIM_TK && token->u.unichar == ':') - { - cr_token_destroy (token) ; - token = NULL ; - status = cr_parser_parse_ident (a_this, &page_pseudo_class) ; - CHECK_PARSING_STATUS (status, FALSE) ; - } - else - { - cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token) ; - token = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + CRToken *token = NULL; + CRTerm *css_expression = NULL; + GString *page_selector = NULL, + *page_pseudo_class = NULL, + *property = NULL; + gboolean important = TRUE; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + RECORD_INITIAL_POS (a_this, &init_pos); + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == PAGE_SYM_TK); + + cr_token_destroy (token); + token = NULL; + + cr_parser_try_to_skip_spaces_and_comments (a_this); + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); + + if (token->type == IDENT_TK) { + page_selector = token->u.str; + token->u.str = NULL; + cr_token_destroy (token); + token = NULL; + } else { + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); + token = NULL; + } + + /* + *try to parse pseudo_page + */ + cr_parser_try_to_skip_spaces_and_comments (a_this); + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token); + + if (token->type == DELIM_TK && token->u.unichar == ':') { + cr_token_destroy (token); + token = NULL; + status = cr_parser_parse_ident (a_this, &page_pseudo_class); + CHECK_PARSING_STATUS (status, FALSE); + } else { + cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token); + token = NULL; } /* *parse_block * */ - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == CBO_TK) ; + ENSURE_PARSING_COND (status == CR_OK && token + && token->type == CBO_TK); - cr_token_destroy (token) ; token = NULL ; + cr_token_destroy (token); + token = NULL; /* *Call the appropriate SAC handler here. */ - if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->start_page) - { - PRIVATE (a_this)->sac_handler->start_page - (PRIVATE (a_this)->sac_handler, - page_selector, page_pseudo_class) ; + if (PRIVATE (a_this)->sac_handler + && PRIVATE (a_this)->sac_handler->start_page) { + PRIVATE (a_this)->sac_handler->start_page + (PRIVATE (a_this)->sac_handler, + page_selector, page_pseudo_class); } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - PRIVATE (a_this)->state = TRY_PARSE_PAGE_STATE ; + PRIVATE (a_this)->state = TRY_PARSE_PAGE_STATE; status = cr_parser_parse_declaration (a_this, &property, - &css_expression, - &important) ; - ENSURE_PARSING_COND (status == CR_OK) ; + &css_expression, &important); + ENSURE_PARSING_COND (status == CR_OK); /* *call the relevant SAC handler here... */ if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->property) - { + && PRIVATE (a_this)->sac_handler->property) { if (css_expression) - cr_term_ref (css_expression) ; + cr_term_ref (css_expression); - PRIVATE (a_this)->sac_handler->property - (PRIVATE (a_this)->sac_handler, - property, css_expression, important) ; + PRIVATE (a_this)->sac_handler->property + (PRIVATE (a_this)->sac_handler, + property, css_expression, important); } /* *... and free the data structure passed to that last *SAC handler. */ - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; + if (property) { + g_string_free (property, TRUE); + property = NULL; } - if (css_expression) - { - cr_term_unref (css_expression) ; - css_expression = NULL ; + if (css_expression) { + cr_term_unref (css_expression); + css_expression = NULL; } - for (;;) - { - /*parse the other ';' separated declarations*/ - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } - status = cr_tknzr_get_next_token - (PRIVATE (a_this)->tknzr, &token) ; + for (;;) { + /*parse the other ';' separated declarations */ + if (token) { + cr_token_destroy (token); + token = NULL; + } + status = cr_tknzr_get_next_token + (PRIVATE (a_this)->tknzr, &token); - ENSURE_PARSING_COND (status == CR_OK && token) ; + ENSURE_PARSING_COND (status == CR_OK && token); - if (token->type != SEMICOLON_TK) break ; + if (token->type != SEMICOLON_TK) + break; - cr_token_destroy (token) ; - token = NULL ; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_token_destroy (token); + token = NULL; + cr_parser_try_to_skip_spaces_and_comments (a_this); status = cr_parser_parse_declaration (a_this, &property, - &css_expression, - &important) ; - CHECK_PARSING_STATUS (status, FALSE) ; - + &css_expression, + &important); + CHECK_PARSING_STATUS (status, FALSE); + /* *call the relevant SAC handler here... */ if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->property) - { - cr_term_ref (css_expression) ; - PRIVATE (a_this)->sac_handler->property - (PRIVATE (a_this)->sac_handler, - property, css_expression, - important) ; + && PRIVATE (a_this)->sac_handler->property) { + cr_term_ref (css_expression); + PRIVATE (a_this)->sac_handler->property + (PRIVATE (a_this)->sac_handler, + property, css_expression, important); } /* *... and free the data structure passed to that last *SAC handler. */ - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; + if (property) { + g_string_free (property, TRUE); + property = NULL; } - if (css_expression) - { - cr_term_unref (css_expression) ; - css_expression = NULL ; + if (css_expression) { + cr_term_unref (css_expression); + css_expression = NULL; } } - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == CBC_TK) ; - cr_token_destroy (token) ; token = NULL ; - + ENSURE_PARSING_COND (status == CR_OK && token + && token->type == CBC_TK); + cr_token_destroy (token); + token = NULL; /* *call the relevant SAC handler here. */ if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->end_page) - { - PRIVATE (a_this)->sac_handler->end_page - (PRIVATE (a_this)->sac_handler, - page_selector, page_pseudo_class) ; + && PRIVATE (a_this)->sac_handler->end_page) { + PRIVATE (a_this)->sac_handler->end_page + (PRIVATE (a_this)->sac_handler, + page_selector, page_pseudo_class); } - if (page_selector) - { - g_string_free (page_selector, TRUE) ; - page_selector = NULL ; + if (page_selector) { + g_string_free (page_selector, TRUE); + page_selector = NULL; } - if (page_pseudo_class) - { - g_string_free (page_pseudo_class, TRUE) ; - page_pseudo_class = NULL ; + if (page_pseudo_class) { + g_string_free (page_pseudo_class, TRUE); + page_pseudo_class = NULL; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - /*here goes the former implem of this function ...*/ + /*here goes the former implem of this function ... */ - cr_parser_clear_errors (a_this) ; - PRIVATE (a_this)->state = PAGE_PARSED_STATE ; + cr_parser_clear_errors (a_this); + PRIVATE (a_this)->state = PAGE_PARSED_STATE; - return CR_OK ; + return CR_OK; - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + error: + if (token) { + cr_token_destroy (token); + token = NULL; } - if (page_selector) - { - g_string_free (page_selector, TRUE) ; - page_selector = NULL ; + if (page_selector) { + g_string_free (page_selector, TRUE); + page_selector = NULL; } - if (page_pseudo_class) - { - g_string_free (page_pseudo_class, TRUE) ; - page_pseudo_class = NULL ; + if (page_pseudo_class) { + g_string_free (page_pseudo_class, TRUE); + page_pseudo_class = NULL; } - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; + if (property) { + g_string_free (property, TRUE); + property = NULL; } - if (css_expression) - { - cr_term_destroy (css_expression) ; - css_expression = NULL ; + if (css_expression) { + cr_term_destroy (css_expression); + css_expression = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - return status ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); + return status; } - /** *Parses a charset declaration as defined implictly by the css2 spec in *appendix D.1: @@ -4864,89 +4245,77 @@ cr_parser_parse_page (CRParser *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_charset (CRParser *a_this, GString **a_value) +cr_parser_parse_charset (CRParser * a_this, GString ** a_value) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - CRToken *token = NULL ; - GString *charset_str = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + CRToken *token = NULL; + GString *charset_str = NULL; - g_return_val_if_fail (a_this && a_value - && (*a_value == NULL), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_value + && (*a_value == NULL), CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - ENSURE_PARSING_COND (status == CR_OK - && token && token->type == CHARSET_SYM_TK) ; + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == CHARSET_SYM_TK); - cr_token_destroy (token) ; - token = NULL ; + cr_token_destroy (token); + token = NULL; - PRIVATE (a_this)->state = TRY_PARSE_CHARSET_STATE ; + PRIVATE (a_this)->state = TRY_PARSE_CHARSET_STATE; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token && token->type == STRING_TK) ; - charset_str = token->u.str ; - token->u.str = NULL ; - cr_token_destroy (token) ; - token = NULL ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == STRING_TK); + charset_str = token->u.str; + token->u.str = NULL; + cr_token_destroy (token); + token = NULL; - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); - ENSURE_PARSING_COND (status == CR_OK - && token && token->type == SEMICOLON_TK) ; - cr_token_destroy (token) ; - token = NULL ; + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == SEMICOLON_TK); + cr_token_destroy (token); + token = NULL; - if (charset_str) - { - *a_value = charset_str ; - charset_str = NULL ; + if (charset_str) { + *a_value = charset_str; + charset_str = NULL; } - PRIVATE (a_this)->state = CHARSET_PARSED_STATE ; - return CR_OK ; + PRIVATE (a_this)->state = CHARSET_PARSED_STATE; + return CR_OK; - error: + error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + if (token) { + cr_token_destroy (token); + token = NULL; } - if (*a_value) - { - g_string_free (*a_value, TRUE) ; - *a_value = NULL ; + if (*a_value) { + g_string_free (*a_value, TRUE); + *a_value = NULL; } - if (charset_str) - { - g_string_free (charset_str, TRUE) ; - charset_str = NULL ; + if (charset_str) { + g_string_free (charset_str, TRUE); + charset_str = NULL; } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, - &init_pos) ; + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); - return status ; + return status; } - - - /** *Parses the "@font-face" rule specified in the css1 spec in *appendix D.1: @@ -4958,168 +4327,144 @@ cr_parser_parse_charset (CRParser *a_this, GString **a_value) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_font_face (CRParser *a_this) +cr_parser_parse_font_face (CRParser * a_this) { - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - GString *property = NULL ; - CRTerm * css_expression = NULL ; - CRToken *token = NULL ; - gboolean important = FALSE ; - guint32 next_char = 0, cur_char = 0 ; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == FONT_FACE_SYM_TK) ; - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } - status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, - &token) ; - ENSURE_PARSING_COND (status == CR_OK - && token - && token->type == CBO_TK) ; - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + enum CRStatus status = CR_ERROR; + CRInputPos init_pos; + GString *property = NULL; + CRTerm *css_expression = NULL; + CRToken *token = NULL; + gboolean important = FALSE; + guint32 next_char = 0, + cur_char = 0; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + RECORD_INITIAL_POS (a_this, &init_pos); + + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK + && token && token->type == FONT_FACE_SYM_TK); + + cr_parser_try_to_skip_spaces_and_comments (a_this); + if (token) { + cr_token_destroy (token); + token = NULL; + } + status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token); + ENSURE_PARSING_COND (status == CR_OK && token + && token->type == CBO_TK); + if (token) { + cr_token_destroy (token); + token = NULL; } /* *here, call the relevant SAC handler. */ - if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->start_font_face) - { - PRIVATE (a_this)->sac_handler->start_font_face - (PRIVATE (a_this)->sac_handler) ; + if (PRIVATE (a_this)->sac_handler + && PRIVATE (a_this)->sac_handler->start_font_face) { + PRIVATE (a_this)->sac_handler->start_font_face + (PRIVATE (a_this)->sac_handler); } - PRIVATE (a_this)->state = TRY_PARSE_FONT_FACE_STATE ; + PRIVATE (a_this)->state = TRY_PARSE_FONT_FACE_STATE; /* *and resume the parsing. */ - cr_parser_try_to_skip_spaces_and_comments (a_this) ; + cr_parser_try_to_skip_spaces_and_comments (a_this); status = cr_parser_parse_declaration (a_this, &property, - &css_expression, - &important) ; - if (status == CR_OK) - { + &css_expression, &important); + if (status == CR_OK) { /* *here, call the relevant SAC handler. */ - cr_term_ref (css_expression) ; + cr_term_ref (css_expression); if (PRIVATE (a_this)->sac_handler && - PRIVATE (a_this)->sac_handler->property) - { + PRIVATE (a_this)->sac_handler->property) { PRIVATE (a_this)->sac_handler->property (PRIVATE (a_this)->sac_handler, - property, css_expression, - important) ; - } - ENSURE_PARSING_COND (css_expression && property) ; - } - /*free the data structures allocated during last parsing.*/ - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; - } - if (css_expression) - { - cr_term_unref (css_expression) ; - css_expression = NULL ; - } - for (;;) - { - PEEK_NEXT_CHAR (a_this, &next_char) ; - if (next_char == ';') - { - READ_NEXT_CHAR (a_this, &cur_char) ; + property, css_expression, important); } - else - { - break ; + ENSURE_PARSING_COND (css_expression && property); + } + /*free the data structures allocated during last parsing. */ + if (property) { + g_string_free (property, TRUE); + property = NULL; + } + if (css_expression) { + cr_term_unref (css_expression); + css_expression = NULL; + } + for (;;) { + PEEK_NEXT_CHAR (a_this, &next_char); + if (next_char == ';') { + READ_NEXT_CHAR (a_this, &cur_char); + } else { + break; } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - status = cr_parser_parse_declaration (a_this, &property, + cr_parser_try_to_skip_spaces_and_comments (a_this); + status = cr_parser_parse_declaration (a_this, &property, &css_expression, - &important) ; - if (status != CR_OK) break ; + &important); + if (status != CR_OK) + break; /* *here, call the relevant SAC handler. */ - cr_term_ref (css_expression) ; - if (PRIVATE (a_this)->sac_handler->property) - { + cr_term_ref (css_expression); + if (PRIVATE (a_this)->sac_handler->property) { PRIVATE (a_this)->sac_handler->property (PRIVATE (a_this)->sac_handler, - property, css_expression, - important) ; + property, css_expression, important); } /* *Then, free the data structures allocated during *last parsing. */ - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; + if (property) { + g_string_free (property, TRUE); + property = NULL; } - if (css_expression) - { - cr_term_unref (css_expression) ; - css_expression = NULL ; + if (css_expression) { + cr_term_unref (css_expression); + css_expression = NULL; } } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - READ_NEXT_CHAR (a_this, &cur_char) ; - ENSURE_PARSING_COND (cur_char == '}') ; + cr_parser_try_to_skip_spaces_and_comments (a_this); + READ_NEXT_CHAR (a_this, &cur_char); + ENSURE_PARSING_COND (cur_char == '}'); /* *here, call the relevant SAC handler. */ - if (PRIVATE (a_this)->sac_handler->end_font_face) - { - PRIVATE (a_this)->sac_handler->end_font_face - (PRIVATE (a_this)->sac_handler) ; - } - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } - cr_parser_clear_errors (a_this) ; - PRIVATE (a_this)->state = FONT_FACE_PARSED_STATE ; - return CR_OK ; - - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; - } - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; - } - if (css_expression) - { - cr_term_destroy (css_expression) ; - css_expression = NULL ; - } - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - return status ; + if (PRIVATE (a_this)->sac_handler->end_font_face) { + PRIVATE (a_this)->sac_handler->end_font_face + (PRIVATE (a_this)->sac_handler); + } + cr_parser_try_to_skip_spaces_and_comments (a_this); + + if (token) { + cr_token_destroy (token); + token = NULL; + } + cr_parser_clear_errors (a_this); + PRIVATE (a_this)->state = FONT_FACE_PARSED_STATE; + return CR_OK; + + error: + if (token) { + cr_token_destroy (token); + token = NULL; + } + if (property) { + g_string_free (property, TRUE); + property = NULL; + } + if (css_expression) { + cr_term_destroy (css_expression); + css_expression = NULL; + } + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos); + return status; } /** @@ -5130,44 +4475,37 @@ cr_parser_parse_font_face (CRParser *a_this) *@return CR_OK ; */ enum CRStatus -cr_parser_parse (CRParser *a_this) +cr_parser_parse (CRParser * a_this) { - enum CRStatus status = CR_ERROR ; + enum CRStatus status = CR_ERROR; g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->tknzr, - CR_BAD_PARAM_ERROR) ; - - if (PRIVATE (a_this)->use_core_grammar == FALSE) - { - status = cr_parser_parse_stylesheet (a_this) ; - } - else - { - status = cr_parser_parse_stylesheet_core (a_this) ; + && PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR); + + if (PRIVATE (a_this)->use_core_grammar == FALSE) { + status = cr_parser_parse_stylesheet (a_this); + } else { + status = cr_parser_parse_stylesheet_core (a_this); } - return status ; + return status; } - enum CRStatus -cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) +cr_parser_set_tknzr (CRParser * a_this, CRTknzr * a_tknzr) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - if (PRIVATE (a_this)->tknzr) - { - cr_tknzr_unref (PRIVATE (a_this)->tknzr) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); + + if (PRIVATE (a_this)->tknzr) { + cr_tknzr_unref (PRIVATE (a_this)->tknzr); } - PRIVATE (a_this)->tknzr = a_tknzr ; + PRIVATE (a_this)->tknzr = a_tknzr; if (a_tknzr) - cr_tknzr_ref (a_tknzr) ; + cr_tknzr_ref (a_tknzr); - return CR_OK ; + return CR_OK; } /** @@ -5178,14 +4516,13 @@ cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) *otherwise */ enum CRStatus -cr_parser_get_tknzr (CRParser *a_this, CRTknzr **a_tknzr) +cr_parser_get_tknzr (CRParser * a_this, CRTknzr ** a_tknzr) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_tknzr, - CR_BAD_PARAM_ERROR) ; + && a_tknzr, CR_BAD_PARAM_ERROR); - *a_tknzr = PRIVATE (a_this)->tknzr ; - return CR_OK ; + *a_tknzr = PRIVATE (a_this)->tknzr; + return CR_OK; } /** @@ -5197,30 +4534,28 @@ cr_parser_get_tknzr (CRParser *a_this, CRTknzr **a_tknzr) *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf, +cr_parser_parse_buf (CRParser * a_this, + const guchar * a_buf, gulong a_len, enum CREncoding a_enc) { - enum CRStatus status = CR_ERROR ; - CRTknzr *tknzr = NULL ; + enum CRStatus status = CR_ERROR; + CRTknzr *tknzr = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_buf, - CR_BAD_PARAM_ERROR) ; + && a_buf, CR_BAD_PARAM_ERROR); - tknzr = cr_tknzr_new_from_buf (a_buf,a_len, - a_enc, FALSE) ; + tknzr = cr_tknzr_new_from_buf (a_buf, a_len, a_enc, FALSE); - g_return_val_if_fail (tknzr != NULL, CR_ERROR) ; + g_return_val_if_fail (tknzr != NULL, CR_ERROR); - status = cr_parser_set_tknzr (a_this, tknzr) ; - g_return_val_if_fail (status == CR_OK, CR_ERROR) ; + status = cr_parser_set_tknzr (a_this, tknzr); + g_return_val_if_fail (status == CR_OK, CR_ERROR); - status = cr_parser_parse (a_this) ; + status = cr_parser_parse (a_this); - return status ; + return status; } - /** *Destroys the current instance *of #CRParser. @@ -5228,38 +4563,32 @@ cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf, *destroy. */ void -cr_parser_destroy (CRParser *a_this) +cr_parser_destroy (CRParser * a_this) { - g_return_if_fail (a_this && PRIVATE (a_this)) ; + g_return_if_fail (a_this && PRIVATE (a_this)); - - if (PRIVATE (a_this)->tknzr) - { + if (PRIVATE (a_this)->tknzr) { if (cr_tknzr_unref (PRIVATE (a_this)->tknzr) == TRUE) - PRIVATE (a_this)->tknzr = NULL ; + PRIVATE (a_this)->tknzr = NULL; } - if (PRIVATE (a_this)->sac_handler) - { - cr_doc_handler_unref (PRIVATE (a_this)->sac_handler) ; - PRIVATE (a_this)->sac_handler = NULL ; + if (PRIVATE (a_this)->sac_handler) { + cr_doc_handler_unref (PRIVATE (a_this)->sac_handler); + PRIVATE (a_this)->sac_handler = NULL; } - - if (PRIVATE (a_this)->err_stack) - { + + if (PRIVATE (a_this)->err_stack) { cr_parser_clear_errors (a_this); - PRIVATE (a_this)->err_stack = NULL ; + PRIVATE (a_this)->err_stack = NULL; } - if (PRIVATE (a_this)) - { - g_free (PRIVATE (a_this)) ; - PRIVATE (a_this) = NULL ; + if (PRIVATE (a_this)) { + g_free (PRIVATE (a_this)); + PRIVATE (a_this) = NULL; } - if (a_this) - { - g_free (a_this) ; - a_this = NULL ;/*useless. Just for the sake of coherence*/ + if (a_this) { + g_free (a_this); + a_this = NULL; /*useless. Just for the sake of coherence */ } } diff --git a/src/cr-prop-list.c b/src/cr-prop-list.c index 84d27bf..acdca79 100644 --- a/src/cr-prop-list.c +++ b/src/cr-prop-list.c @@ -23,46 +23,41 @@ #define PRIVATE(a_obj) (a_obj)->priv -struct _CRPropListPriv -{ - GString *prop ; - CRDeclaration *decl ; - CRPropList *next ; - CRPropList *prev ; +struct _CRPropListPriv { + GString *prop; + CRDeclaration *decl; + CRPropList *next; + CRPropList *prev; }; -static CRPropList * -cr_prop_list_allocate (void) ; +static CRPropList *cr_prop_list_allocate (void); /** *Default allocator of CRPropList *@return the newly allocated CRPropList or NULL *if an error arises. */ -static CRPropList * +static CRPropList * cr_prop_list_allocate (void) { - CRPropList *result = NULL; - - result = g_try_malloc (sizeof (CRPropList)) ; - if (!result) - { - cr_utils_trace_info ("could not allocate CRPropList") ; - return NULL ; - } - memset (result, 0, sizeof (CRPropList)) ; - PRIVATE (result) = g_try_malloc (sizeof (CRPropListPriv)) ; - if (!result) - { - cr_utils_trace_info ("could not allocate CRPropListPriv") ; - g_free (result) ; - return NULL ; - } - memset (PRIVATE (result), 0, sizeof (CRPropListPriv)) ; - return result ; + CRPropList *result = NULL; + + result = g_try_malloc (sizeof (CRPropList)); + if (!result) { + cr_utils_trace_info ("could not allocate CRPropList"); + return NULL; + } + memset (result, 0, sizeof (CRPropList)); + PRIVATE (result) = g_try_malloc (sizeof (CRPropListPriv)); + if (!result) { + cr_utils_trace_info ("could not allocate CRPropListPriv"); + g_free (result); + return NULL; + } + memset (PRIVATE (result), 0, sizeof (CRPropListPriv)); + return result; } - /**************** *public methods ***************/ @@ -74,28 +69,25 @@ cr_prop_list_allocate (void) *@return the resulting prop list, or NULL if an error *occured */ -CRPropList * -cr_prop_list_append (CRPropList *a_this, - CRPropList *a_to_append) +CRPropList * +cr_prop_list_append (CRPropList * a_this, CRPropList * a_to_append) { - CRPropList *cur=NULL ; - - g_return_val_if_fail (a_to_append, NULL) ; - - if (!a_this) - return a_to_append ; - - /*go fetch the last element of the list*/ - for (cur = a_this ; - cur && PRIVATE (cur) && PRIVATE (cur)->next ; - cur = PRIVATE (cur)->next) - ; - g_return_val_if_fail (cur, NULL) ; - PRIVATE (cur)->next = a_to_append ; - PRIVATE (a_to_append)->prev = cur ; - return a_this ; -} + CRPropList *cur = NULL; + + g_return_val_if_fail (a_to_append, NULL); + if (!a_this) + return a_to_append; + + /*go fetch the last element of the list */ + for (cur = a_this; + cur && PRIVATE (cur) && PRIVATE (cur)->next; + cur = PRIVATE (cur)->next) ; + g_return_val_if_fail (cur, NULL); + PRIVATE (cur)->next = a_to_append; + PRIVATE (a_to_append)->prev = cur; + return a_this; +} /** *Appends a pair of prop/declaration to @@ -106,24 +98,23 @@ cr_prop_list_append (CRPropList *a_this, *@return the resulting property list, or NULL in case *of an error. */ -CRPropList * -cr_prop_list_append2 (CRPropList *a_this, - GString *a_prop, - CRDeclaration *a_decl) +CRPropList * +cr_prop_list_append2 (CRPropList * a_this, + GString * a_prop, CRDeclaration * a_decl) { - CRPropList *list = NULL, *result = NULL ; + CRPropList *list = NULL, + *result = NULL; - g_return_val_if_fail (a_prop && a_decl, - NULL) ; + g_return_val_if_fail (a_prop && a_decl, NULL); - list = cr_prop_list_allocate () ; - g_return_val_if_fail (list && PRIVATE (list), NULL) ; + list = cr_prop_list_allocate (); + g_return_val_if_fail (list && PRIVATE (list), NULL); - PRIVATE (list)->prop = a_prop ; - PRIVATE (list)->decl = a_decl ; + PRIVATE (list)->prop = a_prop; + PRIVATE (list)->decl = a_decl; - result = cr_prop_list_append (a_this, list) ; - return result ; + result = cr_prop_list_append (a_this, list); + return result; } /** @@ -131,24 +122,22 @@ cr_prop_list_append2 (CRPropList *a_this, *@param a_this the current instance of #CRPropList *@param the new list to prepend. */ -CRPropList * -cr_prop_list_prepend (CRPropList *a_this, - CRPropList *a_to_prepend) +CRPropList * +cr_prop_list_prepend (CRPropList * a_this, CRPropList * a_to_prepend) { - CRPropList *cur = NULL ; + CRPropList *cur = NULL; - g_return_val_if_fail (a_to_prepend, NULL) ; + g_return_val_if_fail (a_to_prepend, NULL); - if (!a_this) - return a_to_prepend ; + if (!a_this) + return a_to_prepend; - for (cur = a_to_prepend; cur && PRIVATE (cur)->next ; - cur = PRIVATE (cur)->next) - ; - g_return_val_if_fail (cur, NULL) ; - PRIVATE (cur)->next = a_this ; - PRIVATE (a_this)->prev = cur ; - return a_to_prepend ; + for (cur = a_to_prepend; cur && PRIVATE (cur)->next; + cur = PRIVATE (cur)->next) ; + g_return_val_if_fail (cur, NULL); + PRIVATE (cur)->next = a_this; + PRIVATE (a_this)->prev = cur; + return a_to_prepend; } /** @@ -156,23 +145,22 @@ cr_prop_list_prepend (CRPropList *a_this, *@param a_this the current instance of #CRPropList *@param the new list to prepend. */ -CRPropList * -cr_prop_list_prepend2 (CRPropList *a_this, - GString *a_prop, - CRDeclaration *a_decl) +CRPropList * +cr_prop_list_prepend2 (CRPropList * a_this, + GString * a_prop, CRDeclaration * a_decl) { - CRPropList *list = NULL, *result = NULL ; - - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_prop && a_decl, NULL) ; - - list = cr_prop_list_allocate () ; - g_return_val_if_fail (list, NULL) ; - PRIVATE (list)->prop = a_prop ; - PRIVATE (list)->decl = a_decl ; - result = cr_prop_list_prepend (a_this, list) ; - return result ; + CRPropList *list = NULL, + *result = NULL; + + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_prop && a_decl, NULL); + + list = cr_prop_list_allocate (); + g_return_val_if_fail (list, NULL); + PRIVATE (list)->prop = a_prop; + PRIVATE (list)->decl = a_decl; + result = cr_prop_list_prepend (a_this, list); + return result; } /** @@ -181,18 +169,15 @@ cr_prop_list_prepend2 (CRPropList *a_this, *@param a_prop the property to set */ enum CRStatus -cr_prop_list_set_prop (CRPropList *a_this, - GString *a_prop) +cr_prop_list_set_prop (CRPropList * a_this, GString * a_prop) { - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_prop, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_prop, CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->prop = a_prop ; - return CR_OK ; + PRIVATE (a_this)->prop = a_prop; + return CR_OK; } - /** *Getter of the property associated to the current instance *of #CRPropList @@ -202,43 +187,33 @@ cr_prop_list_set_prop (CRPropList *a_this, *otherwise. */ enum CRStatus -cr_prop_list_get_prop (CRPropList *a_this, - GString **a_prop) +cr_prop_list_get_prop (CRPropList * a_this, GString ** a_prop) { - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_prop, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_prop, CR_BAD_PARAM_ERROR); - *a_prop = PRIVATE (a_this)->prop ; - return CR_OK ; + *a_prop = PRIVATE (a_this)->prop; + return CR_OK; } enum CRStatus -cr_prop_list_set_decl (CRPropList *a_this, - CRDeclaration *a_decl) +cr_prop_list_set_decl (CRPropList * a_this, CRDeclaration * a_decl) { - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_decl, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_decl, CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->decl =a_decl ; - return CR_OK ; + PRIVATE (a_this)->decl = a_decl; + return CR_OK; } - enum CRStatus -cr_prop_list_get_decl (CRPropList *a_this, - CRDeclaration **a_decl) +cr_prop_list_get_decl (CRPropList * a_this, CRDeclaration ** a_decl) { - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_decl, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_decl, CR_BAD_PARAM_ERROR); - *a_decl = PRIVATE (a_this)->decl ; - return CR_OK ; + *a_decl = PRIVATE (a_this)->decl; + return CR_OK; } /** @@ -252,40 +227,33 @@ cr_prop_list_get_decl (CRPropList *a_this, *bad happens. */ enum CRStatus -cr_prop_list_lookup_prop (CRPropList *a_this, - GString *a_prop, - CRPropList **a_pair) +cr_prop_list_lookup_prop (CRPropList * a_this, + GString * a_prop, CRPropList ** a_pair) { - CRPropList *cur = NULL ; - - g_return_val_if_fail (a_prop && a_pair, - CR_BAD_PARAM_ERROR) ; - - if (!a_this) - return CR_VALUE_NOT_FOUND_ERROR ; - - g_return_val_if_fail (PRIVATE (a_this), CR_BAD_PARAM_ERROR) ; - - for (cur = a_this ; cur ; - cur = PRIVATE (cur)->next) - { - if (PRIVATE (cur)->prop - && PRIVATE (cur)->prop->str - && a_prop->str - && ! strcmp (PRIVATE (cur)->prop->str, - a_prop->str)) - break ; - } - - if (cur) - { - *a_pair = cur ; - return CR_OK ; - } - - return CR_VALUE_NOT_FOUND_ERROR ; -} + CRPropList *cur = NULL; + + g_return_val_if_fail (a_prop && a_pair, CR_BAD_PARAM_ERROR); + + if (!a_this) + return CR_VALUE_NOT_FOUND_ERROR; + g_return_val_if_fail (PRIVATE (a_this), CR_BAD_PARAM_ERROR); + + for (cur = a_this; cur; cur = PRIVATE (cur)->next) { + if (PRIVATE (cur)->prop + && PRIVATE (cur)->prop->str + && a_prop->str + && !strcmp (PRIVATE (cur)->prop->str, a_prop->str)) + break; + } + + if (cur) { + *a_pair = cur; + return CR_OK; + } + + return CR_VALUE_NOT_FOUND_ERROR; +} /** *Gets the next prop/decl pair in the list @@ -296,12 +264,11 @@ cr_prop_list_lookup_prop (CRPropList *a_this, *or NULL if we reached end of list (or if an error occurs) */ CRPropList * -cr_prop_list_get_next (CRPropList *a_this) +cr_prop_list_get_next (CRPropList * a_this) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - NULL) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), NULL); - return PRIVATE (a_this)->next ; + return PRIVATE (a_this)->next; } /** @@ -313,12 +280,11 @@ cr_prop_list_get_next (CRPropList *a_this) *or NULL if we reached end of list (or if an error occurs) */ CRPropList * -cr_prop_list_get_prev (CRPropList *a_this) +cr_prop_list_get_prev (CRPropList * a_this) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - NULL) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), NULL); - return PRIVATE (a_this)->prev ; + return PRIVATE (a_this)->prev; } /** @@ -327,73 +293,63 @@ cr_prop_list_get_prev (CRPropList *a_this) *@param a_pair the prop/decl pair to unlink. *@return the new list or NULL in case of an error. */ -CRPropList * -cr_prop_list_unlink (CRPropList *a_this, - CRPropList *a_pair) +CRPropList * +cr_prop_list_unlink (CRPropList * a_this, CRPropList * a_pair) { - CRPropList *prev = NULL, *next = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pair, - NULL) ; - - /*some sanity checks*/ - if (PRIVATE (a_pair)->next) - { - next = PRIVATE (a_pair)->next ; - g_return_val_if_fail (PRIVATE (next), NULL) ; - g_return_val_if_fail - (PRIVATE (next)->prev == a_pair, - NULL) ; - } - if (PRIVATE (a_pair)->prev) - { - prev = PRIVATE (a_pair)->prev ; - g_return_val_if_fail (PRIVATE (prev), NULL) ; - g_return_val_if_fail - (PRIVATE (prev)->next == a_pair, NULL) ; - } - if (prev) - { - PRIVATE (prev)->next = next ; - } - if (next) - { - PRIVATE (next)->prev = prev ; - } - PRIVATE (a_pair)->prev = PRIVATE (a_pair)->next = NULL ; - if (a_this == a_pair) - { - if (next) - return next ; - return NULL ; - } - return a_this ; + CRPropList *prev = NULL, + *next = NULL; + + g_return_val_if_fail (a_this && PRIVATE (a_this) && a_pair, NULL); + + /*some sanity checks */ + if (PRIVATE (a_pair)->next) { + next = PRIVATE (a_pair)->next; + g_return_val_if_fail (PRIVATE (next), NULL); + g_return_val_if_fail (PRIVATE (next)->prev == a_pair, NULL); + } + if (PRIVATE (a_pair)->prev) { + prev = PRIVATE (a_pair)->prev; + g_return_val_if_fail (PRIVATE (prev), NULL); + g_return_val_if_fail (PRIVATE (prev)->next == a_pair, NULL); + } + if (prev) { + PRIVATE (prev)->next = next; + } + if (next) { + PRIVATE (next)->prev = prev; + } + PRIVATE (a_pair)->prev = PRIVATE (a_pair)->next = NULL; + if (a_this == a_pair) { + if (next) + return next; + return NULL; + } + return a_this; } void -cr_prop_list_destroy (CRPropList *a_this) +cr_prop_list_destroy (CRPropList * a_this) { - CRPropList *tail = NULL, *cur = NULL ; - - g_return_if_fail (a_this && PRIVATE (a_this)) ; - - for (tail = a_this ; - tail && PRIVATE (tail) && PRIVATE (tail)->next; - tail = cr_prop_list_get_next (tail)) - ; - g_return_if_fail (tail) ; - - cur = tail ; - - while (cur) - { - tail = PRIVATE (cur)->prev ; - if (tail && PRIVATE (tail)) - PRIVATE (tail)->next = NULL ; - PRIVATE (cur)->prev = NULL ; - g_free (PRIVATE (cur)) ; - PRIVATE (cur) = NULL ; - g_free (cur) ; - cur = tail ; - } + CRPropList *tail = NULL, + *cur = NULL; + + g_return_if_fail (a_this && PRIVATE (a_this)); + + for (tail = a_this; + tail && PRIVATE (tail) && PRIVATE (tail)->next; + tail = cr_prop_list_get_next (tail)) ; + g_return_if_fail (tail); + + cur = tail; + + while (cur) { + tail = PRIVATE (cur)->prev; + if (tail && PRIVATE (tail)) + PRIVATE (tail)->next = NULL; + PRIVATE (cur)->prev = NULL; + g_free (PRIVATE (cur)); + PRIVATE (cur) = NULL; + g_free (cur); + cur = tail; + } } diff --git a/src/cr-pseudo.c b/src/cr-pseudo.c index 0323e44..1e0cd69 100644 --- a/src/cr-pseudo.c +++ b/src/cr-pseudo.c @@ -38,136 +38,117 @@ CRPseudo * cr_pseudo_new (void) { - CRPseudo * result = NULL ; - - result = g_malloc0 (sizeof (CRPseudo)) ; + CRPseudo *result = NULL; - return result ; -} + result = g_malloc0 (sizeof (CRPseudo)); + return result; +} guchar * -cr_pseudo_to_string (CRPseudo *a_this) +cr_pseudo_to_string (CRPseudo * a_this) { - guchar *result = NULL ; - GString *str_buf = NULL ; + guchar *result = NULL; + GString *str_buf = NULL; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - str_buf = g_string_new (NULL) ; + str_buf = g_string_new (NULL); - if (a_this->type == IDENT_PSEUDO) - { - guchar * name = NULL ; + if (a_this->type == IDENT_PSEUDO) { + guchar *name = NULL; - if (a_this->name == NULL) - { - goto error ; + if (a_this->name == NULL) { + goto error; } - name = g_strndup (a_this->name->str, - a_this->name->len) ; + name = g_strndup (a_this->name->str, a_this->name->len); - if (name) - { - g_string_append_printf (str_buf,"%s", name) ; - g_free (name) ; - name = NULL ; + if (name) { + g_string_append_printf (str_buf, "%s", name); + g_free (name); + name = NULL; } - } - else if (a_this->type == FUNCTION_PSEUDO) - { - guchar * name = NULL, *arg = NULL ; - - if (a_this->name == NULL) - goto error ; - - name = g_strndup (a_this->name->str, - a_this->name->len) ; - - if (a_this->extra) - { + } else if (a_this->type == FUNCTION_PSEUDO) { + guchar *name = NULL, + *arg = NULL; + + if (a_this->name == NULL) + goto error; + + name = g_strndup (a_this->name->str, a_this->name->len); + + if (a_this->extra) { arg = g_strndup (a_this->extra->str, - a_this->extra->len) ; + a_this->extra->len); } - if (name) - { - g_string_append_printf (str_buf, - "%s(", name) ; - g_free (name) ; - name = NULL ; - - if (arg) - { - g_string_append_printf (str_buf, - "%s", arg) ; - g_free (arg) ; - arg = NULL ; + if (name) { + g_string_append_printf (str_buf, "%s(", name); + g_free (name); + name = NULL; + + if (arg) { + g_string_append_printf (str_buf, "%s", arg); + g_free (arg); + arg = NULL; } - g_string_append_printf (str_buf, ")") ; - } + g_string_append_printf (str_buf, ")"); + } } - if (str_buf) - { - result = str_buf->str ; - g_string_free (str_buf, FALSE) ; - str_buf = NULL ; + if (str_buf) { + result = str_buf->str; + g_string_free (str_buf, FALSE); + str_buf = NULL; } - return result ; + return result; - error: - g_string_free (str_buf, TRUE) ; - return NULL ; + error: + g_string_free (str_buf, TRUE); + return NULL; } - /** *Dumps the pseudo to a file. *@param a_this the current instance of pseudo *@param a_fp the destination file pointer. */ void -cr_pseudo_dump (CRPseudo *a_this, FILE *a_fp) +cr_pseudo_dump (CRPseudo * a_this, FILE * a_fp) { - guchar *tmp_str = NULL ; - - if (a_this) - { - tmp_str = cr_pseudo_to_string (a_this) ; - if (tmp_str) - { - fprintf (a_fp, "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + guchar *tmp_str = NULL; + + if (a_this) { + tmp_str = cr_pseudo_to_string (a_this); + if (tmp_str) { + fprintf (a_fp, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } } } - /** *destructor of the #CRPseudo class. *@param a_this the current instance to destroy. */ void -cr_pseudo_destroy (CRPseudo *a_this) +cr_pseudo_destroy (CRPseudo * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - if (a_this->name) - { - g_string_free (a_this->name, TRUE) ; - a_this->name = NULL ; - } + if (a_this->name) { + g_string_free (a_this->name, TRUE); + a_this->name = NULL; + } - if (a_this->extra) - { - g_string_free (a_this->extra, TRUE) ; - a_this->extra = NULL ; - } + if (a_this->extra) { + g_string_free (a_this->extra, TRUE); + a_this->extra = NULL; + } - g_free (a_this) ; + g_free (a_this); } diff --git a/src/cr-rgb.c b/src/cr-rgb.c index d1c1c38..5cacb3e 100644 --- a/src/cr-rgb.c +++ b/src/cr-rgb.c @@ -28,156 +28,155 @@ #include #include "cr-rgb.h" -static CRRgb gv_standard_colors[] = -{ - { "aliceblue", 240, 248, 255, 0}, - { "antiquewhite", 250, 235, 215, 0}, - { "aqua", 0, 255, 255, 0}, - { "aquamarine", 127, 255, 212, 0}, - { "azure", 240, 255, 255, 0}, - { "beige", 245, 245, 220, 0}, - { "bisque", 255, 228, 196, 0}, - { "black", 0, 0, 0, 0}, - { "blanchedalmond", 255, 235, 205, 0}, - { "blue", 0, 0, 255, 0}, - { "blueviolet", 138, 43, 226, 0}, - { "brown", 165, 42, 42, 0}, - { "burlywood", 222, 184, 135, 0}, - { "cadetblue", 95, 158, 160, 0}, - { "chartreuse", 127, 255, 0, 0}, - { "chocolate", 210, 105, 30, 0}, - { "coral", 255, 127, 80, 0}, - { "cornflowerblue", 100, 149, 237, 0}, - { "cornsilk", 255, 248, 220, 0}, - { "crimson", 220, 20, 60, 0}, - { "cyan", 0, 255, 255, 0}, - { "darkblue", 0, 0, 139, 0}, - { "darkcyan", 0, 139, 139, 0}, - { "darkgoldenrod", 184, 134, 11, 0}, - { "darkgray", 169, 169, 169, 0}, - { "darkgreen", 0, 100, 0, 0}, - { "darkgrey", 169, 169, 169, 0}, - { "darkkhaki", 189, 183, 107, 0}, - { "darkmagenta", 139, 0, 139, 0}, - { "darkolivegreen", 85, 107, 47, 0}, - { "darkorange", 255, 140, 0, 0}, - { "darkorchid", 153, 50, 204, 0}, - { "darkred", 139, 0, 0, 0}, - { "darksalmon", 233, 150, 122, 0}, - { "darkseagreen", 143, 188, 143, 0}, - { "darkslateblue", 72, 61, 139, 0}, - { "darkslategray", 47, 79, 79, 0}, - { "darkslategrey", 47, 79, 79, 0}, - { "darkturquoise", 0, 206, 209, 0}, - { "darkviolet", 148, 0, 211, 0}, - { "deeppink", 255, 20, 147, 0}, - { "deepskyblue", 0, 191, 255, 0}, - { "dimgray", 105, 105, 105, 0}, - { "dimgrey", 105, 105, 105, 0}, - { "dodgerblue", 30, 144, 255, 0}, - { "firebrick", 178, 34, 34, 0}, - { "floralwhite", 255, 250, 240, 0}, - { "forestgreen", 34, 139, 34, 0}, - { "fuchsia", 255, 0, 255, 0}, - { "gainsboro", 220, 220, 220, 0}, - { "ghostwhite", 248, 248, 255, 0}, - { "gold", 255, 215, 0, 0}, - { "goldenrod", 218, 165, 32, 0}, - { "gray", 128, 128, 128, 0}, - { "grey", 128, 128, 128, 0}, - { "green", 0, 128, 0, 0}, - { "greenyellow", 173, 255, 47, 0}, - { "honeydew", 240, 255, 240, 0}, - { "hotpink", 255, 105, 180, 0}, - { "indianred", 205, 92, 92, 0}, - { "indigo", 75, 0, 130, 0}, - { "ivory", 255, 255, 240, 0}, - { "khaki", 240, 230, 140, 0}, - { "lavender", 230, 230, 250, 0}, - { "lavenderblush", 255, 240, 245, 0}, - { "lawngreen", 124, 252, 0, 0}, - { "lemonchiffon", 255, 250, 205, 0}, - { "lightblue", 173, 216, 230, 0}, - { "lightcoral", 240, 128, 128, 0}, - { "lightcyan", 224, 255, 255, 0}, - { "lightgoldenrodyellow", 250, 250, 210, 0}, - { "lightgray", 211, 211, 211, 0}, - { "lightgreen", 144, 238, 144, 0}, - { "lightgrey", 211, 211, 211, 0}, - { "lightpink", 255, 182, 193, 0}, - { "lightsalmon", 255, 160, 122, 0}, - { "lightseagreen", 32, 178, 170, 0}, - { "lightskyblue", 135, 206, 250, 0}, - { "lightslategray", 119, 136, 153, 0}, - { "lightslategrey", 119, 136, 153, 0}, - { "lightsteelblue", 176, 196, 222, 0}, - { "lightyellow", 255, 255, 224, 0}, - { "lime", 0, 255, 0, 0}, - { "limegreen", 50, 205, 50, 0}, - { "linen", 250, 240, 230, 0}, - { "magenta", 255, 0, 255, 0}, - { "maroon", 128, 0, 0, 0}, - { "mediumaquamarine", 102, 205, 170, 0}, - { "mediumblue", 0, 0, 205, 0}, - { "mediumorchid", 186, 85, 211, 0}, - { "mediumpurple", 147, 112, 219, 0}, - { "mediumseagreen", 60, 179, 113, 0}, - { "mediumslateblue", 123, 104, 238, 0}, - { "mediumspringgreen", 0, 250, 154, 0}, - { "mediumturquoise", 72, 209, 204, 0}, - { "mediumvioletred", 199, 21, 133, 0}, - { "midnightblue", 25, 25, 112, 0}, - { "mintcream", 245, 255, 250, 0}, - { "mistyrose", 255, 228, 225, 0}, - { "moccasin", 255, 228, 181, 0}, - { "navajowhite", 255, 222, 173, 0}, - { "navy", 0, 0, 128, 0}, - { "oldlace", 253, 245, 230, 0}, - { "olive", 128, 128, 0, 0}, - { "olivedrab", 107, 142, 35, 0}, - { "orange", 255, 165, 0, 0}, - { "orangered", 255, 69, 0, 0}, - { "orchid", 218, 112, 214, 0}, - { "palegoldenrod", 238, 232, 170, 0}, - { "palegreen", 152, 251, 152, 0}, - { "paleturquoise", 175, 238, 238, 0}, - { "palevioletred", 219, 112, 147, 0}, - { "papayawhip", 255, 239, 213, 0}, - { "peachpuff", 255, 218, 185, 0}, - { "peru", 205, 133, 63, 0}, - { "pink", 255, 192, 203, 0}, - { "plum", 221, 160, 221, 0}, - { "powderblue", 176, 224, 230, 0}, - { "purple", 128, 0, 128, 0}, - { "red", 255, 0, 0, 0}, - { "rosybrown", 188, 143, 143, 0}, - { "royalblue", 65, 105, 225, 0}, - { "saddlebrown", 139, 69, 19, 0}, - { "salmon", 250, 128, 114, 0}, - { "sandybrown", 244, 164, 96, 0}, - { "seagreen", 46, 139, 87, 0}, - { "seashell", 255, 245, 238, 0}, - { "sienna", 160, 82, 45, 0}, - { "silver", 192, 192, 192, 0}, - { "skyblue", 135, 206, 235, 0}, - { "slateblue", 106, 90, 205, 0}, - { "slategray", 112, 128, 144, 0}, - { "slategrey", 112, 128, 144, 0}, - { "snow", 255, 250, 250, 0}, - { "springgreen", 0, 255, 127, 0}, - { "steelblue", 70, 130, 180, 0}, - { "tan", 210, 180, 140, 0}, - { "teal", 0, 128, 128, 0}, - { "thistle", 216, 191, 216, 0}, - { "tomato", 255, 99, 71, 0}, - { "turquoise", 64, 224, 208, 0}, - { "violet", 238, 130, 238, 0}, - { "wheat", 245, 222, 179, 0}, - { "white", 255, 255, 255, 0}, - { "whitesmoke", 245, 245, 245, 0}, - { "yellow", 255, 255, 0, 0}, - { "yellowgreen", 154, 205, 50, 0} -} ; +static CRRgb gv_standard_colors[] = { + {"aliceblue", 240, 248, 255, 0}, + {"antiquewhite", 250, 235, 215, 0}, + {"aqua", 0, 255, 255, 0}, + {"aquamarine", 127, 255, 212, 0}, + {"azure", 240, 255, 255, 0}, + {"beige", 245, 245, 220, 0}, + {"bisque", 255, 228, 196, 0}, + {"black", 0, 0, 0, 0}, + {"blanchedalmond", 255, 235, 205, 0}, + {"blue", 0, 0, 255, 0}, + {"blueviolet", 138, 43, 226, 0}, + {"brown", 165, 42, 42, 0}, + {"burlywood", 222, 184, 135, 0}, + {"cadetblue", 95, 158, 160, 0}, + {"chartreuse", 127, 255, 0, 0}, + {"chocolate", 210, 105, 30, 0}, + {"coral", 255, 127, 80, 0}, + {"cornflowerblue", 100, 149, 237, 0}, + {"cornsilk", 255, 248, 220, 0}, + {"crimson", 220, 20, 60, 0}, + {"cyan", 0, 255, 255, 0}, + {"darkblue", 0, 0, 139, 0}, + {"darkcyan", 0, 139, 139, 0}, + {"darkgoldenrod", 184, 134, 11, 0}, + {"darkgray", 169, 169, 169, 0}, + {"darkgreen", 0, 100, 0, 0}, + {"darkgrey", 169, 169, 169, 0}, + {"darkkhaki", 189, 183, 107, 0}, + {"darkmagenta", 139, 0, 139, 0}, + {"darkolivegreen", 85, 107, 47, 0}, + {"darkorange", 255, 140, 0, 0}, + {"darkorchid", 153, 50, 204, 0}, + {"darkred", 139, 0, 0, 0}, + {"darksalmon", 233, 150, 122, 0}, + {"darkseagreen", 143, 188, 143, 0}, + {"darkslateblue", 72, 61, 139, 0}, + {"darkslategray", 47, 79, 79, 0}, + {"darkslategrey", 47, 79, 79, 0}, + {"darkturquoise", 0, 206, 209, 0}, + {"darkviolet", 148, 0, 211, 0}, + {"deeppink", 255, 20, 147, 0}, + {"deepskyblue", 0, 191, 255, 0}, + {"dimgray", 105, 105, 105, 0}, + {"dimgrey", 105, 105, 105, 0}, + {"dodgerblue", 30, 144, 255, 0}, + {"firebrick", 178, 34, 34, 0}, + {"floralwhite", 255, 250, 240, 0}, + {"forestgreen", 34, 139, 34, 0}, + {"fuchsia", 255, 0, 255, 0}, + {"gainsboro", 220, 220, 220, 0}, + {"ghostwhite", 248, 248, 255, 0}, + {"gold", 255, 215, 0, 0}, + {"goldenrod", 218, 165, 32, 0}, + {"gray", 128, 128, 128, 0}, + {"grey", 128, 128, 128, 0}, + {"green", 0, 128, 0, 0}, + {"greenyellow", 173, 255, 47, 0}, + {"honeydew", 240, 255, 240, 0}, + {"hotpink", 255, 105, 180, 0}, + {"indianred", 205, 92, 92, 0}, + {"indigo", 75, 0, 130, 0}, + {"ivory", 255, 255, 240, 0}, + {"khaki", 240, 230, 140, 0}, + {"lavender", 230, 230, 250, 0}, + {"lavenderblush", 255, 240, 245, 0}, + {"lawngreen", 124, 252, 0, 0}, + {"lemonchiffon", 255, 250, 205, 0}, + {"lightblue", 173, 216, 230, 0}, + {"lightcoral", 240, 128, 128, 0}, + {"lightcyan", 224, 255, 255, 0}, + {"lightgoldenrodyellow", 250, 250, 210, 0}, + {"lightgray", 211, 211, 211, 0}, + {"lightgreen", 144, 238, 144, 0}, + {"lightgrey", 211, 211, 211, 0}, + {"lightpink", 255, 182, 193, 0}, + {"lightsalmon", 255, 160, 122, 0}, + {"lightseagreen", 32, 178, 170, 0}, + {"lightskyblue", 135, 206, 250, 0}, + {"lightslategray", 119, 136, 153, 0}, + {"lightslategrey", 119, 136, 153, 0}, + {"lightsteelblue", 176, 196, 222, 0}, + {"lightyellow", 255, 255, 224, 0}, + {"lime", 0, 255, 0, 0}, + {"limegreen", 50, 205, 50, 0}, + {"linen", 250, 240, 230, 0}, + {"magenta", 255, 0, 255, 0}, + {"maroon", 128, 0, 0, 0}, + {"mediumaquamarine", 102, 205, 170, 0}, + {"mediumblue", 0, 0, 205, 0}, + {"mediumorchid", 186, 85, 211, 0}, + {"mediumpurple", 147, 112, 219, 0}, + {"mediumseagreen", 60, 179, 113, 0}, + {"mediumslateblue", 123, 104, 238, 0}, + {"mediumspringgreen", 0, 250, 154, 0}, + {"mediumturquoise", 72, 209, 204, 0}, + {"mediumvioletred", 199, 21, 133, 0}, + {"midnightblue", 25, 25, 112, 0}, + {"mintcream", 245, 255, 250, 0}, + {"mistyrose", 255, 228, 225, 0}, + {"moccasin", 255, 228, 181, 0}, + {"navajowhite", 255, 222, 173, 0}, + {"navy", 0, 0, 128, 0}, + {"oldlace", 253, 245, 230, 0}, + {"olive", 128, 128, 0, 0}, + {"olivedrab", 107, 142, 35, 0}, + {"orange", 255, 165, 0, 0}, + {"orangered", 255, 69, 0, 0}, + {"orchid", 218, 112, 214, 0}, + {"palegoldenrod", 238, 232, 170, 0}, + {"palegreen", 152, 251, 152, 0}, + {"paleturquoise", 175, 238, 238, 0}, + {"palevioletred", 219, 112, 147, 0}, + {"papayawhip", 255, 239, 213, 0}, + {"peachpuff", 255, 218, 185, 0}, + {"peru", 205, 133, 63, 0}, + {"pink", 255, 192, 203, 0}, + {"plum", 221, 160, 221, 0}, + {"powderblue", 176, 224, 230, 0}, + {"purple", 128, 0, 128, 0}, + {"red", 255, 0, 0, 0}, + {"rosybrown", 188, 143, 143, 0}, + {"royalblue", 65, 105, 225, 0}, + {"saddlebrown", 139, 69, 19, 0}, + {"salmon", 250, 128, 114, 0}, + {"sandybrown", 244, 164, 96, 0}, + {"seagreen", 46, 139, 87, 0}, + {"seashell", 255, 245, 238, 0}, + {"sienna", 160, 82, 45, 0}, + {"silver", 192, 192, 192, 0}, + {"skyblue", 135, 206, 235, 0}, + {"slateblue", 106, 90, 205, 0}, + {"slategray", 112, 128, 144, 0}, + {"slategrey", 112, 128, 144, 0}, + {"snow", 255, 250, 250, 0}, + {"springgreen", 0, 255, 127, 0}, + {"steelblue", 70, 130, 180, 0}, + {"tan", 210, 180, 140, 0}, + {"teal", 0, 128, 128, 0}, + {"thistle", 216, 191, 216, 0}, + {"tomato", 255, 99, 71, 0}, + {"turquoise", 64, 224, 208, 0}, + {"violet", 238, 130, 238, 0}, + {"wheat", 245, 222, 179, 0}, + {"white", 255, 255, 255, 0}, + {"whitesmoke", 245, 245, 245, 0}, + {"yellow", 255, 255, 0, 0}, + {"yellowgreen", 154, 205, 50, 0} +}; /** *The default constructor of #CRRgb. @@ -186,21 +185,19 @@ static CRRgb gv_standard_colors[] = CRRgb * cr_rgb_new (void) { - CRRgb *result = NULL ; + CRRgb *result = NULL; - result = g_try_malloc (sizeof (CRRgb)) ; + result = g_try_malloc (sizeof (CRRgb)); - if (result == NULL) - { - cr_utils_trace_info ("No more memory") ; - return NULL ; + if (result == NULL) { + cr_utils_trace_info ("No more memory"); + return NULL; } - - memset (result, 0, sizeof (CRRgb)) ; - return result ; -} + memset (result, 0, sizeof (CRRgb)); + return result; +} /** *A constructor of #CRRgb. @@ -212,21 +209,21 @@ cr_rgb_new (void) *@return the newly built instance of #CRRgb. */ CRRgb * -cr_rgb_new_with_vals (gulong a_red, gulong a_green, +cr_rgb_new_with_vals (gulong a_red, gulong a_green, gulong a_blue, gboolean a_is_percentage) { - CRRgb *result = NULL ; - - result = cr_rgb_new () ; - - g_return_val_if_fail (result, NULL) ; - - result->red = a_red ; - result->green = a_green ; - result->blue = a_blue ; - result->is_percentage = a_is_percentage ; - - return result ; + CRRgb *result = NULL; + + result = cr_rgb_new (); + + g_return_val_if_fail (result, NULL); + + result->red = a_red; + result->green = a_green; + result->blue = a_blue; + result->is_percentage = a_is_percentage; + + return result; } /** @@ -236,46 +233,42 @@ cr_rgb_new_with_vals (gulong a_red, gulong a_green, *rgb. MUST BE FREED by the caller using g_free(). */ guchar * -cr_rgb_to_string (CRRgb *a_this) +cr_rgb_to_string (CRRgb * a_this) { - guchar *result = NULL ; - GString *str_buf = NULL ; + guchar *result = NULL; + GString *str_buf = NULL; - str_buf = g_string_new (NULL) ; - g_return_val_if_fail (str_buf, NULL) ; + str_buf = g_string_new (NULL); + g_return_val_if_fail (str_buf, NULL); - if (a_this->is_percentage == TRUE) - { - g_string_append_printf (str_buf, "%ld", a_this->red) ; + if (a_this->is_percentage == TRUE) { + g_string_append_printf (str_buf, "%ld", a_this->red); - g_string_append_c (str_buf, '%') ; - g_string_append_printf (str_buf,", ") ; - - g_string_append_printf (str_buf,"%ld", a_this->green) ; - g_string_append_c (str_buf, '%') ; ; - g_string_append_printf (str_buf,", ") ; + g_string_append_c (str_buf, '%'); + g_string_append_printf (str_buf, ", "); - g_string_append_printf (str_buf,"%ld", a_this->blue) ; - g_string_append_c (str_buf, '%') ; - } - else - { - g_string_append_printf (str_buf,"%ld", a_this->red) ; - g_string_append_printf (str_buf,", ") ; - - g_string_append_printf (str_buf,"%ld", a_this->green) ; - g_string_append_printf (str_buf,", ") ; - - g_string_append_printf (str_buf,"%ld", a_this->blue) ; + g_string_append_printf (str_buf, "%ld", a_this->green); + g_string_append_c (str_buf, '%');; + g_string_append_printf (str_buf, ", "); + + g_string_append_printf (str_buf, "%ld", a_this->blue); + g_string_append_c (str_buf, '%'); + } else { + g_string_append_printf (str_buf, "%ld", a_this->red); + g_string_append_printf (str_buf, ", "); + + g_string_append_printf (str_buf, "%ld", a_this->green); + g_string_append_printf (str_buf, ", "); + + g_string_append_printf (str_buf, "%ld", a_this->blue); } - if (str_buf) - { - result = str_buf->str ; - g_string_free (str_buf, FALSE) ; + if (str_buf) { + result = str_buf->str; + g_string_free (str_buf, FALSE); } - return result ; + return result; } /** @@ -286,19 +279,18 @@ cr_rgb_to_string (CRRgb *a_this) *@param a_fp the destination file pointer. */ void -cr_rgb_dump (CRRgb *a_this, FILE *a_fp) +cr_rgb_dump (CRRgb * a_this, FILE * a_fp) { - guchar *str = NULL ; + guchar *str = NULL; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - str = cr_rgb_to_string (a_this) ; + str = cr_rgb_to_string (a_this); - if (str) - { - fprintf (a_fp, "%s",str) ; - g_free (str) ; - str = NULL ; + if (str) { + fprintf (a_fp, "%s", str); + g_free (str); + str = NULL; } } @@ -309,17 +301,17 @@ cr_rgb_dump (CRRgb *a_this, FILE *a_fp) *@return */ enum CRStatus -cr_rgb_compute_from_percentage (CRRgb *a_this) +cr_rgb_compute_from_percentage (CRRgb * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); if (a_this->is_percentage == FALSE) - return CR_OK ; - a_this->red = a_this->red * 255 / 100 ; - a_this->green = a_this->green * 255 / 100 ; - a_this->blue = a_this->blue * 255 / 100 ; - a_this->is_percentage = FALSE ; - return CR_OK ; + return CR_OK; + a_this->red = a_this->red * 255 / 100; + a_this->green = a_this->green * 255 / 100; + a_this->blue = a_this->blue * 255 / 100; + a_this->is_percentage = FALSE; + return CR_OK; } /** @@ -332,26 +324,23 @@ cr_rgb_compute_from_percentage (CRRgb *a_this) *otherwise. */ enum CRStatus -cr_rgb_set (CRRgb *a_this, gulong a_red, - gulong a_green, gulong a_blue, - gboolean a_is_percentage) +cr_rgb_set (CRRgb * a_this, gulong a_red, + gulong a_green, gulong a_blue, gboolean a_is_percentage) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - if (a_is_percentage != FALSE) - { + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + if (a_is_percentage != FALSE) { g_return_val_if_fail (a_red <= 100 && a_green <= 100 - && a_blue <= 100, - CR_BAD_PARAM_ERROR) ; + && a_blue <= 100, CR_BAD_PARAM_ERROR); } - a_this->is_percentage = a_is_percentage ; + a_this->is_percentage = a_is_percentage; - a_this->red = a_red ; - a_this->green = a_green ; - a_this->blue = a_blue ; + a_this->red = a_red; + a_this->green = a_green; + a_this->blue = a_blue; - return CR_OK ; + return CR_OK; } /** @@ -361,118 +350,90 @@ cr_rgb_set (CRRgb *a_this, gulong a_red, *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_rgb_set_from_rgb (CRRgb *a_this, CRRgb *a_rgb) +cr_rgb_set_from_rgb (CRRgb * a_this, CRRgb * a_rgb) { - g_return_val_if_fail (a_this && a_rgb, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_rgb, CR_BAD_PARAM_ERROR); cr_rgb_set (a_this, a_rgb->red, a_rgb->green, - a_rgb->blue, a_rgb->is_percentage) ; + a_rgb->blue, a_rgb->is_percentage); - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_rgb_set_from_name (CRRgb *a_this, const guchar *a_color_name) +cr_rgb_set_from_name (CRRgb * a_this, const guchar * a_color_name) { - gulong i = 0 ; - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_this && a_color_name, CR_BAD_PARAM_ERROR) ; - - for (i = 0 ; i < sizeof (gv_standard_colors); i++) - { - if (!strcmp (a_color_name, gv_standard_colors[i].name)) - { - cr_rgb_set_from_rgb (a_this, &gv_standard_colors[i]) ; - break ; - } + gulong i = 0; + enum CRStatus status = CR_OK; + + g_return_val_if_fail (a_this && a_color_name, CR_BAD_PARAM_ERROR); + + for (i = 0; i < sizeof (gv_standard_colors); i++) { + if (!strcmp (a_color_name, gv_standard_colors[i].name)) { + cr_rgb_set_from_rgb (a_this, &gv_standard_colors[i]); + break; + } } if (i < sizeof (gv_standard_colors)) - status = CR_OK ; + status = CR_OK; else - status = CR_UNKNOWN_TYPE_ERROR ; + status = CR_UNKNOWN_TYPE_ERROR; - return status ; + return status; } enum CRStatus -cr_rgb_set_from_hex_str (CRRgb *a_this, const guchar * a_hex) +cr_rgb_set_from_hex_str (CRRgb * a_this, const guchar * a_hex) { - enum CRStatus status = CR_OK ; - gulong i = 0 ; - guchar colors[3] = {0} ; - - g_return_val_if_fail (a_this && a_hex, - CR_BAD_PARAM_ERROR) ; - - if (strlen (a_hex) == 3) - { - for (i = 0 ;i < 3 ; i++) - { - if (a_hex[i] >= '0' && a_hex[i] <= '9') - { + enum CRStatus status = CR_OK; + gulong i = 0; + guchar colors[3] = { 0 }; + + g_return_val_if_fail (a_this && a_hex, CR_BAD_PARAM_ERROR); + + if (strlen (a_hex) == 3) { + for (i = 0; i < 3; i++) { + if (a_hex[i] >= '0' && a_hex[i] <= '9') { colors[i] = a_hex[i] - '0'; - colors[i] = (colors[i] << 4) | colors[i] ; - } - else if (a_hex[i] >= 'a' && a_hex[i] <= 'z') - { + colors[i] = (colors[i] << 4) | colors[i]; + } else if (a_hex[i] >= 'a' && a_hex[i] <= 'z') { colors[i] = 10 + a_hex[i] - 'a'; - colors[i] = (colors[i] << 4) | colors[i] ; - } - else if (a_hex[i] >= 'A' && a_hex[i] <= 'Z') - { + colors[i] = (colors[i] << 4) | colors[i]; + } else if (a_hex[i] >= 'A' && a_hex[i] <= 'Z') { colors[i] = 10 + a_hex[i] - 'A'; - colors[i] = (colors[i] << 4) | colors[i] ; - } - else - { - status = CR_UNKNOWN_TYPE_ERROR ; + colors[i] = (colors[i] << 4) | colors[i]; + } else { + status = CR_UNKNOWN_TYPE_ERROR; } } - } - else if (strlen (a_hex) == 6) - { - for (i = 0 ; i < 6 ; i++) - { - if (a_hex[i] >='0' && a_hex[i] <= '9') - { - colors[i/2] <<= 4 ; - colors[i/2] |= a_hex[i] - '0'; - status = CR_OK ; - } - else if (a_hex[i] >= 'a' && a_hex[i] <= 'z') - { - colors[i/2] <<= 4 ; - colors[i/2] |= 10 + a_hex[i] - 'a'; - status = CR_OK ; - } - else if (a_hex[i] >= 'A' && a_hex[i] <= 'Z') - { - colors[i/2] <<= 4 ; - colors[i/2] |= 10 + a_hex[i] - 'A'; - status = CR_OK ; - } - else - { - status = CR_UNKNOWN_TYPE_ERROR ; + } else if (strlen (a_hex) == 6) { + for (i = 0; i < 6; i++) { + if (a_hex[i] >= '0' && a_hex[i] <= '9') { + colors[i / 2] <<= 4; + colors[i / 2] |= a_hex[i] - '0'; + status = CR_OK; + } else if (a_hex[i] >= 'a' && a_hex[i] <= 'z') { + colors[i / 2] <<= 4; + colors[i / 2] |= 10 + a_hex[i] - 'a'; + status = CR_OK; + } else if (a_hex[i] >= 'A' && a_hex[i] <= 'Z') { + colors[i / 2] <<= 4; + colors[i / 2] |= 10 + a_hex[i] - 'A'; + status = CR_OK; + } else { + status = CR_UNKNOWN_TYPE_ERROR; } } + } else { + status = CR_UNKNOWN_TYPE_ERROR; } - else - { - status = CR_UNKNOWN_TYPE_ERROR ; - } - - if (status == CR_OK) - { + + if (status == CR_OK) { status = cr_rgb_set (a_this, colors[0], - colors[1], colors[2], - FALSE) ; + colors[1], colors[2], FALSE); } - return status ; + return status; } /** @@ -481,9 +442,9 @@ cr_rgb_set_from_hex_str (CRRgb *a_this, const guchar * a_hex) *current instance of #CRRgb. */ void -cr_rgb_destroy (CRRgb *a_this) +cr_rgb_destroy (CRRgb * a_this) { - g_return_if_fail (a_this) ; - - g_free (a_this) ; + g_return_if_fail (a_this); + + g_free (a_this); } diff --git a/src/cr-sel-eng.c b/src/cr-sel-eng.c index 6ac2a65..3161adc 100644 --- a/src/cr-sel-eng.c +++ b/src/cr-sel-eng.c @@ -21,11 +21,9 @@ * See COPYRIGHTS file for copyright informations. */ - #include #include "cr-sel-eng.h" - /** *@file: *The definition of the #CRSelEng class. @@ -36,180 +34,171 @@ #define PRIVATE(a_this) (a_this)->priv -struct CRPseudoClassSelHandlerEntry -{ - guchar *name ; - enum CRPseudoType type ; - CRPseudoClassSelectorHandler handler ; -} ; +struct CRPseudoClassSelHandlerEntry { + guchar *name; + enum CRPseudoType type; + CRPseudoClassSelectorHandler handler; +}; -struct _CRSelEngPriv -{ - /*not used yet*/ - gboolean case_sensitive ; +struct _CRSelEngPriv { + /*not used yet */ + gboolean case_sensitive; - CRStyleSheet *sheet ; + CRStyleSheet *sheet; /** *where to store the next statement *to be visited so that we can remember *it from one method call to another. */ - CRStatement *cur_stmt ; - GList *pcs_handlers ; - gint pcs_handlers_size ; + CRStatement *cur_stmt; + GList *pcs_handlers; + gint pcs_handlers_size; }; -static gboolean class_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; +static gboolean class_add_sel_matches_node (CRAdditionalSel * a_add_sel, + xmlNode * a_node); -static gboolean id_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; +static gboolean id_add_sel_matches_node (CRAdditionalSel * a_add_sel, + xmlNode * a_node); -static gboolean attr_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; +static gboolean attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, + xmlNode * a_node); -static enum CRStatus sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, - xmlNode *a_node, gboolean *a_result, - gboolean a_recurse) ; +static enum CRStatus sel_matches_node_real (CRSelEng * a_this, + CRSimpleSel * a_sel, + xmlNode * a_node, + gboolean * a_result, + gboolean a_recurse); -static enum CRStatus cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, - CRStyleSheet *a_stylesheet, - xmlNode *a_node, - CRStatement **a_rulesets, - gulong *a_len) ; +static enum CRStatus cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this, + CRStyleSheet * + a_stylesheet, + xmlNode * a_node, + CRStatement ** + a_rulesets, + gulong * a_len); #ifndef NEW_PROPERTIES_GETTER -static enum CRStatus put_css_properties_in_hashtable (GHashTable **a_props_hashtable, - CRStatement *a_ruleset) ; -static void set_style_from_props_hash_hr_func (gpointer a_prop, gpointer a_decl, - gpointer a_style) ; +static enum CRStatus put_css_properties_in_hashtable (GHashTable ** + a_props_hashtable, + CRStatement * + a_ruleset); +static void set_style_from_props_hash_hr_func (gpointer a_prop, + gpointer a_decl, + gpointer a_style); #else -static enum CRStatus put_css_properties_in_props_list (CRPropList **a_props, - CRStatement *a_ruleset) ; +static enum CRStatus put_css_properties_in_props_list (CRPropList ** a_props, + CRStatement * + a_ruleset); #endif - - static gboolean pseudo_class_add_sel_matches_node (CRSelEng * a_this, - CRAdditionalSel *a_add_sel, - xmlNode *a_node) ; + CRAdditionalSel * + a_add_sel, + xmlNode * a_node); -static gboolean lang_pseudo_class_handler (CRSelEng *a_this, - CRAdditionalSel *a_sel, - xmlNode *a_node) ; +static gboolean lang_pseudo_class_handler (CRSelEng * a_this, + CRAdditionalSel * a_sel, + xmlNode * a_node); -static gboolean first_child_pseudo_class_handler (CRSelEng *a_this, - CRAdditionalSel *a_sel, - xmlNode *a_node) ; +static gboolean first_child_pseudo_class_handler (CRSelEng * a_this, + CRAdditionalSel * a_sel, + xmlNode * a_node); -static xmlNode * get_next_element_node (xmlNode *a_node) ; +static xmlNode *get_next_element_node (xmlNode * a_node); -static xmlNode * get_next_child_element_node (xmlNode *a_node) ; +static xmlNode *get_next_child_element_node (xmlNode * a_node); -static xmlNode * get_prev_element_node (xmlNode *a_node) ; +static xmlNode *get_prev_element_node (xmlNode * a_node); -static xmlNode * get_next_parent_element_node (xmlNode *a_node) ; +static xmlNode *get_next_parent_element_node (xmlNode * a_node); -static gboolean -lang_pseudo_class_handler (CRSelEng *a_this, - CRAdditionalSel *a_sel, - xmlNode *a_node) +static gboolean +lang_pseudo_class_handler (CRSelEng * a_this, + CRAdditionalSel * a_sel, xmlNode * a_node) { - xmlNode *node = a_node ; - xmlChar *val = NULL; - gboolean result = FALSE ; + xmlNode *node = a_node; + xmlChar *val = NULL; + gboolean result = FALSE; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_sel && a_sel->content.pseudo && a_sel->content.pseudo && a_sel->content.pseudo->name - && a_node, - CR_BAD_PARAM_ERROR) ; - - if (strncmp (a_sel->content.pseudo->name->str, - "lang", 4) - || !a_sel->content.pseudo->type == FUNCTION_PSEUDO) - { - cr_utils_trace_info - ("This handler is for :lang only") ; - return CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR ; + && a_node, CR_BAD_PARAM_ERROR); + + if (strncmp (a_sel->content.pseudo->name->str, "lang", 4) + || !a_sel->content.pseudo->type == FUNCTION_PSEUDO) { + cr_utils_trace_info ("This handler is for :lang only"); + return CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR; } - /*lang code should exist and be at least of length 2*/ - if (!a_sel->content.pseudo->extra || a_sel->content.pseudo->extra->len < 2) - return FALSE ; - for (;node;node = get_next_parent_element_node (node)) - { - val = xmlGetProp (node, "lang"); - if (val - && !strncmp (val, - a_sel->content.pseudo->extra->str, - a_sel->content.pseudo->extra->len)) - { - result = TRUE ; + /*lang code should exist and be at least of length 2 */ + if (!a_sel->content.pseudo->extra + || a_sel->content.pseudo->extra->len < 2) + return FALSE; + for (; node; node = get_next_parent_element_node (node)) { + val = xmlGetProp (node, "lang"); + if (val + && !strncmp (val, + a_sel->content.pseudo->extra->str, + a_sel->content.pseudo->extra->len)) { + result = TRUE; } - } - if (val) - { - xmlFree (val) ; - val = NULL ; } - return result ; + if (val) { + xmlFree (val); + val = NULL; + } + return result; } -static gboolean -first_child_pseudo_class_handler (CRSelEng *a_this, - CRAdditionalSel *a_sel, - xmlNode *a_node) +static gboolean +first_child_pseudo_class_handler (CRSelEng * a_this, + CRAdditionalSel * a_sel, xmlNode * a_node) { - xmlNode *node = NULL ; + xmlNode *node = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_sel && a_sel->content.pseudo && a_sel->content.pseudo && a_sel->content.pseudo->name - && a_node, - CR_BAD_PARAM_ERROR) ; - - if (strcmp (a_sel->content.pseudo->name->str, - "first-child") - || !a_sel->content.pseudo->type == IDENT_PSEUDO) - { - cr_utils_trace_info - ("This handler is for :first-child only") ; - return CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR ; + && a_node, CR_BAD_PARAM_ERROR); + + if (strcmp (a_sel->content.pseudo->name->str, "first-child") + || !a_sel->content.pseudo->type == IDENT_PSEUDO) { + cr_utils_trace_info ("This handler is for :first-child only"); + return CR_BAD_PSEUDO_CLASS_SEL_HANDLER_ERROR; } if (!a_node->parent) - return FALSE ; - node = get_next_child_element_node (a_node->parent) ; + return FALSE; + node = get_next_child_element_node (a_node->parent); if (node == a_node) - return TRUE ; - return FALSE ; + return TRUE; + return FALSE; } static gboolean pseudo_class_add_sel_matches_node (CRSelEng * a_this, - CRAdditionalSel *a_add_sel, - xmlNode *a_node) + CRAdditionalSel * a_add_sel, + xmlNode * a_node) { - enum CRStatus status = CR_OK ; - CRPseudoClassSelectorHandler handler = NULL ; - + enum CRStatus status = CR_OK; + CRPseudoClassSelectorHandler handler = NULL; + g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_add_sel + && a_add_sel && a_add_sel->content.pseudo && a_add_sel->content.pseudo->name && a_add_sel->content.pseudo->name->str - && a_node, - CR_BAD_PARAM_ERROR) ; + && a_node, CR_BAD_PARAM_ERROR); status = cr_sel_eng_get_pseudo_class_selector_handler (a_this, a_add_sel->content.pseudo->name->str, - a_add_sel->content.pseudo->type, - &handler) ; + a_add_sel->content.pseudo->type, &handler); if (status != CR_OK || !handler) - return FALSE ; + return FALSE; - return handler (a_this, a_add_sel, a_node) ; + return handler (a_this, a_add_sel, a_node); } /** @@ -219,44 +208,41 @@ pseudo_class_add_sel_matches_node (CRSelEng * a_this, *the xml node given in argument, FALSE otherwise. */ static gboolean -class_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) +class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) { - gboolean result = FALSE ; - xmlChar *klass = NULL, *cur = NULL ; + gboolean result = FALSE; + xmlChar *klass = NULL, + *cur = NULL; g_return_val_if_fail (a_add_sel && a_add_sel->type == CLASS_ADD_SELECTOR && a_add_sel->content.class_name && a_add_sel->content.class_name->str - && a_node, FALSE) ; + && a_node, FALSE); - if (xmlHasProp (a_node, "class")) - { - klass = xmlGetProp (a_node, "class") ; - for (cur = klass ; *cur ; cur++) - { + if (xmlHasProp (a_node, "class")) { + klass = xmlGetProp (a_node, "class"); + for (cur = klass; *cur; cur++) { while (cr_utils_is_white_space (*cur) == TRUE && *cur) - cur ++ ; + cur++; if (!*cur) - break ; + break; if (!strncmp (cur, a_add_sel->content.class_name->str, - a_add_sel->content.class_name->len)) - { + a_add_sel->content.class_name->len)) { cur += a_add_sel->content.class_name->len; - if (!*cur || cr_utils_is_white_space (*cur) == TRUE) - result = TRUE ; + if (!*cur + || cr_utils_is_white_space (*cur) == TRUE) + result = TRUE; } } } - if (klass) - { - xmlFree (klass) ; - klass = NULL ; + if (klass) { + xmlFree (klass); + klass = NULL; } - return result ; - + return result; + } /** @@ -266,37 +252,33 @@ class_add_sel_matches_node (CRAdditionalSel *a_add_sel, *@param a_node the xml node to consider. */ static gboolean -id_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) +id_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) { - gboolean result = FALSE ; - xmlChar *id = NULL ; + gboolean result = FALSE; + xmlChar *id = NULL; - g_return_val_if_fail (a_add_sel + g_return_val_if_fail (a_add_sel && a_add_sel->type == ID_ADD_SELECTOR && a_add_sel->content.id_name && a_add_sel->content.id_name->str - && a_node, FALSE) ; + && a_node, FALSE); g_return_val_if_fail (a_add_sel && a_add_sel->type == ID_ADD_SELECTOR - && a_node, FALSE) ; + && a_node, FALSE); - if (xmlHasProp (a_node, "id")) - { - id = xmlGetProp (a_node, "id") ; + if (xmlHasProp (a_node, "id")) { + id = xmlGetProp (a_node, "id"); if (!strncmp (id, a_add_sel->content.id_name->str, - a_add_sel->content.id_name->len)) - { - result = TRUE ; + a_add_sel->content.id_name->len)) { + result = TRUE; } } - if (id) - { - xmlFree (id) ; - id = NULL ; + if (id) { + xmlFree (id); + id = NULL; } - return result ; + return result; } /** @@ -309,162 +291,163 @@ id_add_sel_matches_node (CRAdditionalSel *a_add_sel, *FALSE otherwise. */ static gboolean -attr_add_sel_matches_node (CRAdditionalSel *a_add_sel, - xmlNode *a_node) -{ - CRAttrSel *cur_sel = NULL ; +attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node) +{ + CRAttrSel *cur_sel = NULL; - g_return_val_if_fail (a_add_sel + g_return_val_if_fail (a_add_sel && a_add_sel->type == ATTRIBUTE_ADD_SELECTOR - && a_node, FALSE) ; - - for (cur_sel = a_add_sel->content.attr_sel ; - cur_sel ; cur_sel = cur_sel->next) - { - switch (cur_sel->match_way) - { + && a_node, FALSE); + + for (cur_sel = a_add_sel->content.attr_sel; + cur_sel; cur_sel = cur_sel->next) { + switch (cur_sel->match_way) { case SET: if (!cur_sel->name || !cur_sel->name->str) - return FALSE ; + return FALSE; if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - break ; + return FALSE; + break; case EQUALS: - { - xmlChar *value = NULL ; + { + xmlChar *value = NULL; - if (!cur_sel->name || !cur_sel->name->str - || !cur_sel->value || !cur_sel->value->str) - return FALSE ; + if (!cur_sel->name || !cur_sel->name->str + || !cur_sel->value + || !cur_sel->value->str) + return FALSE; - if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - - value = xmlGetProp (a_node, cur_sel->name->str) ; + if (!xmlHasProp (a_node, cur_sel->name->str)) + return FALSE; - if (value && strncmp (value, cur_sel->value->str, - cur_sel->value->len)) - { - xmlFree (value) ; - return FALSE ; + value = xmlGetProp (a_node, + cur_sel->name->str); + + if (value + && strncmp (value, cur_sel->value->str, + cur_sel->value->len)) { + xmlFree (value); + return FALSE; + } + xmlFree (value); } - xmlFree (value); - } - break ; + break; case INCLUDES: - { - xmlChar *value = NULL, *ptr1 = NULL, *ptr2 = NULL, - *cur = NULL; - gboolean found = FALSE ; - - if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - value = xmlGetProp (a_node, cur_sel->name->str) ; - - if (!value) - return FALSE; - - /* - *here, make sure value is a space - *separated list of "words", where one - *value is exactly cur_sel->value->str - */ - for (cur = value ; *cur ; cur++) { - /* - *set ptr1 to the first non white space - *char addr. - */ - while (cr_utils_is_white_space - (*cur) == TRUE && *cur) - cur ++ ; - if (!*cur) - break ; - ptr1 = cur ; + xmlChar *value = NULL, + *ptr1 = NULL, + *ptr2 = NULL, + *cur = NULL; + gboolean found = FALSE; + + if (!xmlHasProp (a_node, cur_sel->name->str)) + return FALSE; + value = xmlGetProp (a_node, + cur_sel->name->str); + + if (!value) + return FALSE; /* - *set ptr2 to the end the word. + *here, make sure value is a space + *separated list of "words", where one + *value is exactly cur_sel->value->str */ - while (cr_utils_is_white_space - (*cur) == FALSE && *cur) - cur++ ; - if (!*cur) - break ; - cur-- ; - ptr2 = cur ; - - if (!strncmp (ptr1, cur_sel->value->str, - ptr2 - ptr1 + 1)) - { - found = TRUE ; - break ; + for (cur = value; *cur; cur++) { + /* + *set ptr1 to the first non white space + *char addr. + */ + while (cr_utils_is_white_space + (*cur) == TRUE && *cur) + cur++; + if (!*cur) + break; + ptr1 = cur; + + /* + *set ptr2 to the end the word. + */ + while (cr_utils_is_white_space + (*cur) == FALSE && *cur) + cur++; + if (!*cur) + break; + cur--; + ptr2 = cur; + + if (!strncmp + (ptr1, cur_sel->value->str, + ptr2 - ptr1 + 1)) { + found = TRUE; + break; + } + ptr1 = ptr2 = NULL; } - ptr1 = ptr2 = NULL ; - } - if (found == FALSE) - { - xmlFree (value) ; - return FALSE ; + if (found == FALSE) { + xmlFree (value); + return FALSE; + } + xmlFree (value); } - xmlFree (value) ; - } - break ; + break; case DASHMATCH: - { - xmlChar *value = NULL, *ptr1 = NULL, *ptr2 = NULL, - *cur = NULL; - gboolean found = FALSE ; - - if (!xmlHasProp (a_node, cur_sel->name->str)) - return FALSE ; - value = xmlGetProp (a_node, cur_sel->name->str) ; - - /* - *here, make sure value is an hyphen - *separated list of "words", each of which - *starting with "cur_sel->value->str" - */ - for (cur = value ; *cur ; cur++) { - if (*cur == '-') - cur ++ ; - ptr1 = cur ; - - while (*cur != '-' && *cur) - cur ++ ; - if (!*cur) - break ; - cur-- ; - ptr2 = cur ; - - if (g_strstr_len (ptr1, ptr2 - ptr1 + 1, - cur_sel->value->str) - == (gchar*)ptr1) - { - found = TRUE ; - break ; + xmlChar *value = NULL, + *ptr1 = NULL, + *ptr2 = NULL, + *cur = NULL; + gboolean found = FALSE; + + if (!xmlHasProp (a_node, cur_sel->name->str)) + return FALSE; + value = xmlGetProp (a_node, + cur_sel->name->str); + + /* + *here, make sure value is an hyphen + *separated list of "words", each of which + *starting with "cur_sel->value->str" + */ + for (cur = value; *cur; cur++) { + if (*cur == '-') + cur++; + ptr1 = cur; + + while (*cur != '-' && *cur) + cur++; + if (!*cur) + break; + cur--; + ptr2 = cur; + + if (g_strstr_len + (ptr1, ptr2 - ptr1 + 1, + cur_sel->value->str) + == (gchar *) ptr1) { + found = TRUE; + break; + } } - } - if (found == FALSE) - { - xmlFree (value) ; - return FALSE ; + if (found == FALSE) { + xmlFree (value); + return FALSE; + } + xmlFree (value); } - xmlFree (value) ; - } - break ; + break; default: - return FALSE ; + return FALSE; } } - return TRUE ; + return TRUE; } /** @@ -474,128 +457,110 @@ attr_add_sel_matches_node (CRAdditionalSel *a_add_sel, *@return TRUE is a_add_sel matches a_node, FALSE otherwise. */ static gboolean -additional_selector_matches_node (CRSelEng *a_this, - CRAdditionalSel *a_add_sel, - xmlNode *a_node) +additional_selector_matches_node (CRSelEng * a_this, + CRAdditionalSel * a_add_sel, + xmlNode * a_node) { - if (!a_add_sel) - { - return FALSE ; + if (!a_add_sel) { + return FALSE; } - if (a_add_sel->type == NO_ADD_SELECTOR) - { - return FALSE ; + if (a_add_sel->type == NO_ADD_SELECTOR) { + return FALSE; } - + if (a_add_sel->type == CLASS_ADD_SELECTOR && a_add_sel->content.class_name - && a_add_sel->content.class_name->str) - { - if (class_add_sel_matches_node - (a_add_sel, a_node) == FALSE) - { - return FALSE ; + && a_add_sel->content.class_name->str) { + if (class_add_sel_matches_node (a_add_sel, a_node) == FALSE) { + return FALSE; } - return TRUE ; - } - else if (a_add_sel->type == ID_ADD_SELECTOR - && a_add_sel->content.id_name - && a_add_sel->content.id_name->str) - { - if (id_add_sel_matches_node - (a_add_sel, a_node) == FALSE) - { - return FALSE ; + return TRUE; + } else if (a_add_sel->type == ID_ADD_SELECTOR + && a_add_sel->content.id_name + && a_add_sel->content.id_name->str) { + if (id_add_sel_matches_node (a_add_sel, a_node) == FALSE) { + return FALSE; } - return TRUE ; - } - else if (a_add_sel->type == ATTRIBUTE_ADD_SELECTOR - && a_add_sel->content.attr_sel) - { + return TRUE; + } else if (a_add_sel->type == ATTRIBUTE_ADD_SELECTOR + && a_add_sel->content.attr_sel) { /* *here, call a function that does the match *against an attribute additionnal selector *and an xml node. */ - if (attr_add_sel_matches_node - (a_add_sel, a_node) - == FALSE) - { - return FALSE ; + if (attr_add_sel_matches_node (a_add_sel, a_node) + == FALSE) { + return FALSE; } - return TRUE ; + return TRUE; } else if (a_add_sel->type == PSEUDO_CLASS_ADD_SELECTOR - && a_add_sel->content.pseudo) - { - if (pseudo_class_add_sel_matches_node - (a_this, a_add_sel, a_node) == TRUE) - { - return TRUE ; + && a_add_sel->content.pseudo) { + if (pseudo_class_add_sel_matches_node + (a_this, a_add_sel, a_node) == TRUE) { + return TRUE; } - return FALSE ; + return FALSE; } - return FALSE ; + return FALSE; } static xmlNode * -get_next_element_node (xmlNode *a_node) +get_next_element_node (xmlNode * a_node) { - xmlNode *cur_node = NULL ; + xmlNode *cur_node = NULL; - g_return_val_if_fail (a_node, NULL) ; + g_return_val_if_fail (a_node, NULL); - cur_node = a_node->next ; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) - { - cur_node = cur_node->next ; + cur_node = a_node->next; + while (cur_node && cur_node->type != XML_ELEMENT_NODE) { + cur_node = cur_node->next; } - return cur_node ; + return cur_node; } static xmlNode * -get_next_child_element_node (xmlNode *a_node) +get_next_child_element_node (xmlNode * a_node) { - xmlNode *cur_node = NULL ; + xmlNode *cur_node = NULL; - g_return_val_if_fail (a_node, NULL) ; - - cur_node = a_node->children ; + g_return_val_if_fail (a_node, NULL); + + cur_node = a_node->children; if (!cur_node) - return cur_node ; + return cur_node; if (a_node->children->type == XML_ELEMENT_NODE) - return a_node->children ; - return get_next_element_node (a_node->children) ; + return a_node->children; + return get_next_element_node (a_node->children); } static xmlNode * -get_prev_element_node (xmlNode *a_node) +get_prev_element_node (xmlNode * a_node) { - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_node, NULL) ; - - cur_node = a_node->prev ; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) - { - cur_node = cur_node->prev ; + xmlNode *cur_node = NULL; + + g_return_val_if_fail (a_node, NULL); + + cur_node = a_node->prev; + while (cur_node && cur_node->type != XML_ELEMENT_NODE) { + cur_node = cur_node->prev; } - return cur_node ; + return cur_node; } static xmlNode * -get_next_parent_element_node (xmlNode *a_node) +get_next_parent_element_node (xmlNode * a_node) { - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_node, NULL) ; - - cur_node = a_node->parent ; - while (cur_node && cur_node->type != XML_ELEMENT_NODE) - { - cur_node = cur_node->parent ; + xmlNode *cur_node = NULL; + + g_return_val_if_fail (a_node, NULL); + + cur_node = a_node->parent; + while (cur_node && cur_node->type != XML_ELEMENT_NODE) { + cur_node = cur_node->parent; } - return cur_node ; + return cur_node; } /** @@ -617,49 +582,37 @@ get_next_parent_element_node (xmlNode *a_node) *know what you are doing. */ static enum CRStatus -sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, - xmlNode *a_node, gboolean *a_result, +sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel, + xmlNode * a_node, gboolean * a_result, gboolean a_recurse) { - CRSimpleSel *cur_sel = NULL ; - xmlNode *cur_node = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_this && a_node - && a_result, - CR_BAD_PARAM_ERROR) ; + CRSimpleSel *cur_sel = NULL; + xmlNode *cur_node = NULL; - *a_result = FALSE ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_this && a_node + && a_result, CR_BAD_PARAM_ERROR); + + *a_result = FALSE; if (a_node->type != XML_ELEMENT_NODE) - return CR_OK ; - - - if (a_recurse == TRUE) - { - /*go and get the last simple selector of the list*/ - for (cur_sel = a_sel ; - cur_sel && cur_sel->next ; - cur_sel = cur_sel->next) ; + return CR_OK; + + if (a_recurse == TRUE) { + /*go and get the last simple selector of the list */ + for (cur_sel = a_sel; + cur_sel && cur_sel->next; cur_sel = cur_sel->next) ; + } else { + cur_sel = a_sel; } - else - { - cur_sel = a_sel ; - } - - for (cur_node = a_node ; cur_sel ; cur_sel = cur_sel->prev) - { - if (cur_sel->type_mask & UNIVERSAL_SELECTOR) - { - goto walk_a_step_in_expr ; - } - else if (cur_sel->type_mask & TYPE_SELECTOR) - { - if (cur_sel && cur_sel->name && cur_sel->name->str) - { - if (!strcmp (cur_sel->name->str, - cur_node->name)) - { + + for (cur_node = a_node; cur_sel; cur_sel = cur_sel->prev) { + if (cur_sel->type_mask & UNIVERSAL_SELECTOR) { + goto walk_a_step_in_expr; + } else if (cur_sel->type_mask & TYPE_SELECTOR) { + if (cur_sel && cur_sel->name && cur_sel->name->str) { + if (!strcmp (cur_sel->name->str, + cur_node->name)) { /* *this simple selector *matches the current xml node @@ -668,130 +621,116 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, *their xml node counterpart. */ if (cur_sel->add_sel) { - if (additional_selector_matches_node - (a_this, cur_sel->add_sel, cur_node) == TRUE) - { - goto walk_a_step_in_expr ; + if (additional_selector_matches_node (a_this, cur_sel->add_sel, cur_node) == TRUE) { + goto walk_a_step_in_expr; } else { - goto done ; + goto done; } } else { - goto walk_a_step_in_expr ; + goto walk_a_step_in_expr; } - } - goto done ; - } - else - { - goto done ; - } - } - - if (!cur_sel->add_sel) - { - goto done ; + } + goto done; + } else { + goto done; + } } - if (additional_selector_matches_node - (a_this, cur_sel->add_sel, cur_node) == TRUE) - { - goto walk_a_step_in_expr ; + + if (!cur_sel->add_sel) { + goto done; + } + if (additional_selector_matches_node + (a_this, cur_sel->add_sel, cur_node) == TRUE) { + goto walk_a_step_in_expr; } else { - goto done ; + goto done; } - walk_a_step_in_expr: - if (a_recurse == FALSE) - { - *a_result = TRUE ; - goto done ; + walk_a_step_in_expr: + if (a_recurse == FALSE) { + *a_result = TRUE; + goto done; } /* - *here, depending on the combinator of cur_sel - *choose the axis of the xml tree traversal - *and walk one step in the xml tree. - */ + *here, depending on the combinator of cur_sel + *choose the axis of the xml tree traversal + *and walk one step in the xml tree. + */ if (!cur_sel->prev) - break ; + break; - switch (cur_sel->combinator) - { + switch (cur_sel->combinator) { case NO_COMBINATOR: - break ; - - case COMB_WS:/*descendant selector*/ - { - xmlNode *n = NULL ; - enum CRStatus status = CR_OK ; - gboolean matches= FALSE ; + break; - /* - *walk the xml tree upward looking for a parent - *node that matches the preceding selector. - */ - for (n = cur_node->parent ; n ; n = n->parent) + case COMB_WS: /*descendant selector */ { - status = - sel_matches_node_real - (a_this, cur_sel->prev, - n, &matches, FALSE) ; - if (status != CR_OK) - goto done ; - if (matches == TRUE) - { - cur_node = n ; - break ; + xmlNode *n = NULL; + enum CRStatus status = CR_OK; + gboolean matches = FALSE; + + /* + *walk the xml tree upward looking for a parent + *node that matches the preceding selector. + */ + for (n = cur_node->parent; n; n = n->parent) { + status = sel_matches_node_real + (a_this, cur_sel->prev, + n, &matches, FALSE); + if (status != CR_OK) + goto done; + if (matches == TRUE) { + cur_node = n; + break; + } } - } - if (!n) - { + if (!n) { + /* + *didn't find any ancestor that matches + *the previous simple selector. + */ + goto done; + } /* - *didn't find any ancestor that matches - *the previous simple selector. + *in this case, the preceding simple sel + *will have been interpreted twice, which + *is a cpu and mem waste ... I need to find + *another way to do this. Anyway, this is + *my first attempt to write this function and + *I am a bit clueless. */ - goto done ; + break; } - /* - *in this case, the preceding simple sel - *will have been interpreted twice, which - *is a cpu and mem waste ... I need to find - *another way to do this. Anyway, this is - *my first attempt to write this function and - *I am a bit clueless. - */ - break ; - } case COMB_PLUS: cur_node = get_prev_element_node (cur_node); if (!cur_node) - goto done ; - break ; + goto done; + break; case COMB_GT: - cur_node = get_next_parent_element_node - (cur_node) ; + cur_node = get_next_parent_element_node (cur_node); if (!cur_node) - goto done ; - break ; + goto done; + break; default: - goto done ; + goto done; } - continue ; - } + continue; + } /* *if we reached this point, it means the selector matches *the xml node. */ - *a_result = TRUE ; - - done: - return CR_OK ; -} + *a_result = TRUE; + done: + return CR_OK; +} /** *Returns array of the ruleset statements that matches the @@ -831,39 +770,36 @@ sel_matches_node_real (CRSelEng *a_this, CRSimpleSel *a_sel, *@return CR_ERROR if any other error occured. */ static enum CRStatus -cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, - CRStyleSheet *a_stylesheet, - xmlNode *a_node, - CRStatement **a_rulesets, - gulong *a_len) +cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this, + CRStyleSheet * a_stylesheet, + xmlNode * a_node, + CRStatement ** a_rulesets, + gulong * a_len) { - CRStatement *cur_stmt = NULL ; - CRSelector *sel_list = NULL, *cur_sel = NULL ; - gboolean matches = FALSE ; - enum CRStatus status = CR_OK ; + CRStatement *cur_stmt = NULL; + CRSelector *sel_list = NULL, + *cur_sel = NULL; + gboolean matches = FALSE; + enum CRStatus status = CR_OK; gulong i = 0; g_return_val_if_fail (a_this && a_stylesheet - && a_node - && a_rulesets, - CR_BAD_PARAM_ERROR) ; - - if (!a_stylesheet->statements) - { - *a_rulesets = NULL ; - *a_len = 0 ; - return CR_OK ; + && a_node && a_rulesets, CR_BAD_PARAM_ERROR); + + if (!a_stylesheet->statements) { + *a_rulesets = NULL; + *a_len = 0; + return CR_OK; } /* *if this stylesheet is "new one" *let's remember it for subsequent calls. */ - if (PRIVATE (a_this)->sheet != a_stylesheet) - { - PRIVATE (a_this)->sheet = a_stylesheet ; - PRIVATE (a_this)->cur_stmt = a_stylesheet->statements ; + if (PRIVATE (a_this)->sheet != a_stylesheet) { + PRIVATE (a_this)->sheet = a_stylesheet; + PRIVATE (a_this)->cur_stmt = a_stylesheet->statements; } /* @@ -872,83 +808,76 @@ cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, *contain some, and try to match our xml node in these *selectors lists. */ - for (cur_stmt = PRIVATE (a_this)->cur_stmt, i = 0 ; - (PRIVATE (a_this)->cur_stmt = cur_stmt); - cur_stmt = cur_stmt->next) - { + for (cur_stmt = PRIVATE (a_this)->cur_stmt, i = 0; + (PRIVATE (a_this)->cur_stmt = cur_stmt); + cur_stmt = cur_stmt->next) { /* *initialyze the selector list in which we will *really perform the search. */ - sel_list = NULL ; + sel_list = NULL; /* *get the the damn selector list in *which we have to look */ - switch (cur_stmt->type) - { + switch (cur_stmt->type) { case RULESET_STMT: - if (cur_stmt->kind.ruleset - && cur_stmt->kind.ruleset->sel_list) - { - sel_list = cur_stmt->kind.ruleset->sel_list ; + if (cur_stmt->kind.ruleset + && cur_stmt->kind.ruleset->sel_list) { + sel_list = cur_stmt->kind.ruleset->sel_list; } - break ; + break; case AT_MEDIA_RULE_STMT: if (cur_stmt->kind.media_rule && cur_stmt->kind.media_rule->rulesets && cur_stmt->kind.media_rule->rulesets-> kind.ruleset - &&cur_stmt->kind.media_rule->rulesets-> - kind.ruleset->sel_list) - { - sel_list = + && cur_stmt->kind.media_rule->rulesets-> + kind.ruleset->sel_list) { + sel_list = cur_stmt->kind.media_rule-> - rulesets->kind.ruleset->sel_list ; + rulesets->kind.ruleset->sel_list; } - break ; + break; case AT_IMPORT_RULE_STMT: /* *some recursivity may be needed here. *I don't like this :( */ - break ; + break; default: - break ; + break; } if (!sel_list) - continue ; + continue; /* *now, we have a comma separated selector list to look in. *let's walk it and try to match the xml_node *on each item of the list. */ - for (cur_sel = sel_list ; cur_sel ; cur_sel = cur_sel->next) - { + for (cur_sel = sel_list; cur_sel; cur_sel = cur_sel->next) { if (!cur_sel->simple_sel) - continue ; + continue; - status = cr_sel_eng_matches_node + status = cr_sel_eng_matches_node (a_this, cur_sel->simple_sel, - a_node, &matches) ; + a_node, &matches); - if (status == CR_OK && matches == TRUE) - { + if (status == CR_OK && matches == TRUE) { /* *bingo!!! we found one ruleset that *matches that fucking node. *lets put it in the out array. */ - if (i < *a_len) - { - a_rulesets[i] = cur_stmt ; - i++ ; + if (i < *a_len) { + a_rulesets[i] = cur_stmt; + i++; /* *For the cascade computing algorithm @@ -959,20 +888,17 @@ cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, *and store it in the css2 statement *(statement == ruleset here). */ - status = - cr_simple_sel_compute_specificity - (cur_sel->simple_sel) ; + status = cr_simple_sel_compute_specificity (cur_sel->simple_sel); g_return_val_if_fail (status == CR_OK, - CR_ERROR) ; - cur_stmt->specificity = - cur_sel->simple_sel->specificity; - } - else - + CR_ERROR); + cur_stmt->specificity = + cur_sel->simple_sel-> + specificity; + } else { - *a_len = i ; - return CR_OUTPUT_TOO_SHORT_ERROR ; + *a_len = i; + return CR_OUTPUT_TOO_SHORT_ERROR; } } } @@ -984,13 +910,12 @@ cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, *no need to store any info about the stylesheet *anymore. */ - g_return_val_if_fail (!PRIVATE (a_this)->cur_stmt, CR_ERROR) ; - PRIVATE (a_this)->sheet = NULL ; - *a_len = i ; - return CR_OK ; + g_return_val_if_fail (!PRIVATE (a_this)->cur_stmt, CR_ERROR); + PRIVATE (a_this)->sheet = NULL; + *a_len = i; + return CR_OK; } - #ifndef NEW_PROPERTIES_GETTER /** *Walks through the property/value pairs of a ruleset @@ -1010,31 +935,28 @@ cr_sel_eng_get_matched_rulesets_real (CRSelEng *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -put_css_properties_in_hashtable (GHashTable **a_props_hashtable, - CRStatement *a_stmt) +put_css_properties_in_hashtable (GHashTable ** a_props_hashtable, + CRStatement * a_stmt) { - GHashTable *props_hash = NULL ; - CRDeclaration *cur_decl = NULL ; + GHashTable *props_hash = NULL; + CRDeclaration *cur_decl = NULL; g_return_val_if_fail (a_props_hashtable && a_stmt && a_stmt->type == RULESET_STMT - && a_stmt->kind.ruleset, - CR_BAD_PARAM_ERROR) ; + && a_stmt->kind.ruleset, CR_BAD_PARAM_ERROR); - if (!*a_props_hashtable) - { + if (!*a_props_hashtable) { *a_props_hashtable = g_hash_table_new (g_str_hash, - g_str_equal) ; + g_str_equal); } - props_hash = *a_props_hashtable ; + props_hash = *a_props_hashtable; + + for (cur_decl = a_stmt->kind.ruleset->decl_list; + cur_decl; cur_decl = cur_decl->next) { + CRDeclaration *decl = NULL; - for (cur_decl = a_stmt->kind.ruleset->decl_list ; - cur_decl ; cur_decl = cur_decl->next) - { - CRDeclaration *decl = NULL ; - if (!cur_decl->property || !cur_decl->property->str) - continue ; + continue; /* *First, test if the property is not @@ -1043,16 +965,14 @@ put_css_properties_in_hashtable (GHashTable **a_props_hashtable, *compute the precedence. If not, insert *the property into the hashtable. */ - decl = g_hash_table_lookup - (props_hash, cur_decl->property->str) ; + decl = g_hash_table_lookup + (props_hash, cur_decl->property->str); - if (!decl) - { - g_hash_table_replace + if (!decl) { + g_hash_table_replace (props_hash, - cur_decl->property->str, - cur_decl) ; - continue ; + cur_decl->property->str, cur_decl); + continue; } /* @@ -1070,27 +990,21 @@ put_css_properties_in_hashtable (GHashTable **a_props_hashtable, *style sheets which override *the default style sheet." */ - if (decl->parent_statement + if (decl->parent_statement && decl->parent_statement->parent_sheet - && (decl->parent_statement->parent_sheet->origin - < - a_stmt->parent_sheet->origin)) - { - g_hash_table_insert + && (decl->parent_statement->parent_sheet->origin + < a_stmt->parent_sheet->origin)) { + g_hash_table_insert (props_hash, - cur_decl->property->str, - cur_decl) ; - continue ; - } - else if (decl->parent_statement - && decl->parent_statement->parent_sheet - && (decl->parent_statement-> - parent_sheet->origin - > - a_stmt->parent_sheet->origin)) - { - /*TODO: support !important rule.*/ - continue ; + cur_decl->property->str, cur_decl); + continue; + } else if (decl->parent_statement + && decl->parent_statement->parent_sheet + && (decl->parent_statement-> + parent_sheet->origin + > a_stmt->parent_sheet->origin)) { + /*TODO: support !important rule. */ + continue; } /* @@ -1106,53 +1020,50 @@ put_css_properties_in_hashtable (GHashTable **a_props_hashtable, *the latter specified wins" */ if (a_stmt->specificity - >= decl->parent_statement->specificity) - { + >= decl->parent_statement->specificity) { g_hash_table_insert (props_hash, - cur_decl->property->str, - cur_decl) ; + cur_decl->property->str, cur_decl); } } - return CR_OK ; + return CR_OK; } static void set_style_from_props_hash_hr_func (gpointer a_prop, gpointer a_decl, gpointer a_style) { - CRDeclaration *decl = a_decl ; - CRStyle *style = a_style ; + CRDeclaration *decl = a_decl; + CRStyle *style = a_style; - g_return_if_fail (a_decl && a_prop && a_style) ; + g_return_if_fail (a_decl && a_prop && a_style); - cr_style_set_style_from_decl (style, decl) ; + cr_style_set_style_from_decl (style, decl); } #else -static enum CRStatus -put_css_properties_in_props_list (CRPropList **a_props, - CRStatement *a_stmt) +static enum CRStatus +put_css_properties_in_props_list (CRPropList ** a_props, CRStatement * a_stmt) { - CRPropList *props = NULL, *pair = NULL, *tmp_props = NULL ; - CRDeclaration *cur_decl = NULL ; + CRPropList *props = NULL, + *pair = NULL, + *tmp_props = NULL; + CRDeclaration *cur_decl = NULL; g_return_val_if_fail (a_props && a_stmt && a_stmt->type == RULESET_STMT - && a_stmt->kind.ruleset, - CR_BAD_PARAM_ERROR) ; + && a_stmt->kind.ruleset, CR_BAD_PARAM_ERROR); + + props = *a_props; - props = *a_props ; + for (cur_decl = a_stmt->kind.ruleset->decl_list; + cur_decl; cur_decl = cur_decl->next) { + CRDeclaration *decl; - for (cur_decl = a_stmt->kind.ruleset->decl_list ; - cur_decl ; cur_decl = cur_decl->next) - { - CRDeclaration *decl ; - - decl = NULL ; - pair = NULL ; + decl = NULL; + pair = NULL; if (!cur_decl->property || !cur_decl->property->str) - continue ; + continue; /* *First, test if the property is not *already present in our properties list @@ -1160,22 +1071,16 @@ put_css_properties_in_props_list (CRPropList **a_props, *compute the precedence. If not, insert *the property into the list */ - cr_prop_list_lookup_prop - (props, cur_decl->property, - &pair) ; - - if (!pair) - { - tmp_props = cr_prop_list_append2 - (props, - cur_decl->property, - cur_decl) ; - if (tmp_props) - { - props = tmp_props ; - tmp_props = NULL ; + cr_prop_list_lookup_prop (props, cur_decl->property, &pair); + + if (!pair) { + tmp_props = cr_prop_list_append2 + (props, cur_decl->property, cur_decl); + if (tmp_props) { + props = tmp_props; + tmp_props = NULL; } - continue ; + continue; } /* @@ -1184,8 +1089,8 @@ put_css_properties_in_props_list (CRPropList **a_props, *some cascading rules *to compute the precedence. */ - cr_prop_list_get_decl (pair, &decl) ; - g_return_val_if_fail (decl, CR_ERROR) ; + cr_prop_list_get_decl (pair, &decl); + g_return_val_if_fail (decl, CR_ERROR); /* *first, look at the origin. @@ -1197,10 +1102,8 @@ put_css_properties_in_props_list (CRPropList **a_props, */ if (decl->parent_statement && decl->parent_statement->parent_sheet - && (decl->parent_statement->parent_sheet->origin - < - a_stmt->parent_sheet->origin)) - { + && (decl->parent_statement->parent_sheet->origin + < a_stmt->parent_sheet->origin)) { /* *if the already selected declaration *is marked as being !important the current @@ -1209,36 +1112,28 @@ put_css_properties_in_props_list (CRPropList **a_props, *has an UA origin) */ if (decl->important == TRUE - && decl->parent_statement->parent_sheet->origin - != ORIGIN_UA) - { - continue ; + && decl->parent_statement->parent_sheet->origin + != ORIGIN_UA) { + continue; } - tmp_props = cr_prop_list_unlink - (props, pair) ; - if (props) - { - cr_prop_list_destroy (pair) ; + tmp_props = cr_prop_list_unlink (props, pair); + if (props) { + cr_prop_list_destroy (pair); } - props = tmp_props ; - tmp_props = NULL ; + props = tmp_props; + tmp_props = NULL; props = cr_prop_list_append2 - (props, - cur_decl->property, - cur_decl) ; - - continue ; - } - else if (decl->parent_statement - && decl->parent_statement->parent_sheet - && (decl->parent_statement-> - parent_sheet->origin - > - a_stmt->parent_sheet->origin)) - { - cr_utils_trace_info - ("We should not reach this line\n") ; - continue ; + (props, cur_decl->property, cur_decl); + + continue; + } else if (decl->parent_statement + && decl->parent_statement->parent_sheet + && (decl->parent_statement-> + parent_sheet->origin + > a_stmt->parent_sheet->origin)) { + cr_utils_trace_info + ("We should not reach this line\n"); + continue; } /* @@ -1254,40 +1149,35 @@ put_css_properties_in_props_list (CRPropList **a_props, *the later specified wins" */ if (a_stmt->specificity - >= decl->parent_statement->specificity) - { + >= decl->parent_statement->specificity) { if (decl->important == TRUE) - continue ; - props = cr_prop_list_unlink (props, - pair) ; - if (pair) - { - cr_prop_list_destroy (pair) ; - pair = NULL ; - } + continue; + props = cr_prop_list_unlink (props, pair); + if (pair) { + cr_prop_list_destroy (pair); + pair = NULL; + } props = cr_prop_list_append2 (props, cur_decl->property, - cur_decl) ; + cur_decl); } } - /*TODO: this may leak. Check this out*/ - *a_props = props ; + /*TODO: this may leak. Check this out */ + *a_props = props; - return CR_OK ; + return CR_OK; } static void -set_style_from_props (CRStyle *a_style, CRPropList *a_props) +set_style_from_props (CRStyle * a_style, CRPropList * a_props) { - CRPropList *cur = NULL ; + CRPropList *cur = NULL; CRDeclaration *decl = NULL; - for (cur = a_props ; cur ; - cur = cr_prop_list_get_next (cur)) - { - cr_prop_list_get_decl (cur, &decl) ; - cr_style_set_style_from_decl (a_style, decl) ; - decl = NULL ; + for (cur = a_props; cur; cur = cr_prop_list_get_next (cur)) { + cr_prop_list_get_decl (cur, &decl); + cr_style_set_style_from_decl (a_style, decl); + decl = NULL; } } #endif @@ -1304,36 +1194,32 @@ set_style_from_props (CRStyle *a_style, CRPropList *a_props) CRSelEng * cr_sel_eng_new (void) { - CRSelEng *result = NULL; - - result = g_try_malloc (sizeof (CRSelEng)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRSelEng)) ; - - PRIVATE (result) = g_try_malloc (sizeof (CRSelEngPriv)) ; - if (!PRIVATE (result)) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } - memset (PRIVATE (result), 0, sizeof (CRSelEngPriv)) ; - cr_sel_eng_register_pseudo_class_sel_handler - (result, (guchar*)"first-child", - IDENT_PSEUDO, - (CRPseudoClassSelectorHandler) - first_child_pseudo_class_handler) ; - cr_sel_eng_register_pseudo_class_sel_handler - (result, (guchar*)"lang", - FUNCTION_PSEUDO, - (CRPseudoClassSelectorHandler) - lang_pseudo_class_handler) ; - - return result ; + CRSelEng *result = NULL; + + result = g_try_malloc (sizeof (CRSelEng)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + memset (result, 0, sizeof (CRSelEng)); + + PRIVATE (result) = g_try_malloc (sizeof (CRSelEngPriv)); + if (!PRIVATE (result)) { + cr_utils_trace_info ("Out of memory"); + g_free (result); + return NULL; + } + memset (PRIVATE (result), 0, sizeof (CRSelEngPriv)); + cr_sel_eng_register_pseudo_class_sel_handler + (result, (guchar *) "first-child", + IDENT_PSEUDO, (CRPseudoClassSelectorHandler) + first_child_pseudo_class_handler); + cr_sel_eng_register_pseudo_class_sel_handler + (result, (guchar *) "lang", + FUNCTION_PSEUDO, (CRPseudoClassSelectorHandler) + lang_pseudo_class_handler); + + return result; } /** @@ -1346,78 +1232,68 @@ cr_sel_eng_new (void) *@return CR_OK, upon successful completion, an error code otherwise. */ enum CRStatus -cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng *a_this, - guchar *a_name, +cr_sel_eng_register_pseudo_class_sel_handler (CRSelEng * a_this, + guchar * a_name, enum CRPseudoType a_type, - CRPseudoClassSelectorHandler a_handler) + CRPseudoClassSelectorHandler + a_handler) { - struct CRPseudoClassSelHandlerEntry *handler_entry = NULL ; - GList *list = NULL ; + struct CRPseudoClassSelHandlerEntry *handler_entry = NULL; + GList *list = NULL; - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_handler - && a_name, - CR_BAD_PARAM_ERROR) ; - - handler_entry = g_try_malloc - (sizeof (struct CRPseudoClassSelHandlerEntry)) ; - if (!handler_entry) - { - return CR_OUT_OF_MEMORY_ERROR ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_handler && a_name, CR_BAD_PARAM_ERROR); + + handler_entry = g_try_malloc + (sizeof (struct CRPseudoClassSelHandlerEntry)); + if (!handler_entry) { + return CR_OUT_OF_MEMORY_ERROR; } - memset (handler_entry, 0, - sizeof (struct CRPseudoClassSelHandlerEntry)) ; - handler_entry->name = g_strdup (a_name) ; - handler_entry->type= a_type ; - handler_entry->handler = a_handler ; - list = g_list_append - (PRIVATE (a_this)->pcs_handlers, handler_entry) ; - if (!list) - { - return CR_OUT_OF_MEMORY_ERROR ; + memset (handler_entry, 0, + sizeof (struct CRPseudoClassSelHandlerEntry)); + handler_entry->name = g_strdup (a_name); + handler_entry->type = a_type; + handler_entry->handler = a_handler; + list = g_list_append (PRIVATE (a_this)->pcs_handlers, handler_entry); + if (!list) { + return CR_OUT_OF_MEMORY_ERROR; } - PRIVATE (a_this)->pcs_handlers = list ; - return CR_OK ; + PRIVATE (a_this)->pcs_handlers = list; + return CR_OK; } enum CRStatus -cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng *a_this, - guchar *a_name, +cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng * a_this, + guchar * a_name, enum CRPseudoType a_type) { - GList *elem = NULL, *deleted_elem = NULL ; - gboolean found = FALSE ; - struct CRPseudoClassSelHandlerEntry *entry = NULL ; - - g_return_val_if_fail (a_this - && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - for (elem = PRIVATE (a_this)->pcs_handlers ; - elem ; - elem = g_list_next (elem)) - { - entry = elem->data ; + GList *elem = NULL, + *deleted_elem = NULL; + gboolean found = FALSE; + struct CRPseudoClassSelHandlerEntry *entry = NULL; + + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); + + for (elem = PRIVATE (a_this)->pcs_handlers; + elem; elem = g_list_next (elem)) { + entry = elem->data; if (!strcmp (entry->name, a_name) - && entry->type == a_type) - { + && entry->type == a_type) { found = TRUE; - break ; - } + break; + } } if (found == FALSE) - return CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR ; - PRIVATE (a_this)->pcs_handlers = g_list_delete_link - (PRIVATE (a_this)->pcs_handlers, - elem) ; - entry = elem->data ; + return CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR; + PRIVATE (a_this)->pcs_handlers = g_list_delete_link + (PRIVATE (a_this)->pcs_handlers, elem); + entry = elem->data; if (entry->name) - g_free (entry->name) ; - g_free (elem) ; - g_list_free (deleted_elem) ; + g_free (entry->name); + g_free (elem); + g_list_free (deleted_elem); - return CR_OK ; + return CR_OK; } /** @@ -1428,68 +1304,60 @@ cr_sel_eng_unregister_pseudo_class_sel_handler (CRSelEng *a_this, *otherwise. */ enum CRStatus -cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng *a_this) +cr_sel_eng_unregister_all_pseudo_class_sel_handlers (CRSelEng * a_this) { - GList *elem = NULL ; - struct CRPseudoClassSelHandlerEntry *entry = NULL ; + GList *elem = NULL; + struct CRPseudoClassSelHandlerEntry *entry = NULL; - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); if (!PRIVATE (a_this)->pcs_handlers) - return CR_OK ; - for (elem = PRIVATE (a_this)->pcs_handlers ; - elem; - elem = g_list_next (elem)) - { - entry = elem->data ; + return CR_OK; + for (elem = PRIVATE (a_this)->pcs_handlers; + elem; elem = g_list_next (elem)) { + entry = elem->data; if (!entry) - continue ; - if (entry->name) - { - g_free (entry->name) ; - entry->name = NULL ; + continue; + if (entry->name) { + g_free (entry->name); + entry->name = NULL; } - g_free (entry) ; - elem->data = NULL ; + g_free (entry); + elem->data = NULL; } - g_list_free (PRIVATE (a_this)->pcs_handlers) ; - PRIVATE (a_this)->pcs_handlers = NULL ; - return CR_OK ; + g_list_free (PRIVATE (a_this)->pcs_handlers); + PRIVATE (a_this)->pcs_handlers = NULL; + return CR_OK; } enum CRStatus -cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng *a_this, - guchar *a_name, +cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng * a_this, + guchar * a_name, enum CRPseudoType a_type, - CRPseudoClassSelectorHandler *a_handler) + CRPseudoClassSelectorHandler * + a_handler) { - GList *elem = NULL ; - struct CRPseudoClassSelHandlerEntry *entry = NULL ; - gboolean found = FALSE ; - - g_return_val_if_fail (a_this - && PRIVATE (a_this) - && a_name, - CR_BAD_PARAM_ERROR) ; - - for (elem = PRIVATE (a_this)->pcs_handlers ; - elem ; - elem = g_list_next (elem)) - { - entry = elem->data ; - if (!strcmp (a_name, entry->name) - && entry->type == a_type) - { - found = TRUE ; - break ; + GList *elem = NULL; + struct CRPseudoClassSelHandlerEntry *entry = NULL; + gboolean found = FALSE; + + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_name, CR_BAD_PARAM_ERROR); + + for (elem = PRIVATE (a_this)->pcs_handlers; + elem; elem = g_list_next (elem)) { + entry = elem->data; + if (!strcmp (a_name, entry->name) + && entry->type == a_type) { + found = TRUE; + break; } } if (found == FALSE) - return CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR ; - *a_handler = entry->handler ; - return CR_OK ; + return CR_PSEUDO_CLASS_SEL_HANDLER_NOT_FOUND_ERROR; + *a_handler = entry->handler; + return CR_OK; } /** @@ -1506,22 +1374,19 @@ cr_sel_eng_get_pseudo_class_selector_handler (CRSelEng *a_this, *@return the CR_OK if the selection ran correctly, an error code otherwise. */ enum CRStatus -cr_sel_eng_matches_node (CRSelEng *a_this, CRSimpleSel *a_sel, - xmlNode *a_node, gboolean *a_result) +cr_sel_eng_matches_node (CRSelEng * a_this, CRSimpleSel * a_sel, + xmlNode * a_node, gboolean * a_result) { - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_this && a_node - && a_result, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_this && a_node + && a_result, CR_BAD_PARAM_ERROR); - if (a_node->type != XML_ELEMENT_NODE) - { - *a_result = FALSE ; - return CR_OK ; + if (a_node->type != XML_ELEMENT_NODE) { + *a_result = FALSE; + return CR_OK; } - return sel_matches_node_real (a_this, a_sel, a_node, - a_result, TRUE) ; + return sel_matches_node_real (a_this, a_sel, a_node, a_result, TRUE); } /** @@ -1541,150 +1406,139 @@ cr_sel_eng_matches_node (CRSelEng *a_this, CRSimpleSel *a_sel, *@return CR_OK upon sucessfull completion, an error code otherwise. */ enum CRStatus -cr_sel_eng_get_matched_rulesets (CRSelEng *a_this, - CRStyleSheet *a_sheet, - xmlNode *a_node, - CRStatement ***a_rulesets, - gulong *a_len) +cr_sel_eng_get_matched_rulesets (CRSelEng * a_this, + CRStyleSheet * a_sheet, + xmlNode * a_node, + CRStatement *** a_rulesets, gulong * a_len) { - CRStatement ** stmts_tab = NULL ; - enum CRStatus status = CR_OK ; - gulong tab_size = 0, tab_len = 0, index = 0 ; - gushort stmts_chunck_size = 8 ; + CRStatement **stmts_tab = NULL; + enum CRStatus status = CR_OK; + gulong tab_size = 0, + tab_len = 0, + index = 0; + gushort stmts_chunck_size = 8; g_return_val_if_fail (a_this && a_sheet && a_node && a_rulesets && *a_rulesets == NULL - && a_len, - CR_BAD_PARAM_ERROR) ; + && a_len, CR_BAD_PARAM_ERROR); - stmts_tab = g_try_malloc (stmts_chunck_size * - sizeof (CRStatement *)) ; + stmts_tab = g_try_malloc (stmts_chunck_size * sizeof (CRStatement *)); - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; + if (!stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto error; } - memset (stmts_tab, 0, stmts_chunck_size * sizeof (CRStatement*)) ; + memset (stmts_tab, 0, stmts_chunck_size * sizeof (CRStatement *)); - tab_size = stmts_chunck_size ; - tab_len = tab_size ; + tab_size = stmts_chunck_size; + tab_len = tab_size; - while ((status = cr_sel_eng_get_matched_rulesets_real + while ((status = cr_sel_eng_get_matched_rulesets_real (a_this, a_sheet, a_node, stmts_tab + index, &tab_len)) - == CR_OUTPUT_TOO_SHORT_ERROR) - { + == CR_OUTPUT_TOO_SHORT_ERROR) { stmts_tab = g_try_realloc (stmts_tab, (tab_size + stmts_chunck_size) - * sizeof (CRStatement*)) ; - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; + * sizeof (CRStatement *)); + if (!stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto error; } - tab_size += stmts_chunck_size ; - index += tab_len ; - tab_len = tab_size - index ; + tab_size += stmts_chunck_size; + index += tab_len; + tab_len = tab_size - index; } + tab_len = tab_size - stmts_chunck_size + tab_len; + *a_rulesets = stmts_tab; + *a_len = tab_len; - tab_len = tab_size - stmts_chunck_size +tab_len ; - *a_rulesets = stmts_tab ; - *a_len = tab_len ; + return CR_OK; - return CR_OK ; + error: - error: + if (stmts_tab) { + g_free (stmts_tab); + stmts_tab = NULL; - if (stmts_tab) - { - g_free (stmts_tab) ; - stmts_tab = NULL ; - } - *a_len = 0 ; - return status ; + *a_len = 0; + return status; } #ifndef NEW_PROPERTIES_GETTER enum CRStatus -cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this, - CRCascade *a_cascade, - xmlNode *a_node, - GHashTable **a_props_hashtable) +cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, + CRCascade * a_cascade, + xmlNode * a_node, + GHashTable ** + a_props_hashtable) { - CRStatement ** stmts_tab = NULL ; - enum CRStatus status = CR_OK ; - gulong tab_size = 0, tab_len = 0, i = 0, index = 0; - enum CRStyleOrigin origin = 0 ; - gushort stmts_chunck_size = 8 ; - CRStyleSheet *sheet = NULL ; + CRStatement **stmts_tab = NULL; + enum CRStatus status = CR_OK; + gulong tab_size = 0, + tab_len = 0, + i = 0, + index = 0; + enum CRStyleOrigin origin = 0; + gushort stmts_chunck_size = 8; + CRStyleSheet *sheet = NULL; g_return_val_if_fail (a_this && a_cascade && a_node - && a_props_hashtable, - CR_BAD_PARAM_ERROR) ; + && a_props_hashtable, CR_BAD_PARAM_ERROR); - for (origin = ORIGIN_UA ; origin < NB_ORIGINS ; origin++) - { - sheet = cr_cascade_get_sheet (a_cascade, origin) ; + for (origin = ORIGIN_UA; origin < NB_ORIGINS; origin++) { + sheet = cr_cascade_get_sheet (a_cascade, origin); if (!sheet) - continue ; - if (tab_size - index < 1) - { + continue; + if (tab_size - index < 1) { stmts_tab = g_try_realloc - (stmts_tab, - (tab_size + stmts_chunck_size) - * sizeof (CRStatement*)) ; - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; + (stmts_tab, (tab_size + stmts_chunck_size) + * sizeof (CRStatement *)); + if (!stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto error; } - tab_size += stmts_chunck_size ; + tab_size += stmts_chunck_size; /* *compute the max size left for *cr_sel_eng_get_matched_rulesets_real()'s output tab */ - tab_len = tab_size - index ; + tab_len = tab_size - index; } while ((status = cr_sel_eng_get_matched_rulesets_real (a_this, sheet, a_node, stmts_tab + index, &tab_len)) - == CR_OUTPUT_TOO_SHORT_ERROR) - { + == CR_OUTPUT_TOO_SHORT_ERROR) { stmts_tab = g_try_realloc - (stmts_tab, - (tab_size + stmts_chunck_size) - * sizeof (CRStatement*)) ; - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; + (stmts_tab, (tab_size + stmts_chunck_size) + * sizeof (CRStatement *)); + if (!stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto error; } - tab_size += stmts_chunck_size ; - index += tab_len ; + tab_size += stmts_chunck_size; + index += tab_len; /* *compute the max size left for *cr_sel_eng_get_matched_rulesets_real()'s output tab */ - tab_len = tab_size - index ; + tab_len = tab_size - index; } - if (status != CR_OK) - { + if (status != CR_OK) { cr_utils_trace_info ("Error while running " - "selector engine") ; - goto error ; + "selector engine"); + goto error; } - index += tab_len ; - tab_len = tab_size - index ; + index += tab_len; + tab_len = tab_size - index; } /* @@ -1693,114 +1547,103 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this, *Make sure one can walk from the declaration to *the stylesheet. */ - for (i = 0 ; i < index ; i ++) - { - CRStatement *stmt = stmts_tab[i] ; + for (i = 0; i < index; i++) { + CRStatement *stmt = stmts_tab[i]; if (!stmt) - continue ; - switch (stmt->type) - { + continue; + switch (stmt->type) { case RULESET_STMT: if (!stmt->parent_sheet) - continue ; + continue; status = put_css_properties_in_hashtable - (a_props_hashtable, - stmt) ; - break ; + (a_props_hashtable, stmt); + break; default: - break ; + break; } - + } - return CR_OK ; - error: + return CR_OK; + error: + + if (stmts_tab) { + g_free (stmts_tab); + stmts_tab = NULL; - if (stmts_tab) - { - g_free (stmts_tab) ; - stmts_tab = NULL ; - } - return status ; + return status; } #else enum CRStatus -cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this, - CRCascade *a_cascade, - xmlNode *a_node, - CRPropList **a_props) +cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this, + CRCascade * a_cascade, + xmlNode * a_node, + CRPropList ** a_props) { - CRStatement ** stmts_tab = NULL ; - enum CRStatus status = CR_OK ; - gulong tab_size = 0, tab_len = 0, i = 0, index = 0; - enum CRStyleOrigin origin = 0 ; - gushort stmts_chunck_size = 8 ; - CRStyleSheet *sheet = NULL ; + CRStatement **stmts_tab = NULL; + enum CRStatus status = CR_OK; + gulong tab_size = 0, + tab_len = 0, + i = 0, + index = 0; + enum CRStyleOrigin origin = 0; + gushort stmts_chunck_size = 8; + CRStyleSheet *sheet = NULL; g_return_val_if_fail (a_this && a_cascade - && a_node - && a_props, - CR_BAD_PARAM_ERROR) ; + && a_node && a_props, CR_BAD_PARAM_ERROR); - for (origin = ORIGIN_UA ; origin < NB_ORIGINS ; origin++) - { - sheet = cr_cascade_get_sheet (a_cascade, origin) ; + for (origin = ORIGIN_UA; origin < NB_ORIGINS; origin++) { + sheet = cr_cascade_get_sheet (a_cascade, origin); if (!sheet) - continue ; - if (tab_size - index < 1) - { + continue; + if (tab_size - index < 1) { stmts_tab = g_try_realloc - (stmts_tab, - (tab_size + stmts_chunck_size) - * sizeof (CRStatement*)) ; - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; + (stmts_tab, (tab_size + stmts_chunck_size) + * sizeof (CRStatement *)); + if (!stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto error; } - tab_size += stmts_chunck_size ; + tab_size += stmts_chunck_size; /* *compute the max size left for *cr_sel_eng_get_matched_rulesets_real()'s output tab */ - tab_len = tab_size - index ; + tab_len = tab_size - index; } while ((status = cr_sel_eng_get_matched_rulesets_real (a_this, sheet, a_node, stmts_tab + index, &tab_len)) - == CR_OUTPUT_TOO_SHORT_ERROR) - { + == CR_OUTPUT_TOO_SHORT_ERROR) { stmts_tab = g_try_realloc - (stmts_tab, - (tab_size + stmts_chunck_size) - * sizeof (CRStatement*)) ; - if (!stmts_tab) - { - cr_utils_trace_info ("Out of memory") ; - status = CR_ERROR ; - goto error ; + (stmts_tab, (tab_size + stmts_chunck_size) + * sizeof (CRStatement *)); + if (!stmts_tab) { + cr_utils_trace_info ("Out of memory"); + status = CR_ERROR; + goto error; } - tab_size += stmts_chunck_size ; - index += tab_len ; + tab_size += stmts_chunck_size; + index += tab_len; /* *compute the max size left for *cr_sel_eng_get_matched_rulesets_real()'s output tab */ - tab_len = tab_size - index ; + tab_len = tab_size - index; } - if (status != CR_OK) - { + if (status != CR_OK) { cr_utils_trace_info ("Error while running " - "selector engine") ; - goto error ; + "selector engine"); + goto error; } - index += tab_len ; - tab_len = tab_size - index ; + index += tab_len; + tab_len = tab_size - index; } /* @@ -1809,117 +1652,100 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this, *Make sure one can walk from the declaration to *the stylesheet. */ - for (i = 0 ; i < index ; i ++) - { - CRStatement *stmt = stmts_tab[i] ; + for (i = 0; i < index; i++) { + CRStatement *stmt = stmts_tab[i]; if (!stmt) - continue ; - switch (stmt->type) - { + continue; + switch (stmt->type) { case RULESET_STMT: if (!stmt->parent_sheet) - continue ; + continue; status = put_css_properties_in_props_list - (a_props, stmt) ; - break ; + (a_props, stmt); + break; default: - break ; + break; } - + } - return CR_OK ; - error: + return CR_OK; + error: + + if (stmts_tab) { + g_free (stmts_tab); + stmts_tab = NULL; - if (stmts_tab) - { - g_free (stmts_tab) ; - stmts_tab = NULL ; - } - return status ; + return status; } #endif enum CRStatus -cr_sel_eng_get_matched_style (CRSelEng *a_this, - CRCascade *a_cascade, - xmlNode *a_node, - CRStyle *a_parent_style, - CRStyle **a_style) +cr_sel_eng_get_matched_style (CRSelEng * a_this, + CRCascade * a_cascade, + xmlNode * a_node, + CRStyle * a_parent_style, CRStyle ** a_style) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; + #ifndef NEW_PROPERTIES_GETTER - GHashTable *props_hash = NULL ; + GHashTable *props_hash = NULL; #else - CRPropList *props = NULL ; + CRPropList *props = NULL; #endif g_return_val_if_fail (a_this && a_cascade - && a_node && a_style, - CR_BAD_PARAM_ERROR) ; -#ifndef NEW_PROPERTIES_GETTER - status = cr_sel_eng_get_matched_properties_from_cascade - (a_this, a_cascade, a_node, &props_hash) ; + && a_node && a_style, CR_BAD_PARAM_ERROR); +#ifndef NEW_PROPERTIES_GETTER + status = cr_sel_eng_get_matched_properties_from_cascade + (a_this, a_cascade, a_node, &props_hash); #else - status = cr_sel_eng_get_matched_properties_from_cascade - (a_this, a_cascade, a_node, &props) ; + status = cr_sel_eng_get_matched_properties_from_cascade + (a_this, a_cascade, a_node, &props); #endif - g_return_val_if_fail (status == CR_OK, status) ; - + g_return_val_if_fail (status == CR_OK, status); #ifndef NEW_PROPERTIES_GETTER - if (props_hash && g_hash_table_size (props_hash)) - { - - if (!*a_style) - { - *a_style = cr_style_new () ; - g_return_val_if_fail (*a_style, CR_ERROR) ; - } - else - { - cr_style_set_props_to_defaults (*a_style) ; + if (props_hash && g_hash_table_size (props_hash)) { + + if (!*a_style) { + *a_style = cr_style_new (); + g_return_val_if_fail (*a_style, CR_ERROR); + } else { + cr_style_set_props_to_defaults (*a_style); } - (*a_style)->parent_style = a_parent_style ; + (*a_style)->parent_style = a_parent_style; - g_hash_table_foreach (props_hash, - ((GHFunc) - set_style_from_props_hash_hr_func), - *a_style) ; + g_hash_table_foreach (props_hash, ((GHFunc) + set_style_from_props_hash_hr_func), + *a_style); } - if (props_hash) - { - g_hash_table_destroy (props_hash) ; - props_hash = NULL ; + if (props_hash) { + g_hash_table_destroy (props_hash); + props_hash = NULL; } #else - if (props) - { - - if (!*a_style) - { - *a_style = cr_style_new () ; - g_return_val_if_fail (*a_style, CR_ERROR) ; - } - else - { - cr_style_set_props_to_defaults (*a_style) ; + if (props) { + + if (!*a_style) { + *a_style = cr_style_new (); + g_return_val_if_fail (*a_style, CR_ERROR); + } else { + cr_style_set_props_to_defaults (*a_style); } - (*a_style)->parent_style = a_parent_style ; + (*a_style)->parent_style = a_parent_style; - set_style_from_props (*a_style, props) ; - if (props) - { - cr_prop_list_destroy (props) ; - props = NULL ; + set_style_from_props (*a_style, props); + if (props) { + cr_prop_list_destroy (props); + props = NULL; } } - #endif - return CR_OK ; + return CR_OK; } /** @@ -1927,22 +1753,19 @@ cr_sel_eng_get_matched_style (CRSelEng *a_this, *@param a_this the current instance of the selection engine. */ void -cr_sel_eng_destroy (CRSelEng *a_this) +cr_sel_eng_destroy (CRSelEng * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - if (PRIVATE (a_this)) - { - g_free (PRIVATE (a_this)) ; - PRIVATE (a_this) = NULL ; - } + if (PRIVATE (a_this)) { + g_free (PRIVATE (a_this)); + PRIVATE (a_this) = NULL; + } /* *FIXME: *unregister all the pseudo class sel handlers. */ - if (a_this) - { - g_free (a_this) ; - } + if (a_this) { + g_free (a_this); + } } - diff --git a/src/cr-selector.c b/src/cr-selector.c index be1a069..7444969 100644 --- a/src/cr-selector.c +++ b/src/cr-selector.c @@ -34,36 +34,33 @@ *@return the newly built instance of #CRSelector, or *NULL in case of failure. */ -CRSelector* -cr_selector_new (CRSimpleSel *a_simple_sel) +CRSelector * +cr_selector_new (CRSimpleSel * a_simple_sel) { - CRSelector *result = NULL ; - - result = g_try_malloc (sizeof (CRSelector)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRSelector)) ; - result->simple_sel = a_simple_sel ; - return result ; + CRSelector *result = NULL; + + result = g_try_malloc (sizeof (CRSelector)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + memset (result, 0, sizeof (CRSelector)); + result->simple_sel = a_simple_sel; + return result; } CRSelector * -cr_selector_parse_from_buf (const guchar * a_char_buf, - enum CREncoding a_enc) +cr_selector_parse_from_buf (const guchar * a_char_buf, enum CREncoding a_enc) { - CRParser * parser = NULL ; - - g_return_val_if_fail (a_char_buf, NULL) ; + CRParser *parser = NULL; + + g_return_val_if_fail (a_char_buf, NULL); - parser = cr_parser_new_from_buf (a_char_buf, strlen (a_char_buf), - a_enc, FALSE) ; - g_return_val_if_fail (parser, NULL) ; + parser = cr_parser_new_from_buf (a_char_buf, strlen (a_char_buf), + a_enc, FALSE); + g_return_val_if_fail (parser, NULL); - - return NULL ; + return NULL; } /** @@ -72,23 +69,22 @@ cr_selector_parse_from_buf (const guchar * a_char_buf, *@param a_new the instance of #CRSelector to be appended. *@return the new list. */ -CRSelector* -cr_selector_append (CRSelector *a_this, CRSelector *a_new) +CRSelector * +cr_selector_append (CRSelector * a_this, CRSelector * a_new) { - CRSelector *cur = NULL ; - - if (!a_this) - { - return a_new ; - } + CRSelector *cur = NULL; - /*walk forward the list headed by a_this to get the list tail*/ - for (cur = a_this ; cur && cur->next ; cur = cur->next) ; + if (!a_this) { + return a_new; + } - cur->next = a_new ; - a_new->prev = cur ; + /*walk forward the list headed by a_this to get the list tail */ + for (cur = a_this; cur && cur->next; cur = cur->next) ; - return a_this ; + cur->next = a_new; + a_new->prev = cur; + + return a_this; } /** @@ -97,17 +93,17 @@ cr_selector_append (CRSelector *a_this, CRSelector *a_new) *@param a_new the instance of #CRSelector. *@return the new list. */ -CRSelector* -cr_selector_prepend (CRSelector *a_this, CRSelector *a_new) +CRSelector * +cr_selector_prepend (CRSelector * a_this, CRSelector * a_new) { - CRSelector *cur = NULL ; - - a_new->next = a_this ; - a_this->prev = a_new ; - - for (cur = a_new ; cur && cur->prev ; cur = cur->prev) ; - - return cur ; + CRSelector *cur = NULL; + + a_new->next = a_this; + a_this->prev = a_new; + + for (cur = a_new; cur && cur->prev; cur = cur->prev) ; + + return cur; } /** @@ -116,67 +112,60 @@ cr_selector_prepend (CRSelector *a_this, CRSelector *a_new) *@param a_simple_sel the simple selector to append. *@return the new list or NULL in case of failure. */ -CRSelector* -cr_selector_append_simple_sel (CRSelector *a_this, CRSimpleSel *a_simple_sel) +CRSelector * +cr_selector_append_simple_sel (CRSelector * a_this, + CRSimpleSel * a_simple_sel) { - CRSelector * selector = NULL ; + CRSelector *selector = NULL; - selector = cr_selector_new (a_simple_sel) ; - g_return_val_if_fail (selector, NULL) ; + selector = cr_selector_new (a_simple_sel); + g_return_val_if_fail (selector, NULL); - return cr_selector_append (a_this, selector) ; + return cr_selector_append (a_this, selector); } - guchar * -cr_selector_to_string (CRSelector *a_this) +cr_selector_to_string (CRSelector * a_this) { - guchar *result = NULL ; - GString *str_buf = NULL ; - - str_buf = g_string_new (NULL) ; - g_return_val_if_fail (str_buf, NULL) ; - - if (a_this) - { - CRSelector *cur = NULL ; - - for (cur = a_this ; cur ; cur = cur->next) - { - if (cur->simple_sel) - { - guchar *tmp_str = NULL ; - - tmp_str = cr_simple_sel_to_string - (cur->simple_sel) ; - - if (tmp_str) - { - if (cur->prev) - g_string_append_printf - (str_buf,", ") ; - - g_string_append_printf - (str_buf, "%s", - tmp_str) ; - - g_free (tmp_str) ; - tmp_str = NULL ; - } - } - } - } - - if (str_buf) - { - result = str_buf->str ; - g_string_free (str_buf, FALSE) ; - str_buf = NULL ; - } - - return result ; -} + guchar *result = NULL; + GString *str_buf = NULL; + + str_buf = g_string_new (NULL); + g_return_val_if_fail (str_buf, NULL); + if (a_this) { + CRSelector *cur = NULL; + + for (cur = a_this; cur; cur = cur->next) { + if (cur->simple_sel) { + guchar *tmp_str = NULL; + + tmp_str = cr_simple_sel_to_string + (cur->simple_sel); + + if (tmp_str) { + if (cur->prev) + g_string_append_printf + (str_buf, ", "); + + g_string_append_printf + (str_buf, "%s", tmp_str); + + g_free (tmp_str); + tmp_str = NULL; + } + } + } + } + + if (str_buf) { + result = str_buf->str; + g_string_free (str_buf, FALSE); + str_buf = NULL; + } + + return result; +} /** *Serializes the current instance of #CRSelector to a file. @@ -184,20 +173,18 @@ cr_selector_to_string (CRSelector *a_this) *@param a_fp the destination file. */ void -cr_selector_dump (CRSelector *a_this, FILE *a_fp) +cr_selector_dump (CRSelector * a_this, FILE * a_fp) { - guchar *tmp_buf = NULL ; - - if (a_this) - { - tmp_buf = cr_selector_to_string (a_this) ; - if (tmp_buf) - { - fprintf (a_fp, "%s", tmp_buf) ; - g_free (tmp_buf) ; - tmp_buf = NULL ; - } - } + guchar *tmp_buf = NULL; + + if (a_this) { + tmp_buf = cr_selector_to_string (a_this); + if (tmp_buf) { + fprintf (a_fp, "%s", tmp_buf); + g_free (tmp_buf); + tmp_buf = NULL; + } + } } /** @@ -206,11 +193,11 @@ cr_selector_dump (CRSelector *a_this, FILE *a_fp) *@param a_this the current instance of #CRSelector. */ void -cr_selector_ref (CRSelector *a_this) +cr_selector_ref (CRSelector * a_this) { - g_return_if_fail (a_this) ; - - a_this->ref_count ++ ; + g_return_if_fail (a_this); + + a_this->ref_count++; } /** @@ -223,22 +210,20 @@ cr_selector_ref (CRSelector *a_this) *of #CRSelector, FALSE otherwise. */ gboolean -cr_selector_unref (CRSelector *a_this) +cr_selector_unref (CRSelector * a_this) { - g_return_val_if_fail (a_this, FALSE) ; - - if (a_this->ref_count) - { - a_this->ref_count -- ; - } - - if (a_this->ref_count == 0) - { - cr_selector_destroy (a_this) ; - return TRUE ; - } - - return FALSE ; + g_return_val_if_fail (a_this, FALSE); + + if (a_this->ref_count) { + a_this->ref_count--; + } + + if (a_this->ref_count == 0) { + cr_selector_destroy (a_this); + return TRUE; + } + + return FALSE; } /** @@ -246,59 +231,51 @@ cr_selector_unref (CRSelector *a_this) *@param a_this the current instance of #CRSelector. */ void -cr_selector_destroy (CRSelector *a_this) +cr_selector_destroy (CRSelector * a_this) { - CRSelector *cur = NULL ; - - g_return_if_fail (a_this) ; - - /* - *go and get the list tail. In the same time, free - *all the simple selectors contained in the list. - */ - for (cur = a_this ;cur && cur->next ; cur = cur->next) - { - if (cur->simple_sel) - { - cr_simple_sel_destroy (cur->simple_sel) ; - cur->simple_sel = NULL ; - } - } - - if (cur) - { - if (cur->simple_sel) - { - cr_simple_sel_destroy (cur->simple_sel) ; - cur->simple_sel = NULL ; - } - } - - /*in case the list has only one element*/ - if (cur && !cur->prev) - { - g_free (cur) ; - return ; - } - - /*walk backward the list and free each "next element"*/ - for (cur = cur->prev ; cur && cur->prev ; cur = cur->prev) - { - if (cur->next) - { - g_free (cur->next) ; - cur->next = NULL ; - } - } - - if (!cur) - return ; - - if (cur->next) - { - g_free (cur->next) ; - cur->next = NULL ; - } - - g_free (cur) ; + CRSelector *cur = NULL; + + g_return_if_fail (a_this); + + /* + *go and get the list tail. In the same time, free + *all the simple selectors contained in the list. + */ + for (cur = a_this; cur && cur->next; cur = cur->next) { + if (cur->simple_sel) { + cr_simple_sel_destroy (cur->simple_sel); + cur->simple_sel = NULL; + } + } + + if (cur) { + if (cur->simple_sel) { + cr_simple_sel_destroy (cur->simple_sel); + cur->simple_sel = NULL; + } + } + + /*in case the list has only one element */ + if (cur && !cur->prev) { + g_free (cur); + return; + } + + /*walk backward the list and free each "next element" */ + for (cur = cur->prev; cur && cur->prev; cur = cur->prev) { + if (cur->next) { + g_free (cur->next); + cur->next = NULL; + } + } + + if (!cur) + return; + + if (cur->next) { + g_free (cur->next); + cur->next = NULL; + } + + g_free (cur); } diff --git a/src/cr-simple-sel.c b/src/cr-simple-sel.c index bd960c1..285309f 100644 --- a/src/cr-simple-sel.c +++ b/src/cr-simple-sel.c @@ -28,7 +28,6 @@ #include #include "cr-simple-sel.h" - /** *The constructor of #CRSimpleSel. * @@ -37,17 +36,16 @@ CRSimpleSel * cr_simple_sel_new (void) { - CRSimpleSel *result = NULL ; + CRSimpleSel *result = NULL; - result = g_try_malloc (sizeof (CRSimpleSel)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; + result = g_try_malloc (sizeof (CRSimpleSel)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; } - memset (result, 0, sizeof (CRSimpleSel)) ; + memset (result, 0, sizeof (CRSimpleSel)); - return result ; + return result; } /** @@ -58,21 +56,21 @@ cr_simple_sel_new (void) *@return the new list upon successfull completion, an error code otherwise. */ CRSimpleSel * -cr_simple_sel_append_simple_sel (CRSimpleSel *a_this, CRSimpleSel *a_sel) +cr_simple_sel_append_simple_sel (CRSimpleSel * a_this, CRSimpleSel * a_sel) { - CRSimpleSel *cur = NULL ; + CRSimpleSel *cur = NULL; - g_return_val_if_fail (a_sel, NULL) ; + g_return_val_if_fail (a_sel, NULL); if (a_this == NULL) - return a_sel ; + return a_sel; - for (cur = a_this ; cur->next ; cur = cur->next) ; + for (cur = a_this; cur->next; cur = cur->next) ; - cur->next = a_sel ; - a_sel->prev = cur ; + cur->next = a_sel; + a_sel->prev = cur; - return a_this ; + return a_this; } /** @@ -82,89 +80,79 @@ cr_simple_sel_append_simple_sel (CRSimpleSel *a_this, CRSimpleSel *a_sel) *@return the new list upon successfull completion, an error code otherwise. */ CRSimpleSel * -cr_simple_sel_prepend_simple_sel (CRSimpleSel *a_this, CRSimpleSel *a_sel) +cr_simple_sel_prepend_simple_sel (CRSimpleSel * a_this, CRSimpleSel * a_sel) { - g_return_val_if_fail (a_sel, NULL) ; + g_return_val_if_fail (a_sel, NULL); if (a_this == NULL) - return a_sel ; + return a_sel; - a_sel->next = a_this ; - a_this->prev = a_sel ; + a_sel->next = a_this; + a_this->prev = a_sel; - return a_sel ; + return a_sel; } guchar * -cr_simple_sel_to_string (CRSimpleSel *a_this) +cr_simple_sel_to_string (CRSimpleSel * a_this) { - GString * str_buf = NULL ; - guchar *result = NULL ; - - CRSimpleSel *cur = NULL ; - - g_return_val_if_fail (a_this, NULL) ; - - str_buf = g_string_new (NULL) ; - for (cur = a_this ; cur ; cur = cur->next) - { - if (cur->name) - { - guchar * str = g_strndup (cur->name->str, - cur->name->len) ; - if (str) - { - switch (cur->combinator) - { + GString *str_buf = NULL; + guchar *result = NULL; + + CRSimpleSel *cur = NULL; + + g_return_val_if_fail (a_this, NULL); + + str_buf = g_string_new (NULL); + for (cur = a_this; cur; cur = cur->next) { + if (cur->name) { + guchar *str = g_strndup (cur->name->str, + cur->name->len); + + if (str) { + switch (cur->combinator) { case COMB_WS: - g_string_append_printf - (str_buf, " ") ; - break ; + g_string_append_printf (str_buf, " "); + break; case COMB_PLUS: - g_string_append_printf - (str_buf, "+") ; - break ; + g_string_append_printf (str_buf, "+"); + break; case COMB_GT: - g_string_append_printf - (str_buf, ">") ; - break ; + g_string_append_printf (str_buf, ">"); + break; default: - break ; + break; } - - g_string_append_printf (str_buf,"%s",str) ; - g_free (str) ; - str = NULL ; - } + + g_string_append_printf (str_buf, "%s", str); + g_free (str); + str = NULL; + } } - if (cur->add_sel) - { - guchar *tmp_str = NULL ; - - tmp_str = cr_additional_sel_to_string - (cur->add_sel) ; - if (tmp_str) - { - g_string_append_printf - (str_buf, "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + if (cur->add_sel) { + guchar *tmp_str = NULL; + + tmp_str = cr_additional_sel_to_string (cur->add_sel); + if (tmp_str) { + g_string_append_printf + (str_buf, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } } } - if (str_buf) - { - result = str_buf->str ; - g_string_free (str_buf, FALSE) ; - str_buf = NULL ; + if (str_buf) { + result = str_buf->str; + g_string_free (str_buf, FALSE); + str_buf = NULL; } - return result ; + return result; } /** @@ -177,24 +165,22 @@ cr_simple_sel_to_string (CRSimpleSel *a_this) *otherwise. */ enum CRStatus -cr_simple_sel_dump (CRSimpleSel *a_this, FILE *a_fp) +cr_simple_sel_dump (CRSimpleSel * a_this, FILE * a_fp) { - guchar *tmp_str = NULL ; - - g_return_val_if_fail (a_fp, CR_BAD_PARAM_ERROR) ; - - if (a_this) - { - tmp_str = cr_simple_sel_to_string (a_this) ; - if (tmp_str) - { - fprintf (a_fp, "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + guchar *tmp_str = NULL; + + g_return_val_if_fail (a_fp, CR_BAD_PARAM_ERROR); + + if (a_this) { + tmp_str = cr_simple_sel_to_string (a_this); + if (tmp_str) { + fprintf (a_fp, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } } - return CR_OK ; + return CR_OK; } /** @@ -204,56 +190,51 @@ cr_simple_sel_dump (CRSimpleSel *a_this, FILE *a_fp) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_simple_sel_compute_specificity (CRSimpleSel *a_this) +cr_simple_sel_compute_specificity (CRSimpleSel * a_this) { - CRAdditionalSel *cur_add_sel = NULL ; - CRSimpleSel *cur_sel = NULL ; - gulong a=0, b=0, c=0; - - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - - for (cur_sel = a_this ; cur_sel ; cur_sel = cur_sel->next) - { - if (cur_sel->type_mask | TYPE_SELECTOR) - { - c++ ;/*hmmh, is this a new language ?*/ - } - else if (!cur_sel->name || ! cur_sel->name->str) - { - if (cur_sel->add_sel->type == PSEUDO_CLASS_ADD_SELECTOR) - { + CRAdditionalSel *cur_add_sel = NULL; + CRSimpleSel *cur_sel = NULL; + gulong a = 0, + b = 0, + c = 0; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + for (cur_sel = a_this; cur_sel; cur_sel = cur_sel->next) { + if (cur_sel->type_mask | TYPE_SELECTOR) { + c++; /*hmmh, is this a new language ? */ + } else if (!cur_sel->name || !cur_sel->name->str) { + if (cur_sel->add_sel->type == + PSEUDO_CLASS_ADD_SELECTOR) { /* *this is a pseudo element, and *the spec says, "ignore pseudo elements". */ - continue ; + continue; } } - for (cur_add_sel = cur_sel->add_sel ; - cur_add_sel ; - cur_add_sel = cur_add_sel->next) - { - switch (cur_add_sel->type) - { + for (cur_add_sel = cur_sel->add_sel; + cur_add_sel; cur_add_sel = cur_add_sel->next) { + switch (cur_add_sel->type) { case ID_ADD_SELECTOR: - a++ ; - break ; + a++; + break; case NO_ADD_SELECTOR: - continue ; + continue; default: - b++ ; - break ; + b++; + break; } } } - /*we suppose a, b and c have 1 to 3 digits*/ + /*we suppose a, b and c have 1 to 3 digits */ a_this->specificity = a * 1000000 + b * 1000 + c; - return CR_OK ; + return CR_OK; } /** @@ -263,30 +244,25 @@ cr_simple_sel_compute_specificity (CRSimpleSel *a_this) * */ void -cr_simple_sel_destroy (CRSimpleSel *a_this) +cr_simple_sel_destroy (CRSimpleSel * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - if (a_this->name) - { - g_string_free (a_this->name, TRUE) ; - a_this->name = NULL ; + if (a_this->name) { + g_string_free (a_this->name, TRUE); + a_this->name = NULL; } - if (a_this->add_sel) - { - cr_additional_sel_destroy (a_this->add_sel) ; - a_this->add_sel = NULL ; + if (a_this->add_sel) { + cr_additional_sel_destroy (a_this->add_sel); + a_this->add_sel = NULL; } - if (a_this->next) - { - cr_simple_sel_destroy (a_this->next) ; + if (a_this->next) { + cr_simple_sel_destroy (a_this->next); } - if (a_this) - { - g_free (a_this) ; + if (a_this) { + g_free (a_this); } } - diff --git a/src/cr-statement.c b/src/cr-statement.c index 8e9bca6..87f2d60 100644 --- a/src/cr-statement.c +++ b/src/cr-statement.c @@ -36,568 +36,513 @@ #define DECLARATION_INDENT_NB 2 static void -cr_statement_clear (CRStatement *a_this) ; + cr_statement_clear (CRStatement * a_this); static void -cr_statement_dump_ruleset (CRStatement *a_this, FILE *a_fp, glong a_indent) ; + cr_statement_dump_ruleset (CRStatement * a_this, FILE * a_fp, glong a_indent); static void -cr_statement_dump_charset (CRStatement *a_this, FILE *a_fp, - gulong a_indent) ; + cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp, + gulong a_indent); static void -cr_statement_dump_page (CRStatement *a_this, FILE *a_fp, gulong a_indent) ; + cr_statement_dump_page (CRStatement * a_this, FILE * a_fp, gulong a_indent); static void -cr_statement_dump_media_rule (CRStatement *a_this, FILE *a_fp, - gulong a_indent) ; + cr_statement_dump_media_rule (CRStatement * a_this, FILE * a_fp, + gulong a_indent); static void -cr_statement_dump_import_rule (CRStatement *a_this, FILE *a_fp, - gulong a_indent) ; + cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp, + gulong a_indent); static void -parse_font_face_start_font_face_cb (CRDocHandler *a_this) +parse_font_face_start_font_face_cb (CRDocHandler * a_this) { - CRStatement *stmt = NULL ; - enum CRStatus status = CR_OK ; + CRStatement *stmt = NULL; + enum CRStatus status = CR_OK; - stmt = cr_statement_new_at_font_face_rule (NULL, - NULL) ; - g_return_if_fail (stmt) ; - - status = cr_doc_handler_set_ctxt (a_this, stmt) ; - g_return_if_fail (status == CR_OK) ; + stmt = cr_statement_new_at_font_face_rule (NULL, NULL); + g_return_if_fail (stmt); + + status = cr_doc_handler_set_ctxt (a_this, stmt); + g_return_if_fail (status == CR_OK); } static void -parse_font_face_unrecoverable_error_cb (CRDocHandler *a_this) +parse_font_face_unrecoverable_error_cb (CRDocHandler * a_this) { - CRStatement *stmt = NULL ; - enum CRStatus status = CR_OK ; + CRStatement *stmt = NULL; + enum CRStatus status = CR_OK; - g_return_if_fail (a_this) ; - - status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; - if (status != CR_OK) - { + g_return_if_fail (a_this); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " - "This may lead to some memory leaks.") ; - return ; + "This may lead to some memory leaks."); + return; + } + if (stmt) { + cr_statement_destroy (stmt); + cr_doc_handler_set_ctxt (a_this, NULL); + return; } - if (stmt) - { - cr_statement_destroy (stmt) ; - cr_doc_handler_set_ctxt (a_this, NULL) ; - return ; - } } static void -parse_font_face_property_cb (CRDocHandler *a_this, - GString *a_name, - CRTerm *a_value, - gboolean a_important) -{ - enum CRStatus status = CR_OK ; - GString *name = NULL ; - CRDeclaration *decl = NULL ; - CRStatement *stmt = NULL ; - - g_return_if_fail (a_this && a_name) ; - - status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; - g_return_if_fail (status == CR_OK && stmt) ; - g_return_if_fail (stmt->type == AT_FONT_FACE_RULE_STMT) ; - - name = g_string_new_len (a_name->str, a_name->len) ; - g_return_if_fail (name) ; - decl = cr_declaration_new (stmt, name, a_value) ; - if (!decl) - { - cr_utils_trace_info ("cr_declaration_new () failed.") ; - goto error ; - } - name = NULL ; - - stmt->kind.font_face_rule->decl_list = - cr_declaration_append (stmt->kind.font_face_rule->decl_list, - decl) ; - if (!stmt->kind.font_face_rule->decl_list) - goto error ; - decl = NULL ; - - error: - if (decl) - { - cr_declaration_unref (decl) ; - decl = NULL ; - } - if (name) - { - g_string_free (name, TRUE) ; - name = NULL ; - } +parse_font_face_property_cb (CRDocHandler * a_this, + GString * a_name, + CRTerm * a_value, gboolean a_important) +{ + enum CRStatus status = CR_OK; + GString *name = NULL; + CRDeclaration *decl = NULL; + CRStatement *stmt = NULL; + + g_return_if_fail (a_this && a_name); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + g_return_if_fail (status == CR_OK && stmt); + g_return_if_fail (stmt->type == AT_FONT_FACE_RULE_STMT); + + name = g_string_new_len (a_name->str, a_name->len); + g_return_if_fail (name); + decl = cr_declaration_new (stmt, name, a_value); + if (!decl) { + cr_utils_trace_info ("cr_declaration_new () failed."); + goto error; + } + name = NULL; + + stmt->kind.font_face_rule->decl_list = + cr_declaration_append (stmt->kind.font_face_rule->decl_list, + decl); + if (!stmt->kind.font_face_rule->decl_list) + goto error; + decl = NULL; + + error: + if (decl) { + cr_declaration_unref (decl); + decl = NULL; + } + if (name) { + g_string_free (name, TRUE); + name = NULL; + } } static void -parse_font_face_end_font_face_cb (CRDocHandler *a_this) +parse_font_face_end_font_face_cb (CRDocHandler * a_this) +{ + CRStatement *result = NULL; + enum CRStatus status = CR_OK; -{ - CRStatement *result = NULL ; - enum CRStatus status = CR_OK ; - - g_return_if_fail (a_this) ; - - status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&result) ; - g_return_if_fail (status == CR_OK && result) ; - g_return_if_fail (result->type == AT_FONT_FACE_RULE_STMT) ; + g_return_if_fail (a_this); - status = cr_doc_handler_set_result (a_this, result) ; - g_return_if_fail (status == CR_OK) ; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & result); + g_return_if_fail (status == CR_OK && result); + g_return_if_fail (result->type == AT_FONT_FACE_RULE_STMT); + + status = cr_doc_handler_set_result (a_this, result); + g_return_if_fail (status == CR_OK); } static void -parse_page_start_page_cb (CRDocHandler *a_this, - GString *a_name, - GString *a_pseudo_page) +parse_page_start_page_cb (CRDocHandler * a_this, + GString * a_name, GString * a_pseudo_page) { - CRStatement *stmt = NULL ; - enum CRStatus status = CR_OK ; - - stmt = cr_statement_new_at_page_rule (NULL, NULL, a_name, - a_pseudo_page) ; - g_return_if_fail (stmt) ; - status = cr_doc_handler_set_ctxt (a_this, stmt) ; - g_return_if_fail (status == CR_OK) ; + CRStatement *stmt = NULL; + enum CRStatus status = CR_OK; + + stmt = cr_statement_new_at_page_rule (NULL, NULL, a_name, + a_pseudo_page); + g_return_if_fail (stmt); + status = cr_doc_handler_set_ctxt (a_this, stmt); + g_return_if_fail (status == CR_OK); } static void -parse_page_unrecoverable_error_cb (CRDocHandler *a_this) +parse_page_unrecoverable_error_cb (CRDocHandler * a_this) { - CRStatement *stmt = NULL ; - enum CRStatus status = CR_OK ; + CRStatement *stmt = NULL; + enum CRStatus status = CR_OK; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; - if (status != CR_OK) - { + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " - "This may lead to some memory leaks.") ; - return ; + "This may lead to some memory leaks."); + return; } - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - cr_doc_handler_set_ctxt (a_this, NULL) ; + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + cr_doc_handler_set_ctxt (a_this, NULL); } } static void -parse_page_property_cb (CRDocHandler *a_this, - GString *a_name, - CRTerm *a_expression, - gboolean a_important) +parse_page_property_cb (CRDocHandler * a_this, + GString * a_name, + CRTerm * a_expression, gboolean a_important) { - GString *name = NULL ; - CRStatement *stmt = NULL ; - CRDeclaration *decl = NULL ; - enum CRStatus status = CR_OK ; + GString *name = NULL; + CRStatement *stmt = NULL; + CRDeclaration *decl = NULL; + enum CRStatus status = CR_OK; - status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; - g_return_if_fail (status == CR_OK && stmt->type == AT_PAGE_RULE_STMT) ; + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + g_return_if_fail (status == CR_OK && stmt->type == AT_PAGE_RULE_STMT); - name = g_string_new_len (a_name->str, a_name->len) ; - g_return_if_fail (name) ; + name = g_string_new_len (a_name->str, a_name->len); + g_return_if_fail (name); - decl = cr_declaration_new (stmt, name, a_expression) ; - g_return_if_fail (decl) ; - decl->important = a_important ; - stmt->kind.page_rule->decl_list = - cr_declaration_append (stmt->kind.page_rule->decl_list, - decl) ; - g_return_if_fail (stmt->kind.page_rule->decl_list) ; + decl = cr_declaration_new (stmt, name, a_expression); + g_return_if_fail (decl); + decl->important = a_important; + stmt->kind.page_rule->decl_list = + cr_declaration_append (stmt->kind.page_rule->decl_list, decl); + g_return_if_fail (stmt->kind.page_rule->decl_list); } static void -parse_page_end_page_cb (CRDocHandler *a_this, - GString *a_name, - GString *a_pseudo_page) +parse_page_end_page_cb (CRDocHandler * a_this, + GString * a_name, GString * a_pseudo_page) { - enum CRStatus status = CR_OK ; - CRStatement *stmt = NULL ; - - status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; - g_return_if_fail (status == CR_OK && stmt); - g_return_if_fail (stmt->type == AT_PAGE_RULE_STMT); - - status = cr_doc_handler_set_result (a_this, stmt) ; - g_return_if_fail (status == CR_OK) ; + enum CRStatus status = CR_OK; + CRStatement *stmt = NULL; + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + g_return_if_fail (status == CR_OK && stmt); + g_return_if_fail (stmt->type == AT_PAGE_RULE_STMT); + + status = cr_doc_handler_set_result (a_this, stmt); + g_return_if_fail (status == CR_OK); } static void -parse_at_media_start_media_cb (CRDocHandler *a_this, - GList *a_media_list) +parse_at_media_start_media_cb (CRDocHandler * a_this, GList * a_media_list) { - enum CRStatus status = CR_OK ; - CRStatement *at_media = NULL ; - GList *media_list = NULL ; + enum CRStatus status = CR_OK; + CRStatement *at_media = NULL; + GList *media_list = NULL; - g_return_if_fail (a_this && a_this->priv) ; + g_return_if_fail (a_this && a_this->priv); - if (a_media_list) - { - /*duplicate media list*/ - media_list = cr_dup_glist_of_string (a_media_list) ; - } + if (a_media_list) { + /*duplicate media list */ + media_list = cr_dup_glist_of_string (a_media_list); + } - g_return_if_fail (media_list) ; + g_return_if_fail (media_list); - /*make sure cr_statement_new_at_media_rule works in this case.*/ - at_media = cr_statement_new_at_media_rule (NULL, NULL, - media_list) ; + /*make sure cr_statement_new_at_media_rule works in this case. */ + at_media = cr_statement_new_at_media_rule (NULL, NULL, media_list); - status = cr_doc_handler_set_ctxt (a_this, at_media) ; - g_return_if_fail (status == CR_OK) ; - status = cr_doc_handler_set_result (a_this, at_media) ; - g_return_if_fail (status == CR_OK) ; + status = cr_doc_handler_set_ctxt (a_this, at_media); + g_return_if_fail (status == CR_OK); + status = cr_doc_handler_set_result (a_this, at_media); + g_return_if_fail (status == CR_OK); } static void -parse_at_media_unrecoverable_error_cb (CRDocHandler *a_this) +parse_at_media_unrecoverable_error_cb (CRDocHandler * a_this) { - enum CRStatus status = CR_OK ; - CRStatement * stmt = NULL ; + enum CRStatus status = CR_OK; + CRStatement *stmt = NULL; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - status = cr_doc_handler_get_result (a_this, (gpointer*)&stmt) ; - if (status != CR_OK) - { + status = cr_doc_handler_get_result (a_this, (gpointer *) & stmt); + if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " - "This may lead to some memory leaks.") ; - return ; + "This may lead to some memory leaks."); + return; } - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - cr_doc_handler_set_ctxt (a_this, NULL) ; - cr_doc_handler_set_result (a_this, NULL) ; + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + cr_doc_handler_set_ctxt (a_this, NULL); + cr_doc_handler_set_result (a_this, NULL); } } static void -parse_at_media_start_selector_cb (CRDocHandler *a_this, - CRSelector *a_sellist) -{ - enum CRStatus status = CR_OK ; - CRStatement *at_media = NULL, *ruleset = NULL ; - - g_return_if_fail (a_this - && a_this->priv - && a_sellist) ; - - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&at_media) ; - g_return_if_fail (status == CR_OK && at_media) ; - g_return_if_fail (at_media->type == AT_MEDIA_RULE_STMT) ; - ruleset = cr_statement_new_ruleset (NULL, a_sellist, - NULL, at_media) ; - g_return_if_fail (ruleset) ; - status = cr_doc_handler_set_ctxt (a_this, ruleset) ; - g_return_if_fail (status == CR_OK) ; +parse_at_media_start_selector_cb (CRDocHandler * a_this, + CRSelector * a_sellist) +{ + enum CRStatus status = CR_OK; + CRStatement *at_media = NULL, + *ruleset = NULL; + + g_return_if_fail (a_this && a_this->priv && a_sellist); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & at_media); + g_return_if_fail (status == CR_OK && at_media); + g_return_if_fail (at_media->type == AT_MEDIA_RULE_STMT); + ruleset = cr_statement_new_ruleset (NULL, a_sellist, NULL, at_media); + g_return_if_fail (ruleset); + status = cr_doc_handler_set_ctxt (a_this, ruleset); + g_return_if_fail (status == CR_OK); } static void -parse_at_media_property_cb (CRDocHandler *a_this, - GString *a_name, CRTerm *a_value, +parse_at_media_property_cb (CRDocHandler * a_this, + GString * a_name, CRTerm * a_value, gboolean a_important) { - enum CRStatus status = CR_OK ; - /* - *the current ruleset stmt, child of the - *current at-media being parsed. - */ - CRStatement *stmt = NULL; - CRDeclaration *decl = NULL ; - GString *name = NULL ; - - g_return_if_fail (a_this && a_name) ; - - name = g_string_new_len (a_name->str, a_name->len) ; - g_return_if_fail (name) ; - - status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ; - g_return_if_fail (status == CR_OK && stmt) ; - g_return_if_fail (stmt->type == RULESET_STMT) ; - - decl = cr_declaration_new (stmt, name, a_value) ; - g_return_if_fail (decl) ; - decl->important = a_important ; - status = cr_statement_ruleset_append_decl - (stmt, decl) ; - g_return_if_fail (status == CR_OK) ; + enum CRStatus status = CR_OK; + + /* + *the current ruleset stmt, child of the + *current at-media being parsed. + */ + CRStatement *stmt = NULL; + CRDeclaration *decl = NULL; + GString *name = NULL; + + g_return_if_fail (a_this && a_name); + + name = g_string_new_len (a_name->str, a_name->len); + g_return_if_fail (name); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + g_return_if_fail (status == CR_OK && stmt); + g_return_if_fail (stmt->type == RULESET_STMT); + + decl = cr_declaration_new (stmt, name, a_value); + g_return_if_fail (decl); + decl->important = a_important; + status = cr_statement_ruleset_append_decl (stmt, decl); + g_return_if_fail (status == CR_OK); } static void -parse_at_media_end_selector_cb (CRDocHandler *a_this, - CRSelector *a_sellist) -{ - enum CRStatus status = CR_OK ; - /* - *the current ruleset stmt, child of the - *current at-media being parsed. - */ - CRStatement *stmt = NULL ; - - g_return_if_fail (a_this && a_sellist) ; - - status = cr_doc_handler_get_ctxt (a_this, - (gpointer *)&stmt) ; - g_return_if_fail (status == CR_OK && stmt - && stmt->type == RULESET_STMT) ; - g_return_if_fail (stmt->kind.ruleset->parent_media_rule) ; - - status = cr_doc_handler_set_ctxt - (a_this, - stmt->kind.ruleset->parent_media_rule) ; - g_return_if_fail (status == CR_OK) ; +parse_at_media_end_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist) +{ + enum CRStatus status = CR_OK; + + /* + *the current ruleset stmt, child of the + *current at-media being parsed. + */ + CRStatement *stmt = NULL; + + g_return_if_fail (a_this && a_sellist); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & stmt); + g_return_if_fail (status == CR_OK && stmt + && stmt->type == RULESET_STMT); + g_return_if_fail (stmt->kind.ruleset->parent_media_rule); + + status = cr_doc_handler_set_ctxt + (a_this, stmt->kind.ruleset->parent_media_rule); + g_return_if_fail (status == CR_OK); } static void -parse_at_media_end_media_cb (CRDocHandler *a_this, - GList *a_media_list) +parse_at_media_end_media_cb (CRDocHandler * a_this, GList * a_media_list) { - enum CRStatus status = CR_OK ; - CRStatement *at_media = NULL ; - g_return_if_fail (a_this && a_this->priv) ; + enum CRStatus status = CR_OK; + CRStatement *at_media = NULL; - status = cr_doc_handler_get_ctxt (a_this, - (gpointer*)&at_media) ; - g_return_if_fail (status == CR_OK && at_media) ; - - status = cr_doc_handler_set_result (a_this, at_media) ; -} + g_return_if_fail (a_this && a_this->priv); + + status = cr_doc_handler_get_ctxt (a_this, (gpointer *) & at_media); + g_return_if_fail (status == CR_OK && at_media); + status = cr_doc_handler_set_result (a_this, at_media); +} static void -parse_ruleset_start_selector_cb (CRDocHandler *a_this, - CRSelector *a_sellist) +parse_ruleset_start_selector_cb (CRDocHandler * a_this, + CRSelector * a_sellist) { - CRStatement *ruleset = NULL ; + CRStatement *ruleset = NULL; - g_return_if_fail (a_this - && a_this->priv - && a_sellist) ; - - ruleset = cr_statement_new_ruleset (NULL, a_sellist, - NULL, NULL) ; - g_return_if_fail (ruleset) ; + g_return_if_fail (a_this && a_this->priv && a_sellist); - cr_doc_handler_set_result (a_this, ruleset) ; + ruleset = cr_statement_new_ruleset (NULL, a_sellist, NULL, NULL); + g_return_if_fail (ruleset); + + cr_doc_handler_set_result (a_this, ruleset); } static void -parse_ruleset_unrecoverable_error_cb (CRDocHandler *a_this) +parse_ruleset_unrecoverable_error_cb (CRDocHandler * a_this) { - CRStatement *stmt = NULL ; - enum CRStatus status = CR_OK ; + CRStatement *stmt = NULL; + enum CRStatus status = CR_OK; - status = cr_doc_handler_get_result (a_this, (gpointer*)&stmt) ; - if (status != CR_OK) - { + status = cr_doc_handler_get_result (a_this, (gpointer *) & stmt); + if (status != CR_OK) { cr_utils_trace_info ("Couldn't get parsing context. " - "This may lead to some memory leaks.") ; - return ; + "This may lead to some memory leaks."); + return; } - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - cr_doc_handler_set_result (a_this, NULL) ; + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + cr_doc_handler_set_result (a_this, NULL); } } static void -parse_ruleset_property_cb (CRDocHandler *a_this, - GString *a_name, - CRTerm *a_value, - gboolean a_important) +parse_ruleset_property_cb (CRDocHandler * a_this, + GString * a_name, + CRTerm * a_value, gboolean a_important) { - enum CRStatus status = CR_OK ; - CRStatement *ruleset = NULL ; - CRDeclaration *decl = NULL ; - GString * stringue = NULL ; + enum CRStatus status = CR_OK; + CRStatement *ruleset = NULL; + CRDeclaration *decl = NULL; + GString *stringue = NULL; - g_return_if_fail (a_this && a_this->priv && a_name) ; + g_return_if_fail (a_this && a_this->priv && a_name); - stringue = g_string_new (a_name->str) ; - g_return_if_fail (stringue) ; + stringue = g_string_new (a_name->str); + g_return_if_fail (stringue); - status = cr_doc_handler_get_result (a_this, (gpointer *)&ruleset) ; - g_return_if_fail (status == CR_OK - && ruleset && ruleset->type == RULESET_STMT) ; + status = cr_doc_handler_get_result (a_this, (gpointer *) & ruleset); + g_return_if_fail (status == CR_OK + && ruleset && ruleset->type == RULESET_STMT); - decl = cr_declaration_new (ruleset, stringue, a_value) ; - g_return_if_fail (decl) ; - decl->important = a_important ; - status = cr_statement_ruleset_append_decl - (ruleset, decl) ; - g_return_if_fail (status == CR_OK) ; + decl = cr_declaration_new (ruleset, stringue, a_value); + g_return_if_fail (decl); + decl->important = a_important; + status = cr_statement_ruleset_append_decl (ruleset, decl); + g_return_if_fail (status == CR_OK); } static void -parse_ruleset_end_selector_cb (CRDocHandler *a_this, - CRSelector *a_sellist) +parse_ruleset_end_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist) { - CRStatement *result = NULL ; - enum CRStatus status = CR_OK ; + CRStatement *result = NULL; + enum CRStatus status = CR_OK; - g_return_if_fail (a_this && a_sellist) ; + g_return_if_fail (a_this && a_sellist); - status = cr_doc_handler_get_result (a_this, (gpointer *)&result) ; + status = cr_doc_handler_get_result (a_this, (gpointer *) & result); - g_return_if_fail (status == CR_OK - && result - && result->type == RULESET_STMT) ; + g_return_if_fail (status == CR_OK + && result && result->type == RULESET_STMT); } static void -cr_statement_clear (CRStatement *a_this) -{ - g_return_if_fail (a_this) ; - - switch (a_this->type) - { - case AT_RULE_STMT: - break ; - case RULESET_STMT: - if (!a_this->kind.ruleset) - return ; - if (a_this->kind.ruleset->sel_list) - { - cr_selector_unref - (a_this->kind.ruleset->sel_list) ; - a_this->kind.ruleset->sel_list = NULL ; - } - if (a_this->kind.ruleset->decl_list) - { - cr_declaration_destroy - (a_this->kind.ruleset->decl_list) ; - a_this->kind.ruleset->decl_list = NULL ; - } - g_free (a_this->kind.ruleset) ; - a_this->kind.ruleset = NULL ; - break ; - - case AT_IMPORT_RULE_STMT: - if (!a_this->kind.import_rule) - return ; - if (a_this->kind.import_rule->url) - { - g_string_free - (a_this->kind.import_rule->url, - TRUE) ; - a_this->kind.import_rule->url = NULL ; - } - g_free (a_this->kind.import_rule) ; - a_this->kind.import_rule = NULL ; - break ; - - case AT_MEDIA_RULE_STMT: - if (!a_this->kind.media_rule) - return; - if (a_this->kind.media_rule->rulesets) - { - cr_statement_destroy - (a_this->kind.media_rule->rulesets) ; - a_this->kind.media_rule->rulesets = NULL ; - } - if (a_this->kind.media_rule->media_list) - { - GList *cur = NULL ; - - for (cur = a_this->kind.media_rule->media_list; - cur ; cur = cur->next) - { - if (cur->data) - { - g_string_free ((GString*)cur->data, - TRUE) ; - cur->data = NULL ; - } - - } - g_list_free - (a_this->kind.media_rule->media_list) ; - a_this->kind.media_rule->media_list = NULL ; - } - g_free (a_this->kind.media_rule) ; - a_this->kind.media_rule = NULL ; - break ; - - case AT_PAGE_RULE_STMT: - if (!a_this->kind.page_rule) - return ; - - if (a_this->kind.page_rule->decl_list) - { - cr_declaration_destroy - (a_this->kind.page_rule->decl_list) ; - a_this->kind.page_rule->decl_list = NULL ; - } - if (a_this->kind.page_rule->name) - { - g_string_free (a_this->kind.page_rule->name, - TRUE) ; - a_this->kind.page_rule->name = NULL ; - } - if (a_this->kind.page_rule->pseudo) - { - g_string_free (a_this->kind.page_rule->pseudo, - TRUE) ; - a_this->kind.page_rule->pseudo = NULL ; - } - - g_free (a_this->kind.page_rule) ; - a_this->kind.page_rule = NULL ; - break ; - - case AT_CHARSET_RULE_STMT: - if (!a_this->kind.charset_rule) - return ; - - if (a_this->kind.charset_rule->charset) - { - g_string_free - (a_this->kind.charset_rule->charset, - TRUE) ; - a_this->kind.charset_rule->charset = NULL ; - } - g_free (a_this->kind.charset_rule) ; - a_this->kind.charset_rule = NULL; - break ; - - case AT_FONT_FACE_RULE_STMT: - if (!a_this->kind.font_face_rule) - return ; - - if (a_this->kind.font_face_rule->decl_list) - { - cr_declaration_unref - (a_this->kind.font_face_rule->decl_list); - a_this->kind.font_face_rule->decl_list = NULL ; - } - g_free (a_this->kind.font_face_rule) ; - a_this->kind.font_face_rule = NULL ; - break ; - - default: - break ; - } +cr_statement_clear (CRStatement * a_this) +{ + g_return_if_fail (a_this); + + switch (a_this->type) { + case AT_RULE_STMT: + break; + case RULESET_STMT: + if (!a_this->kind.ruleset) + return; + if (a_this->kind.ruleset->sel_list) { + cr_selector_unref (a_this->kind.ruleset->sel_list); + a_this->kind.ruleset->sel_list = NULL; + } + if (a_this->kind.ruleset->decl_list) { + cr_declaration_destroy + (a_this->kind.ruleset->decl_list); + a_this->kind.ruleset->decl_list = NULL; + } + g_free (a_this->kind.ruleset); + a_this->kind.ruleset = NULL; + break; + + case AT_IMPORT_RULE_STMT: + if (!a_this->kind.import_rule) + return; + if (a_this->kind.import_rule->url) { + g_string_free (a_this->kind.import_rule->url, TRUE); + a_this->kind.import_rule->url = NULL; + } + g_free (a_this->kind.import_rule); + a_this->kind.import_rule = NULL; + break; + + case AT_MEDIA_RULE_STMT: + if (!a_this->kind.media_rule) + return; + if (a_this->kind.media_rule->rulesets) { + cr_statement_destroy + (a_this->kind.media_rule->rulesets); + a_this->kind.media_rule->rulesets = NULL; + } + if (a_this->kind.media_rule->media_list) { + GList *cur = NULL; + + for (cur = a_this->kind.media_rule->media_list; + cur; cur = cur->next) { + if (cur->data) { + g_string_free ((GString *) cur->data, + TRUE); + cur->data = NULL; + } + + } + g_list_free (a_this->kind.media_rule->media_list); + a_this->kind.media_rule->media_list = NULL; + } + g_free (a_this->kind.media_rule); + a_this->kind.media_rule = NULL; + break; + + case AT_PAGE_RULE_STMT: + if (!a_this->kind.page_rule) + return; + + if (a_this->kind.page_rule->decl_list) { + cr_declaration_destroy + (a_this->kind.page_rule->decl_list); + a_this->kind.page_rule->decl_list = NULL; + } + if (a_this->kind.page_rule->name) { + g_string_free (a_this->kind.page_rule->name, TRUE); + a_this->kind.page_rule->name = NULL; + } + if (a_this->kind.page_rule->pseudo) { + g_string_free (a_this->kind.page_rule->pseudo, TRUE); + a_this->kind.page_rule->pseudo = NULL; + } + + g_free (a_this->kind.page_rule); + a_this->kind.page_rule = NULL; + break; + + case AT_CHARSET_RULE_STMT: + if (!a_this->kind.charset_rule) + return; + + if (a_this->kind.charset_rule->charset) { + g_string_free + (a_this->kind.charset_rule->charset, TRUE); + a_this->kind.charset_rule->charset = NULL; + } + g_free (a_this->kind.charset_rule); + a_this->kind.charset_rule = NULL; + break; + + case AT_FONT_FACE_RULE_STMT: + if (!a_this->kind.font_face_rule) + return; + + if (a_this->kind.font_face_rule->decl_list) { + cr_declaration_unref + (a_this->kind.font_face_rule->decl_list); + a_this->kind.font_face_rule->decl_list = NULL; + } + g_free (a_this->kind.font_face_rule); + a_this->kind.font_face_rule = NULL; + break; + + default: + break; + } } /** @@ -608,71 +553,62 @@ cr_statement_clear (CRStatement *a_this) *by the caller, using g_free(). */ static gchar * -cr_statement_ruleset_to_string (CRStatement *a_this, glong a_indent) +cr_statement_ruleset_to_string (CRStatement * a_this, glong a_indent) { - GString *stringue = NULL ; - gchar *tmp_str = NULL, *result = NULL ; + GString *stringue = NULL; + gchar *tmp_str = NULL, + *result = NULL; - g_return_val_if_fail (a_this && a_this->type == RULESET_STMT, - NULL) ; - - stringue = g_string_new (NULL) ; - - if (a_this->kind.ruleset->sel_list) - { - if (a_indent) - cr_utils_dump_n_chars2 - (' ', stringue, a_indent) ; - - tmp_str = - cr_selector_to_string (a_this->kind.ruleset->sel_list) ; - if (tmp_str) - { - g_string_append_printf (stringue, - "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + g_return_val_if_fail (a_this && a_this->type == RULESET_STMT, NULL); + + stringue = g_string_new (NULL); + + if (a_this->kind.ruleset->sel_list) { + if (a_indent) + cr_utils_dump_n_chars2 (' ', stringue, a_indent); + + tmp_str = + cr_selector_to_string (a_this->kind.ruleset-> + sel_list); + if (tmp_str) { + g_string_append_printf (stringue, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } - } + } - if (a_this->kind.ruleset->decl_list) - { - g_string_append_printf (stringue," {\n") ; + if (a_this->kind.ruleset->decl_list) { + g_string_append_printf (stringue, " {\n"); - tmp_str = cr_declaration_list_to_string2 + tmp_str = cr_declaration_list_to_string2 (a_this->kind.ruleset->decl_list, - a_indent + DECLARATION_INDENT_NB, - TRUE) ; + a_indent + DECLARATION_INDENT_NB, TRUE); /* - cr_declaration_dump (a_this->kind.ruleset->decl_list, - a_fp, a_indent + DECLARATION_INDENT_NB, - TRUE) ; - */ - if (tmp_str) - { - g_string_append_printf - (stringue, "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + cr_declaration_dump (a_this->kind.ruleset->decl_list, + a_fp, a_indent + DECLARATION_INDENT_NB, + TRUE) ; + */ + if (tmp_str) { + g_string_append_printf (stringue, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } - g_string_append_printf (stringue, "%s", "\n") ; - cr_utils_dump_n_chars2 (' ', stringue, a_indent) ; - g_string_append_printf (stringue ,"%s","}") ; - } - - result = stringue->str ; - - if (stringue) - { - g_string_free (stringue, FALSE) ; - stringue = NULL ; - } - if (tmp_str) - { - g_free (tmp_str) ; - tmp_str = NULL ; - } - return result ; + g_string_append_printf (stringue, "%s", "\n"); + cr_utils_dump_n_chars2 (' ', stringue, a_indent); + g_string_append_printf (stringue, "%s", "}"); + } + + result = stringue->str; + + if (stringue) { + g_string_free (stringue, FALSE); + stringue = NULL; + } + if (tmp_str) { + g_free (tmp_str); + tmp_str = NULL; + } + return result; } /** @@ -682,22 +618,19 @@ cr_statement_ruleset_to_string (CRStatement *a_this, glong a_indent) *@param a_indent the number of indentation white spaces to add. */ static void -cr_statement_dump_ruleset (CRStatement *a_this, FILE *a_fp, glong a_indent) +cr_statement_dump_ruleset (CRStatement * a_this, FILE * a_fp, glong a_indent) { - guchar *str = NULL; + guchar *str = NULL; - g_return_if_fail (a_fp && a_this) ; - str = cr_statement_ruleset_to_string (a_this, a_indent) ; - if (str) - { - fprintf (a_fp, str) ; - g_free (str) ; - str = NULL ; + g_return_if_fail (a_fp && a_this); + str = cr_statement_ruleset_to_string (a_this, a_indent); + if (str) { + fprintf (a_fp, str); + g_free (str); + str = NULL; } } - - /** *TODO: write cr_statement_font_face_rule_to_string() *and make this function use it. @@ -707,25 +640,23 @@ cr_statement_dump_ruleset (CRStatement *a_this, FILE *a_fp, glong a_indent) *@param a_indent the number of white space indentation. */ static void -cr_statement_dump_font_face_rule (CRStatement *a_this , FILE *a_fp, - glong a_indent) -{ - g_return_if_fail (a_this - && a_this->type == AT_FONT_FACE_RULE_STMT) ; - - if (a_this->kind.font_face_rule->decl_list) - { - cr_utils_dump_n_chars (' ', a_fp, a_indent) ; - - if (a_indent) - cr_utils_dump_n_chars (' ', a_fp, a_indent) ; - - fprintf (a_fp,"@font-face {\n") ; - cr_declaration_dump - (a_this->kind.font_face_rule->decl_list, - a_fp, a_indent + DECLARATION_INDENT_NB, TRUE) ; - fprintf (a_fp,"\n}") ; - } +cr_statement_dump_font_face_rule (CRStatement * a_this, FILE * a_fp, + glong a_indent) +{ + g_return_if_fail (a_this && a_this->type == AT_FONT_FACE_RULE_STMT); + + if (a_this->kind.font_face_rule->decl_list) { + cr_utils_dump_n_chars (' ', a_fp, a_indent); + + if (a_indent) + cr_utils_dump_n_chars (' ', a_fp, a_indent); + + fprintf (a_fp, "@font-face {\n"); + cr_declaration_dump + (a_this->kind.font_face_rule->decl_list, + a_fp, a_indent + DECLARATION_INDENT_NB, TRUE); + fprintf (a_fp, "\n}"); + } } /** @@ -735,30 +666,25 @@ cr_statement_dump_font_face_rule (CRStatement *a_this , FILE *a_fp, *@param a_indent the number of indentation white spaces. */ static void -cr_statement_dump_charset (CRStatement *a_this, FILE *a_fp, - gulong a_indent) +cr_statement_dump_charset (CRStatement * a_this, FILE * a_fp, gulong a_indent) { - guchar *str = NULL ; + guchar *str = NULL; + + g_return_if_fail (a_this && a_this->type == AT_CHARSET_RULE_STMT); - g_return_if_fail (a_this - && a_this->type == AT_CHARSET_RULE_STMT) ; - - if (a_this->kind.charset_rule - && a_this->kind.charset_rule->charset) - { - str = g_strndup (a_this->kind.charset_rule->charset->str, - a_this->kind.charset_rule->charset->len) ; + if (a_this->kind.charset_rule && a_this->kind.charset_rule->charset) { + str = g_strndup (a_this->kind.charset_rule->charset->str, + a_this->kind.charset_rule->charset->len); - g_return_if_fail (str) ; + g_return_if_fail (str); - cr_utils_dump_n_chars (' ', a_fp, a_indent) ; - fprintf (a_fp,"@charset \"%s\" ;", str) ; - if (str) - { - g_free (str) ; - str = NULL; - } - } + cr_utils_dump_n_chars (' ', a_fp, a_indent); + fprintf (a_fp, "@charset \"%s\" ;", str); + if (str) { + g_free (str); + str = NULL; + } + } } /** @@ -768,55 +694,48 @@ cr_statement_dump_charset (CRStatement *a_this, FILE *a_fp, *@param a_indent the number of indentation white spaces. */ static void -cr_statement_dump_page (CRStatement *a_this, FILE *a_fp, gulong a_indent) -{ - guchar *str = NULL ; - - g_return_if_fail (a_this - && a_this->type == AT_PAGE_RULE_STMT - && a_this->kind.page_rule) ; - - cr_utils_dump_n_chars (' ', a_fp, a_indent) ; - fprintf (a_fp,"@page") ; - - if (a_this->kind.page_rule->name) - { - str = g_strndup (a_this->kind.page_rule->name->str, - a_this->kind.page_rule->name->len) ; - g_return_if_fail (str) ; - fprintf (a_fp," %s", str) ; - if (str) - { - g_free (str) ; - str = NULL ; - } - } - else - { - fprintf (a_fp," ") ; - } - - if (a_this->kind.page_rule->pseudo) - { - str = g_strndup (a_this->kind.page_rule->pseudo->str, - a_this->kind.page_rule->pseudo->len) ; - g_return_if_fail (str) ; - fprintf (a_fp," :%s", str) ; - if (str) - { - g_free (str) ; - str = NULL ; - } - } - - if (a_this->kind.page_rule->decl_list) - { - fprintf (a_fp," {\n") ; - cr_declaration_dump - (a_this->kind.page_rule->decl_list, - a_fp, a_indent + DECLARATION_INDENT_NB, TRUE) ; - fprintf (a_fp,"\n}\n") ; - } +cr_statement_dump_page (CRStatement * a_this, FILE * a_fp, gulong a_indent) +{ + guchar *str = NULL; + + g_return_if_fail (a_this + && a_this->type == AT_PAGE_RULE_STMT + && a_this->kind.page_rule); + + cr_utils_dump_n_chars (' ', a_fp, a_indent); + fprintf (a_fp, "@page"); + + if (a_this->kind.page_rule->name) { + str = g_strndup (a_this->kind.page_rule->name->str, + a_this->kind.page_rule->name->len); + g_return_if_fail (str); + fprintf (a_fp, " %s", str); + if (str) { + g_free (str); + str = NULL; + } + } else { + fprintf (a_fp, " "); + } + + if (a_this->kind.page_rule->pseudo) { + str = g_strndup (a_this->kind.page_rule->pseudo->str, + a_this->kind.page_rule->pseudo->len); + g_return_if_fail (str); + fprintf (a_fp, " :%s", str); + if (str) { + g_free (str); + str = NULL; + } + } + + if (a_this->kind.page_rule->decl_list) { + fprintf (a_fp, " {\n"); + cr_declaration_dump + (a_this->kind.page_rule->decl_list, + a_fp, a_indent + DECLARATION_INDENT_NB, TRUE); + fprintf (a_fp, "\n}\n"); + } } /** @@ -825,16 +744,16 @@ cr_statement_dump_page (CRStatement *a_this, FILE *a_fp, gulong a_indent) *@return number of rules in the statement list. */ int -cr_statement_nr_rules (CRStatement *a_this) +cr_statement_nr_rules (CRStatement * a_this) { - CRStatement *cur = NULL ; - int nr = 0; + CRStatement *cur = NULL; + int nr = 0; - g_return_val_if_fail (a_this, -1) ; + g_return_val_if_fail (a_this, -1); - for (cur = a_this ; cur ; cur = cur->next) - nr ++; - return nr; + for (cur = a_this; cur; cur = cur->next) + nr++; + return nr; } /** @@ -845,17 +764,17 @@ cr_statement_nr_rules (CRStatement *a_this) *it will return NULL. */ CRStatement * -cr_statement_get_from_list (CRStatement *a_this, int itemnr) +cr_statement_get_from_list (CRStatement * a_this, int itemnr) { - CRStatement *cur = NULL ; - int nr = 0; + CRStatement *cur = NULL; + int nr = 0; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - for (cur = a_this ; cur ; cur = cur->next) - if (nr++ == itemnr) - return cur; - return NULL; + for (cur = a_this; cur; cur = cur->next) + if (nr++ == itemnr) + return cur; + return NULL; } /** @@ -865,41 +784,38 @@ cr_statement_get_from_list (CRStatement *a_this, int itemnr) *@param a_indent the number of white spaces indentation. */ static void -cr_statement_dump_media_rule (CRStatement *a_this, FILE *a_fp, - gulong a_indent) -{ - GList *cur = NULL ; - - g_return_if_fail (a_this->type == AT_MEDIA_RULE_STMT) ; - - if (a_this->kind.media_rule) - { - cr_utils_dump_n_chars (' ', a_fp, a_indent) ; - fprintf (a_fp,"@media") ; - for (cur = a_this->kind.media_rule->media_list ; cur ; - cur = cur->next) - { - if (cur->data) - { - guchar *str = g_strndup - (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; - if (str) - { - if (cur->prev) - { - fprintf (a_fp,",") ; - } - fprintf (a_fp," %s", str) ; - g_free (str) ; str = NULL ; - } - } - } - fprintf (a_fp," {\n") ; - cr_statement_dump (a_this->kind.media_rule->rulesets, - a_fp, a_indent + DECLARATION_INDENT_NB) ; - fprintf (a_fp,"\n}") ; - } +cr_statement_dump_media_rule (CRStatement * a_this, FILE * a_fp, + gulong a_indent) +{ + GList *cur = NULL; + + g_return_if_fail (a_this->type == AT_MEDIA_RULE_STMT); + + if (a_this->kind.media_rule) { + cr_utils_dump_n_chars (' ', a_fp, a_indent); + fprintf (a_fp, "@media"); + for (cur = a_this->kind.media_rule->media_list; cur; + cur = cur->next) { + if (cur->data) { + guchar *str = g_strndup + (((GString *) cur->data)->str, + ((GString *) cur->data)->len); + + if (str) { + if (cur->prev) { + fprintf (a_fp, ","); + } + fprintf (a_fp, " %s", str); + g_free (str); + str = NULL; + } + } + } + fprintf (a_fp, " {\n"); + cr_statement_dump (a_this->kind.media_rule->rulesets, + a_fp, a_indent + DECLARATION_INDENT_NB); + fprintf (a_fp, "\n}"); + } } /** @@ -908,60 +824,51 @@ cr_statement_dump_media_rule (CRStatement *a_this, FILE *a_fp, *@param a_indent the number of white space indentations. */ static void -cr_statement_dump_import_rule (CRStatement *a_this, FILE *a_fp, - gulong a_indent) -{ - g_return_if_fail (a_this - && a_this->type == AT_IMPORT_RULE_STMT - && a_this->kind.import_rule) ; - - if (a_this->kind.import_rule->url) - { - guchar *str = NULL ; - - str = g_strndup (a_this->kind.import_rule->url->str, - a_this->kind.import_rule->url->len) ; - cr_utils_dump_n_chars (' ', a_fp, a_indent) ; - - if (str) - { - fprintf (a_fp,"@import url(\"%s\")", str) ; - g_free (str) ; - } - else /*there is no url, so no import rule, get out!*/ - return ; - - if (a_this->kind.import_rule->media_list) - { - GList *cur = NULL ; - - for (cur = a_this->kind.import_rule->media_list ; - cur; cur = cur->next) - { - if (cur->data) - { - GString *gstr = cur->data ; - - if (cur->prev) - { - fprintf (a_fp,", ") ; - } - - str = g_strndup (gstr->str, - gstr->len) ; - if (str) - { - fprintf (a_fp,str) ; - g_free (str) ; - } - } - } - } - fprintf (a_fp," ;") ; - } +cr_statement_dump_import_rule (CRStatement * a_this, FILE * a_fp, + gulong a_indent) +{ + g_return_if_fail (a_this + && a_this->type == AT_IMPORT_RULE_STMT + && a_this->kind.import_rule); + + if (a_this->kind.import_rule->url) { + guchar *str = NULL; + + str = g_strndup (a_this->kind.import_rule->url->str, + a_this->kind.import_rule->url->len); + cr_utils_dump_n_chars (' ', a_fp, a_indent); + + if (str) { + fprintf (a_fp, "@import url(\"%s\")", str); + g_free (str); + } else /*there is no url, so no import rule, get out! */ + return; + + if (a_this->kind.import_rule->media_list) { + GList *cur = NULL; + + for (cur = a_this->kind.import_rule->media_list; + cur; cur = cur->next) { + if (cur->data) { + GString *gstr = cur->data; + + if (cur->prev) { + fprintf (a_fp, ", "); + } + + str = g_strndup (gstr->str, + gstr->len); + if (str) { + fprintf (a_fp, str); + g_free (str); + } + } + } + } + fprintf (a_fp, " ;"); + } } - /******************* *public functions ******************/ @@ -975,36 +882,33 @@ cr_statement_dump_import_rule (CRStatement *a_this, FILE *a_fp, *@return TRUE if the buffer parses against the core grammar, false otherwise. */ gboolean -cr_statement_does_buf_parses_against_core (const guchar *a_buf, +cr_statement_does_buf_parses_against_core (const guchar * a_buf, enum CREncoding a_encoding) { - CRParser *parser = NULL ; - enum CRStatus status = CR_OK ; - gboolean result = FALSE ; + CRParser *parser = NULL; + enum CRStatus status = CR_OK; + gboolean result = FALSE; parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_encoding, FALSE) ; - g_return_val_if_fail (parser, FALSE) ; + a_encoding, FALSE); + g_return_val_if_fail (parser, FALSE); - status = cr_parser_set_use_core_grammar (parser, TRUE) ; - if (status != CR_OK) - { - goto cleanup ; + status = cr_parser_set_use_core_grammar (parser, TRUE); + if (status != CR_OK) { + goto cleanup; } - - status = cr_parser_parse_statement_core (parser) ; - if (status == CR_OK) - { - result = TRUE ; + + status = cr_parser_parse_statement_core (parser); + if (status == CR_OK) { + result = TRUE; } - cleanup: - if (parser) - { - cr_parser_destroy (parser) ; + cleanup: + if (parser) { + cr_parser_destroy (parser); } - return result ; + return result; } /** @@ -1017,83 +921,64 @@ cr_statement_does_buf_parses_against_core (const guchar *a_buf, *of successfull parsing, NULL otherwise. */ CRStatement * -cr_statement_parse_from_buf (const guchar *a_buf, - enum CREncoding a_encoding) -{ - CRStatement *result = NULL ; - - /* - *The strategy of this function is "brute force". - *It tries to parse all the types of #CRStatement it knows about. - *I could do this a smarter way but I don't have the time now. - *I think I will revisit this when time of performances and - *pull based incremental parsing comes. - */ - - result = cr_statement_ruleset_parse_from_buf (a_buf, a_encoding) ; - if (!result) - { - result = cr_statement_at_charset_rule_parse_from_buf - (a_buf, a_encoding) ; - } - else - { - goto out ; - } - - if (!result) - { - result = cr_statement_at_media_rule_parse_from_buf - (a_buf, a_encoding) ; - } - else - { - goto out ; - } - - if (!result) - { - result = cr_statement_at_charset_rule_parse_from_buf - (a_buf, a_encoding) ; - } - else - { - goto out ; - } - - if (!result) - { - result = cr_statement_font_face_rule_parse_from_buf - (a_buf, a_encoding) ; - - } - else - { - goto out ; - } - - if (!result) - { - result = cr_statement_at_page_rule_parse_from_buf - (a_buf, a_encoding) ; - } - else - { - goto out ; - } - - if (!result) - { - result = cr_statement_at_import_rule_parse_from_buf - (a_buf, a_encoding) ; - } - else - { - goto out ; - } - - out: - return result ; +cr_statement_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) +{ + CRStatement *result = NULL; + + /* + *The strategy of this function is "brute force". + *It tries to parse all the types of #CRStatement it knows about. + *I could do this a smarter way but I don't have the time now. + *I think I will revisit this when time of performances and + *pull based incremental parsing comes. + */ + + result = cr_statement_ruleset_parse_from_buf (a_buf, a_encoding); + if (!result) { + result = cr_statement_at_charset_rule_parse_from_buf + (a_buf, a_encoding); + } else { + goto out; + } + + if (!result) { + result = cr_statement_at_media_rule_parse_from_buf + (a_buf, a_encoding); + } else { + goto out; + } + + if (!result) { + result = cr_statement_at_charset_rule_parse_from_buf + (a_buf, a_encoding); + } else { + goto out; + } + + if (!result) { + result = cr_statement_font_face_rule_parse_from_buf + (a_buf, a_encoding); + + } else { + goto out; + } + + if (!result) { + result = cr_statement_at_page_rule_parse_from_buf + (a_buf, a_encoding); + } else { + goto out; + } + + if (!result) { + result = cr_statement_at_import_rule_parse_from_buf + (a_buf, a_encoding); + } else { + goto out; + } + + out: + return result; } /** @@ -1106,60 +991,54 @@ cr_statement_parse_from_buf (const guchar *a_buf, */ CRStatement * cr_statement_ruleset_parse_from_buf (const guchar * a_buf, - enum CREncoding a_enc) -{ - enum CRStatus status = CR_OK ; - CRStatement *result = NULL; - CRParser *parser = NULL ; - CRDocHandler *sac_handler = NULL ; - - g_return_val_if_fail (a_buf, NULL) ; - - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_enc, FALSE) ; - - g_return_val_if_fail (parser, NULL) ; - - sac_handler = cr_doc_handler_new () ; - g_return_val_if_fail (parser, NULL) ; - - sac_handler->start_selector = parse_ruleset_start_selector_cb ; - sac_handler->end_selector = parse_ruleset_end_selector_cb ; - sac_handler->property = parse_ruleset_property_cb ; - sac_handler->unrecoverable_error = - parse_ruleset_unrecoverable_error_cb ; - - cr_parser_set_sac_handler (parser, sac_handler) ; - cr_parser_try_to_skip_spaces_and_comments (parser) ; - status = cr_parser_parse_ruleset (parser) ; - if (status != CR_OK) - { - goto cleanup ; - } - - status = cr_doc_handler_get_result (sac_handler, - (gpointer*)&result) ; - if (! ((status == CR_OK) && result) ) - { - if (result) - { - cr_statement_destroy (result) ; - result = NULL ; - } - } - - cleanup: - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - if (sac_handler) - { - cr_doc_handler_unref (sac_handler) ; - sac_handler = NULL ; - } - return result ; + enum CREncoding a_enc) +{ + enum CRStatus status = CR_OK; + CRStatement *result = NULL; + CRParser *parser = NULL; + CRDocHandler *sac_handler = NULL; + + g_return_val_if_fail (a_buf, NULL); + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), a_enc, FALSE); + + g_return_val_if_fail (parser, NULL); + + sac_handler = cr_doc_handler_new (); + g_return_val_if_fail (parser, NULL); + + sac_handler->start_selector = parse_ruleset_start_selector_cb; + sac_handler->end_selector = parse_ruleset_end_selector_cb; + sac_handler->property = parse_ruleset_property_cb; + sac_handler->unrecoverable_error = + parse_ruleset_unrecoverable_error_cb; + + cr_parser_set_sac_handler (parser, sac_handler); + cr_parser_try_to_skip_spaces_and_comments (parser); + status = cr_parser_parse_ruleset (parser); + if (status != CR_OK) { + goto cleanup; + } + + status = cr_doc_handler_get_result (sac_handler, + (gpointer *) & result); + if (!((status == CR_OK) && result)) { + if (result) { + cr_statement_destroy (result); + result = NULL; + } + } + + cleanup: + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + if (sac_handler) { + cr_doc_handler_unref (sac_handler); + sac_handler = NULL; + } + return result; } /** @@ -1174,64 +1053,59 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf, *@return the new instance of #CRStatement or NULL if something *went wrong. */ -CRStatement* +CRStatement * cr_statement_new_ruleset (CRStyleSheet * a_sheet, - CRSelector *a_sel_list, - CRDeclaration *a_decl_list, - CRStatement *a_parent_media_rule) -{ - CRStatement *result = NULL ; - - g_return_val_if_fail (a_sel_list, NULL) ; - - if (a_parent_media_rule) - { - g_return_val_if_fail - (a_parent_media_rule->type == AT_MEDIA_RULE_STMT, - NULL) ; - g_return_val_if_fail (a_parent_media_rule->kind.media_rule, - NULL) ; - } - - result = g_try_malloc (sizeof (CRStatement)) ; - - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - - memset (result, 0, sizeof (CRStatement)) ; - result->type = RULESET_STMT ; - result->kind.ruleset = g_try_malloc (sizeof (CRRuleSet)) ; - - if (!result->kind.ruleset) - { - cr_utils_trace_info ("Out of memory") ; - if (result) g_free (result) ; - return NULL ; - } - - memset (result->kind.ruleset, 0, sizeof (CRRuleSet)) ; - result->kind.ruleset->sel_list = a_sel_list; - if (a_sel_list) - cr_selector_ref (a_sel_list) ; - result->kind.ruleset->decl_list = a_decl_list; - - if (a_parent_media_rule) - { - result->kind.ruleset->parent_media_rule = - a_parent_media_rule; - a_parent_media_rule->kind.media_rule->rulesets = - cr_statement_append - (a_parent_media_rule->kind.media_rule->rulesets, - result) ; - } - - - cr_statement_set_parent_sheet (result, a_sheet) ; - - return result ; + CRSelector * a_sel_list, + CRDeclaration * a_decl_list, + CRStatement * a_parent_media_rule) +{ + CRStatement *result = NULL; + + g_return_val_if_fail (a_sel_list, NULL); + + if (a_parent_media_rule) { + g_return_val_if_fail + (a_parent_media_rule->type == AT_MEDIA_RULE_STMT, + NULL); + g_return_val_if_fail (a_parent_media_rule->kind.media_rule, + NULL); + } + + result = g_try_malloc (sizeof (CRStatement)); + + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + + memset (result, 0, sizeof (CRStatement)); + result->type = RULESET_STMT; + result->kind.ruleset = g_try_malloc (sizeof (CRRuleSet)); + + if (!result->kind.ruleset) { + cr_utils_trace_info ("Out of memory"); + if (result) + g_free (result); + return NULL; + } + + memset (result->kind.ruleset, 0, sizeof (CRRuleSet)); + result->kind.ruleset->sel_list = a_sel_list; + if (a_sel_list) + cr_selector_ref (a_sel_list); + result->kind.ruleset->decl_list = a_decl_list; + + if (a_parent_media_rule) { + result->kind.ruleset->parent_media_rule = a_parent_media_rule; + a_parent_media_rule->kind.media_rule->rulesets = + cr_statement_append + (a_parent_media_rule->kind.media_rule->rulesets, + result); + } + + cr_statement_set_parent_sheet (result, a_sheet); + + return result; } /** @@ -1243,74 +1117,64 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, *be successfully parsed. */ CRStatement * -cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf, - enum CREncoding a_enc) -{ - CRParser *parser = NULL ; - CRStatement *result = NULL ; - CRDocHandler *sac_handler = NULL ; - enum CRStatus status = CR_OK ; - - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_enc, FALSE) ; - if (!parser) - { - cr_utils_trace_info ("Instanciation of the parser failed") ; - goto cleanup ; - } - - sac_handler = cr_doc_handler_new () ; - if (!sac_handler) - { - cr_utils_trace_info ("Instanciation of the sac handler failed") ; - goto cleanup ; - } - - sac_handler->start_media = - parse_at_media_start_media_cb ; - sac_handler->start_selector = - parse_at_media_start_selector_cb ; - sac_handler->property = - parse_at_media_property_cb ; - sac_handler->end_selector = - parse_at_media_end_selector_cb ; - sac_handler->end_media = - parse_at_media_end_media_cb ; +cr_statement_at_media_rule_parse_from_buf (const guchar * a_buf, + enum CREncoding a_enc) +{ + CRParser *parser = NULL; + CRStatement *result = NULL; + CRDocHandler *sac_handler = NULL; + enum CRStatus status = CR_OK; + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), a_enc, FALSE); + if (!parser) { + cr_utils_trace_info ("Instanciation of the parser failed"); + goto cleanup; + } + + sac_handler = cr_doc_handler_new (); + if (!sac_handler) { + cr_utils_trace_info + ("Instanciation of the sac handler failed"); + goto cleanup; + } + + sac_handler->start_media = parse_at_media_start_media_cb; + sac_handler->start_selector = parse_at_media_start_selector_cb; + sac_handler->property = parse_at_media_property_cb; + sac_handler->end_selector = parse_at_media_end_selector_cb; + sac_handler->end_media = parse_at_media_end_media_cb; sac_handler->unrecoverable_error = - parse_at_media_unrecoverable_error_cb ; - - status = cr_parser_set_sac_handler (parser, sac_handler) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_parser_try_to_skip_spaces_and_comments (parser) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_parser_parse_media (parser) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_doc_handler_get_result (sac_handler, - (gpointer*)&result) ; - if (status != CR_OK) - goto cleanup ; - - - cleanup: - - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - if (sac_handler) - { - cr_doc_handler_unref (sac_handler) ; - sac_handler = NULL ; - } - - return result ; + parse_at_media_unrecoverable_error_cb; + + status = cr_parser_set_sac_handler (parser, sac_handler); + if (status != CR_OK) + goto cleanup; + + status = cr_parser_try_to_skip_spaces_and_comments (parser); + if (status != CR_OK) + goto cleanup; + + status = cr_parser_parse_media (parser); + if (status != CR_OK) + goto cleanup; + + status = cr_doc_handler_get_result (sac_handler, + (gpointer *) & result); + if (status != CR_OK) + goto cleanup; + + cleanup: + + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + if (sac_handler) { + cr_doc_handler_unref (sac_handler); + sac_handler = NULL; + } + + return result; } /** @@ -1321,60 +1185,53 @@ cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf, *@param a_media, the media string list. A list of GString pointers. */ CRStatement * -cr_statement_new_at_media_rule (CRStyleSheet *a_sheet, - CRStatement *a_rulesets, - GList *a_media) -{ - CRStatement *result = NULL, *cur = NULL ; - - if (a_rulesets) - g_return_val_if_fail (a_rulesets->type == RULESET_STMT, - NULL) ; - - result = g_try_malloc (sizeof (CRStatement)) ; - - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - - memset (result, 0, sizeof (CRStatement)) ; - result->type = AT_MEDIA_RULE_STMT ; - - result->kind.media_rule = g_try_malloc (sizeof (CRAtMediaRule)) ; - if (!result->kind.media_rule) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } - memset (result->kind.media_rule, 0, sizeof (CRAtMediaRule)) ; - result->kind.media_rule->rulesets = a_rulesets ; - for (cur = a_rulesets ; cur ; cur = cur->next) - { - if (cur->type != RULESET_STMT || !cur->kind.ruleset) - { - cr_utils_trace_info ("Bad parameter a_rulesets. " - "It should be a list of " - "correct ruleset statement only !"); - goto error ; - } - cur->kind.ruleset->parent_media_rule = result ; - } - - result->kind.media_rule->media_list = a_media ; - if (a_sheet) - { - cr_statement_set_parent_sheet (result, a_sheet) ; - } - - return result ; - - error: - return NULL ; -} +cr_statement_new_at_media_rule (CRStyleSheet * a_sheet, + CRStatement * a_rulesets, GList * a_media) +{ + CRStatement *result = NULL, + *cur = NULL; + + if (a_rulesets) + g_return_val_if_fail (a_rulesets->type == RULESET_STMT, NULL); + + result = g_try_malloc (sizeof (CRStatement)); + + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + + memset (result, 0, sizeof (CRStatement)); + result->type = AT_MEDIA_RULE_STMT; + result->kind.media_rule = g_try_malloc (sizeof (CRAtMediaRule)); + if (!result->kind.media_rule) { + cr_utils_trace_info ("Out of memory"); + g_free (result); + return NULL; + } + memset (result->kind.media_rule, 0, sizeof (CRAtMediaRule)); + result->kind.media_rule->rulesets = a_rulesets; + for (cur = a_rulesets; cur; cur = cur->next) { + if (cur->type != RULESET_STMT || !cur->kind.ruleset) { + cr_utils_trace_info ("Bad parameter a_rulesets. " + "It should be a list of " + "correct ruleset statement only !"); + goto error; + } + cur->kind.ruleset->parent_media_rule = result; + } + + result->kind.media_rule->media_list = a_media; + if (a_sheet) { + cr_statement_set_parent_sheet (result, a_sheet); + } + + return result; + + error: + return NULL; +} /** *Creates a new instance of #CRStatment of type @@ -1384,43 +1241,40 @@ cr_statement_new_at_media_rule (CRStyleSheet *a_sheet, *@param a_sheet the imported parsed stylesheet. *@return the newly built instance of #CRStatement. */ -CRStatement* -cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet, - GString *a_url, - GList *a_media_list, - CRStyleSheet *a_imported_sheet) -{ - CRStatement *result = NULL ; - - result = g_try_malloc (sizeof (CRStatement)) ; - - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - - memset (result, 0, sizeof (CRStatement)) ; - result->type = AT_IMPORT_RULE_STMT ; - - result->kind.import_rule = - g_try_malloc (sizeof (CRAtImportRule)) ; - - if (!result->kind.import_rule) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } - - memset (result->kind.import_rule, 0, sizeof (CRAtImportRule)) ; - result->kind.import_rule->url = a_url; - result->kind.import_rule->media_list = a_media_list ; - result->kind.import_rule->sheet = a_imported_sheet; +CRStatement * +cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet, + GString * a_url, + GList * a_media_list, + CRStyleSheet * a_imported_sheet) +{ + CRStatement *result = NULL; + + result = g_try_malloc (sizeof (CRStatement)); + + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + + memset (result, 0, sizeof (CRStatement)); + result->type = AT_IMPORT_RULE_STMT; + + result->kind.import_rule = g_try_malloc (sizeof (CRAtImportRule)); + + if (!result->kind.import_rule) { + cr_utils_trace_info ("Out of memory"); + g_free (result); + return NULL; + } + + memset (result->kind.import_rule, 0, sizeof (CRAtImportRule)); + result->kind.import_rule->url = a_url; + result->kind.import_rule->media_list = a_media_list; + result->kind.import_rule->sheet = a_imported_sheet; if (a_container_sheet) - cr_statement_set_parent_sheet (result, a_container_sheet) ; + cr_statement_set_parent_sheet (result, a_container_sheet); - return result ; + return result; } /** @@ -1435,65 +1289,58 @@ CRStatement * cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { - enum CRStatus status = CR_OK ; - CRParser *parser = NULL ; - CRStatement *result = NULL ; - GList *media_list = NULL ; - GString *import_string = NULL ; + enum CRStatus status = CR_OK; + CRParser *parser = NULL; + CRStatement *result = NULL; + GList *media_list = NULL; + GString *import_string = NULL; parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_encoding, FALSE) ; - if (!parser) - { - cr_utils_trace_info ("Instanciation of parser failed.") ; - goto cleanup ; + a_encoding, FALSE); + if (!parser) { + cr_utils_trace_info ("Instanciation of parser failed."); + goto cleanup; } - status = cr_parser_try_to_skip_spaces_and_comments (parser) ; + status = cr_parser_try_to_skip_spaces_and_comments (parser); if (status != CR_OK) - goto cleanup ; + goto cleanup; - status = cr_parser_parse_import (parser, &media_list, - &import_string) ; + status = cr_parser_parse_import (parser, &media_list, &import_string); if (status != CR_OK || !import_string) - goto cleanup ; + goto cleanup; result = cr_statement_new_at_import_rule (NULL, import_string, - media_list, NULL) ; - if (result) - { - import_string = NULL ; - media_list = NULL ; - } - - cleanup: - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - if (media_list) - { - GList *cur = NULL ; - for (cur = media_list; media_list; - media_list = g_list_next (media_list)) - { - if (media_list->data) - { + media_list, NULL); + if (result) { + import_string = NULL; + media_list = NULL; + } + + cleanup: + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + if (media_list) { + GList *cur = NULL; + + for (cur = media_list; media_list; + media_list = g_list_next (media_list)) { + if (media_list->data) { g_string_free (media_list->data, TRUE); - media_list->data = NULL ; + media_list->data = NULL; } } - g_list_free (media_list) ; + g_list_free (media_list); media_list = NULL; } - if (import_string) - { - g_string_free (import_string, TRUE) ; + if (import_string) { + g_string_free (import_string, TRUE); import_string = NULL; } - return result ; + return result; } /** @@ -1507,46 +1354,41 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf, *in case of error. */ CRStatement * -cr_statement_new_at_page_rule (CRStyleSheet *a_sheet, - CRDeclaration *a_decl_list, - GString *a_name, - GString *a_pseudo) +cr_statement_new_at_page_rule (CRStyleSheet * a_sheet, + CRDeclaration * a_decl_list, + GString * a_name, GString * a_pseudo) { - CRStatement *result = NULL ; - + CRStatement *result = NULL; - result = g_try_malloc (sizeof (CRStatement)) ; + result = g_try_malloc (sizeof (CRStatement)); - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - memset (result, 0, sizeof (CRStatement)) ; - result->type = AT_PAGE_RULE_STMT ; + memset (result, 0, sizeof (CRStatement)); + result->type = AT_PAGE_RULE_STMT; - result->kind.page_rule = g_try_malloc (sizeof (CRAtPageRule)) ; + result->kind.page_rule = g_try_malloc (sizeof (CRAtPageRule)); - if (!result->kind.page_rule) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } + if (!result->kind.page_rule) { + cr_utils_trace_info ("Out of memory"); + g_free (result); + return NULL; + } - memset (result->kind.page_rule, 0, sizeof (CRAtPageRule)) ; - if (a_decl_list) - { - result->kind.page_rule->decl_list = a_decl_list; - cr_declaration_ref (a_decl_list) ; - } - result->kind.page_rule->name = a_name ; - result->kind.page_rule->name = a_pseudo ; - if (a_sheet) - cr_statement_set_parent_sheet (result, a_sheet) ; + memset (result->kind.page_rule, 0, sizeof (CRAtPageRule)); + if (a_decl_list) { + result->kind.page_rule->decl_list = a_decl_list; + cr_declaration_ref (a_decl_list); + } + result->kind.page_rule->name = a_name; + result->kind.page_rule->name = a_pseudo; + if (a_sheet) + cr_statement_set_parent_sheet (result, a_sheet); - return result ; + return result; } /** @@ -1558,70 +1400,62 @@ cr_statement_new_at_page_rule (CRStyleSheet *a_sheet, *NULL otherwise. */ CRStatement * -cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf, - enum CREncoding a_encoding) -{ - enum CRStatus status = CR_OK ; - CRParser *parser = NULL ; - CRDocHandler *sac_handler = NULL ; - CRStatement *result = NULL ; - - g_return_val_if_fail (a_buf, NULL) ; - - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_encoding, FALSE) ; - if (!parser) - { - cr_utils_trace_info ("Instanciation of the parser failed.") ; - goto cleanup ; - } - - sac_handler = cr_doc_handler_new () ; - if (!sac_handler) - { - cr_utils_trace_info - ("Instanciation of the sac handler failed.") ; - goto cleanup ; - } - - sac_handler->start_page = - parse_page_start_page_cb ; - sac_handler->property = - parse_page_property_cb ; - sac_handler->end_page = - parse_page_end_page_cb ; - sac_handler->unrecoverable_error = - parse_page_unrecoverable_error_cb ; - - status = cr_parser_set_sac_handler (parser, sac_handler) ; - if (status != CR_OK) - goto cleanup ; - - /*Now, invoke the parser to parse the "@page production"*/ - cr_parser_try_to_skip_spaces_and_comments (parser) ; - if (status != CR_OK) - goto cleanup ; - status = cr_parser_parse_page (parser) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_doc_handler_get_result (sac_handler, - (gpointer*)&result) ; - - cleanup: - - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - if (sac_handler) - { - cr_doc_handler_unref (sac_handler) ; - sac_handler = NULL ; - } - return result ; - +cr_statement_at_page_rule_parse_from_buf (const guchar * a_buf, + enum CREncoding a_encoding) +{ + enum CRStatus status = CR_OK; + CRParser *parser = NULL; + CRDocHandler *sac_handler = NULL; + CRStatement *result = NULL; + + g_return_val_if_fail (a_buf, NULL); + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + a_encoding, FALSE); + if (!parser) { + cr_utils_trace_info ("Instanciation of the parser failed."); + goto cleanup; + } + + sac_handler = cr_doc_handler_new (); + if (!sac_handler) { + cr_utils_trace_info + ("Instanciation of the sac handler failed."); + goto cleanup; + } + + sac_handler->start_page = parse_page_start_page_cb; + sac_handler->property = parse_page_property_cb; + sac_handler->end_page = parse_page_end_page_cb; + sac_handler->unrecoverable_error = parse_page_unrecoverable_error_cb; + + status = cr_parser_set_sac_handler (parser, sac_handler); + if (status != CR_OK) + goto cleanup; + + /*Now, invoke the parser to parse the "@page production" */ + cr_parser_try_to_skip_spaces_and_comments (parser); + if (status != CR_OK) + goto cleanup; + status = cr_parser_parse_page (parser); + if (status != CR_OK) + goto cleanup; + + status = cr_doc_handler_get_result (sac_handler, + (gpointer *) & result); + + cleanup: + + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + if (sac_handler) { + cr_doc_handler_unref (sac_handler); + sac_handler = NULL; + } + return result; + } /** @@ -1634,38 +1468,34 @@ cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf, *if an error arises. */ CRStatement * -cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet, - GString *a_charset) +cr_statement_new_at_charset_rule (CRStyleSheet * a_sheet, GString * a_charset) { - CRStatement * result = NULL ; + CRStatement *result = NULL; - g_return_val_if_fail (a_charset, NULL) ; + g_return_val_if_fail (a_charset, NULL); - result = g_try_malloc (sizeof (CRStatement)) ; + result = g_try_malloc (sizeof (CRStatement)); - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - memset (result, 0, sizeof (CRStatement)) ; - result->type = AT_CHARSET_RULE_STMT ; + memset (result, 0, sizeof (CRStatement)); + result->type = AT_CHARSET_RULE_STMT; - result->kind.charset_rule = g_try_malloc - (sizeof (CRAtCharsetRule)) ; + result->kind.charset_rule = g_try_malloc (sizeof (CRAtCharsetRule)); - if (!result->kind.charset_rule) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } - memset (result->kind.charset_rule, 0, sizeof (CRAtCharsetRule)) ; - result->kind.charset_rule->charset = a_charset ; - cr_statement_set_parent_sheet (result, a_sheet) ; + if (!result->kind.charset_rule) { + cr_utils_trace_info ("Out of memory"); + g_free (result); + return NULL; + } + memset (result->kind.charset_rule, 0, sizeof (CRAtCharsetRule)); + result->kind.charset_rule->charset = a_charset; + cr_statement_set_parent_sheet (result, a_sheet); - return result ; + return result; } /** @@ -1676,49 +1506,46 @@ cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet, *@return the newly built instance of #CRStatement. */ CRStatement * -cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf, - enum CREncoding a_encoding) -{ - enum CRStatus status = CR_OK ; - CRParser *parser = NULL ; - CRStatement *result = NULL ; - GString *charset = NULL ; - - g_return_val_if_fail (a_buf, NULL) ; - - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_encoding, FALSE) ; - if (!parser) - { - cr_utils_trace_info ("Instanciation of the parser failed.") ; - goto cleanup ; - } - - /*Now, invoke the parser to parse the "@charset production"*/ - cr_parser_try_to_skip_spaces_and_comments (parser) ; - if (status != CR_OK) - goto cleanup ; - status = cr_parser_parse_charset (parser, &charset) ; - if (status != CR_OK || !charset) - goto cleanup ; - - result = cr_statement_new_at_charset_rule (NULL, charset) ; - if (result) - charset = NULL ; - - cleanup: - - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - if (charset) - { - g_string_free (charset, TRUE) ; - } - - return result ; +cr_statement_at_charset_rule_parse_from_buf (const guchar * a_buf, + enum CREncoding a_encoding) +{ + enum CRStatus status = CR_OK; + CRParser *parser = NULL; + CRStatement *result = NULL; + GString *charset = NULL; + + g_return_val_if_fail (a_buf, NULL); + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + a_encoding, FALSE); + if (!parser) { + cr_utils_trace_info ("Instanciation of the parser failed."); + goto cleanup; + } + + /*Now, invoke the parser to parse the "@charset production" */ + cr_parser_try_to_skip_spaces_and_comments (parser); + if (status != CR_OK) + goto cleanup; + status = cr_parser_parse_charset (parser, &charset); + if (status != CR_OK || !charset) + goto cleanup; + + result = cr_statement_new_at_charset_rule (NULL, charset); + if (result) + charset = NULL; + + cleanup: + + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + if (charset) { + g_string_free (charset, TRUE); + } + + return result; } /** @@ -1728,38 +1555,35 @@ cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf, *@return the newly built instance of #CRStatement. */ CRStatement * -cr_statement_new_at_font_face_rule (CRStyleSheet *a_sheet, - CRDeclaration *a_font_decls) -{ - CRStatement *result = NULL ; - - result = g_try_malloc (sizeof (CRStatement)) ; - - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRStatement)) ; - result->type = AT_FONT_FACE_RULE_STMT ; - - result->kind.font_face_rule = g_try_malloc - (sizeof (CRAtFontFaceRule)) ; - - if (!result->kind.font_face_rule) - { - cr_utils_trace_info ("Out of memory") ; - g_free (result) ; - return NULL ; - } - memset (result->kind.font_face_rule, 0, - sizeof (CRAtFontFaceRule)); - - result->kind.font_face_rule->decl_list = a_font_decls ; - if (a_sheet) - cr_statement_set_parent_sheet (result, a_sheet) ; - - return result ; +cr_statement_new_at_font_face_rule (CRStyleSheet * a_sheet, + CRDeclaration * a_font_decls) +{ + CRStatement *result = NULL; + + result = g_try_malloc (sizeof (CRStatement)); + + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + memset (result, 0, sizeof (CRStatement)); + result->type = AT_FONT_FACE_RULE_STMT; + + result->kind.font_face_rule = g_try_malloc + (sizeof (CRAtFontFaceRule)); + + if (!result->kind.font_face_rule) { + cr_utils_trace_info ("Out of memory"); + g_free (result); + return NULL; + } + memset (result->kind.font_face_rule, 0, sizeof (CRAtFontFaceRule)); + + result->kind.font_face_rule->decl_list = a_font_decls; + if (a_sheet) + cr_statement_set_parent_sheet (result, a_sheet); + + return result; } /** @@ -1771,64 +1595,63 @@ cr_statement_new_at_font_face_rule (CRStyleSheet *a_sheet, *parsing, NULL otherwise. */ CRStatement * -cr_statement_font_face_rule_parse_from_buf (const guchar *a_buf, - enum CREncoding a_encoding) -{ - CRStatement *result = NULL ; - CRParser *parser = NULL ; - CRDocHandler *sac_handler = NULL ; - enum CRStatus status = CR_OK ; - - parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_encoding, FALSE) ; - if (!parser) - goto cleanup ; - - sac_handler = cr_doc_handler_new () ; - if (!sac_handler) - goto cleanup ; - - /* - *set sac callbacks here - */ - sac_handler->start_font_face = parse_font_face_start_font_face_cb ; - sac_handler->property = parse_font_face_property_cb ; - sac_handler->end_font_face = parse_font_face_end_font_face_cb ; +cr_statement_font_face_rule_parse_from_buf (const guchar * a_buf, + enum CREncoding a_encoding) +{ + CRStatement *result = NULL; + CRParser *parser = NULL; + CRDocHandler *sac_handler = NULL; + enum CRStatus status = CR_OK; + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + a_encoding, FALSE); + if (!parser) + goto cleanup; + + sac_handler = cr_doc_handler_new (); + if (!sac_handler) + goto cleanup; + + /* + *set sac callbacks here + */ + sac_handler->start_font_face = parse_font_face_start_font_face_cb; + sac_handler->property = parse_font_face_property_cb; + sac_handler->end_font_face = parse_font_face_end_font_face_cb; sac_handler->unrecoverable_error = - parse_font_face_unrecoverable_error_cb ; - - status = cr_parser_set_sac_handler (parser, sac_handler) ; - if (status != CR_OK) - goto cleanup ; - - /* - *cleanup spaces of comment that may be there before the real - *"@font-face" thing. - */ - status = cr_parser_try_to_skip_spaces_and_comments (parser) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_parser_parse_font_face (parser) ; - if (status != CR_OK) - goto cleanup ; - - status = cr_doc_handler_get_result (sac_handler, (gpointer*)&result) ; - if (status != CR_OK || !result) - goto cleanup ; - - cleanup: - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; - } - if (sac_handler) - { - cr_doc_handler_unref (sac_handler) ; - sac_handler = NULL ; - } - return result ; + parse_font_face_unrecoverable_error_cb; + + status = cr_parser_set_sac_handler (parser, sac_handler); + if (status != CR_OK) + goto cleanup; + + /* + *cleanup spaces of comment that may be there before the real + *"@font-face" thing. + */ + status = cr_parser_try_to_skip_spaces_and_comments (parser); + if (status != CR_OK) + goto cleanup; + + status = cr_parser_parse_font_face (parser); + if (status != CR_OK) + goto cleanup; + + status = cr_doc_handler_get_result (sac_handler, + (gpointer *) & result); + if (status != CR_OK || !result) + goto cleanup; + + cleanup: + if (parser) { + cr_parser_destroy (parser); + parser = NULL; + } + if (sac_handler) { + cr_doc_handler_unref (sac_handler); + sac_handler = NULL; + } + return result; } /** @@ -1838,12 +1661,11 @@ cr_statement_font_face_rule_parse_from_buf (const guchar *a_buf, *@return CR_OK upon successfull completion, an errror code otherwise. */ enum CRStatus -cr_statement_set_parent_sheet (CRStatement *a_this, - CRStyleSheet *a_sheet) +cr_statement_set_parent_sheet (CRStatement * a_this, CRStyleSheet * a_sheet) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; - a_this->parent_sheet = a_sheet ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + a_this->parent_sheet = a_sheet; + return CR_OK; } /** @@ -1853,13 +1675,11 @@ cr_statement_set_parent_sheet (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_get_parent_sheet (CRStatement *a_this, - CRStyleSheet **a_sheet) +cr_statement_get_parent_sheet (CRStatement * a_this, CRStyleSheet ** a_sheet) { - g_return_val_if_fail (a_this && a_sheet, - CR_BAD_PARAM_ERROR) ; - *a_sheet = a_this->parent_sheet ; - return CR_OK ; + g_return_val_if_fail (a_this && a_sheet, CR_BAD_PARAM_ERROR); + *a_sheet = a_this->parent_sheet; + return CR_OK; } /** @@ -1869,25 +1689,23 @@ cr_statement_get_parent_sheet (CRStatement *a_this, *@return the new list statement list, or NULL in cas of failure. */ CRStatement * -cr_statement_append (CRStatement *a_this, - CRStatement *a_new) +cr_statement_append (CRStatement * a_this, CRStatement * a_new) { - CRStatement * cur = NULL ; + CRStatement *cur = NULL; - g_return_val_if_fail (a_new, NULL) ; - - if (!a_this) - { - return a_new ; - } + g_return_val_if_fail (a_new, NULL); - /*walk forward in the current list to find the tail list element*/ - for (cur = a_this ; cur && cur->next ; cur = cur->next) ; + if (!a_this) { + return a_new; + } - cur->next = a_new ; - a_new->prev = cur ; + /*walk forward in the current list to find the tail list element */ + for (cur = a_this; cur && cur->next; cur = cur->next) ; - return a_this ; + cur->next = a_new; + a_new->prev = cur; + + return a_this; } /** @@ -1898,24 +1716,23 @@ cr_statement_append (CRStatement *a_this, *@return the new list with the new statement prepended, *or NULL in case of an error. */ -CRStatement* -cr_statement_prepend (CRStatement *a_this, - CRStatement *a_new) +CRStatement * +cr_statement_prepend (CRStatement * a_this, CRStatement * a_new) { - CRStatement *cur = NULL ; + CRStatement *cur = NULL; - g_return_val_if_fail (a_new, NULL) ; + g_return_val_if_fail (a_new, NULL); - if (!a_this) - return a_new ; + if (!a_this) + return a_new; + + a_new->next = a_this; + a_this->prev = a_new; - a_new->next = a_this ; - a_this->prev = a_new ; + /*walk backward in the prepended list to find the head list element */ + for (cur = a_new; cur && cur->prev; cur = cur->prev) ; - /*walk backward in the prepended list to find the head list element*/ - for (cur = a_new ; cur && cur->prev ; cur = cur->prev) ; - - return cur ; + return cur; } /** @@ -1926,53 +1743,45 @@ cr_statement_prepend (CRStatement *a_this, *from, or NULL in case of error. */ CRStatement * -cr_statement_unlink (CRStatement *a_stmt) +cr_statement_unlink (CRStatement * a_stmt) { - CRStatement *result = a_stmt ; + CRStatement *result = a_stmt; - g_return_val_if_fail (result, NULL) ; + g_return_val_if_fail (result, NULL); /** *Some sanity checks first */ - if (a_stmt->next) - { - g_return_val_if_fail (a_stmt->next->prev == a_stmt, - NULL) ; + if (a_stmt->next) { + g_return_val_if_fail (a_stmt->next->prev == a_stmt, NULL); } - if (a_stmt->prev) - { - g_return_val_if_fail (a_stmt->prev->next == a_stmt, - NULL) ; + if (a_stmt->prev) { + g_return_val_if_fail (a_stmt->prev->next == a_stmt, NULL); } - + /** *Now, the real unlinking job. */ - if (a_stmt->next) - { - a_stmt->next->prev = a_stmt->prev ; + if (a_stmt->next) { + a_stmt->next->prev = a_stmt->prev; } - if (a_stmt->prev) - { - a_stmt->prev->next = a_stmt->next ; + if (a_stmt->prev) { + a_stmt->prev->next = a_stmt->next; } - - if (a_stmt->parent_sheet - && a_stmt->parent_sheet->statements == a_stmt) - { - a_stmt->parent_sheet->statements = - a_stmt->parent_sheet->statements->next ; + + if (a_stmt->parent_sheet + && a_stmt->parent_sheet->statements == a_stmt) { + a_stmt->parent_sheet->statements = + a_stmt->parent_sheet->statements->next; } - a_stmt->next = NULL ; - a_stmt->prev = NULL ; - a_stmt->parent_sheet = NULL ; + a_stmt->next = NULL; + a_stmt->prev = NULL; + a_stmt->parent_sheet = NULL; - return result ; + return result; } - /** *Sets a selector list to a ruleset statement. *@param a_this the current ruleset statement. @@ -1983,21 +1792,21 @@ cr_statement_unlink (CRStatement *a_stmt) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_ruleset_set_sel_list (CRStatement *a_this, - CRSelector *a_sel_list) +cr_statement_ruleset_set_sel_list (CRStatement * a_this, + CRSelector * a_sel_list) { - g_return_val_if_fail (a_this && a_this->type == RULESET_STMT, - CR_BAD_PARAM_ERROR) ; - - if (a_this->kind.ruleset->sel_list) - cr_selector_unref (a_this->kind.ruleset->sel_list) ; - - a_this->kind.ruleset->sel_list = a_sel_list ; + g_return_val_if_fail (a_this && a_this->type == RULESET_STMT, + CR_BAD_PARAM_ERROR); + + if (a_this->kind.ruleset->sel_list) + cr_selector_unref (a_this->kind.ruleset->sel_list); - if (a_sel_list) - cr_selector_ref (a_sel_list) ; + a_this->kind.ruleset->sel_list = a_sel_list; - return CR_OK ; + if (a_sel_list) + cr_selector_ref (a_sel_list); + + return CR_OK; } /** @@ -2010,18 +1819,17 @@ cr_statement_ruleset_set_sel_list (CRStatement *a_this, *bad happened. */ enum CRStatus -cr_statement_ruleset_get_declarations (CRStatement *a_this, - CRDeclaration **a_decl_list) +cr_statement_ruleset_get_declarations (CRStatement * a_this, + CRDeclaration ** a_decl_list) { - g_return_val_if_fail (a_this + g_return_val_if_fail (a_this && a_this->type == RULESET_STMT && a_this->kind.ruleset - && a_decl_list, - CR_BAD_PARAM_ERROR) ; + && a_decl_list, CR_BAD_PARAM_ERROR); - *a_decl_list = a_this->kind.ruleset->decl_list ; + *a_decl_list = a_this->kind.ruleset->decl_list; - return CR_OK ; + return CR_OK; } /** @@ -2033,17 +1841,15 @@ cr_statement_ruleset_get_declarations (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_ruleset_get_sel_list (CRStatement *a_this, - CRSelector **a_list) +cr_statement_ruleset_get_sel_list (CRStatement * a_this, CRSelector ** a_list) { - g_return_val_if_fail (a_this && a_this->type == RULESET_STMT - && a_this->kind.ruleset, CR_BAD_PARAM_ERROR) ; - - *a_list = a_this->kind.ruleset->sel_list ; + g_return_val_if_fail (a_this && a_this->type == RULESET_STMT + && a_this->kind.ruleset, CR_BAD_PARAM_ERROR); - return CR_OK ; -} + *a_list = a_this->kind.ruleset->sel_list; + return CR_OK; +} /** *Sets a declaration list to the current ruleset statement. @@ -2053,26 +1859,24 @@ cr_statement_ruleset_get_sel_list (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_ruleset_set_decl_list (CRStatement *a_this, - CRDeclaration *a_list) +cr_statement_ruleset_set_decl_list (CRStatement * a_this, + CRDeclaration * a_list) { - g_return_val_if_fail (a_this && a_this->type == RULESET_STMT - && a_this->kind.ruleset, CR_BAD_PARAM_ERROR); + g_return_val_if_fail (a_this && a_this->type == RULESET_STMT + && a_this->kind.ruleset, CR_BAD_PARAM_ERROR); - if (a_this->kind.ruleset->decl_list == a_list) - return CR_OK ; + if (a_this->kind.ruleset->decl_list == a_list) + return CR_OK; - if (a_this->kind.ruleset->sel_list) - { - cr_declaration_destroy (a_this->kind.ruleset->decl_list) ; - } + if (a_this->kind.ruleset->sel_list) { + cr_declaration_destroy (a_this->kind.ruleset->decl_list); + } - a_this->kind.ruleset->sel_list = NULL; + a_this->kind.ruleset->sel_list = NULL; - return CR_OK ; + return CR_OK; } - /** *Appends a declaration to the current ruleset statement. *@param a_this the current statement. @@ -2082,20 +1886,20 @@ cr_statement_ruleset_set_decl_list (CRStatement *a_this, *otherwise. */ enum CRStatus -cr_statement_ruleset_append_decl2 (CRStatement *a_this, - GString *a_prop, CRTerm *a_value) +cr_statement_ruleset_append_decl2 (CRStatement * a_this, + GString * a_prop, CRTerm * a_value) { - CRDeclaration * new_decls = NULL ; + CRDeclaration *new_decls = NULL; - g_return_val_if_fail (a_this && a_this->type == RULESET_STMT - && a_this->kind.ruleset, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_this->type == RULESET_STMT + && a_this->kind.ruleset, CR_BAD_PARAM_ERROR); - new_decls = cr_declaration_append2 - (a_this->kind.ruleset->decl_list, a_prop, a_value) ; - g_return_val_if_fail (new_decls, CR_ERROR) ; - a_this->kind.ruleset->decl_list = new_decls ; + new_decls = cr_declaration_append2 + (a_this->kind.ruleset->decl_list, a_prop, a_value); + g_return_val_if_fail (new_decls, CR_ERROR); + a_this->kind.ruleset->decl_list = new_decls; - return CR_OK ; + return CR_OK; } /** @@ -2106,23 +1910,22 @@ cr_statement_ruleset_append_decl2 (CRStatement *a_this, *otherwise. */ enum CRStatus -cr_statement_ruleset_append_decl (CRStatement *a_this, - CRDeclaration *a_decl) +cr_statement_ruleset_append_decl (CRStatement * a_this, + CRDeclaration * a_decl) { - CRDeclaration * new_decls = NULL ; + CRDeclaration *new_decls = NULL; - g_return_val_if_fail (a_this && a_this->type == RULESET_STMT - && a_this->kind.ruleset, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && a_this->type == RULESET_STMT + && a_this->kind.ruleset, CR_BAD_PARAM_ERROR); - new_decls = cr_declaration_append - (a_this->kind.ruleset->decl_list, a_decl) ; - g_return_val_if_fail (new_decls, CR_ERROR) ; - a_this->kind.ruleset->decl_list = new_decls ; + new_decls = cr_declaration_append + (a_this->kind.ruleset->decl_list, a_decl); + g_return_val_if_fail (new_decls, CR_ERROR); + a_this->kind.ruleset->decl_list = new_decls; - return CR_OK ; + return CR_OK; } - /** *Sets a stylesheet to the current @import rule. *@param a_this the current @import rule. @@ -2133,20 +1936,19 @@ cr_statement_ruleset_append_decl (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_import_rule_set_imported_sheet (CRStatement *a_this, - CRStyleSheet *a_sheet) +cr_statement_at_import_rule_set_imported_sheet (CRStatement * a_this, + CRStyleSheet * a_sheet) { - g_return_val_if_fail (a_this - && a_this->type == AT_IMPORT_RULE_STMT - && a_this->kind.import_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_IMPORT_RULE_STMT + && a_this->kind.import_rule, + CR_BAD_PARAM_ERROR); - a_this->kind.import_rule->sheet = a_sheet ; + a_this->kind.import_rule->sheet = a_sheet; - return CR_OK ; + return CR_OK; } - /** *Gets the stylesheet contained by the @import rule statement. *@param a_this the current @import rule statement. @@ -2155,15 +1957,15 @@ cr_statement_at_import_rule_set_imported_sheet (CRStatement *a_this, *@return CR_OK upon sucessfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_import_rule_get_imported_sheet (CRStatement *a_this, - CRStyleSheet **a_sheet) +cr_statement_at_import_rule_get_imported_sheet (CRStatement * a_this, + CRStyleSheet ** a_sheet) { - g_return_val_if_fail (a_this - && a_this->type == AT_IMPORT_RULE_STMT - && a_this->kind.import_rule, - CR_BAD_PARAM_ERROR) ; - *a_sheet = a_this->kind.import_rule->sheet ; - return CR_OK ; + g_return_val_if_fail (a_this + && a_this->type == AT_IMPORT_RULE_STMT + && a_this->kind.import_rule, + CR_BAD_PARAM_ERROR); + *a_sheet = a_this->kind.import_rule->sheet; + return CR_OK; } @@ -2174,24 +1976,21 @@ cr_statement_at_import_rule_get_imported_sheet (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_import_rule_set_url (CRStatement *a_this, - GString *a_url) +cr_statement_at_import_rule_set_url (CRStatement * a_this, GString * a_url) { - g_return_val_if_fail (a_this - && a_this->type == AT_IMPORT_RULE_STMT - && a_this->kind.import_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_IMPORT_RULE_STMT + && a_this->kind.import_rule, + CR_BAD_PARAM_ERROR); - if (a_this->kind.import_rule->url) - { - g_string_free (a_this->kind.import_rule->url, TRUE) ; - } - - a_this->kind.import_rule->url = a_url ; + if (a_this->kind.import_rule->url) { + g_string_free (a_this->kind.import_rule->url, TRUE); + } - return CR_OK ; -} + a_this->kind.import_rule->url = a_url; + return CR_OK; +} /** *Gets the url of the @import rule statement. @@ -2200,17 +1999,16 @@ cr_statement_at_import_rule_set_url (CRStatement *a_this, *and only if the function returned CR_OK. */ enum CRStatus -cr_statement_at_import_rule_get_url (CRStatement *a_this, - GString **a_url) +cr_statement_at_import_rule_get_url (CRStatement * a_this, GString ** a_url) { - g_return_val_if_fail (a_this - && a_this->type == AT_IMPORT_RULE_STMT - && a_this->kind.import_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_IMPORT_RULE_STMT + && a_this->kind.import_rule, + CR_BAD_PARAM_ERROR); - *a_url = a_this->kind.import_rule->url ; + *a_url = a_this->kind.import_rule->url; - return CR_OK ; + return CR_OK; } /** @@ -2219,14 +2017,13 @@ cr_statement_at_import_rule_get_url (CRStatement *a_this, *@return number of rules in the media rule. */ int -cr_statement_at_media_nr_rules (CRStatement *a_this) +cr_statement_at_media_nr_rules (CRStatement * a_this) { - g_return_val_if_fail (a_this - && a_this->type == AT_MEDIA_RULE_STMT - && a_this->kind.media_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_MEDIA_RULE_STMT + && a_this->kind.media_rule, CR_BAD_PARAM_ERROR); - return cr_statement_nr_rules (a_this->kind.media_rule->rulesets); + return cr_statement_nr_rules (a_this->kind.media_rule->rulesets); } /** @@ -2237,14 +2034,14 @@ cr_statement_at_media_nr_rules (CRStatement *a_this) *it will return NULL. */ CRStatement * -cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) +cr_statement_at_media_get_from_list (CRStatement * a_this, int itemnr) { - g_return_val_if_fail (a_this - && a_this->type == AT_MEDIA_RULE_STMT - && a_this->kind.media_rule, - NULL) ; + g_return_val_if_fail (a_this + && a_this->type == AT_MEDIA_RULE_STMT + && a_this->kind.media_rule, NULL); - return cr_statement_get_from_list (a_this->kind.media_rule->rulesets, itemnr); + return cr_statement_get_from_list (a_this->kind.media_rule->rulesets, + itemnr); } /** @@ -2255,30 +2052,26 @@ cr_statement_at_media_get_from_list (CRStatement *a_this, int itemnr) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_page_rule_set_declarations (CRStatement *a_this, - CRDeclaration *a_decl_list) +cr_statement_at_page_rule_set_declarations (CRStatement * a_this, + CRDeclaration * a_decl_list) { - g_return_val_if_fail (a_this - && a_this->type == AT_PAGE_RULE_STMT - && a_this->kind.page_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_PAGE_RULE_STMT + && a_this->kind.page_rule, CR_BAD_PARAM_ERROR); - if (a_this->kind.page_rule->decl_list) - { - cr_declaration_unref (a_this->kind.page_rule->decl_list); - } + if (a_this->kind.page_rule->decl_list) { + cr_declaration_unref (a_this->kind.page_rule->decl_list); + } - a_this->kind.page_rule->decl_list = a_decl_list ; + a_this->kind.page_rule->decl_list = a_decl_list; - if (a_decl_list) - { - cr_declaration_ref (a_decl_list) ; - } + if (a_decl_list) { + cr_declaration_ref (a_decl_list); + } - return CR_OK ; + return CR_OK; } - /** *Gets the declaration list associated to the current @page rule *statement. @@ -2287,20 +2080,18 @@ cr_statement_at_page_rule_set_declarations (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_page_rule_get_declarations (CRStatement *a_this, - CRDeclaration **a_decl_list) +cr_statement_at_page_rule_get_declarations (CRStatement * a_this, + CRDeclaration ** a_decl_list) { - g_return_val_if_fail (a_this - && a_this->type == AT_PAGE_RULE_STMT - && a_this->kind.page_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_PAGE_RULE_STMT + && a_this->kind.page_rule, CR_BAD_PARAM_ERROR); - *a_decl_list = a_this->kind.page_rule->decl_list ; + *a_decl_list = a_this->kind.page_rule->decl_list; - return CR_OK ; + return CR_OK; } - /** *Sets the charset of the current @charset rule statement. *@param a_this the current @charset rule statement. @@ -2308,25 +2099,22 @@ cr_statement_at_page_rule_get_declarations (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_charset_rule_set_charset (CRStatement *a_this, - GString *a_charset) +cr_statement_at_charset_rule_set_charset (CRStatement * a_this, + GString * a_charset) { - g_return_val_if_fail (a_this - && a_this->type == AT_CHARSET_RULE_STMT - && a_this->kind.charset_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_CHARSET_RULE_STMT + && a_this->kind.charset_rule, + CR_BAD_PARAM_ERROR); - if (a_this->kind.charset_rule->charset) - { - g_string_free (a_this->kind.charset_rule->charset, - TRUE) ; - } + if (a_this->kind.charset_rule->charset) { + g_string_free (a_this->kind.charset_rule->charset, TRUE); + } - a_this->kind.charset_rule->charset = a_charset ; - return CR_OK ; + a_this->kind.charset_rule->charset = a_charset; + return CR_OK; } - /** *Gets the charset string associated to the current *@charset rule statement. @@ -2335,20 +2123,19 @@ cr_statement_at_charset_rule_set_charset (CRStatement *a_this, *and only if the function returned CR_OK. */ enum CRStatus -cr_statement_at_charset_rule_get_charset (CRStatement *a_this, - GString **a_charset) +cr_statement_at_charset_rule_get_charset (CRStatement * a_this, + GString ** a_charset) { - g_return_val_if_fail (a_this - && a_this->type == AT_CHARSET_RULE_STMT - && a_this->kind.charset_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_CHARSET_RULE_STMT + && a_this->kind.charset_rule, + CR_BAD_PARAM_ERROR); - *a_charset = a_this->kind.charset_rule->charset ; + *a_charset = a_this->kind.charset_rule->charset; - return CR_OK ; + return CR_OK; } - /** *Sets a declaration list to the current @font-face rule statement. *@param a_this the current @font-face rule statement. @@ -2356,26 +2143,23 @@ cr_statement_at_charset_rule_get_charset (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_font_face_rule_set_decls (CRStatement *a_this, - CRDeclaration *a_decls) +cr_statement_at_font_face_rule_set_decls (CRStatement * a_this, + CRDeclaration * a_decls) { - g_return_val_if_fail (a_this - && a_this->type == AT_FONT_FACE_RULE_STMT - && a_this->kind.font_face_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_FONT_FACE_RULE_STMT + && a_this->kind.font_face_rule, + CR_BAD_PARAM_ERROR); - if (a_this->kind.font_face_rule->decl_list) - { - cr_declaration_unref - (a_this->kind.font_face_rule->decl_list) ; - } + if (a_this->kind.font_face_rule->decl_list) { + cr_declaration_unref (a_this->kind.font_face_rule->decl_list); + } - a_this->kind.font_face_rule->decl_list = a_decls; - cr_declaration_ref (a_decls) ; - - return CR_OK ; -} + a_this->kind.font_face_rule->decl_list = a_decls; + cr_declaration_ref (a_decls); + return CR_OK; +} /** *Gets the declaration list associated to the current instance @@ -2386,19 +2170,18 @@ cr_statement_at_font_face_rule_set_decls (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_font_face_rule_get_decls (CRStatement *a_this, - CRDeclaration **a_decls) +cr_statement_at_font_face_rule_get_decls (CRStatement * a_this, + CRDeclaration ** a_decls) { - g_return_val_if_fail (a_this - && a_this->type == AT_FONT_FACE_RULE_STMT - && a_this->kind.font_face_rule, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this + && a_this->type == AT_FONT_FACE_RULE_STMT + && a_this->kind.font_face_rule, + CR_BAD_PARAM_ERROR); - *a_decls = a_this->kind.font_face_rule->decl_list ; - - return CR_OK ; -} + *a_decls = a_this->kind.font_face_rule->decl_list; + return CR_OK; +} /** *Adds a declaration to the current @font-face rule @@ -2409,29 +2192,27 @@ cr_statement_at_font_face_rule_get_decls (CRStatement *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_statement_at_font_face_rule_add_decl (CRStatement *a_this, - GString *a_prop, - CRTerm *a_value) +cr_statement_at_font_face_rule_add_decl (CRStatement * a_this, + GString * a_prop, CRTerm * a_value) { - CRDeclaration *decls = NULL ; - - g_return_val_if_fail (a_this - && a_this->type == AT_FONT_FACE_RULE_STMT - && a_this->kind.font_face_rule, - CR_BAD_PARAM_ERROR) ; + CRDeclaration *decls = NULL; + + g_return_val_if_fail (a_this + && a_this->type == AT_FONT_FACE_RULE_STMT + && a_this->kind.font_face_rule, + CR_BAD_PARAM_ERROR); + + decls = cr_declaration_append2 + (a_this->kind.font_face_rule->decl_list, a_prop, a_value); - decls = cr_declaration_append2 - (a_this->kind.font_face_rule->decl_list, - a_prop, a_value) ; + g_return_val_if_fail (decls, CR_ERROR); - g_return_val_if_fail (decls, CR_ERROR) ; - - if (a_this->kind.font_face_rule->decl_list == NULL) - cr_declaration_ref (decls) ; + if (a_this->kind.font_face_rule->decl_list == NULL) + cr_declaration_ref (decls); - a_this->kind.font_face_rule->decl_list = decls ; + a_this->kind.font_face_rule->decl_list = decls; - return CR_OK ; + return CR_OK; } /** @@ -2441,96 +2222,88 @@ cr_statement_at_font_face_rule_add_decl (CRStatement *a_this, *@param a_indent the number of white space indentation characters. */ void -cr_statement_dump (CRStatement *a_this, FILE *a_fp, gulong a_indent) +cr_statement_dump (CRStatement * a_this, FILE * a_fp, gulong a_indent) { if (!a_this) - return ; + return; - if (a_this->prev) - { - fprintf (a_fp,"\n\n") ; - } + if (a_this->prev) { + fprintf (a_fp, "\n\n"); + } - switch (a_this->type) - { - case RULESET_STMT: - cr_statement_dump_ruleset (a_this, a_fp, a_indent) ; - break ; + switch (a_this->type) { + case RULESET_STMT: + cr_statement_dump_ruleset (a_this, a_fp, a_indent); + break; - case AT_FONT_FACE_RULE_STMT: - cr_statement_dump_font_face_rule - (a_this, a_fp, a_indent); - break ; + case AT_FONT_FACE_RULE_STMT: + cr_statement_dump_font_face_rule (a_this, a_fp, a_indent); + break; - case AT_CHARSET_RULE_STMT: - cr_statement_dump_charset (a_this, a_fp, a_indent) ; - break ; + case AT_CHARSET_RULE_STMT: + cr_statement_dump_charset (a_this, a_fp, a_indent); + break; - case AT_PAGE_RULE_STMT: - cr_statement_dump_page (a_this, a_fp, a_indent) ; - break ; + case AT_PAGE_RULE_STMT: + cr_statement_dump_page (a_this, a_fp, a_indent); + break; - case AT_MEDIA_RULE_STMT: - cr_statement_dump_media_rule (a_this, a_fp, a_indent) ; - break ; + case AT_MEDIA_RULE_STMT: + cr_statement_dump_media_rule (a_this, a_fp, a_indent); + break; - case AT_IMPORT_RULE_STMT: - cr_statement_dump_import_rule (a_this, a_fp, a_indent) ; - break ; + case AT_IMPORT_RULE_STMT: + cr_statement_dump_import_rule (a_this, a_fp, a_indent); + break; - default : - fprintf (a_fp, "Statement unrecognized at %s:%d", - __FILE__, __LINE__) ; - break ; - } + default: + fprintf (a_fp, "Statement unrecognized at %s:%d", + __FILE__, __LINE__); + break; + } } /** *Destructor of #CRStatement. */ void -cr_statement_destroy (CRStatement *a_this) -{ - CRStatement *cur = NULL ; - - g_return_if_fail (a_this) ; - - /*go get the tail of the list*/ - for (cur = a_this ; cur && cur->next; cur = cur->next) - { - cr_statement_clear (cur) ; - } - - if (cur) - cr_statement_clear (cur) ; - - if (cur->prev == NULL) - { - g_free (a_this); - return ; - } - - /*walk backward and free next element*/ - for (cur = cur->prev ; cur && cur->prev; cur = cur->prev) - { - if (cur->next) - { - g_free (cur->next) ; - cur->next = NULL ; - } - } - - if (!cur) - return ; - - /*free the one remaining list*/ - if (cur->next) - { - g_free (cur->next) ; - cur->next = NULL ; - } - - g_free (cur) ; - cur = NULL ; +cr_statement_destroy (CRStatement * a_this) +{ + CRStatement *cur = NULL; + + g_return_if_fail (a_this); + + /*go get the tail of the list */ + for (cur = a_this; cur && cur->next; cur = cur->next) { + cr_statement_clear (cur); + } + + if (cur) + cr_statement_clear (cur); + + if (cur->prev == NULL) { + g_free (a_this); + return; + } + + /*walk backward and free next element */ + for (cur = cur->prev; cur && cur->prev; cur = cur->prev) { + if (cur->next) { + g_free (cur->next); + cur->next = NULL; + } + } + + if (!cur) + return; + + /*free the one remaining list */ + if (cur->next) { + g_free (cur->next); + cur->next = NULL; + } + + g_free (cur); + cur = NULL; } diff --git a/src/cr-style.c b/src/cr-style.c index ca06c22..20859d7 100644 --- a/src/cr-style.c +++ b/src/cr-style.c @@ -33,7 +33,6 @@ *The definition of the #CRStyle class. */ - /** *A property ID. *Each supported css property has an ID which is @@ -42,22 +41,21 @@ *contains code to tranform the literal form of *a property value into a strongly typed value. */ -enum CRPropertyID -{ +enum CRPropertyID { PROP_ID_NOT_KNOWN = 0, - PROP_ID_PADDING_TOP, - PROP_ID_PADDING_RIGHT, - PROP_ID_PADDING_BOTTOM, - PROP_ID_PADDING_LEFT, + PROP_ID_PADDING_TOP, + PROP_ID_PADDING_RIGHT, + PROP_ID_PADDING_BOTTOM, + PROP_ID_PADDING_LEFT, PROP_ID_PADDING, - PROP_ID_BORDER_TOP_WIDTH, - PROP_ID_BORDER_RIGHT_WIDTH, - PROP_ID_BORDER_BOTTOM_WIDTH, - PROP_ID_BORDER_LEFT_WIDTH, - PROP_ID_BORDER_TOP_STYLE, - PROP_ID_BORDER_RIGHT_STYLE, - PROP_ID_BORDER_BOTTOM_STYLE, - PROP_ID_BORDER_LEFT_STYLE, + PROP_ID_BORDER_TOP_WIDTH, + PROP_ID_BORDER_RIGHT_WIDTH, + PROP_ID_BORDER_BOTTOM_WIDTH, + PROP_ID_BORDER_LEFT_WIDTH, + PROP_ID_BORDER_TOP_STYLE, + PROP_ID_BORDER_RIGHT_STYLE, + PROP_ID_BORDER_BOTTOM_STYLE, + PROP_ID_BORDER_LEFT_STYLE, PROP_ID_BORDER_TOP_COLOR, PROP_ID_BORDER_RIGHT_COLOR, PROP_ID_BORDER_BOTTOM_COLOR, @@ -67,83 +65,77 @@ enum CRPropertyID PROP_ID_BORDER_BOTTOM, PROP_ID_BORDER_LEFT, PROP_ID_BORDER, - PROP_ID_MARGIN_TOP, - PROP_ID_MARGIN_RIGHT, - PROP_ID_MARGIN_BOTTOM, - PROP_ID_MARGIN_LEFT, + PROP_ID_MARGIN_TOP, + PROP_ID_MARGIN_RIGHT, + PROP_ID_MARGIN_BOTTOM, + PROP_ID_MARGIN_LEFT, PROP_ID_MARGIN, - PROP_ID_DISPLAY, - PROP_ID_POSITION, - PROP_ID_TOP, - PROP_ID_RIGHT, - PROP_ID_BOTTOM, - PROP_ID_LEFT, - PROP_ID_FLOAT, - PROP_ID_WIDTH, - PROP_ID_COLOR, + PROP_ID_DISPLAY, + PROP_ID_POSITION, + PROP_ID_TOP, + PROP_ID_RIGHT, + PROP_ID_BOTTOM, + PROP_ID_LEFT, + PROP_ID_FLOAT, + PROP_ID_WIDTH, + PROP_ID_COLOR, PROP_ID_BACKGROUND_COLOR, PROP_ID_FONT_FAMILY, PROP_ID_FONT_SIZE, PROP_ID_FONT_STYLE, PROP_ID_FONT_WEIGHT, - /*should be the last one.*/ + /*should be the last one. */ NB_PROP_IDS -} ; - - -typedef struct _CRPropertyDesc CRPropertyDesc ; +}; -struct _CRPropertyDesc -{ - const guchar * name ; - enum CRPropertyID prop_id ; -} ; +typedef struct _CRPropertyDesc CRPropertyDesc; -static CRPropertyDesc gv_prop_table [] = +struct _CRPropertyDesc { + const guchar *name; + enum CRPropertyID prop_id; +}; -{ - {"padding-top", PROP_ID_PADDING_TOP}, - {"padding-right", PROP_ID_PADDING_RIGHT}, - {"padding-bottom", PROP_ID_PADDING_BOTTOM}, - {"padding-left", PROP_ID_PADDING_LEFT}, +static CRPropertyDesc gv_prop_table[] = { + {"padding-top", PROP_ID_PADDING_TOP}, + {"padding-right", PROP_ID_PADDING_RIGHT}, + {"padding-bottom", PROP_ID_PADDING_BOTTOM}, + {"padding-left", PROP_ID_PADDING_LEFT}, {"padding", PROP_ID_PADDING}, - {"border-top-width", PROP_ID_BORDER_TOP_WIDTH}, - {"border-right-width", PROP_ID_BORDER_RIGHT_WIDTH}, - {"border-bottom-width", PROP_ID_BORDER_BOTTOM_WIDTH}, - {"border-left-width", PROP_ID_BORDER_LEFT_WIDTH}, - {"border-top-style", PROP_ID_BORDER_TOP_STYLE}, - {"border-right-style", PROP_ID_BORDER_RIGHT_STYLE}, - {"border-bottom-style", PROP_ID_BORDER_BOTTOM_STYLE}, - {"border-left-style", PROP_ID_BORDER_LEFT_STYLE}, + {"border-top-width", PROP_ID_BORDER_TOP_WIDTH}, + {"border-right-width", PROP_ID_BORDER_RIGHT_WIDTH}, + {"border-bottom-width", PROP_ID_BORDER_BOTTOM_WIDTH}, + {"border-left-width", PROP_ID_BORDER_LEFT_WIDTH}, + {"border-top-style", PROP_ID_BORDER_TOP_STYLE}, + {"border-right-style", PROP_ID_BORDER_RIGHT_STYLE}, + {"border-bottom-style", PROP_ID_BORDER_BOTTOM_STYLE}, + {"border-left-style", PROP_ID_BORDER_LEFT_STYLE}, {"border-top", PROP_ID_BORDER_TOP}, {"border-right", PROP_ID_BORDER_RIGHT}, {"border-bottom", PROP_ID_BORDER_BOTTOM}, {"border-left", PROP_ID_BORDER_LEFT}, {"border", PROP_ID_BORDER}, - {"margin-top", PROP_ID_MARGIN_TOP}, - {"margin-right", PROP_ID_MARGIN_RIGHT}, - {"margin-bottom", PROP_ID_MARGIN_BOTTOM}, - {"margin-left", PROP_ID_MARGIN_LEFT}, + {"margin-top", PROP_ID_MARGIN_TOP}, + {"margin-right", PROP_ID_MARGIN_RIGHT}, + {"margin-bottom", PROP_ID_MARGIN_BOTTOM}, + {"margin-left", PROP_ID_MARGIN_LEFT}, {"margin", PROP_ID_MARGIN}, - {"display", PROP_ID_DISPLAY}, - {"position", PROP_ID_POSITION}, - {"top", PROP_ID_TOP}, - {"right", PROP_ID_RIGHT}, - {"bottom", PROP_ID_BOTTOM}, - {"left", PROP_ID_LEFT}, - {"float", PROP_ID_FLOAT}, - {"width", PROP_ID_WIDTH}, + {"display", PROP_ID_DISPLAY}, + {"position", PROP_ID_POSITION}, + {"top", PROP_ID_TOP}, + {"right", PROP_ID_RIGHT}, + {"bottom", PROP_ID_BOTTOM}, + {"left", PROP_ID_LEFT}, + {"float", PROP_ID_FLOAT}, + {"width", PROP_ID_WIDTH}, {"color", PROP_ID_COLOR}, {"background-color", PROP_ID_BACKGROUND_COLOR}, {"font-family", PROP_ID_FONT_FAMILY}, {"font-size", PROP_ID_FONT_SIZE}, {"font-style", PROP_ID_FONT_STYLE}, {"font-weight", PROP_ID_FONT_WEIGHT}, - /*must be the last one*/ - {NULL, 0} -} ; - - + /*must be the last one */ + {NULL, 0} +}; /** *A the key/value pair of this hash table @@ -153,48 +145,47 @@ static CRPropertyDesc gv_prop_table [] = *So this hash table is here just to retrieval of a property id *from a property name. */ -static GHashTable *gv_prop_hash = NULL ; +static GHashTable *gv_prop_hash = NULL; /** *incremented by each new instance of #CRStyle *and decremented at the it destroy time. *When this reaches zero, gv_prop_hash is destroyed. */ -static gulong gv_prop_hash_ref_count = 0 ; +static gulong gv_prop_hash_ref_count = 0; struct CRNumPropEnumDumpInfo { - enum CRNumProp code ; - const gchar * str ; -} ; + enum CRNumProp code; + const gchar *str; +}; static struct CRNumPropEnumDumpInfo gv_num_props_dump_infos[] = { - {NUM_PROP_TOP, "top"}, - {NUM_PROP_RIGHT, "right"}, - {NUM_PROP_BOTTOM, "bottom"}, - {NUM_PROP_LEFT, "left"}, - {NUM_PROP_PADDING_TOP, "padding-top"}, - {NUM_PROP_PADDING_RIGHT, "padding-right"}, - {NUM_PROP_PADDING_BOTTOM, "padding-bottom"}, - {NUM_PROP_PADDING_LEFT, "padding-left"}, - {NUM_PROP_BORDER_TOP, "border-top"}, - {NUM_PROP_BORDER_RIGHT, "border-right"}, - {NUM_PROP_BORDER_BOTTOM, "border-bottom"}, - {NUM_PROP_BORDER_LEFT, "border-left"}, - {NUM_PROP_MARGIN_TOP, "margin-top"}, - {NUM_PROP_MARGIN_RIGHT, "margin-right"}, - {NUM_PROP_MARGIN_BOTTOM, "margin-bottom"}, - {NUM_PROP_MARGIN_LEFT, "margin-left"}, - {NUM_PROP_WIDTH, "width"}, + {NUM_PROP_TOP, "top"}, + {NUM_PROP_RIGHT, "right"}, + {NUM_PROP_BOTTOM, "bottom"}, + {NUM_PROP_LEFT, "left"}, + {NUM_PROP_PADDING_TOP, "padding-top"}, + {NUM_PROP_PADDING_RIGHT, "padding-right"}, + {NUM_PROP_PADDING_BOTTOM, "padding-bottom"}, + {NUM_PROP_PADDING_LEFT, "padding-left"}, + {NUM_PROP_BORDER_TOP, "border-top"}, + {NUM_PROP_BORDER_RIGHT, "border-right"}, + {NUM_PROP_BORDER_BOTTOM, "border-bottom"}, + {NUM_PROP_BORDER_LEFT, "border-left"}, + {NUM_PROP_MARGIN_TOP, "margin-top"}, + {NUM_PROP_MARGIN_RIGHT, "margin-right"}, + {NUM_PROP_MARGIN_BOTTOM, "margin-bottom"}, + {NUM_PROP_MARGIN_LEFT, "margin-left"}, + {NUM_PROP_WIDTH, "width"}, {0, NULL} -} ; +}; struct CRRgbPropEnumDumpInfo { - enum CRRgbProp code ; - const gchar *str ; -} ; + enum CRRgbProp code; + const gchar *str; +}; -static struct CRRgbPropEnumDumpInfo gv_rgb_props_dump_infos [] = -{ +static struct CRRgbPropEnumDumpInfo gv_rgb_props_dump_infos[] = { {RGB_PROP_BORDER_TOP_COLOR, "border-top-color"}, {RGB_PROP_BORDER_RIGHT_COLOR, "border-right-color"}, {RGB_PROP_BORDER_BOTTOM_COLOR, "bottom-color"}, @@ -202,325 +193,294 @@ static struct CRRgbPropEnumDumpInfo gv_rgb_props_dump_infos [] = {RGB_PROP_COLOR, "color"}, {RGB_PROP_BACKGROUND_COLOR, "background-color"}, {0, NULL} -} ; +}; -struct CRBorderStylePropEnumDumpInfo -{ - enum CRBorderStyleProp code ; - const gchar *str ; - -} ; +struct CRBorderStylePropEnumDumpInfo { + enum CRBorderStyleProp code; + const gchar *str; -static struct CRBorderStylePropEnumDumpInfo gv_border_style_props_dump_infos [] = -{ - {BORDER_STYLE_PROP_TOP, "border-style-top"}, - {BORDER_STYLE_PROP_RIGHT, "border-style-right"}, +}; + +static struct CRBorderStylePropEnumDumpInfo gv_border_style_props_dump_infos[] + = { + {BORDER_STYLE_PROP_TOP, "border-style-top"}, + {BORDER_STYLE_PROP_RIGHT, "border-style-right"}, {BORDER_STYLE_PROP_BOTTOM, "boder-style-bottom"}, - {BORDER_STYLE_PROP_LEFT, "border-style-left"}, - {0,NULL} -} ; + {BORDER_STYLE_PROP_LEFT, "border-style-left"}, + {0, NULL} +}; static enum CRStatus -cr_style_init_properties (void) ; + cr_style_init_properties (void); -enum CRDirection -{ +enum CRDirection { DIR_TOP = 0, DIR_RIGHT, DIR_BOTTOM, DIR_LEFT, - /*must be the last one*/ + /*must be the last one */ NB_DIRS -} ; +}; -static const gchar * -num_prop_code_to_string (enum CRNumProp a_code) ; +static const gchar *num_prop_code_to_string (enum CRNumProp a_code); -static const gchar * -rgb_prop_code_to_string (enum CRRgbProp a_code) ; +static const gchar *rgb_prop_code_to_string (enum CRRgbProp a_code); -static const gchar * -border_style_prop_code_to_string (enum CRBorderStyleProp a_code) ; +static const gchar *border_style_prop_code_to_string (enum CRBorderStyleProp + a_code); static enum CRStatus -set_prop_padding_x_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) ; + set_prop_padding_x_from_value (CRStyle * a_style, + CRTerm * a_value, enum CRDirection a_dir); static enum CRStatus -set_prop_border_x_width_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) ; + set_prop_border_x_width_from_value (CRStyle * a_style, + CRTerm * a_value, + enum CRDirection a_dir); static enum CRStatus -set_prop_border_x_style_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) ; + set_prop_border_x_style_from_value (CRStyle * a_style, + CRTerm * a_value, + enum CRDirection a_dir); static enum CRStatus -set_prop_margin_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; + set_prop_margin_x_from_value (CRStyle * a_style, CRTerm * a_value, + enum CRDirection a_dir); static enum CRStatus -set_prop_display_from_value (CRStyle *a_style, CRTerm *a_value) ; + set_prop_display_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_position_from_value (CRStyle *a_style, CRTerm *a_value) ; + set_prop_position_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; + set_prop_x_from_value (CRStyle * a_style, CRTerm * a_value, + enum CRDirection a_dir); static enum CRStatus -set_prop_float (CRStyle *a_style, CRTerm *a_value) ; + set_prop_float (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_width (CRStyle *a_style, CRTerm *a_value) ; + set_prop_width (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_color (CRStyle *a_style, CRTerm *a_value) ; + set_prop_color (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_background_color (CRStyle *a_style, CRTerm *a_value) ; + set_prop_background_color (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_border_x_color_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; + set_prop_border_x_color_from_value (CRStyle * a_style, CRTerm * a_value, + enum CRDirection a_dir); static enum CRStatus -set_prop_border_x_from_value (CRStyle *a_style, CRTerm *a_value, - enum CRDirection a_dir) ; + set_prop_border_x_from_value (CRStyle * a_style, CRTerm * a_value, + enum CRDirection a_dir); static enum CRStatus -set_prop_border_from_value (CRStyle *a_style, CRTerm *a_value) ; + set_prop_border_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_padding_from_value (CRStyle *a_style, CRTerm *a_value) ; + set_prop_padding_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_margin_from_value (CRStyle *a_style, CRTerm *a_value) ; + set_prop_margin_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_font_family_from_value (CRStyle *a_style, CRTerm *a_value) ; + set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -init_style_font_size_field (CRStyle *a_style) ; + init_style_font_size_field (CRStyle * a_style); static enum CRStatus -set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) ; - + set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_font_style_from_value (CRStyle *a_style, CRTerm *a_value) ; + set_prop_font_style_from_value (CRStyle * a_style, CRTerm * a_value); static enum CRStatus -set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) ; - + set_prop_font_weight_from_value (CRStyle * a_style, CRTerm * a_value); static const gchar * num_prop_code_to_string (enum CRNumProp a_code) { - gint len = sizeof (gv_num_props_dump_infos) / - sizeof (struct CRNumPropEnumDumpInfo) ; - if (a_code >= len) - { + gint len = sizeof (gv_num_props_dump_infos) / + sizeof (struct CRNumPropEnumDumpInfo); + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRNumProp' and no matching" " entry has been " "added to gv_num_prop_dump_infos table.\n" - "Please add the missing matching entry") ; - return NULL ; + "Please add the missing matching entry"); + return NULL; } - if (gv_num_props_dump_infos[a_code].code != a_code) - { + if (gv_num_props_dump_infos[a_code].code != a_code) { cr_utils_trace_info ("mismatch between the order of fields in" " 'enum CRNumProp' and " "the order of entries in " - "the gv_num_prop_dump_infos table") ; - return NULL ; + "the gv_num_prop_dump_infos table"); + return NULL; } - return gv_num_props_dump_infos[a_code].str ; + return gv_num_props_dump_infos[a_code].str; } static const gchar * rgb_prop_code_to_string (enum CRRgbProp a_code) { gint len = sizeof (gv_rgb_props_dump_infos) / - sizeof (struct CRRgbPropEnumDumpInfo) ; + sizeof (struct CRRgbPropEnumDumpInfo); - if (a_code >= len) - { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRRgbProp' and no matching" " entry has been " "added to gv_rgb_prop_dump_infos table.\n" - "Please add the missing matching entry") ; - return NULL ; + "Please add the missing matching entry"); + return NULL; } - if (gv_rgb_props_dump_infos[a_code].code != a_code) - { + if (gv_rgb_props_dump_infos[a_code].code != a_code) { cr_utils_trace_info ("mismatch between the order of fields in" " 'enum CRRgbProp' and " "the order of entries in " - "the gv_rgb_props_dump_infos table") ; - return NULL ; + "the gv_rgb_props_dump_infos table"); + return NULL; } - return gv_rgb_props_dump_infos[a_code].str ; + return gv_rgb_props_dump_infos[a_code].str; } static const gchar * border_style_prop_code_to_string (enum CRBorderStyleProp a_code) { gint len = sizeof (gv_border_style_props_dump_infos) / - sizeof (struct CRBorderStylePropEnumDumpInfo) ; + sizeof (struct CRBorderStylePropEnumDumpInfo); - if (a_code >= len) - { + if (a_code >= len) { cr_utils_trace_info ("A field has been added " "to 'enum CRBorderStyleProp' and no matching" " entry has been " "added to gv_border_style_prop_dump_infos table.\n" - "Please add the missing matching entry") ; - return NULL ; + "Please add the missing matching entry"); + return NULL; } - if (gv_border_style_props_dump_infos[a_code].code != a_code) - { + if (gv_border_style_props_dump_infos[a_code].code != a_code) { cr_utils_trace_info ("mismatch between the order of fields in" " 'enum CRBorderStyleProp' and " "the order of entries in " - "the gv_border_style_props_dump_infos table") ; - return NULL ; + "the gv_border_style_props_dump_infos table"); + return NULL; } - return gv_border_style_props_dump_infos[a_code].str ; + return gv_border_style_props_dump_infos[a_code].str; } static enum CRStatus cr_style_init_properties (void) { - if (!gv_prop_hash) - { - gulong i = 0 ; + if (!gv_prop_hash) { + gulong i = 0; - gv_prop_hash = g_hash_table_new (g_str_hash, - g_str_equal) ; - if (!gv_prop_hash) - { - cr_utils_trace_info ("Out of memory") ; - return CR_ERROR ; + gv_prop_hash = g_hash_table_new (g_str_hash, g_str_equal); + if (!gv_prop_hash) { + cr_utils_trace_info ("Out of memory"); + return CR_ERROR; } - /*load gv_prop_hash from gv_prop_table*/ - for (i = 0 ; gv_prop_table[i].name ; i++) - { - g_hash_table_insert + /*load gv_prop_hash from gv_prop_table */ + for (i = 0; gv_prop_table[i].name; i++) { + g_hash_table_insert (gv_prop_hash, - (gpointer)gv_prop_table[i].name, - GINT_TO_POINTER - (gv_prop_table[i].prop_id)) ; + (gpointer) gv_prop_table[i].name, + GINT_TO_POINTER (gv_prop_table[i].prop_id)); } } - return CR_OK ; + return CR_OK; } - static enum CRPropertyID cr_style_get_prop_id (const guchar * a_prop) { - gpointer * raw_id = NULL ; + gpointer *raw_id = NULL; - if (!gv_prop_hash) - { - cr_style_init_properties () ; + if (!gv_prop_hash) { + cr_style_init_properties (); } - raw_id = g_hash_table_lookup (gv_prop_hash, - a_prop) ; - if (!raw_id) - { - return PROP_ID_NOT_KNOWN ; + raw_id = g_hash_table_lookup (gv_prop_hash, a_prop); + if (!raw_id) { + return PROP_ID_NOT_KNOWN; } - return GPOINTER_TO_INT (raw_id) ; + return GPOINTER_TO_INT (raw_id); } - static enum CRStatus -set_prop_padding_x_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) +set_prop_padding_x_from_value (CRStyle * a_style, + CRTerm * a_value, enum CRDirection a_dir) { - enum CRStatus status = CR_OK ; - CRNum *num_val = NULL, *parent_num_val = NULL ; + enum CRStatus status = CR_OK; + CRNum *num_val = NULL, + *parent_num_val = NULL; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - if (a_value->type != TERM_NUMBER - && a_value->type != TERM_IDENT) - return CR_BAD_PARAM_ERROR ; + if (a_value->type != TERM_NUMBER && a_value->type != TERM_IDENT) + return CR_BAD_PARAM_ERROR; - switch (a_dir) - { + switch (a_dir) { case DIR_TOP: - num_val = &a_style->num_props[NUM_PROP_PADDING_TOP].sv ; - parent_num_val = + num_val = &a_style->num_props[NUM_PROP_PADDING_TOP].sv; + parent_num_val = &a_style->parent_style-> - num_props[NUM_PROP_PADDING_TOP].sv ; - break ; - + num_props[NUM_PROP_PADDING_TOP].sv; + break; + case DIR_RIGHT: - num_val = &a_style->num_props[NUM_PROP_PADDING_RIGHT].sv ; - parent_num_val = - &a_style->parent_style-> + num_val = &a_style->num_props[NUM_PROP_PADDING_RIGHT].sv; + parent_num_val = + &a_style->parent_style-> num_props[NUM_PROP_PADDING_RIGHT].sv; - num_val = &a_style->num_props[NUM_PROP_PADDING_RIGHT].sv ; + num_val = &a_style->num_props[NUM_PROP_PADDING_RIGHT].sv; parent_num_val = &a_style->parent_style-> - num_props[NUM_PROP_PADDING_RIGHT].sv ; - break ; + num_props[NUM_PROP_PADDING_RIGHT].sv; + break; case DIR_BOTTOM: - num_val = - &a_style->num_props[NUM_PROP_PADDING_BOTTOM].sv ; - parent_num_val = + num_val = &a_style->num_props[NUM_PROP_PADDING_BOTTOM].sv; + parent_num_val = &a_style->parent_style-> - num_props[NUM_PROP_PADDING_BOTTOM].sv ; - break ; + num_props[NUM_PROP_PADDING_BOTTOM].sv; + break; case DIR_LEFT: - num_val = & a_style->num_props[NUM_PROP_PADDING_LEFT].sv ; - parent_num_val = + num_val = &a_style->num_props[NUM_PROP_PADDING_LEFT].sv; + parent_num_val = &a_style->parent_style-> - num_props[NUM_PROP_PADDING_LEFT].sv ; - break ; + num_props[NUM_PROP_PADDING_LEFT].sv; + break; default: - return CR_BAD_PARAM_ERROR ; + return CR_BAD_PARAM_ERROR; } - if (a_value->type == TERM_IDENT) - { + if (a_value->type == TERM_IDENT) { if (a_value->content.str && a_value->content.str->str - && !strncmp ((guchar*)"inherited", + && !strncmp ((guchar *) "inherited", a_value->content.str->str, - strlen ("inherited"))) - { - cr_num_copy (num_val, parent_num_val) ; - return CR_OK ; - } - else - return CR_UNKNOWN_TYPE_ERROR ; + strlen ("inherited"))) { + cr_num_copy (num_val, parent_num_val); + return CR_OK; + } else + return CR_UNKNOWN_TYPE_ERROR; } g_return_val_if_fail (a_value->type == TERM_NUMBER - && a_value->content.num, - CR_UNKNOWN_TYPE_ERROR) ; + && a_value->content.num, CR_UNKNOWN_TYPE_ERROR); - switch (a_value->content.num->type) - { + switch (a_value->content.num->type) { case NUM_LENGTH_EM: case NUM_LENGTH_EX: case NUM_LENGTH_PX: @@ -530,704 +490,581 @@ set_prop_padding_x_from_value (CRStyle *a_style, case NUM_LENGTH_PT: case NUM_LENGTH_PC: case NUM_PERCENTAGE: - status = cr_num_copy (num_val, a_value->content.num) ; - break ; + status = cr_num_copy (num_val, a_value->content.num); + break; default: - status = CR_UNKNOWN_TYPE_ERROR ; - break ; + status = CR_UNKNOWN_TYPE_ERROR; + break; } - return status ; + return status; } - static enum CRStatus -set_prop_border_x_width_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) +set_prop_border_x_width_from_value (CRStyle * a_style, + CRTerm * a_value, enum CRDirection a_dir) { - enum CRStatus status = CR_OK ; - CRNum *num_val = NULL ; + enum CRStatus status = CR_OK; + CRNum *num_val = NULL; - g_return_val_if_fail (a_value - && a_style, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_value && a_style, CR_BAD_PARAM_ERROR); - switch (a_dir) - { + switch (a_dir) { case DIR_TOP: - num_val = &a_style->num_props[NUM_PROP_BORDER_TOP].sv ; - break ; + num_val = &a_style->num_props[NUM_PROP_BORDER_TOP].sv; + break; case DIR_RIGHT: - num_val = - &a_style->num_props[NUM_PROP_BORDER_RIGHT].sv ; - break ; + num_val = &a_style->num_props[NUM_PROP_BORDER_RIGHT].sv; + break; case DIR_BOTTOM: - num_val = &a_style->num_props[NUM_PROP_BORDER_BOTTOM].sv ; - break ; + num_val = &a_style->num_props[NUM_PROP_BORDER_BOTTOM].sv; + break; case DIR_LEFT: - num_val = &a_style->num_props[NUM_PROP_BORDER_LEFT].sv ; - break ; + num_val = &a_style->num_props[NUM_PROP_BORDER_LEFT].sv; + break; default: - return CR_BAD_PARAM_ERROR ; - break ; + return CR_BAD_PARAM_ERROR; + break; } - - if (a_value->type == TERM_IDENT) - { - if (a_value->content.str && a_value->content.str->str) - { - if (!strncmp ("thin", + if (a_value->type == TERM_IDENT) { + if (a_value->content.str && a_value->content.str->str) { + if (!strncmp ("thin", a_value->content.str->str, - strlen ("thin"))) - { + strlen ("thin"))) { cr_num_set (num_val, BORDER_THIN, - NUM_LENGTH_PX) ; - } - else if (!strncmp ("medium", - a_value->content.str->str, - strlen ("medium"))) - { + NUM_LENGTH_PX); + } else if (!strncmp ("medium", + a_value->content.str->str, + strlen ("medium"))) { cr_num_set (num_val, BORDER_MEDIUM, - NUM_LENGTH_PX) ; - } - else if (!strncmp ("thick", - a_value->content.str->str, - strlen ("thick"))) - { + NUM_LENGTH_PX); + } else if (!strncmp ("thick", + a_value->content.str->str, + strlen ("thick"))) { cr_num_set (num_val, BORDER_THICK, - NUM_LENGTH_PX) ; - } - else - { - return CR_UNKNOWN_TYPE_ERROR ; + NUM_LENGTH_PX); + } else { + return CR_UNKNOWN_TYPE_ERROR; } } - } - else if (a_value->type == TERM_NUMBER) - { - if (a_value->content.num) - { - cr_num_copy (num_val, a_value->content.num) ; + } else if (a_value->type == TERM_NUMBER) { + if (a_value->content.num) { + cr_num_copy (num_val, a_value->content.num); } + } else if (a_value->type != TERM_NUMBER + || a_value->content.num == NULL) { + return CR_UNKNOWN_TYPE_ERROR; } - else if (a_value->type != TERM_NUMBER - || a_value->content.num == NULL) - { - return CR_UNKNOWN_TYPE_ERROR ; - } - - return status ; -} + return status; +} static enum CRStatus -set_prop_border_x_style_from_value (CRStyle *a_style, - CRTerm *a_value, - enum CRDirection a_dir) +set_prop_border_x_style_from_value (CRStyle * a_style, + CRTerm * a_value, enum CRDirection a_dir) { - enum CRStatus status = CR_OK ; - enum CRBorderStyle *border_style_ptr=NULL, + enum CRStatus status = CR_OK; + enum CRBorderStyle *border_style_ptr = NULL, *parent_border_style_ptr = NULL; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_dir) - { + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); + + switch (a_dir) { case DIR_TOP: border_style_ptr = &a_style-> - border_style_props[BORDER_STYLE_PROP_TOP] ; - parent_border_style_ptr = (a_style->parent_style)? + border_style_props[BORDER_STYLE_PROP_TOP]; + parent_border_style_ptr = (a_style->parent_style) ? &a_style->parent_style-> - border_style_props[BORDER_STYLE_PROP_TOP]: NULL ; + border_style_props[BORDER_STYLE_PROP_TOP] : NULL; - break ; + break; case DIR_RIGHT: - border_style_ptr = - &a_style->border_style_props[BORDER_STYLE_PROP_RIGHT] ; + border_style_ptr = + &a_style->border_style_props[BORDER_STYLE_PROP_RIGHT]; - parent_border_style_ptr = (a_style->parent_style)? + parent_border_style_ptr = (a_style->parent_style) ? &a_style->parent_style-> - border_style_props[BORDER_STYLE_PROP_RIGHT] : NULL ; - break ; + border_style_props[BORDER_STYLE_PROP_RIGHT] : NULL; + break; case DIR_BOTTOM: border_style_ptr = &a_style-> - border_style_props[BORDER_STYLE_PROP_BOTTOM] ; - parent_border_style_ptr = (a_style->parent_style)? + border_style_props[BORDER_STYLE_PROP_BOTTOM]; + parent_border_style_ptr = (a_style->parent_style) ? &a_style->parent_style-> border_style_props[BORDER_STYLE_PROP_BOTTOM] : NULL; - break ; + break; case DIR_LEFT: border_style_ptr = &a_style-> - border_style_props[BORDER_STYLE_PROP_LEFT] ; - parent_border_style_ptr = (a_style->parent_style)? + border_style_props[BORDER_STYLE_PROP_LEFT]; + parent_border_style_ptr = (a_style->parent_style) ? &a_style->parent_style-> border_style_props[BORDER_STYLE_PROP_LEFT] : NULL; - break ; + break; default: - break ; - } - - if (a_value->type != TERM_IDENT - || !a_value->content.str) - { - return CR_UNKNOWN_TYPE_ERROR ; - } - - if (!strncmp ("none", - a_value->content.str->str, - strlen ("none"))) - { - *border_style_ptr = BORDER_STYLE_NONE ; - } - else if (!strncmp ("hidden", - a_value->content.str->str, - strlen ("hidden"))) - { - *border_style_ptr = BORDER_STYLE_HIDDEN ; - } - else if (!strncmp ("dotted", - a_value->content.str->str, - strlen ("dotted"))) - { - *border_style_ptr = BORDER_STYLE_DOTTED ; - } - else if (!strncmp ("dashed", - a_value->content.str->str, - strlen ("dashed"))) - { - *border_style_ptr = BORDER_STYLE_DASHED ; - } - else if (!strncmp ("solid", - a_value->content.str->str, - strlen ("solid"))) - { - *border_style_ptr = BORDER_STYLE_SOLID ; - } - else if (!strncmp ("double", - a_value->content.str->str, - strlen ("double"))) - { - *border_style_ptr = BORDER_STYLE_DOUBLE ; - } - else if (!strncmp ("groove", - a_value->content.str->str, - strlen ("groove"))) - { - *border_style_ptr = BORDER_STYLE_GROOVE ; - } - else if (!strncmp ("ridge", - a_value->content.str->str, - strlen ("ridge"))) - { - *border_style_ptr = BORDER_STYLE_RIDGE ; - } - else if (!strncmp ("inset", - a_value->content.str->str, - strlen ("inset"))) - { - *border_style_ptr = BORDER_STYLE_INSET ; - } - else if (!strncmp ("outset", - a_value->content.str->str, - strlen ("outset"))) - { - *border_style_ptr = BORDER_STYLE_OUTSET ; - } - else if (!strncmp ("inherit", - a_value->content.str->str, - strlen ("inherit"))) - { + break; + } + + if (a_value->type != TERM_IDENT || !a_value->content.str) { + return CR_UNKNOWN_TYPE_ERROR; + } + + if (!strncmp ("none", a_value->content.str->str, strlen ("none"))) { + *border_style_ptr = BORDER_STYLE_NONE; + } else if (!strncmp ("hidden", + a_value->content.str->str, strlen ("hidden"))) { + *border_style_ptr = BORDER_STYLE_HIDDEN; + } else if (!strncmp ("dotted", + a_value->content.str->str, strlen ("dotted"))) { + *border_style_ptr = BORDER_STYLE_DOTTED; + } else if (!strncmp ("dashed", + a_value->content.str->str, strlen ("dashed"))) { + *border_style_ptr = BORDER_STYLE_DASHED; + } else if (!strncmp ("solid", + a_value->content.str->str, strlen ("solid"))) { + *border_style_ptr = BORDER_STYLE_SOLID; + } else if (!strncmp ("double", + a_value->content.str->str, strlen ("double"))) { + *border_style_ptr = BORDER_STYLE_DOUBLE; + } else if (!strncmp ("groove", + a_value->content.str->str, strlen ("groove"))) { + *border_style_ptr = BORDER_STYLE_GROOVE; + } else if (!strncmp ("ridge", + a_value->content.str->str, strlen ("ridge"))) { + *border_style_ptr = BORDER_STYLE_RIDGE; + } else if (!strncmp ("inset", + a_value->content.str->str, strlen ("inset"))) { + *border_style_ptr = BORDER_STYLE_INSET; + } else if (!strncmp ("outset", + a_value->content.str->str, strlen ("outset"))) { + *border_style_ptr = BORDER_STYLE_OUTSET; + } else if (!strncmp ("inherit", + a_value->content.str->str, strlen ("inherit"))) { if (parent_border_style_ptr) - *border_style_ptr = *parent_border_style_ptr ; - } - else - { - status = CR_UNKNOWN_TYPE_ERROR ; + *border_style_ptr = *parent_border_style_ptr; + } else { + status = CR_UNKNOWN_TYPE_ERROR; } - return status ; + return status; } static enum CRStatus -set_prop_margin_x_from_value (CRStyle *a_style, CRTerm *a_value, +set_prop_margin_x_from_value (CRStyle * a_style, CRTerm * a_value, enum CRDirection a_dir) { - enum CRStatus status = CR_OK ; - CRNum *num_val = NULL, *parent_num_val = NULL ; + enum CRStatus status = CR_OK; + CRNum *num_val = NULL, + *parent_num_val = NULL; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - switch (a_dir) - { + switch (a_dir) { case DIR_TOP: - num_val = &a_style->num_props[NUM_PROP_MARGIN_TOP].sv ; - parent_num_val = + num_val = &a_style->num_props[NUM_PROP_MARGIN_TOP].sv; + parent_num_val = &a_style->parent_style-> - num_props[NUM_PROP_MARGIN_TOP].sv ; - break ; + num_props[NUM_PROP_MARGIN_TOP].sv; + break; case DIR_RIGHT: - num_val = - &a_style->num_props[NUM_PROP_MARGIN_RIGHT].sv ; + num_val = &a_style->num_props[NUM_PROP_MARGIN_RIGHT].sv; - parent_num_val = + parent_num_val = &a_style->parent_style-> - num_props[NUM_PROP_MARGIN_RIGHT].sv ; - break ; + num_props[NUM_PROP_MARGIN_RIGHT].sv; + break; case DIR_BOTTOM: - num_val = &a_style->num_props[NUM_PROP_MARGIN_BOTTOM].sv ; - parent_num_val = - &a_style->parent_style->num_props[NUM_PROP_MARGIN_BOTTOM].sv ; - break ; + num_val = &a_style->num_props[NUM_PROP_MARGIN_BOTTOM].sv; + parent_num_val = + &a_style->parent_style-> + num_props[NUM_PROP_MARGIN_BOTTOM].sv; + break; case DIR_LEFT: - num_val = &a_style->num_props[NUM_PROP_MARGIN_LEFT].sv ; - parent_num_val = + num_val = &a_style->num_props[NUM_PROP_MARGIN_LEFT].sv; + parent_num_val = &a_style->parent_style-> - num_props[NUM_PROP_MARGIN_LEFT].sv ; - break ; + num_props[NUM_PROP_MARGIN_LEFT].sv; + break; default: - break ; + break; } - switch (a_value->type) - { + switch (a_value->type) { case TERM_IDENT: - if (a_value->content.str + if (a_value->content.str && a_value->content.str->str && !strncmp (a_value->content.str->str, - "inherit", strlen ("inherit"))) - { - status = cr_num_copy (num_val, parent_num_val) ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strncmp (a_value->content.str->str, - "auto", strlen ("auto"))) - { - status = cr_num_set (num_val, 0.0, NUM_AUTO) ; - } - else - { - status = CR_UNKNOWN_TYPE_ERROR ; + "inherit", strlen ("inherit"))) { + status = cr_num_copy (num_val, parent_num_val); + } else if (a_value->content.str + && a_value->content.str->str + && !strncmp (a_value->content.str->str, + "auto", strlen ("auto"))) { + status = cr_num_set (num_val, 0.0, NUM_AUTO); + } else { + status = CR_UNKNOWN_TYPE_ERROR; } case TERM_NUMBER: - status = cr_num_copy (num_val, a_value->content.num) ; - break ; + status = cr_num_copy (num_val, a_value->content.num); + break; default: - status = CR_UNKNOWN_TYPE_ERROR ; - break ; + status = CR_UNKNOWN_TYPE_ERROR; + break; } - return status ; + return status; } -struct CRPropDisplayValPair -{ - const guchar *prop_name ; +struct CRPropDisplayValPair { + const guchar *prop_name; enum CRDisplayType type; -} ; +}; static enum CRStatus -set_prop_display_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_display_from_value (CRStyle * a_style, CRTerm * a_value) { - enum CRDisplayType default_display_val = DISPLAY_INLINE ; - static const struct CRPropDisplayValPair disp_vals_map[] = - { - {"none", DISPLAY_NONE}, - {"inline", DISPLAY_INLINE}, - {"block", DISPLAY_BLOCK}, - {"run-in", DISPLAY_RUN_IN}, - {"compact", DISPLAY_COMPACT}, - {"marker", DISPLAY_MARKER}, - {"table", DISPLAY_TABLE}, - {"inline-table", DISPLAY_INLINE_TABLE}, - {"table-row-group", DISPLAY_TABLE_ROW_GROUP}, - {"table-header-group", DISPLAY_TABLE_HEADER_GROUP}, - {"table-footer-group", DISPLAY_TABLE_FOOTER_GROUP}, - {"table-row", DISPLAY_TABLE_ROW}, - {"table-column-group", DISPLAY_TABLE_COLUMN_GROUP}, - {"table-column", DISPLAY_TABLE_COLUMN}, - {"table-cell", DISPLAY_TABLE_CELL}, - {"table-caption", DISPLAY_TABLE_CAPTION}, - {"inherit", DISPLAY_INHERIT}, - {NULL, DISPLAY_NONE} - } ; - - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; - - /*Sets to its default value according to the css2 spec.*/ - a_style->display = default_display_val ; - - switch (a_value->type) - { + enum CRDisplayType default_display_val = DISPLAY_INLINE; + static const struct CRPropDisplayValPair disp_vals_map[] = { + {"none", DISPLAY_NONE}, + {"inline", DISPLAY_INLINE}, + {"block", DISPLAY_BLOCK}, + {"run-in", DISPLAY_RUN_IN}, + {"compact", DISPLAY_COMPACT}, + {"marker", DISPLAY_MARKER}, + {"table", DISPLAY_TABLE}, + {"inline-table", DISPLAY_INLINE_TABLE}, + {"table-row-group", DISPLAY_TABLE_ROW_GROUP}, + {"table-header-group", DISPLAY_TABLE_HEADER_GROUP}, + {"table-footer-group", DISPLAY_TABLE_FOOTER_GROUP}, + {"table-row", DISPLAY_TABLE_ROW}, + {"table-column-group", DISPLAY_TABLE_COLUMN_GROUP}, + {"table-column", DISPLAY_TABLE_COLUMN}, + {"table-cell", DISPLAY_TABLE_CELL}, + {"table-caption", DISPLAY_TABLE_CAPTION}, + {"inherit", DISPLAY_INHERIT}, + {NULL, DISPLAY_NONE} + }; + + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); + + /*Sets to its default value according to the css2 spec. */ + a_style->display = default_display_val; + + switch (a_value->type) { case TERM_IDENT: - { - int i = 0 ; - - if (!a_value->content.str || !a_value->content.str->str) - break ; - - for (i = 0; disp_vals_map[i].prop_name ; i++) { - if (!strncmp (disp_vals_map[i].prop_name, - a_value->content.str->str, - strlen - (disp_vals_map[i].prop_name))) - { - a_style->display = disp_vals_map[i].type ; - break ; + int i = 0; + + if (!a_value->content.str + || !a_value->content.str->str) + break; + + for (i = 0; disp_vals_map[i].prop_name; i++) { + if (!strncmp (disp_vals_map[i].prop_name, + a_value->content.str->str, + strlen + (disp_vals_map[i].prop_name))) { + a_style->display = + disp_vals_map[i].type; + break; + } } - } - if (a_style->display == DISPLAY_INHERIT) - { - if (a_style->parent_style) - { - a_style->display = - a_style->parent_style->display ; - } - else - { - a_style->display = default_display_val ; + if (a_style->display == DISPLAY_INHERIT) { + if (a_style->parent_style) { + a_style->display = + a_style->parent_style-> + display; + } else { + a_style->display = + default_display_val; + } } } - } - break ; + break; - default : - break ; + default: + break; } - return CR_OK ; + return CR_OK; } -struct CRPropPositionValPair -{ - const guchar * name ; - enum CRPositionType type ; -} ; +struct CRPropPositionValPair { + const guchar *name; + enum CRPositionType type; +}; static enum CRStatus -set_prop_position_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_position_from_value (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_UNKNOWN_PROP_VAL_ERROR ; - static const struct CRPropPositionValPair position_vals_map [] = - { - {"static", POSITION_STATIC}, - {"relative", POSITION_RELATIVE}, - {"absolute", POSITION_ABSOLUTE}, - {"fixed", POSITION_FIXED}, - {"inherited", POSITION_INHERIT}, - {NULL, POSITION_STATIC} - /*must alwas be the last one*/ - } ; - - g_return_val_if_fail (a_value, CR_BAD_PARAM_ERROR) ; - - /*set to it's default value according to the css2 spec*/ - a_style->position = POSITION_STATIC ; - - switch (a_value->type) - { + enum CRStatus status = CR_UNKNOWN_PROP_VAL_ERROR; + static const struct CRPropPositionValPair position_vals_map[] = { + {"static", POSITION_STATIC}, + {"relative", POSITION_RELATIVE}, + {"absolute", POSITION_ABSOLUTE}, + {"fixed", POSITION_FIXED}, + {"inherited", POSITION_INHERIT}, + {NULL, POSITION_STATIC} + /*must alwas be the last one */ + }; + + g_return_val_if_fail (a_value, CR_BAD_PARAM_ERROR); + + /*set to it's default value according to the css2 spec */ + a_style->position = POSITION_STATIC; + + switch (a_value->type) { case TERM_IDENT: - { - int i = 0 ; - - if (!a_value->content.str || !a_value->content.str->str) - break ; - - for (i = 0; position_vals_map[i].name ; i++) { - if (!strncmp (position_vals_map[i].name, - a_value->content.str->str, - strlen (position_vals_map[i].name))) - { - a_style->position = - position_vals_map[i].type ; - status = CR_OK ; - break ; + int i = 0; + + if (!a_value->content.str + || !a_value->content.str->str) + break; + + for (i = 0; position_vals_map[i].name; i++) { + if (!strncmp (position_vals_map[i].name, + a_value->content.str->str, + strlen (position_vals_map[i]. + name))) { + a_style->position = + position_vals_map[i].type; + status = CR_OK; + break; + } } - } - if (a_style->position == POSITION_INHERIT) - { - if (a_style->parent_style) - { - a_style->position = - a_style->parent_style->position ; - } - else - { - a_style->position = POSITION_STATIC ; + if (a_style->position == POSITION_INHERIT) { + if (a_style->parent_style) { + a_style->position = + a_style->parent_style-> + position; + } else { + a_style->position = POSITION_STATIC; + } } } - } - break ; + break; default: - break ; + break; } - return CR_OK ; + return CR_OK; } static enum CRStatus -set_prop_x_from_value (CRStyle *a_style, CRTerm *a_value, +set_prop_x_from_value (CRStyle * a_style, CRTerm * a_value, enum CRDirection a_dir) { - CRNum *box_offset = NULL, *parent_box_offset = NULL ; + CRNum *box_offset = NULL, + *parent_box_offset = NULL; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - if (!(a_value->type == TERM_NUMBER) - && !(a_value->type == TERM_IDENT)) - { - return CR_UNKNOWN_PROP_VAL_ERROR ; + && !(a_value->type == TERM_IDENT)) { + return CR_UNKNOWN_PROP_VAL_ERROR; } - - switch (a_dir) - { + + switch (a_dir) { case DIR_TOP: - box_offset = &a_style->num_props[NUM_PROP_TOP].sv ; + box_offset = &a_style->num_props[NUM_PROP_TOP].sv; if (a_style->parent_style) - parent_box_offset = + parent_box_offset = &a_style->parent_style-> - num_props[NUM_PROP_TOP].sv ; - break ; + num_props[NUM_PROP_TOP].sv; + break; - case DIR_RIGHT: - box_offset = &a_style->num_props[NUM_PROP_RIGHT].sv ; + case DIR_RIGHT: + box_offset = &a_style->num_props[NUM_PROP_RIGHT].sv; if (a_style->parent_style) parent_box_offset = &a_style->parent_style-> - num_props[NUM_PROP_RIGHT].sv ; - break ; + num_props[NUM_PROP_RIGHT].sv; + break; case DIR_BOTTOM: - box_offset = &a_style->num_props[NUM_PROP_BOTTOM].sv ; + box_offset = &a_style->num_props[NUM_PROP_BOTTOM].sv; if (a_style->parent_style) - parent_box_offset = + parent_box_offset = &a_style->parent_style-> - num_props[NUM_PROP_BOTTOM].sv ; - break ; + num_props[NUM_PROP_BOTTOM].sv; + break; case DIR_LEFT: - box_offset = &a_style->num_props[NUM_PROP_LEFT].sv ; + box_offset = &a_style->num_props[NUM_PROP_LEFT].sv; if (a_style->parent_style) - parent_box_offset = + parent_box_offset = &a_style->parent_style-> - num_props[NUM_PROP_LEFT].sv ; - break ; + num_props[NUM_PROP_LEFT].sv; + break; default: - break ; + break; } - box_offset->type = NUM_AUTO ; + box_offset->type = NUM_AUTO; - if (a_value->type == TERM_NUMBER - && a_value->content.num) - { - cr_num_copy (box_offset, a_value->content.num) ; - } - else if (a_value->type == TERM_IDENT - && a_value->content.str - && a_value->content.str->str) - { - if (!strncmp ("inherit", + if (a_value->type == TERM_NUMBER && a_value->content.num) { + cr_num_copy (box_offset, a_value->content.num); + } else if (a_value->type == TERM_IDENT + && a_value->content.str && a_value->content.str->str) { + if (!strncmp ("inherit", a_value->content.str->str, - strlen ("inherit"))) - { - cr_num_copy (box_offset, - parent_box_offset) ; - } - else if (!strncmp ("auto", - a_value->content.str->str, - strlen ("auto"))) - { - box_offset->type = NUM_AUTO ; + strlen ("inherit"))) { + cr_num_copy (box_offset, parent_box_offset); + } else if (!strncmp ("auto", + a_value->content.str->str, + strlen ("auto"))) { + box_offset->type = NUM_AUTO; } } - return CR_OK ; + return CR_OK; } - static enum CRStatus -set_prop_float (CRStyle *a_style, CRTerm *a_value) +set_prop_float (CRStyle * a_style, CRTerm * a_value) { - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - /*the default float type as specified by the css2 spec*/ - a_style->float_type = FLOAT_NONE ; + /*the default float type as specified by the css2 spec */ + a_style->float_type = FLOAT_NONE; - if (a_value->type != TERM_IDENT - || !a_value->content.str - || !a_value->content.str->str) - {/*unknow type, the float type is set to it's default value*/ - return CR_OK ; + if (a_value->type != TERM_IDENT || !a_value->content.str || !a_value->content.str->str) { /*unknow type, the float type is set to it's default value */ + return CR_OK; } - if (!strncmp ("none", - a_value->content.str->str, - strlen ("none"))) - { - a_style->float_type = FLOAT_NONE ; - } - else if (!strncmp ("left", - a_value->content.str->str, - strlen ("left"))) - { - a_style->float_type = FLOAT_LEFT ; - } - else if (!strncmp ("right", - a_value->content.str->str, - strlen ("right"))) - { - a_style->float_type = FLOAT_RIGHT ; - } - else if (!strncmp ("inherit", - a_value->content.str->str, - strlen ("inherit"))) - { - a_style->float_type = - a_style->parent_style->float_type ; + if (!strncmp ("none", a_value->content.str->str, strlen ("none"))) { + a_style->float_type = FLOAT_NONE; + } else if (!strncmp ("left", + a_value->content.str->str, strlen ("left"))) { + a_style->float_type = FLOAT_LEFT; + } else if (!strncmp ("right", + a_value->content.str->str, strlen ("right"))) { + a_style->float_type = FLOAT_RIGHT; + } else if (!strncmp ("inherit", + a_value->content.str->str, strlen ("inherit"))) { + a_style->float_type = a_style->parent_style->float_type; } - return CR_OK ; + return CR_OK; } - static enum CRStatus -set_prop_width (CRStyle *a_style, CRTerm *a_value) +set_prop_width (CRStyle * a_style, CRTerm * a_value) { - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - - a_style->num_props[NUM_PROP_WIDTH].sv.type = NUM_AUTO ; - - if (a_value->type == TERM_IDENT) - { - if (a_value->content.str - && a_value->content.str->str) - { + a_style->num_props[NUM_PROP_WIDTH].sv.type = NUM_AUTO; + + if (a_value->type == TERM_IDENT) { + if (a_value->content.str && a_value->content.str->str) { if (!strncmp ("auto", a_value->content.str->str, - strlen ("auto"))) - { - a_style->num_props[NUM_PROP_WIDTH].sv.type = - NUM_AUTO ; - } - else if (!strncmp ("inherit", - a_value->content.str->str, - strlen ("inherit"))) - { - cr_num_copy + strlen ("auto"))) { + a_style->num_props[NUM_PROP_WIDTH].sv.type = + NUM_AUTO; + } else if (!strncmp ("inherit", + a_value->content.str->str, + strlen ("inherit"))) { + cr_num_copy (&a_style-> num_props[NUM_PROP_WIDTH].sv, &a_style->parent_style-> - num_props[NUM_PROP_WIDTH].sv) ; + num_props[NUM_PROP_WIDTH].sv); } } - } - else if (a_value->type == TERM_NUMBER) - { - if (a_value->content.num) - { + } else if (a_value->type == TERM_NUMBER) { + if (a_value->content.num) { cr_num_copy (&a_style->num_props[NUM_PROP_WIDTH].sv, - a_value->content.num) ; + a_value->content.num); } } - return CR_OK ; + return CR_OK; } static enum CRStatus -set_prop_color (CRStyle *a_style, CRTerm *a_value) +set_prop_color (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_OK ; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; + enum CRStatus status = CR_OK; - switch(a_value->type) { - case TERM_RGB: - if (a_value->content.rgb) - { + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); + + switch (a_value->type) { + case TERM_RGB: + if (a_value->content.rgb) { cr_rgb_set_from_rgb (&a_style->rgb_props[RGB_PROP_COLOR].sv, - a_value->content.rgb) ; + a_value->content.rgb); } - break ; - case TERM_IDENT: - status = cr_rgb_set_from_name + break; + case TERM_IDENT: + status = cr_rgb_set_from_name (&a_style->rgb_props[RGB_PROP_COLOR].sv, - a_value->content.str->str) ; - break ; - case TERM_HASH: + a_value->content.str->str); + break; + case TERM_HASH: status = cr_rgb_set_from_hex_str - (&a_style->rgb_props[RGB_PROP_COLOR].sv, - a_value->content.str->str) ; - break ; - default: - status = CR_UNKNOWN_TYPE_ERROR ; - } - - return status ; + (&a_style->rgb_props[RGB_PROP_COLOR].sv, + a_value->content.str->str); + break; + default: + status = CR_UNKNOWN_TYPE_ERROR; + } + + return status; } static enum CRStatus -set_prop_background_color (CRStyle *a_style, CRTerm *a_value) +set_prop_background_color (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - switch (a_value->type) - { + switch (a_value->type) { case TERM_RGB: - if (a_value->content.rgb) - { + if (a_value->content.rgb) { status = cr_rgb_set_from_rgb (&a_style-> rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.rgb) ; + a_value->content.rgb); } - break ; + break; case TERM_IDENT: - status = cr_rgb_set_from_name + status = cr_rgb_set_from_name (&a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.str->str) ; - break ; + a_value->content.str->str); + break; case TERM_HASH: status = cr_rgb_set_from_hex_str - (&a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, - a_value->content.str->str) ; - break ; + (&a_style->rgb_props[RGB_PROP_BACKGROUND_COLOR].sv, + a_value->content.str->str); + break; default: - status = CR_UNKNOWN_TYPE_ERROR ; - break ; + status = CR_UNKNOWN_TYPE_ERROR; + break; } - return status ; + return status; } /** @@ -1241,657 +1078,542 @@ set_prop_background_color (CRStyle *a_style, CRTerm *a_value) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -set_prop_border_x_color_from_value (CRStyle *a_style, CRTerm *a_value, +set_prop_border_x_color_from_value (CRStyle * a_style, CRTerm * a_value, enum CRDirection a_dir) { - CRRgb *rgb_color = NULL ; - enum CRStatus status = CR_OK ; - - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; - - switch (a_dir) - { + CRRgb *rgb_color = NULL; + enum CRStatus status = CR_OK; + + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); + + switch (a_dir) { case DIR_TOP: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_TOP_COLOR].sv ; - break ; + rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_TOP_COLOR].sv; + break; case DIR_RIGHT: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_RIGHT_COLOR].sv ; - break ; + rgb_color = + &a_style->rgb_props[RGB_PROP_BORDER_RIGHT_COLOR].sv; + break; case DIR_BOTTOM: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_BOTTOM_COLOR].sv; - break ; + rgb_color = + &a_style->rgb_props[RGB_PROP_BORDER_BOTTOM_COLOR].sv; + break; case DIR_LEFT: - rgb_color = &a_style->rgb_props[RGB_PROP_BORDER_LEFT_COLOR].sv ; - break ; + rgb_color = + &a_style->rgb_props[RGB_PROP_BORDER_LEFT_COLOR].sv; + break; default: - cr_utils_trace_info ("unknown DIR type") ; - return CR_BAD_PARAM_ERROR ; + cr_utils_trace_info ("unknown DIR type"); + return CR_BAD_PARAM_ERROR; } - status = CR_UNKNOWN_PROP_VAL_ERROR ; + status = CR_UNKNOWN_PROP_VAL_ERROR; + + if (a_value->type == TERM_IDENT) { + if (a_value->content.str && a_value->content.str->str) { + status = cr_rgb_set_from_name + (rgb_color, a_value->content.str->str); - if (a_value->type == TERM_IDENT) - { - if (a_value->content.str && a_value->content.str->str) - { - status = cr_rgb_set_from_name - (rgb_color, a_value->content.str->str) ; - } - if (status != CR_OK) - { - cr_rgb_set_from_name (rgb_color, "black") ; + if (status != CR_OK) { + cr_rgb_set_from_name (rgb_color, "black"); } - } - else if (a_value->type == TERM_RGB) - { - if (a_value->content.rgb) - { - status = cr_rgb_set_from_rgb - (rgb_color, a_value->content.rgb) ; + } else if (a_value->type == TERM_RGB) { + if (a_value->content.rgb) { + status = cr_rgb_set_from_rgb + (rgb_color, a_value->content.rgb); } } - return status ; + return status; } - static enum CRStatus -set_prop_border_x_from_value (CRStyle *a_style, CRTerm *a_value, +set_prop_border_x_from_value (CRStyle * a_style, CRTerm * a_value, enum CRDirection a_dir) { - CRTerm *cur_term = NULL ; + CRTerm *cur_term = NULL; - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - for (cur_term = a_value ; cur_term ; cur_term = cur_term->next) - { - status = - set_prop_border_x_width_from_value (a_style, cur_term, - a_dir) ; + for (cur_term = a_value; cur_term; cur_term = cur_term->next) { + status = set_prop_border_x_width_from_value (a_style, + cur_term, a_dir); - if (status != CR_OK) - { - status = set_prop_border_x_style_from_value - (a_style, cur_term, a_dir) ; + if (status != CR_OK) { + status = set_prop_border_x_style_from_value + (a_style, cur_term, a_dir); } - if (status != CR_OK) - { - status = set_prop_border_x_color_from_value - (a_style, cur_term, a_dir) ; + if (status != CR_OK) { + status = set_prop_border_x_color_from_value + (a_style, cur_term, a_dir); } } - return CR_OK ; + return CR_OK; } static enum CRStatus -set_prop_border_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_border_from_value (CRStyle * a_style, CRTerm * a_value) { - enum CRDirection direction = 0 ; + enum CRDirection direction = 0; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - for (direction = 0 ; direction < NB_DIRS ; direction ++) - { - set_prop_border_x_from_value (a_style, a_value, direction) ; + for (direction = 0; direction < NB_DIRS; direction++) { + set_prop_border_x_from_value (a_style, a_value, direction); } - return CR_OK ; + return CR_OK; } static enum CRStatus -set_prop_padding_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_padding_from_value (CRStyle * a_style, CRTerm * a_value) { - CRTerm *cur_term = NULL ; - enum CRDirection direction = 0 ; - enum CRStatus status = CR_OK ; + CRTerm *cur_term = NULL; + enum CRDirection direction = 0; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - cur_term = a_value ; - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + cur_term = a_value; + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; + return CR_OK; - for (direction = 0 ; direction < NB_DIRS ; direction ++) - { - set_prop_padding_x_from_value (a_style, cur_term, - direction) ; + for (direction = 0; direction < NB_DIRS; direction++) { + set_prop_padding_x_from_value (a_style, cur_term, direction); } - cur_term = cur_term->next ; + cur_term = cur_term->next; - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; + return CR_OK; - set_prop_padding_x_from_value (a_style, cur_term, DIR_RIGHT) ; - set_prop_padding_x_from_value (a_style, cur_term, DIR_LEFT) ; + set_prop_padding_x_from_value (a_style, cur_term, DIR_RIGHT); + set_prop_padding_x_from_value (a_style, cur_term, DIR_LEFT); - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; - - set_prop_padding_x_from_value (a_style, cur_term, DIR_BOTTOM) ; + return CR_OK; - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + set_prop_padding_x_from_value (a_style, cur_term, DIR_BOTTOM); + + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; + return CR_OK; - status = set_prop_padding_x_from_value (a_style, cur_term, DIR_LEFT) ; + status = set_prop_padding_x_from_value (a_style, cur_term, DIR_LEFT); - return status ; + return status; } static enum CRStatus -set_prop_margin_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_margin_from_value (CRStyle * a_style, CRTerm * a_value) { - CRTerm *cur_term = NULL ; - enum CRDirection direction = 0 ; - enum CRStatus status = CR_OK ; + CRTerm *cur_term = NULL; + enum CRDirection direction = 0; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - cur_term = a_value ; - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + cur_term = a_value; + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; + return CR_OK; - for (direction = 0 ; direction < NB_DIRS ; direction ++) - { - set_prop_margin_x_from_value (a_style, cur_term, - direction) ; + for (direction = 0; direction < NB_DIRS; direction++) { + set_prop_margin_x_from_value (a_style, cur_term, direction); } - cur_term = cur_term->next ; + cur_term = cur_term->next; - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; + return CR_OK; - set_prop_margin_x_from_value (a_style, cur_term, DIR_RIGHT) ; - set_prop_margin_x_from_value (a_style, cur_term, DIR_LEFT) ; + set_prop_margin_x_from_value (a_style, cur_term, DIR_RIGHT); + set_prop_margin_x_from_value (a_style, cur_term, DIR_LEFT); - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; - - set_prop_margin_x_from_value (a_style, cur_term, DIR_BOTTOM) ; + return CR_OK; + + set_prop_margin_x_from_value (a_style, cur_term, DIR_BOTTOM); - while (cur_term && cur_term->type != TERM_NUMBER) - { - cur_term = cur_term->next ; + while (cur_term && cur_term->type != TERM_NUMBER) { + cur_term = cur_term->next; } if (!cur_term) - return CR_OK ; + return CR_OK; - status = set_prop_margin_x_from_value (a_style, cur_term, DIR_LEFT) ; + status = set_prop_margin_x_from_value (a_style, cur_term, DIR_LEFT); - return status ; + return status; } static enum CRStatus -set_prop_font_family_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value) { - CRTerm *cur_term = NULL ; - CRFontFamily *font_family = NULL, *cur_ff = NULL, *cur_ff2 = NULL; + CRTerm *cur_term = NULL; + CRFontFamily *font_family = NULL, + *cur_ff = NULL, + *cur_ff2 = NULL; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - - for (cur_term = a_value ; cur_term ; cur_term = cur_term->next) - { - switch (cur_term->type) - { + for (cur_term = a_value; cur_term; cur_term = cur_term->next) { + switch (cur_term->type) { case TERM_IDENT: - { - enum CRFontFamilyType font_type ; - - if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "sans-serif")) { - font_type = FONT_FAMILY_SANS_SERIF ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "serif")) - { - font_type = FONT_FAMILY_SERIF ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "cursive")) - { - font_type = FONT_FAMILY_CURSIVE ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "fantasy")) - { - font_type = FONT_FAMILY_FANTASY ; - } - else if (cur_term->content.str - && cur_term->content.str->str - && ! strcmp (cur_term->content.str->str, - "monospace")) - { - font_type = FONT_FAMILY_MONOSPACE ; - } - else - { - /* - *unknown property value. - *ignore it. - */ - continue ; + enum CRFontFamilyType font_type; + + if (cur_term->content.str + && cur_term->content.str->str + && !strcmp (cur_term->content.str->str, + "sans-serif")) { + font_type = FONT_FAMILY_SANS_SERIF; + } else if (cur_term->content.str + && cur_term->content.str->str + && !strcmp (cur_term->content.str-> + str, "serif")) { + font_type = FONT_FAMILY_SERIF; + } else if (cur_term->content.str + && cur_term->content.str->str + && !strcmp (cur_term->content.str-> + str, "cursive")) { + font_type = FONT_FAMILY_CURSIVE; + } else if (cur_term->content.str + && cur_term->content.str->str + && !strcmp (cur_term->content.str-> + str, "fantasy")) { + font_type = FONT_FAMILY_FANTASY; + } else if (cur_term->content.str + && cur_term->content.str->str + && !strcmp (cur_term->content.str-> + str, "monospace")) { + font_type = FONT_FAMILY_MONOSPACE; + } else { + /* + *unknown property value. + *ignore it. + */ + continue; + } + + cur_ff = cr_font_family_new (font_type, NULL); } - - cur_ff = - cr_font_family_new (font_type, NULL) ; - } - break ; + break; case TERM_STRING: - { - if (cur_term->content.str - && cur_term->content.str->str) { - cur_ff = cr_font_family_new - (FONT_FAMILY_NON_GENERIC, - cur_term->content.str->str) ; + if (cur_term->content.str + && cur_term->content.str->str) { + cur_ff = cr_font_family_new + (FONT_FAMILY_NON_GENERIC, + cur_term->content.str->str); + } } - } - break ; + break; default: - break ; + break; } - cur_ff2 = cr_font_family_append (font_family, - cur_ff) ; - if (cur_ff2) - { - font_family = cur_ff2 ; + cur_ff2 = cr_font_family_append (font_family, cur_ff); + if (cur_ff2) { + font_family = cur_ff2; } } - - if (font_family) - { - if (a_style->font_family) - { - cr_font_family_destroy (a_style->font_family) ; - a_style->font_family = font_family ; + + if (font_family) { + if (a_style->font_family) { + cr_font_family_destroy (a_style->font_family); + a_style->font_family = font_family; } } - return CR_OK ; + return CR_OK; } static enum CRStatus -init_style_font_size_field (CRStyle *a_style) +init_style_font_size_field (CRStyle * a_style) { - g_return_val_if_fail (a_style, CR_BAD_PARAM_ERROR) ; - - if (!a_style->font_size) - { - a_style->font_size = cr_font_size_new () ; - if (!a_style->font_size) - { - return CR_INSTANCIATION_FAILED_ERROR ; + g_return_val_if_fail (a_style, CR_BAD_PARAM_ERROR); + + if (!a_style->font_size) { + a_style->font_size = cr_font_size_new (); + if (!a_style->font_size) { + return CR_INSTANCIATION_FAILED_ERROR; } + } else { + cr_font_size_clear (a_style->font_size); } - else - { - cr_font_size_clear (a_style->font_size) ; - } - - return CR_OK ; + + return CR_OK; } static enum CRStatus -set_prop_font_size_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - switch (a_value->type) - { + switch (a_value->type) { case TERM_IDENT: - if (a_value->content.str + if (a_value->content.str && a_value->content.str->str - && !strcmp (a_value->content.str->str, "xx-small")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_XX_SMALL ; - - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "x-small")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_X_SMALL ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "small")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_SMALL ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "medium")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_MEDIUM ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "large")) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_LARGE ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "x-large")) + && !strcmp (a_value->content.str->str, "xx-small")) { + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = + PREDEFINED_ABSOLUTE_FONT_SIZE; + a_style->font_size->value.predefined = + FONT_SIZE_XX_SMALL; + + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "x-small")) { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_X_LARGE ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "xx-large")) + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = + PREDEFINED_ABSOLUTE_FONT_SIZE; + a_style->font_size->value.predefined = + FONT_SIZE_X_SMALL; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "small")) { + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = + PREDEFINED_ABSOLUTE_FONT_SIZE; + a_style->font_size->value.predefined = + FONT_SIZE_SMALL; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "medium")) { + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = + PREDEFINED_ABSOLUTE_FONT_SIZE; + a_style->font_size->value.predefined = + FONT_SIZE_MEDIUM; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "large")) { + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = + PREDEFINED_ABSOLUTE_FONT_SIZE; + a_style->font_size->value.predefined = + FONT_SIZE_LARGE; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "x-large")) { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, - status) ; - - a_style->font_size->type = - PREDEFINED_ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.predefined = - FONT_SIZE_XX_LARGE ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "larger")) + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = + PREDEFINED_ABSOLUTE_FONT_SIZE; + a_style->font_size->value.predefined = + FONT_SIZE_X_LARGE; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "xx-large")) { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; - - a_style->font_size->type = - RELATIVE_FONT_SIZE ; - a_style->font_size->value.relative = - FONT_SIZE_LARGER ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "smaller")) + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = + PREDEFINED_ABSOLUTE_FONT_SIZE; + a_style->font_size->value.predefined = + FONT_SIZE_XX_LARGE; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "larger")) { + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = RELATIVE_FONT_SIZE; + a_style->font_size->value.relative = FONT_SIZE_LARGER; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "smaller")) { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; - - a_style->font_size->type = - RELATIVE_FONT_SIZE ; - a_style->font_size->value.relative = - FONT_SIZE_SMALLER ; - } - else if (a_value->content.str - && a_value->content.str->str - && !strcmp (a_value->content.str->str, "inherit")) + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); + + a_style->font_size->type = RELATIVE_FONT_SIZE; + a_style->font_size->value.relative = + FONT_SIZE_SMALLER; + } else if (a_value->content.str + && a_value->content.str->str + && !strcmp (a_value->content.str->str, "inherit")) { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); if (a_style->parent_style - && a_style->parent_style->font_style) - { - cr_font_size_copy + && a_style->parent_style->font_style) { + cr_font_size_copy (a_style->font_size, - a_style->parent_style->font_size) ; + a_style->parent_style->font_size); } + } else { + return CR_UNKNOWN_PROP_VAL_ERROR; } - else - { - return CR_UNKNOWN_PROP_VAL_ERROR ; - } - break ; + break; case TERM_NUMBER: - if (a_value->content.num) - { - status = init_style_font_size_field (a_style) ; - g_return_val_if_fail (status == CR_OK, status) ; + if (a_value->content.num) { + status = init_style_font_size_field (a_style); + g_return_val_if_fail (status == CR_OK, status); - a_style->font_size->type = ABSOLUTE_FONT_SIZE ; - a_style->font_size->value.absolute = - cr_num_dup (a_value->content.num) ; + a_style->font_size->type = ABSOLUTE_FONT_SIZE; + a_style->font_size->value.absolute = + cr_num_dup (a_value->content.num); } - break ; + break; default: - return CR_UNKNOWN_PROP_VAL_ERROR ; + return CR_UNKNOWN_PROP_VAL_ERROR; } - return CR_OK ; + return CR_OK; } static enum CRStatus -set_prop_font_style_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_font_style_from_value (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - switch (a_value->type) - { + switch (a_value->type) { case TERM_IDENT: - if (a_value->content.str && a_value->content.str->str) - { - if (!strcmp (a_value->content.str->str, "normal")) - { - a_style->font_style = FONT_STYLE_NORMAL ; - } - else if (!strcmp (a_value->content.str->str, "italic")) - { - a_style->font_style = FONT_STYLE_ITALIC ; - } - else if (!strcmp (a_value->content.str->str, "oblique")) - { - a_style->font_style = FONT_STYLE_OBLIQUE ; - } - else if (!strcmp (a_value->content.str->str, "inherit")) - { + if (a_value->content.str && a_value->content.str->str) { + if (!strcmp (a_value->content.str->str, "normal")) { + a_style->font_style = FONT_STYLE_NORMAL; + } else if (!strcmp + (a_value->content.str->str, "italic")) { + a_style->font_style = FONT_STYLE_ITALIC; + } else if (!strcmp + (a_value->content.str->str, "oblique")) { + a_style->font_style = FONT_STYLE_OBLIQUE; + } else if (!strcmp + (a_value->content.str->str, "inherit")) { if (!a_style->font_style) - a_style->font_style = FONT_STYLE_NORMAL; + a_style->font_style = + FONT_STYLE_NORMAL; else - a_style->font_style = + a_style->font_style = a_style->parent_style-> - font_style ; - } - else - { - status = CR_UNKNOWN_PROP_VAL_ERROR ; + font_style; + } else { + status = CR_UNKNOWN_PROP_VAL_ERROR; } } - break ; + break; default: - status = CR_UNKNOWN_PROP_VAL_ERROR ; - break ; + status = CR_UNKNOWN_PROP_VAL_ERROR; + break; } - return status ; + return status; } static enum CRStatus -set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) +set_prop_font_weight_from_value (CRStyle * a_style, CRTerm * a_value) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_style && a_value, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR); - switch (a_value->type) - { + switch (a_value->type) { case TERM_IDENT: - if (a_value->content.str && a_value->content.str->str) - { - if (!strcmp (a_value->content.str->str, - "normal")) - { - a_style->font_weight = FONT_WEIGHT_NORMAL ; - } - else if (!strcmp (a_value->content.str->str, - "bold")) - { - a_style->font_weight = FONT_WEIGHT_BOLD ; - } - else if (!strcmp (a_value->content.str->str, - "bolder")) - { - a_style->font_weight = FONT_WEIGHT_BOLDER ; - } - else if (!strcmp (a_value->content.str->str, - "lighter")) - { - a_style->font_weight = FONT_WEIGHT_LIGHTER ; - } - else - { - status = CR_UNKNOWN_PROP_VAL_ERROR ; + if (a_value->content.str && a_value->content.str->str) { + if (!strcmp (a_value->content.str->str, "normal")) { + a_style->font_weight = FONT_WEIGHT_NORMAL; + } else if (!strcmp (a_value->content.str->str, + "bold")) { + a_style->font_weight = FONT_WEIGHT_BOLD; + } else if (!strcmp (a_value->content.str->str, + "bolder")) { + a_style->font_weight = FONT_WEIGHT_BOLDER; + } else if (!strcmp (a_value->content.str->str, + "lighter")) { + a_style->font_weight = FONT_WEIGHT_LIGHTER; + } else { + status = CR_UNKNOWN_PROP_VAL_ERROR; } } - break ; + break; case TERM_NUMBER: - if (a_value->content.num + if (a_value->content.num && (a_value->content.num->type == NUM_GENERIC - ||a_value->content.num->type == NUM_AUTO)) - { - if (a_value->content.num->val <= 150) - { - a_style->font_weight = FONT_WEIGHT_100 ; - } - else if (a_value->content.num->val <= 250) - { - a_style->font_weight = FONT_WEIGHT_200 ; - } - else if (a_value->content.num->val <= 350) - { - a_style->font_weight = FONT_WEIGHT_300 ; - } - else if (a_value->content.num->val <= 450) - { - a_style->font_weight = FONT_WEIGHT_400 ; - } - else if (a_value->content.num->val <= 550) - { - a_style->font_weight = FONT_WEIGHT_500 ; - } - else if (a_value->content.num->val <= 650) - { - a_style->font_weight = FONT_WEIGHT_600 ; - } - else if (a_value->content.num->val <= 750) - { - a_style->font_weight = FONT_WEIGHT_700 ; + || a_value->content.num->type == NUM_AUTO)) { + if (a_value->content.num->val <= 150) { + a_style->font_weight = FONT_WEIGHT_100; + } else if (a_value->content.num->val <= 250) { + a_style->font_weight = FONT_WEIGHT_200; + } else if (a_value->content.num->val <= 350) { + a_style->font_weight = FONT_WEIGHT_300; + } else if (a_value->content.num->val <= 450) { + a_style->font_weight = FONT_WEIGHT_400; + } else if (a_value->content.num->val <= 550) { + a_style->font_weight = FONT_WEIGHT_500; + } else if (a_value->content.num->val <= 650) { + a_style->font_weight = FONT_WEIGHT_600; + } else if (a_value->content.num->val <= 750) { + a_style->font_weight = FONT_WEIGHT_700; + } else if (a_value->content.num->val <= 850) { + a_style->font_weight = FONT_WEIGHT_800; + } else { + a_style->font_weight = FONT_WEIGHT_900; } - else if (a_value->content.num->val <= 850) - { - a_style->font_weight = FONT_WEIGHT_800 ; - } - else - { - a_style->font_weight = FONT_WEIGHT_900 ; - } } - break ; + break; default: - status = CR_UNKNOWN_PROP_VAL_ERROR ; - break ; + status = CR_UNKNOWN_PROP_VAL_ERROR; + break; } - return status ; + return status; } /****************** @@ -1904,24 +1626,22 @@ set_prop_font_weight_from_value (CRStyle *a_style, CRTerm *a_value) CRStyle * cr_style_new (void) { - CRStyle *result = NULL ; + CRStyle *result = NULL; - result = g_try_malloc (sizeof (CRStyle)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } - memset (result, 0, sizeof (CRStyle)) ; - gv_prop_hash_ref_count ++ ; + result = g_try_malloc (sizeof (CRStyle)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } + memset (result, 0, sizeof (CRStyle)); + gv_prop_hash_ref_count++; - /*set the style properties to their default values*/ - cr_style_set_props_to_defaults (result) ; + /*set the style properties to their default values */ + cr_style_set_props_to_defaults (result); - return result ; + return result; } - /** *Sets the style properties to their default values *according to the css2 spec. @@ -1929,24 +1649,21 @@ cr_style_new (void) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_style_set_props_to_defaults (CRStyle *a_this) +cr_style_set_props_to_defaults (CRStyle * a_this) { - glong i = 0 ; + glong i = 0; - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - for (i = 0 ; i < NB_NUM_PROPS ; i++) - { - switch (i) - { + for (i = 0; i < NB_NUM_PROPS; i++) { + switch (i) { case NUM_PROP_WIDTH: case NUM_PROP_TOP: case NUM_PROP_RIGHT: case NUM_PROP_BOTTOM: case NUM_PROP_LEFT: - cr_num_set (&a_this->num_props[i].sv, - 0, NUM_AUTO) ; - break ; + cr_num_set (&a_this->num_props[i].sv, 0, NUM_AUTO); + break; case NUM_PROP_PADDING_TOP: case NUM_PROP_PADDING_RIGHT: @@ -1959,52 +1676,47 @@ cr_style_set_props_to_defaults (CRStyle *a_this) case NUM_PROP_MARGIN_TOP: case NUM_PROP_MARGIN_RIGHT: case NUM_PROP_MARGIN_BOTTOM: - case NUM_PROP_MARGIN_LEFT: + case NUM_PROP_MARGIN_LEFT: cr_num_set (&a_this->num_props[i].sv, - 0, NUM_LENGTH_PX) ; - break ; + 0, NUM_LENGTH_PX); + break; default: - cr_utils_trace_info ("Unknown property") ; - break ; + cr_utils_trace_info ("Unknown property"); + break; } } - for (i = 0 ; i < NB_RGB_PROPS ; i++) - { - - switch (i) - { - /*default foreground color is black*/ + for (i = 0; i < NB_RGB_PROPS; i++) { + + switch (i) { + /*default foreground color is black */ case RGB_PROP_COLOR: - cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, - FALSE) ; - break ; - - /*default background color is white*/ + cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, FALSE); + break; + + /*default background color is white */ case RGB_PROP_BACKGROUND_COLOR: - cr_rgb_set (&a_this->rgb_props[i].sv, - 255, 255, 255, FALSE) ; - break ; + cr_rgb_set (&a_this->rgb_props[i].sv, + 255, 255, 255, FALSE); + break; default: - cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, - FALSE) ; - break ; + cr_rgb_set (&a_this->rgb_props[i].sv, 0, 0, 0, FALSE); + break; } } - for (i = 0 ; i < NB_BORDER_STYLE_PROPS ; i++) - { - a_this->border_style_props[i] = BORDER_STYLE_NONE ; + for (i = 0; i < NB_BORDER_STYLE_PROPS; i++) { + a_this->border_style_props[i] = BORDER_STYLE_NONE; } - a_this->display = DISPLAY_BLOCK ; - a_this->position = POSITION_STATIC ; - a_this->float_type = FLOAT_NONE ; - a_this->parent_style = NULL ; + a_this->display = DISPLAY_BLOCK; + a_this->position = POSITION_STATIC; + a_this->float_type = FLOAT_NONE; + a_this->parent_style = NULL; - return CR_OK ; + return CR_OK; } /** @@ -2018,248 +1730,215 @@ cr_style_set_props_to_defaults (CRStyle *a_this) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl) +cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl) { - CRTerm *value = NULL ; - enum CRStatus status = CR_OK ; + CRTerm *value = NULL; + enum CRStatus status = CR_OK; - enum CRPropertyID prop_id = PROP_ID_NOT_KNOWN ; + enum CRPropertyID prop_id = PROP_ID_NOT_KNOWN; g_return_val_if_fail (a_this && a_decl && a_decl && a_decl->property - && a_decl->property->str, - CR_BAD_PARAM_ERROR) ; + && a_decl->property->str, CR_BAD_PARAM_ERROR); - prop_id = cr_style_get_prop_id (a_decl->property->str) ; + prop_id = cr_style_get_prop_id (a_decl->property->str); - value = a_decl->value ; - switch (prop_id) - { + value = a_decl->value; + switch (prop_id) { case PROP_ID_PADDING_TOP: - status = set_prop_padding_x_from_value - (a_this, value, DIR_TOP) ; - break ; + status = set_prop_padding_x_from_value + (a_this, value, DIR_TOP); + break; case PROP_ID_PADDING_RIGHT: - status = set_prop_padding_x_from_value - (a_this, value, DIR_RIGHT) ; - break ; + status = set_prop_padding_x_from_value + (a_this, value, DIR_RIGHT); + break; case PROP_ID_PADDING_BOTTOM: - status = set_prop_padding_x_from_value - (a_this, value, DIR_BOTTOM) ; - break ; + status = set_prop_padding_x_from_value + (a_this, value, DIR_BOTTOM); + break; case PROP_ID_PADDING_LEFT: - status = set_prop_padding_x_from_value - (a_this, value, DIR_LEFT) ; - break ; + status = set_prop_padding_x_from_value + (a_this, value, DIR_LEFT); + break; case PROP_ID_PADDING: - status = set_prop_padding_from_value (a_this, value) ; - break ; + status = set_prop_padding_from_value (a_this, value); + break; case PROP_ID_BORDER_TOP_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_TOP) ; - break ; + status = set_prop_border_x_width_from_value (a_this, value, + DIR_TOP); + break; case PROP_ID_BORDER_RIGHT_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_RIGHT) ; - break ; + status = set_prop_border_x_width_from_value (a_this, value, + DIR_RIGHT); + break; case PROP_ID_BORDER_BOTTOM_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_BOTTOM) ; - break ; + status = set_prop_border_x_width_from_value (a_this, value, + DIR_BOTTOM); + break; case PROP_ID_BORDER_LEFT_WIDTH: - status = - set_prop_border_x_width_from_value (a_this, value, - DIR_LEFT) ; - break ; + status = set_prop_border_x_width_from_value (a_this, value, + DIR_LEFT); + break; case PROP_ID_BORDER_TOP_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_TOP) ; - break ; + status = set_prop_border_x_style_from_value (a_this, value, + DIR_TOP); + break; case PROP_ID_BORDER_RIGHT_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_RIGHT) ; - break ; + status = set_prop_border_x_style_from_value (a_this, value, + DIR_RIGHT); + break; case PROP_ID_BORDER_BOTTOM_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_BOTTOM) ; - break ; + status = set_prop_border_x_style_from_value (a_this, value, + DIR_BOTTOM); + break; - case PROP_ID_BORDER_LEFT_STYLE: - status = - set_prop_border_x_style_from_value (a_this, value, - DIR_LEFT) ; - break ; + case PROP_ID_BORDER_LEFT_STYLE: + status = set_prop_border_x_style_from_value (a_this, value, + DIR_LEFT); + break; case PROP_ID_BORDER_TOP_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_TOP) ; - break ; + status = set_prop_border_x_color_from_value (a_this, value, + DIR_TOP); + break; case PROP_ID_BORDER_RIGHT_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_RIGHT) ; - break ; + status = set_prop_border_x_color_from_value (a_this, value, + DIR_RIGHT); + break; case PROP_ID_BORDER_BOTTOM_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_BOTTOM) ; - break ; + status = set_prop_border_x_color_from_value (a_this, value, + DIR_BOTTOM); + break; case PROP_ID_BORDER_LEFT_COLOR: - status = - set_prop_border_x_color_from_value (a_this, value, - DIR_BOTTOM) ; - break ; + status = set_prop_border_x_color_from_value (a_this, value, + DIR_BOTTOM); + break; case PROP_ID_BORDER_TOP: - status = - set_prop_border_x_from_value (a_this, value, - DIR_TOP) ; - break ; + status = set_prop_border_x_from_value (a_this, value, + DIR_TOP); + break; case PROP_ID_BORDER_RIGHT: - status = - set_prop_border_x_from_value (a_this, value, - DIR_RIGHT) ; - break ; + status = set_prop_border_x_from_value (a_this, value, + DIR_RIGHT); + break; case PROP_ID_BORDER_BOTTOM: - status = - set_prop_border_x_from_value (a_this, value, - DIR_BOTTOM) ; - break ; + status = set_prop_border_x_from_value (a_this, value, + DIR_BOTTOM); + break; case PROP_ID_BORDER_LEFT: - status = - set_prop_border_x_from_value (a_this, value, - DIR_LEFT) ; - break ; + status = set_prop_border_x_from_value (a_this, value, + DIR_LEFT); + break; case PROP_ID_MARGIN_TOP: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_TOP) ; - break ; + status = set_prop_margin_x_from_value (a_this, value, + DIR_TOP); + break; case PROP_ID_BORDER: - status = - set_prop_border_from_value (a_this, value) ; - break ; + status = set_prop_border_from_value (a_this, value); + break; case PROP_ID_MARGIN_RIGHT: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_RIGHT) ; - break ; + status = set_prop_margin_x_from_value (a_this, value, + DIR_RIGHT); + break; case PROP_ID_MARGIN_BOTTOM: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_BOTTOM) ; - break ; + status = set_prop_margin_x_from_value (a_this, value, + DIR_BOTTOM); + break; case PROP_ID_MARGIN_LEFT: - status = - set_prop_margin_x_from_value (a_this, value, - DIR_LEFT) ; - break ; + status = set_prop_margin_x_from_value (a_this, value, + DIR_LEFT); + break; case PROP_ID_MARGIN: - status = - set_prop_margin_from_value (a_this, value) ; - break ; + status = set_prop_margin_from_value (a_this, value); + break; case PROP_ID_DISPLAY: - status = - set_prop_display_from_value (a_this, value) ; - break ; + status = set_prop_display_from_value (a_this, value); + break; case PROP_ID_POSITION: - status = set_prop_position_from_value (a_this, value) ; - break ; + status = set_prop_position_from_value (a_this, value); + break; case PROP_ID_TOP: - status = set_prop_x_from_value (a_this, value, - DIR_TOP) ; - break ; + status = set_prop_x_from_value (a_this, value, DIR_TOP); + break; case PROP_ID_RIGHT: - status = set_prop_x_from_value (a_this, value, - DIR_RIGHT) ; - break ; + status = set_prop_x_from_value (a_this, value, DIR_RIGHT); + break; case PROP_ID_BOTTOM: - status = set_prop_x_from_value (a_this, value, - DIR_BOTTOM) ; - break ; + status = set_prop_x_from_value (a_this, value, DIR_BOTTOM); + break; case PROP_ID_LEFT: - status = set_prop_x_from_value (a_this, value, - DIR_LEFT) ; - break ; + status = set_prop_x_from_value (a_this, value, DIR_LEFT); + break; case PROP_ID_FLOAT: - status = set_prop_float (a_this, value) ; - break ; + status = set_prop_float (a_this, value); + break; case PROP_ID_WIDTH: - status = set_prop_width (a_this, value) ; - break ; + status = set_prop_width (a_this, value); + break; case PROP_ID_COLOR: - status = set_prop_color (a_this, value) ; - break ; + status = set_prop_color (a_this, value); + break; case PROP_ID_BACKGROUND_COLOR: - status = set_prop_background_color (a_this, value) ; - break ; - + status = set_prop_background_color (a_this, value); + break; + case PROP_ID_FONT_FAMILY: - status = - set_prop_font_family_from_value (a_this, value) ; - break ; + status = set_prop_font_family_from_value (a_this, value); + break; case PROP_ID_FONT_SIZE: - status = - set_prop_font_size_from_value (a_this, value) ; - break ; + status = set_prop_font_size_from_value (a_this, value); + break; case PROP_ID_FONT_STYLE: - status = - set_prop_font_style_from_value (a_this, value) ; - break ; + status = set_prop_font_style_from_value (a_this, value); + break; case PROP_ID_FONT_WEIGHT: - status = - set_prop_font_weight_from_value (a_this, value) ; - break ; + status = set_prop_font_weight_from_value (a_this, value); + break; default: - return CR_UNKNOWN_TYPE_ERROR ; + return CR_UNKNOWN_TYPE_ERROR; } - return status ; + return status; } /** @@ -2270,15 +1949,14 @@ cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl) *otherwise. */ enum CRStatus -cr_style_ref (CRStyle *a_this) +cr_style_ref (CRStyle * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - a_this->ref_count ++ ; - return CR_OK ; + a_this->ref_count++; + return CR_OK; } - /** *Decreases the reference count of *the current instance of #CRStyle. @@ -2289,21 +1967,19 @@ cr_style_ref (CRStyle *a_this) *otherwise. */ gboolean -cr_style_unref (CRStyle *a_this) +cr_style_unref (CRStyle * a_this) { - g_return_val_if_fail (a_this, - FALSE) ; + g_return_val_if_fail (a_this, FALSE); if (a_this->ref_count) - a_this->ref_count -- ; + a_this->ref_count--; - if (!a_this->ref_count) - { - cr_style_destroy (a_this) ; - return TRUE ; + if (!a_this->ref_count) { + cr_style_destroy (a_this); + return TRUE; } - return FALSE ; + return FALSE; } /** @@ -2314,20 +1990,19 @@ cr_style_unref (CRStyle *a_this) *@return the newly duplicated instance of #CRStyle. */ CRStyle * -cr_style_dup (CRStyle *a_this) +cr_style_dup (CRStyle * a_this) { - CRStyle *result = NULL ; + CRStyle *result = NULL; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - result = cr_style_new () ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; + result = cr_style_new (); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; } - cr_style_copy (result, a_this) ; - return result ; + cr_style_copy (result, a_this); + return result; } /** @@ -2340,12 +2015,12 @@ cr_style_dup (CRStyle *a_this) *@return CR_OK upon succesfull completion, an error code otherwise */ enum CRStatus -cr_style_copy (CRStyle *a_dest, CRStyle *a_src) +cr_style_copy (CRStyle * a_dest, CRStyle * a_src) { - g_return_val_if_fail (a_dest && a_src, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_dest && a_src, CR_BAD_PARAM_ERROR); - memcpy (a_dest, a_src, sizeof (CRStyle)) ; - return CR_OK ; + memcpy (a_dest, a_src, sizeof (CRStyle)); + return CR_OK; } /** @@ -2356,304 +2031,282 @@ cr_style_copy (CRStyle *a_dest, CRStyle *a_src) *@param a_nb_indent the number white chars of indentation. */ enum CRStatus -cr_style_num_prop_val_to_string (CRNumPropVal *a_prop_val, - GString *a_str, - guint a_nb_indent) +cr_style_num_prop_val_to_string (CRNumPropVal * a_prop_val, + GString * a_str, guint a_nb_indent) { - enum CRStatus status = CR_OK ; - guchar * tmp_str = NULL ; - GString *str = NULL ; - - g_return_val_if_fail (a_prop_val && a_str, - CR_BAD_PARAM_ERROR) ; - - str = g_string_new (NULL) ; - cr_utils_dump_n_chars2 (' ', str, a_nb_indent) ; - g_string_append_printf (str, "%s", "NumPropVal {") ; - tmp_str = cr_num_to_string (&a_prop_val->sv) ; - if (!tmp_str) - { - status = CR_ERROR ; - goto cleanup ; - } - g_string_append_printf (str, "sv: %s ", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; - tmp_str = cr_num_to_string (&a_prop_val->cv) ; - if (!tmp_str) - { - status = CR_ERROR ; - goto cleanup ; - } - g_string_append_printf (str, "av: %s ", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; - g_string_append_printf (str, "%s", "}") ; - g_string_append_printf (a_str, "%s", str->str) ; - status = CR_OK ; - cleanup: - - if (tmp_str) - { - g_free (tmp_str) ; - tmp_str = NULL ; - } - if (str) - { - g_string_free (str, TRUE) ; - } - return status ; + enum CRStatus status = CR_OK; + guchar *tmp_str = NULL; + GString *str = NULL; + + g_return_val_if_fail (a_prop_val && a_str, CR_BAD_PARAM_ERROR); + + str = g_string_new (NULL); + cr_utils_dump_n_chars2 (' ', str, a_nb_indent); + g_string_append_printf (str, "%s", "NumPropVal {"); + tmp_str = cr_num_to_string (&a_prop_val->sv); + if (!tmp_str) { + status = CR_ERROR; + goto cleanup; + } + g_string_append_printf (str, "sv: %s ", tmp_str); + g_free (tmp_str); + tmp_str = NULL; + tmp_str = cr_num_to_string (&a_prop_val->cv); + if (!tmp_str) { + status = CR_ERROR; + goto cleanup; + } + g_string_append_printf (str, "av: %s ", tmp_str); + g_free (tmp_str); + tmp_str = NULL; + g_string_append_printf (str, "%s", "}"); + g_string_append_printf (a_str, "%s", str->str); + status = CR_OK; + cleanup: + + if (tmp_str) { + g_free (tmp_str); + tmp_str = NULL; + } + if (str) { + g_string_free (str, TRUE); + } + return status; } - enum CRStatus -cr_style_rgb_prop_val_to_string (CRRgbPropVal *a_prop_val, - GString *a_str, - guint a_nb_indent) +cr_style_rgb_prop_val_to_string (CRRgbPropVal * a_prop_val, + GString * a_str, guint a_nb_indent) { - enum CRStatus status = CR_OK ; - guchar * tmp_str = NULL ; - GString *str = NULL ; - - g_return_val_if_fail (a_prop_val && a_str, CR_BAD_PARAM_ERROR) ; - - str = g_string_new (NULL) ; - - cr_utils_dump_n_chars2 (' ', str, a_nb_indent) ; - g_string_append_printf (str, "RGBPropVal {") ; - tmp_str = cr_rgb_to_string (&a_prop_val->sv) ; - if (!tmp_str) - { - status = CR_ERROR ; - goto cleanup ; - } - g_string_append_printf (str, "sv: %s ", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; - tmp_str = cr_rgb_to_string (&a_prop_val->cv) ; - if (!tmp_str) - { - status = CR_ERROR ; - goto cleanup ; - } - g_string_append_printf (str, "cv: %s ", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; - tmp_str = cr_rgb_to_string (&a_prop_val->av) ; - if (!tmp_str) - { - status = CR_ERROR ; - goto cleanup ; - } - g_string_append_printf (str, "av: %s ", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; - - g_string_append_printf (str, "}") ; - g_string_append_printf (a_str, "%s", str->str) ; - status = CR_OK ; - cleanup: - - if (tmp_str) - { - g_free (tmp_str) ; - tmp_str = NULL ; - } - if (str) - { - g_string_free (str, TRUE) ; - } - return status ; + enum CRStatus status = CR_OK; + guchar *tmp_str = NULL; + GString *str = NULL; + + g_return_val_if_fail (a_prop_val && a_str, CR_BAD_PARAM_ERROR); + + str = g_string_new (NULL); + + cr_utils_dump_n_chars2 (' ', str, a_nb_indent); + g_string_append_printf (str, "RGBPropVal {"); + tmp_str = cr_rgb_to_string (&a_prop_val->sv); + if (!tmp_str) { + status = CR_ERROR; + goto cleanup; + } + g_string_append_printf (str, "sv: %s ", tmp_str); + g_free (tmp_str); + tmp_str = NULL; + tmp_str = cr_rgb_to_string (&a_prop_val->cv); + if (!tmp_str) { + status = CR_ERROR; + goto cleanup; + } + g_string_append_printf (str, "cv: %s ", tmp_str); + g_free (tmp_str); + tmp_str = NULL; + tmp_str = cr_rgb_to_string (&a_prop_val->av); + if (!tmp_str) { + status = CR_ERROR; + goto cleanup; + } + g_string_append_printf (str, "av: %s ", tmp_str); + g_free (tmp_str); + tmp_str = NULL; + + g_string_append_printf (str, "}"); + g_string_append_printf (a_str, "%s", str->str); + status = CR_OK; + cleanup: + + if (tmp_str) { + g_free (tmp_str); + tmp_str = NULL; + } + if (str) { + g_string_free (str, TRUE); + } + return status; } enum CRStatus cr_style_border_style_to_string (enum CRBorderStyle a_prop, - GString *a_str, - guint a_nb_indent) + GString * a_str, guint a_nb_indent) { - gchar *str = NULL ; + gchar *str = NULL; - g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR); - switch (a_prop) - { + switch (a_prop) { case BORDER_STYLE_NONE: - str = (gchar*) "border-style-none" ; - break ; + str = (gchar *) "border-style-none"; + break; case BORDER_STYLE_HIDDEN: - str = (gchar*) "border-style-hidden" ; - break ; + str = (gchar *) "border-style-hidden"; + break; case BORDER_STYLE_DOTTED: - str = (gchar*) "border-style-dotted" ; - break ; + str = (gchar *) "border-style-dotted"; + break; case BORDER_STYLE_DASHED: - str = (gchar*) "border-style-dashed" ; - break ; + str = (gchar *) "border-style-dashed"; + break; case BORDER_STYLE_SOLID: - str = (gchar*) "border-style-solid" ; - break ; + str = (gchar *) "border-style-solid"; + break; case BORDER_STYLE_DOUBLE: - str = (gchar*) "border-style-double" ; - break ; + str = (gchar *) "border-style-double"; + break; case BORDER_STYLE_GROOVE: - str = (gchar*) "border-style-groove" ; - break ; + str = (gchar *) "border-style-groove"; + break; case BORDER_STYLE_RIDGE: - str = (gchar*) "border-style-ridge" ; - break ; + str = (gchar *) "border-style-ridge"; + break; case BORDER_STYLE_INSET: - str = (gchar*) "border-style-inset" ; - break ; + str = (gchar *) "border-style-inset"; + break; case BORDER_STYLE_OUTSET: - str = (gchar*) "border-style-outset" ; - break ; + str = (gchar *) "border-style-outset"; + break; default: - str = (gchar*) "unknown border style" ; - break ; - } - cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent) ; - g_string_append_printf (a_str, "%s", str) ; - return CR_OK ; + str = (gchar *) "unknown border style"; + break; + } + cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent); + g_string_append_printf (a_str, "%s", str); + return CR_OK; } - enum CRStatus cr_style_display_type_to_string (enum CRDisplayType a_code, - GString *a_str, - guint a_nb_indent) + GString * a_str, guint a_nb_indent) { - gchar *str = NULL ; + gchar *str = NULL; - g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR); - switch (a_code) - { + switch (a_code) { case DISPLAY_NONE: - str = (gchar*) "display-none" ; - break ; + str = (gchar *) "display-none"; + break; case DISPLAY_INLINE: - str = (gchar*) "display-inline" ; - break ; + str = (gchar *) "display-inline"; + break; case DISPLAY_BLOCK: - str = (gchar*) "display-block" ; - break ; + str = (gchar *) "display-block"; + break; case DISPLAY_LIST_ITEM: - str = (gchar*) "display-list-item" ; - break ; + str = (gchar *) "display-list-item"; + break; case DISPLAY_RUN_IN: - str = (gchar*) "display-run-in" ; - break ; + str = (gchar *) "display-run-in"; + break; case DISPLAY_COMPACT: - str = (gchar*) "display-compact" ; - break ; + str = (gchar *) "display-compact"; + break; case DISPLAY_MARKER: - str = (gchar*) "display-marker" ; - break ; + str = (gchar *) "display-marker"; + break; case DISPLAY_TABLE: - str = (gchar*) "display-table" ; - break ; + str = (gchar *) "display-table"; + break; case DISPLAY_INLINE_TABLE: - str = (gchar*) "display-inline-table" ; - break ; + str = (gchar *) "display-inline-table"; + break; case DISPLAY_TABLE_ROW_GROUP: - str = (gchar*) "display-table-row-group" ; - break ; + str = (gchar *) "display-table-row-group"; + break; case DISPLAY_TABLE_HEADER_GROUP: - str = (gchar*) "display-table-header-group" ; - break ; + str = (gchar *) "display-table-header-group"; + break; case DISPLAY_TABLE_FOOTER_GROUP: - str = (gchar*) "display-table-footer-group" ; - break ; + str = (gchar *) "display-table-footer-group"; + break; case DISPLAY_TABLE_ROW: - str = (gchar*) "display-table-row" ; - break ; + str = (gchar *) "display-table-row"; + break; case DISPLAY_TABLE_COLUMN_GROUP: - str = (gchar*) "display-table-column-group" ; - break ; + str = (gchar *) "display-table-column-group"; + break; case DISPLAY_TABLE_COLUMN: - str = (gchar*) "display-table-column" ; - break ; + str = (gchar *) "display-table-column"; + break; case DISPLAY_TABLE_CELL: - str = (gchar*) "display-table-cell" ; - break ; + str = (gchar *) "display-table-cell"; + break; case DISPLAY_TABLE_CAPTION: - str = (gchar*) "display-table-caption" ; - break ; + str = (gchar *) "display-table-caption"; + break; case DISPLAY_INHERIT: - str = (gchar*) "display-inherit" ; - break ; + str = (gchar *) "display-inherit"; + break; default: - str = (gchar*) "unknown display property" ; - break ; + str = (gchar *) "unknown display property"; + break; } - cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent) ; - g_string_append_printf (a_str, str) ; - return CR_OK ; - + cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent); + g_string_append_printf (a_str, str); + return CR_OK; + } enum CRStatus cr_style_position_type_to_string (enum CRPositionType a_code, - GString *a_str, - guint a_nb_indent) + GString * a_str, guint a_nb_indent) { - gchar *str = NULL ; + gchar *str = NULL; - g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR); - switch (a_code) - { + switch (a_code) { case POSITION_STATIC: - str = (gchar*) "position-static" ; - break ; + str = (gchar *) "position-static"; + break; case POSITION_RELATIVE: - str = (gchar*) "position-relative" ; - break ; + str = (gchar *) "position-relative"; + break; case POSITION_ABSOLUTE: - str = (gchar*) "position-absolute" ; - break ; + str = (gchar *) "position-absolute"; + break; case POSITION_FIXED: - str = (gchar*) "position-fixed" ; - break ; + str = (gchar *) "position-fixed"; + break; case POSITION_INHERIT: - str = (gchar*) "position-inherit" ; - break ; + str = (gchar *) "position-inherit"; + break; default: - str = (gchar*)"unknown static property" ; + str = (gchar *) "unknown static property"; } - cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent) ; - g_string_append_printf (a_str, "%s", str) ; - return CR_OK ; + cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent); + g_string_append_printf (a_str, "%s", str); + return CR_OK; } enum CRStatus cr_style_float_type_to_string (enum CRFloatType a_code, - GString *a_str, - guint a_nb_indent) + GString * a_str, guint a_nb_indent) { - gchar *str = NULL ; + gchar *str = NULL; - g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR); - switch (a_code) - { + switch (a_code) { case FLOAT_NONE: - str = (gchar*)"float-none" ; - break ; + str = (gchar *) "float-none"; + break; case FLOAT_LEFT: - str = (gchar*)"float-left" ; - break ; + str = (gchar *) "float-left"; + break; case FLOAT_RIGHT: - str = (gchar*)"float-right" ; - break ; + str = (gchar *) "float-right"; + break; case FLOAT_INHERIT: - str = (gchar*)"float-inherit" ; - break ; + str = (gchar *) "float-inherit"; + break; default: - str = (gchar*)"unknown float property value" ; - break ; + str = (gchar *) "unknown float property value"; + break; } - return CR_OK ; + return CR_OK; } /** @@ -2667,202 +2320,165 @@ cr_style_float_type_to_string (enum CRFloatType a_code, *@return CR_OK upon successful completion, an error code otherwise. */ enum CRStatus -cr_style_to_string (CRStyle *a_this, - GString **a_str, - guint a_nb_indent) +cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent) { - const gint INTERNAL_INDENT = 2 ; - gint indent = a_nb_indent + INTERNAL_INDENT ; - gchar *tmp_str = NULL ; - GString *str = NULL ; - gint i = 0 ; - - g_return_val_if_fail (a_this && a_str, CR_BAD_PARAM_ERROR) ; - - if (!*a_str) - { - str = g_string_new (NULL) ; - } - else - { - str = *a_str ; - } - cr_utils_dump_n_chars2 (' ', str, a_nb_indent) ; - g_string_append_printf (str, "style {\n") ; - - /*loop over the num_props and to_string() them*/ - for (i = NUM_PROP_TOP ; i < NB_NUM_PROPS ; i++) { + const gint INTERNAL_INDENT = 2; + gint indent = a_nb_indent + INTERNAL_INDENT; + gchar *tmp_str = NULL; + GString *str = NULL; + gint i = 0; + + g_return_val_if_fail (a_this && a_str, CR_BAD_PARAM_ERROR); + + if (!*a_str) { + str = g_string_new (NULL); + } else { + str = *a_str; + } + cr_utils_dump_n_chars2 (' ', str, a_nb_indent); + g_string_append_printf (str, "style {\n"); + + /*loop over the num_props and to_string() them */ + for (i = NUM_PROP_TOP; i < NB_NUM_PROPS; i++) { /* *to_string() the name of the num_prop *(using num_prop_code_to_string) *before outputing it value */ - cr_utils_dump_n_chars2 (' ', str, indent) ; - tmp_str = (gchar*)num_prop_code_to_string (i) ; - if (tmp_str) - { - g_string_append_printf (str, "%s: ", tmp_str) ; - } - else - { - g_string_append_printf (str, "%s", "NULL") ; + cr_utils_dump_n_chars2 (' ', str, indent); + tmp_str = (gchar *) num_prop_code_to_string (i); + if (tmp_str) { + g_string_append_printf (str, "%s: ", tmp_str); + } else { + g_string_append_printf (str, "%s", "NULL"); } - tmp_str = NULL ; + tmp_str = NULL; cr_style_num_prop_val_to_string (&a_this->num_props[i], str, - a_nb_indent + INTERNAL_INDENT) ; - g_string_append_printf (str, "\n") ; - } - /*loop over the rgb_props and to_string() them all*/ - for (i=RGB_PROP_BORDER_TOP_COLOR ; i < NB_RGB_PROPS; i++) - { - tmp_str = (gchar*)rgb_prop_code_to_string (i) ; - cr_utils_dump_n_chars2 (' ', str, indent) ; - if (tmp_str) - { - g_string_append_printf (str, "%s: ", tmp_str) ; - } - else - { - g_string_append_printf (str, "%s", "NULL: ") ; + a_nb_indent + + INTERNAL_INDENT); + g_string_append_printf (str, "\n"); + } + /*loop over the rgb_props and to_string() them all */ + for (i = RGB_PROP_BORDER_TOP_COLOR; i < NB_RGB_PROPS; i++) { + tmp_str = (gchar *) rgb_prop_code_to_string (i); + cr_utils_dump_n_chars2 (' ', str, indent); + if (tmp_str) { + g_string_append_printf (str, "%s: ", tmp_str); + } else { + g_string_append_printf (str, "%s", "NULL: "); } - tmp_str = NULL ; + tmp_str = NULL; cr_style_rgb_prop_val_to_string (&a_this->rgb_props[i], str, - a_nb_indent + INTERNAL_INDENT) ; - g_string_append_printf (str, "\n") ; - } - /*loop over the border_style_props and to_string() them*/ - for (i=BORDER_STYLE_PROP_TOP ; i < NB_BORDER_STYLE_PROPS ; i++) - { - tmp_str = (gchar*)border_style_prop_code_to_string (i) ; - cr_utils_dump_n_chars2 (' ', str, indent) ; - if (tmp_str) - { - g_string_append_printf (str, "%s: ", tmp_str) ; - } - else - { - g_string_append_printf (str, "NULL: ") ; + a_nb_indent + + INTERNAL_INDENT); + g_string_append_printf (str, "\n"); + } + /*loop over the border_style_props and to_string() them */ + for (i = BORDER_STYLE_PROP_TOP; i < NB_BORDER_STYLE_PROPS; i++) { + tmp_str = (gchar *) border_style_prop_code_to_string (i); + cr_utils_dump_n_chars2 (' ', str, indent); + if (tmp_str) { + g_string_append_printf (str, "%s: ", tmp_str); + } else { + g_string_append_printf (str, "NULL: "); } - tmp_str = NULL ; - cr_style_border_style_to_string (a_this->border_style_props[i], - str, 0) ; - g_string_append_printf (str, "\n") ; - } - cr_utils_dump_n_chars2 (' ', str, indent) ; - g_string_append_printf (str, "display: ") ; - cr_style_display_type_to_string (a_this->display, str, 0) ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - g_string_append_printf (str, "position: ") ; - cr_style_position_type_to_string (a_this->position, str, - 0) ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - g_string_append_printf (str, "float-type: ") ; - cr_style_float_type_to_string (a_this->float_type, str, 0) ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - g_string_append_printf (str, "font-family: ") ; - tmp_str = cr_font_family_to_string (a_this->font_family, - TRUE) ; - if (tmp_str) - { - g_string_append_printf (str, "%s", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; - } - else - { - g_string_append_printf (str, "NULL") ; - } - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - tmp_str = cr_font_size_to_string (a_this->font_size) ; - if (tmp_str) - { - g_string_append_printf (str, "font-size: %s", tmp_str) ; - } - else - { - g_string_append_printf (str, "font-size: NULL") ; - } - tmp_str = NULL ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - tmp_str = cr_font_size_adjust_to_string (a_this->font_size_adjust) ; - if (tmp_str) - { - g_string_append_printf (str, "font-size-adjust: %s", tmp_str) ; - } - else - { - g_string_append_printf (str, "font-size-adjust: NULL") ; - } - tmp_str = NULL ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - tmp_str = (gchar*)cr_font_style_to_string (a_this->font_style) ; - if (tmp_str) - { - g_string_append_printf (str, "font-size: %s", tmp_str) ; - } - else - { - g_string_append_printf (str, "font-size: NULL") ; - } - tmp_str = NULL ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - tmp_str = (gchar*)cr_font_variant_to_string (a_this->font_variant) ; - if (tmp_str) - { - g_string_append_printf (str, "font-variant: %s", tmp_str) ; - } - else - { - g_string_append_printf (str, "font-variant: NULL") ; - } - tmp_str = NULL ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, indent) ; - tmp_str = (gchar*)cr_font_weight_to_string (a_this->font_weight) ; - if (tmp_str) - { - g_string_append_printf (str, "font-weight: %s", tmp_str) ; - } - else - { - g_string_append_printf (str, "font-weight: NULL") ; - } - tmp_str = NULL ; - g_string_append_printf (str, "\n") ; - - - cr_utils_dump_n_chars2 (' ', str, indent) ; - tmp_str = (gchar*)cr_font_stretch_to_string (a_this->font_stretch) ; - if (tmp_str) - { - g_string_append_printf (str, "font-stretch: %s", tmp_str) ; - } - else - { - g_string_append_printf (str, "font-stretch: NULL") ; - } - tmp_str = NULL ; - g_string_append_printf (str, "\n") ; - - cr_utils_dump_n_chars2 (' ', str, a_nb_indent) ; - g_string_append_printf (str, "}") ; - - return CR_OK ; + tmp_str = NULL; + cr_style_border_style_to_string (a_this-> + border_style_props[i], str, + 0); + g_string_append_printf (str, "\n"); + } + cr_utils_dump_n_chars2 (' ', str, indent); + g_string_append_printf (str, "display: "); + cr_style_display_type_to_string (a_this->display, str, 0); + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + g_string_append_printf (str, "position: "); + cr_style_position_type_to_string (a_this->position, str, 0); + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + g_string_append_printf (str, "float-type: "); + cr_style_float_type_to_string (a_this->float_type, str, 0); + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + g_string_append_printf (str, "font-family: "); + tmp_str = cr_font_family_to_string (a_this->font_family, TRUE); + if (tmp_str) { + g_string_append_printf (str, "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; + } else { + g_string_append_printf (str, "NULL"); + } + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + tmp_str = cr_font_size_to_string (a_this->font_size); + if (tmp_str) { + g_string_append_printf (str, "font-size: %s", tmp_str); + } else { + g_string_append_printf (str, "font-size: NULL"); + } + tmp_str = NULL; + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + tmp_str = cr_font_size_adjust_to_string (a_this->font_size_adjust); + if (tmp_str) { + g_string_append_printf (str, "font-size-adjust: %s", tmp_str); + } else { + g_string_append_printf (str, "font-size-adjust: NULL"); + } + tmp_str = NULL; + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + tmp_str = (gchar *) cr_font_style_to_string (a_this->font_style); + if (tmp_str) { + g_string_append_printf (str, "font-size: %s", tmp_str); + } else { + g_string_append_printf (str, "font-size: NULL"); + } + tmp_str = NULL; + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + tmp_str = (gchar *) cr_font_variant_to_string (a_this->font_variant); + if (tmp_str) { + g_string_append_printf (str, "font-variant: %s", tmp_str); + } else { + g_string_append_printf (str, "font-variant: NULL"); + } + tmp_str = NULL; + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + tmp_str = (gchar *) cr_font_weight_to_string (a_this->font_weight); + if (tmp_str) { + g_string_append_printf (str, "font-weight: %s", tmp_str); + } else { + g_string_append_printf (str, "font-weight: NULL"); + } + tmp_str = NULL; + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, indent); + tmp_str = (gchar *) cr_font_stretch_to_string (a_this->font_stretch); + if (tmp_str) { + g_string_append_printf (str, "font-stretch: %s", tmp_str); + } else { + g_string_append_printf (str, "font-stretch: NULL"); + } + tmp_str = NULL; + g_string_append_printf (str, "\n"); + + cr_utils_dump_n_chars2 (' ', str, a_nb_indent); + g_string_append_printf (str, "}"); + + return CR_OK; } /** @@ -2870,9 +2486,9 @@ cr_style_to_string (CRStyle *a_this, *@param a_this the instance to destroy. */ void -cr_style_destroy (CRStyle *a_this) +cr_style_destroy (CRStyle * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - g_free (a_this) ; + g_free (a_this); } diff --git a/src/cr-stylesheet.c b/src/cr-stylesheet.c index a7e77f8..3f3665a 100644 --- a/src/cr-stylesheet.c +++ b/src/cr-stylesheet.c @@ -38,44 +38,40 @@ *@return the newly built css2 stylesheet, or NULL in case of error. */ CRStyleSheet * -cr_stylesheet_new (CRStatement *a_stmts) +cr_stylesheet_new (CRStatement * a_stmts) { - CRStyleSheet *result ; + CRStyleSheet *result; - result = g_try_malloc (sizeof (CRStyleSheet)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + result = g_try_malloc (sizeof (CRStyleSheet)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - memset (result, 0, sizeof (CRStyleSheet)) ; + memset (result, 0, sizeof (CRStyleSheet)); - if (a_stmts) - result->statements = a_stmts ; + if (a_stmts) + result->statements = a_stmts; - return result ; + return result; } - /** *Dumps the current css2 stylesheet to a file. *@param a_this the current instance of #CRStyleSheet. *@param a_fp the destination file */ void -cr_stylesheet_dump (CRStyleSheet *a_this, FILE *a_fp) +cr_stylesheet_dump (CRStyleSheet * a_this, FILE * a_fp) { - CRStatement * cur_stmt = NULL ; + CRStatement *cur_stmt = NULL; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - for (cur_stmt = a_this->statements ; - cur_stmt ; - cur_stmt = cur_stmt->next) - { - cr_statement_dump (cur_stmt, a_fp, 0) ; - } + for (cur_stmt = a_this->statements; + cur_stmt; cur_stmt = cur_stmt->next) { + cr_statement_dump (cur_stmt, a_fp, 0); + } } /** @@ -84,11 +80,11 @@ cr_stylesheet_dump (CRStyleSheet *a_this, FILE *a_fp) *@return number of rules in the stylesheet. */ gint -cr_stylesheet_nr_rules (CRStyleSheet *a_this) +cr_stylesheet_nr_rules (CRStyleSheet * a_this) { - g_return_val_if_fail (a_this, -1) ; + g_return_val_if_fail (a_this, -1); - return cr_statement_nr_rules (a_this->statements); + return cr_statement_nr_rules (a_this->statements); } /** @@ -99,52 +95,49 @@ cr_stylesheet_nr_rules (CRStyleSheet *a_this) *it will return NULL. */ CRStatement * -cr_stylesheet_statement_get_from_list (CRStyleSheet *a_this, int itemnr) +cr_stylesheet_statement_get_from_list (CRStyleSheet * a_this, int itemnr) { - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - return cr_statement_get_from_list (a_this->statements, itemnr); + return cr_statement_get_from_list (a_this->statements, itemnr); } void -cr_stylesheet_ref (CRStyleSheet *a_this) +cr_stylesheet_ref (CRStyleSheet * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - a_this->ref_count ++ ; + a_this->ref_count++; } gboolean -cr_stylesheet_unref (CRStyleSheet *a_this) +cr_stylesheet_unref (CRStyleSheet * a_this) { - g_return_val_if_fail (a_this, FALSE) ; - - if (a_this->ref_count) - a_this->ref_count -- ; - - if (!a_this->ref_count) - { - cr_stylesheet_destroy (a_this) ; - return TRUE ; - } - - return FALSE ; -} + g_return_val_if_fail (a_this, FALSE); + + if (a_this->ref_count) + a_this->ref_count--; + if (!a_this->ref_count) { + cr_stylesheet_destroy (a_this); + return TRUE; + } + + return FALSE; +} /** *Destructor of the #CRStyleSheet class. *@param a_this the current instance of the #CRStyleSheet class. */ void -cr_stylesheet_destroy (CRStyleSheet *a_this) +cr_stylesheet_destroy (CRStyleSheet * a_this) { - g_return_if_fail (a_this) ; - - if (a_this->statements) - { - cr_statement_destroy (a_this->statements) ; - a_this->statements = NULL ; - } - g_free (a_this) ; + g_return_if_fail (a_this); + + if (a_this->statements) { + cr_statement_destroy (a_this->statements); + a_this->statements = NULL; + } + g_free (a_this); } diff --git a/src/cr-term.c b/src/cr-term.c index 7bfab93..8760f74 100644 --- a/src/cr-term.c +++ b/src/cr-term.c @@ -34,57 +34,50 @@ *Definition of the #CRTem class. */ - static void -cr_term_clear (CRTerm *a_this) +cr_term_clear (CRTerm * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - switch (a_this->type) - { + switch (a_this->type) { case TERM_NUMBER: - if (a_this->content.num) - { - cr_num_destroy (a_this->content.num) ; - a_this->content.num = NULL ; + if (a_this->content.num) { + cr_num_destroy (a_this->content.num); + a_this->content.num = NULL; } - break ; + break; case TERM_FUNCTION: - if (a_this->ext_content.func_param) - { - cr_term_destroy (a_this->ext_content.func_param) ; - a_this->ext_content.func_param = NULL ; + if (a_this->ext_content.func_param) { + cr_term_destroy (a_this->ext_content.func_param); + a_this->ext_content.func_param = NULL; } case TERM_STRING: case TERM_IDENT: case TERM_URI: case TERM_HASH: - if (a_this->content.str) - { - g_string_free (a_this->content.str, TRUE) ; - a_this->content.str = NULL ; + if (a_this->content.str) { + g_string_free (a_this->content.str, TRUE); + a_this->content.str = NULL; } - break ; + break; - case TERM_RGB: - if (a_this->content.rgb) - { - cr_rgb_destroy (a_this->content.rgb) ; - a_this->content.rgb = NULL ; + case TERM_RGB: + if (a_this->content.rgb) { + cr_rgb_destroy (a_this->content.rgb); + a_this->content.rgb = NULL; } - break ; + break; case TERM_UNICODERANGE: case TERM_NO_TYPE: - default: - break ; + default: + break; } - a_this->type = TERM_NO_TYPE ; + a_this->type = TERM_NO_TYPE; } - /** *Instanciate a #CRTerm. *@return the newly build instance @@ -93,16 +86,15 @@ cr_term_clear (CRTerm *a_this) CRTerm * cr_term_new (void) { - CRTerm *result = NULL ; + CRTerm *result = NULL; - result = g_try_malloc (sizeof (CRTerm)) ; - if (!result) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; + result = g_try_malloc (sizeof (CRTerm)); + if (!result) { + cr_utils_trace_info ("Out of memory"); + return NULL; } - memset (result, 0, sizeof (CRTerm)) ; - return result ; + memset (result, 0, sizeof (CRTerm)); + return result; } /** @@ -113,135 +105,124 @@ cr_term_new (void) *NULL if parsing failed. */ CRTerm * -cr_term_parse_expression_from_buf (const guchar *a_buf, +cr_term_parse_expression_from_buf (const guchar * a_buf, enum CREncoding a_encoding) { - CRParser *parser = NULL ; - CRTerm *result = NULL ; - enum CRStatus status = CR_OK ; + CRParser *parser = NULL; + CRTerm *result = NULL; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_buf, NULL) ; + g_return_val_if_fail (a_buf, NULL); parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), - a_encoding, FALSE) ; - g_return_val_if_fail (parser, NULL) ; - - status = cr_parser_try_to_skip_spaces_and_comments (parser) ; - if (status != CR_OK) - { - goto cleanup ; + a_encoding, FALSE); + g_return_val_if_fail (parser, NULL); + + status = cr_parser_try_to_skip_spaces_and_comments (parser); + if (status != CR_OK) { + goto cleanup; } - status = cr_parser_parse_expr (parser, &result) ; - if (status != CR_OK) - { - if (result) - { - cr_term_destroy (result) ; - result = NULL ; + status = cr_parser_parse_expr (parser, &result); + if (status != CR_OK) { + if (result) { + cr_term_destroy (result); + result = NULL; } } - cleanup: - if (parser) - { - cr_parser_destroy (parser) ; - parser = NULL ; + cleanup: + if (parser) { + cr_parser_destroy (parser); + parser = NULL; } - return result ; + return result; } enum CRStatus -cr_term_set_number (CRTerm *a_this, CRNum *a_num) +cr_term_set_number (CRTerm * a_this, CRNum * a_num) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_term_clear (a_this) ; - - a_this->type = TERM_NUMBER ; - a_this->content.num = a_num ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_term_clear (a_this); + + a_this->type = TERM_NUMBER; + a_this->content.num = a_num; + return CR_OK; } enum CRStatus -cr_term_set_function (CRTerm *a_this, GString *a_func_name, - CRTerm *a_func_param) +cr_term_set_function (CRTerm * a_this, GString * a_func_name, + CRTerm * a_func_param) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_term_clear (a_this) ; - - a_this->type = TERM_FUNCTION ; - a_this->content.str = a_func_name ; - a_this->ext_content.func_param = a_func_param ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_term_clear (a_this); + + a_this->type = TERM_FUNCTION; + a_this->content.str = a_func_name; + a_this->ext_content.func_param = a_func_param; + return CR_OK; } enum CRStatus -cr_term_set_string (CRTerm *a_this, GString *a_str) +cr_term_set_string (CRTerm * a_this, GString * a_str) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_term_clear (a_this) ; - - a_this->type = TERM_STRING ; - a_this->content.str = a_str ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_term_clear (a_this); + + a_this->type = TERM_STRING; + a_this->content.str = a_str; + return CR_OK; } enum CRStatus -cr_term_set_ident (CRTerm *a_this, GString *a_str) +cr_term_set_ident (CRTerm * a_this, GString * a_str) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_term_clear (a_this) ; - - a_this->type = TERM_IDENT ; - a_this->content.str = a_str ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_term_clear (a_this); + + a_this->type = TERM_IDENT; + a_this->content.str = a_str; + return CR_OK; } enum CRStatus -cr_term_set_uri (CRTerm *a_this, GString *a_str) +cr_term_set_uri (CRTerm * a_this, GString * a_str) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_term_clear (a_this) ; - - a_this->type = TERM_URI ; - a_this->content.str = a_str ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_term_clear (a_this); + + a_this->type = TERM_URI; + a_this->content.str = a_str; + return CR_OK; } - + enum CRStatus -cr_term_set_rgb (CRTerm *a_this, CRRgb *a_rgb) +cr_term_set_rgb (CRTerm * a_this, CRRgb * a_rgb) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_term_clear (a_this) ; - - a_this->type = TERM_RGB ; - a_this->content.rgb = a_rgb ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_term_clear (a_this); + + a_this->type = TERM_RGB; + a_this->content.rgb = a_rgb; + return CR_OK; } - + enum CRStatus -cr_term_set_hash (CRTerm *a_this, GString *a_str) +cr_term_set_hash (CRTerm * a_this, GString * a_str) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_term_clear (a_this) ; - - a_this->type = TERM_HASH ; - a_this->content.str = a_str ; - return CR_OK ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_term_clear (a_this); + + a_this->type = TERM_HASH; + a_this->content.str = a_str; + return CR_OK; } /** @@ -253,24 +234,22 @@ cr_term_set_hash (CRTerm *a_this, GString *a_str) *@return the list of terms with the a_new_term appended to it. */ CRTerm * -cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) +cr_term_append_term (CRTerm * a_this, CRTerm * a_new_term) { - CRTerm *cur = NULL ; + CRTerm *cur = NULL; + + g_return_val_if_fail (a_new_term, NULL); - g_return_val_if_fail (a_new_term, - NULL) ; - if (a_this == NULL) - return a_new_term ; + return a_new_term; - for (cur = a_this ;cur->next ; cur = cur->next) ; - - cur->next = a_new_term ; - a_new_term->prev = cur ; + for (cur = a_this; cur->next; cur = cur->next) ; - return a_this ; -} + cur->next = a_new_term; + a_new_term->prev = cur; + return a_this; +} /** *Prepends a term to the list of terms represented by a_this. @@ -281,17 +260,15 @@ cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) *@return the head of the new list. */ CRTerm * -cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) +cr_term_prepend_term (CRTerm * a_this, CRTerm * a_new_term) { - g_return_val_if_fail (a_this && a_new_term, - NULL) ; - - a_new_term->next = a_this ; - a_this->prev = a_new_term ; - - return a_new_term ; -} + g_return_val_if_fail (a_this && a_new_term, NULL); + a_new_term->next = a_this; + a_this->prev = a_new_term; + + return a_new_term; +} /** *Serializes the expression represented by @@ -301,230 +278,202 @@ cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) *form of #CRTerm. MUST BE FREED BY THE CALLER using g_free(). */ guchar * -cr_term_to_string (CRTerm *a_this) +cr_term_to_string (CRTerm * a_this) { - GString *str_buf = NULL ; - CRTerm *cur = NULL ; - guchar *result = NULL, *content = NULL ; + GString *str_buf = NULL; + CRTerm *cur = NULL; + guchar *result = NULL, + *content = NULL; - g_return_val_if_fail (a_this, NULL) ; + g_return_val_if_fail (a_this, NULL); - str_buf = g_string_new (NULL) ; - g_return_val_if_fail (str_buf, NULL) ; + str_buf = g_string_new (NULL); + g_return_val_if_fail (str_buf, NULL); - for (cur = a_this ; cur ; cur = cur->next) - { + for (cur = a_this; cur; cur = cur->next) { if ((cur->content.str == NULL) && (cur->content.num == NULL) && (cur->content.str == NULL) && (cur->content.rgb == NULL)) - continue ; - - switch (cur->the_operator) - { + continue; + + switch (cur->the_operator) { case DIVIDE: - g_string_append_printf (str_buf, " / ") ; - break ; + g_string_append_printf (str_buf, " / "); + break; case COMMA: - g_string_append_printf (str_buf, ", ") ; - break ; + g_string_append_printf (str_buf, ", "); + break; case NO_OP: - if (cur->prev) - { - g_string_append_printf (str_buf, " ") ; + if (cur->prev) { + g_string_append_printf (str_buf, " "); } - break ; + break; default: - - break ; + + break; } - switch (cur->unary_op) - { + switch (cur->unary_op) { case PLUS_UOP: - g_string_append_printf (str_buf, "+") ; - break ; + g_string_append_printf (str_buf, "+"); + break; case MINUS_UOP: - g_string_append_printf (str_buf, "-") ; - break ; + g_string_append_printf (str_buf, "-"); + break; - default : - break ; + default: + break; } - switch (cur->type) - { + switch (cur->type) { case TERM_NUMBER: - if (cur->content.num) - { - content = - cr_num_to_string - (cur->content.num) ; + if (cur->content.num) { + content = cr_num_to_string (cur->content.num); } - if (content) - { - g_string_append(str_buf, content) ; - g_free (content) ; - content = NULL ; + if (content) { + g_string_append (str_buf, content); + g_free (content); + content = NULL; } - break ; + break; case TERM_FUNCTION: - if (cur->content.str) - { - content = g_strndup + if (cur->content.str) { + content = g_strndup (cur->content.str->str, - cur->content.str->len) ; - } + cur->content.str->len); + } - if (content) - { - g_string_append_printf (str_buf, "%s(", - content) ; + if (content) { + g_string_append_printf (str_buf, "%s(", + content); - if (a_this->ext_content.func_param) - { - guchar *tmp_str = NULL ; + if (a_this->ext_content.func_param) { + guchar *tmp_str = NULL; - tmp_str = cr_term_to_string + tmp_str = cr_term_to_string (a_this-> ext_content.func_param); - if (tmp_str) - { - g_string_append_printf - (str_buf, - "%s", - tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + if (tmp_str) { + g_string_append_printf + (str_buf, + "%s", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } - g_string_append_printf (str_buf, - ")") ; - g_free (content) ; - content = NULL ; + g_string_append_printf (str_buf, ")"); + g_free (content); + content = NULL; } } - break ; + break; case TERM_STRING: - if (cur->content.str) - { - content = g_strndup + if (cur->content.str) { + content = g_strndup (cur->content.str->str, - cur->content.str->len) ; + cur->content.str->len); } - if (content) - { - g_string_append_printf (str_buf, - "\"%s\"", - content) ; - g_free (content) ; - content = NULL ; - } - break ; + if (content) { + g_string_append_printf (str_buf, + "\"%s\"", content); + g_free (content); + content = NULL; + } + break; case TERM_IDENT: - if (cur->content.str) - { - content = g_strndup - (cur->content.str->str, - cur->content.str->len) ; + if (cur->content.str) { + content = g_strndup + (cur->content.str->str, + cur->content.str->len); + } + + if (content) { + g_string_append (str_buf, content); + g_free (content); + content = NULL; } - - if (content) - { - g_string_append (str_buf,content) ; - g_free (content) ; - content = NULL ; - } - break ; + break; case TERM_URI: - if (cur->content.str) - { - content = g_strndup - (cur->content.str->str, - cur->content.str->len) ; + if (cur->content.str) { + content = g_strndup + (cur->content.str->str, + cur->content.str->len); } - if (content) - { - g_string_append_printf - (str_buf, "url(%s)",content) ; - g_free (content) ; - content = NULL ; - } - break ; + if (content) { + g_string_append_printf + (str_buf, "url(%s)", content); + g_free (content); + content = NULL; + } + break; case TERM_RGB: - if (cur->content.rgb) - { - guchar *tmp_str = NULL ; - - g_string_append_printf (str_buf, "rgb("); - tmp_str = cr_rgb_to_string - (cur->content.rgb) ; - - if (tmp_str) - { - g_string_append (str_buf, - tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + if (cur->content.rgb) { + guchar *tmp_str = NULL; + + g_string_append_printf (str_buf, "rgb("); + tmp_str = cr_rgb_to_string (cur->content.rgb); + + if (tmp_str) { + g_string_append (str_buf, tmp_str); + g_free (tmp_str); + tmp_str = NULL; } - g_string_append_printf (str_buf, ")") ; + g_string_append_printf (str_buf, ")"); } - break ; + break; case TERM_UNICODERANGE: - g_string_append_printf - (str_buf, - "?found unicoderange: dump not supported yet?") ; - break ; + g_string_append_printf + (str_buf, + "?found unicoderange: dump not supported yet?"); + break; case TERM_HASH: - if (cur->content.str) - { - content = g_strndup + if (cur->content.str) { + content = g_strndup (cur->content.str->str, - cur->content.str->len) ; + cur->content.str->len); } - if (content) - { - g_string_append_printf (str_buf, - "#%s", content) ; - g_free (content) ; - content = NULL ; + if (content) { + g_string_append_printf (str_buf, + "#%s", content); + g_free (content); + content = NULL; } - break ; + break; default: - g_string_append_printf (str_buf, - "%s", + g_string_append_printf (str_buf, + "%s", "Unrecognized Term type"); - break ; + break; } } - if (str_buf) - { - result = str_buf->str ; - g_string_free (str_buf, FALSE) ; - str_buf = NULL ; + if (str_buf) { + result = str_buf->str; + g_string_free (str_buf, FALSE); + str_buf = NULL; } - return result ; + return result; } /** @@ -536,36 +485,33 @@ cr_term_to_string (CRTerm *a_this) *@param a_fp the destination file pointer. */ void -cr_term_dump (CRTerm *a_this, FILE *a_fp) +cr_term_dump (CRTerm * a_this, FILE * a_fp) { - guchar *content=NULL ; + guchar *content = NULL; - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - content = cr_term_to_string (a_this) ; + content = cr_term_to_string (a_this); - if (content) - { - fprintf (a_fp, "%s", content) ; - g_free (content) ; + if (content) { + fprintf (a_fp, "%s", content); + g_free (content); } } - /** *Increments the reference counter of the current instance *of #CRTerm.* *@param a_this the current instance of #CRTerm. */ void -cr_term_ref (CRTerm *a_this) +cr_term_ref (CRTerm * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - a_this->ref_count ++ ; + a_this->ref_count++; } - /** *Decrements the ref count of the current instance of *#CRTerm. If the ref count reaches zero, the instance is @@ -574,22 +520,20 @@ cr_term_ref (CRTerm *a_this) *@return TRUE if the current instance has been destroyed, FALSE otherwise. */ gboolean -cr_term_unref (CRTerm *a_this) +cr_term_unref (CRTerm * a_this) { - g_return_val_if_fail (a_this, FALSE) ; + g_return_val_if_fail (a_this, FALSE); - if (a_this->ref_count) - { - a_this->ref_count -- ; + if (a_this->ref_count) { + a_this->ref_count--; } - if (a_this->ref_count == 0) - { - cr_term_destroy (a_this) ; - return TRUE ; + if (a_this->ref_count == 0) { + cr_term_destroy (a_this); + return TRUE; } - return FALSE ; + return FALSE; } /** @@ -598,21 +542,19 @@ cr_term_unref (CRTerm *a_this) *of #CRTerm. */ void -cr_term_destroy (CRTerm *a_this) +cr_term_destroy (CRTerm * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - cr_term_clear (a_this) ; + cr_term_clear (a_this); - if (a_this->next) - { - cr_term_destroy (a_this->next) ; - a_this->next = NULL ; - } + if (a_this->next) { + cr_term_destroy (a_this->next); + a_this->next = NULL; + } - if (a_this) - { - g_free (a_this) ; + if (a_this) { + g_free (a_this); } } diff --git a/src/cr-tknzr.c b/src/cr-tknzr.c index 8bcc349..87a46a2 100644 --- a/src/cr-tknzr.c +++ b/src/cr-tknzr.c @@ -34,10 +34,9 @@ #include "cr-tknzr.h" #include "cr-doc-handler.h" -struct _CRTknzrPriv -{ +struct _CRTknzrPriv { /**The parser input stream of bytes*/ - CRInput *input ; + CRInput *input; /** *A cache where tknzr_unget_token() @@ -46,24 +45,23 @@ struct _CRTknzrPriv *only if it's empty, fetches the next token *from the input stream. */ - CRToken *token_cache ; - + CRToken *token_cache; + /** *The position of the end of the previous token *or char fetched. */ - CRInputPos prev_pos ; + CRInputPos prev_pos; - CRDocHandler *sac_handler ; + CRDocHandler *sac_handler; /** *The reference count of the current instance *of #CRTknzr. Is manipulated by cr_tknzr_ref() *and cr_tknzr_unref(). */ - glong ref_count ; -} ; - + glong ref_count; +}; #define PRIVATE(obj) ((obj)->priv) @@ -92,7 +90,6 @@ if ((status) != CR_OK) \ goto error ; \ } - /** *Peeks the next char from the input stream of the current tokenizer. *invokes CHECK_PARSING_STATUS on the status returned by @@ -108,8 +105,6 @@ status = cr_tknzr_peek_char (a_tknzr, a_to_char) ; \ CHECK_PARSING_STATUS (status, TRUE) \ } - - /** *Reads the next char from the input stream of the current parser. *In case of error, jumps to the "error:" label located in the @@ -122,7 +117,6 @@ CHECK_PARSING_STATUS (status, TRUE) \ status = cr_tknzr_read_char (a_tknzr, to_char) ;\ CHECK_PARSING_STATUS (status, TRUE) - /** *Gets information about the current position in *the input of the parser. @@ -138,7 +132,6 @@ status = cr_input_get_cur_pos (PRIVATE \ (a_tknzr)->input, a_pos) ; \ g_return_val_if_fail (status == CR_OK, status) - /** *Gets the address of the current byte inside the *parser input. @@ -151,7 +144,6 @@ status = cr_input_get_cur_byte_addr \ (PRIVATE (a_tknzr)->input, a_addr) ; \ CHECK_PARSING_STATUS (status, TRUE) - /** *Peeks a byte from the topmost parser input at *a given offset from the current position. @@ -169,7 +161,6 @@ status = cr_tknzr_peek_byte (a_tknzr, \ a_byte_ptr) ; \ CHECK_PARSING_STATUS (status, TRUE) ; - #define BYTE(a_input, a_n, a_eof) \ cr_input_peek_byte2 (a_input, a_n, a_eof) @@ -185,7 +176,6 @@ status = \ cr_input_read_byte (PRIVATE (a_tknzr)->input, a_byte_ptr) ;\ CHECK_PARSING_STATUS (status, TRUE) ; - /** *Skips a given number of byte in the topmost *parser input. Don't update line and column number. @@ -199,7 +189,6 @@ status = cr_input_seek_index (PRIVATE (a_tknzr)->input, \ CR_SEEK_CUR, a_nb_bytes) ; \ CHECK_PARSING_STATUS (status, TRUE) ; - /** *Skip utf8 encoded characters. *Updates line and column numbers. @@ -215,7 +204,6 @@ status = cr_input_consume_chars \ CHECK_PARSING_STATUS (status, TRUE) ; \ } - /** *Tests the condition and if it is false, sets *status to "CR_PARSING_ERROR" and goto the 'error' @@ -225,32 +213,29 @@ CHECK_PARSING_STATUS (status, TRUE) ; \ #define ENSURE_PARSING_COND(condition) \ if (! (condition)) {status = CR_PARSING_ERROR; goto error ;} - static enum CRStatus -cr_tknzr_parse_nl (CRTknzr *a_this, guchar **a_start, guchar **a_end) ; + cr_tknzr_parse_nl (CRTknzr * a_this, guchar ** a_start, guchar ** a_end); static enum CRStatus -cr_tknzr_parse_w (CRTknzr *a_this, guchar **a_start, guchar **a_end) ; + cr_tknzr_parse_w (CRTknzr * a_this, guchar ** a_start, guchar ** a_end); static enum CRStatus -cr_tknzr_parse_unicode_escape (CRTknzr *a_this, - guint32 *a_unicode) ; + cr_tknzr_parse_unicode_escape (CRTknzr * a_this, guint32 * a_unicode); static enum CRStatus -cr_tknzr_parse_escape (CRTknzr *a_this, guint32 *a_esc_code) ; - + cr_tknzr_parse_escape (CRTknzr * a_this, guint32 * a_esc_code); static enum CRStatus -cr_tknzr_parse_string (CRTknzr *a_this, GString **a_str) ; + cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str); static enum CRStatus -cr_tknzr_parse_comment (CRTknzr *a_this, GString **a_comment) ; + cr_tknzr_parse_comment (CRTknzr * a_this, GString ** a_comment); static enum CRStatus -cr_tknzr_parse_nmstart (CRTknzr *a_this, guint32 *a_char) ; + cr_tknzr_parse_nmstart (CRTknzr * a_this, guint32 * a_char); static enum CRStatus -cr_tknzr_parse_num (CRTknzr *a_this, CRNum ** a_num) ; + cr_tknzr_parse_num (CRTknzr * a_this, CRNum ** a_num); /********************************** *PRIVATE methods @@ -269,73 +254,62 @@ cr_tknzr_parse_num (CRTknzr *a_this, CRNum ** a_num) ; *Can also point to NULL is there is no white space actually. */ static enum CRStatus -cr_tknzr_parse_w (CRTknzr *a_this, guchar **a_start, guchar **a_end) +cr_tknzr_parse_w (CRTknzr * a_this, guchar ** a_start, guchar ** a_end) { - guint32 cur_char = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; + guint32 cur_char = 0; + CRInputPos init_pos; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_start && a_end, - CR_BAD_PARAM_ERROR) ; + && a_start && a_end, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - *a_start = NULL ; - *a_end = NULL ; + *a_start = NULL; + *a_end = NULL; - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - if (cr_utils_is_white_space (cur_char) == FALSE) - { - status = CR_PARSING_ERROR ; - goto error ; + if (cr_utils_is_white_space (cur_char) == FALSE) { + status = CR_PARSING_ERROR; + goto error; } - RECORD_CUR_BYTE_ADDR (a_this, a_start) ; - *a_end = *a_start ; + RECORD_CUR_BYTE_ADDR (a_this, a_start); + *a_end = *a_start; - for (;;) - { - gboolean is_eof = FALSE ; + for (;;) { + gboolean is_eof = FALSE; - cr_input_get_end_of_file (PRIVATE (a_this)->input, - &is_eof) ; + cr_input_get_end_of_file (PRIVATE (a_this)->input, &is_eof); if (is_eof) - break ; - - status = cr_tknzr_peek_char (a_this, &cur_char) ; - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; - break ; - } - else if (status != CR_OK) - { - goto error ; + break; + + status = cr_tknzr_peek_char (a_this, &cur_char); + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + break; + } else if (status != CR_OK) { + goto error; } - if (cr_utils_is_white_space (cur_char) == TRUE) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - RECORD_CUR_BYTE_ADDR (a_this, a_end) ; - } - else - { - break ; + if (cr_utils_is_white_space (cur_char) == TRUE) { + READ_NEXT_CHAR (a_this, &cur_char); + RECORD_CUR_BYTE_ADDR (a_this, a_end); + } else { + break; } } - return CR_OK ; + return CR_OK; - error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + error: + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } - /** *Parses a newline as defined in the css2 spec: * nl ::= \n|\r\n|\r|\f @@ -348,56 +322,48 @@ cr_tknzr_parse_w (CRTknzr *a_this, guchar **a_start, guchar **a_end) *@result CR_OK uppon successfull completion, an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_nl (CRTknzr *a_this, guchar **a_start, guchar **a_end) +cr_tknzr_parse_nl (CRTknzr * a_this, guchar ** a_start, guchar ** a_end) { - CRInputPos init_pos ; - guchar next_chars[2] = {0} ; - enum CRStatus status = CR_PARSING_ERROR ; - + CRInputPos init_pos; + guchar next_chars[2] = { 0 }; + enum CRStatus status = CR_PARSING_ERROR; + g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_start && a_end, - CR_BAD_PARAM_ERROR) ; + && a_start && a_end, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - PEEK_BYTE (a_this, 1, &next_chars[0]) ; - PEEK_BYTE (a_this, 2, &next_chars[1]) ; + PEEK_BYTE (a_this, 1, &next_chars[0]); + PEEK_BYTE (a_this, 2, &next_chars[1]); - if ((next_chars[0] == '\r' && next_chars[1] == '\n')) - { - SKIP_BYTES (a_this, 1) ; - SKIP_CHARS (a_this, 1) ; + if ((next_chars[0] == '\r' && next_chars[1] == '\n')) { + SKIP_BYTES (a_this, 1); + SKIP_CHARS (a_this, 1); - RECORD_CUR_BYTE_ADDR (a_this, a_end) ; + RECORD_CUR_BYTE_ADDR (a_this, a_end); - status = CR_OK ; - } - else if (next_chars[0] == '\n' - || next_chars[0] == '\r' - || next_chars[0] == '\f') - { - SKIP_CHARS (a_this, 1) ; + status = CR_OK; + } else if (next_chars[0] == '\n' + || next_chars[0] == '\r' || next_chars[0] == '\f') { + SKIP_CHARS (a_this, 1); - RECORD_CUR_BYTE_ADDR (a_this, a_start) ; - *a_end = *a_start ; - status = CR_OK ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + RECORD_CUR_BYTE_ADDR (a_this, a_start); + *a_end = *a_start; + status = CR_OK; + } else { + status = CR_PARSING_ERROR; + goto error; } - return CR_OK ; + return CR_OK; - error: + error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } - /** *Go ahead in the parser input, skipping all the spaces. *If the next char if not a white space, this function does nothing. @@ -407,36 +373,32 @@ cr_tknzr_parse_nl (CRTknzr *a_this, guchar **a_start, guchar **a_end) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_tknzr_try_to_skip_spaces (CRTknzr *a_this) +cr_tknzr_try_to_skip_spaces (CRTknzr * a_this) { - enum CRStatus status = CR_ERROR ; - guint32 cur_char = 0 ; + enum CRStatus status = CR_ERROR; + guint32 cur_char = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - status = cr_input_peek_char - (PRIVATE (a_this)->input, &cur_char) ; + status = cr_input_peek_char (PRIVATE (a_this)->input, &cur_char); - if (status != CR_OK) - { - if (status == CR_END_OF_INPUT_ERROR) return CR_OK ; - return status ; + if (status != CR_OK) { + if (status == CR_END_OF_INPUT_ERROR) + return CR_OK; + return status; } - if (cr_utils_is_white_space (cur_char) == TRUE) - { - glong nb_chars = -1; /*consume all spaces*/ + if (cr_utils_is_white_space (cur_char) == TRUE) { + glong nb_chars = -1; /*consume all spaces */ - status = cr_input_consume_white_spaces - (PRIVATE (a_this)->input, &nb_chars) ; + status = cr_input_consume_white_spaces + (PRIVATE (a_this)->input, &nb_chars); } - return status ; + return status; } - /** *Parses a "comment" as defined in the css spec at [4.1.1]: *COMMENT ::= \/\*[^*]*\*+([^/][^*]*\*+)*\/ . @@ -447,88 +409,79 @@ cr_tknzr_try_to_skip_spaces (CRTknzr *a_this) *simply and in a straight forward manner. */ static enum CRStatus -cr_tknzr_parse_comment (CRTknzr *a_this, GString **a_comment) +cr_tknzr_parse_comment (CRTknzr * a_this, GString ** a_comment) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - guint32 cur_char = 0 ; - GString *comment = NULL ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + guint32 cur_char = 0; + GString *comment = NULL; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); + + RECORD_INITIAL_POS (a_this, &init_pos); - RECORD_INITIAL_POS (a_this, &init_pos) ; + READ_NEXT_CHAR (a_this, &cur_char); + ENSURE_PARSING_COND (cur_char == '/'); - READ_NEXT_CHAR (a_this, &cur_char) ; - ENSURE_PARSING_COND (cur_char == '/') ; + READ_NEXT_CHAR (a_this, &cur_char); + ENSURE_PARSING_COND (cur_char == '*'); - READ_NEXT_CHAR (a_this, &cur_char) ; - ENSURE_PARSING_COND (cur_char == '*') ; + comment = g_string_new (NULL); - comment = g_string_new (NULL) ; + for (;;) { + READ_NEXT_CHAR (a_this, &cur_char); - for (;;) - { - READ_NEXT_CHAR (a_this, &cur_char) ; + /*make sure there are no nested comments */ + if (cur_char == '/') { - /*make sure there are no nested comments*/ - if (cur_char == '/') { - - READ_NEXT_CHAR (a_this, &cur_char) ; - ENSURE_PARSING_COND (cur_char != '*') ; + READ_NEXT_CHAR (a_this, &cur_char); + ENSURE_PARSING_COND (cur_char != '*'); - g_string_append_c (comment, '/') ; - g_string_append_unichar (comment, cur_char) ; + g_string_append_c (comment, '/'); + g_string_append_unichar (comment, cur_char); - continue ; + continue; } - /*Detect the end of the comments region*/ - if (cur_char == '*') - { - READ_NEXT_CHAR (a_this, &cur_char) ; + /*Detect the end of the comments region */ + if (cur_char == '*') { + READ_NEXT_CHAR (a_this, &cur_char); - if (cur_char == '/') - { + if (cur_char == '/') { /* *end of comments region *Now, call the right SAC callback. - */ - status = CR_OK ; - break ; - } - else - { - g_string_append_c (comment, '*') ; + */ + status = CR_OK; + break; + } else { + g_string_append_c (comment, '*'); } } - g_string_append_unichar (comment, cur_char) ; + g_string_append_unichar (comment, cur_char); } - if (status == CR_OK) - { - *a_comment = comment ; + if (status == CR_OK) { + *a_comment = comment; - return CR_OK ; + return CR_OK; } - error: + error: - if (comment) - { - g_string_free (comment, TRUE) ; - comment = NULL ; + if (comment) { + g_string_free (comment, TRUE); + comment = NULL; } - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } - /** *Parses an 'unicode' escape sequence defined *in css spec at chap 4.1.1: @@ -546,79 +499,65 @@ cr_tknzr_parse_comment (CRTknzr *a_this, GString **a_comment) *lower level error occured. */ static enum CRStatus -cr_tknzr_parse_unicode_escape (CRTknzr *a_this, - guint32 *a_unicode) +cr_tknzr_parse_unicode_escape (CRTknzr * a_this, guint32 * a_unicode) { - guint32 cur_char ; - CRInputPos init_pos ; - glong occur = 0 ; - guint32 unicode = 0 ; - guchar *tmp_char_ptr1 = NULL, *tmp_char_ptr2 = NULL ; - enum CRStatus status = CR_OK ; + guint32 cur_char; + CRInputPos init_pos; + glong occur = 0; + guint32 unicode = 0; + guchar *tmp_char_ptr1 = NULL, + *tmp_char_ptr2 = NULL; + enum CRStatus status = CR_OK; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_unicode, - CR_BAD_PARAM_ERROR) ; + && a_unicode, CR_BAD_PARAM_ERROR); - /*first, let's backup the current position pointer*/ - RECORD_INITIAL_POS (a_this, &init_pos) ; + /*first, let's backup the current position pointer */ + RECORD_INITIAL_POS (a_this, &init_pos); - READ_NEXT_CHAR (a_this, &cur_char) ; - - if (cur_char != '\\') - { - status = CR_PARSING_ERROR ; - goto error ; + READ_NEXT_CHAR (a_this, &cur_char); + + if (cur_char != '\\') { + status = CR_PARSING_ERROR; + goto error; } - PEEK_NEXT_CHAR (a_this, &cur_char) ; + PEEK_NEXT_CHAR (a_this, &cur_char); - for (occur = 0, unicode = 0 ; - ((cur_char >= '0' && cur_char <= '9') - || (cur_char >= 'a' && cur_char <= 'f') - || (cur_char >= 'A' && cur_char <= 'F')) && occur < 6 ; - occur ++) - { - gint cur_char_val = 0 ; + for (occur = 0, unicode = 0; ((cur_char >= '0' && cur_char <= '9') + || (cur_char >= 'a' && cur_char <= 'f') + || (cur_char >= 'A' && cur_char <= 'F')) + && occur < 6; occur++) { + gint cur_char_val = 0; - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - if ((cur_char >= '0' && cur_char <= '9')) - { - cur_char_val = (cur_char - '0') ; - } - else if ((cur_char >= 'a' && cur_char <= 'f')) - { - cur_char_val = 10 + (cur_char - 'a') ; - } - else if ((cur_char >= 'A' && cur_char <= 'F')) - { - cur_char_val = 10 + (cur_char - 'A') ; + if ((cur_char >= '0' && cur_char <= '9')) { + cur_char_val = (cur_char - '0'); + } else if ((cur_char >= 'a' && cur_char <= 'f')) { + cur_char_val = 10 + (cur_char - 'a'); + } else if ((cur_char >= 'A' && cur_char <= 'F')) { + cur_char_val = 10 + (cur_char - 'A'); } - unicode = unicode * 10 + cur_char_val ; + unicode = unicode * 10 + cur_char_val; - PEEK_NEXT_CHAR (a_this, &cur_char) ; + PEEK_NEXT_CHAR (a_this, &cur_char); } - - if (occur == 5) - { + if (occur == 5) { /* *the unicode escape is 6 digit length */ - + /* *parse one space that may *appear just after the unicode *escape. */ - cr_tknzr_parse_w (a_this, &tmp_char_ptr1, - &tmp_char_ptr2) ; - status = CR_OK ; - } - else - { + cr_tknzr_parse_w (a_this, &tmp_char_ptr1, &tmp_char_ptr2); + status = CR_OK; + } else { /* *The unicode escape is less than *6 digit length. The character @@ -626,23 +565,22 @@ cr_tknzr_parse_unicode_escape (CRTknzr *a_this, *must be a white space. */ status = cr_tknzr_parse_w (a_this, &tmp_char_ptr1, - &tmp_char_ptr2) ; + &tmp_char_ptr2); + } + + if (status == CR_OK) { + *a_unicode = unicode; + return CR_OK; } - - if (status == CR_OK) - { - *a_unicode = unicode ; - return CR_OK ; - } - error: + error: /* *restore the initial position pointer backuped at *the beginning of this function. */ - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } /** @@ -651,64 +589,55 @@ cr_tknzr_parse_unicode_escape (CRTknzr *a_this, *@param a_this the current instance of #CRTknzr . */ static enum CRStatus -cr_tknzr_parse_escape (CRTknzr *a_this, guint32 *a_esc_code) +cr_tknzr_parse_escape (CRTknzr * a_this, guint32 * a_esc_code) { - enum CRStatus status = CR_OK ; - guint32 cur_char = 0 ; - CRInputPos init_pos ; - guchar next_chars[2] ; + enum CRStatus status = CR_OK; + guint32 cur_char = 0; + CRInputPos init_pos; + guchar next_chars[2]; g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_esc_code, CR_BAD_PARAM_ERROR) ; + && a_esc_code, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - PEEK_BYTE (a_this, 1, &next_chars[0]) ; - PEEK_BYTE (a_this, 2, &next_chars[1]) ; + PEEK_BYTE (a_this, 1, &next_chars[0]); + PEEK_BYTE (a_this, 2, &next_chars[1]); - if (next_chars[0] != '\\') - { - status = CR_PARSING_ERROR ; - goto error ; + if (next_chars[0] != '\\') { + status = CR_PARSING_ERROR; + goto error; } - + if ((next_chars[1] >= '0' && next_chars[1] <= '9') - || (next_chars[1] >= 'a' && next_chars[1] <='f') - || (next_chars[1] >= 'A' && next_chars[1] <='F')) - { - status = - cr_tknzr_parse_unicode_escape (a_this, - a_esc_code); - } - else - { - /*consume the '\' char*/ - READ_NEXT_CHAR (a_this, &cur_char) ; - - /*then read the char after the '\'*/ - READ_NEXT_CHAR (a_this, &cur_char) ; - - if (cur_char != ' ' - && (cur_char < 200 || cur_char > 4177777)) - { - status = CR_PARSING_ERROR ; - goto error ; + || (next_chars[1] >= 'a' && next_chars[1] <= 'f') + || (next_chars[1] >= 'A' && next_chars[1] <= 'F')) { + status = cr_tknzr_parse_unicode_escape (a_this, a_esc_code); + } else { + /*consume the '\' char */ + READ_NEXT_CHAR (a_this, &cur_char); + + /*then read the char after the '\' */ + READ_NEXT_CHAR (a_this, &cur_char); + + if (cur_char != ' ' && (cur_char < 200 || cur_char > 4177777)) { + status = CR_PARSING_ERROR; + goto error; } - *a_esc_code = cur_char ; + *a_esc_code = cur_char; } - if (status == CR_OK) - { - return CR_OK ; + if (status == CR_OK) { + return CR_OK; } - error: + error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } /** @@ -727,132 +656,112 @@ cr_tknzr_parse_escape (CRTknzr *a_this, guint32 *a_esc_code) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_string (CRTknzr *a_this, GString **a_str) +cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str) { - guint32 cur_char = 0, delim = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; - GString *str = NULL ; - g_return_val_if_fail (a_this && PRIVATE (a_this) + guint32 cur_char = 0, + delim = 0; + CRInputPos init_pos; + enum CRStatus status = CR_OK; + GString *str = NULL; + + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_str, - CR_BAD_PARAM_ERROR) ; + && a_str, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - if (cur_char == '"') delim = '"' ; - else if (cur_char == '\'') delim = '\'' ; - else - { - status = CR_PARSING_ERROR ; - goto error ; + if (cur_char == '"') + delim = '"'; + else if (cur_char == '\'') + delim = '\''; + else { + status = CR_PARSING_ERROR; + goto error; } - str = g_string_new (NULL) ; + str = g_string_new (NULL); - for (;;) - { - guchar next_chars[2] = {0} ; + for (;;) { + guchar next_chars[2] = { 0 }; - PEEK_BYTE (a_this, 1, &next_chars[0]) ; - PEEK_BYTE (a_this, 2, &next_chars[1]) ; + PEEK_BYTE (a_this, 1, &next_chars[0]); + PEEK_BYTE (a_this, 2, &next_chars[1]); - if (next_chars[0] == '\\') - { - guchar *tmp_char_ptr1 = NULL, - *tmp_char_ptr2 = NULL ; - guint32 esc_code = 0 ; - - if (next_chars[1] == '\'' - || next_chars[1] == '"') - { - g_string_append_unichar (str, - next_chars[1]) ; - SKIP_BYTES (a_this, 2) ; - status = CR_OK ; - } - else - { - status = cr_tknzr_parse_escape - (a_this, &esc_code) ; - - if (status == CR_OK) - { - g_string_append_unichar + if (next_chars[0] == '\\') { + guchar *tmp_char_ptr1 = NULL, + *tmp_char_ptr2 = NULL; + guint32 esc_code = 0; + + if (next_chars[1] == '\'' || next_chars[1] == '"') { + g_string_append_unichar (str, next_chars[1]); + SKIP_BYTES (a_this, 2); + status = CR_OK; + } else { + status = cr_tknzr_parse_escape + (a_this, &esc_code); + + if (status == CR_OK) { + g_string_append_unichar (str, esc_code); } } - if (status != CR_OK) - { + if (status != CR_OK) { /* *consume the '\' char, and try to parse *a newline. */ - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - status = cr_tknzr_parse_nl - (a_this,&tmp_char_ptr1, - &tmp_char_ptr2) ; + status = cr_tknzr_parse_nl + (a_this, &tmp_char_ptr1, + &tmp_char_ptr2); } - CHECK_PARSING_STATUS (status, FALSE) ; - } - else if (strchr ("\t !#$%&", next_chars[0]) - || (next_chars[0] >= '(' && next_chars[0] <= '~')) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - g_string_append_unichar (str, cur_char) ; - status = CR_OK ; - } - - else if (cr_utils_is_nonascii (next_chars[0])) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - g_string_append_unichar (str, cur_char) ; - } - else if (next_chars[0] == delim) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - break ; + CHECK_PARSING_STATUS (status, FALSE); + } else if (strchr ("\t !#$%&", next_chars[0]) + || (next_chars[0] >= '(' && next_chars[0] <= '~')) { + READ_NEXT_CHAR (a_this, &cur_char); + g_string_append_unichar (str, cur_char); + status = CR_OK; } - else - { - status = CR_PARSING_ERROR ; - goto error ; + + else if (cr_utils_is_nonascii (next_chars[0])) { + READ_NEXT_CHAR (a_this, &cur_char); + g_string_append_unichar (str, cur_char); + } else if (next_chars[0] == delim) { + READ_NEXT_CHAR (a_this, &cur_char); + break; + } else { + status = CR_PARSING_ERROR; + goto error; } } - if (status == CR_OK) - { - if (*a_str == NULL) - { - *a_str = str ; - str = NULL ; - } - else - { + if (status == CR_OK) { + if (*a_str == NULL) { + *a_str = str; + str = NULL; + } else { *a_str = g_string_append_len (*a_str, - str->str, - str->len) ; - g_string_free (str, TRUE) ; + str->str, str->len); + g_string_free (str, TRUE); } - return CR_OK ; + return CR_OK; } - error: + error: - if (str) - { - g_string_free (str, TRUE) ; - str = NULL ; + if (str) { + g_string_free (str, TRUE); + str = NULL; } - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } /** @@ -869,51 +778,46 @@ cr_tknzr_parse_string (CRTknzr *a_this, GString **a_str) *an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_nmstart (CRTknzr *a_this, guint32 *a_char) +cr_tknzr_parse_nmstart (CRTknzr * a_this, guint32 * a_char) { - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; - guint32 cur_char = 0, next_char = 0 ; + CRInputPos init_pos; + enum CRStatus status = CR_OK; + guint32 cur_char = 0, + next_char = 0; g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_char, - CR_BAD_PARAM_ERROR) ; + && a_char, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; - - PEEK_NEXT_CHAR (a_this, &next_char) ; + RECORD_INITIAL_POS (a_this, &init_pos); - if (next_char == '\\') - { - status = - cr_tknzr_parse_escape (a_this, a_char) ; + PEEK_NEXT_CHAR (a_this, &next_char); - if (status != CR_OK) goto error ; + if (next_char == '\\') { + status = cr_tknzr_parse_escape (a_this, a_char); - } - else if (cr_utils_is_nonascii (next_char) == TRUE - || ((next_char >= 'a') && (next_char <= 'z')) - || ((next_char >= 'A') && (next_char <= 'Z')) - ) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - *a_char = cur_char ; - status = CR_OK ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + if (status != CR_OK) + goto error; + + } else if (cr_utils_is_nonascii (next_char) == TRUE + || ((next_char >= 'a') && (next_char <= 'z')) + || ((next_char >= 'A') && (next_char <= 'Z')) + ) { + READ_NEXT_CHAR (a_this, &cur_char); + *a_char = cur_char; + status = CR_OK; + } else { + status = CR_PARSING_ERROR; + goto error; } - return CR_OK ; + return CR_OK; - error: + error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } @@ -935,59 +839,53 @@ cr_tknzr_parse_nmstart (CRTknzr *a_this, guint32 *a_char) *an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_nmchar (CRTknzr *a_this, guint32 *a_char) +cr_tknzr_parse_nmchar (CRTknzr * a_this, guint32 * a_char) { - guint32 cur_char = 0, next_char = 0 ; - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; + guint32 cur_char = 0, + next_char = 0; + enum CRStatus status = CR_OK; + CRInputPos init_pos; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_char, - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; + CR_BAD_PARAM_ERROR); - status = - cr_input_peek_char (PRIVATE (a_this)->input, - &next_char) ; + RECORD_INITIAL_POS (a_this, &init_pos); - if (status != CR_OK) goto error ; + status = cr_input_peek_char (PRIVATE (a_this)->input, &next_char); - if (next_char == '\\') - { - status = - cr_tknzr_parse_escape (a_this, a_char) ; + if (status != CR_OK) + goto error; - if (status != CR_OK) goto error ; + if (next_char == '\\') { + status = cr_tknzr_parse_escape (a_this, a_char); - } - else if (cr_utils_is_nonascii (next_char) == TRUE - || ((next_char >= 'a') && (next_char <= 'z')) - || ((next_char >= 'A') && (next_char <= 'Z')) - || ((next_char >= '0') && (next_char <= '9')) - || (next_char == '-') - || (next_char == '_') /*'_' not allowed by the spec.*/ - ) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - *a_char = cur_char ; - status = CR_OK ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + if (status != CR_OK) + goto error; + + } else if (cr_utils_is_nonascii (next_char) == TRUE + || ((next_char >= 'a') && (next_char <= 'z')) + || ((next_char >= 'A') && (next_char <= 'Z')) + || ((next_char >= '0') && (next_char <= '9')) + || (next_char == '-') + || (next_char == '_') /*'_' not allowed by the spec. */ + ) { + READ_NEXT_CHAR (a_this, &cur_char); + *a_char = cur_char; + status = CR_OK; + } else { + status = CR_PARSING_ERROR; + goto error; } - return CR_OK ; + return CR_OK; - error: + error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } - /** *Parses an "ident" as defined in css spec [4.1.1]: *ident ::= {nmstart}{nmchar}* @@ -1003,42 +901,39 @@ cr_tknzr_parse_nmchar (CRTknzr *a_this, guint32 *a_char) *otherwise. */ static enum CRStatus -cr_tknzr_parse_ident (CRTknzr *a_this, GString **a_str) +cr_tknzr_parse_ident (CRTknzr * a_this, GString ** a_str) { - guint32 tmp_char = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; + guint32 tmp_char = 0; + CRInputPos init_pos; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input - && a_str, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->input + && a_str, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_tknzr_parse_nmstart (a_this, &tmp_char) ; + status = cr_tknzr_parse_nmstart (a_this, &tmp_char); if (status != CR_OK) - return CR_PARSING_ERROR ; + return CR_PARSING_ERROR; - if (*a_str == NULL) - { - *a_str = g_string_new (NULL) ; + if (*a_str == NULL) { + *a_str = g_string_new (NULL); } - g_string_append_unichar (*a_str, tmp_char) ; + g_string_append_unichar (*a_str, tmp_char); - for (;;) - { - status = - cr_tknzr_parse_nmchar (a_this, &tmp_char); + for (;;) { + status = cr_tknzr_parse_nmchar (a_this, &tmp_char); - if (status != CR_OK) break ; + if (status != CR_OK) + break; - g_string_append_unichar (*a_str, tmp_char) ; + g_string_append_unichar (*a_str, tmp_char); } - return CR_OK ; + return CR_OK; } /** @@ -1056,57 +951,49 @@ cr_tknzr_parse_ident (CRTknzr *a_this, GString **a_str) *otherwise. */ static enum CRStatus -cr_tknzr_parse_vendor_specific_ident (CRTknzr *a_this, - GString **a_str) +cr_tknzr_parse_vendor_specific_ident (CRTknzr * a_this, GString ** a_str) { - guint32 tmp_char = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; + guint32 tmp_char = 0; + CRInputPos init_pos; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input - && a_str, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->input + && a_str, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - if (BYTE (PRIVATE (a_this)->input, 1, NULL) == '-') - { - SKIP_BYTES (a_this, 1) ; - } - else - { - return CR_PARSING_ERROR ; + if (BYTE (PRIVATE (a_this)->input, 1, NULL) == '-') { + SKIP_BYTES (a_this, 1); + } else { + return CR_PARSING_ERROR; } - status = cr_tknzr_parse_nmstart (a_this, &tmp_char) ; - if (status != CR_OK) - { - status = CR_PARSING_ERROR ; - goto error ; + status = cr_tknzr_parse_nmstart (a_this, &tmp_char); + if (status != CR_OK) { + status = CR_PARSING_ERROR; + goto error; } - if (*a_str == NULL) - { - *a_str = g_string_new (NULL) ; + if (*a_str == NULL) { + *a_str = g_string_new (NULL); } - g_string_append_c (*a_str, '-') ; - g_string_append_unichar (*a_str, tmp_char) ; + g_string_append_c (*a_str, '-'); + g_string_append_unichar (*a_str, tmp_char); - for (;;) - { - status = - cr_tknzr_parse_nmchar (a_this, &tmp_char); + for (;;) { + status = cr_tknzr_parse_nmchar (a_this, &tmp_char); - if (status != CR_OK) break ; + if (status != CR_OK) + break; - g_string_append_unichar (*a_str, tmp_char) ; + g_string_append_unichar (*a_str, tmp_char); } - return CR_OK ; + return CR_OK; - error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; - return status ; + error: + cr_tknzr_set_cur_pos (a_this, &init_pos); + return status; } /** @@ -1123,49 +1010,46 @@ cr_tknzr_parse_vendor_specific_ident (CRTknzr *a_this, *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_name (CRTknzr *a_this, GString **a_str) +cr_tknzr_parse_name (CRTknzr * a_this, GString ** a_str) { - guint32 tmp_char = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; - gboolean str_needs_free = FALSE ; - glong i = 0 ; + guint32 tmp_char = 0; + CRInputPos init_pos; + enum CRStatus status = CR_OK; + gboolean str_needs_free = FALSE; + glong i = 0; - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_str, CR_BAD_PARAM_ERROR) ; + && a_str, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - if (*a_str == NULL) - { - *a_str = g_string_new (NULL) ; - str_needs_free = TRUE ; + if (*a_str == NULL) { + *a_str = g_string_new (NULL); + str_needs_free = TRUE; } - for (i = 0 ; ; i++) - { - status = cr_tknzr_parse_nmchar (a_this, &tmp_char) ; + for (i = 0;; i++) { + status = cr_tknzr_parse_nmchar (a_this, &tmp_char); - if (status != CR_OK) break ; + if (status != CR_OK) + break; - g_string_append_unichar (*a_str, tmp_char) ; + g_string_append_unichar (*a_str, tmp_char); } - if (i > 0) - { - return CR_OK ; + if (i > 0) { + return CR_OK; } - if (str_needs_free == TRUE && *a_str) - { - g_string_free (*a_str, TRUE) ; - *a_str= NULL ; + if (str_needs_free == TRUE && *a_str) { + g_string_free (*a_str, TRUE); + *a_str = NULL; } - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return CR_PARSING_ERROR ; + return CR_PARSING_ERROR; } /** @@ -1173,52 +1057,47 @@ cr_tknzr_parse_name (CRTknzr *a_this, GString **a_str) *HASH ::= #{name} */ static enum CRStatus -cr_tknzr_parse_hash (CRTknzr *a_this, GString **a_str) +cr_tknzr_parse_hash (CRTknzr * a_this, GString ** a_str) { - guint32 cur_char = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; - gboolean str_needs_free = FALSE ; + guint32 cur_char = 0; + CRInputPos init_pos; + enum CRStatus status = CR_OK; + gboolean str_needs_free = FALSE; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; - READ_NEXT_CHAR (a_this, &cur_char) ; + RECORD_INITIAL_POS (a_this, &init_pos); + READ_NEXT_CHAR (a_this, &cur_char); - if (cur_char != '#') - { - status = CR_PARSING_ERROR ; - goto error ; + if (cur_char != '#') { + status = CR_PARSING_ERROR; + goto error; } - if (*a_str == NULL) - { - *a_str = g_string_new (NULL) ; - str_needs_free = TRUE ; + if (*a_str == NULL) { + *a_str = g_string_new (NULL); + str_needs_free = TRUE; } - status = cr_tknzr_parse_name (a_this, a_str) ; + status = cr_tknzr_parse_name (a_this, a_str); - if (status != CR_OK) - { - goto error ; + if (status != CR_OK) { + goto error; } - return CR_OK ; + return CR_OK; - error: + error: - if (str_needs_free == TRUE && *a_str) - { - g_string_free (*a_str, TRUE) ; - *a_str = NULL ; + if (str_needs_free == TRUE && *a_str) { + g_string_free (*a_str, TRUE); + *a_str = NULL; } - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } /** @@ -1231,146 +1110,116 @@ cr_tknzr_parse_hash (CRTknzr *a_this, GString **a_str) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_uri (CRTknzr *a_this, GString **a_str) +cr_tknzr_parse_uri (CRTknzr * a_this, GString ** a_str) { - guint32 cur_char = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_PARSING_ERROR ; - guchar tab[4] = {0}, *tmp_ptr1 = NULL, *tmp_ptr2 = NULL ; - GString *str = NULL ; + guint32 cur_char = 0; + CRInputPos init_pos; + enum CRStatus status = CR_PARSING_ERROR; + guchar tab[4] = { 0 }, *tmp_ptr1 = NULL, *tmp_ptr2 = NULL; + GString *str = NULL; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - PEEK_BYTE (a_this, 1, &tab[0]) ; - PEEK_BYTE (a_this, 2, &tab[1]) ; - PEEK_BYTE (a_this, 3, &tab[2]) ; - PEEK_BYTE (a_this, 4, &tab[3]) ; + PEEK_BYTE (a_this, 1, &tab[0]); + PEEK_BYTE (a_this, 2, &tab[1]); + PEEK_BYTE (a_this, 3, &tab[2]); + PEEK_BYTE (a_this, 4, &tab[3]); - if (tab[0] != 'u' - || tab[1] != 'r' - || tab[2] != 'l' - || tab[3] != '(') - { - status = CR_PARSING_ERROR ; - goto error ; + if (tab[0] != 'u' || tab[1] != 'r' || tab[2] != 'l' || tab[3] != '(') { + status = CR_PARSING_ERROR; + goto error; } - SKIP_CHARS (a_this, 4) ; + SKIP_CHARS (a_this, 4); - cr_tknzr_try_to_skip_spaces (a_this) ; - - status = cr_tknzr_parse_string (a_this, a_str) ; + cr_tknzr_try_to_skip_spaces (a_this); - if (status == CR_OK) - { - guint32 next_char = 0 ; + status = cr_tknzr_parse_string (a_this, a_str); - status = cr_tknzr_parse_w (a_this, &tmp_ptr1, - &tmp_ptr2) ; + if (status == CR_OK) { + guint32 next_char = 0; - cr_tknzr_try_to_skip_spaces (a_this) ; + status = cr_tknzr_parse_w (a_this, &tmp_ptr1, &tmp_ptr2); - PEEK_NEXT_CHAR (a_this, &next_char) ; + cr_tknzr_try_to_skip_spaces (a_this); - if (next_char == ')') - { - READ_NEXT_CHAR (a_this, &cur_char) ; - status = CR_OK ; - } - else - { - status = CR_PARSING_ERROR ; + PEEK_NEXT_CHAR (a_this, &next_char); + + if (next_char == ')') { + READ_NEXT_CHAR (a_this, &cur_char); + status = CR_OK; + } else { + status = CR_PARSING_ERROR; } } + if (status != CR_OK) { + str = g_string_new (NULL); - if (status != CR_OK) - { - str = g_string_new (NULL) ; - - for (;;) - { - guint32 next_char = 0 ; + for (;;) { + guint32 next_char = 0; - PEEK_NEXT_CHAR (a_this, &next_char) ; + PEEK_NEXT_CHAR (a_this, &next_char); - if (strchr ("!#$%&", next_char) + if (strchr ("!#$%&", next_char) || (next_char >= '*' && next_char <= '~') - || (cr_utils_is_nonascii (next_char) == TRUE)) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - g_string_append_unichar (str, - cur_char); - status = CR_OK ; - } - else - { - guint32 esc_code = 0 ; - - status = cr_tknzr_parse_escape - (a_this, - &esc_code) ; - - if (status == CR_OK) - { - g_string_append_unichar - (str, esc_code) ; - } - else - { - status = CR_OK ; - break ; + || (cr_utils_is_nonascii (next_char) == TRUE)) { + READ_NEXT_CHAR (a_this, &cur_char); + g_string_append_unichar (str, cur_char); + status = CR_OK; + } else { + guint32 esc_code = 0; + + status = cr_tknzr_parse_escape + (a_this, &esc_code); + + if (status == CR_OK) { + g_string_append_unichar + (str, esc_code); + } else { + status = CR_OK; + break; } } } - cr_tknzr_try_to_skip_spaces (a_this) ; + cr_tknzr_try_to_skip_spaces (a_this); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - if (cur_char == ')') - { - status = CR_OK ; + if (cur_char == ')') { + status = CR_OK; + } else { + status = CR_PARSING_ERROR; + goto error; } - else - { - status = CR_PARSING_ERROR ; - goto error ; - } - if (str) - { - if (*a_str == NULL) - { - *a_str = str ; - str = NULL ; - } - else - { + if (str) { + if (*a_str == NULL) { + *a_str = str; + str = NULL; + } else { g_string_append_len (*a_str, - str->str, - str->len) ; - g_string_free (str, TRUE) ; + str->str, str->len); + g_string_free (str, TRUE); } } } - return CR_OK ; + return CR_OK; - error: + error: - if (str) - { - g_string_free (str, TRUE) ; - str = NULL ; + if (str) { + g_string_free (str, TRUE); + str = NULL; } - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } /** @@ -1382,142 +1231,125 @@ cr_tknzr_parse_uri (CRTknzr *a_this, GString **a_str) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_rgb (CRTknzr *a_this, CRRgb **a_rgb) +cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb) { - enum CRStatus status = CR_OK ; - CRInputPos init_pos ; - CRNum * num = NULL ; - guchar next_bytes[3] = {0}, cur_byte = 0 ; - glong red = 0, green = 0, blue = 0, i = 0 ; - gboolean is_percentage = FALSE ; - - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - PEEK_BYTE (a_this, 1, &next_bytes[0]) ; - PEEK_BYTE (a_this, 2, &next_bytes[1]) ; - PEEK_BYTE (a_this, 3, &next_bytes[2]) ; + enum CRStatus status = CR_OK; + CRInputPos init_pos; + CRNum *num = NULL; + guchar next_bytes[3] = { 0 }, cur_byte = 0; + glong red = 0, + green = 0, + blue = 0, + i = 0; + gboolean is_percentage = FALSE; + + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); + + RECORD_INITIAL_POS (a_this, &init_pos); + + PEEK_BYTE (a_this, 1, &next_bytes[0]); + PEEK_BYTE (a_this, 2, &next_bytes[1]); + PEEK_BYTE (a_this, 3, &next_bytes[2]); if (((next_bytes[0] == 'r') || (next_bytes[0] == 'R')) && ((next_bytes[1] == 'g') || (next_bytes[1] == 'G')) - && ((next_bytes[2] == 'b') || (next_bytes[2] == 'B'))) - { - SKIP_CHARS (a_this, 3) ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + && ((next_bytes[2] == 'b') || (next_bytes[2] == 'B'))) { + SKIP_CHARS (a_this, 3); + } else { + status = CR_PARSING_ERROR; + goto error; } - READ_NEXT_BYTE (a_this, &cur_byte) ; + READ_NEXT_BYTE (a_this, &cur_byte); - ENSURE_PARSING_COND (cur_byte == '(') ; + ENSURE_PARSING_COND (cur_byte == '('); - cr_tknzr_try_to_skip_spaces (a_this) ; + cr_tknzr_try_to_skip_spaces (a_this); - status = cr_tknzr_parse_num (a_this, &num) ; + status = cr_tknzr_parse_num (a_this, &num); - ENSURE_PARSING_COND - ((status == CR_OK) && (num!= NULL)) ; + ENSURE_PARSING_COND ((status == CR_OK) && (num != NULL)); - red = num->val ; + red = num->val; - cr_num_destroy (num) ; - num = NULL ; + cr_num_destroy (num); + num = NULL; - PEEK_BYTE (a_this, 1, &next_bytes[0]) ; + PEEK_BYTE (a_this, 1, &next_bytes[0]); - if (next_bytes[0] == '%') - { - SKIP_CHARS (a_this, 1) ; - is_percentage = TRUE ; + if (next_bytes[0] == '%') { + SKIP_CHARS (a_this, 1); + is_percentage = TRUE; } - cr_tknzr_try_to_skip_spaces (a_this) ; + cr_tknzr_try_to_skip_spaces (a_this); - for (i = 0 ; i < 2 ; i++) - { - READ_NEXT_BYTE (a_this, &cur_byte) ; + for (i = 0; i < 2; i++) { + READ_NEXT_BYTE (a_this, &cur_byte); - ENSURE_PARSING_COND (cur_byte == ',') ; + ENSURE_PARSING_COND (cur_byte == ','); - cr_tknzr_try_to_skip_spaces (a_this) ; + cr_tknzr_try_to_skip_spaces (a_this); - status = cr_tknzr_parse_num (a_this, &num) ; + status = cr_tknzr_parse_num (a_this, &num); - ENSURE_PARSING_COND - ((status == CR_OK)&&(num != NULL)) ; + ENSURE_PARSING_COND ((status == CR_OK) && (num != NULL)); - PEEK_BYTE (a_this, 1, &next_bytes[0]) ; + PEEK_BYTE (a_this, 1, &next_bytes[0]); - if (next_bytes[0] == '%') - { - SKIP_CHARS (a_this, 1) ; - is_percentage = TRUE ; + if (next_bytes[0] == '%') { + SKIP_CHARS (a_this, 1); + is_percentage = TRUE; } - if (i == 0) - { - green = num->val ; - } - else if (i == 1) - { - blue = num->val ; + if (i == 0) { + green = num->val; + } else if (i == 1) { + blue = num->val; } - if (num) - { - cr_num_destroy (num) ; - num = NULL ; + if (num) { + cr_num_destroy (num); + num = NULL; } - cr_tknzr_try_to_skip_spaces (a_this) ; + cr_tknzr_try_to_skip_spaces (a_this); } - READ_NEXT_BYTE (a_this, &cur_byte) ; + READ_NEXT_BYTE (a_this, &cur_byte); - if (*a_rgb == NULL) - { - *a_rgb = - cr_rgb_new_with_vals (red, green, blue, - is_percentage) ; + if (*a_rgb == NULL) { + *a_rgb = cr_rgb_new_with_vals (red, green, blue, + is_percentage); - if (*a_rgb == NULL) - { - status = CR_ERROR ; - goto error ; - } - status = CR_OK ; + if (*a_rgb == NULL) { + status = CR_ERROR; + goto error; + } + status = CR_OK; + } else { + (*a_rgb)->red = red; + (*a_rgb)->green = green; + (*a_rgb)->blue = blue; + (*a_rgb)->is_percentage = is_percentage; + + status = CR_OK; } - else - { - (*a_rgb)->red = red ; - (*a_rgb)->green = green ; - (*a_rgb)->blue = blue ; - (*a_rgb)->is_percentage = is_percentage ; - status = CR_OK ; - } - - if (status == CR_OK) - { - return CR_OK ; + if (status == CR_OK) { + return CR_OK; } - error: - - if (num) - { - cr_num_destroy (num) ; - num = NULL ; + error: + + if (num) { + cr_num_destroy (num); + num = NULL; } - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return CR_OK ; + return CR_OK; } /** @@ -1536,102 +1368,90 @@ cr_tknzr_parse_rgb (CRTknzr *a_this, CRRgb **a_rgb) *@return CR_OK upon successfull completion, an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_atkeyword (CRTknzr *a_this, GString **a_str) +cr_tknzr_parse_atkeyword (CRTknzr * a_this, GString ** a_str) { - guint32 cur_char = 0 ; - CRInputPos init_pos ; - gboolean str_needs_free = FALSE ; - enum CRStatus status = CR_OK ; + guint32 cur_char = 0; + CRInputPos init_pos; + gboolean str_needs_free = FALSE; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_str, - CR_BAD_PARAM_ERROR) ; + && a_str, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - if (cur_char != '@') - { - status = CR_PARSING_ERROR ; - goto error ; + if (cur_char != '@') { + status = CR_PARSING_ERROR; + goto error; } - if (*a_str == NULL) - { - *a_str = g_string_new (NULL) ; - str_needs_free = TRUE ; + if (*a_str == NULL) { + *a_str = g_string_new (NULL); + str_needs_free = TRUE; } - status = cr_tknzr_parse_ident (a_this, a_str) ; + status = cr_tknzr_parse_ident (a_this, a_str); - if (status != CR_OK) - { - goto error ; + if (status != CR_OK) { + goto error; } - return CR_OK ; + return CR_OK; - error: + error: - if (str_needs_free == TRUE && *a_str) - { - g_string_free (*a_str, TRUE) ; - *a_str = NULL ; + if (str_needs_free == TRUE && *a_str) { + g_string_free (*a_str, TRUE); + *a_str = NULL; } - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } - - static enum CRStatus -cr_tknzr_parse_important (CRTknzr *a_this) +cr_tknzr_parse_important (CRTknzr * a_this) { - guint32 cur_char = 0 ; - CRInputPos init_pos ; - enum CRStatus status = CR_OK ; + guint32 cur_char = 0; + CRInputPos init_pos; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - ENSURE_PARSING_COND (cur_char == '!') ; + ENSURE_PARSING_COND (cur_char == '!'); - cr_tknzr_try_to_skip_spaces (a_this) ; + cr_tknzr_try_to_skip_spaces (a_this); - if (BYTE (PRIVATE (a_this)->input, 1, NULL) == 'i' - && BYTE (PRIVATE (a_this)->input, 2, NULL) == 'm' - && BYTE (PRIVATE (a_this)->input, 3, NULL) == 'p' - && BYTE (PRIVATE (a_this)->input, 4, NULL) == 'o' - && BYTE (PRIVATE (a_this)->input, 5, NULL) == 'r' - && BYTE (PRIVATE (a_this)->input, 6, NULL) == 't' - && BYTE (PRIVATE (a_this)->input, 7, NULL) == 'a' - && BYTE (PRIVATE (a_this)->input, 8, NULL) == 'n' - && BYTE (PRIVATE (a_this)->input, 9, NULL) == 't') - { - SKIP_BYTES (a_this, 9) ; - return CR_OK ; - } - else - { - status = CR_PARSING_ERROR ; + if (BYTE (PRIVATE (a_this)->input, 1, NULL) == 'i' + && BYTE (PRIVATE (a_this)->input, 2, NULL) == 'm' + && BYTE (PRIVATE (a_this)->input, 3, NULL) == 'p' + && BYTE (PRIVATE (a_this)->input, 4, NULL) == 'o' + && BYTE (PRIVATE (a_this)->input, 5, NULL) == 'r' + && BYTE (PRIVATE (a_this)->input, 6, NULL) == 't' + && BYTE (PRIVATE (a_this)->input, 7, NULL) == 'a' + && BYTE (PRIVATE (a_this)->input, 8, NULL) == 'n' + && BYTE (PRIVATE (a_this)->input, 9, NULL) == 't') { + SKIP_BYTES (a_this, 9); + return CR_OK; + } else { + status = CR_PARSING_ERROR; } - error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + error: + cr_tknzr_set_cur_pos (a_this, &init_pos); - return status ; + return status; } - /** *Parses a num as defined in the css spec [4.1.1]: *[0-9]+|[0-9]*\.[0-9]+ @@ -1641,260 +1461,221 @@ cr_tknzr_parse_important (CRTknzr *a_this) *an error code otherwise. */ static enum CRStatus -cr_tknzr_parse_num (CRTknzr *a_this, CRNum ** a_num) +cr_tknzr_parse_num (CRTknzr * a_this, CRNum ** a_num) { - enum CRStatus status = CR_PARSING_ERROR ; - enum CRNumType val_type = NUM_GENERIC ; - gboolean parsing_dec = FALSE, parsed = FALSE ; - guint32 cur_char = 0, int_part = 0, dec_part = 0, - next_char = 0 ; - CRInputPos init_pos ; + enum CRStatus status = CR_PARSING_ERROR; + enum CRNumType val_type = NUM_GENERIC; + gboolean parsing_dec = FALSE, + parsed = FALSE; + guint32 cur_char = 0, + int_part = 0, + dec_part = 0, + next_char = 0; + CRInputPos init_pos; g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - READ_NEXT_CHAR (a_this, &cur_char) ; + READ_NEXT_CHAR (a_this, &cur_char); - if (IS_NUM (cur_char) == TRUE) - { - int_part = int_part * 10 - + (cur_char - '0') ; + if (IS_NUM (cur_char) == TRUE) { + int_part = int_part * 10 + (cur_char - '0'); - parsed = TRUE ; - } - else if (cur_char == '.') - { - parsing_dec = TRUE ; - } - else - { - status = CR_PARSING_ERROR ; - goto error ; + parsed = TRUE; + } else if (cur_char == '.') { + parsing_dec = TRUE; + } else { + status = CR_PARSING_ERROR; + goto error; } - for (;;) - { - status = cr_tknzr_peek_char (a_this, - &next_char) ; - if (status != CR_OK) - { + for (;;) { + status = cr_tknzr_peek_char (a_this, &next_char); + if (status != CR_OK) { if (status == CR_END_OF_INPUT_ERROR) - status = CR_OK ; - break ; + status = CR_OK; + break; } - if (next_char == '.') - { - if (parsing_dec == TRUE) - { - status = CR_PARSING_ERROR ; - goto error ; + if (next_char == '.') { + if (parsing_dec == TRUE) { + status = CR_PARSING_ERROR; + goto error; } - READ_NEXT_CHAR (a_this, &cur_char) ; - parsing_dec = TRUE ; - parsed = TRUE ; - } - else if (IS_NUM (next_char) == TRUE) - { - READ_NEXT_CHAR (a_this, &cur_char) ; - parsed = TRUE ; - - if (parsing_dec == FALSE) - { - int_part = int_part * 10 - + (cur_char - '0') ; - } - else - { - dec_part = dec_part *10 - + (cur_char - '0') ; + READ_NEXT_CHAR (a_this, &cur_char); + parsing_dec = TRUE; + parsed = TRUE; + } else if (IS_NUM (next_char) == TRUE) { + READ_NEXT_CHAR (a_this, &cur_char); + parsed = TRUE; + + if (parsing_dec == FALSE) { + int_part = int_part * 10 + (cur_char - '0'); + } else { + dec_part = dec_part * 10 + (cur_char - '0'); } - } - else - { - break ; + } else { + break; } } - if (parsed == FALSE) - { - status = CR_PARSING_ERROR ; + if (parsed == FALSE) { + status = CR_PARSING_ERROR; } /* *Now, set the output param values. */ - if (status == CR_OK) - { - gdouble val = 0.0 ; + if (status == CR_OK) { + gdouble val = 0.0; - val = int_part ; - val += cr_utils_n_to_0_dot_n (dec_part) ; - if (*a_num == NULL) - { - *a_num = cr_num_new_with_val (val, val_type) ; + val = int_part; + val += cr_utils_n_to_0_dot_n (dec_part); + if (*a_num == NULL) { + *a_num = cr_num_new_with_val (val, val_type); - if (*a_num == NULL) - { - status = CR_ERROR ; - goto error ; + if (*a_num == NULL) { + status = CR_ERROR; + goto error; } + } else { + (*a_num)->val = val; + (*a_num)->type = val_type; } - else - { - (*a_num)->val = val ; - (*a_num)->type = val_type ; - } - - return CR_OK ; + + return CR_OK; } - - error: - cr_tknzr_set_cur_pos (a_this, &init_pos) ; + error: - return status ; -} + cr_tknzr_set_cur_pos (a_this, &init_pos); + return status; +} /********************************************* *PUBLIC methods ********************************************/ CRTknzr * -cr_tknzr_new (CRInput *a_input) +cr_tknzr_new (CRInput * a_input) { - CRTknzr * result = NULL ; + CRTknzr *result = NULL; + + result = g_try_malloc (sizeof (CRTknzr)); - result = g_try_malloc (sizeof (CRTknzr)) ; + if (result == NULL) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - if (result == NULL) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + memset (result, 0, sizeof (CRTknzr)); - memset (result, 0, sizeof (CRTknzr)) ; + result->priv = g_try_malloc (sizeof (CRTknzrPriv)); - result->priv = g_try_malloc (sizeof (CRTknzrPriv)) ; - - if (result->priv == NULL) - { - cr_utils_trace_info ("Out of memory") ; + if (result->priv == NULL) { + cr_utils_trace_info ("Out of memory"); - if (result) - { - g_free (result) ; - result = NULL ; + if (result) { + g_free (result); + result = NULL; } - return NULL ; - } + return NULL; + } - memset (result->priv, 0, sizeof (CRTknzrPriv)) ; + memset (result->priv, 0, sizeof (CRTknzrPriv)); if (a_input) - cr_tknzr_set_input (result, a_input) ; + cr_tknzr_set_input (result, a_input); - return result ; + return result; } - CRTknzr * -cr_tknzr_new_from_buf (const guchar *a_buf, gulong a_len, - enum CREncoding a_enc, - gboolean a_free_at_destroy) +cr_tknzr_new_from_buf (const guchar * a_buf, gulong a_len, + enum CREncoding a_enc, gboolean a_free_at_destroy) { - CRTknzr * result = NULL ; - CRInput *input = NULL ; + CRTknzr *result = NULL; + CRInput *input = NULL; input = cr_input_new_from_buf (a_buf, a_len, a_enc, - a_free_at_destroy) ; + a_free_at_destroy); - g_return_val_if_fail (input != NULL, NULL) ; + g_return_val_if_fail (input != NULL, NULL); - result = cr_tknzr_new (input) ; + result = cr_tknzr_new (input); - return result ; + return result; } CRTknzr * -cr_tknzr_new_from_uri (const guchar *a_file_uri, - enum CREncoding a_enc) +cr_tknzr_new_from_uri (const guchar * a_file_uri, enum CREncoding a_enc) { - CRTknzr * result = NULL ; - CRInput *input = NULL ; + CRTknzr *result = NULL; + CRInput *input = NULL; - input = cr_input_new_from_uri (a_file_uri, a_enc) ; - g_return_val_if_fail (input != NULL, NULL) ; + input = cr_input_new_from_uri (a_file_uri, a_enc); + g_return_val_if_fail (input != NULL, NULL); - result = cr_tknzr_new (input) ; + result = cr_tknzr_new (input); - return result ; + return result; } void -cr_tknzr_ref (CRTknzr *a_this) +cr_tknzr_ref (CRTknzr * a_this) { - g_return_if_fail (a_this && PRIVATE (a_this)) ; + g_return_if_fail (a_this && PRIVATE (a_this)); - PRIVATE (a_this)->ref_count ++ ; + PRIVATE (a_this)->ref_count++; } gboolean -cr_tknzr_unref (CRTknzr *a_this) +cr_tknzr_unref (CRTknzr * a_this) { - g_return_val_if_fail (a_this && PRIVATE (a_this), FALSE) ; - - if (PRIVATE (a_this)->ref_count > 0) - { - PRIVATE (a_this)->ref_count -- ; + g_return_val_if_fail (a_this && PRIVATE (a_this), FALSE); + + if (PRIVATE (a_this)->ref_count > 0) { + PRIVATE (a_this)->ref_count--; } - - if (PRIVATE (a_this)->ref_count == 0) - { - cr_tknzr_destroy (a_this) ; - return TRUE ; + + if (PRIVATE (a_this)->ref_count == 0) { + cr_tknzr_destroy (a_this); + return TRUE; } - return FALSE ; + return FALSE; } enum CRStatus -cr_tknzr_set_input (CRTknzr *a_this, CRInput *a_input) +cr_tknzr_set_input (CRTknzr * a_this, CRInput * a_input) { - g_return_val_if_fail (a_this - && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->input) - { - cr_input_unref (PRIVATE (a_this)->input) ; - } + if (PRIVATE (a_this)->input) { + cr_input_unref (PRIVATE (a_this)->input); + } - PRIVATE (a_this)->input = a_input ; + PRIVATE (a_this)->input = a_input; - cr_input_ref (PRIVATE (a_this)->input) ; + cr_input_ref (PRIVATE (a_this)->input); - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_tknzr_get_input (CRTknzr *a_this, CRInput **a_input) +cr_tknzr_get_input (CRTknzr * a_this, CRInput ** a_input) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - *a_input = PRIVATE (a_this)->input ; + *a_input = PRIVATE (a_this)->input; - return CR_OK ; + return CR_OK; } - /********************************* *Tokenizer input handling routines *********************************/ @@ -1909,16 +1690,13 @@ cr_tknzr_get_input (CRTknzr *a_this, CRInput **a_input) *code otherwise. */ enum CRStatus -cr_tknzr_read_byte (CRTknzr *a_this, guchar *a_byte) +cr_tknzr_read_byte (CRTknzr * a_this, guchar * a_byte) { - g_return_val_if_fail (a_this && PRIVATE (a_this), - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR); - return cr_input_read_byte (PRIVATE (a_this)->input, - a_byte) ; - -} + return cr_input_read_byte (PRIVATE (a_this)->input, a_byte); +} /** *Reads the next char from the parser input stream. @@ -1928,23 +1706,20 @@ cr_tknzr_read_byte (CRTknzr *a_this, guchar *a_byte) *otherwise. */ enum CRStatus -cr_tknzr_read_char (CRTknzr *a_this, guint32 *a_char) +cr_tknzr_read_char (CRTknzr * a_this, guint32 * a_char) { - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_char, - CR_BAD_PARAM_ERROR) ; + && a_char, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; } - return cr_input_read_char (PRIVATE (a_this)->input, - a_char) ; + return cr_input_read_char (PRIVATE (a_this)->input, a_char); } /** @@ -1956,26 +1731,22 @@ cr_tknzr_read_char (CRTknzr *a_this, guint32 *a_char) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_tknzr_peek_char (CRTknzr *a_this, guint32 *a_char) +cr_tknzr_peek_char (CRTknzr * a_this, guint32 * a_char) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input - && a_char, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->input + && a_char, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; } - return cr_input_peek_char (PRIVATE (a_this)->input, - a_char) ; + return cr_input_peek_char (PRIVATE (a_this)->input, a_char); } - /** *Peeks a byte ahead at a given postion in the parser input stream. *@param a_this the current instance of #CRTknzr. @@ -1986,22 +1757,21 @@ cr_tknzr_peek_char (CRTknzr *a_this, guint32 *a_char) *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_tknzr_peek_byte (CRTknzr *a_this, gulong a_offset, guchar *a_byte) +cr_tknzr_peek_byte (CRTknzr * a_this, gulong a_offset, guchar * a_byte) { - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input && a_byte, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; } return cr_input_peek_byte (PRIVATE (a_this)->input, - CR_SEEK_CUR, a_offset, a_byte) ; + CR_SEEK_CUR, a_offset, a_byte); } /** @@ -2015,15 +1785,12 @@ cr_tknzr_peek_byte (CRTknzr *a_this, gulong a_offset, guchar *a_byte) *@return the peeked byte. */ guchar -cr_tknzr_peek_byte2 (CRTknzr *a_this, gulong a_offset, - gboolean *a_eof) +cr_tknzr_peek_byte2 (CRTknzr * a_this, gulong a_offset, gboolean * a_eof) { - g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - 0) ; + g_return_val_if_fail (a_this && PRIVATE (a_this) + && PRIVATE (a_this)->input, 0); - return cr_input_peek_byte2 (PRIVATE (a_this)->input, - a_offset, a_eof) ; + return cr_input_peek_byte2 (PRIVATE (a_this)->input, a_offset, a_eof); } /** @@ -2033,130 +1800,110 @@ cr_tknzr_peek_byte2 (CRTknzr *a_this, gulong a_offset, *@return the number of bytes left or -1 in case of error. */ glong -cr_tknzr_get_nb_bytes_left (CRTknzr *a_this) +cr_tknzr_get_nb_bytes_left (CRTknzr * a_this) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; } - return cr_input_get_nb_bytes_left (PRIVATE (a_this)->input) ; + return cr_input_get_nb_bytes_left (PRIVATE (a_this)->input); } - enum CRStatus -cr_tknzr_get_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) +cr_tknzr_get_cur_pos (CRTknzr * a_this, CRInputPos * a_pos) { g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_pos, CR_BAD_PARAM_ERROR) ; - - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; - } - - return cr_input_get_cur_pos (PRIVATE (a_this)->input, - a_pos) ; + && a_pos, CR_BAD_PARAM_ERROR); + + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; + } + + return cr_input_get_cur_pos (PRIVATE (a_this)->input, a_pos); } enum CRStatus -cr_tknzr_get_cur_byte_addr (CRTknzr *a_this, guchar **a_addr) +cr_tknzr_get_cur_byte_addr (CRTknzr * a_this, guchar ** a_addr) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; - } - - return cr_input_get_cur_byte_addr - (PRIVATE (a_this)->input, a_addr) ; -} + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; + } + return cr_input_get_cur_byte_addr (PRIVATE (a_this)->input, a_addr); +} enum CRStatus -cr_tknzr_seek_index (CRTknzr *a_this, - enum CRSeekPos a_origin, - gint a_pos) +cr_tknzr_seek_index (CRTknzr * a_this, enum CRSeekPos a_origin, gint a_pos) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; - - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; - } - - return cr_input_seek_index (PRIVATE (a_this)->input, - a_origin, a_pos) ; + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); + + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; + } + + return cr_input_seek_index (PRIVATE (a_this)->input, a_origin, a_pos); } enum CRStatus -cr_tknzr_consume_chars (CRTknzr *a_this, guint32 a_char, - glong *a_nb_char) +cr_tknzr_consume_chars (CRTknzr * a_this, guint32 a_char, glong * a_nb_char) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->token_cache) - { - cr_input_set_cur_pos (PRIVATE (a_this)->input, - &PRIVATE (a_this)->prev_pos) ; - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; + if (PRIVATE (a_this)->token_cache) { + cr_input_set_cur_pos (PRIVATE (a_this)->input, + &PRIVATE (a_this)->prev_pos); + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; } return cr_input_consume_chars (PRIVATE (a_this)->input, - a_char, a_nb_char) ; + a_char, a_nb_char); } enum CRStatus -cr_tknzr_set_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) +cr_tknzr_set_cur_pos (CRTknzr * a_this, CRInputPos * a_pos) { g_return_val_if_fail (a_this && PRIVATE (a_this) - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->token_cache) - { - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; + if (PRIVATE (a_this)->token_cache) { + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; } - return cr_input_set_cur_pos (PRIVATE (a_this)->input, - a_pos) ; + return cr_input_set_cur_pos (PRIVATE (a_this)->input, a_pos); } enum CRStatus -cr_tknzr_unget_token (CRTknzr *a_this, CRToken *a_token) +cr_tknzr_unget_token (CRTknzr * a_this, CRToken * a_token) { g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->token_cache == NULL, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); - PRIVATE (a_this)->token_cache = a_token ; + PRIVATE (a_this)->token_cache = a_token; - return CR_OK ; + return CR_OK; } /** @@ -2171,347 +1918,312 @@ cr_tknzr_unget_token (CRTknzr *a_this, CRToken *a_token) *otherwise. */ enum CRStatus -cr_tknzr_get_next_token (CRTknzr *a_this, CRToken **a_tk) +cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk) { - enum CRStatus status = CR_OK ; - CRToken *token = NULL ; - CRInputPos init_pos ; - guint32 next_char = 0 ; - guchar next_bytes[4] = {0} ; - gboolean reached_eof = FALSE ; - CRInput *input = NULL ; - GString *str = NULL ; - CRRgb *rgb = NULL ; + enum CRStatus status = CR_OK; + CRToken *token = NULL; + CRInputPos init_pos; + guint32 next_char = 0; + guchar next_bytes[4] = { 0 }; + gboolean reached_eof = FALSE; + CRInput *input = NULL; + GString *str = NULL; + CRRgb *rgb = NULL; g_return_val_if_fail (a_this && PRIVATE (a_this) && a_tk && *a_tk == NULL - && PRIVATE (a_this)->input, - CR_BAD_PARAM_ERROR) ; + && PRIVATE (a_this)->input, CR_BAD_PARAM_ERROR); - if (PRIVATE (a_this)->token_cache) - { - *a_tk = PRIVATE (a_this)->token_cache ; - PRIVATE (a_this)->token_cache = NULL ; - return CR_OK ; + if (PRIVATE (a_this)->token_cache) { + *a_tk = PRIVATE (a_this)->token_cache; + PRIVATE (a_this)->token_cache = NULL; + return CR_OK; } - RECORD_INITIAL_POS (a_this, &init_pos) ; + RECORD_INITIAL_POS (a_this, &init_pos); - status = cr_input_get_end_of_file - (PRIVATE (a_this)->input, &reached_eof) ; - ENSURE_PARSING_COND (status == CR_OK) ; + status = cr_input_get_end_of_file + (PRIVATE (a_this)->input, &reached_eof); + ENSURE_PARSING_COND (status == CR_OK); - if (reached_eof == TRUE) - { - status = CR_END_OF_INPUT_ERROR ; - goto error ; + if (reached_eof == TRUE) { + status = CR_END_OF_INPUT_ERROR; + goto error; } - input = PRIVATE (a_this)->input ; - - PEEK_NEXT_CHAR (a_this, &next_char) ; - token = cr_token_new () ; - ENSURE_PARSING_COND (token) ; + input = PRIVATE (a_this)->input; - switch (next_char) - { + PEEK_NEXT_CHAR (a_this, &next_char); + token = cr_token_new (); + ENSURE_PARSING_COND (token); + + switch (next_char) { case '@': - { - if (BYTE (input, 2, NULL) == 'f' - && BYTE (input, 3, NULL) == 'o' - && BYTE (input, 4, NULL) == 'n' - && BYTE (input, 5, NULL) == 't' - && BYTE (input, 6, NULL) == '-' - && BYTE (input, 7, NULL) == 'f' - && BYTE (input, 8, NULL) == 'a' - && BYTE (input, 9, NULL) == 'c' - && BYTE (input, 10, NULL) == 'e') - { - SKIP_CHARS (a_this, 10) ; - status = cr_token_set_font_face_sym (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; - } - - if (BYTE (input, 2, NULL) == 'c' - && BYTE (input, 3, NULL) == 'h' - && BYTE (input, 4, NULL) == 'a' - && BYTE (input, 5, NULL) == 'r' - && BYTE (input, 6, NULL) == 's' - && BYTE (input, 7, NULL) == 'e' - && BYTE (input, 8, NULL) == 't') { - SKIP_CHARS (a_this, 8) ; - status = cr_token_set_charset_sym (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; - } + if (BYTE (input, 2, NULL) == 'f' + && BYTE (input, 3, NULL) == 'o' + && BYTE (input, 4, NULL) == 'n' + && BYTE (input, 5, NULL) == 't' + && BYTE (input, 6, NULL) == '-' + && BYTE (input, 7, NULL) == 'f' + && BYTE (input, 8, NULL) == 'a' + && BYTE (input, 9, NULL) == 'c' + && BYTE (input, 10, NULL) == 'e') { + SKIP_CHARS (a_this, 10); + status = cr_token_set_font_face_sym (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } - if (BYTE (input, 2, NULL) == 'i' - && BYTE (input, 3, NULL) == 'm' - && BYTE (input, 4, NULL) == 'p' - && BYTE (input, 5, NULL) == 'o' - && BYTE (input, 6, NULL) == 'r' - && BYTE (input, 7, NULL) == 't') - { - SKIP_CHARS (a_this, 7) ; - status = cr_token_set_import_sym (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; - } + if (BYTE (input, 2, NULL) == 'c' + && BYTE (input, 3, NULL) == 'h' + && BYTE (input, 4, NULL) == 'a' + && BYTE (input, 5, NULL) == 'r' + && BYTE (input, 6, NULL) == 's' + && BYTE (input, 7, NULL) == 'e' + && BYTE (input, 8, NULL) == 't') { + SKIP_CHARS (a_this, 8); + status = cr_token_set_charset_sym (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } - if (BYTE (input, 2, NULL) == 'm' - && BYTE (input, 3, NULL) == 'e' - && BYTE (input, 4, NULL) == 'd' - && BYTE (input, 5, NULL) == 'i' - && BYTE (input, 6, NULL) == 'a') - { - SKIP_CHARS (a_this, 6) ; - status = cr_token_set_media_sym (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; - } - - if (BYTE (input, 2, NULL) == 'p' - && BYTE (input, 3, NULL) == 'a' - && BYTE (input, 4, NULL) == 'g' - && BYTE (input, 5, NULL) == 'e') - { - SKIP_CHARS (a_this, 5) ; - status = cr_token_set_page_sym (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; - } + if (BYTE (input, 2, NULL) == 'i' + && BYTE (input, 3, NULL) == 'm' + && BYTE (input, 4, NULL) == 'p' + && BYTE (input, 5, NULL) == 'o' + && BYTE (input, 6, NULL) == 'r' + && BYTE (input, 7, NULL) == 't') { + SKIP_CHARS (a_this, 7); + status = cr_token_set_import_sym (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } - status = cr_tknzr_parse_atkeyword (a_this, &str) ; - if (status == CR_OK) - { - status = cr_token_set_atkeyword (token, str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + if (BYTE (input, 2, NULL) == 'm' + && BYTE (input, 3, NULL) == 'e' + && BYTE (input, 4, NULL) == 'd' + && BYTE (input, 5, NULL) == 'i' + && BYTE (input, 6, NULL) == 'a') { + SKIP_CHARS (a_this, 6); + status = cr_token_set_media_sym (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } + + if (BYTE (input, 2, NULL) == 'p' + && BYTE (input, 3, NULL) == 'a' + && BYTE (input, 4, NULL) == 'g' + && BYTE (input, 5, NULL) == 'e') { + SKIP_CHARS (a_this, 5); + status = cr_token_set_page_sym (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } + + status = cr_tknzr_parse_atkeyword (a_this, &str); + if (status == CR_OK) { + status = cr_token_set_atkeyword (token, str); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } } - } - break ; + break; case 'u': - if (BYTE (input, 2, NULL) == 'r' - && BYTE (input, 3, NULL) == 'l' - && BYTE (input, 4, NULL) == '(') - { - GString *str = NULL ; - status = cr_tknzr_parse_uri (a_this, &str) ; - if (status == CR_OK) - { - status = cr_token_set_uri (token, str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; - } - } - else - { - status = cr_tknzr_parse_ident (a_this, - &str) ; - if (status == CR_OK && str) - { - status = cr_token_set_ident (token, - str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + if (BYTE (input, 2, NULL) == 'r' + && BYTE (input, 3, NULL) == 'l' + && BYTE (input, 4, NULL) == '(') { + GString *str = NULL; + + status = cr_tknzr_parse_uri (a_this, &str); + if (status == CR_OK) { + status = cr_token_set_uri (token, str); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } + } else { + status = cr_tknzr_parse_ident (a_this, &str); + if (status == CR_OK && str) { + status = cr_token_set_ident (token, str); + CHECK_PARSING_STATUS (status, TRUE); + goto done; } } - break ; + break; case 'r': - if (BYTE (input, 2, NULL) == 'g' - && BYTE (input, 3, NULL) == 'b' - && BYTE (input, 4, NULL) == '(') - { - status = cr_tknzr_parse_rgb (a_this, &rgb) ; - if (status == CR_OK && rgb) - { - status = cr_token_set_rgb (token, rgb) ; - CHECK_PARSING_STATUS (status, TRUE) ; - rgb = NULL ; - goto done ; + if (BYTE (input, 2, NULL) == 'g' + && BYTE (input, 3, NULL) == 'b' + && BYTE (input, 4, NULL) == '(') { + status = cr_tknzr_parse_rgb (a_this, &rgb); + if (status == CR_OK && rgb) { + status = cr_token_set_rgb (token, rgb); + CHECK_PARSING_STATUS (status, TRUE); + rgb = NULL; + goto done; } - - } - else - { - status = cr_tknzr_parse_ident (a_this, - &str) ; - if (status == CR_OK) - { - status = cr_token_set_ident (token, - str) ; - CHECK_PARSING_STATUS(status, TRUE) ; - str = NULL ; - goto done ; + + } else { + status = cr_tknzr_parse_ident (a_this, &str); + if (status == CR_OK) { + status = cr_token_set_ident (token, str); + CHECK_PARSING_STATUS (status, TRUE); + str = NULL; + goto done; } } - break ; + break; case '<': - if (BYTE (input, 2, NULL) == '-' - && BYTE (input, 3, NULL) == '-') - { - SKIP_CHARS (a_this, 3) ; - status = cr_token_set_cdo (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + if (BYTE (input, 2, NULL) == '-' + && BYTE (input, 3, NULL) == '-') { + SKIP_CHARS (a_this, 3); + status = cr_token_set_cdo (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; } - break ; + break; case '-': - if (BYTE (input, 2, NULL) == '-' - && BYTE (input, 3, NULL) == '>') - { - SKIP_CHARS (a_this, 3) ; - status = cr_token_set_cdc (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; - } - else - { - status = cr_tknzr_parse_vendor_specific_ident - (a_this, &str) ; - if (status == CR_OK) - { - cr_token_set_vendor_specific_ident - (token, str) ; - goto done ; + if (BYTE (input, 2, NULL) == '-' + && BYTE (input, 3, NULL) == '>') { + SKIP_CHARS (a_this, 3); + status = cr_token_set_cdc (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } else { + status = cr_tknzr_parse_vendor_specific_ident + (a_this, &str); + if (status == CR_OK) { + cr_token_set_vendor_specific_ident + (token, str); + goto done; } } - break ; + break; case '~': - if (BYTE (input, 2, NULL) == '=') - { - SKIP_CHARS (a_this, 2) ; - status = cr_token_set_includes (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + if (BYTE (input, 2, NULL) == '=') { + SKIP_CHARS (a_this, 2); + status = cr_token_set_includes (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; } - break ; + break; case '|': - if (BYTE (input, 2, NULL) == '=') - { - SKIP_CHARS (a_this, 2) ; - status = cr_token_set_dashmatch (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + if (BYTE (input, 2, NULL) == '=') { + SKIP_CHARS (a_this, 2); + status = cr_token_set_dashmatch (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; } - break ; + break; case '/': - if (BYTE (input, 2, NULL) == '*') - { - status = cr_tknzr_parse_comment (a_this, &str) ; - - if (status == CR_OK) - { - status = cr_token_set_comment (token, - str) ; - str = NULL ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + if (BYTE (input, 2, NULL) == '*') { + status = cr_tknzr_parse_comment (a_this, &str); + + if (status == CR_OK) { + status = cr_token_set_comment (token, str); + str = NULL; + CHECK_PARSING_STATUS (status, TRUE); + goto done; } } case ';': - SKIP_CHARS (a_this, 1) ; - status = cr_token_set_semicolon (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + SKIP_CHARS (a_this, 1); + status = cr_token_set_semicolon (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; case '{': - SKIP_CHARS (a_this, 1) ; - status = cr_token_set_cbo (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + SKIP_CHARS (a_this, 1); + status = cr_token_set_cbo (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; case '}': - SKIP_CHARS (a_this, 1) ; - status = cr_token_set_cbc (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + SKIP_CHARS (a_this, 1); + status = cr_token_set_cbc (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; case '(': - SKIP_CHARS (a_this, 1) ; - status = cr_token_set_po (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + SKIP_CHARS (a_this, 1); + status = cr_token_set_po (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; case ')': - SKIP_CHARS (a_this, 1) ; - status = cr_token_set_pc (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + SKIP_CHARS (a_this, 1); + status = cr_token_set_pc (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; case '[': - SKIP_CHARS (a_this, 1) ; - status = cr_token_set_bo (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + SKIP_CHARS (a_this, 1); + status = cr_token_set_bo (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; case ']': - SKIP_CHARS (a_this, 1) ; - status = cr_token_set_bc (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + SKIP_CHARS (a_this, 1); + status = cr_token_set_bc (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; case ' ': case '\t': case '\n': case '\f': case '\r': - { - guchar *start = NULL, *end = NULL ; - status = cr_tknzr_parse_w (a_this, &start, &end) ; - if (status == CR_OK) { - status = cr_token_set_s (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + guchar *start = NULL, + *end = NULL; + + status = cr_tknzr_parse_w (a_this, &start, &end); + if (status == CR_OK) { + status = cr_token_set_s (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; + } } - } - break ; + break; - case '#': - { - status = cr_tknzr_parse_hash (a_this, &str) ; - if (status == CR_OK && str) + case '#': { - status = cr_token_set_hash (token, str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - str = NULL ; - goto done ; + status = cr_tknzr_parse_hash (a_this, &str); + if (status == CR_OK && str) { + status = cr_token_set_hash (token, str); + CHECK_PARSING_STATUS (status, TRUE); + str = NULL; + goto done; + } } - } - break ; + break; - case '\'': + case '\'': case '"': - status = cr_tknzr_parse_string (a_this, &str) ; - if (status == CR_OK && str) - { - status = cr_token_set_string (token, str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - str = NULL ; - goto done ; + status = cr_tknzr_parse_string (a_this, &str); + if (status == CR_OK && str) { + status = cr_token_set_string (token, str); + CHECK_PARSING_STATUS (status, TRUE); + str = NULL; + goto done; } - break ; + break; case '!': - status = cr_tknzr_parse_important (a_this) ; - if (status == CR_OK) - { - status = cr_token_set_important_sym (token) ; - CHECK_PARSING_STATUS (status, TRUE) ; - goto done ; + status = cr_tknzr_parse_important (a_this); + if (status == CR_OK) { + status = cr_token_set_important_sym (token); + CHECK_PARSING_STATUS (status, TRUE); + goto done; } - break ; + break; case '0': case '1': @@ -2524,423 +2236,362 @@ cr_tknzr_get_next_token (CRTknzr *a_this, CRToken **a_tk) case '8': case '9': case '.': - { - CRNum *num = NULL ; - - status = cr_tknzr_parse_num (a_this, &num) ; - if (status == CR_OK && num) { - next_bytes[0] = BYTE (input, 1, NULL) ; - next_bytes[1] = BYTE (input, 2, NULL) ; - next_bytes[2] = BYTE (input, 3, NULL) ; - next_bytes[3] = BYTE (input, 3, NULL) ; - - if (next_bytes[0] == 'e' - && next_bytes[1] == 'm') - { - num->type = NUM_LENGTH_EM ; - status = cr_token_set_ems (token, num) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'e' - && next_bytes[1] == 'x') - { - num->type = NUM_LENGTH_EX ; - status = cr_token_set_exs (token, num) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'p' - && next_bytes[1] == 'x') - { - num->type = NUM_LENGTH_PX ; - status = cr_token_set_length - (token, num, - LENGTH_PX_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'c' - && next_bytes[1] == 'm') - { - num->type = NUM_LENGTH_CM ; - status = cr_token_set_length - (token, num, LENGTH_CM_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'm' - && next_bytes[1] == 'm') - { - num->type = NUM_LENGTH_MM ; - status = cr_token_set_length - (token, num, LENGTH_MM_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'i' - && next_bytes[1] == 'n') - { - num->type = NUM_LENGTH_IN ; - status = cr_token_set_length - (token, num, LENGTH_IN_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'p' - && next_bytes[1] == 't') - { - num->type = NUM_LENGTH_PT ; - status = cr_token_set_length - (token, num, LENGTH_PT_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'p' - && next_bytes[1] == 'c') - { - num->type = NUM_LENGTH_PC ; - status = cr_token_set_length - (token, num, LENGTH_PC_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'd' - && next_bytes[1] == 'e' - && next_bytes[2] == 'g') - { - num->type = NUM_ANGLE_DEG ; - status = cr_token_set_angle - (token, num, ANGLE_DEG_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 3) ; - } - else if (next_bytes[0] == 'r' - && next_bytes[1] == 'a' - && next_bytes[2] == 'd') - { - num->type = NUM_ANGLE_RAD ; - status = cr_token_set_angle - (token, num, ANGLE_RAD_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 3) ; - } - else if (next_bytes[0] == 'g' - && next_bytes[1] == 'r' - && next_bytes[2] == 'a' - && next_bytes[3] == 'd') - { - num->type = NUM_ANGLE_GRAD ; - status = cr_token_set_angle - (token, num, ANGLE_GRAD_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 4) ; - } - else if (next_bytes[0] == 'm' - && next_bytes[1] == 's') - { - num->type = NUM_TIME_MS ; - status = cr_token_set_time - (token, num,TIME_MS_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] =='s') - { - num->type = NUM_TIME_S ; - status = cr_token_set_time - (token, num, TIME_S_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 1) ; - } - else if (next_bytes[0] == 'H' - && next_bytes[1] == 'z') - { - num->type = NUM_FREQ_HZ ; - status = cr_token_set_freq - (token, num, FREQ_HZ_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 2) ; - } - else if (next_bytes[0] == 'k' - && next_bytes[1] == 'H' - && next_bytes[2] == 'z') - { - num->type = NUM_FREQ_KHZ ; - status = cr_token_set_freq - (token, num, FREQ_KHZ_ET) ; - num = NULL ; - SKIP_CHARS (a_this, 3) ; - } - else if (next_bytes[0] == '%') - { - num->type = NUM_PERCENTAGE ; - status = cr_token_set_percentage (token, - num) ; - num = NULL ; - SKIP_CHARS (a_this, 1) ; - } - else - { - status = cr_tknzr_parse_ident (a_this, - &str) ; - if (status == CR_OK && str) - { - num->type = NUM_UNKNOWN_TYPE ; - status = cr_token_set_dimen - (token, num, str) ; - num = NULL ; - CHECK_PARSING_STATUS (status, - TRUE); - str = NULL ; - } - else - { - status = cr_token_set_number - (token, num) ; - num = NULL ; - CHECK_PARSING_STATUS (status, - TRUE) ; - str = NULL ; + CRNum *num = NULL; + + status = cr_tknzr_parse_num (a_this, &num); + if (status == CR_OK && num) { + next_bytes[0] = BYTE (input, 1, NULL); + next_bytes[1] = BYTE (input, 2, NULL); + next_bytes[2] = BYTE (input, 3, NULL); + next_bytes[3] = BYTE (input, 3, NULL); + + if (next_bytes[0] == 'e' + && next_bytes[1] == 'm') { + num->type = NUM_LENGTH_EM; + status = cr_token_set_ems (token, + num); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'e' + && next_bytes[1] == 'x') { + num->type = NUM_LENGTH_EX; + status = cr_token_set_exs (token, + num); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'p' + && next_bytes[1] == 'x') { + num->type = NUM_LENGTH_PX; + status = cr_token_set_length + (token, num, LENGTH_PX_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'c' + && next_bytes[1] == 'm') { + num->type = NUM_LENGTH_CM; + status = cr_token_set_length + (token, num, LENGTH_CM_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'm' + && next_bytes[1] == 'm') { + num->type = NUM_LENGTH_MM; + status = cr_token_set_length + (token, num, LENGTH_MM_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'i' + && next_bytes[1] == 'n') { + num->type = NUM_LENGTH_IN; + status = cr_token_set_length + (token, num, LENGTH_IN_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'p' + && next_bytes[1] == 't') { + num->type = NUM_LENGTH_PT; + status = cr_token_set_length + (token, num, LENGTH_PT_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'p' + && next_bytes[1] == 'c') { + num->type = NUM_LENGTH_PC; + status = cr_token_set_length + (token, num, LENGTH_PC_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'd' + && next_bytes[1] == 'e' + && next_bytes[2] == 'g') { + num->type = NUM_ANGLE_DEG; + status = cr_token_set_angle + (token, num, ANGLE_DEG_ET); + num = NULL; + SKIP_CHARS (a_this, 3); + } else if (next_bytes[0] == 'r' + && next_bytes[1] == 'a' + && next_bytes[2] == 'd') { + num->type = NUM_ANGLE_RAD; + status = cr_token_set_angle + (token, num, ANGLE_RAD_ET); + num = NULL; + SKIP_CHARS (a_this, 3); + } else if (next_bytes[0] == 'g' + && next_bytes[1] == 'r' + && next_bytes[2] == 'a' + && next_bytes[3] == 'd') { + num->type = NUM_ANGLE_GRAD; + status = cr_token_set_angle + (token, num, ANGLE_GRAD_ET); + num = NULL; + SKIP_CHARS (a_this, 4); + } else if (next_bytes[0] == 'm' + && next_bytes[1] == 's') { + num->type = NUM_TIME_MS; + status = cr_token_set_time + (token, num, TIME_MS_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 's') { + num->type = NUM_TIME_S; + status = cr_token_set_time + (token, num, TIME_S_ET); + num = NULL; + SKIP_CHARS (a_this, 1); + } else if (next_bytes[0] == 'H' + && next_bytes[1] == 'z') { + num->type = NUM_FREQ_HZ; + status = cr_token_set_freq + (token, num, FREQ_HZ_ET); + num = NULL; + SKIP_CHARS (a_this, 2); + } else if (next_bytes[0] == 'k' + && next_bytes[1] == 'H' + && next_bytes[2] == 'z') { + num->type = NUM_FREQ_KHZ; + status = cr_token_set_freq + (token, num, FREQ_KHZ_ET); + num = NULL; + SKIP_CHARS (a_this, 3); + } else if (next_bytes[0] == '%') { + num->type = NUM_PERCENTAGE; + status = cr_token_set_percentage + (token, num); + num = NULL; + SKIP_CHARS (a_this, 1); + } else { + status = cr_tknzr_parse_ident (a_this, + &str); + if (status == CR_OK && str) { + num->type = NUM_UNKNOWN_TYPE; + status = cr_token_set_dimen + (token, num, str); + num = NULL; + CHECK_PARSING_STATUS (status, + TRUE); + str = NULL; + } else { + status = cr_token_set_number + (token, num); + num = NULL; + CHECK_PARSING_STATUS (status, + TRUE); + str = NULL; + } } - } - goto done ; + goto done; + } } - } - break ; + break; default: - /*process the fallback cases here*/ + /*process the fallback cases here */ if (next_char == '\\' || (cr_utils_is_nonascii (next_bytes[0]) == TRUE) || ((next_char >= 'a') && (next_char <= 'z')) - || ((next_char >= 'A') && (next_char <= 'Z'))) - { - status = cr_tknzr_parse_ident (a_this, &str) ; - if (status == CR_OK && str) - { - guint32 next_c = 0 ; + || ((next_char >= 'A') && (next_char <= 'Z'))) { + status = cr_tknzr_parse_ident (a_this, &str); + if (status == CR_OK && str) { + guint32 next_c = 0; - status = cr_input_peek_char - (PRIVATE (a_this)->input, - &next_c); + status = cr_input_peek_char + (PRIVATE (a_this)->input, &next_c); - if (status == CR_OK && next_c == '(') - { + if (status == CR_OK && next_c == '(') { - SKIP_CHARS (a_this, 1) ; + SKIP_CHARS (a_this, 1); status = cr_token_set_function - (token, str) ; - CHECK_PARSING_STATUS (status, TRUE) ; + (token, str); + CHECK_PARSING_STATUS (status, TRUE); /*ownership is transfered *to token by cr_token_set_function. */ - str = NULL ; - } - else - { + str = NULL; + } else { status = cr_token_set_ident (token, - str) ; - CHECK_PARSING_STATUS (status, TRUE) ; - str = NULL ; + str); + CHECK_PARSING_STATUS (status, TRUE); + str = NULL; } - goto done ; - } - else - { - if (str) - { - g_string_free (str, TRUE) ; - str = NULL ; + goto done; + } else { + if (str) { + g_string_free (str, TRUE); + str = NULL; } } } - break ; + break; } - - READ_NEXT_CHAR (a_this, &next_char) ; - status = cr_token_set_delim (token, next_char) ; - CHECK_PARSING_STATUS (status, TRUE) ; - done: + READ_NEXT_CHAR (a_this, &next_char); + status = cr_token_set_delim (token, next_char); + CHECK_PARSING_STATUS (status, TRUE); - if (status == CR_OK && token) - { - *a_tk = token ; + done: + + if (status == CR_OK && token) { + *a_tk = token; /* *store the previous position input stream pos. */ - memmove (&PRIVATE (a_this)->prev_pos, - &init_pos, sizeof (CRInputPos)) ; - return CR_OK ; + memmove (&PRIVATE (a_this)->prev_pos, + &init_pos, sizeof (CRInputPos)); + return CR_OK; } - error: - if (token) - { - cr_token_destroy (token) ; - token = NULL ; + error: + if (token) { + cr_token_destroy (token); + token = NULL; } - if (str) - { - g_string_free (str, TRUE) ; - str = NULL ; + if (str) { + g_string_free (str, TRUE); + str = NULL; } - cr_tknzr_set_cur_pos (a_this, - &init_pos) ; - return status ; + cr_tknzr_set_cur_pos (a_this, &init_pos); + return status; } enum CRStatus -cr_tknzr_parse_token (CRTknzr *a_this, enum CRTokenType a_type, +cr_tknzr_parse_token (CRTknzr * a_this, enum CRTokenType a_type, enum CRTokenExtraType a_et, gpointer a_res, gpointer a_extra_res) { - enum CRStatus status = CR_OK ; - CRToken *token = NULL ; + enum CRStatus status = CR_OK; + CRToken *token = NULL; - g_return_val_if_fail (a_this && PRIVATE (a_this) + g_return_val_if_fail (a_this && PRIVATE (a_this) && PRIVATE (a_this)->input - && a_res, - CR_BAD_PARAM_ERROR) ; + && a_res, CR_BAD_PARAM_ERROR); - status = cr_tknzr_get_next_token (a_this, - &token) ; - if (status != CR_OK) return status ; - if (token == NULL) return CR_PARSING_ERROR ; + status = cr_tknzr_get_next_token (a_this, &token); + if (status != CR_OK) + return status; + if (token == NULL) + return CR_PARSING_ERROR; - if (token->type == a_type) - { - switch (a_type) - { + if (token->type == a_type) { + switch (a_type) { case NO_TK: - case S_TK: - case CDO_TK: - case CDC_TK: - case INCLUDES_TK: - case DASHMATCH_TK: + case S_TK: + case CDO_TK: + case CDC_TK: + case INCLUDES_TK: + case DASHMATCH_TK: case IMPORT_SYM_TK: - case PAGE_SYM_TK: - case MEDIA_SYM_TK: - case FONT_FACE_SYM_TK: - case CHARSET_SYM_TK: + case PAGE_SYM_TK: + case MEDIA_SYM_TK: + case FONT_FACE_SYM_TK: + case CHARSET_SYM_TK: case IMPORTANT_SYM_TK: - status = CR_OK ; - break ; + status = CR_OK; + break; - case STRING_TK: + case STRING_TK: case IDENT_TK: - case VENDOR_SPECIFIC_IDENT_TK: - case HASH_TK: + case VENDOR_SPECIFIC_IDENT_TK: + case HASH_TK: case ATKEYWORD_TK: case FUNCTION_TK: case COMMENT_TK: case URI_TK: - *((GString**)a_res) = token->u.str ; - token->u.str = NULL ; - status = CR_OK ; - break ; - - case EMS_TK: - case EXS_TK: + *((GString **) a_res) = token->u.str; + token->u.str = NULL; + status = CR_OK; + break; + + case EMS_TK: + case EXS_TK: case PERCENTAGE_TK: - case NUMBER_TK: - *((CRNum**)a_res) = token->u.num ; - token->u.num = NULL ; - status = CR_OK ; - break ; - - case LENGTH_TK: - case ANGLE_TK: - case TIME_TK: - case FREQ_TK: - if (token->extra_type == a_et) - { - *((CRNum**)a_res) = token->u.num ; - token->u.num = NULL ; - status = CR_OK ; + case NUMBER_TK: + *((CRNum **) a_res) = token->u.num; + token->u.num = NULL; + status = CR_OK; + break; + + case LENGTH_TK: + case ANGLE_TK: + case TIME_TK: + case FREQ_TK: + if (token->extra_type == a_et) { + *((CRNum **) a_res) = token->u.num; + token->u.num = NULL; + status = CR_OK; } - break ; - - case DIMEN_TK: - *((CRNum**)a_res) = token->u.num ; - if (a_extra_res == NULL) - { - status = CR_BAD_PARAM_ERROR ; - goto error ; + break; + + case DIMEN_TK: + *((CRNum **) a_res) = token->u.num; + if (a_extra_res == NULL) { + status = CR_BAD_PARAM_ERROR; + goto error; } - *((GString**)a_extra_res) = token->dimen ; - token->u.num = NULL ; - token->dimen = NULL ; - status = CR_OK ; - break ; + *((GString **) a_extra_res) = token->dimen; + token->u.num = NULL; + token->dimen = NULL; + status = CR_OK; + break; - case DELIM_TK: - *((guint32*)a_res) = token->u.unichar ; - status = CR_OK ; - break ; + case DELIM_TK: + *((guint32 *) a_res) = token->u.unichar; + status = CR_OK; + break; case UNICODERANGE_TK: default: - status = CR_PARSING_ERROR ; - break ; + status = CR_PARSING_ERROR; + break; } - cr_token_destroy (token) ; token = NULL ; - } - else - { - cr_tknzr_unget_token (a_this, - token) ; - token = NULL ; - status = CR_PARSING_ERROR ; + cr_token_destroy (token); + token = NULL; + } else { + cr_tknzr_unget_token (a_this, token); + token = NULL; + status = CR_PARSING_ERROR; } - return status ; + return status; - error: + error: - if (token) - { - cr_tknzr_unget_token (a_this, token) ; - token = NULL ; + if (token) { + cr_tknzr_unget_token (a_this, token); + token = NULL; } - return status ; + return status; } void -cr_tknzr_destroy (CRTknzr *a_this) +cr_tknzr_destroy (CRTknzr * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - - if (PRIVATE (a_this) && PRIVATE (a_this)->input) - { - if (cr_input_unref (PRIVATE (a_this)->input) - == TRUE) - { - PRIVATE (a_this)->input = NULL ; - } - } + if (PRIVATE (a_this) && PRIVATE (a_this)->input) { + if (cr_input_unref (PRIVATE (a_this)->input) + == TRUE) { + PRIVATE (a_this)->input = NULL; + } + } - if (PRIVATE (a_this)->token_cache) - { - cr_token_destroy (PRIVATE (a_this)->token_cache) ; - PRIVATE (a_this)->token_cache = NULL ; + if (PRIVATE (a_this)->token_cache) { + cr_token_destroy (PRIVATE (a_this)->token_cache); + PRIVATE (a_this)->token_cache = NULL; } - if (PRIVATE (a_this)) - { - g_free (PRIVATE (a_this)) ; - PRIVATE (a_this) = NULL ; + if (PRIVATE (a_this)) { + g_free (PRIVATE (a_this)); + PRIVATE (a_this) = NULL; } - g_free (a_this) ; + g_free (a_this); } diff --git a/src/cr-token.c b/src/cr-token.c index 1ce78dc..8988e8b 100644 --- a/src/cr-token.c +++ b/src/cr-token.c @@ -32,46 +32,43 @@ #include #include "cr-token.h" - /** *Frees the attributes of the current instance *of #CRtoken. *@param a_this the current instance of #CRToken. */ static void -cr_token_clear (CRToken *a_this) -{ - g_return_if_fail (a_this) ; - - switch (a_this->type) - { - case S_TK: - case CDO_TK: - case INCLUDES_TK: - case DASHMATCH_TK: - case PAGE_SYM_TK: - case MEDIA_SYM_TK: - case FONT_FACE_SYM_TK: - case CHARSET_SYM_TK: +cr_token_clear (CRToken * a_this) +{ + g_return_if_fail (a_this); + + switch (a_this->type) { + case S_TK: + case CDO_TK: + case INCLUDES_TK: + case DASHMATCH_TK: + case PAGE_SYM_TK: + case MEDIA_SYM_TK: + case FONT_FACE_SYM_TK: + case CHARSET_SYM_TK: case IMPORT_SYM_TK: - case IMPORTANT_SYM_TK: - break ; + case IMPORTANT_SYM_TK: + break; - case STRING_TK: + case STRING_TK: case IDENT_TK: case HASH_TK: case URI_TK: case FUNCTION_TK: case COMMENT_TK: case VENDOR_SPECIFIC_IDENT_TK: - if (a_this->u.str) - { - g_string_free (a_this->u.str, TRUE) ; - a_this->u.str = NULL ; + if (a_this->u.str) { + g_string_free (a_this->u.str, TRUE); + a_this->u.str = NULL; } - break ; - - case EMS_TK: + break; + + case EMS_TK: case EXS_TK: case LENGTH_TK: case ANGLE_TK: @@ -79,64 +76,58 @@ cr_token_clear (CRToken *a_this) case FREQ_TK: case PERCENTAGE_TK: case NUMBER_TK: - if (a_this->u.num) - { - cr_num_destroy (a_this->u.num) ; - a_this->u.num = NULL ; + if (a_this->u.num) { + cr_num_destroy (a_this->u.num); + a_this->u.num = NULL; } - break ; - - case DIMEN_TK: - if (a_this->u.num) - { - cr_num_destroy (a_this->u.num) ; - a_this->u.num = NULL ; + break; + + case DIMEN_TK: + if (a_this->u.num) { + cr_num_destroy (a_this->u.num); + a_this->u.num = NULL; } - - if (a_this->dimen) - { - g_string_free (a_this->dimen, TRUE) ; - a_this->dimen = NULL ; + + if (a_this->dimen) { + g_string_free (a_this->dimen, TRUE); + a_this->dimen = NULL; } - - break ; - - case UNICODERANGE_TK: - /*not supported yet.*/ - break ; - - default: - break ; - } - - a_this->type = NO_TK ; -} + break; + + case UNICODERANGE_TK: + /*not supported yet. */ + break; + + default: + break; + } + + a_this->type = NO_TK; +} /** *Default constructor of *the #CRToken class. *@return the newly built instance of #CRToken. */ -CRToken* +CRToken * cr_token_new (void) { - CRToken *result = NULL ; + CRToken *result = NULL; - result = g_try_malloc (sizeof (CRToken)) ; + result = g_try_malloc (sizeof (CRToken)); - if (result == NULL) - { - cr_utils_trace_info ("Out of memory") ; - return NULL ; - } + if (result == NULL) { + cr_utils_trace_info ("Out of memory"); + return NULL; + } - memset (result, 0, sizeof (CRToken)) ; + memset (result, 0, sizeof (CRToken)); - return result ; + return result; } - /** *Sets the type of curren instance of *#CRToken to 'S_TK' (S in the css2 spec) @@ -145,18 +136,16 @@ cr_token_new (void) *code otherwise. */ enum CRStatus -cr_token_set_s (CRToken *a_this) +cr_token_set_s (CRToken * a_this) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_token_clear (a_this) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - a_this->type = S_TK ; - - return CR_OK ; -} + cr_token_clear (a_this); + + a_this->type = S_TK; + return CR_OK; +} /** *Sets the type of the current instance of @@ -166,16 +155,15 @@ cr_token_set_s (CRToken *a_this) *code otherwise. */ enum CRStatus -cr_token_set_cdo (CRToken *a_this) +cr_token_set_cdo (CRToken * a_this) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_token_clear (a_this) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); + + cr_token_clear (a_this); - a_this->type = CDO_TK ; + a_this->type = CDO_TK; - return CR_OK ; + return CR_OK; } /** @@ -186,18 +174,16 @@ cr_token_set_cdo (CRToken *a_this) *code otherwise. */ enum CRStatus -cr_token_set_cdc (CRToken *a_this) +cr_token_set_cdc (CRToken * a_this) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_token_clear (a_this) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - a_this->type = CDC_TK ; + cr_token_clear (a_this); - return CR_OK ; -} + a_this->type = CDC_TK; + return CR_OK; +} /** *Sets the type of the current instance of @@ -207,18 +193,16 @@ cr_token_set_cdc (CRToken *a_this) *code otherwise. */ enum CRStatus -cr_token_set_includes (CRToken *a_this) +cr_token_set_includes (CRToken * a_this) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_token_clear (a_this) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - a_this->type = INCLUDES_TK ; + cr_token_clear (a_this); - return CR_OK ; -} + a_this->type = INCLUDES_TK; + return CR_OK; +} /** *Sets the type of the current instance of @@ -228,460 +212,450 @@ cr_token_set_includes (CRToken *a_this) *code otherwise. */ enum CRStatus -cr_token_set_dashmatch (CRToken *a_this) +cr_token_set_dashmatch (CRToken * a_this) { - g_return_val_if_fail (a_this, - CR_BAD_PARAM_ERROR) ; - - cr_token_clear (a_this) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - a_this->type = DASHMATCH_TK ; + cr_token_clear (a_this); - return CR_OK ; -} + a_this->type = DASHMATCH_TK; + return CR_OK; +} enum CRStatus -cr_token_set_comment (CRToken *a_this, GString *a_str) +cr_token_set_comment (CRToken * a_this, GString * a_str) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = COMMENT_TK ; + a_this->type = COMMENT_TK; - a_this->u.str = a_str ; + a_this->u.str = a_str; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_string (CRToken *a_this, GString *a_str) +cr_token_set_string (CRToken * a_this, GString * a_str) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = STRING_TK ; + a_this->type = STRING_TK; - a_this->u.str = a_str ; + a_this->u.str = a_str; - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_token_set_ident (CRToken *a_this, GString * a_ident) +cr_token_set_ident (CRToken * a_this, GString * a_ident) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = IDENT_TK ; + a_this->type = IDENT_TK; - a_this->u.str = a_ident ; + a_this->u.str = a_ident; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_vendor_specific_ident (CRToken *a_this, GString * a_ident) +cr_token_set_vendor_specific_ident (CRToken * a_this, GString * a_ident) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = VENDOR_SPECIFIC_IDENT_TK ; + a_this->type = VENDOR_SPECIFIC_IDENT_TK; - a_this->u.str = a_ident ; - return CR_OK ; + a_this->u.str = a_ident; + return CR_OK; } enum CRStatus -cr_token_set_function (CRToken *a_this, GString *a_fun_name) +cr_token_set_function (CRToken * a_this, GString * a_fun_name) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = FUNCTION_TK ; + a_this->type = FUNCTION_TK; - a_this->u.str = a_fun_name ; + a_this->u.str = a_fun_name; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_hash (CRToken *a_this, GString *a_hash) +cr_token_set_hash (CRToken * a_this, GString * a_hash) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = HASH_TK ; + a_this->type = HASH_TK; - a_this->u.str = a_hash ; + a_this->u.str = a_hash; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_rgb (CRToken *a_this, CRRgb *a_rgb) +cr_token_set_rgb (CRToken * a_this, CRRgb * a_rgb) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = RGB_TK ; + a_this->type = RGB_TK; - a_this->u.rgb = a_rgb ; + a_this->u.rgb = a_rgb; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_import_sym (CRToken *a_this) +cr_token_set_import_sym (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = IMPORT_SYM_TK ; + a_this->type = IMPORT_SYM_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_page_sym (CRToken *a_this) +cr_token_set_page_sym (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = PAGE_SYM_TK ; + a_this->type = PAGE_SYM_TK; - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_token_set_media_sym (CRToken *a_this) +cr_token_set_media_sym (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = MEDIA_SYM_TK ; + a_this->type = MEDIA_SYM_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_font_face_sym (CRToken *a_this) +cr_token_set_font_face_sym (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = FONT_FACE_SYM_TK ; + a_this->type = FONT_FACE_SYM_TK; - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_token_set_charset_sym (CRToken *a_this) +cr_token_set_charset_sym (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = CHARSET_SYM_TK ; + a_this->type = CHARSET_SYM_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_atkeyword (CRToken *a_this, GString *a_atname) +cr_token_set_atkeyword (CRToken * a_this, GString * a_atname) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = ATKEYWORD_TK ; + a_this->type = ATKEYWORD_TK; - a_this->u.str = a_atname ; + a_this->u.str = a_atname; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_important_sym (CRToken *a_this) +cr_token_set_important_sym (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = IMPORTANT_SYM_TK ; + a_this->type = IMPORTANT_SYM_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_ems (CRToken *a_this, CRNum *a_num) +cr_token_set_ems (CRToken * a_this, CRNum * a_num) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = EMS_TK ; + a_this->type = EMS_TK; - a_this->u.num = a_num ; + a_this->u.num = a_num; - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_token_set_exs (CRToken *a_this, CRNum *a_num) +cr_token_set_exs (CRToken * a_this, CRNum * a_num) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = EXS_TK ; + a_this->type = EXS_TK; - a_this->u.num = a_num ; + a_this->u.num = a_num; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_length (CRToken *a_this, CRNum *a_num, +cr_token_set_length (CRToken * a_this, CRNum * a_num, enum CRTokenExtraType a_et) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = LENGTH_TK ; - - a_this->extra_type = a_et ; - a_this->u.num = a_num ; + a_this->type = LENGTH_TK; - return CR_OK ; + a_this->extra_type = a_et; + a_this->u.num = a_num; + + return CR_OK; } enum CRStatus -cr_token_set_angle (CRToken *a_this, CRNum *a_num, +cr_token_set_angle (CRToken * a_this, CRNum * a_num, enum CRTokenExtraType a_et) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = ANGLE_TK ; - a_this->extra_type = a_et ; - a_this->u.num = a_num ; + a_this->type = ANGLE_TK; + a_this->extra_type = a_et; + a_this->u.num = a_num; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_time (CRToken *a_this, CRNum *a_num, +cr_token_set_time (CRToken * a_this, CRNum * a_num, enum CRTokenExtraType a_et) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = TIME_TK ; + a_this->type = TIME_TK; a_this->extra_type = a_et; - a_this->u.num = a_num ; + a_this->u.num = a_num; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_freq (CRToken *a_this, CRNum *a_num, +cr_token_set_freq (CRToken * a_this, CRNum * a_num, enum CRTokenExtraType a_et) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = FREQ_TK ; - a_this->extra_type = a_et ; - a_this->u.num = a_num ; + a_this->type = FREQ_TK; + a_this->extra_type = a_et; + a_this->u.num = a_num; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_dimen (CRToken *a_this, CRNum *a_num, - GString *a_dim) +cr_token_set_dimen (CRToken * a_this, CRNum * a_num, GString * a_dim) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = DIMEN_TK ; - a_this->u.num = a_num ; - a_this->dimen = a_dim ; + a_this->type = DIMEN_TK; + a_this->u.num = a_num; + a_this->dimen = a_dim; - return CR_OK ; - -} + return CR_OK; +} enum CRStatus -cr_token_set_percentage (CRToken *a_this, CRNum *a_num) +cr_token_set_percentage (CRToken * a_this, CRNum * a_num) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = PERCENTAGE_TK ; - a_this->u.num = a_num ; + a_this->type = PERCENTAGE_TK; + a_this->u.num = a_num; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_number (CRToken *a_this, CRNum *a_num) +cr_token_set_number (CRToken * a_this, CRNum * a_num) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = NUMBER_TK ; - a_this->u.num = a_num ; + a_this->type = NUMBER_TK; + a_this->u.num = a_num; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_uri (CRToken *a_this, GString *a_uri) +cr_token_set_uri (CRToken * a_this, GString * a_uri) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = URI_TK ; - a_this->u.str = a_uri ; + a_this->type = URI_TK; + a_this->u.str = a_uri; - return CR_OK ; + return CR_OK; } - enum CRStatus -cr_token_set_delim (CRToken *a_this, guint32 a_char) +cr_token_set_delim (CRToken * a_this, guint32 a_char) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = DELIM_TK ; - a_this->u.unichar = a_char ; + a_this->type = DELIM_TK; + a_this->u.unichar = a_char; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_semicolon (CRToken *a_this) +cr_token_set_semicolon (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = SEMICOLON_TK ; + a_this->type = SEMICOLON_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_cbo (CRToken *a_this) +cr_token_set_cbo (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = CBO_TK ; + a_this->type = CBO_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_cbc (CRToken *a_this) +cr_token_set_cbc (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = CBC_TK ; + a_this->type = CBC_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_po (CRToken *a_this) +cr_token_set_po (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = PO_TK ; + a_this->type = PO_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_pc (CRToken *a_this) +cr_token_set_pc (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = PC_TK ; + a_this->type = PC_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_bo (CRToken *a_this) +cr_token_set_bo (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = BO_TK ; + a_this->type = BO_TK; - return CR_OK ; + return CR_OK; } enum CRStatus -cr_token_set_bc (CRToken *a_this) +cr_token_set_bc (CRToken * a_this) { - g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - a_this->type = BC_TK ; + a_this->type = BC_TK; - return CR_OK ; + return CR_OK; } - /** *The destructor of the #CRToken class. *@param a_this the current instance of #CRToken. */ void -cr_token_destroy (CRToken *a_this) +cr_token_destroy (CRToken * a_this) { - g_return_if_fail (a_this) ; + g_return_if_fail (a_this); - cr_token_clear (a_this) ; + cr_token_clear (a_this); - g_free (a_this) ; + g_free (a_this); } diff --git a/src/cr-utils.c b/src/cr-utils.c index 4c7c00a..e4036a2 100644 --- a/src/cr-utils.c +++ b/src/cr-utils.c @@ -36,7 +36,6 @@ *at http://www.w3.org/TR/REC-CSS2/ . */ - /**************************** *Encoding transformations and *encoding helpers @@ -56,8 +55,6 @@ *0400 0000-7FFF FFFF 1111110x 10xxxxxx ... 10xxxxxx */ - - /** *Given an utf8 string buffer, calculates *the length of this string if it was encoded @@ -71,134 +68,112 @@ *otherwise. */ enum CRStatus -cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start, - const guchar *a_in_end, - gulong *a_len) -{ - guchar *byte_ptr = NULL ; - gint len = 0 ; - - /* +cr_utils_utf8_str_len_as_ucs4 (const guchar * a_in_start, + const guchar * a_in_end, gulong * a_len) +{ + guchar *byte_ptr = NULL; + gint len = 0; + + /* *to store the final decoded - *unicode char - */ - guint c = 0 ; - - g_return_val_if_fail (a_in_start && a_in_end && a_len, - CR_BAD_PARAM_ERROR) ; - *a_len = 0 ; - - for (byte_ptr = (guchar*)a_in_start ; - byte_ptr <= a_in_end ; - byte_ptr++) - { - gint nb_bytes_2_decode = 0 ; - - if (*byte_ptr <= 0x7F) - { - /* - *7 bits long char - *encoded over 1 byte: - * 0xxx xxxx - */ - c = *byte_ptr ; - nb_bytes_2_decode = 1 ; - - } - else if ((*byte_ptr & 0xE0) == 0xC0) - { - /* - *up to 11 bits long char. - *encoded over 2 bytes: - *110x xxxx 10xx xxxx - */ - c = *byte_ptr & 0x1F ; - nb_bytes_2_decode = 2 ; - - } - else if ((*byte_ptr & 0xF0) == 0xE0) - { - /* - *up to 16 bit long char - *encoded over 3 bytes: - *1110 xxxx 10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 0x0F ; - nb_bytes_2_decode = 3 ; - - } - else if ((*byte_ptr & 0xF8) == 0xF0) - { - /* - *up to 21 bits long char - *encoded over 4 bytes: - *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 0x7 ; - nb_bytes_2_decode = 4 ; - - } - else if ((*byte_ptr & 0xFC) == 0xF8) - { - /* - *up to 26 bits long char - *encoded over 5 bytes. + *unicode char + */ + guint c = 0; + + g_return_val_if_fail (a_in_start && a_in_end && a_len, + CR_BAD_PARAM_ERROR); + *a_len = 0; + + for (byte_ptr = (guchar *) a_in_start; + byte_ptr <= a_in_end; byte_ptr++) { + gint nb_bytes_2_decode = 0; + + if (*byte_ptr <= 0x7F) { + /* + *7 bits long char + *encoded over 1 byte: + * 0xxx xxxx + */ + c = *byte_ptr; + nb_bytes_2_decode = 1; + + } else if ((*byte_ptr & 0xE0) == 0xC0) { + /* + *up to 11 bits long char. + *encoded over 2 bytes: + *110x xxxx 10xx xxxx + */ + c = *byte_ptr & 0x1F; + nb_bytes_2_decode = 2; + + } else if ((*byte_ptr & 0xF0) == 0xE0) { + /* + *up to 16 bit long char + *encoded over 3 bytes: + *1110 xxxx 10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 0x0F; + nb_bytes_2_decode = 3; + + } else if ((*byte_ptr & 0xF8) == 0xF0) { + /* + *up to 21 bits long char + *encoded over 4 bytes: + *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 0x7; + nb_bytes_2_decode = 4; + + } else if ((*byte_ptr & 0xFC) == 0xF8) { + /* + *up to 26 bits long char + *encoded over 5 bytes. *1111 10xx 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 3 ; - nb_bytes_2_decode = 5 ; - - } - else if ((*byte_ptr & 0xFE) == 0xFC) - { - /* - *up to 31 bits long char - *encoded over 6 bytes: - *1111 110x 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 1 ; - nb_bytes_2_decode = 6 ; - - } - else - { - /* + *10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 3; + nb_bytes_2_decode = 5; + + } else if ((*byte_ptr & 0xFE) == 0xFC) { + /* + *up to 31 bits long char + *encoded over 6 bytes: + *1111 110x 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 1; + nb_bytes_2_decode = 6; + + } else { + /* *BAD ENCODING */ - return CR_ENCODING_ERROR ; - } - - /* - *Go and decode the remaining byte(s) - *(if any) to get the current character. - */ - for ( ; - nb_bytes_2_decode > 1 ; - nb_bytes_2_decode --) - { - /*decode the next byte*/ - byte_ptr ++ ; - - /*byte pattern must be: 10xx xxxx*/ - if ((*byte_ptr & 0xC0) != 0x80) - { - return CR_ENCODING_ERROR ; - } - - c = (c << 6) | (*byte_ptr & 0x3F) ; - } - - len ++ ; - } - - *a_len = len ; - - return CR_OK ; -} + return CR_ENCODING_ERROR; + } + + /* + *Go and decode the remaining byte(s) + *(if any) to get the current character. + */ + for (; nb_bytes_2_decode > 1; nb_bytes_2_decode--) { + /*decode the next byte */ + byte_ptr++; + + /*byte pattern must be: 10xx xxxx */ + if ((*byte_ptr & 0xC0) != 0x80) { + return CR_ENCODING_ERROR; + } + c = (c << 6) | (*byte_ptr & 0x3F); + } + + len++; + } + *a_len = len; + + return CR_OK; +} /** *Given an ucs4 string, this function @@ -211,53 +186,38 @@ cr_utils_utf8_str_len_as_ucs4 (const guchar *a_in_start, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start, - const guint32 *a_in_end, - gulong *a_len) +cr_utils_ucs4_str_len_as_utf8 (const guint32 * a_in_start, + const guint32 * a_in_end, gulong * a_len) { - gint len = 0 ; - guint32 *char_ptr = NULL ; - - g_return_val_if_fail (a_in_start && a_in_end && a_len, - CR_BAD_PARAM_ERROR) ; - - for (char_ptr = (guint32*)a_in_start ; - char_ptr <= a_in_end ; - char_ptr ++) - { - if (*char_ptr <= 0x7F) - { - /*the utf-8 char would take 1 byte*/ - len += 1 ; - } - else if (*char_ptr <= 0x7FF) - { - /*the utf-8 char would take 2 bytes*/ - len += 2 ; - } - else if (*char_ptr <= 0xFFFF) - { - len += 3 ; - } - else if (*char_ptr <= 0x1FFFFF) - { - len += 4 ; + gint len = 0; + guint32 *char_ptr = NULL; + + g_return_val_if_fail (a_in_start && a_in_end && a_len, + CR_BAD_PARAM_ERROR); + + for (char_ptr = (guint32 *) a_in_start; + char_ptr <= a_in_end; char_ptr++) { + if (*char_ptr <= 0x7F) { + /*the utf-8 char would take 1 byte */ + len += 1; + } else if (*char_ptr <= 0x7FF) { + /*the utf-8 char would take 2 bytes */ + len += 2; + } else if (*char_ptr <= 0xFFFF) { + len += 3; + } else if (*char_ptr <= 0x1FFFFF) { + len += 4; + } else if (*char_ptr <= 0x3FFFFFF) { + len += 5; + } else if (*char_ptr <= 0x7FFFFFFF) { + len += 6; } - else if (*char_ptr <= 0x3FFFFFF) - { - len += 5 ; - } - else if (*char_ptr <= 0x7FFFFFFF) - { - len+= 6 ; - } - } + } - *a_len = len ; - return CR_OK ; + *a_len = len; + return CR_OK; } - /** *Given an ucsA string, this function *returns the size (in bytes) this string @@ -269,34 +229,28 @@ cr_utils_ucs4_str_len_as_utf8 (const guint32 *a_in_start, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start, - const guchar *a_in_end, - gulong *a_len) +cr_utils_ucs1_str_len_as_utf8 (const guchar * a_in_start, + const guchar * a_in_end, gulong * a_len) { - gint len = 0 ; - guchar *char_ptr = NULL ; - - g_return_val_if_fail (a_in_start && a_in_end && a_len, - CR_BAD_PARAM_ERROR) ; - - for (char_ptr = (guchar *)a_in_start ; - char_ptr <= a_in_end ; - char_ptr ++) - { - if (*char_ptr <= 0x7F) - { - /*the utf-8 char would take 1 byte*/ - len += 1 ; - } - else - { - /*the utf-8 char would take 2 bytes*/ - len += 2 ; - } + gint len = 0; + guchar *char_ptr = NULL; + + g_return_val_if_fail (a_in_start && a_in_end && a_len, + CR_BAD_PARAM_ERROR); + + for (char_ptr = (guchar *) a_in_start; + char_ptr <= a_in_end; char_ptr++) { + if (*char_ptr <= 0x7F) { + /*the utf-8 char would take 1 byte */ + len += 1; + } else { + /*the utf-8 char would take 2 bytes */ + len += 2; + } } - *a_len = len ; - return CR_OK ; + *a_len = len; + return CR_OK; } /** @@ -315,132 +269,113 @@ cr_utils_ucs1_str_len_as_utf8 (const guchar *a_in_start, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_utils_utf8_to_ucs4 (const guchar * a_in, - gulong *a_in_len, - guint32 *a_out, - gulong *a_out_len) +cr_utils_utf8_to_ucs4 (const guchar * a_in, + gulong * a_in_len, guint32 * a_out, gulong * a_out_len) { - gulong in_len = 0, out_len = 0, in_index = 0, out_index = 0 ; - enum CRStatus status = CR_OK ; + gulong in_len = 0, + out_len = 0, + in_index = 0, + out_index = 0; + enum CRStatus status = CR_OK; - /* + /* *to store the final decoded - *unicode char - */ - guint c = 0 ; - - g_return_val_if_fail (a_in && a_in_len - && a_out && a_out_len, - CR_BAD_PARAM_ERROR) ; - - if (*a_in_len < 1) - { - status = CR_OK ; - goto end ; + *unicode char + */ + guint c = 0; + + g_return_val_if_fail (a_in && a_in_len + && a_out && a_out_len, CR_BAD_PARAM_ERROR); + + if (*a_in_len < 1) { + status = CR_OK; + goto end; } - in_len = *a_in_len ; - out_len = *a_out_len ; - - for (in_index = 0, out_index = 0 ; - (in_index < in_len) && (out_index < out_len) ; - in_index++, out_index++) - { - gint nb_bytes_2_decode = 0 ; - - if (a_in[in_index] <= 0x7F) - { - /* - *7 bits long char - *encoded over 1 byte: - * 0xxx xxxx - */ - c = a_in[in_index] ; - nb_bytes_2_decode = 1 ; - - } - else if ((a_in[in_index] & 0xE0) == 0xC0) - { - /* - *up to 11 bits long char. - *encoded over 2 bytes: - *110x xxxx 10xx xxxx - */ - c = a_in[in_index] & 0x1F ; - nb_bytes_2_decode = 2 ; - - } - else if ((a_in[in_index] & 0xF0) == 0xE0) - { - /* - *up to 16 bit long char - *encoded over 3 bytes: - *1110 xxxx 10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 0x0F ; - nb_bytes_2_decode = 3 ; - - } - else if ((a_in[in_index] & 0xF8) == 0xF0) - { - /* - *up to 21 bits long char - *encoded over 4 bytes: - *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 0x7 ; - nb_bytes_2_decode = 4 ; - - } - else if ((a_in[in_index] & 0xFC) == 0xF8) - { - /* - *up to 26 bits long char - *encoded over 5 bytes. - *1111 10xx 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 3 ; - nb_bytes_2_decode = 5 ; - - } - else if ((a_in[in_index] & 0xFE) == 0xFC) - { - /* - *up to 31 bits long char - *encoded over 6 bytes: - *1111 110x 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 1 ; - nb_bytes_2_decode = 6 ; - - } - else - { - /*BAD ENCODING*/ - goto end ; - } - - /* - *Go and decode the remaining byte(s) - *(if any) to get the current character. - */ - for ( ; - nb_bytes_2_decode > 1 ; - nb_bytes_2_decode --) - { - /*decode the next byte*/ - in_index ++ ; - - /*byte pattern must be: 10xx xxxx*/ - if ((a_in[in_index] & 0xC0) != 0x80) - { - goto end ; - } - - c = (c << 6) | (a_in[in_index] & 0x3F) ; - } + in_len = *a_in_len; + out_len = *a_out_len; + + for (in_index = 0, out_index = 0; + (in_index < in_len) && (out_index < out_len); + in_index++, out_index++) { + gint nb_bytes_2_decode = 0; + + if (a_in[in_index] <= 0x7F) { + /* + *7 bits long char + *encoded over 1 byte: + * 0xxx xxxx + */ + c = a_in[in_index]; + nb_bytes_2_decode = 1; + + } else if ((a_in[in_index] & 0xE0) == 0xC0) { + /* + *up to 11 bits long char. + *encoded over 2 bytes: + *110x xxxx 10xx xxxx + */ + c = a_in[in_index] & 0x1F; + nb_bytes_2_decode = 2; + + } else if ((a_in[in_index] & 0xF0) == 0xE0) { + /* + *up to 16 bit long char + *encoded over 3 bytes: + *1110 xxxx 10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 0x0F; + nb_bytes_2_decode = 3; + + } else if ((a_in[in_index] & 0xF8) == 0xF0) { + /* + *up to 21 bits long char + *encoded over 4 bytes: + *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 0x7; + nb_bytes_2_decode = 4; + + } else if ((a_in[in_index] & 0xFC) == 0xF8) { + /* + *up to 26 bits long char + *encoded over 5 bytes. + *1111 10xx 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 3; + nb_bytes_2_decode = 5; + + } else if ((a_in[in_index] & 0xFE) == 0xFC) { + /* + *up to 31 bits long char + *encoded over 6 bytes: + *1111 110x 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 1; + nb_bytes_2_decode = 6; + + } else { + /*BAD ENCODING */ + goto end; + } + + /* + *Go and decode the remaining byte(s) + *(if any) to get the current character. + */ + for (; nb_bytes_2_decode > 1; nb_bytes_2_decode--) { + /*decode the next byte */ + in_index++; + + /*byte pattern must be: 10xx xxxx */ + if ((a_in[in_index] & 0xC0) != 0x80) { + goto end; + } + + c = (c << 6) | (a_in[in_index] & 0x3F); + } /* *The decoded ucs4 char is now @@ -450,34 +385,36 @@ cr_utils_utf8_to_ucs4 (const guchar * a_in, /************************ *Some security tests ***********************/ - - /*be sure c is a char*/ - if (c == 0xFFFF || c == 0xFFFE) goto end ; - - /*be sure c is inferior to the max ucs4 char value*/ - if (c > 0x10FFFF) goto end ; + + /*be sure c is a char */ + if (c == 0xFFFF || c == 0xFFFE) + goto end; + + /*be sure c is inferior to the max ucs4 char value */ + if (c > 0x10FFFF) + goto end; /* *c must be less than UTF16 "lower surrogate begin" *or higher than UTF16 "High surrogate end" */ - if (c >= 0xD800 && c <= 0xDFFF) goto end ; + if (c >= 0xD800 && c <= 0xDFFF) + goto end; - /*Avoid characters that equals zero*/ - if (c == 0) goto end ; + /*Avoid characters that equals zero */ + if (c == 0) + goto end; - - a_out[out_index] = c ; + a_out[out_index] = c; } - end: + end: *a_out_len = out_index + 1; *a_in_len = in_index + 1; - return status ; + return status; } - /** *Reads a character from an utf8 buffer. *Actually decode the next character code (unicode character code) @@ -490,309 +427,275 @@ cr_utils_utf8_to_ucs4 (const guchar * a_in, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_utils_read_char_from_utf8_buf (const guchar * a_in, +cr_utils_read_char_from_utf8_buf (const guchar * a_in, gulong a_in_len, - guint32 *a_out, gulong *a_consumed) + guint32 * a_out, gulong * a_consumed) { - gulong in_len = 0, in_index = 0, nb_bytes_2_decode = 0 ; - enum CRStatus status = CR_OK ; - - /* - *to store the final decoded - *unicode char - */ - guint32 c = 0 ; - - g_return_val_if_fail (a_in && a_out && a_out - && a_consumed, CR_BAD_PARAM_ERROR) ; - - if (a_in_len < 1) - { - status = CR_OK ; - goto end ; - } - - in_len = a_in_len ; - - if (*a_in <= 0x7F) - { - /* - *7 bits long char - *encoded over 1 byte: - * 0xxx xxxx - */ - c = *a_in ; - nb_bytes_2_decode = 1 ; - - } - else if ((*a_in & 0xE0) == 0xC0) - { - /* - *up to 11 bits long char. - *encoded over 2 bytes: - *110x xxxx 10xx xxxx - */ - c = *a_in & 0x1F ; - nb_bytes_2_decode = 2 ; - - } - else if ((*a_in & 0xF0) == 0xE0) - { - /* - *up to 16 bit long char - *encoded over 3 bytes: - *1110 xxxx 10xx xxxx 10xx xxxx - */ - c = *a_in & 0x0F ; - nb_bytes_2_decode = 3 ; - - } - else if ((*a_in & 0xF8) == 0xF0) - { + gulong in_len = 0, + in_index = 0, + nb_bytes_2_decode = 0; + enum CRStatus status = CR_OK; + /* - *up to 21 bits long char - *encoded over 4 bytes: - *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + *to store the final decoded + *unicode char */ - c = *a_in & 0x7 ; - nb_bytes_2_decode = 4 ; - - } - else if ((*a_in & 0xFC) == 0xF8) - { + guint32 c = 0; + + g_return_val_if_fail (a_in && a_out && a_out + && a_consumed, CR_BAD_PARAM_ERROR); + + if (a_in_len < 1) { + status = CR_OK; + goto end; + } + + in_len = a_in_len; + + if (*a_in <= 0x7F) { + /* + *7 bits long char + *encoded over 1 byte: + * 0xxx xxxx + */ + c = *a_in; + nb_bytes_2_decode = 1; + + } else if ((*a_in & 0xE0) == 0xC0) { + /* + *up to 11 bits long char. + *encoded over 2 bytes: + *110x xxxx 10xx xxxx + */ + c = *a_in & 0x1F; + nb_bytes_2_decode = 2; + + } else if ((*a_in & 0xF0) == 0xE0) { + /* + *up to 16 bit long char + *encoded over 3 bytes: + *1110 xxxx 10xx xxxx 10xx xxxx + */ + c = *a_in & 0x0F; + nb_bytes_2_decode = 3; + + } else if ((*a_in & 0xF8) == 0xF0) { + /* + *up to 21 bits long char + *encoded over 4 bytes: + *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + */ + c = *a_in & 0x7; + nb_bytes_2_decode = 4; + + } else if ((*a_in & 0xFC) == 0xF8) { + /* + *up to 26 bits long char + *encoded over 5 bytes. + *1111 10xx 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx + */ + c = *a_in & 3; + nb_bytes_2_decode = 5; + + } else if ((*a_in & 0xFE) == 0xFC) { + /* + *up to 31 bits long char + *encoded over 6 bytes: + *1111 110x 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx 10xx xxxx + */ + c = *a_in & 1; + nb_bytes_2_decode = 6; + + } else { + /*BAD ENCODING */ + goto end; + } + + if (nb_bytes_2_decode > a_in_len) { + status = CR_END_OF_INPUT_ERROR; + goto end; + } + /* - *up to 26 bits long char - *encoded over 5 bytes. - *1111 10xx 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx + *Go and decode the remaining byte(s) + *(if any) to get the current character. */ - c = *a_in & 3 ; - nb_bytes_2_decode = 5 ; - - } - else if ((*a_in & 0xFE) == 0xFC) - { + for (in_index = 1; in_index < nb_bytes_2_decode; in_index++) { + /*byte pattern must be: 10xx xxxx */ + if ((a_in[in_index] & 0xC0) != 0x80) { + goto end; + } + + c = (c << 6) | (a_in[in_index] & 0x3F); + } + /* - *up to 31 bits long char - *encoded over 6 bytes: - *1111 110x 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx 10xx xxxx + *The decoded ucs4 char is now + *in c. */ - c = *a_in & 1 ; - nb_bytes_2_decode = 6 ; - - } - else - { - /*BAD ENCODING*/ - goto end ; - } - - if (nb_bytes_2_decode > a_in_len) - { - status = CR_END_OF_INPUT_ERROR ; - goto end ; - } - - /* - *Go and decode the remaining byte(s) - *(if any) to get the current character. - */ - for ( in_index = 1 ; - in_index < nb_bytes_2_decode ; - in_index ++) - { - /*byte pattern must be: 10xx xxxx*/ - if ((a_in[in_index] & 0xC0) != 0x80) - { - goto end ; - } - - c = (c << 6) | (a_in[in_index] & 0x3F) ; - } - - /* - *The decoded ucs4 char is now - *in c. - */ - + /************************ *Some security tests ***********************/ - - /*be sure c is a char*/ - if (c == 0xFFFF || c == 0xFFFE) goto end ; - - /*be sure c is inferior to the max ucs4 char value*/ - if (c > 0x10FFFF) goto end ; - - /* - *c must be less than UTF16 "lower surrogate begin" - *or higher than UTF16 "High surrogate end" - */ - if (c >= 0xD800 && c <= 0xDFFF) goto end ; - - /*Avoid characters that equals zero*/ - if (c == 0) goto end ; - - *a_out = c ; - - end: - *a_consumed = nb_bytes_2_decode ; - - return status ; -} + /*be sure c is a char */ + if (c == 0xFFFF || c == 0xFFFE) + goto end; + + /*be sure c is inferior to the max ucs4 char value */ + if (c > 0x10FFFF) + goto end; + + /* + *c must be less than UTF16 "lower surrogate begin" + *or higher than UTF16 "High surrogate end" + */ + if (c >= 0xD800 && c <= 0xDFFF) + goto end; + + /*Avoid characters that equals zero */ + if (c == 0) + goto end; + + *a_out = c; + + end: + *a_consumed = nb_bytes_2_decode; + + return status; +} /** * */ enum CRStatus -cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start, - const guchar *a_in_end, - gulong *a_len) +cr_utils_utf8_str_len_as_ucs1 (const guchar * a_in_start, + const guchar * a_in_end, gulong * a_len) { - /* - *Note: this function can be made shorter - *but it considers all the cases of the utf8 encoding - *to ease further extensions ... - */ + /* + *Note: this function can be made shorter + *but it considers all the cases of the utf8 encoding + *to ease further extensions ... + */ - guchar *byte_ptr = NULL ; - gint len = 0 ; + guchar *byte_ptr = NULL; + gint len = 0; - /* + /* *to store the final decoded - *unicode char - */ - guint c = 0 ; - - g_return_val_if_fail (a_in_start && a_in_end && a_len, - CR_BAD_PARAM_ERROR) ; - *a_len = 0 ; - - for (byte_ptr = (guchar*)a_in_start ; - byte_ptr <= a_in_end ; - byte_ptr++) - { - gint nb_bytes_2_decode = 0 ; - - if (*byte_ptr <= 0x7F) - { - /* - *7 bits long char - *encoded over 1 byte: - * 0xxx xxxx - */ - c = *byte_ptr ; - nb_bytes_2_decode = 1 ; - - } - else if ((*byte_ptr & 0xE0) == 0xC0) - { - /* - *up to 11 bits long char. - *encoded over 2 bytes: - *110x xxxx 10xx xxxx - */ - c = *byte_ptr & 0x1F ; - nb_bytes_2_decode = 2 ; - - } - else if ((*byte_ptr & 0xF0) == 0xE0) - { - /* - *up to 16 bit long char - *encoded over 3 bytes: - *1110 xxxx 10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 0x0F ; - nb_bytes_2_decode = 3 ; - - } - else if ((*byte_ptr & 0xF8) == 0xF0) - { - /* - *up to 21 bits long char - *encoded over 4 bytes: - *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 0x7 ; - nb_bytes_2_decode = 4 ; - - } - else if ((*byte_ptr & 0xFC) == 0xF8) - { - /* - *up to 26 bits long char - *encoded over 5 bytes. + *unicode char + */ + guint c = 0; + + g_return_val_if_fail (a_in_start && a_in_end && a_len, + CR_BAD_PARAM_ERROR); + *a_len = 0; + + for (byte_ptr = (guchar *) a_in_start; + byte_ptr <= a_in_end; byte_ptr++) { + gint nb_bytes_2_decode = 0; + + if (*byte_ptr <= 0x7F) { + /* + *7 bits long char + *encoded over 1 byte: + * 0xxx xxxx + */ + c = *byte_ptr; + nb_bytes_2_decode = 1; + + } else if ((*byte_ptr & 0xE0) == 0xC0) { + /* + *up to 11 bits long char. + *encoded over 2 bytes: + *110x xxxx 10xx xxxx + */ + c = *byte_ptr & 0x1F; + nb_bytes_2_decode = 2; + + } else if ((*byte_ptr & 0xF0) == 0xE0) { + /* + *up to 16 bit long char + *encoded over 3 bytes: + *1110 xxxx 10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 0x0F; + nb_bytes_2_decode = 3; + + } else if ((*byte_ptr & 0xF8) == 0xF0) { + /* + *up to 21 bits long char + *encoded over 4 bytes: + *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 0x7; + nb_bytes_2_decode = 4; + + } else if ((*byte_ptr & 0xFC) == 0xF8) { + /* + *up to 26 bits long char + *encoded over 5 bytes. *1111 10xx 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 3 ; - nb_bytes_2_decode = 5 ; - - } - else if ((*byte_ptr & 0xFE) == 0xFC) - { - /* - *up to 31 bits long char - *encoded over 6 bytes: - *1111 110x 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx 10xx xxxx - */ - c = *byte_ptr & 1 ; - nb_bytes_2_decode = 6 ; - - } - else - { - /* + *10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 3; + nb_bytes_2_decode = 5; + + } else if ((*byte_ptr & 0xFE) == 0xFC) { + /* + *up to 31 bits long char + *encoded over 6 bytes: + *1111 110x 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx 10xx xxxx + */ + c = *byte_ptr & 1; + nb_bytes_2_decode = 6; + + } else { + /* *BAD ENCODING */ - return CR_ENCODING_ERROR ; - } - - /* - *Go and decode the remaining byte(s) - *(if any) to get the current character. - */ - for ( ; - nb_bytes_2_decode > 1 ; - nb_bytes_2_decode --) - { - /*decode the next byte*/ - byte_ptr ++ ; - - /*byte pattern must be: 10xx xxxx*/ - if ((*byte_ptr & 0xC0) != 0x80) - { - return CR_ENCODING_ERROR ; - } - - c = (c << 6) | (*byte_ptr & 0x3F) ; - } + return CR_ENCODING_ERROR; + } + + /* + *Go and decode the remaining byte(s) + *(if any) to get the current character. + */ + for (; nb_bytes_2_decode > 1; nb_bytes_2_decode--) { + /*decode the next byte */ + byte_ptr++; + + /*byte pattern must be: 10xx xxxx */ + if ((*byte_ptr & 0xC0) != 0x80) { + return CR_ENCODING_ERROR; + } + + c = (c << 6) | (*byte_ptr & 0x3F); + } /* *The decoded ucs4 char is now *in c. */ - if (c <= 0xFF) {/*Add other conditions to support - *other char sets (ucs2, ucs3, ucs4). - */ - len ++ ; - } else { - /*the char is too long to fit - *into the supposed charset len. - */ - return CR_ENCODING_ERROR ; - } - } - - *a_len = len ; - - return CR_OK ; + if (c <= 0xFF) { /*Add other conditions to support + *other char sets (ucs2, ucs3, ucs4). + */ + len++; + } else { + /*the char is too long to fit + *into the supposed charset len. + */ + return CR_ENCODING_ERROR; + } + } + + *a_len = len; + + return CR_OK; } /** @@ -809,30 +712,26 @@ cr_utils_utf8_str_len_as_ucs1 (const guchar *a_in_start, * */ enum CRStatus -cr_utils_utf8_str_to_ucs4 (const guchar * a_in, - gulong *a_in_len, - guint32 **a_out, gulong *a_out_len) +cr_utils_utf8_str_to_ucs4 (const guchar * a_in, + gulong * a_in_len, + guint32 ** a_out, gulong * a_out_len) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_in && a_in_len - && a_out && a_out_len, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_in && a_in_len + && a_out && a_out_len, CR_BAD_PARAM_ERROR); + + status = cr_utils_utf8_str_len_as_ucs4 (a_in, + &a_in[*a_in_len - 1], + a_out_len); - status = - cr_utils_utf8_str_len_as_ucs4 (a_in, - &a_in[*a_in_len - 1], - a_out_len) ; + g_return_val_if_fail (status == CR_OK, status); - g_return_val_if_fail (status == CR_OK, status) ; + *a_out = g_malloc0 (*a_out_len * sizeof (guint32)); - *a_out = g_malloc0 (*a_out_len * sizeof (guint32)) ; - - status = - cr_utils_utf8_to_ucs4 (a_in, a_in_len, - *a_out, a_out_len) ; + status = cr_utils_utf8_to_ucs4 (a_in, a_in_len, *a_out, a_out_len); - return status ; + return status; } /** @@ -851,103 +750,89 @@ cr_utils_utf8_str_to_ucs4 (const guchar * a_in, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_utils_ucs4_to_utf8 (const guint32 *a_in, - gulong *a_in_len, - guchar *a_out, - gulong *a_out_len) +cr_utils_ucs4_to_utf8 (const guint32 * a_in, + gulong * a_in_len, guchar * a_out, gulong * a_out_len) { - gulong in_len = 0, in_index = 0, out_index = 0 ; - enum CRStatus status = CR_OK ; + gulong in_len = 0, + in_index = 0, + out_index = 0; + enum CRStatus status = CR_OK; g_return_val_if_fail (a_in && a_in_len && a_out && a_out_len, - CR_BAD_PARAM_ERROR) ; + CR_BAD_PARAM_ERROR); - if (*a_in_len < 1) - { - status = CR_OK ; - goto end ; + if (*a_in_len < 1) { + status = CR_OK; + goto end; } - in_len = *a_in_len ; + in_len = *a_in_len; - for (in_index = 0 ; - in_index < in_len ; - in_index++) - { + for (in_index = 0; in_index < in_len; in_index++) { /* *FIXME: return whenever we encounter forbidden char values. */ - if (a_in[in_index] <= 0x7F) - { - a_out[out_index] = a_in[in_index] ; - out_index ++ ; - } - else if (a_in[in_index] <= 0x7FF) - { - a_out[out_index] = (0xC0 | (a_in[in_index] >> 6)) ; - a_out[out_index + 1] = (0x80 | (a_in[in_index] & 0x3F)); - out_index += 2 ; - } - else if (a_in[in_index] <= 0xFFFF) - { - a_out[out_index] = (0xE0 | (a_in[in_index] >> 12)) ; - a_out[out_index + 1] = - (0x80 | ((a_in[in_index] >> 6) & 0x3F)) ; - a_out[out_index + 2] = (0x80 | (a_in[in_index] & 0x3F)) ; - out_index += 3 ; - } - else if (a_in[in_index] <= 0x1FFFFF) - { - a_out[out_index] = (0xF0 | (a_in[in_index] >> 18)) ; - a_out[out_index + 1] - = (0x80 | ((a_in[in_index] >> 12) & 0x3F)) ; - a_out[out_index + 2] - = (0x80 | ((a_in[in_index] >> 6) & 0x3F)) ; - a_out[out_index + 3] - = (0x80 | (a_in[in_index] & 0x3F)) ; - out_index += 4 ; - } - else if (a_in[in_index] <= 0x3FFFFFF) - { - a_out[out_index] = (0xF8 | (a_in[in_index] >> 24)) ; - a_out[out_index + 1] = (0x80 | (a_in[in_index] >> 18)) ; - a_out[out_index + 2] - = (0x80 | ((a_in[in_index] >> 12) & 0x3F)) ; - a_out[out_index + 3] - = (0x80 | ((a_in[in_index] >> 6) & 0x3F)) ; - a_out[out_index + 4] - = (0x80 | (a_in[in_index] & 0x3F)) ; - out_index += 5 ; - } - else if (a_in[in_index] <= 0x7FFFFFFF) - { - a_out[out_index] = (0xFC | (a_in[in_index] >> 30)) ; - a_out[out_index + 1] = (0x80 | (a_in[in_index] >> 24)) ; - a_out[out_index + 2] - = (0x80 | ((a_in[in_index] >> 18) & 0x3F)) ; - a_out[out_index + 3] - = (0x80 | ((a_in[in_index] >> 12) & 0x3F)) ; - a_out[out_index + 4] - = (0x80 | ((a_in[in_index] >> 6) & 0x3F)) ; + if (a_in[in_index] <= 0x7F) { + a_out[out_index] = a_in[in_index]; + out_index++; + } else if (a_in[in_index] <= 0x7FF) { + a_out[out_index] = (0xC0 | (a_in[in_index] >> 6)); + a_out[out_index + 1] = + (0x80 | (a_in[in_index] & 0x3F)); + out_index += 2; + } else if (a_in[in_index] <= 0xFFFF) { + a_out[out_index] = (0xE0 | (a_in[in_index] >> 12)); + a_out[out_index + 1] = + (0x80 | ((a_in[in_index] >> 6) & 0x3F)); + a_out[out_index + 2] = + (0x80 | (a_in[in_index] & 0x3F)); + out_index += 3; + } else if (a_in[in_index] <= 0x1FFFFF) { + a_out[out_index] = (0xF0 | (a_in[in_index] >> 18)); + a_out[out_index + 1] + = (0x80 | ((a_in[in_index] >> 12) & 0x3F)); + a_out[out_index + 2] + = (0x80 | ((a_in[in_index] >> 6) & 0x3F)); + a_out[out_index + 3] + = (0x80 | (a_in[in_index] & 0x3F)); + out_index += 4; + } else if (a_in[in_index] <= 0x3FFFFFF) { + a_out[out_index] = (0xF8 | (a_in[in_index] >> 24)); + a_out[out_index + 1] = + (0x80 | (a_in[in_index] >> 18)); + a_out[out_index + 2] + = (0x80 | ((a_in[in_index] >> 12) & 0x3F)); + a_out[out_index + 3] + = (0x80 | ((a_in[in_index] >> 6) & 0x3F)); a_out[out_index + 4] - = (0x80 | (a_in[in_index] & 0x3F)) ; - out_index += 6 ; - } - else - { - status = CR_ENCODING_ERROR ; - goto end ; + = (0x80 | (a_in[in_index] & 0x3F)); + out_index += 5; + } else if (a_in[in_index] <= 0x7FFFFFFF) { + a_out[out_index] = (0xFC | (a_in[in_index] >> 30)); + a_out[out_index + 1] = + (0x80 | (a_in[in_index] >> 24)); + a_out[out_index + 2] + = (0x80 | ((a_in[in_index] >> 18) & 0x3F)); + a_out[out_index + 3] + = (0x80 | ((a_in[in_index] >> 12) & 0x3F)); + a_out[out_index + 4] + = (0x80 | ((a_in[in_index] >> 6) & 0x3F)); + a_out[out_index + 4] + = (0x80 | (a_in[in_index] & 0x3F)); + out_index += 6; + } else { + status = CR_ENCODING_ERROR; + goto end; } - }/*end for*/ - - end: - *a_in_len = in_index + 1 ; - *a_out_len = out_index + 1 ; + } /*end for */ - return status ; -} + end: + *a_in_len = in_index + 1; + *a_out_len = out_index + 1; + return status; +} /** *Converts an ucs4 string into an utf8 string. @@ -962,29 +847,26 @@ cr_utils_ucs4_to_utf8 (const guint32 *a_in, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_utils_ucs4_str_to_utf8 (const guint32 *a_in, - gulong *a_in_len, - guchar **a_out, gulong *a_out_len) -{ - enum CRStatus status = CR_OK ; +cr_utils_ucs4_str_to_utf8 (const guint32 * a_in, + gulong * a_in_len, + guchar ** a_out, gulong * a_out_len) +{ + enum CRStatus status = CR_OK; g_return_val_if_fail (a_in && a_in_len && a_out - && a_out_len, CR_BAD_PARAM_ERROR) ; + && a_out_len, CR_BAD_PARAM_ERROR); - status = - cr_utils_ucs4_str_len_as_utf8 (a_in, - &a_in[*a_out_len -1], - a_out_len) ; + status = cr_utils_ucs4_str_len_as_utf8 (a_in, + &a_in[*a_out_len - 1], + a_out_len); - g_return_val_if_fail (status == CR_OK, status) ; + g_return_val_if_fail (status == CR_OK, status); - status = - cr_utils_ucs4_to_utf8 (a_in, a_in_len, *a_out, a_out_len) ; + status = cr_utils_ucs4_to_utf8 (a_in, a_in_len, *a_out, a_out_len); - return status ; + return status; } - /** *Converts an ucs1 buffer into an utf8 buffer. *The caller must know the size of the resulting buffer and @@ -1006,55 +888,50 @@ cr_utils_ucs4_str_to_utf8 (const guint32 *a_in, * */ enum CRStatus -cr_utils_ucs1_to_utf8 (const guchar *a_in, - gulong *a_in_len, - guchar *a_out, - gulong *a_out_len) +cr_utils_ucs1_to_utf8 (const guchar * a_in, + gulong * a_in_len, guchar * a_out, gulong * a_out_len) { - gulong out_index = 0, in_index = 0, in_len = 0, out_len = 0 ; - enum CRStatus status = CR_OK ; + gulong out_index = 0, + in_index = 0, + in_len = 0, + out_len = 0; + enum CRStatus status = CR_OK; g_return_val_if_fail (a_in && a_in_len && a_out - && a_out_len, CR_BAD_PARAM_ERROR) ; + && a_out_len, CR_BAD_PARAM_ERROR); - if (*a_in_len < 1) - { - status = CR_OK ; - goto end ; + if (*a_in_len < 1) { + status = CR_OK; + goto end; } - in_len = *a_in_len ; - out_len = *a_out_len ; + in_len = *a_in_len; + out_len = *a_out_len; - for (in_index = 0, out_index = 0 ; - (in_index < in_len) && (out_index < out_len) ; - in_index ++) - { + for (in_index = 0, out_index = 0; + (in_index < in_len) && (out_index < out_len); in_index++) { /* *FIXME: return whenever we encounter forbidden char values. */ - if (a_in[in_index] <= 0x7F) - { - a_out[out_index] = a_in[in_index] ; - out_index ++ ; - } - else - { - a_out[out_index] = (0xC0 | (a_in[in_index] >> 6)) ; - a_out[out_index + 1] = (0x80 | (a_in[in_index] & 0x3F)); - out_index += 2 ; + if (a_in[in_index] <= 0x7F) { + a_out[out_index] = a_in[in_index]; + out_index++; + } else { + a_out[out_index] = (0xC0 | (a_in[in_index] >> 6)); + a_out[out_index + 1] = + (0x80 | (a_in[in_index] & 0x3F)); + out_index += 2; } - }/*end for*/ + } /*end for */ - end: - *a_in_len = in_index ; - *a_out_len = out_index ; + end: + *a_in_len = in_index; + *a_out_len = out_index; - return CR_OK ; + return CR_OK; } - /** *Converts an ucs1 string into an utf8 string. *@param a_in_start the beginning of the input string to convert. @@ -1065,43 +942,39 @@ cr_utils_ucs1_to_utf8 (const guchar *a_in, * */ enum CRStatus -cr_utils_ucs1_str_to_utf8 (const guchar *a_in, - gulong *a_in_len, - guchar **a_out, - gulong *a_out_len) +cr_utils_ucs1_str_to_utf8 (const guchar * a_in, + gulong * a_in_len, + guchar ** a_out, gulong * a_out_len) { - gulong in_len = 0, out_len = 0 ; - enum CRStatus status = CR_OK ; + gulong in_len = 0, + out_len = 0; + enum CRStatus status = CR_OK; g_return_val_if_fail (a_in && a_in_len && a_out - && a_out_len, CR_BAD_PARAM_ERROR) ; - - if (*a_in_len < 1) - { - *a_out_len = 0 ; - *a_out = NULL ; - return CR_OK ; + && a_out_len, CR_BAD_PARAM_ERROR); + + if (*a_in_len < 1) { + *a_out_len = 0; + *a_out = NULL; + return CR_OK; } - status = - cr_utils_ucs1_str_len_as_utf8 (a_in, &a_in[*a_in_len -1], - &out_len) ; + status = cr_utils_ucs1_str_len_as_utf8 (a_in, &a_in[*a_in_len - 1], + &out_len); - g_return_val_if_fail (status == CR_OK, status) ; + g_return_val_if_fail (status == CR_OK, status); - in_len = *a_in_len ; + in_len = *a_in_len; - *a_out = g_malloc0 (out_len) ; + *a_out = g_malloc0 (out_len); - status = cr_utils_ucs1_to_utf8 (a_in, a_in_len, - *a_out, &out_len) ; + status = cr_utils_ucs1_to_utf8 (a_in, a_in_len, *a_out, &out_len); - *a_out_len = out_len ; + *a_out_len = out_len; - return status ; + return status; } - /** *Converts an utf8 buffer into an ucs1 buffer. *The caller must know the size of the resulting @@ -1126,163 +999,141 @@ cr_utils_ucs1_str_to_utf8 (const guchar *a_in, *@return CR_OK upon successfull completion, an error code otherwise. */ enum CRStatus -cr_utils_utf8_to_ucs1 (const guchar * a_in, - gulong * a_in_len, - guchar *a_out, - gulong *a_out_len) +cr_utils_utf8_to_ucs1 (const guchar * a_in, + gulong * a_in_len, guchar * a_out, gulong * a_out_len) { - gulong in_index = 0, out_index = 0, in_len = 0, out_len = 0 ; - enum CRStatus status = CR_OK ; + gulong in_index = 0, + out_index = 0, + in_len = 0, + out_len = 0; + enum CRStatus status = CR_OK; - /* + /* *to store the final decoded - *unicode char - */ - guint32 c = 0 ; + *unicode char + */ + guint32 c = 0; g_return_val_if_fail (a_in && a_in_len - && a_out && a_out_len, - CR_BAD_PARAM_ERROR) ; + && a_out && a_out_len, CR_BAD_PARAM_ERROR); - if (*a_in_len < 1) - { - status = CR_OK ; - goto end ; + if (*a_in_len < 1) { + status = CR_OK; + goto end; } - in_len = *a_in_len ; - out_len = *a_out_len ; - - for (in_index = 0 , out_index = 0 ; - (in_index < in_len) && (out_index < out_len) ; - in_index ++, out_index++) - { - gint nb_bytes_2_decode = 0 ; - - if (a_in[in_index] <= 0x7F) - { - /* - *7 bits long char - *encoded over 1 byte: - * 0xxx xxxx - */ - c = a_in[in_index] ; - nb_bytes_2_decode = 1 ; - - } - else if ((a_in[in_index] & 0xE0) == 0xC0) - { - /* - *up to 11 bits long char. - *encoded over 2 bytes: - *110x xxxx 10xx xxxx - */ - c = a_in[in_index] & 0x1F ; - nb_bytes_2_decode = 2 ; - - } - else if ((a_in[in_index] & 0xF0) == 0xE0) - { - /* - *up to 16 bit long char - *encoded over 3 bytes: - *1110 xxxx 10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 0x0F ; - nb_bytes_2_decode = 3 ; - - } - else if ((a_in[in_index] & 0xF8) == 0xF0) - { - /* - *up to 21 bits long char - *encoded over 4 bytes: - *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 0x7 ; - nb_bytes_2_decode = 4 ; - - } - else if ((a_in[in_index] & 0xFC) == 0xF8) - { - /* - *up to 26 bits long char - *encoded over 5 bytes. - *1111 10xx 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 3 ; - nb_bytes_2_decode = 5 ; - - } - else if ((a_in[in_index] & 0xFE) == 0xFC) - { - /* - *up to 31 bits long char - *encoded over 6 bytes: - *1111 110x 10xx xxxx 10xx xxxx - *10xx xxxx 10xx xxxx 10xx xxxx - */ - c = a_in[in_index] & 1 ; - nb_bytes_2_decode = 6 ; - - } - else - { - /*BAD ENCODING*/ - status = CR_ENCODING_ERROR ; - goto end ; - } - - /* - *Go and decode the remaining byte(s) - *(if any) to get the current character. - */ - if (in_index + nb_bytes_2_decode - 1 >= in_len) - { - status = CR_OK ; - goto end ; + in_len = *a_in_len; + out_len = *a_out_len; + + for (in_index = 0, out_index = 0; + (in_index < in_len) && (out_index < out_len); + in_index++, out_index++) { + gint nb_bytes_2_decode = 0; + + if (a_in[in_index] <= 0x7F) { + /* + *7 bits long char + *encoded over 1 byte: + * 0xxx xxxx + */ + c = a_in[in_index]; + nb_bytes_2_decode = 1; + + } else if ((a_in[in_index] & 0xE0) == 0xC0) { + /* + *up to 11 bits long char. + *encoded over 2 bytes: + *110x xxxx 10xx xxxx + */ + c = a_in[in_index] & 0x1F; + nb_bytes_2_decode = 2; + + } else if ((a_in[in_index] & 0xF0) == 0xE0) { + /* + *up to 16 bit long char + *encoded over 3 bytes: + *1110 xxxx 10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 0x0F; + nb_bytes_2_decode = 3; + + } else if ((a_in[in_index] & 0xF8) == 0xF0) { + /* + *up to 21 bits long char + *encoded over 4 bytes: + *1111 0xxx 10xx xxxx 10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 0x7; + nb_bytes_2_decode = 4; + + } else if ((a_in[in_index] & 0xFC) == 0xF8) { + /* + *up to 26 bits long char + *encoded over 5 bytes. + *1111 10xx 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 3; + nb_bytes_2_decode = 5; + + } else if ((a_in[in_index] & 0xFE) == 0xFC) { + /* + *up to 31 bits long char + *encoded over 6 bytes: + *1111 110x 10xx xxxx 10xx xxxx + *10xx xxxx 10xx xxxx 10xx xxxx + */ + c = a_in[in_index] & 1; + nb_bytes_2_decode = 6; + + } else { + /*BAD ENCODING */ + status = CR_ENCODING_ERROR; + goto end; + } + + /* + *Go and decode the remaining byte(s) + *(if any) to get the current character. + */ + if (in_index + nb_bytes_2_decode - 1 >= in_len) { + status = CR_OK; + goto end; } - for ( ; - nb_bytes_2_decode > 1 ; - nb_bytes_2_decode --) - { - /*decode the next byte*/ - in_index ++ ; - - /*byte pattern must be: 10xx xxxx*/ - if ((a_in[in_index] & 0xC0) != 0x80) - { - status = CR_ENCODING_ERROR ; - goto end ; - } - - c = (c << 6) | (a_in[in_index] & 0x3F) ; - } + for (; nb_bytes_2_decode > 1; nb_bytes_2_decode--) { + /*decode the next byte */ + in_index++; + + /*byte pattern must be: 10xx xxxx */ + if ((a_in[in_index] & 0xC0) != 0x80) { + status = CR_ENCODING_ERROR; + goto end; + } + + c = (c << 6) | (a_in[in_index] & 0x3F); + } /* *The decoded ucs4 char is now *in c. */ - if (c > 0xFF) - { - status = CR_ENCODING_ERROR ; - goto end ; + if (c > 0xFF) { + status = CR_ENCODING_ERROR; + goto end; } - - a_out[out_index] = c ; + + a_out[out_index] = c; } - end: - *a_out_len = out_index ; - *a_in_len = in_index ; + end: + *a_out_len = out_index; + *a_in_len = in_index; - return CR_OK ; + return CR_OK; } - /** *Converts an utf8 buffer into an *ucs1 buffer. @@ -1296,44 +1147,36 @@ cr_utils_utf8_to_ucs1 (const guchar * a_in, *returns CR_OK. */ enum CRStatus -cr_utils_utf8_str_to_ucs1 (const guchar * a_in, +cr_utils_utf8_str_to_ucs1 (const guchar * a_in, gulong * a_in_len, - guchar **a_out, - gulong *a_out_len) + guchar ** a_out, gulong * a_out_len) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - g_return_val_if_fail (a_in && a_in_len - && a_out && a_out_len, - CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_in && a_in_len + && a_out && a_out_len, CR_BAD_PARAM_ERROR); - if (*a_in_len < 1) - { - *a_out_len = 0 ; - *a_out = NULL ; - return CR_OK ; + if (*a_in_len < 1) { + *a_out_len = 0; + *a_out = NULL; + return CR_OK; } - status = - cr_utils_utf8_str_len_as_ucs4 (a_in, &a_in[*a_in_len - 1], - a_out_len) ; + status = cr_utils_utf8_str_len_as_ucs4 (a_in, &a_in[*a_in_len - 1], + a_out_len); - g_return_val_if_fail (status == CR_OK, status) ; + g_return_val_if_fail (status == CR_OK, status); - *a_out = g_malloc0 (*a_out_len * sizeof (guint32)) ; + *a_out = g_malloc0 (*a_out_len * sizeof (guint32)); - status = - cr_utils_utf8_to_ucs1 (a_in, a_in_len, - *a_out, a_out_len) ; - return status ; + status = cr_utils_utf8_to_ucs1 (a_in, a_in_len, *a_out, a_out_len); + return status; } - /***************************************** *CSS basic types identification utilities *****************************************/ - /** *Returns TRUE if a_char is a white space as *defined in the css spec in chap 4.1.1. @@ -1346,17 +1189,16 @@ cr_utils_utf8_str_to_ucs1 (const guchar * a_in, gboolean cr_utils_is_white_space (guint32 a_char) { - switch (a_char) - { - case ' ': - case '\t': + switch (a_char) { + case ' ': + case '\t': case '\r': - case '\n': + case '\n': case '\f': - return TRUE ; - break ; + return TRUE; + break; default: - return FALSE ; + return FALSE; } } @@ -1372,15 +1214,14 @@ cr_utils_is_white_space (guint32 a_char) gboolean cr_utils_is_newline (guint32 a_char) { - switch (a_char) - { + switch (a_char) { case '\n': case '\r': case '\f': - return TRUE ; + return TRUE; break; default: - return FALSE ; + return FALSE; } } @@ -1392,11 +1233,10 @@ gboolean cr_utils_is_hexa_char (guint32 a_char) { if ((a_char >= '0' && a_char <= '9') - || (a_char >= 'A' && a_char <= 'F')) - { - return TRUE ; + || (a_char >= 'A' && a_char <= 'F')) { + return TRUE; } - return FALSE ; + return FALSE; } /** @@ -1412,12 +1252,11 @@ cr_utils_is_hexa_char (guint32 a_char) gboolean cr_utils_is_nonascii (guint32 a_char) { - if (a_char <= 177) - { - return FALSE ; + if (a_char <= 177) { + return FALSE; } - return TRUE ; + return TRUE; } /** @@ -1427,42 +1266,37 @@ cr_utils_is_nonascii (guint32 a_char) *@param a_nb the number of times a_char is to be dumped. */ void -cr_utils_dump_n_chars (guchar a_char, FILE *a_fp, glong a_nb) +cr_utils_dump_n_chars (guchar a_char, FILE * a_fp, glong a_nb) { - glong i = 0 ; + glong i = 0; - for (i = 0 ; i < a_nb ; i++) - { - fprintf (a_fp, "%c", a_char) ; + for (i = 0; i < a_nb; i++) { + fprintf (a_fp, "%c", a_char); } } void -cr_utils_dump_n_chars2 (guchar a_char, - GString *a_string, - glong a_nb) +cr_utils_dump_n_chars2 (guchar a_char, GString * a_string, glong a_nb) { - glong i = 0 ; + glong i = 0; - g_return_if_fail (a_string) ; + g_return_if_fail (a_string); - for (i = 0 ; i < a_nb ; i++) - { - g_string_append_printf (a_string, "%c", a_char) ; + for (i = 0; i < a_nb; i++) { + g_string_append_printf (a_string, "%c", a_char); } } gdouble cr_utils_n_to_0_dot_n (glong a_n) { - gdouble result = a_n ; + gdouble result = a_n; - while (ABS (result) > 1) - { - result = result / 10 ; + while (ABS (result) > 1) { + result = result / 10; } - return result ; + return result; } /** @@ -1472,21 +1306,21 @@ cr_utils_n_to_0_dot_n (glong a_n) *@param a_list_of_strings the list of strings to be duplicated. */ GList * -cr_dup_glist_of_string (GList *a_list_of_strings) +cr_dup_glist_of_string (GList * a_list_of_strings) { - GList *cur = NULL, *result = NULL ; + GList *cur = NULL, + *result = NULL; + + g_return_val_if_fail (a_list_of_strings, NULL); - g_return_val_if_fail (a_list_of_strings, NULL) ; + for (cur = a_list_of_strings; cur; cur = cur->next) { + GString *str = NULL; - for (cur = a_list_of_strings ; cur ; cur = cur->next) - { - GString *str = NULL ; - - str = g_string_new_len (((GString *)cur->data)->str, - ((GString *)cur->data)->len) ; + str = g_string_new_len (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (str) - result = g_list_append (result, str) ; + result = g_list_append (result, str); } - return result ; + return result; } diff --git a/tests/cr-test-utils.c b/tests/cr-test-utils.c index e03955e..9435ef7 100644 --- a/tests/cr-test-utils.c +++ b/tests/cr-test-utils.c @@ -29,35 +29,31 @@ */ void cr_test_utils_parse_cmd_line (int a_argc, char **a_argv, - struct Options *a_options) + struct Options *a_options) { - int i= 0 ; - - g_return_if_fail (a_options) ; + int i = 0; - memset (a_options, 0, sizeof (struct Options)) ; + g_return_if_fail (a_options); - for (i = 1 ; i < a_argc ; i++) - { - if (a_argv[i][0] != '-') break ; + memset (a_options, 0, sizeof (struct Options)); - if (!strcmp (a_argv[i], "-h") || !strcmp (a_argv[i], "--help")) - { - a_options->display_help = TRUE ; + for (i = 1; i < a_argc; i++) { + if (a_argv[i][0] != '-') + break; + + if (!strcmp (a_argv[i], "-h") + || !strcmp (a_argv[i], "--help")) { + a_options->display_help = TRUE; } - if (!strcmp (a_argv[i], "--about")) - { - a_options->display_about = TRUE ; + if (!strcmp (a_argv[i], "--about")) { + a_options->display_about = TRUE; } - } + } - if (i >= a_argc) - { - /*No file parameter where given*/ - a_options->files_list = NULL ; + if (i >= a_argc) { + /*No file parameter where given */ + a_options->files_list = NULL; + } else { + a_options->files_list = &a_argv[i]; } - else - { - a_options->files_list = &a_argv[i] ; - } } diff --git a/tests/test0-main.c b/tests/test0-main.c index ac1a55e..a991abf 100644 --- a/tests/test0-main.c +++ b/tests/test0-main.c @@ -39,25 +39,23 @@ *during the parsing the command line by the *parse_command_line() function. */ -struct Options -{ - gboolean display_help ; - gboolean display_about ; - gchar ** files_list ; +struct Options { + gboolean display_help; + gboolean display_about; + gchar **files_list; }; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) ; + parse_command_line (int a_argc, char **a_argv, struct Options *a_options); static enum CRStatus -test_cr_input_read_byte (guchar * a_file_uri) ; + test_cr_input_read_byte (guchar * a_file_uri); /** *Displays the usage of the test @@ -65,15 +63,15 @@ test_cr_input_read_byte (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s \n", prg_name) ; - g_print ("\t : the file to parse\n") ; - g_print ("\n\n") ; - g_print ("This test just reads the file byte per byte\nand sends each byte to stdout\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s \n", prg_name); + g_print ("\t : the file to parse\n"); + g_print ("\n\n"); + g_print ("This test just reads the file byte per byte\nand sends each byte to stdout\n"); + g_print ("\n\n"); } /** @@ -81,15 +79,15 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CRInput class test program.\n", prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli .\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CRInput class test program.\n", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli .\n"); + g_print ("\n\n"); } /** @@ -99,41 +97,35 @@ display_about (char *prg_name) *@param a_options out parameter. The abstraction of the parsed the options. */ static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) +parse_command_line (int a_argc, char **a_argv, struct Options *a_options) { - int i= 0 ; - - g_return_if_fail (a_options) ; + int i = 0; + + g_return_if_fail (a_options); - memset (a_options, 0, sizeof (struct Options)) ; + memset (a_options, 0, sizeof (struct Options)); - for (i = 1 ; i < a_argc ; i++) - { - if (a_argv[i][0] != '-') break ; + for (i = 1; i < a_argc; i++) { + if (a_argv[i][0] != '-') + break; - if (!strcmp (a_argv[i], "-h") || !strcmp (a_argv[i], "--help")) - { - a_options->display_help = TRUE ; + if (!strcmp (a_argv[i], "-h") + || !strcmp (a_argv[i], "--help")) { + a_options->display_help = TRUE; } - if (!strcmp (a_argv[i], "--about")) - { - a_options->display_about = TRUE ; + if (!strcmp (a_argv[i], "--about")) { + a_options->display_about = TRUE; } - } + } - if (i >= a_argc) - { - /*No file parameter where given*/ - a_options->files_list = NULL ; + if (i >= a_argc) { + /*No file parameter where given */ + a_options->files_list = NULL; + } else { + a_options->files_list = &a_argv[i]; } - else - { - a_options->files_list = &a_argv[i] ; - } } - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -146,78 +138,66 @@ parse_command_line (int a_argc, char **a_argv, static enum CRStatus test_cr_input_read_byte (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRInput * input = NULL ; - guchar byte = 0 ; - guint c = 0 ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - input = - cr_input_new_from_uri (a_file_uri, CR_UTF_8) ; - - if (!input) - { - cr_utils_trace_debug ("Input Stream creation failed.") ; - return CR_ERROR ; - } + enum CRStatus status = CR_OK; + CRInput *input = NULL; + guchar byte = 0; + guint c = 0; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); - for (status = CR_OK; - status == CR_OK ;) - { - status = cr_input_read_byte (input, &byte) ; - - if (status == CR_OK) - { - c = byte ; - printf ("%d", c) ; - fflush (stdout) ; - } + input = cr_input_new_from_uri (a_file_uri, CR_UTF_8); + + if (!input) { + cr_utils_trace_debug ("Input Stream creation failed."); + return CR_ERROR; } - + for (status = CR_OK; status == CR_OK;) { + status = cr_input_read_byte (input, &byte); - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; + if (status == CR_OK) { + c = byte; + printf ("%d", c); + fflush (stdout); + } } - cr_input_destroy (input) ; - input = NULL ; + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; + } - return status ; -} + cr_input_destroy (input); + input = NULL; + return status; +} /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; + struct Options options; - parse_command_line (argc, argv, &options) ; + parse_command_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - test_cr_input_read_byte (options.files_list[0]) ; + test_cr_input_read_byte (options.files_list[0]); - return 0 ; + return 0; } diff --git a/tests/test1-main.c b/tests/test1-main.c index 893b5d5..019e6dc 100644 --- a/tests/test1-main.c +++ b/tests/test1-main.c @@ -39,27 +39,23 @@ *during the parsing the command line by the *parse_command_line() function. */ -struct Options -{ - gboolean display_help ; - gboolean display_about ; - gchar ** files_list ; +struct Options { + gboolean display_help; + gboolean display_about; + gchar **files_list; }; +static void + display_help (char *prg_name); -static void -display_help (char *prg_name) ; - -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) ; + parse_command_line (int a_argc, char **a_argv, struct Options *a_options); static enum CRStatus -test_cr_input_read_char (guchar * a_file_uri) ; - + test_cr_input_read_char (guchar * a_file_uri); /** *Displays the usage of the test @@ -67,15 +63,15 @@ test_cr_input_read_char (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s \n", prg_name) ; - g_print ("\t : the file to parse\n") ; - g_print ("\n\n") ; - g_print ("This test just reads the file character per character\nand sends each character to stdout\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s \n", prg_name); + g_print ("\t : the file to parse\n"); + g_print ("\n\n"); + g_print ("This test just reads the file character per character\nand sends each character to stdout\n"); + g_print ("\n\n"); } /** @@ -83,15 +79,15 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CRInput class test program.\n", prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli .\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CRInput class test program.\n", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli .\n"); + g_print ("\n\n"); } /** @@ -101,41 +97,35 @@ display_about (char *prg_name) *@param a_options out parameter. The abstraction of the parsed the options. */ static void -parse_command_line (int a_argc, char **a_argv, - struct Options *a_options) +parse_command_line (int a_argc, char **a_argv, struct Options *a_options) { - int i= 0 ; - - g_return_if_fail (a_options) ; + int i = 0; + + g_return_if_fail (a_options); - memset (a_options, 0, sizeof (struct Options)) ; + memset (a_options, 0, sizeof (struct Options)); - for (i = 1 ; i < a_argc ; i++) - { - if (a_argv[i][0] != '-') break ; + for (i = 1; i < a_argc; i++) { + if (a_argv[i][0] != '-') + break; - if (!strcmp (a_argv[i], "-h") || !strcmp (a_argv[i], "--help")) - { - a_options->display_help = TRUE ; + if (!strcmp (a_argv[i], "-h") + || !strcmp (a_argv[i], "--help")) { + a_options->display_help = TRUE; } - if (!strcmp (a_argv[i], "--about")) - { - a_options->display_about = TRUE ; + if (!strcmp (a_argv[i], "--about")) { + a_options->display_about = TRUE; } - } + } - if (i >= a_argc) - { - /*No file parameter where given*/ - a_options->files_list = NULL ; + if (i >= a_argc) { + /*No file parameter where given */ + a_options->files_list = NULL; + } else { + a_options->files_list = &a_argv[i]; } - else - { - a_options->files_list = &a_argv[i] ; - } } - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -148,74 +138,64 @@ parse_command_line (int a_argc, char **a_argv, enum CRStatus test_cr_input_read_char (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRInput * input = NULL ; - guint32 c = 0 ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - input = - cr_input_new_from_uri (a_file_uri, CR_UTF_8) ; - - if (!input) - { - cr_utils_trace_debug ("Input Stream creation failed.") ; - return CR_ERROR ; + enum CRStatus status = CR_OK; + CRInput *input = NULL; + guint32 c = 0; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); + + input = cr_input_new_from_uri (a_file_uri, CR_UTF_8); + + if (!input) { + cr_utils_trace_debug ("Input Stream creation failed."); + return CR_ERROR; } - for (status = CR_OK; - status == CR_OK ;) - { - status = cr_input_read_char (input, &c) ; + for (status = CR_OK; status == CR_OK;) { + status = cr_input_read_char (input, &c); - if (status == CR_OK) - { - printf ("%c", c) ; - fflush (stdout) ; + if (status == CR_OK) { + printf ("%c", c); + fflush (stdout); } - } + } - if (status == CR_END_OF_INPUT_ERROR) - { - status = CR_OK ; + if (status == CR_END_OF_INPUT_ERROR) { + status = CR_OK; } - cr_input_destroy (input) ; - input = NULL ; + cr_input_destroy (input); + input = NULL; - return status ; + return status; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; + struct Options options; - parse_command_line (argc, argv, &options) ; + parse_command_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - test_cr_input_read_char (options.files_list[0]) ; + test_cr_input_read_char (options.files_list[0]); - return 0 ; + return 0; } diff --git a/tests/test2-main.c b/tests/test2-main.c index b27967e..d64071c 100644 --- a/tests/test2-main.c +++ b/tests/test2-main.c @@ -31,22 +31,21 @@ #include "cr-test-utils.h" #include "cr-parser.h" - /** *@file *Some test facilities for the #CRParser class. */ -CRDocHandler * gv_test_handler = {0} ; +CRDocHandler *gv_test_handler = { 0 }; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static enum CRStatus -test_cr_parser_parse (guchar * a_file_uri) ; + test_cr_parser_parse (guchar * a_file_uri); /** *Displays the usage of the test @@ -54,16 +53,16 @@ test_cr_parser_parse (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"usage: %s \n", prg_name) ; - fprintf (stdout,"\t : the file to parse\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Tests the cr_parser_parse () method.\n") ; - fprintf (stdout,"Returns OK if the status is CR_OK, KO otherwise\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "usage: %s \n", prg_name); + fprintf (stdout, "\t : the file to parse\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, "Tests the cr_parser_parse () method.\n"); + fprintf (stdout, "Returns OK if the status is CR_OK, KO otherwise\n"); + fprintf (stdout, "\n\n"); } /** @@ -71,492 +70,437 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"%s is a libcroco CRParser class test program.\n", prg_name) ; - fprintf (stdout,"It should run on GNU compliants systems.\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Initial author: Dodji Seketeli .\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "%s is a libcroco CRParser class test program.\n", + prg_name); + fprintf (stdout, "It should run on GNU compliants systems.\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, + "Initial author: Dodji Seketeli .\n"); + fprintf (stdout, "\n\n"); } - /*************************** *Some SAC document handlers *for TEST PURPOSES. ***************************/ static void -test_start_document (CRDocHandler *a_handler) +test_start_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_end_document (CRDocHandler *a_handler) +test_end_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_import_style (CRDocHandler *a_handler, - GList *a_media_list, GString *a_uri, - GString *a_uri_default_ns) +test_import_style (CRDocHandler * a_handler, + GList * a_media_list, GString * a_uri, + GString * a_uri_default_ns) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"****************\n") ; - fprintf (stdout,"import_style\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - - fprintf (stdout,"\nmedia list:\n") ; - fprintf (stdout,"-------------\n") ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data) - { - guchar *str = - g_strndup - (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; - - if (str) - { - fprintf (stdout,str) ; - fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"\ndefault namespace:\n") ; - fprintf (stdout,"--------------------\n") ; - - if (a_uri_default_ns && a_uri_default_ns->str) - { - guchar * str = - g_strndup (a_uri_default_ns->str, - a_uri_default_ns->len) ; - if (str) - { - fprintf (stdout,str) ; - fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"******************\n\n") ; - a_uri = NULL; /*keep compiler happy*/ -} + g_return_if_fail (a_handler); + + fprintf (stdout, "****************\n"); + fprintf (stdout, "import_style\n"); + + if (a_media_list) { + GList *cur = NULL; + + fprintf (stdout, "\nmedia list:\n"); + fprintf (stdout, "-------------\n"); + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data) { + guchar *str = + g_strndup + (((GString *) cur->data)->str, + ((GString *) cur->data)->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + fprintf (stdout, "\ndefault namespace:\n"); + fprintf (stdout, "--------------------\n"); + + if (a_uri_default_ns && a_uri_default_ns->str) { + guchar *str = g_strndup (a_uri_default_ns->str, + a_uri_default_ns->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + + fprintf (stdout, "******************\n\n"); + a_uri = NULL; /*keep compiler happy */ +} static void -test_namespace_declaration (CRDocHandler *a_handler, - GString *a_prefix, - GString *a_uri) +test_namespace_declaration (CRDocHandler * a_handler, + GString * a_prefix, GString * a_uri) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"namespace_declaration:\n") ; - - if (a_prefix && a_prefix->str) - { - guchar * prefix = NULL ; - - prefix = g_strndup (a_prefix->str, a_prefix->len) ; - - if (prefix) - { - fprintf (stdout,"prefix: %s\n", prefix) ; - g_free (prefix) ; - prefix = NULL ; - } - } - - if (a_uri && a_uri->str) - { - guchar *uri = NULL ; - - uri = g_strndup (a_uri->str, a_uri->len) ; - - if (uri) - { - fprintf (stdout,"uri: %s\n", uri) ; - g_free (uri) ; - uri = NULL ; - } - } - fprintf (stdout,"\n") ; - - fprintf (stdout,"***************\n\n") ; - - -} + g_return_if_fail (a_handler); + fprintf (stdout, "***************\n"); + fprintf (stdout, "namespace_declaration:\n"); + + if (a_prefix && a_prefix->str) { + guchar *prefix = NULL; + + prefix = g_strndup (a_prefix->str, a_prefix->len); + + if (prefix) { + fprintf (stdout, "prefix: %s\n", prefix); + g_free (prefix); + prefix = NULL; + } + } + + if (a_uri && a_uri->str) { + guchar *uri = NULL; + + uri = g_strndup (a_uri->str, a_uri->len); + + if (uri) { + fprintf (stdout, "uri: %s\n", uri); + g_free (uri); + uri = NULL; + } + } + fprintf (stdout, "\n"); + + fprintf (stdout, "***************\n\n"); + +} static void -test_comment (CRDocHandler *a_handler, - GString *a_comment) +test_comment (CRDocHandler * a_handler, GString * a_comment) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"comment:\n") ; - - if (a_comment && a_comment->str) - { - guchar *comment = NULL ; - - comment = g_strndup (a_comment->str, a_comment->len) ; - - if (comment) - { - fprintf (stdout,"\n/*----------------------\n") ; - fprintf (stdout,"%s\n", comment) ; - fprintf (stdout,"-------------------------*/\n") ; - - g_free (comment) ; - comment = NULL ; - } - } - - fprintf (stdout,"***************\n\n") ; -} + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "comment:\n"); + if (a_comment && a_comment->str) { + guchar *comment = NULL; + comment = g_strndup (a_comment->str, a_comment->len); + + if (comment) { + fprintf (stdout, "\n/*----------------------\n"); + fprintf (stdout, "%s\n", comment); + fprintf (stdout, "-------------------------*/\n"); + + g_free (comment); + comment = NULL; + } + } + + fprintf (stdout, "***************\n\n"); +} static void -test_start_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_start_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_selector\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_selector\n"); - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout, "\n") ; + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_end_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_selector\n") ; - - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout,"\n") ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_selector\n"); + + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_property (CRDocHandler *a_handler, GString *a_name, - CRTerm *a_expr, gboolean a_important) +test_property (CRDocHandler * a_handler, GString * a_name, + CRTerm * a_expr, gboolean a_important) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"property\n") ; - - if (a_name && a_name->str) - { - guchar *name = g_strndup (a_name->str, a_name->len) ; - - if (name) - { - fprintf (stdout,name) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "property\n"); + + if (a_name && a_name->str) { + guchar *name = g_strndup (a_name->str, a_name->len); + + if (name) { + fprintf (stdout, name); } - - if (a_expr) - { - fprintf (stdout,": ") ; - cr_term_dump (a_expr, stdout) ; + + if (a_expr) { + fprintf (stdout, ": "); + cr_term_dump (a_expr, stdout); } - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - - fprintf (stdout,"\n") ; + + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_start_font_face (CRDocHandler *a_handler) +test_start_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_font_face\n"); + fprintf (stdout, "***************\n\n"); } - static void -test_end_font_face (CRDocHandler *a_handler) +test_end_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_font_face\n"); + fprintf (stdout, "***************\n\n"); } static void -test_start_media (CRDocHandler *a_handler, - GList *a_media_list) +test_start_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_media (CRDocHandler *a_handler, - GList *a_media_list) +test_end_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } static void -test_start_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_start_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; + + g_return_if_fail (a_handler); - g_return_if_fail (a_handler) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_page\n"); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } static void -test_end_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_end_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_page\n"); + + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; - + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); + } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } - static void -test_ignorable_at_rule (CRDocHandler *a_handler, - GString *a_name) +test_ignorable_at_rule (CRDocHandler * a_handler, GString * a_name) { - guchar *name = NULL ; + guchar *name = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"*********************\n") ; - fprintf (stdout,"ignorable_at_rule\n") ; + fprintf (stdout, "*********************\n"); + fprintf (stdout, "ignorable_at_rule\n"); - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (name) - { - fprintf (stdout,"%s\n", name) ; + if (name) { + fprintf (stdout, "%s\n", name); } - fprintf (stdout,"*********************\n\n") ; + fprintf (stdout, "*********************\n\n"); } - static void -init_test_sac_handler (CRDocHandler *a_handler) - +init_test_sac_handler (CRDocHandler * a_handler) { - a_handler->start_document = test_start_document ; - a_handler->end_document = test_end_document ; - a_handler->import_style = test_import_style ; - a_handler->namespace_declaration = test_namespace_declaration ; - a_handler->comment = test_comment ; - a_handler->start_selector = test_start_selector ; - a_handler->end_selector = test_end_selector ; - a_handler->property = test_property ; - a_handler->start_font_face = test_start_font_face ; - a_handler->end_font_face = test_end_font_face ; - a_handler->start_media = test_start_media ; - a_handler->end_media = test_end_media ; - a_handler->start_page = test_start_page ; - a_handler->end_page = test_end_page ; - a_handler->ignorable_at_rule = test_ignorable_at_rule ; + a_handler->start_document = test_start_document; + a_handler->end_document = test_end_document; + a_handler->import_style = test_import_style; + a_handler->namespace_declaration = test_namespace_declaration; + a_handler->comment = test_comment; + a_handler->start_selector = test_start_selector; + a_handler->end_selector = test_end_selector; + a_handler->property = test_property; + a_handler->start_font_face = test_start_font_face; + a_handler->end_font_face = test_end_font_face; + a_handler->start_media = test_start_media; + a_handler->end_media = test_end_media; + a_handler->start_page = test_start_page; + a_handler->end_page = test_end_page; + a_handler->ignorable_at_rule = test_ignorable_at_rule; } /*************************** @@ -564,7 +508,6 @@ init_test_sac_handler (CRDocHandler *a_handler) *handlers. ***************************/ - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -577,69 +520,63 @@ init_test_sac_handler (CRDocHandler *a_handler) static enum CRStatus test_cr_parser_parse (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRParser *parser = NULL ; + enum CRStatus status = CR_OK; + CRParser *parser = NULL; - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); - gv_test_handler = cr_doc_handler_new () ; - init_test_sac_handler (gv_test_handler) ; + gv_test_handler = cr_doc_handler_new (); + init_test_sac_handler (gv_test_handler); - parser = cr_parser_new (NULL) ; + parser = cr_parser_new (NULL); - status = cr_parser_set_sac_handler (parser, gv_test_handler) ; - - if (status != CR_OK) - { - cr_parser_destroy (parser) ; - g_return_val_if_fail (status == CR_OK, CR_ERROR) ; + status = cr_parser_set_sac_handler (parser, gv_test_handler); + + if (status != CR_OK) { + cr_parser_destroy (parser); + g_return_val_if_fail (status == CR_OK, CR_ERROR); } - status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII) ; + status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII); - cr_parser_destroy (parser) ; + cr_parser_destroy (parser); - gv_test_handler = NULL ; + gv_test_handler = NULL; - return status ; + return status; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - status = test_cr_parser_parse (options.files_list[0]) ; + status = test_cr_parser_parse (options.files_list[0]); - if (status != CR_OK) - { - fprintf (stdout,"KO\n") ; + if (status != CR_OK) { + fprintf (stdout, "KO\n"); } - return 0 ; + return 0; } diff --git a/tests/test3-main.c b/tests/test3-main.c index 3b7f1ac..e312b3b 100644 --- a/tests/test3-main.c +++ b/tests/test3-main.c @@ -29,22 +29,21 @@ #include "cr-test-utils.h" #include "cr-parser.h" - /** *@file *Some test facilities for the #CRParser class. */ -CRDocHandler * gv_test_handler = {0} ; +CRDocHandler *gv_test_handler = { 0 }; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static enum CRStatus -test_cr_parser_parse (guchar * a_file_uri) ; + test_cr_parser_parse (guchar * a_file_uri); /** *Displays the usage of the test @@ -52,17 +51,17 @@ test_cr_parser_parse (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"usage: %s \n", prg_name) ; - fprintf (stdout,"\t : the file to parse\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Tests the cr_parser_parse () method.\n") ; - fprintf (stdout,"Tests the parsing following the css core syntax\n") ; - fprintf (stdout,"Returns OK if the status is CR_OK, KO otherwise\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "usage: %s \n", prg_name); + fprintf (stdout, "\t : the file to parse\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, "Tests the cr_parser_parse () method.\n"); + fprintf (stdout, "Tests the parsing following the css core syntax\n"); + fprintf (stdout, "Returns OK if the status is CR_OK, KO otherwise\n"); + fprintf (stdout, "\n\n"); } /** @@ -70,492 +69,437 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - fprintf (stdout,"\n\n") ; - fprintf (stdout,"%s is a libcroco CRParser class test program.\n", - prg_name) ; - fprintf (stdout,"It should run on GNU compliants systems.\n") ; - fprintf (stdout,"\n\n") ; - fprintf (stdout,"Initial author: Dodji Seketeli .\n") ; - fprintf (stdout,"\n\n") ; + fprintf (stdout, "\n\n"); + fprintf (stdout, "%s is a libcroco CRParser class test program.\n", + prg_name); + fprintf (stdout, "It should run on GNU compliants systems.\n"); + fprintf (stdout, "\n\n"); + fprintf (stdout, + "Initial author: Dodji Seketeli .\n"); + fprintf (stdout, "\n\n"); } - /*************************** *Some SAC document handlers *for TEST PURPOSES. ***************************/ static void -test_start_document (CRDocHandler *a_handler) +test_start_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_end_document (CRDocHandler *a_handler) +test_end_document (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_document\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_document\n"); + fprintf (stdout, "***************\n\n"); } static void -test_import_style (CRDocHandler *a_handler, - GList *a_media_list, GString *a_uri, - GString *a_uri_default_ns) +test_import_style (CRDocHandler * a_handler, + GList * a_media_list, GString * a_uri, + GString * a_uri_default_ns) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"****************\n") ; - fprintf (stdout,"import_style\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - - fprintf (stdout,"\nmedia list:\n") ; - fprintf (stdout,"-------------\n") ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data) - { - guchar *str = - g_strndup - (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; - - if (str) - { - fprintf (stdout,str) ; fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"\ndefault namespace:\n") ; - fprintf (stdout,"--------------------\n") ; - - if (a_uri_default_ns && a_uri_default_ns->str) - { - guchar * str = - g_strndup (a_uri_default_ns->str, - a_uri_default_ns->len) ; - if (str) - { - fprintf (stdout,str) ; fprintf (stdout,"\n") ; - g_free (str) ; - str = NULL ; - } - } - } - - fprintf (stdout,"******************\n\n") ; - a_uri = NULL ; /*keep compiler happy*/ -} + g_return_if_fail (a_handler); + + fprintf (stdout, "****************\n"); + fprintf (stdout, "import_style\n"); + + if (a_media_list) { + GList *cur = NULL; + + fprintf (stdout, "\nmedia list:\n"); + fprintf (stdout, "-------------\n"); + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data) { + guchar *str = + g_strndup + (((GString *) cur->data)->str, + ((GString *) cur->data)->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + fprintf (stdout, "\ndefault namespace:\n"); + fprintf (stdout, "--------------------\n"); + + if (a_uri_default_ns && a_uri_default_ns->str) { + guchar *str = g_strndup (a_uri_default_ns->str, + a_uri_default_ns->len); + + if (str) { + fprintf (stdout, str); + fprintf (stdout, "\n"); + g_free (str); + str = NULL; + } + } + } + + fprintf (stdout, "******************\n\n"); + a_uri = NULL; /*keep compiler happy */ +} static void -test_namespace_declaration (CRDocHandler *a_handler, - GString *a_prefix, - GString *a_uri) +test_namespace_declaration (CRDocHandler * a_handler, + GString * a_prefix, GString * a_uri) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"namespace_declaration:\n") ; - - if (a_prefix && a_prefix->str) - { - guchar * prefix = NULL ; - - prefix = g_strndup (a_prefix->str, a_prefix->len) ; - - if (prefix) - { - fprintf (stdout,"prefix: %s\n", prefix) ; - g_free (prefix) ; - prefix = NULL ; - } - } - - if (a_uri && a_uri->str) - { - guchar *uri = NULL ; - - uri = g_strndup (a_uri->str, a_uri->len) ; - - if (uri) - { - fprintf (stdout,"uri: %s\n", uri) ; - g_free (uri) ; - uri = NULL ; - } - } - fprintf (stdout,"\n") ; - - fprintf (stdout,"***************\n\n") ; - - -} + g_return_if_fail (a_handler); + fprintf (stdout, "***************\n"); + fprintf (stdout, "namespace_declaration:\n"); + + if (a_prefix && a_prefix->str) { + guchar *prefix = NULL; + + prefix = g_strndup (a_prefix->str, a_prefix->len); + + if (prefix) { + fprintf (stdout, "prefix: %s\n", prefix); + g_free (prefix); + prefix = NULL; + } + } + + if (a_uri && a_uri->str) { + guchar *uri = NULL; + + uri = g_strndup (a_uri->str, a_uri->len); + + if (uri) { + fprintf (stdout, "uri: %s\n", uri); + g_free (uri); + uri = NULL; + } + } + fprintf (stdout, "\n"); + + fprintf (stdout, "***************\n\n"); + +} static void -test_comment (CRDocHandler *a_handler, - GString *a_comment) +test_comment (CRDocHandler * a_handler, GString * a_comment) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"comment:\n") ; - - if (a_comment && a_comment->str) - { - guchar *comment = NULL ; - - comment = g_strndup (a_comment->str, a_comment->len) ; - - if (comment) - { - fprintf (stdout,"\n/*----------------------\n") ; - fprintf (stdout,"%s\n", comment) ; - fprintf (stdout,"-------------------------*/\n") ; - - g_free (comment) ; - comment = NULL ; - } - } - - fprintf (stdout,"***************\n\n") ; -} + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "comment:\n"); + if (a_comment && a_comment->str) { + guchar *comment = NULL; + comment = g_strndup (a_comment->str, a_comment->len); + if (comment) { + fprintf (stdout, "\n/*----------------------\n"); + fprintf (stdout, "%s\n", comment); + fprintf (stdout, "-------------------------*/\n"); + + g_free (comment); + comment = NULL; + } + } + + fprintf (stdout, "***************\n\n"); +} static void -test_start_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_start_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_selector\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_selector\n"); - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout,"\n") ; + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_selector (CRDocHandler *a_handler, - CRSelector *a_selector_list) +test_end_selector (CRDocHandler * a_handler, CRSelector * a_selector_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_selector\n") ; - - if (a_selector_list) - { - cr_selector_dump (a_selector_list, stdout) ; - fprintf (stdout,"\n") ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_selector\n"); + + if (a_selector_list) { + cr_selector_dump (a_selector_list, stdout); + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_property (CRDocHandler *a_handler, GString *a_name, - CRTerm *a_expr, gboolean a_important) +test_property (CRDocHandler * a_handler, GString * a_name, + CRTerm * a_expr, gboolean a_important) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"property\n") ; - - if (a_name && a_name->str) - { - guchar *name = g_strndup (a_name->str, a_name->len) ; - - if (name) - { - fprintf (stdout,name) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "property\n"); + + if (a_name && a_name->str) { + guchar *name = g_strndup (a_name->str, a_name->len); + + if (name) { + fprintf (stdout, name); } - - if (a_expr) - { - fprintf (stdout,": ") ; - cr_term_dump (a_expr, stdout) ; + + if (a_expr) { + fprintf (stdout, ": "); + cr_term_dump (a_expr, stdout); } - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - - fprintf (stdout,"\n") ; + + fprintf (stdout, "\n"); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_start_font_face (CRDocHandler *a_handler) +test_start_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_font_face\n"); + fprintf (stdout, "***************\n\n"); } - static void -test_end_font_face (CRDocHandler *a_handler) +test_end_font_face (CRDocHandler * a_handler) { - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_font_face\n") ; - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_font_face\n"); + fprintf (stdout, "***************\n\n"); } static void -test_start_media (CRDocHandler *a_handler, - GList *a_media_list) +test_start_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } - static void -test_end_media (CRDocHandler *a_handler, - GList *a_media_list) +test_end_media (CRDocHandler * a_handler, GList * a_media_list) { - g_return_if_fail (a_handler) ; - - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_media\n") ; - - if (a_media_list) - { - GList *cur = NULL ; - guchar *medium = NULL ; - - for (cur = a_media_list ; cur ; cur = cur->next) - { - if (cur->data == NULL) - continue ; - - medium = g_strndup (((GString*)cur->data)->str, - ((GString*)cur->data)->len) ; + g_return_if_fail (a_handler); + + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_media\n"); + + if (a_media_list) { + GList *cur = NULL; + guchar *medium = NULL; + + for (cur = a_media_list; cur; cur = cur->next) { + if (cur->data == NULL) + continue; + + medium = g_strndup (((GString *) cur->data)->str, + ((GString *) cur->data)->len); if (medium == NULL) - continue ; + continue; - fprintf (stdout,"medium: %s\n", medium) ; + fprintf (stdout, "medium: %s\n", medium); - if (medium) - { - g_free (medium) ; - medium = NULL ; + if (medium) { + g_free (medium); + medium = NULL; } } } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); } static void -test_start_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_start_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"start_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "start_page\n"); + + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } static void -test_end_page (CRDocHandler *a_handler, - GString *a_name, GString *a_pseudo_page) +test_end_page (CRDocHandler * a_handler, + GString * a_name, GString * a_pseudo_page) { - guchar *name = NULL, *pseudo_page = NULL ; + guchar *name = NULL, + *pseudo_page = NULL; + + g_return_if_fail (a_handler); - g_return_if_fail (a_handler) ; + fprintf (stdout, "***************\n"); + fprintf (stdout, "end_page\n"); - fprintf (stdout,"***************\n") ; - fprintf (stdout,"end_page\n") ; - - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (a_pseudo_page && a_pseudo_page->str) - { - pseudo_page = g_strndup (a_pseudo_page->str, - a_pseudo_page->len) ; + if (a_pseudo_page && a_pseudo_page->str) { + pseudo_page = g_strndup (a_pseudo_page->str, + a_pseudo_page->len); } - if (name) - { - fprintf (stdout,"%s", name) ; + if (name) { + fprintf (stdout, "%s", name); } - if (pseudo_page) - { - fprintf (stdout,": %s\n", pseudo_page) ; - + if (pseudo_page) { + fprintf (stdout, ": %s\n", pseudo_page); + } - fprintf (stdout,"***************\n\n") ; + fprintf (stdout, "***************\n\n"); - if (name) - { - g_free (name) ; - name = NULL ; + if (name) { + g_free (name); + name = NULL; } - if (pseudo_page) - { - g_free (pseudo_page) ; - pseudo_page = NULL ; + if (pseudo_page) { + g_free (pseudo_page); + pseudo_page = NULL; } } - static void -test_ignorable_at_rule (CRDocHandler *a_handler, - GString *a_name) +test_ignorable_at_rule (CRDocHandler * a_handler, GString * a_name) { - guchar *name = NULL ; + guchar *name = NULL; - g_return_if_fail (a_handler) ; + g_return_if_fail (a_handler); - fprintf (stdout,"*********************\n") ; - fprintf (stdout,"ignorable_at_rule\n") ; + fprintf (stdout, "*********************\n"); + fprintf (stdout, "ignorable_at_rule\n"); - if (a_name && a_name->str) - { - name = g_strndup (a_name->str, a_name->len) ; + if (a_name && a_name->str) { + name = g_strndup (a_name->str, a_name->len); } - if (name) - { - fprintf (stdout,"%s\n", name) ; + if (name) { + fprintf (stdout, "%s\n", name); } - fprintf (stdout,"*********************\n\n") ; + fprintf (stdout, "*********************\n\n"); } - static void -init_test_sac_handler (CRDocHandler *a_handler) - +init_test_sac_handler (CRDocHandler * a_handler) { - a_handler->start_document = test_start_document ; - a_handler->end_document = test_end_document ; - a_handler->import_style = test_import_style ; - a_handler->namespace_declaration = test_namespace_declaration ; - a_handler->comment = test_comment ; - a_handler->start_selector = test_start_selector ; - a_handler->end_selector = test_end_selector ; - a_handler->property = test_property ; - a_handler->start_font_face = test_start_font_face ; - a_handler->end_font_face = test_end_font_face ; - a_handler->start_media = test_start_media ; - a_handler->end_media = test_end_media ; - a_handler->start_page = test_start_page ; - a_handler->end_page = test_end_page ; - a_handler->ignorable_at_rule = test_ignorable_at_rule ; + a_handler->start_document = test_start_document; + a_handler->end_document = test_end_document; + a_handler->import_style = test_import_style; + a_handler->namespace_declaration = test_namespace_declaration; + a_handler->comment = test_comment; + a_handler->start_selector = test_start_selector; + a_handler->end_selector = test_end_selector; + a_handler->property = test_property; + a_handler->start_font_face = test_start_font_face; + a_handler->end_font_face = test_end_font_face; + a_handler->start_media = test_start_media; + a_handler->end_media = test_end_media; + a_handler->start_page = test_start_page; + a_handler->end_page = test_end_page; + a_handler->ignorable_at_rule = test_ignorable_at_rule; } /*************************** @@ -563,7 +507,6 @@ init_test_sac_handler (CRDocHandler *a_handler) *handlers. ***************************/ - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -576,70 +519,64 @@ init_test_sac_handler (CRDocHandler *a_handler) static enum CRStatus test_cr_parser_parse (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CRParser *parser = NULL ; + enum CRStatus status = CR_OK; + CRParser *parser = NULL; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; + gv_test_handler = cr_doc_handler_new (); + init_test_sac_handler (gv_test_handler); - gv_test_handler = cr_doc_handler_new () ; - init_test_sac_handler (gv_test_handler) ; + parser = cr_parser_new (NULL); - parser = cr_parser_new (NULL) ; + status = cr_parser_set_sac_handler (parser, gv_test_handler); - status = cr_parser_set_sac_handler (parser, gv_test_handler) ; - - if (status != CR_OK) - { - cr_parser_destroy (parser) ; - g_return_val_if_fail (status == CR_OK, CR_ERROR) ; - } + if (status != CR_OK) { + cr_parser_destroy (parser); + g_return_val_if_fail (status == CR_OK, CR_ERROR); + } - status = cr_parser_set_use_core_grammar (parser, TRUE) ; - status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII) ; + status = cr_parser_set_use_core_grammar (parser, TRUE); + status = cr_parser_parse_file (parser, a_file_uri, CR_ASCII); - cr_parser_destroy (parser) ; + cr_parser_destroy (parser); - gv_test_handler = NULL ; + gv_test_handler = NULL; - return status ; + return status; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - status = test_cr_parser_parse (options.files_list[0]) ; + status = test_cr_parser_parse (options.files_list[0]); - if (status != CR_OK) - { - fprintf (stdout,"KO\n") ; + if (status != CR_OK) { + fprintf (stdout, "KO\n"); } - return 0 ; + return 0; } diff --git a/tests/test4-main.c b/tests/test4-main.c index 997e2ec..ea51d68 100644 --- a/tests/test4-main.c +++ b/tests/test4-main.c @@ -27,59 +27,43 @@ #include "cr-test-utils.h" #include "libcroco.h" - /** *@file *Some test facilities for the #CROMParser class. */ -CRDocHandler * gv_test_handler = {0} ; +CRDocHandler *gv_test_handler = { 0 }; -const guchar * gv_term_buf= "106" ; +const guchar *gv_term_buf = "106"; -const guchar * gv_decl_buf = -"toto: tutu, tata" ; +const guchar *gv_decl_buf = "toto: tutu, tata"; -const guchar * gv_decl_list_buf = -"toto: titi; prop1:val1 ; prop2:val2;" ; +const guchar *gv_decl_list_buf = "toto: titi; prop1:val1 ; prop2:val2;"; -const guchar *gv_ruleset_buf = -"s1 > s2 {toto: tutu, tata} " -; +const guchar *gv_ruleset_buf = "s1 > s2 {toto: tutu, tata} "; const guchar *gv_at_media_buf = -"@media print, toto {" -" BODY { font-size: 10pt }" -" }" -; + "@media print, toto {" " BODY { font-size: 10pt }" " }"; -const guchar *gv_at_page_buf = -"@page { size :8.5in 11in; margin: 2cm }" -; +const guchar *gv_at_page_buf = "@page { size :8.5in 11in; margin: 2cm }"; -const guchar *gv_at_charset_buf = -"@charset \"ISO-8859-1\" ; " -; +const guchar *gv_at_charset_buf = "@charset \"ISO-8859-1\" ; "; -const guchar *gv_at_font_face_buf= -"@font-face {" -" font-family: \"Robson Celtic\";" -" src: url(\"http://site/fonts/rob-celt\")" -"}" -; +const guchar *gv_at_font_face_buf = + "@font-face {" + " font-family: \"Robson Celtic\";" + " src: url(\"http://site/fonts/rob-celt\")" "}"; -const guchar *gv_at_import_buf= -"@import \"subs.css\";" -; +const guchar *gv_at_import_buf = "@import \"subs.css\";"; -static void -display_help (char *prg_name) ; +static void + display_help (char *prg_name); -static void -display_about (char *prg_name) ; +static void + display_about (char *prg_name); static enum CRStatus -test_cr_parser_parse (guchar * a_file_uri) ; + test_cr_parser_parse (guchar * a_file_uri); /** *Displays the usage of the test @@ -87,17 +71,17 @@ test_cr_parser_parse (guchar * a_file_uri) ; *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s \n", prg_name) ; - g_print ("\t : the file to parse\n") ; - g_print ("\n\n") ; - g_print ("Tests the cr_parser_parse () method.\n") ; - g_print ("Tests the parsing following the css core syntax\n") ; - g_print ("Returns OK if the status is CR_OK, KO otherwise\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s \n", prg_name); + g_print ("\t : the file to parse\n"); + g_print ("\n\n"); + g_print ("Tests the cr_parser_parse () method.\n"); + g_print ("Tests the parsing following the css core syntax\n"); + g_print ("Returns OK if the status is CR_OK, KO otherwise\n"); + g_print ("\n\n"); } /** @@ -105,21 +89,19 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CROMParser class test program.\n", - prg_name) ; - g_print ("%s Parses a file and builds a CSS object model", - prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli .\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CROMParser class test program.\n", + prg_name); + g_print ("%s Parses a file and builds a CSS object model", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli .\n"); + g_print ("\n\n"); } - /** *The test of the cr_input_read_byte() method. *Reads the each byte of a_file_uri using the @@ -132,383 +114,332 @@ display_about (char *prg_name) static enum CRStatus test_cr_parser_parse (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CROMParser *parser = NULL ; - CRStyleSheet *stylesheet = NULL ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - parser = cr_om_parser_new (NULL) ; - status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, - &stylesheet) ; - if (status == CR_OK && stylesheet) - { - cr_stylesheet_dump (stylesheet, stdout) ; - cr_stylesheet_destroy (stylesheet) ; - } - cr_om_parser_destroy (parser) ; - - return status ; -} + enum CRStatus status = CR_OK; + CROMParser *parser = NULL; + CRStyleSheet *stylesheet = NULL; + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); + + parser = cr_om_parser_new (NULL); + status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, + &stylesheet); + if (status == CR_OK && stylesheet) { + cr_stylesheet_dump (stylesheet, stdout); + cr_stylesheet_destroy (stylesheet); + } + cr_om_parser_destroy (parser); + + return status; +} static enum CRStatus test_cr_term_parse_expression_from_buf (void) { - guchar * tmp_str = NULL ; - CRTerm * term = NULL ; + guchar *tmp_str = NULL; + CRTerm *term = NULL; - term = cr_term_parse_expression_from_buf (gv_term_buf, - CR_UTF_8) ; + term = cr_term_parse_expression_from_buf (gv_term_buf, CR_UTF_8); if (!term) - return CR_ERROR ; - tmp_str = cr_term_to_string (term) ; - if (term) - { - cr_term_destroy (term) ; - term = NULL ; - } - if (tmp_str) - { - g_free (tmp_str) ; - tmp_str = NULL ; - } - return CR_OK ; + return CR_ERROR; + tmp_str = cr_term_to_string (term); + if (term) { + cr_term_destroy (term); + term = NULL; + } + if (tmp_str) { + g_free (tmp_str); + tmp_str = NULL; + } + return CR_OK; } static enum CRStatus test_cr_declaration_parse (void) { - guchar * tmp_str = NULL ; - CRDeclaration * decl = NULL ; + guchar *tmp_str = NULL; + CRDeclaration *decl = NULL; - decl = cr_declaration_parse_from_buf (NULL, gv_decl_buf, - CR_UTF_8) ; + decl = cr_declaration_parse_from_buf (NULL, gv_decl_buf, CR_UTF_8); if (!decl) - return CR_ERROR ; - tmp_str = cr_declaration_to_string (decl, 2) ; + return CR_ERROR; + tmp_str = cr_declaration_to_string (decl, 2); - if (decl) - { - cr_declaration_destroy (decl) ; + if (decl) { + cr_declaration_destroy (decl); } - if (tmp_str) - { - g_free (tmp_str) ; - tmp_str = NULL ; + if (tmp_str) { + g_free (tmp_str); + tmp_str = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_declaration_parse_list (void) { - GString *str = NULL ; - guchar *tmp_str = NULL ; - CRDeclaration *decl = NULL, *cur_decl = NULL ; + GString *str = NULL; + guchar *tmp_str = NULL; + CRDeclaration *decl = NULL, + *cur_decl = NULL; decl = cr_declaration_parse_list_from_buf (gv_decl_list_buf, - CR_UTF_8) ; + CR_UTF_8); if (!decl) - return CR_ERROR ; - str = g_string_new (NULL) ; - for (cur_decl = decl ; cur_decl ; cur_decl = cur_decl->next) - { - tmp_str = cr_declaration_to_string (cur_decl, 2) ; - if (tmp_str) - { - g_string_append_printf (str, "%s;", tmp_str) ; - g_free (tmp_str) ; - tmp_str = NULL ; + return CR_ERROR; + str = g_string_new (NULL); + for (cur_decl = decl; cur_decl; cur_decl = cur_decl->next) { + tmp_str = cr_declaration_to_string (cur_decl, 2); + if (tmp_str) { + g_string_append_printf (str, "%s;", tmp_str); + g_free (tmp_str); + tmp_str = NULL; } - + } - if (decl) - { - cr_declaration_destroy (decl) ; + if (decl) { + cr_declaration_destroy (decl); } - if (str) - { - g_string_free (str, TRUE) ; - str = NULL ; + if (str) { + g_string_free (str, TRUE); + str = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_ruleset_parse (void) { - CRStatement *stmt = NULL ; - - stmt = cr_statement_ruleset_parse_from_buf (gv_ruleset_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; + CRStatement *stmt = NULL; + + stmt = cr_statement_ruleset_parse_from_buf (gv_ruleset_buf, CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_at_media_rule_parse (void) { - CRStatement *stmt = NULL ; + CRStatement *stmt = NULL; stmt = cr_statement_at_media_rule_parse_from_buf (gv_at_media_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_at_page_rule_parse (void) { - CRStatement *stmt = NULL ; - + CRStatement *stmt = NULL; + stmt = cr_statement_at_page_rule_parse_from_buf (gv_at_page_buf, - CR_UTF_8) ; - - g_return_val_if_fail (stmt, CR_ERROR) ; - - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + + g_return_val_if_fail (stmt, CR_ERROR); + + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_at_charset_rule_parse (void) { - CRStatement *stmt = NULL ; - + CRStatement *stmt = NULL; + stmt = cr_statement_at_charset_rule_parse_from_buf (gv_at_charset_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } - static enum CRStatus test_cr_statement_font_face_rule_parse_from_buf (void) { - CRStatement *stmt = NULL ; - - stmt = cr_statement_font_face_rule_parse_from_buf (gv_at_font_face_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - - return CR_OK ; + CRStatement *stmt = NULL; + + stmt = cr_statement_font_face_rule_parse_from_buf + (gv_at_font_face_buf, CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } + + return CR_OK; } static enum CRStatus test_cr_statement_at_import_rule_parse_from_buf (void) { - CRStatement *stmt = NULL ; + CRStatement *stmt = NULL; stmt = cr_statement_at_import_rule_parse_from_buf (gv_at_import_buf, - CR_UTF_8) ; - g_return_val_if_fail (stmt, CR_ERROR) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; + CR_UTF_8); + g_return_val_if_fail (stmt, CR_ERROR); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; } - return CR_OK ; + return CR_OK; } static enum CRStatus test_cr_statement_parse_from_buf (void) { - CRStatement *stmt = NULL ; - - stmt = cr_statement_parse_from_buf (gv_ruleset_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_media_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_page_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_charset_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_font_face_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - stmt = cr_statement_parse_from_buf (gv_at_import_buf, CR_UTF_8) ; - if (stmt) - { - cr_statement_destroy (stmt) ; - stmt = NULL ; - } - else - { - return CR_ERROR ; - } - - return CR_OK ; + CRStatement *stmt = NULL; + + stmt = cr_statement_parse_from_buf (gv_ruleset_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_media_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_page_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_charset_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_font_face_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + stmt = cr_statement_parse_from_buf (gv_at_import_buf, CR_UTF_8); + if (stmt) { + cr_statement_destroy (stmt); + stmt = NULL; + } else { + return CR_ERROR; + } + + return CR_OK; } /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - status = test_cr_term_parse_expression_from_buf() ; - if (status != CR_OK) - { - g_print ("\ntest \"cr_term_parse_expression_from_buf failed\"") ; + status = test_cr_term_parse_expression_from_buf (); + if (status != CR_OK) { + g_print ("\ntest \"cr_term_parse_expression_from_buf failed\""); } - status = test_cr_declaration_parse () ; - if (status != CR_OK) - { - g_print ("\n test \"cr_declaration_parse() failed\"\n") ; + status = test_cr_declaration_parse (); + if (status != CR_OK) { + g_print ("\n test \"cr_declaration_parse() failed\"\n"); } - status = test_cr_declaration_parse_list () ; - if (status != CR_OK) - { - g_print ("\ntest cr_declaration_parse_list() failed\n") ; + status = test_cr_declaration_parse_list (); + if (status != CR_OK) { + g_print ("\ntest cr_declaration_parse_list() failed\n"); } - status = test_cr_statement_ruleset_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_ruleset_parse() failed\n") ; + status = test_cr_statement_ruleset_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_ruleset_parse() failed\n"); } - status = test_cr_statement_at_media_rule_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_media_rule_parse() failed\n") ; + status = test_cr_statement_at_media_rule_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_media_rule_parse() failed\n"); } - test_cr_statement_at_page_rule_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_page_rule_parse() failed\n") ; - return 0 ; + test_cr_statement_at_page_rule_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_page_rule_parse() failed\n"); + return 0; } - status = test_cr_statement_at_charset_rule_parse () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_charset_rule_parse() failed\n") ; + status = test_cr_statement_at_charset_rule_parse (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_charset_rule_parse() failed\n"); } - status = test_cr_statement_font_face_rule_parse_from_buf () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_font_face_rule_parse_from_buf() failed\n") ; + status = test_cr_statement_font_face_rule_parse_from_buf (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_font_face_rule_parse_from_buf() failed\n"); } - test_cr_statement_at_import_rule_parse_from_buf () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_at_import_rule() failed\n") ; + test_cr_statement_at_import_rule_parse_from_buf (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_at_import_rule() failed\n"); } - status = test_cr_statement_parse_from_buf () ; - if (status != CR_OK) - { - g_print ("\ntest cr_statement_parse_from_buf() failed\n") ; + status = test_cr_statement_parse_from_buf (); + if (status != CR_OK) { + g_print ("\ntest cr_statement_parse_from_buf() failed\n"); } - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - - status = test_cr_parser_parse (options.files_list[0]) ; - if (status != CR_OK) - { - g_print ("\nKO\n") ; + + status = test_cr_parser_parse (options.files_list[0]); + if (status != CR_OK) { + g_print ("\nKO\n"); } - - return 0 ; + + return 0; } diff --git a/tests/test5-main.c b/tests/test5-main.c index 4214746..59d81aa 100644 --- a/tests/test5-main.c +++ b/tests/test5-main.c @@ -28,38 +28,35 @@ #include "cr-test-utils.h" #include "libcroco.h" - /** *@file *Some test facilities for the #CRParser class. */ -CRDocHandler * gv_test_handler = {0} ; - -const guchar *xml_content= -"" -"text0 " -"text1" -"text2" -"text3" -"text4" -"text5" -"text6" -"text7" -""; - -static void -display_help (char *prg_name) ; - -static void -display_about (char *prg_name) ; +CRDocHandler *gv_test_handler = { 0 }; + +const guchar *xml_content = + "" + "text0 " + "text1" + "text2" + "text3" + "text4" + "text5" + "text6" + "text7" ""; + +static void + display_help (char *prg_name); + +static void + display_about (char *prg_name); static enum CRStatus -test_sel_eng (guchar * a_file_uri) ; + test_sel_eng (guchar * a_file_uri); static void -walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, - CRStyleSheet *a_sheet, - xmlNode *a_node) ; + walk_xml_tree_and_lookup_rules (CRSelEng * a_sel_eng, + CRStyleSheet * a_sheet, xmlNode * a_node); /** *Displays the usage of the test @@ -67,16 +64,16 @@ walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_help (char *prg_name) { - g_print ("\n\n") ; - g_print ("usage: %s \n", prg_name) ; - g_print ("\t : the file to parse\n") ; - g_print ("\n\n") ; - g_print ("Test the selection engine") ; - g_print ("Returns OK if the status is CR_OK, KO otherwise\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("usage: %s \n", prg_name); + g_print ("\t : the file to parse\n"); + g_print ("\n\n"); + g_print ("Test the selection engine"); + g_print ("Returns OK if the status is CR_OK, KO otherwise\n"); + g_print ("\n\n"); } /** @@ -84,68 +81,56 @@ display_help (char *prg_name) *@param a_argc the argc variable passed to the main function. *@param a_argv the argv variable passed to the main function. */ -static void +static void display_about (char *prg_name) { - g_print ("\n\n") ; - g_print ("%s is a libcroco CROMParser class test program.\n", - prg_name) ; - g_print ("%s Parses a file and builds a CSS object model", - prg_name) ; - g_print ("It should run on GNU compliants systems.\n") ; - g_print ("\n\n") ; - g_print ("Initial author: Dodji Seketeli .\n") ; - g_print ("\n\n") ; + g_print ("\n\n"); + g_print ("%s is a libcroco CROMParser class test program.\n", + prg_name); + g_print ("%s Parses a file and builds a CSS object model", prg_name); + g_print ("It should run on GNU compliants systems.\n"); + g_print ("\n\n"); + g_print ("Initial author: Dodji Seketeli .\n"); + g_print ("\n\n"); } - static void -walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, - CRStyleSheet *a_sheet, - xmlNode *a_node) +walk_xml_tree_and_lookup_rules (CRSelEng * a_sel_eng, + CRStyleSheet * a_sheet, xmlNode * a_node) { CRStatement **stmts_tab = NULL; - gulong tab_len = 0, i= 0 ; - enum CRStatus status = CR_OK ; - - xmlNode *cur_node = a_node ; - - for (cur_node = a_node ;cur_node ; cur_node = cur_node->next) - { - status = cr_sel_eng_get_matched_rulesets - (a_sel_eng, a_sheet, - cur_node, &stmts_tab, &tab_len) ; - - if (status == CR_OK && tab_len) - { - g_print ("'''''''''''''''''''''''''\n") ; - g_print ("xml start element: %s\n", - cur_node->name); - - for (i = 0 ; i < tab_len; i++) - { - if (stmts_tab[i]) - { - g_print ("\n") ; + gulong tab_len = 0, + i = 0; + enum CRStatus status = CR_OK; + + xmlNode *cur_node = a_node; + + for (cur_node = a_node; cur_node; cur_node = cur_node->next) { + status = cr_sel_eng_get_matched_rulesets + (a_sel_eng, a_sheet, cur_node, &stmts_tab, &tab_len); + + if (status == CR_OK && tab_len) { + g_print ("'''''''''''''''''''''''''\n"); + g_print ("xml start element: %s\n", cur_node->name); + + for (i = 0; i < tab_len; i++) { + if (stmts_tab[i]) { + g_print ("\n"); cr_statement_dump (stmts_tab[i], - stdout, 2) ; + stdout, 2); } } - g_print ("\n\nxml end element: %s\n", - cur_node->name); - g_print ("'''''''''''''''''''''''''\n") ; + g_print ("\n\nxml end element: %s\n", cur_node->name); + g_print ("'''''''''''''''''''''''''\n"); } - if (stmts_tab) - { - g_free (stmts_tab) ; - stmts_tab= NULL ; + if (stmts_tab) { + g_free (stmts_tab); + stmts_tab = NULL; } - if (cur_node->children) - { - walk_xml_tree_and_lookup_rules - (a_sel_eng, a_sheet, - cur_node->children) ; + if (cur_node->children) { + walk_xml_tree_and_lookup_rules + (a_sel_eng, a_sheet, cur_node->children); } } } @@ -162,121 +147,107 @@ walk_xml_tree_and_lookup_rules (CRSelEng *a_sel_eng, static enum CRStatus test_sel_eng (guchar * a_file_uri) { - enum CRStatus status = CR_OK ; - CROMParser *parser = NULL ; - CRStyleSheet *stylesheet = NULL ; - xmlDoc * xml_doc = NULL ; - xmlNode *cur_node = NULL ; - CRSelEng *selection_engine = NULL ; - - g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR) ; - - parser = cr_om_parser_new (NULL) ; - status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, - &stylesheet) ; - if (status != CR_OK || !stylesheet) - { - cr_utils_trace_info ("Could not parse xml content") ; - goto error ; - } - - xml_doc = xmlParseMemory (xml_content, strlen (xml_content)) ; - if (!xml_doc) - { - cr_utils_trace_info ("Could not parse xml content") ; - goto error ; - + enum CRStatus status = CR_OK; + CROMParser *parser = NULL; + CRStyleSheet *stylesheet = NULL; + xmlDoc *xml_doc = NULL; + xmlNode *cur_node = NULL; + CRSelEng *selection_engine = NULL; + + g_return_val_if_fail (a_file_uri, CR_BAD_PARAM_ERROR); + + parser = cr_om_parser_new (NULL); + status = cr_om_parser_parse_file (parser, a_file_uri, CR_ASCII, + &stylesheet); + if (status != CR_OK || !stylesheet) { + cr_utils_trace_info ("Could not parse xml content"); + goto error; } - selection_engine = cr_sel_eng_new () ; + xml_doc = xmlParseMemory (xml_content, strlen (xml_content)); + if (!xml_doc) { + cr_utils_trace_info ("Could not parse xml content"); + goto error; - cur_node = xml_doc->children ; + } + + selection_engine = cr_sel_eng_new (); + + cur_node = xml_doc->children; walk_xml_tree_and_lookup_rules (selection_engine, - stylesheet, - cur_node) ; + stylesheet, cur_node); - if (parser) - { - cr_om_parser_destroy (parser) ; - parser = NULL ; + if (parser) { + cr_om_parser_destroy (parser); + parser = NULL; } - if (xml_doc) - { - xmlFreeDoc (xml_doc) ; - xml_doc = NULL ; + if (xml_doc) { + xmlFreeDoc (xml_doc); + xml_doc = NULL; } - if (stylesheet) - { - cr_stylesheet_destroy (stylesheet) ; - stylesheet = NULL ; + if (stylesheet) { + cr_stylesheet_destroy (stylesheet); + stylesheet = NULL; } - xmlCleanupParser () ; - return status ; + xmlCleanupParser (); + return status; - error: + error: - if (parser) - { - cr_om_parser_destroy (parser) ; - parser = NULL ; + if (parser) { + cr_om_parser_destroy (parser); + parser = NULL; } - if (xml_doc) - { - xmlFreeDoc (xml_doc) ; - xml_doc = NULL ; + if (xml_doc) { + xmlFreeDoc (xml_doc); + xml_doc = NULL; } - if (stylesheet) - { - cr_stylesheet_destroy (stylesheet) ; - stylesheet = NULL ; + if (stylesheet) { + cr_stylesheet_destroy (stylesheet); + stylesheet = NULL; } - xmlCleanupParser () ; - return CR_ERROR ; + xmlCleanupParser (); + return CR_ERROR; } - /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - struct Options options ; - enum CRStatus status = CR_OK ; + struct Options options; + enum CRStatus status = CR_OK; - cr_test_utils_parse_cmd_line (argc, argv, &options) ; + cr_test_utils_parse_cmd_line (argc, argv, &options); - if (options.display_help == TRUE) - { - display_help (argv[0]) ; - return 0 ; + if (options.display_help == TRUE) { + display_help (argv[0]); + return 0; } - if (options.display_about == TRUE) - { - display_about (argv[0]) ; - return 0 ; + if (options.display_about == TRUE) { + display_about (argv[0]); + return 0; } - if (options.files_list == NULL) - { - display_help (argv[0]) ; - return 0 ; + if (options.files_list == NULL) { + display_help (argv[0]); + return 0; } - status = test_sel_eng (options.files_list[0]) ; + status = test_sel_eng (options.files_list[0]); - if (status != CR_OK) - { - g_print ("\nKO\n") ; + if (status != CR_OK) { + g_print ("\nKO\n"); } - return 0 ; + return 0; } diff --git a/tests/test6-main.c b/tests/test6-main.c index 4e534bf..f9dd1c3 100644 --- a/tests/test6-main.c +++ b/tests/test6-main.c @@ -30,13 +30,11 @@ #include "libcroco.h" #include "cr-test-utils.h" -const guchar * gv_cssbuf = -".str0 {stroke:#007844;stroke-width:44}" -".fil0 {fill:url(#id0)}" ; +const guchar *gv_cssbuf = + ".str0 {stroke:#007844;stroke-width:44}" ".fil0 {fill:url(#id0)}"; static enum CRStatus -test_cr_parser_parse (void) ; - + test_cr_parser_parse (void); /** *The test of the cr_input_read_byte() method. @@ -50,40 +48,37 @@ test_cr_parser_parse (void) ; static enum CRStatus test_cr_parser_parse (void) { - enum CRStatus status = CR_OK ; - CROMParser *parser = NULL ; - CRStyleSheet *stylesheet = NULL ; + enum CRStatus status = CR_OK; + CROMParser *parser = NULL; + CRStyleSheet *stylesheet = NULL; - parser = cr_om_parser_new (NULL) ; - status = cr_om_parser_parse_buf (parser, (guchar*)gv_cssbuf, - strlen (gv_cssbuf), - CR_ASCII, - &stylesheet) ; + parser = cr_om_parser_new (NULL); + status = cr_om_parser_parse_buf (parser, (guchar *) gv_cssbuf, + strlen (gv_cssbuf), + CR_ASCII, &stylesheet); - if (status == CR_OK && stylesheet) - { - cr_stylesheet_dump (stylesheet, stdout) ; - cr_stylesheet_destroy (stylesheet) ; - } - cr_om_parser_destroy (parser) ; + if (status == CR_OK && stylesheet) { + cr_stylesheet_dump (stylesheet, stdout); + cr_stylesheet_destroy (stylesheet); + } + cr_om_parser_destroy (parser); - return status ; + return status; } /** *The entry point of the testing routine. */ int -main (int argc, char ** argv) +main (int argc, char **argv) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - status = test_cr_parser_parse () ; + status = test_cr_parser_parse (); - if (status != CR_OK) - { - g_print ("\nKO\n") ; + if (status != CR_OK) { + g_print ("\nKO\n"); } - return 0 ; + return 0; } diff --git a/tests/test7-main.c b/tests/test7-main.c index 4165a53..e55467a 100644 --- a/tests/test7-main.c +++ b/tests/test7-main.c @@ -30,179 +30,164 @@ #include "libcroco.h" #include "cr-test-utils.h" - const guchar *gv_xmlbuf = -"" -"" -"" -"scottandrew.com JavaScript and DHTML Channel" -"http://www.scottandrew.com" -"DHTML, DOM and JavaScript snippets from scottandrew.com" -"en-us" -"" -"DHTML Animation Array Generator" -"Robert points us to the first third-party tool for the DomAPI: The Animation Array Generator, a visual tool for creating..." -"http://www.scottandrew.com/weblog/2002_06#a000395" -"" -"" -"DOM and Extended Entries" -"Aarondot: A Better Way To Display Extended Entries. Very cool, and uses the DOM and JavaScript to reveal the extended..." -"http://www.scottandrew.com/weblog/2002_06#a000373" -"" -"" -"cellspacing and the DOM" -"By the way, if you're using the DOM to generate TABLE elements, you have to use setAttribute() to set the..." -"http://www.scottandrew.com/weblog/2002_05#a000365" -"" -"" -"contenteditable for Mozilla" -"The folks art Q42, creator of Quek (cute little avatar/chat) and Xopus (browser-based WYSIWYG XML-editor) have released code that ,simulates..." -"http://www.scottandrew.com/weblog/2002_05#a000361" -"" -"" -"" -; - -const char * gv_cssbuf= -"rss " -"{ " -" display:block; " -" margin:10px; " -"} " -" " -"channel " -"{ " -" display:block; " -" /*height:300px;*/ " -" width:200px; " -" border:1px solid #000; " -" overflow:auto; " -" background-color:#eee; " -" /*font: 12px verdana;*/ " -" font-style: font-family ; " -" font-style: normal; " -"} " -" " -"item " -"{ " -" width: 100%; " -" display: block; " -" padding:10px; " -" margin-bottom:10px; " -" border:1px solid #ccc; " -" /*border-top:1px solid #ccc; " -" border-bottom:1px solid #ccc; " -" border-left:1px solid #ccc; " -" border-right:1px solid #ccc; " -" */ " -" background-color:#fff; " -"} " -" " -" " -"channel>title, channel>description " -"{ " -" display: block; " -" width: 100%; " -" /*margin-left:10px;*/ " -" /*margin-top:10px;*/ " -" background-color:#eee; " -" font-weight:bold; " -" font-size: 12px; " -"} " -" " -"channel>title " -"{ " -" font-size:16px; " -"} " -" " -"channel>description " -"{ " -" display: block ; " -" font-size:10px; " -" margin-bottom:10px; " -"} " -" " -"item>title " -"{ " -" font-weight:bold; " -"} " -" " -"item>link, channel>link, channel>language " -"{ " -" display: none; " -"} " -" " -; + "" + "" + "" + "scottandrew.com JavaScript and DHTML Channel" + "http://www.scottandrew.com" + "DHTML, DOM and JavaScript snippets from scottandrew.com" + "en-us" + "" + "DHTML Animation Array Generator" + "Robert points us to the first third-party tool for the DomAPI: The Animation Array Generator, a visual tool for creating..." + "http://www.scottandrew.com/weblog/2002_06#a000395" + "" + "" + "DOM and Extended Entries" + "Aarondot: A Better Way To Display Extended Entries. Very cool, and uses the DOM and JavaScript to reveal the extended..." + "http://www.scottandrew.com/weblog/2002_06#a000373" + "" + "" + "cellspacing and the DOM" + "By the way, if you're using the DOM to generate TABLE elements, you have to use setAttribute() to set the..." + "http://www.scottandrew.com/weblog/2002_05#a000365" + "" + "" + "contenteditable for Mozilla" + "The folks art Q42, creator of Quek (cute little avatar/chat) and Xopus (browser-based WYSIWYG XML-editor) have released code that ,simulates..." + "http://www.scottandrew.com/weblog/2002_05#a000361" + "" "" ""; + +const char *gv_cssbuf = + "rss " + "{ " + " display:block; " + " margin:10px; " + "} " + " " + "channel " + "{ " + " display:block; " + " /*height:300px;*/ " + " width:200px; " + " border:1px solid #000; " + " overflow:auto; " + " background-color:#eee; " + " /*font: 12px verdana;*/ " + " font-style: font-family ; " + " font-style: normal; " + "} " + " " + "item " + "{ " + " width: 100%; " + " display: block; " + " padding:10px; " + " margin-bottom:10px; " + " border:1px solid #ccc; " + " /*border-top:1px solid #ccc; " + " border-bottom:1px solid #ccc; " + " border-left:1px solid #ccc; " + " border-right:1px solid #ccc; " + " */ " + " background-color:#fff; " + "} " + " " + " " + "channel>title, channel>description " + "{ " + " display: block; " + " width: 100%; " + " /*margin-left:10px;*/ " + " /*margin-top:10px;*/ " + " background-color:#eee; " + " font-weight:bold; " + " font-size: 12px; " + "} " + " " + "channel>title " + "{ " + " font-size:16px; " + "} " + " " + "channel>description " + "{ " + " display: block ; " + " font-size:10px; " + " margin-bottom:10px; " + "} " + " " + "item>title " + "{ " + " font-weight:bold; " + "} " + " " + "item>link, channel>link, channel>language " + "{ " + " display: none; " + "} " + " "; static enum CRStatus -test_layout_box (void) ; + test_layout_box (void); static gboolean -delete_event_cb (GtkWidget *a_widget, GdkEvent *a_event, - gpointer *a_user_data) ; - +delete_event_cb (GtkWidget * a_widget, GdkEvent * a_event, + gpointer * a_user_data); static gboolean -delete_event_cb (GtkWidget *a_widget, GdkEvent *a_event, - gpointer *a_user_data) +delete_event_cb (GtkWidget * a_widget, GdkEvent * a_event, + gpointer * a_user_data) { - gtk_main_quit () ; - return FALSE ; + gtk_main_quit (); + return FALSE; } static enum CRStatus test_layout_box (void) { - CRBoxView *box_view = NULL ; - GtkWidget *window = NULL, *scroll = NULL ; + CRBoxView *box_view = NULL; + GtkWidget *window = NULL, + *scroll = NULL; - box_view = cr_box_view_new_from_xml_css_bufs - (gv_xmlbuf, gv_cssbuf) ; - g_return_val_if_fail (box_view, CR_BAD_PARAM_ERROR) ; + box_view = cr_box_view_new_from_xml_css_bufs (gv_xmlbuf, gv_cssbuf); + g_return_val_if_fail (box_view, CR_BAD_PARAM_ERROR); - window = gtk_window_new (GTK_WINDOW_TOPLEVEL) ; - g_return_val_if_fail (window, CR_BAD_PARAM_ERROR) ; + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + g_return_val_if_fail (window, CR_BAD_PARAM_ERROR); - gtk_window_set_title (GTK_WINDOW (window), - "Croco Renderer Test") ; - gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, TRUE) ; - gtk_widget_set_size_request (window, 800, 600) ; + gtk_window_set_title (GTK_WINDOW (window), "Croco Renderer Test"); + gtk_window_set_policy (GTK_WINDOW (window), TRUE, TRUE, TRUE); + gtk_widget_set_size_request (window, 800, 600); g_signal_connect (G_OBJECT (window), - "delete-event", - G_CALLBACK (delete_event_cb), - NULL) ; + "delete-event", G_CALLBACK (delete_event_cb), NULL); - scroll = gtk_scrolled_window_new (NULL, NULL) ; - g_return_val_if_fail (scroll, CR_BAD_PARAM_ERROR) ; + scroll = gtk_scrolled_window_new (NULL, NULL); + g_return_val_if_fail (scroll, CR_BAD_PARAM_ERROR); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scroll), - GTK_POLICY_ALWAYS, - GTK_POLICY_ALWAYS) ; - gtk_container_add (GTK_CONTAINER (window), scroll) ; - gtk_container_add - (GTK_CONTAINER (scroll), - GTK_WIDGET (box_view)) ; - gtk_widget_show_all (window) ; - gtk_main () ; - - return CR_OK ; -} - + GTK_POLICY_ALWAYS, GTK_POLICY_ALWAYS); + gtk_container_add (GTK_CONTAINER (window), scroll); + gtk_container_add (GTK_CONTAINER (scroll), GTK_WIDGET (box_view)); + gtk_widget_show_all (window); + gtk_main (); + return CR_OK; +} int main (int argc, char **argv) { - enum CRStatus status = CR_OK ; + enum CRStatus status = CR_OK; - cr_lay_eng_init (argc, argv) ; + cr_lay_eng_init (argc, argv); - status = test_layout_box () ; + status = test_layout_box (); - if (status != CR_OK) - { - g_print ("\nKO\n") ; - } - return 0 ; + if (status != CR_OK) { + g_print ("\nKO\n"); + } + return 0; } -- cgit v1.2.1