Code

Handle missing, inaccessible and misnamed cache directories.
[inkscape.git] / src / libcroco / cr-declaration.c
index a1ff0d292335faa86f914fbd9c7eb60ab8af58b4..530085b52cfdd394fe57df1a147adf267aaae8ba 100644 (file)
 static void
 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);
+        gchar *str = cr_declaration_to_string (a_this, a_indent);
         if (str) {
                 fprintf (a_fp, "%s", str);
                 g_free (str);
@@ -64,8 +62,6 @@ CRDeclaration *
 cr_declaration_new (CRStatement * a_statement,
                     CRString * a_property, CRTerm * a_value)
 {
-        CRDeclaration *result = NULL;
-
         g_return_val_if_fail (a_property, NULL);
 
         if (a_statement)
@@ -76,7 +72,7 @@ cr_declaration_new (CRStatement * a_statement,
                                           || (a_statement->type
                                               == AT_PAGE_RULE_STMT)), NULL);
 
-        result = g_try_malloc (sizeof (CRDeclaration));
+        CRDeclaration * result = (CRDeclaration *)g_try_malloc (sizeof (CRDeclaration));
         if (!result) {
                 cr_utils_trace_info ("Out of memory");
                 return NULL;
@@ -111,7 +107,6 @@ cr_declaration_parse_from_buf (CRStatement * a_statement,
         CRTerm *value = NULL;
         CRString *property = NULL;
         CRDeclaration *result = NULL;
-        CRParser *parser = NULL;
         gboolean important = FALSE;
 
         g_return_val_if_fail (a_str, NULL);
@@ -119,7 +114,9 @@ cr_declaration_parse_from_buf (CRStatement * a_statement,
                 g_return_val_if_fail (a_statement->type == RULESET_STMT,
                                       NULL);
 
-        parser = cr_parser_new_from_buf ((guchar*)a_str, strlen (a_str), a_enc, FALSE);
+        CRParser *parser = (CRParser *)
+                       cr_parser_new_from_buf ((guchar*)a_str,
+                                 strlen ((char *)a_str), a_enc, FALSE);
         g_return_val_if_fail (parser, NULL);
 
         status = cr_parser_try_to_skip_spaces_and_comments (parser);
@@ -175,13 +172,13 @@ cr_declaration_parse_list_from_buf (const guchar * a_str,
         CRString *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 ((guchar*)a_str, strlen (a_str), a_enc, FALSE);
+        CRParser *parser = (CRParser *)cr_parser_new_from_buf
+                     ((guchar*)a_str, strlen ((char *)a_str), a_enc, FALSE);
         g_return_val_if_fail (parser, NULL);
         status = cr_parser_get_tknzr (parser, &tokenizer);
         if (status != CR_OK || !tokenizer) {
@@ -213,14 +210,15 @@ cr_declaration_parse_list_from_buf (const guchar * a_str,
                 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)
+                        if (status == CR_END_OF_INPUT_ERROR) 
                                 status = CR_OK;
                         goto cleanup;
                 }
                 if (c == ';') {
                         status = cr_tknzr_read_char (tokenizer, &c);
                 } else {
-                        break;
+                        cr_tknzr_read_char (tokenizer, &c);
+                        continue; // try to keep reading until we reach the end or a ;
                 }
                 important = FALSE;
                 cr_parser_try_to_skip_spaces_and_comments (parser);
@@ -228,9 +226,11 @@ cr_declaration_parse_list_from_buf (const guchar * a_str,
                                                       &value, &important);
                 if (status != CR_OK || !property) {
                         if (status == CR_END_OF_INPUT_ERROR) {
-                                status = CR_OK;
-                        }
-                        break;
+                                status = CR_OK; // simply the end of input, do not delete what we got so far, just finish
+                                break; 
+                        } else {
+                                continue; // even if one declaration is broken, it's no reason to discard others (see http://www.w3.org/TR/CSS21/syndata.html#declaration)
+                                                               }
                 }
                 cur_decl = cr_declaration_new (NULL, property, value);
                 if (cur_decl) {
@@ -468,7 +468,7 @@ cr_declaration_to_string (CRDeclaration * a_this, gulong a_indent)
 {
         GString *stringue = NULL;
 
-        guchar *str = NULL,
+        gchar *str = NULL,
                 *result = NULL;
 
         g_return_val_if_fail (a_this, NULL);
@@ -535,7 +535,7 @@ cr_declaration_list_to_string (CRDeclaration * a_this, gulong a_indent)
 {
         CRDeclaration *cur = NULL;
         GString *stringue = NULL;
-        guchar *str = NULL,
+        gchar *str = NULL,
                 *result = NULL;
 
         g_return_val_if_fail (a_this, NULL);
@@ -555,7 +555,7 @@ cr_declaration_list_to_string (CRDeclaration * a_this, gulong a_indent)
                 g_string_free (stringue, FALSE);
         }
 
-        return result;
+        return (guchar *)result;
 }
 
 /**
@@ -570,7 +570,7 @@ cr_declaration_list_to_string2 (CRDeclaration * a_this,
 {
         CRDeclaration *cur = NULL;
         GString *stringue = NULL;
-        guchar *str = NULL,
+        gchar *str = NULL,
                 *result = NULL;
 
         g_return_val_if_fail (a_this, NULL);
@@ -604,7 +604,7 @@ cr_declaration_list_to_string2 (CRDeclaration * a_this,
                 g_string_free (stringue, FALSE);
         }
 
-        return result;
+        return (guchar *)result;
 }
 
 /**
@@ -666,7 +666,7 @@ cr_declaration_get_by_prop_name (CRDeclaration * a_this,
                    && cur->property->stryng
                    && cur->property->stryng->str) {
                        if (!strcmp (cur->property->stryng->str, 
-                                    a_prop)) {
+                                    (char *)a_prop)) {
                                return cur;
                        }
                }