summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDodji Seketeli <dodji@src.gnome.org>2004-04-18 15:26:47 +0000
committerDodji Seketeli <dodji@src.gnome.org>2004-04-18 15:26:47 +0000
commit6d08258366de84957200071d2ec6aef2c027529c (patch)
tree41690fa2b005f166f6ee92e2915ef48f28d8b925 /src
parent5d0671c2a41511e78b60f52ad25ac9748fbfd28a (diff)
downloadlibcroco-6d08258366de84957200071d2ec6aef2c027529c.tar.gz
Changes from arch/CVS synchronization
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am8
-rw-r--r--src/cr-additional-sel.c132
-rw-r--r--src/cr-additional-sel.h20
-rw-r--r--src/cr-attr-sel.c43
-rw-r--r--src/cr-attr-sel.h43
-rw-r--r--src/cr-declaration.c68
-rw-r--r--src/cr-declaration.h37
-rw-r--r--src/cr-doc-handler.c32
-rw-r--r--src/cr-doc-handler.h75
-rw-r--r--src/cr-fonts.c98
-rw-r--r--src/cr-fonts.h12
-rw-r--r--src/cr-input.c51
-rw-r--r--src/cr-input.h16
-rw-r--r--src/cr-num.c17
-rw-r--r--src/cr-num.h13
-rw-r--r--src/cr-om-parser.c167
-rw-r--r--src/cr-parser.c794
-rw-r--r--src/cr-parser.h112
-rw-r--r--src/cr-prop-list.c23
-rw-r--r--src/cr-prop-list.h12
-rw-r--r--src/cr-pseudo.c29
-rw-r--r--src/cr-pseudo.h26
-rw-r--r--src/cr-rgb.c77
-rw-r--r--src/cr-rgb.h9
-rw-r--r--src/cr-sel-eng.c626
-rw-r--r--src/cr-sel-eng.h15
-rw-r--r--src/cr-selector.c14
-rw-r--r--src/cr-selector.h46
-rw-r--r--src/cr-simple-sel.c68
-rw-r--r--src/cr-simple-sel.h42
-rw-r--r--src/cr-statement.c267
-rw-r--r--src/cr-statement.h34
-rw-r--r--src/cr-style.c1003
-rw-r--r--src/cr-style.h35
-rw-r--r--src/cr-stylesheet.c2
-rw-r--r--src/cr-term.c264
-rw-r--r--src/cr-term.h75
-rw-r--r--src/cr-tknzr.c695
-rw-r--r--src/cr-tknzr.h94
-rw-r--r--src/cr-token.c77
-rw-r--r--src/cr-token.h157
-rw-r--r--src/cr-utils.c36
-rw-r--r--src/cr-utils.h9
43 files changed, 3021 insertions, 2452 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index ee4d2c9..6bbaac0 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -25,6 +25,8 @@ cr-fonts.h \
cr-sel-eng.h \
cr-style.h \
cr-prop-list.h \
+cr-parsing-location.h \
+cr-string.h \
libcroco-config.h
@@ -77,7 +79,11 @@ cr-sel-eng.h \
cr-fonts.c \
cr-fonts.h \
cr-prop-list.c \
-cr-prop-list.h
+cr-prop-list.h \
+cr-parsing-location.c \
+cr-parsing-location.h \
+cr-string.c \
+cr-string.h
lib_LTLIBRARIES=libcroco.la
libcroco_la_SOURCES= $(SRCS)
diff --git a/src/cr-additional-sel.c b/src/cr-additional-sel.c
index c1fe960..9f511af 100644
--- a/src/cr-additional-sel.c
+++ b/src/cr-additional-sel.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
+ *
*/
#include "cr-additional-sel.h"
@@ -78,12 +76,12 @@ 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)
+ CRString * 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);
+ cr_string_destroy (a_this->content.class_name);
}
a_this->content.class_name = a_class_name;
@@ -97,12 +95,12 @@ 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, CRString * 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);
+ cr_string_destroy (a_this->content.id_name);
}
a_this->content.id_name = a_id;
@@ -222,9 +220,8 @@ cr_additional_sel_to_string (CRAdditionalSel * a_this)
if (cur->content.class_name) {
name = g_strndup
- (cur->content.class_name->str,
- cur->content.class_name->
- len);
+ (cur->content.class_name->stryng->str,
+ cur->content.class_name->stryng->len);
if (name) {
g_string_append_printf
@@ -243,8 +240,8 @@ cr_additional_sel_to_string (CRAdditionalSel * a_this)
if (cur->content.class_name) {
name = g_strndup
- (cur->content.id_name->str,
- cur->content.id_name->len);
+ (cur->content.id_name->stryng->str,
+ cur->content.id_name->stryng->len);
if (name) {
g_string_append_printf
@@ -280,7 +277,7 @@ cr_additional_sel_to_string (CRAdditionalSel * a_this)
if (cur->content.attr_sel) {
guchar *tmp_str = NULL;
- g_string_append_printf (str_buf, "[");
+ g_string_append_c (str_buf, '[');
tmp_str = cr_attr_sel_to_string
(cur->content.attr_sel);
if (tmp_str) {
@@ -306,6 +303,105 @@ cr_additional_sel_to_string (CRAdditionalSel * a_this)
return result;
}
+guchar *
+cr_additional_sel_one_to_string (CRAdditionalSel *a_this)
+{
+ guchar *result = NULL;
+ GString *str_buf = NULL;
+
+ g_return_val_if_fail (a_this, NULL) ;
+
+ str_buf = g_string_new (NULL) ;
+
+ switch (a_this->type) {
+ case CLASS_ADD_SELECTOR:
+ {
+ guchar *name = NULL;
+
+ if (a_this->content.class_name) {
+ name = g_strndup
+ (a_this->content.class_name->stryng->str,
+ a_this->content.class_name->stryng->len);
+
+ if (name) {
+ g_string_append_printf
+ (str_buf, ".%s",
+ name);
+ g_free (name);
+ name = NULL;
+ }
+ }
+ }
+ break;
+
+ case ID_ADD_SELECTOR:
+ {
+ guchar *name = NULL;
+
+ if (a_this->content.class_name) {
+ name = g_strndup
+ (a_this->content.id_name->stryng->str,
+ a_this->content.id_name->stryng->len);
+
+ if (name) {
+ g_string_append_printf
+ (str_buf, "#%s",
+ name);
+ g_free (name);
+ name = NULL;
+ }
+ }
+ }
+
+ break;
+
+ case PSEUDO_CLASS_ADD_SELECTOR:
+ {
+ if (a_this->content.pseudo) {
+ guchar *tmp_str = NULL;
+
+ tmp_str = cr_pseudo_to_string
+ (a_this->content.pseudo);
+ if (tmp_str) {
+ g_string_append_printf
+ (str_buf, ":%s",
+ tmp_str);
+ g_free (tmp_str);
+ tmp_str = NULL;
+ }
+ }
+ }
+ break;
+
+ case ATTRIBUTE_ADD_SELECTOR:
+ if (a_this->content.attr_sel) {
+ guchar *tmp_str = NULL;
+
+ g_string_append_printf (str_buf, "[");
+ tmp_str = cr_attr_sel_to_string
+ (a_this->content.attr_sel);
+ if (tmp_str) {
+ g_string_append_printf
+ (str_buf, "%s]", tmp_str);
+ g_free (tmp_str);
+ tmp_str = NULL;
+ }
+ }
+ break;
+
+ default:
+ break;
+ }
+
+ if (str_buf) {
+ result = str_buf->str;
+ g_string_free (str_buf, FALSE);
+ str_buf = NULL;
+ }
+
+ return result;
+}
+
/**
*Dumps the current instance of #CRAdditionalSel to a file
*@param a_this the "this pointer" of the current instance of
@@ -341,7 +437,7 @@ cr_additional_sel_destroy (CRAdditionalSel * a_this)
switch (a_this->type) {
case CLASS_ADD_SELECTOR:
- g_string_free (a_this->content.class_name, TRUE);
+ cr_string_destroy (a_this->content.class_name);
a_this->content.class_name = NULL;
break;
@@ -351,7 +447,7 @@ cr_additional_sel_destroy (CRAdditionalSel * a_this)
break;
case ID_ADD_SELECTOR:
- g_string_free (a_this->content.id_name, TRUE);
+ cr_string_destroy (a_this->content.id_name);
a_this->content.id_name = NULL;
break;
diff --git a/src/cr-additional-sel.h b/src/cr-additional-sel.h
index 04992c3..1ec1aa0 100644
--- a/src/cr-additional-sel.h
+++ b/src/cr-additional-sel.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji at seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,11 +16,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * Author: Dodji Seketeli
+ * See the COPYRIGHTS file for copyright information.
*/
-/*
- *$Id$
- */
/**
*@file
@@ -37,6 +35,7 @@
#include "cr-utils.h"
#include "cr-attr-sel.h"
#include "cr-pseudo.h"
+#include "cr-additional-sel.h"
G_BEGIN_DECLS
@@ -51,8 +50,8 @@ enum AddSelectorType
union CRAdditionalSelectorContent
{
- GString *class_name ;
- GString *id_name ;
+ CRString *class_name ;
+ CRString *id_name ;
CRPseudo *pseudo ;
CRAttrSel *attr_sel ;
} ;
@@ -75,6 +74,7 @@ struct _CRAdditionalSel
CRAdditionalSel * next ;
CRAdditionalSel * prev ;
+ CRParsingLocation location ;
} ;
CRAdditionalSel * cr_additional_sel_new (void) ;
@@ -85,10 +85,10 @@ CRAdditionalSel * cr_additional_sel_append (CRAdditionalSel *a_this,
CRAdditionalSel *a_sel) ;
void cr_additional_sel_set_class_name (CRAdditionalSel *a_this,
- GString *a_class_name) ;
+ CRString *a_class_name) ;
void cr_additional_sel_set_id_name (CRAdditionalSel *a_this,
- GString *a_id) ;
+ CRString *a_id) ;
void cr_additional_sel_set_pseudo (CRAdditionalSel *a_this,
CRPseudo *a_pseudo) ;
@@ -101,6 +101,8 @@ CRAdditionalSel * cr_additional_sel_prepend (CRAdditionalSel *a_this,
guchar * cr_additional_sel_to_string (CRAdditionalSel *a_this) ;
+guchar * cr_additional_sel_one_to_string (CRAdditionalSel *a_this) ;
+
void cr_additional_sel_dump (CRAdditionalSel *a_this, FILE *a_fp) ;
void cr_additional_sel_destroy (CRAdditionalSel *a_this) ;
diff --git a/src/cr-attr-sel.c b/src/cr-attr-sel.c
index 4deb63c..cf048d1 100644
--- a/src/cr-attr-sel.c
+++ b/src/cr-attr-sel.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * See COPYRIGHTS file for copyrights information.
*/
#include <stdio.h>
@@ -64,9 +60,12 @@ 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);
+ 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) ;
+ 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;
@@ -84,9 +83,11 @@ 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);
+ 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;
@@ -107,15 +108,16 @@ cr_attr_sel_to_string (CRAttrSel * a_this)
for (cur = a_this; cur; cur = cur->next) {
if (cur->prev) {
- g_string_append_printf (str_buf, " ");
+ g_string_append_c (str_buf, ' ');
}
if (cur->name) {
guchar *name = NULL;
- name = g_strndup (cur->name->str, cur->name->len);
+ name = g_strndup (cur->name->stryng->str,
+ cur->name->stryng->len);
if (name) {
- g_string_append_printf (str_buf, "%s", name);
+ g_string_append (str_buf, name);
g_free (name);
name = NULL;
}
@@ -124,24 +126,23 @@ cr_attr_sel_to_string (CRAttrSel * a_this)
if (cur->value) {
guchar *value = NULL;
- value = g_strndup (cur->value->str, cur->value->len);
+ value = g_strndup (cur->value->stryng->str,
+ cur->value->stryng->len);
if (value) {
switch (cur->match_way) {
case SET:
break;
case EQUALS:
- g_string_append_printf (str_buf, "=");
+ g_string_append_c (str_buf, '=');
break;
case INCLUDES:
- g_string_append_printf
- (str_buf, "~=");
+ g_string_append (str_buf, "~=");
break;
case DASHMATCH:
- g_string_append_printf
- (str_buf, "|=");
+ g_string_append (str_buf, "|=");
break;
default:
@@ -199,12 +200,12 @@ cr_attr_sel_destroy (CRAttrSel * a_this)
g_return_if_fail (a_this);
if (a_this->name) {
- g_string_free (a_this->name, TRUE);
+ cr_string_destroy (a_this->name);
a_this->name = NULL;
}
if (a_this->value) {
- g_string_free (a_this->value, TRUE);
+ cr_string_destroy (a_this->value);
a_this->value = NULL;
}
diff --git a/src/cr-attr-sel.h b/src/cr-attr-sel.h
index fd18635..9cc03d3 100644
--- a/src/cr-attr-sel.h
+++ b/src/cr-attr-sel.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,18 +16,19 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
-/*
- *$Id$
- */
+#ifndef __CR_ATTR_SEL_H__
+#define __CR_ATTR_SEL_H__
#include <stdio.h>
#include <glib.h>
#include "cr-utils.h"
-
-#ifndef __CR_ATTR_SEL_H__
-#define __CR_ATTR_SEL_H__
+#include "cr-parsing-location.h"
+#include "cr-string.h"
G_BEGIN_DECLS
@@ -48,31 +47,27 @@ enum AttrMatchWay
struct _CRAttrSel
{
- GString *name ;
- GString *value ;
+ CRString *name ;
+ CRString *value ;
enum AttrMatchWay match_way ;
CRAttrSel *next ;
CRAttrSel *prev ;
+ CRParsingLocation location ;
} ;
-CRAttrSel *
-cr_attr_sel_new (void) ;
+CRAttrSel * cr_attr_sel_new (void) ;
+
+enum CRStatus cr_attr_sel_append_attr_sel (CRAttrSel * a_this,
+ CRAttrSel *a_new) ;
-enum CRStatus
-cr_attr_sel_append_attr_sel (CRAttrSel * a_this,
- CRAttrSel *a_new) ;
-enum CRStatus
-cr_attr_sel_prepend_attr_sel (CRAttrSel *a_this,
- CRAttrSel *a_attr_sel) ;
+enum CRStatus cr_attr_sel_prepend_attr_sel (CRAttrSel *a_this,
+ CRAttrSel *a_attr_sel) ;
-guchar *
-cr_attr_sel_to_string (CRAttrSel *a_this) ;
+guchar * cr_attr_sel_to_string (CRAttrSel *a_this) ;
-void
-cr_attr_sel_dump (CRAttrSel *a_this, FILE *a_fp) ;
+void cr_attr_sel_dump (CRAttrSel *a_this, FILE *a_fp) ;
-void
-cr_attr_sel_destroy (CRAttrSel *a_this) ;
+void cr_attr_sel_destroy (CRAttrSel *a_this) ;
G_END_DECLS
diff --git a/src/cr-declaration.c b/src/cr-declaration.c
index 77e58bd..a1ff0d2 100644
--- a/src/cr-declaration.c
+++ b/src/cr-declaration.c
@@ -17,12 +17,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
- *See COPYRIGHTS file for copyright information.
+ * Author: Dodji Seketeli.
+ * See COPYRIGHTS file for copyright information.
*/
-/*
- *$Id$
- */
#include <string.h>
#include "cr-declaration.h"
@@ -64,7 +62,7 @@ dump (CRDeclaration * a_this, FILE * a_fp, glong a_indent)
*/
CRDeclaration *
cr_declaration_new (CRStatement * a_statement,
- GString * a_property, CRTerm * a_value)
+ CRString * a_property, CRTerm * a_value)
{
CRDeclaration *result = NULL;
@@ -111,7 +109,7 @@ cr_declaration_parse_from_buf (CRStatement * a_statement,
{
enum CRStatus status = CR_OK;
CRTerm *value = NULL;
- GString *property = NULL;
+ CRString *property = NULL;
CRDeclaration *result = NULL;
CRParser *parser = NULL;
gboolean important = FALSE;
@@ -148,7 +146,7 @@ cr_declaration_parse_from_buf (CRStatement * a_statement,
}
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
@@ -174,7 +172,7 @@ cr_declaration_parse_list_from_buf (const guchar * a_str,
enum CRStatus status = CR_OK;
CRTerm *value = NULL;
- GString *property = NULL;
+ CRString *property = NULL;
CRDeclaration *result = NULL,
*cur_decl = NULL;
CRParser *parser = NULL;
@@ -254,7 +252,7 @@ cr_declaration_parse_list_from_buf (const guchar * a_str,
}
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
@@ -404,7 +402,7 @@ cr_declaration_prepend (CRDeclaration * a_this, CRDeclaration * a_new)
*/
CRDeclaration *
cr_declaration_append2 (CRDeclaration * a_this,
- GString * a_prop, CRTerm * a_value)
+ CRString * a_prop, CRTerm * a_value)
{
CRDeclaration *new_elem = NULL;
@@ -475,17 +473,20 @@ cr_declaration_to_string (CRDeclaration * a_this, gulong a_indent)
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
+ stringue = g_string_new (NULL);
+
+ if (a_this->property
+ && a_this->property->stryng
+ && a_this->property->stryng->str) {
+ str = g_strndup (a_this->property->stryng->str,
+ a_this->property->stryng->len);
+ if (str) {
+ cr_utils_dump_n_chars2 (' ', stringue,
+ a_indent);
+ g_string_append (stringue, str);
+ g_free (str);
+ str = NULL;
+ } else
goto error;
if (a_this->value) {
@@ -584,15 +585,15 @@ cr_declaration_list_to_string2 (CRDeclaration * a_this,
g_string_append_printf (stringue,
"%s;\n", str);
else
- g_string_append_printf (stringue,
- "%s", str);
+ g_string_append (stringue,
+ str);
} else {
if (cur->next)
g_string_append_printf (stringue,
"%s;", str);
else
- g_string_append_printf (stringue,
- "%s", str);
+ g_string_append (stringue,
+ str);
}
g_free (str);
} else
@@ -660,9 +661,16 @@ cr_declaration_get_by_prop_name (CRDeclaration * a_this,
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;
+ for (cur = a_this; cur; cur = cur->next) {
+ if (cur->property
+ && cur->property->stryng
+ && cur->property->stryng->str) {
+ if (!strcmp (cur->property->stryng->str,
+ a_prop)) {
+ return cur;
+ }
+ }
+ }
return NULL;
}
@@ -719,7 +727,7 @@ cr_declaration_destroy (CRDeclaration * a_this)
*/
for (cur = a_this; cur && cur->next; cur = cur->next) {
if (cur->property) {
- g_string_free (cur->property, TRUE);
+ cr_string_destroy (cur->property);
cur->property = NULL;
}
@@ -731,7 +739,7 @@ cr_declaration_destroy (CRDeclaration * a_this)
if (cur) {
if (cur->property) {
- g_string_free (cur->property, TRUE);
+ cr_string_destroy (cur->property);
cur->property = NULL;
}
diff --git a/src/cr-declaration.h b/src/cr-declaration.h
index eed3a3d..0052395 100644
--- a/src/cr-declaration.h
+++ b/src/cr-declaration.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * See the COPYRIGHTS file for copyright information.
*/
#ifndef __CR_DECLARATION_H__
@@ -30,6 +26,7 @@
#include <stdio.h>
#include "cr-utils.h"
#include "cr-term.h"
+#include "cr-parsing-location.h"
G_BEGIN_DECLS
@@ -50,7 +47,7 @@ typedef struct _CRDeclaration CRDeclaration ;
struct _CRDeclaration
{
/**The property.*/
- GString *property ;
+ CRString *property ;
/**The value of the property.*/
CRTerm *value ;
@@ -69,7 +66,8 @@ struct _CRDeclaration
glong ref_count ;
- /*reserved for future usage*/
+ CRParsingLocation location ;
+ /*reserved for future usage*/
gpointer rfu0 ;
gpointer rfu1 ;
gpointer rfu2 ;
@@ -78,7 +76,7 @@ struct _CRDeclaration
CRDeclaration * cr_declaration_new (CRStatement *a_statement,
- GString *a_property,
+ CRString *a_property,
CRTerm *a_value) ;
@@ -89,17 +87,21 @@ CRDeclaration * cr_declaration_parse_from_buf (CRStatement *a_statement,
CRDeclaration * cr_declaration_parse_list_from_buf (const guchar *a_str,
enum CREncoding a_enc) ;
-CRDeclaration * cr_declaration_append (CRDeclaration *a_this, CRDeclaration *a_new) ;
+CRDeclaration * cr_declaration_append (CRDeclaration *a_this,
+ CRDeclaration *a_new) ;
-CRDeclaration * cr_declaration_append2 (CRDeclaration *a_this, GString *a_prop,
+CRDeclaration * cr_declaration_append2 (CRDeclaration *a_this,
+ CRString *a_prop,
CRTerm *a_value) ;
-CRDeclaration * cr_declaration_prepend (CRDeclaration *a_this, CRDeclaration *a_new) ;
+CRDeclaration * cr_declaration_prepend (CRDeclaration *a_this,
+ CRDeclaration *a_new) ;
CRDeclaration * cr_declaration_unlink (CRDeclaration * a_decl) ;
void
-cr_declaration_dump (CRDeclaration *a_this, FILE *a_fp, glong a_indent,
+cr_declaration_dump (CRDeclaration *a_this,
+ FILE *a_fp, glong a_indent,
gboolean a_one_per_line) ;
void cr_declaration_dump_one (CRDeclaration *a_this,
@@ -107,17 +109,22 @@ void cr_declaration_dump_one (CRDeclaration *a_this,
gint cr_declaration_nr_props (CRDeclaration *a_this) ;
-CRDeclaration * cr_declaration_get_from_list (CRDeclaration *a_this, int itemnr) ;
+CRDeclaration * cr_declaration_get_from_list (CRDeclaration *a_this,
+ int itemnr) ;
-CRDeclaration * cr_declaration_get_by_prop_name (CRDeclaration *a_this, const guchar *a_str) ;
+CRDeclaration * cr_declaration_get_by_prop_name (CRDeclaration *a_this,
+ const guchar *a_str) ;
gchar * cr_declaration_to_string (CRDeclaration *a_this,
gulong a_indent) ;
+
guchar * cr_declaration_list_to_string (CRDeclaration *a_this,
gulong a_indent) ;
+
guchar * cr_declaration_list_to_string2 (CRDeclaration *a_this,
gulong a_indent,
gboolean a_one_decl_per_line) ;
+
void cr_declaration_ref (CRDeclaration *a_this) ;
gboolean cr_declaration_unref (CRDeclaration *a_this) ;
diff --git a/src/cr-doc-handler.c b/src/cr-doc-handler.c
index 6ff51e6..2780b6a 100644
--- a/src/cr-doc-handler.c
+++ b/src/cr-doc-handler.c
@@ -20,8 +20,9 @@
* See COPRYRIGHTS file for copyright information.
*/
-#include "cr-doc-handler.h"
#include <string.h>
+#include "cr-doc-handler.h"
+#include "cr-parser.h"
/**
*@file
@@ -31,8 +32,10 @@
*to custom values.
*/
+#define PRIVATE(obj) (obj)->priv
+
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,11 +45,16 @@ struct _CRDocHandlerPriv {
*/
gpointer context;
- /**
+ /**
*The place where #CROMParser puts the result of its parsing, if
*any.
*/
gpointer result;
+ /**
+ *a pointer to the parser used to parse
+ *the current document.
+ */
+ CRParser *parser ;
};
/**
@@ -208,8 +216,7 @@ cr_doc_handler_unref (CRDocHandler * a_this)
cr_doc_handler_destroy (a_this);
return TRUE;
}
-
- return FALSE;
+ return FALSE ;
}
/**
@@ -228,3 +235,18 @@ cr_doc_handler_destroy (CRDocHandler * a_this)
}
g_free (a_this);
}
+
+/**
+ *Associates a parser to the current document handler
+ *@param a_this the current instance of document handler.
+ *@param a_parser the parser to associate.
+ */
+void
+cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
+ gpointer a_parser)
+{
+ g_return_if_fail (a_this && PRIVATE (a_this)
+ && a_parser) ;
+
+ PRIVATE (a_this)->parser = a_parser ;
+}
diff --git a/src/cr-doc-handler.h b/src/cr-doc-handler.h
index aa5ccd0..704f186 100644
--- a/src/cr-doc-handler.h
+++ b/src/cr-doc-handler.h
@@ -79,7 +79,9 @@ struct _CRDocHandler
*@param a_this the document handler.
*@param a_charset the declared charset.
*/
- void (*charset) (CRDocHandler *a_this, GString *a_charset) ;
+ void (*charset) (CRDocHandler *a_this,
+ CRString *a_charset,
+ CRParsingLocation *a_charset_sym_location) ;
/**
*Is called to notify an import statement in
@@ -90,17 +92,20 @@ struct _CRDocHandler
*destination media for style information.
*@param a_uri the uri of the imported style sheet.
*@param a_uri_default_ns the default namespace of URI
+ *@param a_location the parsing location of the '@import'
+ *keyword.
*of the imported style sheet.
*/
void (*import_style) (CRDocHandler *a_this,
GList *a_media_list,
- GString *a_uri,
- GString *a_uri_default_ns) ;
+ CRString *a_uri,
+ CRString *a_uri_default_ns,
+ CRParsingLocation *a_location) ;
void (*import_style_result) (CRDocHandler *a_this,
GList *a_media_list,
- GString *a_uri,
- GString *a_uri_default_ns,
+ CRString *a_uri,
+ CRString *a_uri_default_ns,
CRStyleSheet *a_sheet) ;
/**
@@ -109,10 +114,12 @@ struct _CRDocHandler
*@param a_this the current instance of #CRDocHandler.
*@param a_prefix the prefix of the namespace.
*@param a_uri the uri of the namespace.
+ *@param a_location the location of the "@namespace" keyword.
*/
void (*namespace_declaration) (CRDocHandler *a_this,
- GString *a_prefix,
- GString *a_uri) ;
+ CRString *a_prefix,
+ CRString *a_uri,
+ CRParsingLocation *a_location) ;
/**
*Is called to notify a comment.
@@ -121,18 +128,16 @@ struct _CRDocHandler
*@param a_comment the comment.
*/
void (*comment) (CRDocHandler *a_this,
- GString *a_comment) ;
+ CRString *a_comment) ;
/**
*Is called to notify the beginning of a rule
*statement.
*@param a_this the current instance of #CRDocHandler.
*@param a_selector_list the list of selectors that precedes
- *the rule declarations. The GList named a_selector_list
- *is a chained list of instances of #CRSimpleSel
- *
+ *the rule declarations.
*/
- void (*start_selector) (CRDocHandler * a_this,
+ void (*start_selector) (CRDocHandler * a_this,
CRSelector *a_selector_list) ;
/**
@@ -158,7 +163,7 @@ struct _CRDocHandler
*
*/
void (*property) (CRDocHandler *a_this,
- GString *a_name,
+ CRString *a_name,
CRTerm *a_expression,
gboolean a_is_important) ;
/**
@@ -170,8 +175,11 @@ struct _CRDocHandler
*
*@param a_this a pointer to the current instance of
*#CRDocHandler.
+ *@param a_location the parsing location of the "@font-face"
+ *keyword.
*/
- void (*start_font_face) (CRDocHandler *a_this) ;
+ void (*start_font_face) (CRDocHandler *a_this,
+ CRParsingLocation *a_location) ;
/**
*Is called to notify the end of a font face statement.
@@ -189,12 +197,14 @@ struct _CRDocHandler
*event.
*@param a_this a pointer to the current instance of
*#CRDocHandler.
- *@param a_media_list a double linked list of GString * objects.
- *Each GString objects is actually a destination media for
+ *@param a_media_list a double linked list of
+ #CRString * objects.
+ *Each CRString objects is actually a destination media for
*the style information.
*/
void (*start_media) (CRDocHandler *a_this,
- GList *a_media_list) ;
+ GList *a_media_list,
+ CRParsingLocation *a_location) ;
/**
*Is called to notify the end of a media statement.
@@ -217,10 +227,12 @@ struct _CRDocHandler
*#CRDocHandler.
*@param a_name the name of the page (if any, null otherwise).
*@param a_pseudo_page the pseudo page (if any, null otherwise).
+ *@param a_location the parsing location of the "@page" keyword.
*/
void (*start_page) (CRDocHandler *a_this,
- GString *a_name,
- GString *a_pseudo_page) ;
+ CRString *a_name,
+ CRString *a_pseudo_page,
+ CRParsingLocation *a_location) ;
/**
*Is called to notify the end of a page statement.
@@ -230,15 +242,15 @@ struct _CRDocHandler
*@parap a_pseudo_page the pseudo page (if any, null otherwise).
*/
void (*end_page) (CRDocHandler *a_this,
- GString *a_name,
- GString *pseudo_page) ;
+ CRString *a_name,
+ CRString *pseudo_page) ;
/**
*Is Called to notify an unknown at-rule not supported
*by this parser.
*/
void (*ignorable_at_rule) (CRDocHandler *a_this,
- GString *a_name) ;
+ CRString *a_name) ;
/**
*Is called to notify a parsing error. After this error
@@ -262,22 +274,21 @@ struct _CRDocHandler
CRDocHandler * cr_doc_handler_new (void) ;
-enum CRStatus
-cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result) ;
+enum CRStatus cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result) ;
-enum CRStatus
-cr_doc_handler_get_result (CRDocHandler *a_this, gpointer * a_result) ;
+enum CRStatus cr_doc_handler_get_result (CRDocHandler *a_this, gpointer * a_result) ;
-enum CRStatus
-cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt) ;
+enum CRStatus cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt) ;
-enum CRStatus
-cr_doc_handler_get_ctxt (CRDocHandler *a_this, gpointer * a_ctxt) ;
+enum CRStatus cr_doc_handler_get_ctxt (CRDocHandler *a_this, gpointer * a_ctxt) ;
-enum CRStatus
-cr_doc_handler_set_default_sac_handler (CRDocHandler *a_this) ;
+enum CRStatus cr_doc_handler_set_default_sac_handler (CRDocHandler *a_this) ;
+
+void cr_doc_handler_associate_a_parser (CRDocHandler *a_this,
+ gpointer a_parser) ;
void cr_doc_handler_ref (CRDocHandler *a_this) ;
+
gboolean cr_doc_handler_unref (CRDocHandler *a_this) ;
void cr_doc_handler_destroy (CRDocHandler *a_this) ;
diff --git a/src/cr-fonts.c b/src/cr-fonts.c
index a99396f..9d3f345 100644
--- a/src/cr-fonts.c
+++ b/src/cr-fonts.c
@@ -40,7 +40,7 @@ cr_font_family_to_string_real (CRFontFamily * a_this,
}
if (!a_this) {
- g_string_append_printf (*a_string, "NULL");
+ g_string_append (*a_string, "NULL");
return CR_OK;
}
@@ -96,28 +96,28 @@ cr_predefined_absolute_font_size_to_string (enum CRPredefinedAbsoluteFontSize
switch (a_code) {
case FONT_SIZE_XX_SMALL:
- str = (gchar *) "font-size-xx-small";
+ str = (gchar *) "xx-small";
break;
case FONT_SIZE_X_SMALL:
- str = (gchar *) "font-size-x-small";
+ str = (gchar *) "x-small";
break;
case FONT_SIZE_SMALL:
- str = (gchar *) "font-size-small";
+ str = (gchar *) "small";
break;
case FONT_SIZE_MEDIUM:
- str = (gchar *) "font-size-medium";
+ str = (gchar *) "medium";
break;
case FONT_SIZE_LARGE:
- str = (gchar *) "font-size-large";
+ str = (gchar *) "large";
break;
case FONT_SIZE_X_LARGE:
- str = (gchar *) "font-size-x-large";
+ str = (gchar *) "x-large";
break;
case FONT_SIZE_XX_LARGE:
- str = (gchar *) "font-size-xx-large";
+ str = (gchar *) "xx-large";
break;
default:
- str = (gchar *) "unknown predefined absolute font size value";
+ str = (gchar *) "unknown absolute font size value";
}
return str;
}
@@ -129,10 +129,10 @@ cr_relative_font_size_to_string (enum CRRelativeFontSize a_code)
switch (a_code) {
case FONT_SIZE_LARGER:
- str = (gchar *) "font-size-larger";
+ str = (gchar *) "larger";
break;
case FONT_SIZE_SMALLER:
- str = (gchar *) "font-size-smaller";
+ str = (gchar *) "smaller";
break;
default:
str = (gchar *) "unknown relative font size value";
@@ -376,7 +376,7 @@ cr_font_size_to_string (CRFontSize * a_this)
(a_this->value.relative));
break;
case INHERITED_FONT_SIZE:
- str = g_strdup ("inherited");
+ str = g_strdup ("inherit");
break;
default:
break;
@@ -397,16 +397,16 @@ cr_font_size_adjust_to_string (CRFontSizeAdjust * a_this)
switch (a_this->type) {
case FONT_SIZE_ADJUST_NONE:
- str = g_strdup ("font-size-adjust-none");
+ str = g_strdup ("none");
break;
case FONT_SIZE_ADJUST_NUMBER:
if (a_this->num)
str = cr_num_to_string (a_this->num);
else
- str = g_strdup ("font-size-adjust-NULL");
+ str = g_strdup ("unknow font-size-adjust property value"); // Should raise an error no?
break;
case FONT_SIZE_ADJUST_INHERIT:
- str = g_strdup ("font-size-adjust-inherit");
+ str = g_strdup ("inherit");
}
return str;
}
@@ -418,19 +418,19 @@ cr_font_style_to_string (enum CRFontStyle a_code)
switch (a_code) {
case FONT_STYLE_NORMAL:
- str = (gchar *) "font-style-normal";
+ str = (gchar *) "normal";
break;
case FONT_STYLE_ITALIC:
- str = (gchar *) "font-style-italic";
+ str = (gchar *) "italic";
break;
case FONT_STYLE_OBLIQUE:
- str = (gchar *) "font-style-oblique";
+ str = (gchar *) "oblique";
break;
case FONT_STYLE_INHERIT:
- str = (gchar *) "font-style-inherit";
+ str = (gchar *) "inherit";
break;
default:
- str = (gchar *) "font-style";
+ str = (gchar *) "unknown font style value";
break;
}
return str;
@@ -443,13 +443,13 @@ cr_font_variant_to_string (enum CRFontVariant a_code)
switch (a_code) {
case FONT_VARIANT_NORMAL:
- str = (gchar *) "font-variant-normal";
+ str = (gchar *) "normal";
break;
case FONT_VARIANT_SMALL_CAPS:
- str = (gchar *) "font-variant-small-caps";
+ str = (gchar *) "small-caps";
break;
case FONT_VARIANT_INHERIT:
- str = (gchar *) "font-variant-inherent";
+ str = (gchar *) "inherit";
break;
}
return str;
@@ -462,46 +462,46 @@ cr_font_weight_to_string (enum CRFontWeight a_code)
switch (a_code) {
case FONT_WEIGHT_NORMAL:
- str = (gchar *) "font-weight-normal";
+ str = (gchar *) "normal";
break;
case FONT_WEIGHT_BOLD:
- str = (gchar *) "font-weight-bold";
+ str = (gchar *) "bold";
break;
case FONT_WEIGHT_BOLDER:
- str = (gchar *) "font-weight-bolder";
+ str = (gchar *) "bolder";
break;
case FONT_WEIGHT_LIGHTER:
- str = (gchar *) "font-weight-lighter";
+ str = (gchar *) "lighter";
break;
case FONT_WEIGHT_100:
- str = (gchar *) "font-weight-100";
+ str = (gchar *) "100";
break;
case FONT_WEIGHT_200:
- str = (gchar *) "font-weight-200";
+ str = (gchar *) "200";
break;
case FONT_WEIGHT_300:
- str = (gchar *) "font-weight-300";
+ str = (gchar *) "300";
break;
case FONT_WEIGHT_400:
- str = (gchar *) "font-weight-400";
+ str = (gchar *) "400";
break;
case FONT_WEIGHT_500:
- str = (gchar *) "font-weight-500";
+ str = (gchar *) "500";
break;
case FONT_WEIGHT_600:
- str = (gchar *) "font-weight-600";
+ str = (gchar *) "600";
break;
case FONT_WEIGHT_700:
- str = (gchar *) "font-weight-700";
+ str = (gchar *) "700";
break;
case FONT_WEIGHT_800:
- str = (gchar *) "font-weight-800";
+ str = (gchar *) "800";
break;
case FONT_WEIGHT_900:
- str = (gchar *) "font-weight-900";
+ str = (gchar *) "900";
break;
case FONT_WEIGHT_INHERIT:
- str = (gchar *) "font-weight-inherit";
+ str = (gchar *) "inherit";
break;
default:
str = (gchar *) "unknown font-weight property value";
@@ -517,40 +517,40 @@ cr_font_stretch_to_string (enum CRFontStretch a_code)
switch (a_code) {
case FONT_STRETCH_NORMAL:
- str = (gchar *) "font-stretch-normal";
+ str = (gchar *) "normal";
break;
case FONT_STRETCH_WIDER:
- str = (gchar *) "font-stretch-wider";
+ str = (gchar *) "wider";
break;
case FONT_STRETCH_NARROWER:
- str = (gchar *) "font-stretch-narrower";
+ str = (gchar *) "narrower";
break;
case FONT_STRETCH_ULTRA_CONDENSED:
- str = (gchar *) "font-stretch-ultra-condensed";
+ str = (gchar *) "ultra-condensed";
break;
case FONT_STRETCH_EXTRA_CONDENSED:
- str = (gchar *) "font-stretch-extra-condensed";
+ str = (gchar *) "extra-condensed";
break;
case FONT_STRETCH_CONDENSED:
- str = (gchar *) "font-stretch-condensed";
+ str = (gchar *) "condensed";
break;
case FONT_STRETCH_SEMI_CONDENSED:
- str = (gchar *) "font-stretch-semi-condensed";
+ str = (gchar *) "semi-condensed";
break;
case FONT_STRETCH_SEMI_EXPANDED:
- str = (gchar *) "font-stretch-semi-expanded";
+ str = (gchar *) "semi-expanded";
break;
case FONT_STRETCH_EXPANDED:
- str = (gchar *) "font-stretch-expanded";
+ str = (gchar *) "expanded";
break;
case FONT_STRETCH_EXTRA_EXPANDED:
- str = (gchar *) "font-stretch-extra-expaned";
+ str = (gchar *) "extra-expaned";
break;
case FONT_STRETCH_ULTRA_EXPANDED:
- str = (gchar *) "font-stretch-ultra-expanded";
+ str = (gchar *) "ultra-expanded";
break;
case FONT_STRETCH_INHERIT:
- str = (gchar *) "font-stretch-inherit";
+ str = (gchar *) "inherit";
break;
}
return str;
diff --git a/src/cr-fonts.h b/src/cr-fonts.h
index 29fdfe3..ae5a258 100644
--- a/src/cr-fonts.h
+++ b/src/cr-fonts.h
@@ -44,6 +44,7 @@ enum CRFontFamilyType
FONT_FAMILY_FANTASY,
FONT_FAMILY_MONOSPACE,
FONT_FAMILY_NON_GENERIC,
+ FONT_FAMILY_INHERIT,
/**/
NB_FONT_FAMILIE_TYPES
} ;
@@ -86,7 +87,7 @@ enum CRPredefinedAbsoluteFontSize
FONT_SIZE_LARGE,
FONT_SIZE_X_LARGE,
FONT_SIZE_XX_LARGE,
-
+ FONT_SIZE_INHERIT,
NB_PREDEFINED_ABSOLUTE_FONT_SIZES
} ;
@@ -112,8 +113,7 @@ enum CRRelativeFontSize
*Used to define the type of #CRFontSize .
*See css2 spec chapter 15.2.4 to understand.
*/
-enum CRFontSizeType
-{
+enum CRFontSizeType {
/**
*If the type of #CRFontSize is
*PREDEFINED_ABSOLUTE_FONT_SIZE,
@@ -148,11 +148,9 @@ enum CRFontSizeType
} ;
typedef struct _CRFontSize CRFontSize ;
-struct _CRFontSize
-{
+struct _CRFontSize {
enum CRFontSizeType type ;
- union
- {
+ union {
enum CRPredefinedAbsoluteFontSize predefined ;
enum CRRelativeFontSize relative ;
CRNum * absolute ;
diff --git a/src/cr-input.c b/src/cr-input.c
index 64c14f8..9485df3 100644
--- a/src/cr-input.c
+++ b/src/cr-input.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
#include "stdio.h"
@@ -63,7 +60,7 @@ struct _CRInputPriv {
gulong line;
/*
- *The current col number.
+ *The current col number
*/
gulong col;
@@ -158,8 +155,7 @@ cr_input_new_from_buf (guchar * a_buf,
if (a_free_buf == TRUE && a_buf) {
g_free (a_buf) ;
a_buf = NULL ;
- }
- PRIVATE (result)->line = 1;
+ }
PRIVATE (result)->nb_bytes = PRIVATE (result)->in_buf_size;
} else {
PRIVATE (result)->in_buf = (guchar *) a_buf;
@@ -167,10 +163,11 @@ cr_input_new_from_buf (guchar * a_buf,
PRIVATE (result)->nb_bytes = a_len;
PRIVATE (result)->free_in_buf = a_free_buf;
}
-
+ PRIVATE (result)->line = 1;
+ PRIVATE (result)->col = 0;
return result;
- error:
+ error:
if (result) {
cr_input_destroy (result);
result = NULL;
@@ -258,8 +255,7 @@ cr_input_new_from_uri (const gchar * a_file_uri, enum CREncoding a_enc)
buf = NULL ;
}
- cleanup:
-
+ cleanup:
if (file_ptr) {
fclose (file_ptr);
file_ptr = NULL;
@@ -956,6 +952,35 @@ cr_input_get_cur_pos (CRInput * a_this, CRInputPos * a_pos)
}
/**
+ *Gets the current parsing location.
+ *The Parsing location is a public datastructure that
+ *represents the current line/column/byte offset/ in the input
+ *stream.
+ *@param a_this the current instance of #CRInput
+ *@param a_loc the set parsing location.
+ *@return CR_OK upon successful completion, an error
+ *code otherwise.
+ */
+enum CRStatus
+cr_input_get_parsing_location (CRInput *a_this,
+ CRParsingLocation *a_loc)
+{
+ g_return_val_if_fail (a_this
+ && PRIVATE (a_this)
+ && a_loc,
+ CR_BAD_PARAM_ERROR) ;
+
+ a_loc->line = PRIVATE (a_this)->line ;
+ a_loc->column = PRIVATE (a_this)->col ;
+ if (PRIVATE (a_this)->next_byte_index) {
+ a_loc->byte_offset = PRIVATE (a_this)->next_byte_index - 1 ;
+ } else {
+ a_loc->byte_offset = PRIVATE (a_this)->next_byte_index ;
+ }
+ return CR_OK ;
+}
+
+/**
*Getter of the next byte index.
*It actually returns the index of the
*next byte to be read.
diff --git a/src/cr-input.h b/src/cr-input.h
index 99ba8df..976b73f 100644
--- a/src/cr-input.h
+++ b/src/cr-input.h
@@ -17,20 +17,17 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See the COPYRIGHTS file for copyrights information.
*/
-
-/*
- *$Id$
- */
-
#ifndef __CR_INPUT_SRC_H__
#define __CR_INPUT_SRC_H__
#include <glib.h>
#include "cr-utils.h"
+#include "cr-parsing-location.h"
G_BEGIN_DECLS
@@ -67,7 +64,8 @@ CRInput *
cr_input_new_from_buf (guchar *a_buf, gulong a_len,
enum CREncoding a_enc, gboolean a_free_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) ;
void
cr_input_destroy (CRInput *a_this) ;
@@ -124,11 +122,15 @@ cr_input_set_cur_index (CRInput *a_this, glong a_index) ;
enum CRStatus
cr_input_get_cur_pos (CRInput *a_this, CRInputPos * a_pos) ;
-
+
enum CRStatus
cr_input_set_cur_pos (CRInput *a_this, CRInputPos *a_pos) ;
enum CRStatus
+cr_input_get_parsing_location (CRInput *a_this,
+ CRParsingLocation *a_loc) ;
+
+enum CRStatus
cr_input_get_end_of_line (CRInput *a_this, gboolean *a_eol) ;
enum CRStatus
diff --git a/src/cr-num.c b/src/cr-num.c
index 374a5da..5781ae3 100644
--- a/src/cr-num.c
+++ b/src/cr-num.c
@@ -3,7 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
@@ -18,6 +17,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyrights information.
*/
/*
@@ -267,16 +269,11 @@ cr_num_is_fixed_length (CRNum * a_this)
g_return_val_if_fail (a_this, FALSE);
- switch (a_this->type) {
- case NUM_LENGTH_EM...NUM_LENGTH_PC:
- result = TRUE;
- break;
- default:
- result = FALSE;
- break;
+ if (a_this->type >= NUM_LENGTH_EM
+ && a_this->type <= NUM_LENGTH_PC) {
+ result = TRUE ;
}
-
- return result;
+ return result ;
}
/**
diff --git a/src/cr-num.h b/src/cr-num.h
index 2f4bf7d..15c49c8 100644
--- a/src/cr-num.h
+++ b/src/cr-num.h
@@ -17,11 +17,8 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
- *see COPYRIGHTS file for copyright information
- */
-
-/*
- *$Id$
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information
*/
@@ -36,6 +33,7 @@
#include <glib.h>
#include "cr-utils.h"
+#include "cr-parsing-location.h"
G_BEGIN_DECLS
@@ -73,6 +71,7 @@ enum CRNumType
NUM_FREQ_HZ,
NUM_FREQ_KHZ,
NUM_PERCENTAGE,
+ NUM_INHERIT,
NUM_UNKNOWN_TYPE
} ;
@@ -91,6 +90,7 @@ struct _CRNum
{
enum CRNumType type ;
gdouble val ;
+ CRParsingLocation location ;
} ;
CRNum *
@@ -106,9 +106,6 @@ cr_num_dup (CRNum *a_this) ;
guchar *
cr_num_to_string (CRNum *a_this) ;
-void
-cr_num_set_type (CRNum *a_this, enum CRNumType a_type) ;
-
enum CRStatus
cr_num_copy (CRNum *a_dest, CRNum *a_src) ;
diff --git a/src/cr-om-parser.c b/src/cr-om-parser.c
index 4b0ab0b..b672499 100644
--- a/src/cr-om-parser.c
+++ b/src/cr-om-parser.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
#include <string.h>
@@ -50,56 +47,55 @@ typedef struct _ParsingContext ParsingContext;
static ParsingContext *new_parsing_context (void);
-static void
- destroy_context (ParsingContext * a_ctxt);
+static void destroy_context (ParsingContext * a_ctxt);
-static void
- unrecoverable_error (CRDocHandler * a_this);
+static void unrecoverable_error (CRDocHandler * a_this);
-static void
- error (CRDocHandler * a_this);
+static void error (CRDocHandler * a_this);
-static void
- property (CRDocHandler * a_this,
- GString * a_name, CRTerm * a_expression, gboolean a_important);
+static void property (CRDocHandler * a_this,
+ CRString * a_name,
+ CRTerm * a_expression,
+ gboolean a_important);
-static void
- end_selector (CRDocHandler * a_this, CRSelector * a_selector_list);
+static void end_selector (CRDocHandler * a_this,
+ CRSelector * a_selector_list);
-static void
- start_selector (CRDocHandler * a_this, CRSelector * a_selector_list);
+static void start_selector (CRDocHandler * a_this,
+ CRSelector * a_selector_list);
-static void
- start_font_face (CRDocHandler * a_this);
+static void start_font_face (CRDocHandler * a_this,
+ CRParsingLocation *a_location);
-static void
- end_font_face (CRDocHandler * a_this);
+static void end_font_face (CRDocHandler * a_this);
-static void
- end_document (CRDocHandler * a_this);
+static void end_document (CRDocHandler * a_this);
-static void
- start_document (CRDocHandler * a_this);
+static void start_document (CRDocHandler * a_this);
-static void
- charset (CRDocHandler * a_this, GString * a_charset);
+static void charset (CRDocHandler * a_this,
+ CRString * a_charset,
+ CRParsingLocation *a_location);
-static void
- start_page (CRDocHandler * a_this, GString * a_page,
- GString * a_pseudo_page);
+static void start_page (CRDocHandler * a_this, CRString * a_page,
+ CRString * a_pseudo_page,
+ CRParsingLocation *a_location);
-static void
- end_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo_page);
+static void end_page (CRDocHandler * a_this, CRString * a_page,
+ CRString * a_pseudo_page);
-static void
- start_media (CRDocHandler * a_this, GList * a_media_list);
+static void start_media (CRDocHandler * a_this,
+ GList * a_media_list,
+ CRParsingLocation *a_location);
-static void
- end_media (CRDocHandler * a_this, GList * a_media_list);
+static void 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);
+static void import_style (CRDocHandler * a_this,
+ GList * a_media_list,
+ CRString * a_uri,
+ CRString * a_uri_default_ns,
+ CRParsingLocation *a_location);
struct _ParsingContext {
CRStyleSheet *stylesheet;
@@ -212,7 +208,8 @@ start_document (CRDocHandler * a_this)
}
static void
-start_font_face (CRDocHandler * a_this)
+start_font_face (CRDocHandler * a_this,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
ParsingContext *ctxt = NULL;
@@ -306,12 +303,13 @@ end_document (CRDocHandler * a_this)
}
static void
-charset (CRDocHandler * a_this, GString * a_charset)
+charset (CRDocHandler * a_this, CRString * a_charset,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
CRStatement *stmt = NULL,
*stmt2 = NULL;
- GString *charset = NULL;
+ CRString *charset = NULL;
ParsingContext *ctxt = NULL;
ParsingContext **ctxtptr = NULL;
@@ -322,30 +320,29 @@ charset (CRDocHandler * a_this, GString * a_charset)
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);
-
+ charset = cr_string_dup (a_charset) ;
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);
+ cr_string_destroy (charset);
}
return;
}
-
ctxt->stylesheet->statements = stmt2;
stmt2 = NULL;
}
static void
-start_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo)
+start_page (CRDocHandler * a_this,
+ CRString * a_page,
+ CRString * a_pseudo,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
ParsingContext *ctxt = NULL;
@@ -359,28 +356,24 @@ start_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo)
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);
+ cr_string_dup (a_page) ;
if (!ctxt->cur_stmt->kind.page_rule->name) {
goto error;
}
}
-
if (a_pseudo) {
ctxt->cur_stmt->kind.page_rule->pseudo =
- g_string_new_len (a_pseudo->str, a_pseudo->len);
-
+ cr_string_dup (a_pseudo) ;
if (!ctxt->cur_stmt->kind.page_rule->pseudo) {
goto error;
}
}
-
return;
- error:
+ error:
if (ctxt->cur_stmt) {
cr_statement_destroy (ctxt->cur_stmt);
ctxt->cur_stmt = NULL;
@@ -388,7 +381,9 @@ start_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo)
}
static void
-end_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo_page)
+end_page (CRDocHandler * a_this,
+ CRString * a_page,
+ CRString * a_pseudo_page)
{
enum CRStatus status = CR_OK;
ParsingContext *ctxt = NULL;
@@ -421,7 +416,9 @@ end_page (CRDocHandler * a_this, GString * a_page, GString * a_pseudo_page)
}
static void
-start_media (CRDocHandler * a_this, GList * a_media_list)
+start_media (CRDocHandler * a_this,
+ GList * a_media_list,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
ParsingContext *ctxt = NULL;
@@ -437,12 +434,11 @@ start_media (CRDocHandler * a_this, GList * a_media_list)
&& ctxt->cur_stmt == NULL
&& ctxt->cur_media_stmt == NULL
&& ctxt->stylesheet);
-
if (a_media_list) {
/*duplicate the media_list */
- media_list = cr_dup_glist_of_string (a_media_list);
+ media_list = cr_utils_dup_glist_of_cr_string
+ (a_media_list);
}
-
ctxt->cur_media_stmt =
cr_statement_new_at_media_rule
(ctxt->stylesheet, NULL, media_list);
@@ -476,21 +472,25 @@ end_media (CRDocHandler * a_this, GList * a_media_list)
ctxt->stylesheet->statements = stmts;
stmts = NULL;
- a_media_list = NULL; /*compiler happy */
+ ctxt->cur_stmt = NULL ;
+ ctxt->cur_media_stmt = NULL ;
+ a_media_list = NULL;
}
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,
+ CRString * a_uri,
+ CRString * a_uri_default_ns,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
- GString *uri = NULL;
+ CRString *uri = NULL;
CRStatement *stmt = NULL,
*stmt2 = NULL;
ParsingContext *ctxt = NULL;
ParsingContext **ctxtptr = NULL;
- GList *media_list = NULL,
- *cur = NULL;
+ GList *media_list = NULL ;
g_return_if_fail (a_this);
ctxtptr = &ctxt;
@@ -498,20 +498,9 @@ import_style (CRDocHandler * a_this, GList * a_media_list,
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);
- }
- }
-
+ uri = cr_string_dup (a_uri) ;
+ if (a_media_list)
+ media_list = cr_utils_dup_glist_of_cr_string (a_media_list) ;
stmt = cr_statement_new_at_import_rule
(ctxt->stylesheet, uri, media_list, NULL);
if (!stmt)
@@ -538,7 +527,7 @@ import_style (CRDocHandler * a_this, GList * a_media_list,
error:
if (uri) {
- g_string_free (uri, TRUE);
+ cr_string_destroy (uri);
}
if (stmt) {
@@ -551,7 +540,7 @@ import_style (CRDocHandler * a_this, GList * a_media_list,
static void
start_selector (CRDocHandler * a_this, CRSelector * a_selector_list)
{
- enum CRStatus status = CR_OK;
+ enum CRStatus status = CR_OK ;
ParsingContext *ctxt = NULL;
ParsingContext **ctxtptr = NULL;
@@ -624,14 +613,16 @@ end_selector (CRDocHandler * a_this, CRSelector * a_selector_list)
static void
property (CRDocHandler * a_this,
- GString * a_name, CRTerm * a_expression, gboolean a_important)
+ CRString * a_name,
+ CRTerm * a_expression,
+ gboolean a_important)
{
enum CRStatus status = CR_OK;
ParsingContext *ctxt = NULL;
ParsingContext **ctxtptr = NULL;
CRDeclaration *decl = NULL,
*decl2 = NULL;
- GString *str = NULL;
+ CRString *str = NULL;
g_return_if_fail (a_this);
ctxtptr = &ctxt;
@@ -650,7 +641,7 @@ property (CRDocHandler * a_this,
|| ctxt->cur_stmt->type == AT_PAGE_RULE_STMT));
if (a_name) {
- str = g_string_new_len (a_name->str, a_name->len);
+ str = cr_string_dup (a_name);
g_return_if_fail (str);
}
diff --git a/src/cr-parser.c b/src/cr-parser.c
index f29de0e..926ba3d 100644
--- a/src/cr-parser.c
+++ b/src/cr-parser.c
@@ -19,13 +19,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for copyrights information.
*/
-/*
- *$Id$
- */
-
/**
*@file
*The definition of the #CRParser class.
@@ -101,7 +98,7 @@ enum CRParserState {
PAGE_PARSED_STATE,
TRY_PARSE_FONT_FACE_STATE,
FONT_FACE_PARSED_STATE
-};
+} ;
/**
*The private attributes of
@@ -148,8 +145,8 @@ struct _CRParserPriv {
*Checks if 'status' equals CR_OK. If not, goto the 'error' label.
*
*@param status the status (of type enum CRStatus) to test.
- *@param is_exception if set to FALSE, the final status returned the
- *current function will be CR_PARSING_ERROR. If set to TRUE, the
+ *@param is_exception if set to FALSE, the final status returned
+ *by the current function will be CR_PARSING_ERROR. If set to TRUE, the
*current status will be the current value of the 'status' variable.
*
*/
@@ -329,8 +326,8 @@ 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);
+ CRString ** a_inf,
+ CRString ** a_sup);
#endif
static enum CRStatus cr_parser_parse_stylesheet_core (CRParser * a_this);
@@ -350,19 +347,19 @@ 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_string (CRParser * a_this,
- GString ** a_str);
+ CRString ** a_str);
static enum CRStatus cr_parser_parse_ident (CRParser * a_this,
- GString ** a_str);
+ CRString ** a_str);
static enum CRStatus cr_parser_parse_uri (CRParser * a_this,
- GString ** a_str);
+ CRString ** a_str);
static enum CRStatus cr_parser_parse_function (CRParser * a_this,
- GString ** a_func_name,
+ CRString ** a_func_name,
CRTerm ** a_expr);
static enum CRStatus cr_parser_parse_property (CRParser * a_this,
- GString ** a_property);
+ CRString ** a_property);
static enum CRStatus cr_parser_parse_attribute_selector (CRParser * a_this,
CRAttrSel ** a_sel);
@@ -654,296 +651,6 @@ cr_parser_try_to_skip_spaces_and_comments (CRParser * a_this)
*End of Parser input handling routines
***************************************/
-#ifdef WITH_UNICODE_ESCAPE_AND_RANGE
-
-/**
- *Parses an "unicode-range" as defined in the css spec at [4.1.1]:
- * UNICODE-RANGE ::= U\+[0-9A-F?]{1,6}(-[0-9A-F]{1,6})?
- *@param a_this the current instance of #CRParser.
- *@param a_inf out parameter. The inferior barrier of the range.
- *@param a_sup out parameter. The superior barrier of the range.
- *@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)
-{
- enum CRStatus status = CR_OK;
- CRInputPos init_pos;
- glong i = 0;
- gboolean min_str_needs_free = FALSE,
- 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);
-
- RECORD_INITIAL_POS (a_this, &init_pos);
-
- READ_NEXT_CHAR (a_this, &cur_char);
-
- 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);
-
- ENSURE_PARSING_COND_ERR
- (a_this, cur_char == '+',
- "while parsing an unicode range: there must be a + after the U",
- CR_SYNTAX_ERROR);
-
- 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);
-
- 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;
- }
- }
-
- if (i < 1) {
- status = CR_PARSING_ERROR;
- cr_parser_push_error (a_this,
- "No unicode range expressed",
- CR_SYNTAX_ERROR);
- goto error;
- }
-
- 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;
- }
-
- 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;
- }
- g_string_append_unichar (*a_sup, cur_char);
- } else {
- break;
- }
- }
-
- 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;
- }
-
- 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);
-
- return status;
-}
-
-/**
- *Parses an 'unicode' escape sequence defined
- *in css spec at chap 4.1.1:
- *unicode ::= \\[0-9a-f]{1,6}[ \n\r\t\f]?
- *@param a_this the current instance of #CRParser.
- *@param a_start out parameter. A pointer to the start
- *of the unicode escape sequence. Must *NOT* be deleted by
- *the caller.
- *@param a_end out parameter. A pointer to the last character
- *of the unicode escape sequence. Must *NOT* be deleted by the caller.
- *@return CR_OK if parsing succeded, an error code otherwise.
- *Error code can be either CR_PARSING_ERROR if the string
- *parsed just doesn't
- *respect the production or another error if a
- *lower level error occured.
- */
-static enum CRStatus
-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;
-
- 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');
- }
-
- unicode = unicode * 10 + cur_char_val;
-
- READ_NEXT_CHAR (a_this, &cur_char);
- }
-
- 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 {
- /*
- *The unicode escape is less than
- *6 digit length. The character
- *that comes right after the escape
- *must be a white space.
- */
- status = cr_parser_parse_w (a_this, &tmp_char_ptr1,
- &tmp_char_ptr2);
-
- CHECK_PARSING_STATUS_ERR
- (a_this, status, FALSE,
- "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;
- }
-
- error:
- /*
- *restore the initial position pointer backuped at
- *the beginning of this function.
- */
- cr_tknzr_set_cur_pos (PRIVATE (a_this) tknzr, &init_pos);
-
- 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)
-{
- 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);
-
- RECORD_INITIAL_POS (a_this, &init_pos);
-
- 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
- (a_this,
- "next char expected to be a '\\'", CR_SYNTAX_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);
- if (status != CR_OK
- && 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,
- "next char expected to be a space",
- CR_SYNTAX_ERROR);
-
- goto error;
- }
-
- *a_esc_code = cur_char;
-
- }
-
- if (status == CR_OK) {
- cr_parser_clear_errors (a_this);
- return CR_OK;
- }
-
- error:
-
- cr_tknzr_set_cur_pos (PRIVATE (a_this) tknzr, &init_pos);
-
- return status;
-}
-#endif /*WITH_UNICODE_ESCAPE_AND_RANGE */
/*************************************
*Non trivial terminal productions
@@ -971,7 +678,7 @@ cr_parser_parse_stylesheet_core (CRParser * a_this)
RECORD_INITIAL_POS (a_this, &init_pos);
- continue_parsing:
+ continue_parsing:
if (token) {
cr_token_destroy (token);
@@ -1009,7 +716,7 @@ cr_parser_parse_stylesheet_core (CRParser * a_this)
}
}
- done:
+ done:
if (token) {
cr_token_destroy (token);
token = NULL;
@@ -1017,8 +724,8 @@ cr_parser_parse_stylesheet_core (CRParser * a_this)
cr_parser_clear_errors (a_this);
return CR_OK;
- error:
+ error:
cr_parser_push_error
(a_this, "could not recognize next production", CR_ERROR);
@@ -1053,7 +760,8 @@ cr_parser_parse_atrule_core (CRParser * a_this)
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
&&
@@ -1073,37 +781,39 @@ cr_parser_parse_atrule_core (CRParser * a_this)
status = cr_parser_parse_any_core (a_this);
} while (status == CR_OK);
- 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);
if (token->type == CBO_TK) {
- cr_tknzr_unget_token (PRIVATE (a_this)->tknzr, token);
+ cr_tknzr_unget_token (PRIVATE (a_this)->tknzr,
+ token);
token = NULL;
status = cr_parser_parse_block_core (a_this);
- CHECK_PARSING_STATUS (status, FALSE);
+ CHECK_PARSING_STATUS (status,
+ FALSE);
goto done;
} else if (token->type == SEMICOLON_TK) {
goto done;
} else {
+ status = CR_PARSING_ERROR ;
goto error;
}
- done:
+ done:
if (token) {
cr_token_destroy (token);
token = NULL;
}
-
return CR_OK;
- error:
+ 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;
}
@@ -1224,7 +934,7 @@ cr_parser_parse_selector_core (CRParser * a_this)
return CR_OK;
- error:
+ error:
if (token) {
cr_token_destroy (token);
token = NULL;
@@ -1317,7 +1027,7 @@ cr_parser_parse_declaration_core (CRParser * a_this)
CRToken *token = NULL;
CRInputPos init_pos;
enum CRStatus status = CR_ERROR;
- GString *prop = NULL;
+ CRString *prop = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
@@ -1327,7 +1037,7 @@ cr_parser_parse_declaration_core (CRParser * a_this)
CHECK_PARSING_STATUS (status, FALSE);
cr_parser_clear_errors (a_this);
ENSURE_PARSING_COND (status == CR_OK && prop);
- g_string_free (prop, TRUE);
+ cr_string_destroy (prop);
prop = NULL;
status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token);
@@ -1346,7 +1056,7 @@ cr_parser_parse_declaration_core (CRParser * a_this)
error:
if (prop) {
- g_string_free (prop, TRUE);
+ cr_string_destroy (prop);
prop = NULL;
}
@@ -1484,6 +1194,7 @@ cr_parser_parse_any_core (CRParser * a_this)
case INCLUDES_TK:
case DASHMATCH_TK:
case S_TK:
+ case COMMENT_TK:
case IMPORTANT_SYM_TK:
status = CR_OK;
break;
@@ -1605,12 +1316,14 @@ 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;
+ CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this && a_sel, CR_BAD_PARAM_ERROR);
@@ -1619,14 +1332,21 @@ cr_parser_parse_attribute_selector (CRParser * a_this, CRAttrSel ** a_sel)
status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token);
ENSURE_PARSING_COND (status == CR_OK && token
&& token->type == BO_TK);
-
+ cr_parsing_location_copy
+ (&location, &token->location) ;
cr_token_destroy (token);
token = NULL;
cr_parser_try_to_skip_spaces_and_comments (a_this);
result = cr_attr_sel_new ();
-
+ if (!result) {
+ cr_utils_trace_info ("result failed") ;
+ status = CR_OUT_OF_MEMORY_ERROR ;
+ goto error ;
+ }
+ cr_parsing_location_copy (&result->location,
+ &location) ;
status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token);
ENSURE_PARSING_COND (status == CR_OK
&& token && token->type == IDENT_TK);
@@ -1655,7 +1375,7 @@ cr_parser_parse_attribute_selector (CRParser * a_this, CRAttrSel ** a_sel)
goto done;
}
- parse_right_part:
+ parse_right_part:
if (token) {
cr_token_destroy (token);
@@ -1665,9 +1385,8 @@ cr_parser_parse_attribute_selector (CRParser * a_this, CRAttrSel ** a_sel)
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) {
result->value = token->u.str;
token->u.str = NULL;
@@ -1690,7 +1409,7 @@ cr_parser_parse_attribute_selector (CRParser * a_this, CRAttrSel ** a_sel)
ENSURE_PARSING_COND (status == CR_OK && token
&& token->type == BC_TK);
- done:
+ done:
if (token) {
cr_token_destroy (token);
token = NULL;
@@ -1706,7 +1425,7 @@ cr_parser_parse_attribute_selector (CRParser * a_this, CRAttrSel ** a_sel)
cr_parser_clear_errors (a_this);
return CR_OK;
- error:
+ error:
if (result) {
cr_attr_sel_destroy (result);
@@ -1737,20 +1456,22 @@ 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,
+ CRString ** a_property)
{
enum CRStatus status = CR_OK;
CRInputPos init_pos;
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);
status = cr_parser_parse_ident (a_this, a_property);
CHECK_PARSING_STATUS (status, TRUE);
-
+
cr_parser_try_to_skip_spaces_and_comments (a_this);
cr_parser_clear_errors (a_this);
@@ -1782,7 +1503,8 @@ cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term)
CRTerm *result = NULL;
CRTerm *param = NULL;
CRToken *token = NULL;
- GString *func_name = NULL;
+ CRString *func_name = NULL;
+ CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this && a_term, CR_BAD_PARAM_ERROR);
@@ -1790,10 +1512,12 @@ cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term)
result = cr_term_new ();
- 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_OK || !token)
goto error;
+ cr_parsing_location_copy (&location, &token->location) ;
if (token->type == DELIM_TK && token->u.unichar == '+') {
result->unary_op = PLUS_UOP;
} else if (token->type == DELIM_TK && token->u.unichar == '-') {
@@ -1818,12 +1542,14 @@ cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term)
&param);
if (status == CR_OK) {
- status = cr_term_set_function (result, func_name,
+ status = cr_term_set_function (result,
+ func_name,
param);
CHECK_PARSING_STATUS (status, TRUE);
}
} else if (token && token->type == STRING_TK) {
- status = cr_term_set_string (result, token->u.str);
+ 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) {
@@ -1852,7 +1578,8 @@ cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term)
if (status != CR_OK) {
goto error;
}
-
+ cr_parsing_location_copy (&result->location,
+ &location) ;
*a_term = cr_term_append_term (*a_term, result);
result = NULL;
@@ -1885,7 +1612,7 @@ cr_parser_parse_term (CRParser * a_this, CRTerm ** a_term)
}
if (func_name) {
- g_string_free (func_name, TRUE);
+ cr_string_destroy (func_name);
func_name = NULL;
}
@@ -1927,19 +1654,24 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
sel = cr_simple_sel_new ();
ENSURE_PARSING_COND (sel);
- if (token && token->type == DELIM_TK && token->u.unichar == '*') {
+ cr_parsing_location_copy
+ (&sel->location,
+ &token->location) ;
+
+ if (token && token->type == DELIM_TK
+ && token->u.unichar == '*') {
sel->type_mask |= UNIVERSAL_SELECTOR;
- sel->name = g_string_new ("*");
+ sel->name = cr_string_new_from_string ("*");
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);
+ status = cr_tknzr_unget_token
+ (PRIVATE (a_this)->tknzr,
+ token);
token = NULL;
}
@@ -1956,8 +1688,9 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
token = NULL;
}
- 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_OK)
goto error;
@@ -1971,10 +1704,12 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
add_sel->content.id_name = token->u.str;
token->u.str = NULL;
+ cr_parsing_location_copy
+ (&add_sel->location,
+ &token->location) ;
add_sel_list =
cr_additional_sel_append
- (add_sel_list, add_sel);
-
+ (add_sel_list, add_sel);
found_sel = TRUE;
} else if (token && (token->type == DELIM_TK)
&& (token->u.unichar == '.')) {
@@ -1999,8 +1734,12 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
cr_additional_sel_append
(add_sel_list, add_sel);
found_sel = TRUE;
+
+ cr_parsing_location_copy
+ (&add_sel->location,
+ & token->location) ;
} else {
- status = CR_OK;
+ status = CR_PARSING_ERROR;
goto error;
}
} else if (token && token->type == BO_TK) {
@@ -2028,6 +1767,9 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
cr_additional_sel_append
(add_sel_list, add_sel);
found_sel = TRUE;
+ cr_parsing_location_copy
+ (&add_sel->location,
+ &attr_sel->location) ;
} else if (token && (token->type == DELIM_TK)
&& (token->u.unichar == ':')) {
CRPseudo *pseudo = NULL;
@@ -2043,9 +1785,12 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
status = cr_tknzr_get_next_token
(PRIVATE (a_this)->tknzr, &token);
-
ENSURE_PARSING_COND (status == CR_OK && token);
+ cr_parsing_location_copy
+ (&pseudo->location,
+ &token->location) ;
+
if (token->type == IDENT_TK) {
pseudo->type = IDENT_PSEUDO;
pseudo->name = token->u.str;
@@ -2076,11 +1821,12 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
(PSEUDO_CLASS_ADD_SELECTOR);
add_sel->content.pseudo = pseudo;
-
+ cr_parsing_location_copy
+ (&add_sel->location,
+ &pseudo->location) ;
add_sel_list =
cr_additional_sel_append
(add_sel_list, add_sel);
-
status = CR_OK;
}
} else {
@@ -2096,7 +1842,7 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
sel->add_sel = add_sel_list;
add_sel_list = NULL;
-
+
if (*a_sel == NULL) {
*a_sel = sel;
} else {
@@ -2116,7 +1862,7 @@ cr_parser_parse_simple_selector (CRParser * a_this, CRSimpleSel ** a_sel)
status = CR_PARSING_ERROR;
}
- error:
+ error:
if (token) {
cr_token_destroy (token);
@@ -2152,14 +1898,18 @@ 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;
- g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
+ g_return_val_if_fail (a_this
+ && PRIVATE (a_this)
+ && a_sel,
+ CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@@ -2192,26 +1942,36 @@ cr_parser_parse_simple_sels (CRParser * a_this, CRSimpleSel ** a_sel)
if (status != CR_OK)
break;
- if (comb) {
+ if (comb && sel) {
sel->combinator = comb;
comb = 0;
}
-
- *a_sel = cr_simple_sel_append_simple_sel (*a_sel, sel);
+ if (sel) {
+ *a_sel = cr_simple_sel_append_simple_sel (*a_sel,
+ sel) ;
+ }
}
-
cr_parser_clear_errors (a_this);
return CR_OK;
- error:
+ error:
cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos);
return status;
}
+/**
+ *Parses a comma separated list of selectors.
+ *@param a_this the current instance of #CRParser.
+ *@param a_selector the parsed list of comma separated
+ *selectors.
+ *@return CR_OK upon successful completion, an error
+ *code otherwise.
+ */
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;
@@ -2225,16 +1985,24 @@ cr_parser_parse_selector (CRParser * a_this, CRSelector ** a_selector)
RECORD_INITIAL_POS (a_this, &init_pos);
status = cr_parser_parse_simple_sels (a_this, &simple_sels);
-
CHECK_PARSING_STATUS (status, FALSE);
if (simple_sels) {
selector = cr_selector_append_simple_sel
(selector, simple_sels);
+ if (selector) {
+ cr_parsing_location_copy
+ (&selector->location,
+ &simple_sels->location) ;
+ }
simple_sels = NULL;
+ } else {
+ status = CR_PARSING_ERROR ;
+ goto error ;
}
- status = cr_tknzr_peek_char (PRIVATE (a_this)->tknzr, &next_char);
+ 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;
@@ -2325,7 +2093,8 @@ cr_parser_parse_selector (CRParser * a_this, CRSelector ** a_selector)
*/
static enum CRStatus
cr_parser_parse_function (CRParser * a_this,
- GString ** a_func_name, CRTerm ** a_expr)
+ CRString ** a_func_name,
+ CRTerm ** a_expr)
{
CRInputPos init_pos;
enum CRStatus status = CR_OK;
@@ -2333,7 +2102,8 @@ cr_parser_parse_function (CRParser * a_this,
CRTerm *expr = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
- && a_func_name, CR_BAD_PARAM_ERROR);
+ && a_func_name,
+ CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@@ -2348,18 +2118,10 @@ cr_parser_parse_function (CRParser * a_this,
status = CR_PARSING_ERROR;
goto error;
}
-
- cr_token_destroy (token);
- token = NULL;
-
- 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);
-
cr_token_destroy (token);
token = NULL;
+
+ cr_parser_try_to_skip_spaces_and_comments (a_this) ;
status = cr_parser_parse_term (a_this, &expr);
@@ -2385,7 +2147,7 @@ cr_parser_parse_function (CRParser * a_this,
error:
if (*a_func_name) {
- g_string_free (*a_func_name, TRUE);
+ cr_string_destroy (*a_func_name);
*a_func_name = NULL;
}
@@ -2414,7 +2176,7 @@ cr_parser_parse_function (CRParser * a_this,
*@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, CRString ** a_str)
{
enum CRStatus status = CR_PARSING_ERROR;
@@ -2443,7 +2205,7 @@ 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, CRString ** a_str)
{
enum CRStatus status = CR_OK;
@@ -2463,7 +2225,7 @@ cr_parser_parse_string (CRParser * a_this, GString ** a_str)
*@param a_this the currens instance of #CRParser.
*
*@param a_str a pointer to parsed ident. If *a_str is NULL,
- *this function allocates a new instance of GString. If not,
+ *this function allocates a new instance of #CRString. If not,
*the function just appends the parsed string to the one passed.
*In both cases it is up to the caller to free *a_str.
*
@@ -2471,7 +2233,7 @@ 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, CRString ** a_str)
{
enum CRStatus status = CR_OK;
@@ -2485,6 +2247,7 @@ cr_parser_parse_ident (CRParser * a_this, GString ** a_str)
}
/**
+ *the next rule is ignored as well. This seems to be a bug
*Parses a stylesheet as defined in the css2 spec in appendix D.1:
*stylesheet ::= [ CHARSET_SYM S* STRING S* ';' ]?
* [S|CDO|CDC]* [ import [S|CDO|CDC]* ]*
@@ -2507,7 +2270,7 @@ cr_parser_parse_stylesheet (CRParser * a_this)
enum CRStatus status = CR_OK;
CRInputPos init_pos;
CRToken *token = NULL;
- GString *charset = NULL;
+ CRString *charset = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->tknzr, CR_BAD_PARAM_ERROR);
@@ -2522,7 +2285,7 @@ cr_parser_parse_stylesheet (CRParser * a_this)
(PRIVATE (a_this)->sac_handler);
}
-/* parse_charset:*/
+ parse_charset:
status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token);
if (status == CR_END_OF_INPUT_ERROR)
@@ -2530,19 +2293,22 @@ cr_parser_parse_stylesheet (CRParser * a_this)
CHECK_PARSING_STATUS (status, TRUE);
if (token && token->type == CHARSET_SYM_TK) {
+ CRParsingLocation location = {0} ;
status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr,
token);
CHECK_PARSING_STATUS (status, TRUE);
token = NULL;
- status = cr_parser_parse_charset (a_this, &charset);
+ status = cr_parser_parse_charset (a_this,
+ &charset,
+ &location);
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);
+ charset, &location);
}
} else if (status != CR_END_OF_INPUT_ERROR) {
status = cr_parser_parse_atrule_core (a_this);
@@ -2550,17 +2316,19 @@ cr_parser_parse_stylesheet (CRParser * a_this)
}
if (charset) {
- g_string_free (charset, TRUE);
+ cr_string_destroy (charset);
charset = NULL;
}
} else if (token
- && (token->type == S_TK || token->type == COMMENT_TK)) {
+ && (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);
cr_parser_try_to_skip_spaces_and_comments (a_this);
+ goto parse_charset ;
} else if (token) {
status = cr_tknzr_unget_token (PRIVATE (a_this)->tknzr,
token);
@@ -2574,6 +2342,7 @@ cr_parser_parse_stylesheet (CRParser * a_this)
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);
@@ -2599,7 +2368,8 @@ cr_parser_parse_stylesheet (CRParser * a_this)
if (token && token->type == IMPORT_SYM_TK) {
GList *media_list = NULL;
- GString *import_string = NULL;
+ CRString *import_string = NULL;
+ CRParsingLocation location = {0} ;
status = cr_tknzr_unget_token
(PRIVATE (a_this)->tknzr, token);
@@ -2608,51 +2378,42 @@ cr_parser_parse_stylesheet (CRParser * a_this)
status = cr_parser_parse_import (a_this,
&media_list,
- &import_string);
-
+ &import_string,
+ &location);
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,
- media_list,
- import_string,
- NULL);
-
- if ((PRIVATE (a_this)->sac_handler->
- resolve_import == TRUE)) {
+ && PRIVATE (a_this)->sac_handler->import_style) {
+ PRIVATE (a_this)->sac_handler->import_style
+ (PRIVATE(a_this)->sac_handler,
+ media_list,
+ import_string,
+ NULL, &location) ;
+
+ if ((PRIVATE (a_this)->sac_handler->resolve_import == TRUE)) {
/*
*TODO: resolve the
*import rule.
*/
}
- if ((PRIVATE (a_this)->sac_handler->
- import_style_result)) {
- PRIVATE (a_this)->
- sac_handler->
- import_style_result
- (PRIVATE (a_this)->
- sac_handler,
- media_list,
- import_string,
+ if ((PRIVATE (a_this)->sac_handler->import_style_result)) {
+ PRIVATE (a_this)->sac_handler->import_style_result
+ (PRIVATE (a_this)->sac_handler,
+ media_list, import_string,
NULL, NULL);
}
}
} 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);
+ PRIVATE (a_this)->sac_handler->error
+ (PRIVATE (a_this)->sac_handler);
}
-
status = cr_parser_parse_atrule_core (a_this);
+ CHECK_PARSING_STATUS (status, TRUE) ;
+ } else {
+ goto error ;
}
/*
@@ -2666,8 +2427,7 @@ cr_parser_parse_stylesheet (CRParser * a_this)
/*free the medium list */
for (cur = media_list; cur; cur = cur->next) {
if (cur->data) {
- g_string_free (cur->data,
- TRUE);
+ cr_string_destroy (cur->data);
}
}
@@ -2676,7 +2436,7 @@ cr_parser_parse_stylesheet (CRParser * a_this)
}
if (import_string) {
- g_string_free (import_string, TRUE);
+ cr_string_destroy (import_string);
import_string = NULL;
}
@@ -2715,7 +2475,7 @@ cr_parser_parse_stylesheet (CRParser * a_this)
}
}
- parse_ruleset_and_others:
+ parse_ruleset_and_others:
cr_parser_try_to_skip_spaces_and_comments (a_this);
@@ -3265,7 +3025,7 @@ 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, CRString ** a_prio)
{
enum CRStatus status = CR_ERROR;
CRInputPos init_pos;
@@ -3285,7 +3045,7 @@ cr_parser_parse_prio (CRParser * a_this, GString ** a_prio)
&& token && token->type == IMPORTANT_SYM_TK);
cr_parser_try_to_skip_spaces_and_comments (a_this);
- *a_prio = g_string_new ("!important");
+ *a_prio = cr_string_new_from_string ("!important");
cr_token_destroy (token);
token = NULL;
return CR_OK;
@@ -3315,14 +3075,14 @@ cr_parser_parse_prio (CRParser * a_this, GString ** a_prio)
*/
enum CRStatus
cr_parser_parse_declaration (CRParser * a_this,
- GString ** a_property,
+ CRString ** 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;
+ CRString *prio = NULL;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_property && a_expr
@@ -3363,7 +3123,7 @@ cr_parser_parse_declaration (CRParser * a_this,
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);
+ cr_string_destroy (prio);
prio = NULL;
*a_important = TRUE;
} else {
@@ -3388,7 +3148,7 @@ cr_parser_parse_declaration (CRParser * a_this,
}
if (*a_property) {
- g_string_free (*a_property, TRUE);
+ cr_string_destroy (*a_property);
*a_property = NULL;
}
@@ -3472,7 +3232,7 @@ cr_parser_parse_ruleset (CRParser * a_this)
CRInputPos init_pos;
guint32 cur_char = 0,
next_char = 0;
- GString *property = NULL;
+ CRString *property = NULL;
CRTerm *expr = NULL;
CRSimpleSel *simple_sels = NULL;
CRSelector *selector = NULL;
@@ -3496,7 +3256,7 @@ cr_parser_parse_ruleset (CRParser * a_this)
if (PRIVATE (a_this)->sac_handler
&& PRIVATE (a_this)->sac_handler->start_selector) {
/*
- *the selector if ref counted so that the parser's user
+ *the selector is ref counted so that the parser's user
*can choose to keep it.
*/
if (selector) {
@@ -3513,7 +3273,8 @@ cr_parser_parse_ruleset (CRParser * a_this)
PRIVATE (a_this)->state = TRY_PARSE_RULESET_STATE;
status = cr_parser_parse_declaration (a_this, &property,
- &expr, &is_important);
+ &expr,
+ &is_important);
if (expr) {
cr_term_ref (expr);
}
@@ -3531,7 +3292,7 @@ cr_parser_parse_ruleset (CRParser * a_this)
*next declarations.
*/
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (expr) {
@@ -3580,7 +3341,7 @@ cr_parser_parse_ruleset (CRParser * a_this)
property, expr, is_important);
}
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (expr) {
@@ -3640,7 +3401,7 @@ cr_parser_parse_ruleset (CRParser * a_this)
simple_sels = NULL;
}
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
}
if (selector) {
cr_selector_unref (selector);
@@ -3656,15 +3417,15 @@ cr_parser_parse_ruleset (CRParser * a_this)
*Parses an 'import' declaration as defined in the css2 spec
*in appendix D.1:
*
- *import ::=
+ *import ::=
*@import [STRING|URI] S* [ medium [ ',' S* medium]* ]? ';' S*
*
*@param a_this the "this pointer" of the current instance
*of #CRParser.
*
*@param a_medium_list out parameter. A linked list of
- *GString (see the doc of glib-2).
- *Each GString is a string that contains
+ *#CRString
+ *Each CRString is a string that contains
*a 'medium' declaration part of the successfully
*parsed 'import' declaration.
*
@@ -3679,13 +3440,15 @@ cr_parser_parse_ruleset (CRParser * a_this)
*/
enum CRStatus
cr_parser_parse_import (CRParser * a_this,
- GList ** a_media_list, GString ** a_import_string)
+ GList ** a_media_list,
+ CRString ** a_import_string,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
CRInputPos init_pos;
guint32 cur_char = 0,
next_char = 0;
- GString *medium = NULL;
+ CRString *medium = NULL;
g_return_val_if_fail (a_this
&& a_import_string
@@ -3701,7 +3464,12 @@ cr_parser_parse_import (CRParser * a_this,
&& BYTE (a_this, 5, NULL) == 'o'
&& BYTE (a_this, 6, NULL) == 'r'
&& BYTE (a_this, 7, NULL) == 't') {
- SKIP_CHARS (a_this, 7);
+ SKIP_CHARS (a_this, 1);
+ if (a_location) {
+ cr_parser_get_parsing_location
+ (a_this, a_location) ;
+ }
+ SKIP_CHARS (a_this, 6);
status = CR_OK;
} else {
status = CR_PARSING_ERROR;
@@ -3793,7 +3561,7 @@ cr_parser_parse_import (CRParser * a_this,
*/
for (cur = *a_media_list; cur; cur = cur->next) {
if (cur->data) {
- g_string_free (cur->data, TRUE);
+ cr_string_destroy (cur->data);
}
}
@@ -3802,12 +3570,12 @@ cr_parser_parse_import (CRParser * a_this,
}
if (*a_import_string) {
- g_string_free (*a_import_string, TRUE);
+ cr_string_destroy (*a_import_string);
*a_import_string = NULL;
}
if (medium) {
- g_string_free (medium, TRUE);
+ cr_string_destroy (medium);
medium = NULL;
}
@@ -3836,17 +3604,22 @@ cr_parser_parse_media (CRParser * a_this)
CRToken *token = NULL;
guint32 next_char = 0,
cur_char = 0;
- GString *medium = NULL;
+ CRString *medium = NULL;
GList *media_list = NULL;
+ CRParsingLocation location = {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);
- 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 == MEDIA_SYM_TK);
-
+ && token
+ && token->type == MEDIA_SYM_TK);
+ cr_parsing_location_copy (&location, &token->location) ;
cr_token_destroy (token);
token = NULL;
@@ -3898,7 +3671,8 @@ cr_parser_parse_media (CRParser * a_this)
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, media_list,
+ &location);
}
cr_parser_try_to_skip_spaces_and_comments (a_this);
@@ -3930,7 +3704,7 @@ cr_parser_parse_media (CRParser * a_this)
*the last call to the SAC handler.
*/
if (medium) {
- g_string_free (medium, TRUE);
+ cr_string_destroy (medium);
medium = NULL;
}
@@ -3938,7 +3712,7 @@ cr_parser_parse_media (CRParser * a_this)
GList *cur = NULL;
for (cur = media_list; cur; cur = cur->next) {
- g_string_free (cur->data, TRUE);
+ cr_string_destroy (cur->data);
}
g_list_free (media_list);
@@ -3958,7 +3732,7 @@ cr_parser_parse_media (CRParser * a_this)
}
if (medium) {
- g_string_free (medium, TRUE);
+ cr_string_destroy (medium);
medium = NULL;
}
@@ -3966,7 +3740,7 @@ cr_parser_parse_media (CRParser * a_this)
GList *cur = NULL;
for (cur = media_list; cur; cur = cur->next) {
- g_string_free (cur->data, TRUE);
+ cr_string_destroy (cur->data);
}
g_list_free (media_list);
@@ -3996,19 +3770,23 @@ cr_parser_parse_page (CRParser * a_this)
CRInputPos init_pos;
CRToken *token = NULL;
CRTerm *css_expression = NULL;
- GString *page_selector = NULL,
+ CRString *page_selector = NULL,
*page_pseudo_class = NULL,
*property = NULL;
gboolean important = TRUE;
+ CRParsingLocation location = {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);
+ status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr,
+ &token) ;
ENSURE_PARSING_COND (status == CR_OK
- && token && token->type == PAGE_SYM_TK);
+ && token
+ && token->type == PAGE_SYM_TK);
+ cr_parsing_location_copy (&location, &token->location) ;
cr_token_destroy (token);
token = NULL;
@@ -4065,14 +3843,16 @@ cr_parser_parse_page (CRParser * a_this)
&& PRIVATE (a_this)->sac_handler->start_page) {
PRIVATE (a_this)->sac_handler->start_page
(PRIVATE (a_this)->sac_handler,
- page_selector, page_pseudo_class);
+ page_selector, page_pseudo_class,
+ &location);
}
cr_parser_try_to_skip_spaces_and_comments (a_this);
PRIVATE (a_this)->state = TRY_PARSE_PAGE_STATE;
status = cr_parser_parse_declaration (a_this, &property,
- &css_expression, &important);
+ &css_expression,
+ &important);
ENSURE_PARSING_COND (status == CR_OK);
/*
@@ -4092,7 +3872,7 @@ cr_parser_parse_page (CRParser * a_this)
*SAC handler.
*/
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (css_expression) {
@@ -4111,8 +3891,13 @@ cr_parser_parse_page (CRParser * a_this)
ENSURE_PARSING_COND (status == CR_OK && token);
- if (token->type != SEMICOLON_TK)
+ if (token->type != SEMICOLON_TK) {
+ cr_tknzr_unget_token
+ (PRIVATE (a_this)->tknzr,
+ token);
+ token = NULL ;
break;
+ }
cr_token_destroy (token);
token = NULL;
@@ -4121,7 +3906,8 @@ cr_parser_parse_page (CRParser * a_this)
status = cr_parser_parse_declaration (a_this, &property,
&css_expression,
&important);
- CHECK_PARSING_STATUS (status, FALSE);
+ if (status != CR_OK)
+ break ;
/*
*call the relevant SAC handler here...
@@ -4138,7 +3924,7 @@ cr_parser_parse_page (CRParser * a_this)
*SAC handler.
*/
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (css_expression) {
@@ -4146,11 +3932,20 @@ cr_parser_parse_page (CRParser * a_this)
css_expression = NULL;
}
}
- ENSURE_PARSING_COND (status == CR_OK && token
- && token->type == CBC_TK);
- cr_token_destroy (token);
- token = NULL;
+ 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 == CBC_TK) ;
+ cr_token_destroy (token) ;
+ token = NULL ;
/*
*call the relevant SAC handler here.
*/
@@ -4162,12 +3957,12 @@ cr_parser_parse_page (CRParser * a_this)
}
if (page_selector) {
- g_string_free (page_selector, TRUE);
+ cr_string_destroy (page_selector);
page_selector = NULL;
}
if (page_pseudo_class) {
- g_string_free (page_pseudo_class, TRUE);
+ cr_string_destroy (page_pseudo_class);
page_pseudo_class = NULL;
}
@@ -4180,21 +3975,21 @@ cr_parser_parse_page (CRParser * a_this)
return CR_OK;
- error:
+ error:
if (token) {
cr_token_destroy (token);
token = NULL;
}
if (page_selector) {
- g_string_free (page_selector, TRUE);
+ cr_string_destroy (page_selector);
page_selector = NULL;
}
if (page_pseudo_class) {
- g_string_free (page_pseudo_class, TRUE);
+ cr_string_destroy (page_pseudo_class);
page_pseudo_class = NULL;
}
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (css_expression) {
@@ -4214,18 +4009,21 @@ cr_parser_parse_page (CRParser * a_this)
*@param a_value out parameter. The actual parsed value of the charset
*declararation. Note that for safety check reasons, *a_value must be
*set to NULL.
+ *@param a_charset_sym_location the parsing location of
*@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, CRString ** a_value,
+ CRParsingLocation *a_charset_sym_location)
{
enum CRStatus status = CR_OK;
CRInputPos init_pos;
CRToken *token = NULL;
- GString *charset_str = NULL;
+ CRString *charset_str = NULL;
g_return_val_if_fail (a_this && a_value
- && (*a_value == NULL), CR_BAD_PARAM_ERROR);
+ && (*a_value == NULL),
+ CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@@ -4233,7 +4031,10 @@ cr_parser_parse_charset (CRParser * a_this, GString ** a_value)
ENSURE_PARSING_COND (status == CR_OK
&& token && token->type == CHARSET_SYM_TK);
-
+ if (a_charset_sym_location) {
+ cr_parsing_location_copy (a_charset_sym_location,
+ &token->location) ;
+ }
cr_token_destroy (token);
token = NULL;
@@ -4266,7 +4067,7 @@ cr_parser_parse_charset (CRParser * a_this, GString ** a_value)
PRIVATE (a_this)->state = CHARSET_PARSED_STATE;
return CR_OK;
- error:
+ error:
if (token) {
cr_token_destroy (token);
@@ -4274,12 +4075,12 @@ cr_parser_parse_charset (CRParser * a_this, GString ** a_value)
}
if (*a_value) {
- g_string_free (*a_value, TRUE);
+ cr_string_destroy (*a_value);
*a_value = NULL;
}
if (charset_str) {
- g_string_free (charset_str, TRUE);
+ cr_string_destroy (charset_str);
charset_str = NULL;
}
@@ -4303,12 +4104,13 @@ cr_parser_parse_font_face (CRParser * a_this)
{
enum CRStatus status = CR_ERROR;
CRInputPos init_pos;
- GString *property = NULL;
+ CRString *property = NULL;
CRTerm *css_expression = NULL;
CRToken *token = NULL;
gboolean important = FALSE;
guint32 next_char = 0,
cur_char = 0;
+ CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
@@ -4316,14 +4118,18 @@ cr_parser_parse_font_face (CRParser * a_this)
status = cr_tknzr_get_next_token (PRIVATE (a_this)->tknzr, &token);
ENSURE_PARSING_COND (status == CR_OK
- && token && token->type == FONT_FACE_SYM_TK);
+ && token
+ && token->type == FONT_FACE_SYM_TK);
cr_parser_try_to_skip_spaces_and_comments (a_this);
if (token) {
+ cr_parsing_location_copy (&location,
+ &token->location) ;
cr_token_destroy (token);
token = NULL;
}
- 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);
if (token) {
@@ -4336,7 +4142,7 @@ cr_parser_parse_font_face (CRParser * a_this)
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)->sac_handler, &location);
}
PRIVATE (a_this)->state = TRY_PARSE_FONT_FACE_STATE;
/*
@@ -4360,7 +4166,7 @@ cr_parser_parse_font_face (CRParser * a_this)
}
/*free the data structures allocated during last parsing. */
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (css_expression) {
@@ -4375,7 +4181,8 @@ cr_parser_parse_font_face (CRParser * a_this)
break;
}
cr_parser_try_to_skip_spaces_and_comments (a_this);
- status = cr_parser_parse_declaration (a_this, &property,
+ status = cr_parser_parse_declaration (a_this,
+ &property,
&css_expression,
&important);
if (status != CR_OK)
@@ -4394,7 +4201,7 @@ cr_parser_parse_font_face (CRParser * a_this)
*last parsing.
*/
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (css_expression) {
@@ -4428,7 +4235,7 @@ cr_parser_parse_font_face (CRParser * a_this)
token = NULL;
}
if (property) {
- g_string_free (property, TRUE);
+ cr_string_destroy (property);
property = NULL;
}
if (css_expression) {
@@ -4498,6 +4305,25 @@ cr_parser_get_tknzr (CRParser * a_this, CRTknzr ** a_tknzr)
}
/**
+ *Gets the current parsing location.
+ *@param a_this the current instance of #CRParser
+ *@param a_loc the parsing location to get.
+ *@return CR_OK upon succesful completion, an error code
+ *otherwise.
+ */
+enum CRStatus
+cr_parser_get_parsing_location (CRParser *a_this,
+ CRParsingLocation *a_loc)
+{
+ g_return_val_if_fail (a_this
+ && PRIVATE (a_this)
+ && a_loc, CR_BAD_PARAM_ERROR) ;
+
+ return cr_tknzr_get_parsing_location
+ (PRIVATE (a_this)->tknzr, a_loc) ;
+}
+
+/**
*Parses a stylesheet from a buffer
*@param a_this the current instance of #CRparser
*@param a_buf the input buffer
diff --git a/src/cr-parser.h b/src/cr-parser.h
index f67b682..7613112 100644
--- a/src/cr-parser.h
+++ b/src/cr-parser.h
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for copyrights information.
*/
@@ -51,101 +52,80 @@ typedef struct _CRParserPriv CRParserPriv ;
*and must be manipulated through
*the provided methods.
*/
-struct _CRParser
-{
+struct _CRParser {
CRParserPriv *priv ;
} ;
-CRParser *
-cr_parser_new (CRTknzr *a_tknzr) ;
-CRParser *
-cr_parser_new_from_buf (guchar *a_buf, gulong a_len,
+CRParser * cr_parser_new (CRTknzr *a_tknzr) ;
+
+CRParser * cr_parser_new_from_buf (guchar *a_buf, gulong a_len,
enum CREncoding a_enc,
gboolean a_free_buf) ;
-CRParser *
-cr_parser_new_from_file (const guchar *a_file_uri,
- enum CREncoding a_enc) ;
-CRParser *
-cr_parser_new_from_input (CRInput *a_input) ;
+CRParser * cr_parser_new_from_file (const guchar *a_file_uri,
+ enum CREncoding a_enc) ;
+
+CRParser * cr_parser_new_from_input (CRInput *a_input) ;
+
+enum CRStatus cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) ;
+
+enum CRStatus cr_parser_get_tknzr (CRParser *a_this, CRTknzr **a_tknzr) ;
-enum CRStatus
-cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) ;
+enum CRStatus cr_parser_get_parsing_location (CRParser *a_this, CRParsingLocation *a_loc) ;
-enum CRStatus
-cr_parser_get_tknzr (CRParser *a_this, CRTknzr **a_tknzr) ;
+enum CRStatus cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) ;
-enum CRStatus
-cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) ;
+enum CRStatus cr_parser_set_sac_handler (CRParser *a_this,
+ CRDocHandler *a_handler) ;
-enum CRStatus
-cr_parser_set_sac_handler (CRParser *a_this,
- CRDocHandler *a_handler) ;
+enum CRStatus cr_parser_get_sac_handler (CRParser *a_this,
+ CRDocHandler **a_handler) ;
-enum CRStatus
-cr_parser_get_sac_handler (CRParser *a_this,
- CRDocHandler **a_handler) ;
-enum CRStatus
-cr_parser_set_use_core_grammar (CRParser *a_this,
- gboolean a_use_core_grammar) ;
-enum CRStatus
-cr_parser_get_use_core_grammar (CRParser *a_this,
- gboolean *a_use_core_grammar) ;
+enum CRStatus cr_parser_set_use_core_grammar (CRParser *a_this,
+ gboolean a_use_core_grammar) ;
+enum CRStatus cr_parser_get_use_core_grammar (CRParser *a_this,
+ gboolean *a_use_core_grammar) ;
-enum CRStatus
-cr_parser_parse (CRParser *a_this) ;
+enum CRStatus cr_parser_parse (CRParser *a_this) ;
-enum CRStatus
-cr_parser_parse_file (CRParser *a_this,
- const guchar *a_file_uri,
- enum CREncoding a_enc) ;
+enum CRStatus cr_parser_parse_file (CRParser *a_this,
+ const guchar *a_file_uri,
+ enum CREncoding a_enc) ;
-enum CRStatus
-cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf,
- gulong a_len, enum CREncoding a_enc) ;
+enum CRStatus cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf,
+ gulong a_len, enum CREncoding a_enc) ;
-enum CRStatus
-cr_parser_set_default_sac_handler (CRParser *a_this) ;
+enum CRStatus cr_parser_set_default_sac_handler (CRParser *a_this) ;
-enum CRStatus
-cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) ;
+enum CRStatus cr_parser_parse_term (CRParser *a_this, CRTerm **a_term) ;
-enum CRStatus
-cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) ;
+enum CRStatus cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) ;
-enum CRStatus
-cr_parser_parse_prio (CRParser *a_this, GString **a_prio) ;
+enum CRStatus cr_parser_parse_prio (CRParser *a_this, CRString **a_prio) ;
-enum CRStatus
-cr_parser_parse_declaration (CRParser *a_this, GString **a_property,
- CRTerm **a_expr, gboolean *a_important) ;
+enum CRStatus cr_parser_parse_declaration (CRParser *a_this, CRString **a_property,
+ CRTerm **a_expr, gboolean *a_important) ;
-enum CRStatus
-cr_parser_parse_statement_core (CRParser *a_this) ;
+enum CRStatus cr_parser_parse_statement_core (CRParser *a_this) ;
-enum CRStatus
-cr_parser_parse_ruleset (CRParser *a_this) ;
+enum CRStatus cr_parser_parse_ruleset (CRParser *a_this) ;
-enum CRStatus
-cr_parser_parse_import (CRParser *a_this, GList ** a_media_list,
- GString **a_import_string) ;
+enum CRStatus cr_parser_parse_import (CRParser *a_this, GList ** a_media_list,
+ CRString **a_import_string,
+ CRParsingLocation *a_location) ;
-enum CRStatus
-cr_parser_parse_media (CRParser *a_this) ;
+enum CRStatus cr_parser_parse_media (CRParser *a_this) ;
-enum CRStatus
-cr_parser_parse_page (CRParser *a_this) ;
+enum CRStatus cr_parser_parse_page (CRParser *a_this) ;
-enum CRStatus
-cr_parser_parse_charset (CRParser *a_this, GString **a_value) ;
+enum CRStatus cr_parser_parse_charset (CRParser *a_this, CRString **a_value,
+ CRParsingLocation *a_charset_sym_location) ;
-enum CRStatus
-cr_parser_parse_font_face (CRParser *a_this) ;
+enum CRStatus cr_parser_parse_font_face (CRParser *a_this) ;
-void
-cr_parser_destroy (CRParser *a_this) ;
+void cr_parser_destroy (CRParser *a_this) ;
G_END_DECLS
diff --git a/src/cr-prop-list.c b/src/cr-prop-list.c
index acdca79..4c56b9c 100644
--- a/src/cr-prop-list.c
+++ b/src/cr-prop-list.c
@@ -15,6 +15,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for copyrights information.
*/
@@ -24,7 +25,7 @@
#define PRIVATE(a_obj) (a_obj)->priv
struct _CRPropListPriv {
- GString *prop;
+ CRString *prop;
CRDeclaration *decl;
CRPropList *next;
CRPropList *prev;
@@ -100,7 +101,8 @@ cr_prop_list_append (CRPropList * a_this, CRPropList * a_to_append)
*/
CRPropList *
cr_prop_list_append2 (CRPropList * a_this,
- GString * a_prop, CRDeclaration * a_decl)
+ CRString * a_prop,
+ CRDeclaration * a_decl)
{
CRPropList *list = NULL,
*result = NULL;
@@ -147,7 +149,7 @@ cr_prop_list_prepend (CRPropList * a_this, CRPropList * a_to_prepend)
*/
CRPropList *
cr_prop_list_prepend2 (CRPropList * a_this,
- GString * a_prop, CRDeclaration * a_decl)
+ CRString * a_prop, CRDeclaration * a_decl)
{
CRPropList *list = NULL,
*result = NULL;
@@ -169,7 +171,7 @@ 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, CRString * a_prop)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_prop, CR_BAD_PARAM_ERROR);
@@ -187,7 +189,7 @@ cr_prop_list_set_prop (CRPropList * a_this, GString * a_prop)
*otherwise.
*/
enum CRStatus
-cr_prop_list_get_prop (CRPropList * a_this, GString ** a_prop)
+cr_prop_list_get_prop (CRPropList * a_this, CRString ** a_prop)
{
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& a_prop, CR_BAD_PARAM_ERROR);
@@ -228,7 +230,7 @@ cr_prop_list_get_decl (CRPropList * a_this, CRDeclaration ** a_decl)
*/
enum CRStatus
cr_prop_list_lookup_prop (CRPropList * a_this,
- GString * a_prop, CRPropList ** a_pair)
+ CRString * a_prop, CRPropList ** a_pair)
{
CRPropList *cur = NULL;
@@ -241,9 +243,12 @@ cr_prop_list_lookup_prop (CRPropList * a_this,
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))
+ && PRIVATE (cur)->prop->stryng
+ && PRIVATE (cur)->prop->stryng->str
+ && a_prop->stryng
+ && a_prop->stryng->str
+ && !strcmp (PRIVATE (cur)->prop->stryng->str,
+ a_prop->stryng->str))
break;
}
diff --git a/src/cr-prop-list.h b/src/cr-prop-list.h
index eb6beac..a003be2 100644
--- a/src/cr-prop-list.h
+++ b/src/cr-prop-list.h
@@ -15,6 +15,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for copyrights information.
*/
@@ -23,6 +24,7 @@
#include "cr-utils.h"
#include "cr-declaration.h"
+#include "cr-string.h"
G_BEGIN_DECLS
@@ -38,24 +40,24 @@ CRPropList * cr_prop_list_append (CRPropList *a_this,
CRPropList *a_to_append) ;
CRPropList * cr_prop_list_append2 (CRPropList *a_this,
- GString *a_prop,
+ CRString *a_prop,
CRDeclaration *a_decl) ;
CRPropList * cr_prop_list_prepend (CRPropList *a_this,
CRPropList *a_to_append) ;
CRPropList * cr_prop_list_prepend2 (CRPropList *a_this,
- GString *a_prop,
+ CRString *a_prop,
CRDeclaration *a_decl) ;
enum CRStatus cr_prop_list_set_prop (CRPropList *a_this,
- GString *a_prop) ;
+ CRString *a_prop) ;
enum CRStatus cr_prop_list_get_prop (CRPropList *a_this,
- GString **a_prop) ;
+ CRString **a_prop) ;
enum CRStatus cr_prop_list_lookup_prop (CRPropList *a_this,
- GString *a_prop,
+ CRString *a_prop,
CRPropList**a_pair) ;
CRPropList * cr_prop_list_get_next (CRPropList *a_this) ;
diff --git a/src/cr-pseudo.c b/src/cr-pseudo.c
index 1e0cd69..8e036a3 100644
--- a/src/cr-pseudo.c
+++ b/src/cr-pseudo.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
#include "cr-pseudo.h"
@@ -62,10 +59,11 @@ cr_pseudo_to_string (CRPseudo * a_this)
goto error;
}
- name = g_strndup (a_this->name->str, a_this->name->len);
+ name = g_strndup (a_this->name->stryng->str,
+ a_this->name->stryng->len);
if (name) {
- g_string_append_printf (str_buf, "%s", name);
+ g_string_append (str_buf, name);
g_free (name);
name = NULL;
}
@@ -76,11 +74,12 @@ cr_pseudo_to_string (CRPseudo * a_this)
if (a_this->name == NULL)
goto error;
- name = g_strndup (a_this->name->str, a_this->name->len);
+ name = g_strndup (a_this->name->stryng->str,
+ a_this->name->stryng->len);
if (a_this->extra) {
- arg = g_strndup (a_this->extra->str,
- a_this->extra->len);
+ arg = g_strndup (a_this->extra->stryng->str,
+ a_this->extra->stryng->len);
}
if (name) {
@@ -89,12 +88,12 @@ cr_pseudo_to_string (CRPseudo * a_this)
name = NULL;
if (arg) {
- g_string_append_printf (str_buf, "%s", arg);
+ g_string_append (str_buf, arg);
g_free (arg);
arg = NULL;
}
- g_string_append_printf (str_buf, ")");
+ g_string_append_c (str_buf, ')');
}
}
@@ -141,12 +140,12 @@ cr_pseudo_destroy (CRPseudo * a_this)
g_return_if_fail (a_this);
if (a_this->name) {
- g_string_free (a_this->name, TRUE);
+ cr_string_destroy (a_this->name);
a_this->name = NULL;
}
if (a_this->extra) {
- g_string_free (a_this->extra, TRUE);
+ cr_string_destroy (a_this->extra);
a_this->extra = NULL;
}
diff --git a/src/cr-pseudo.h b/src/cr-pseudo.h
index 1949612..6de6c9e 100644
--- a/src/cr-pseudo.h
+++ b/src/cr-pseudo.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji at seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,8 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * See COPYRIGHTS file for copyright information
*/
#ifndef __CR_PSEUDO_H__
@@ -30,6 +26,7 @@
#include <stdio.h>
#include <glib.h>
#include "cr-attr-sel.h"
+#include "cr-parsing-location.h"
G_BEGIN_DECLS
@@ -49,21 +46,18 @@ typedef struct _CRPseudo CRPseudo ;
struct _CRPseudo
{
enum CRPseudoType type ;
- GString *name ;
- GString *extra ;
+ CRString *name ;
+ CRString *extra ;
+ CRParsingLocation location ;
} ;
-CRPseudo *
-cr_pseudo_new (void) ;
+CRPseudo * cr_pseudo_new (void) ;
-guchar *
-cr_pseudo_to_string (CRPseudo *a_this) ;
+guchar * cr_pseudo_to_string (CRPseudo *a_this) ;
-void
-cr_pseudo_dump (CRPseudo *a_this, FILE *a_fp) ;
+void cr_pseudo_dump (CRPseudo *a_this, FILE *a_fp) ;
-void
-cr_pseudo_destroy (CRPseudo *a_this) ;
+void cr_pseudo_destroy (CRPseudo *a_this) ;
G_END_DECLS
diff --git a/src/cr-rgb.c b/src/cr-rgb.c
index c125675..dac1d53 100644
--- a/src/cr-rgb.c
+++ b/src/cr-rgb.c
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for copyrights information.
*/
@@ -240,24 +241,22 @@ cr_rgb_to_string (CRRgb * a_this)
str_buf = g_string_new (NULL);
g_return_val_if_fail (str_buf, NULL);
- if (a_this->is_percentage == TRUE) {
+ if (a_this->is_percentage == 1) {
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 (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 (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 (str_buf, ", ");
g_string_append_printf (str_buf, "%ld", a_this->green);
- g_string_append_printf (str_buf, ", ");
+ g_string_append (str_buf, ", ");
g_string_append_printf (str_buf, "%ld", a_this->blue);
}
@@ -338,11 +337,36 @@ cr_rgb_set (CRRgb * a_this, gulong a_red,
a_this->red = a_red;
a_this->green = a_green;
a_this->blue = a_blue;
-
+ a_this->inherit = FALSE ;
return CR_OK;
}
/**
+ *sets the value of the rgb to inherit.
+ *Look at the css spec from chapter 6.1 to 6.2 to understand
+ *the meaning of "inherit".
+ *@param a_this the current instance of #CRRgb
+ *
+ */
+enum CRStatus
+cr_rgb_set_to_inherit (CRRgb *a_this)
+{
+ g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
+
+ a_this->inherit = TRUE ;
+
+ return CR_OK ;
+}
+
+gboolean
+cr_rgb_is_set_to_inherit (CRRgb *a_this)
+{
+ g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ;
+
+ return a_this->inherit ;
+}
+
+/**
*Sets the rgb from an other one.
*@param a_this the current instance of #CRRgb.
*@param a_rgb the rgb to "copy"
@@ -455,19 +479,41 @@ cr_rgb_set_from_term (CRRgb *a_this, const struct _CRTerm *a_value)
}
break ;
case TERM_IDENT:
- status = cr_rgb_set_from_name
- (a_this,
- a_value->content.str->str) ;
+ if (a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
+ if (!strncmp ("inherit",
+ a_value->content.str->stryng->str,
+ sizeof ("inherit")-1))
+ {
+ a_this->inherit = TRUE;
+ }
+ else
+ {
+ status = cr_rgb_set_from_name
+ (a_this,
+ a_value->content.str->stryng->str) ;
+ }
+ } else {
+ cr_utils_trace_info
+ ("a_value has NULL string value") ;
+ }
break ;
case TERM_HASH:
- status = cr_rgb_set_from_hex_str
- (a_this,
- a_value->content.str->str) ;
+ if (a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
+ status = cr_rgb_set_from_hex_str
+ (a_this,
+ a_value->content.str->stryng->str) ;
+ } else {
+ cr_utils_trace_info
+ ("a_value has NULL string value") ;
+ }
break ;
default:
status = CR_UNKNOWN_TYPE_ERROR ;
}
-
return status ;
}
@@ -480,7 +526,6 @@ void
cr_rgb_destroy (CRRgb * a_this)
{
g_return_if_fail (a_this);
-
g_free (a_this);
}
diff --git a/src/cr-rgb.h b/src/cr-rgb.h
index 2918a4c..e61169a 100644
--- a/src/cr-rgb.h
+++ b/src/cr-rgb.h
@@ -26,6 +26,7 @@
#include <stdio.h>
#include <glib.h>
#include "cr-utils.h"
+#include "cr-parsing-location.h"
G_BEGIN_DECLS
@@ -43,6 +44,8 @@ struct _CRRgb
glong green ;
glong blue ;
gboolean is_percentage ;
+ gboolean inherit ;
+ CRParsingLocation location ;
} ;
CRRgb * cr_rgb_new (void) ;
@@ -58,7 +61,11 @@ enum CRStatus cr_rgb_compute_from_percentage (CRRgb *a_this) ;
enum CRStatus cr_rgb_set (CRRgb *a_this, gulong a_red,
gulong a_green, gulong a_blue,
gboolean a_is_percentage) ;
-
+
+enum CRStatus cr_rgb_set_to_inherit (CRRgb *a_this) ;
+
+gboolean cr_rgb_is_set_to_inherit (CRRgb *a_this) ;
+
enum CRStatus cr_rgb_set_from_rgb (CRRgb *a_this, CRRgb *a_rgb) ;
enum CRStatus cr_rgb_set_from_name (CRRgb *a_this, const guchar *a_color_name) ;
diff --git a/src/cr-sel-eng.c b/src/cr-sel-eng.c
index 82d70c4..daa30b7 100644
--- a/src/cr-sel-eng.c
+++ b/src/cr-sel-eng.c
@@ -53,7 +53,7 @@ struct _CRSelEngPriv {
CRStatement *cur_stmt;
GList *pcs_handlers;
gint pcs_handlers_size;
-};
+} ;
static gboolean class_add_sel_matches_node (CRAdditionalSel * a_add_sel,
xmlNode * a_node);
@@ -68,6 +68,7 @@ static enum CRStatus sel_matches_node_real (CRSelEng * a_this,
CRSimpleSel * a_sel,
xmlNode * a_node,
gboolean * a_result,
+ gboolean a_eval_sel_list_from_end,
gboolean a_recurse);
static enum CRStatus cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this,
@@ -78,19 +79,9 @@ static enum CRStatus cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this,
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);
-#else
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 *
@@ -125,23 +116,26 @@ lang_pseudo_class_handler (CRSelEng * a_this,
&& a_sel && a_sel->content.pseudo
&& a_sel->content.pseudo
&& a_sel->content.pseudo->name
+ && a_sel->content.pseudo->name->stryng
&& a_node, CR_BAD_PARAM_ERROR);
- if (strncmp (a_sel->content.pseudo->name->str, "lang", 4)
+ if (strncmp (a_sel->content.pseudo->name->stryng->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)
+ || !a_sel->content.pseudo->extra->stryng
+ || a_sel->content.pseudo->extra->stryng->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)) {
+ a_sel->content.pseudo->extra->stryng->str,
+ a_sel->content.pseudo->extra->stryng->len)) {
result = TRUE;
}
if (val) {
@@ -163,9 +157,11 @@ first_child_pseudo_class_handler (CRSelEng * a_this,
&& a_sel && a_sel->content.pseudo
&& a_sel->content.pseudo
&& a_sel->content.pseudo->name
+ && a_sel->content.pseudo->name->stryng
&& a_node, CR_BAD_PARAM_ERROR);
- if (strcmp (a_sel->content.pseudo->name->str, "first-child")
+ if (strcmp (a_sel->content.pseudo->name->stryng->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;
@@ -190,11 +186,12 @@ pseudo_class_add_sel_matches_node (CRSelEng * a_this,
&& a_add_sel
&& a_add_sel->content.pseudo
&& a_add_sel->content.pseudo->name
- && a_add_sel->content.pseudo->name->str
+ && a_add_sel->content.pseudo->name->stryng
+ && a_add_sel->content.pseudo->name->stryng->str
&& 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_this, a_add_sel->content.pseudo->name->stryng->str,
a_add_sel->content.pseudo->type, &handler);
if (status != CR_OK || !handler)
return FALSE;
@@ -218,7 +215,8 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
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_add_sel->content.class_name->stryng
+ && a_add_sel->content.class_name->stryng->str
&& a_node, FALSE);
if (xmlHasProp (a_node, "class")) {
@@ -228,11 +226,11 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
&& cr_utils_is_white_space (*cur)
== TRUE)
cur++;
- if (!*cur)
- break;
- if (!strncmp (cur, a_add_sel->content.class_name->str,
- a_add_sel->content.class_name->len)) {
- cur += a_add_sel->content.class_name->len;
+
+ if (!strncmp (cur,
+ a_add_sel->content.class_name->stryng->str,
+ a_add_sel->content.class_name->stryng->len)) {
+ cur += a_add_sel->content.class_name->stryng->len;
if ((cur && !*cur)
|| cr_utils_is_white_space (*cur) == TRUE)
result = TRUE;
@@ -241,7 +239,6 @@ class_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
break ;
}
}
-
if (klass) {
xmlFree (klass);
klass = NULL;
@@ -265,7 +262,8 @@ id_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
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_add_sel->content.id_name->stryng
+ && a_add_sel->content.id_name->stryng->str
&& a_node, FALSE);
g_return_val_if_fail (a_add_sel
&& a_add_sel->type == ID_ADD_SELECTOR
@@ -273,12 +271,11 @@ id_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
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)) {
+ if (!strncmp (id, a_add_sel->content.id_name->stryng->str,
+ a_add_sel->content.id_name->stryng->len)) {
result = TRUE;
}
}
-
if (id) {
xmlFree (id);
id = NULL;
@@ -308,10 +305,13 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
cur_sel; cur_sel = cur_sel->next) {
switch (cur_sel->match_way) {
case SET:
- if (!cur_sel->name || !cur_sel->name->str)
+ if (!cur_sel->name
+ || !cur_sel->name->stryng
+ || !cur_sel->name->stryng->str)
return FALSE;
- if (!xmlHasProp (a_node, cur_sel->name->str))
+ if (!xmlHasProp (a_node,
+ cur_sel->name->stryng->str))
return FALSE;
break;
@@ -319,20 +319,27 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
{
xmlChar *value = NULL;
- if (!cur_sel->name || !cur_sel->name->str
+ if (!cur_sel->name
+ || !cur_sel->name->stryng
+ || !cur_sel->name->stryng->str
|| !cur_sel->value
- || !cur_sel->value->str)
+ || !cur_sel->value->stryng
+ || !cur_sel->value->stryng->str)
return FALSE;
- if (!xmlHasProp (a_node, cur_sel->name->str))
+ if (!xmlHasProp
+ (a_node,
+ cur_sel->name->stryng->str))
return FALSE;
- value = xmlGetProp (a_node,
- cur_sel->name->str);
+ value = xmlGetProp
+ (a_node,
+ cur_sel->name->stryng->str);
if (value
- && strncmp (value, cur_sel->value->str,
- cur_sel->value->len)) {
+ && strcmp
+ (value,
+ cur_sel->value->stryng->str)) {
xmlFree (value);
return FALSE;
}
@@ -348,10 +355,13 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
*cur = NULL;
gboolean found = FALSE;
- if (!xmlHasProp (a_node, cur_sel->name->str))
+ if (!xmlHasProp
+ (a_node,
+ cur_sel->name->stryng->str))
return FALSE;
- value = xmlGetProp (a_node,
- cur_sel->name->str);
+ value = xmlGetProp
+ (a_node,
+ cur_sel->name->stryng->str);
if (!value)
return FALSE;
@@ -379,13 +389,12 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
while (cr_utils_is_white_space
(*cur) == FALSE && *cur)
cur++;
- if (!*cur)
- break;
cur--;
ptr2 = cur;
if (!strncmp
- (ptr1, cur_sel->value->str,
+ (ptr1,
+ cur_sel->value->stryng->str,
ptr2 - ptr1 + 1)) {
found = TRUE;
break;
@@ -409,10 +418,13 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
*cur = NULL;
gboolean found = FALSE;
- if (!xmlHasProp (a_node, cur_sel->name->str))
+ if (!xmlHasProp
+ (a_node,
+ cur_sel->name->stryng->str))
return FALSE;
- value = xmlGetProp (a_node,
- cur_sel->name->str);
+ value = xmlGetProp
+ (a_node,
+ cur_sel->name->stryng->str);
/*
*here, make sure value is an hyphen
@@ -426,14 +438,12 @@ attr_add_sel_matches_node (CRAdditionalSel * a_add_sel, xmlNode * a_node)
while (*cur != '-' && *cur)
cur++;
- if (!*cur)
- break;
cur--;
ptr2 = cur;
if (g_strstr_len
(ptr1, ptr2 - ptr1 + 1,
- cur_sel->value->str)
+ cur_sel->value->stryng->str)
== (gchar *) ptr1) {
found = TRUE;
break;
@@ -466,49 +476,65 @@ additional_selector_matches_node (CRSelEng * a_this,
CRAdditionalSel * a_add_sel,
xmlNode * a_node)
{
- if (!a_add_sel) {
- return FALSE;
- }
+ CRAdditionalSel *cur_add_sel = NULL, *tail = NULL ;
+ gboolean evaluated = FALSE ;
- if (a_add_sel->type == NO_ADD_SELECTOR) {
- return FALSE;
- }
+ for (tail = a_add_sel ;
+ tail && tail->next;
+ tail = tail->next) ;
- 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;
- }
- 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) {
+ g_return_val_if_fail (tail, FALSE) ;
+
+ for (cur_add_sel = tail ;
+ cur_add_sel ;
+ cur_add_sel = cur_add_sel->prev) {
+
+ evaluated = TRUE ;
+ if (cur_add_sel->type == NO_ADD_SELECTOR) {
return FALSE;
}
- 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) {
+
+ if (cur_add_sel->type == CLASS_ADD_SELECTOR
+ && cur_add_sel->content.class_name
+ && cur_add_sel->content.class_name->stryng
+ && cur_add_sel->content.class_name->stryng->str) {
+ if (class_add_sel_matches_node (cur_add_sel,
+ a_node) == FALSE) {
+ return FALSE;
+ }
+ continue ;
+ } else if (cur_add_sel->type == ID_ADD_SELECTOR
+ && cur_add_sel->content.id_name
+ && cur_add_sel->content.id_name->stryng
+ && cur_add_sel->content.id_name->stryng->str) {
+ if (id_add_sel_matches_node (cur_add_sel, a_node) == FALSE) {
+ return FALSE;
+ }
+ continue ;
+ } else if (cur_add_sel->type == ATTRIBUTE_ADD_SELECTOR
+ && cur_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 (cur_add_sel, a_node)
+ == FALSE) {
+ return FALSE;
+ }
+ continue ;
+ } else if (cur_add_sel->type == PSEUDO_CLASS_ADD_SELECTOR
+ && cur_add_sel->content.pseudo) {
+ if (pseudo_class_add_sel_matches_node
+ (a_this, cur_add_sel, a_node) == TRUE) {
+ return TRUE;
+ }
return FALSE;
}
- 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;
- }
- return FALSE;
}
- return FALSE;
+ if (evaluated == TRUE)
+ return TRUE;
+ return FALSE ;
}
static xmlNode *
@@ -589,6 +615,7 @@ get_next_parent_element_node (xmlNode * a_node)
static enum CRStatus
sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel,
xmlNode * a_node, gboolean * a_result,
+ gboolean a_eval_sel_list_from_end,
gboolean a_recurse)
{
CRSimpleSel *cur_sel = NULL;
@@ -603,7 +630,7 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel,
if (a_node->type != XML_ELEMENT_NODE)
return CR_OK;
- if (a_recurse == TRUE) {
+ if (a_eval_sel_list_from_end == 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) ;
@@ -612,46 +639,48 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * 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)) {
- /*
- *this simple selector
- *matches the current xml node
- *Let's see if the preceding
- *simple selectors also match
- *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;
- } else {
- goto done;
- }
- } else {
- goto walk_a_step_in_expr;
- }
+ if (((cur_sel->type_mask & TYPE_SELECTOR)
+ && (cur_sel->name
+ && cur_sel->name->stryng
+ && cur_sel->name->stryng->str)
+ && (!strcmp (cur_sel->name->stryng->str,
+ cur_node->name)))
+ || (cur_sel->type_mask & UNIVERSAL_SELECTOR)) {
+ /*
+ *this simple selector
+ *matches the current xml node
+ *Let's see if the preceding
+ *simple selectors also match
+ *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;
+ } else {
+ goto done;
}
+ } else {
+ goto walk_a_step_in_expr;
+ }
+ }
+ if (!(cur_sel->type_mask & TYPE_SELECTOR)
+ && !(cur_sel->type_mask & UNIVERSAL_SELECTOR)) {
+ 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;
}
- }
-
- 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:
+ walk_a_step_in_expr:
if (a_recurse == FALSE) {
*a_result = TRUE;
goto done;
@@ -670,44 +699,46 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel,
break;
case COMB_WS: /*descendant selector */
- {
- xmlNode *n = NULL;
- enum CRStatus status = CR_OK;
- gboolean matches = FALSE;
+ {
+ 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;
- }
- }
+ /*
+ *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, TRUE);
- if (!n) {
- /*
- *didn't find any ancestor that matches
- *the previous simple selector.
- */
+ if (status != CR_OK)
goto done;
+
+ if (matches == TRUE) {
+ cur_node = n ;
+ break;
}
+ }
+
+ if (!n) {
/*
- *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.
+ *didn't find any ancestor that matches
+ *the previous simple selector.
*/
- break;
+ goto done;
}
+ /*
+ *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);
@@ -733,10 +764,11 @@ sel_matches_node_real (CRSelEng * a_this, CRSimpleSel * a_sel,
*/
*a_result = TRUE;
- done:
+ done:
return CR_OK;
}
+
/**
*Returns array of the ruleset statements that matches the
*given xml node.
@@ -921,131 +953,6 @@ cr_sel_eng_get_matched_rulesets_real (CRSelEng * a_this,
return CR_OK;
}
-#ifndef NEW_PROPERTIES_GETTER
-/**
- *Walks through the property/value pairs of a ruleset
- *statement and put the properties found into a hashtable.
- *Each key of the hashtable is a css property. The
- *associated value is a pointer to the current #CRDeclaration.
- *This function is where the cascading property sorting is done.
- *
- *@param a_props_hashtable in/out parameter. The hashtable into
- *which the the property/Declaration pairs will be added.
- *Note that each hashtable key (a statement property) is a null terminated
- *instance of guchar *.
- *Each value associated to a key is an instance of #CRDeclaration.
- *The declaration is actually the css declaration (rule)
- *that contains the property (the key).
- *@param a_ruleset the ruleset from wich the properties are gathered.
- *@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)
-{
- 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);
-
- if (!*a_props_hashtable) {
- *a_props_hashtable = g_hash_table_new (g_str_hash,
- g_str_equal);
- }
- props_hash = *a_props_hashtable;
-
- 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;
-
- /*
- *First, test if the property is not
- *already present in our properties hashtable.
- *If yes, apply the cascading rules to
- *compute the precedence. If not, insert
- *the property into the hashtable.
- */
- decl = g_hash_table_lookup
- (props_hash, cur_decl->property->str);
-
- if (!decl) {
- g_hash_table_replace
- (props_hash,
- cur_decl->property->str, cur_decl);
- continue;
- }
-
- /*
- *A property with the same name already exists.
- *We must apply here
- *some cascading rules
- *to compute the precedence.
- */
-
- /*
- *first, look at the origin.
- *6.4.1 says:
- *"for normal declarations,
- *author style sheets override user
- *style sheets which override
- *the default style sheet."
- */
- if (decl->parent_statement
- && decl->parent_statement->parent_sheet
- && (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;
- }
-
- /*
- *A property with the same
- *name and the same origin already exist.
- *shit. This is lasting longer than expected ...
- *Luckily, the spec says in 6.4.1:
- *"more specific selectors will override
- *more general ones"
- *and
- *"if two rules have the same weight,
- *origin and specificity,
- *the latter specified wins"
- */
- if (a_stmt->specificity
- >= decl->parent_statement->specificity) {
- g_hash_table_insert
- (props_hash,
- cur_decl->property->str, cur_decl);
- }
- }
- 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;
-
- g_return_if_fail (a_decl && a_prop && a_style);
-
- cr_style_set_style_from_decl (style, decl);
-}
-#else
static enum CRStatus
put_css_properties_in_props_list (CRPropList ** a_props, CRStatement * a_stmt)
{
@@ -1067,7 +974,9 @@ put_css_properties_in_props_list (CRPropList ** a_props, CRStatement * a_stmt)
decl = NULL;
pair = NULL;
- if (!cur_decl->property || !cur_decl->property->str)
+ if (!cur_decl->property
+ || !cur_decl->property->stryng
+ || !cur_decl->property->stryng->str)
continue;
/*
*First, test if the property is not
@@ -1076,7 +985,9 @@ put_css_properties_in_props_list (CRPropList ** a_props, CRStatement * a_stmt)
*compute the precedence. If not, insert
*the property into the list
*/
- cr_prop_list_lookup_prop (props, cur_decl->property, &pair);
+ cr_prop_list_lookup_prop (props,
+ cur_decl->property,
+ &pair);
if (!pair) {
tmp_props = cr_prop_list_append2
@@ -1185,7 +1096,6 @@ set_style_from_props (CRStyle * a_style, CRPropList * a_props)
decl = NULL;
}
}
-#endif
/****************************************
*PUBLIC METHODS
@@ -1391,7 +1301,9 @@ cr_sel_eng_matches_node (CRSelEng * a_this, CRSimpleSel * a_sel,
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, TRUE);
}
/**
@@ -1475,114 +1387,7 @@ cr_sel_eng_get_matched_rulesets (CRSelEng * a_this,
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)
-{
- 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);
-
- for (origin = ORIGIN_UA; origin < NB_ORIGINS; origin++) {
- sheet = cr_cascade_get_sheet (a_cascade, origin);
- if (!sheet)
- 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;
- }
- 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;
- }
- while ((status = cr_sel_eng_get_matched_rulesets_real
- (a_this, sheet, a_node, stmts_tab + index, &tab_len))
- == 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;
- }
- 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;
- }
- if (status != CR_OK) {
- cr_utils_trace_info ("Error while running "
- "selector engine");
- goto error;
- }
- index += tab_len;
- tab_len = tab_size - index;
- }
-
- /*
- *TODO, walk down the stmts_tab and build the
- *property_name/declaration hashtable.
- *Make sure one can walk from the declaration to
- *the stylesheet.
- */
- for (i = 0; i < index; i++) {
- CRStatement *stmt = stmts_tab[i];
-
- if (!stmt)
- continue;
- switch (stmt->type) {
- case RULESET_STMT:
- if (!stmt->parent_sheet)
- continue;
- status = put_css_properties_in_hashtable
- (a_props_hashtable, stmt);
- break;
- default:
- break;
- }
-
- }
-
- return CR_OK;
- error:
-
- if (stmts_tab) {
- g_free (stmts_tab);
- stmts_tab = NULL;
-
- }
-
- return status;
-}
-#else
enum CRStatus
cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this,
CRCascade * a_cascade,
@@ -1683,60 +1488,36 @@ cr_sel_eng_get_matched_properties_from_cascade (CRSelEng * a_this,
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)
+ CRStyle * a_parent_style,
+ CRStyle ** a_style,
+ gboolean a_set_props_to_initial_values)
{
enum CRStatus status = CR_OK;
-#ifndef NEW_PROPERTIES_GETTER
- GHashTable *props_hash = NULL;
-#else
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);
-#else
+
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);
-
-#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);
- }
- (*a_style)->parent_style = a_parent_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;
- }
-#else
+ g_return_val_if_fail (status == CR_OK, status);
if (props) {
-
if (!*a_style) {
- *a_style = cr_style_new ();
+ *a_style = cr_style_new (a_set_props_to_initial_values) ;
g_return_val_if_fail (*a_style, CR_ERROR);
} else {
- cr_style_set_props_to_defaults (*a_style);
+ if (a_set_props_to_initial_values == TRUE) {
+ cr_style_set_props_to_initial_values (*a_style) ;
+ } else {
+ cr_style_set_props_to_default_values (*a_style);
+ }
}
(*a_style)->parent_style = a_parent_style;
@@ -1746,7 +1527,6 @@ cr_sel_eng_get_matched_style (CRSelEng * a_this,
props = NULL;
}
}
-#endif
return CR_OK;
}
diff --git a/src/cr-sel-eng.h b/src/cr-sel-eng.h
index c6b30f0..e64d133 100644
--- a/src/cr-sel-eng.h
+++ b/src/cr-sel-eng.h
@@ -17,21 +17,18 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for copyrights information.
*/
#ifndef __CR_SEL_ENG_H__
#define __CR_SEL_ENG_H__
-#define NEW_PROPERTIES_GETTER 1
-
#include "cr-utils.h"
#include "cr-stylesheet.h"
#include "cr-cascade.h"
#include "cr-style.h"
-#ifdef NEW_PROPERTIES_GETTER
#include "cr-prop-list.h"
-#endif
#ifdef CROCO_HAVE_LIBXML2
#include <libxml/tree.h>
@@ -96,24 +93,18 @@ enum CRStatus cr_sel_eng_get_matched_rulesets (CRSelEng *a_this,
CRStatement ***a_rulesets,
gulong *a_len) ;
-#ifndef NEW_PROPERTIES_GETTER
-enum CRStatus cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this,
- CRCascade *a_cascade,
- xmlNode *a_node,
- GHashTable **props_decls_dict) ;
-#else
enum CRStatus
cr_sel_eng_get_matched_properties_from_cascade (CRSelEng *a_this,
CRCascade *a_cascade,
xmlNode *a_node,
CRPropList **a_props) ;
-#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) ;
+ CRStyle **a_style,
+ gboolean a_set_props_to_initial_values) ;
void cr_sel_eng_destroy (CRSelEng *a_this) ;
diff --git a/src/cr-selector.c b/src/cr-selector.c
index 498efc5..5f7316a 100644
--- a/src/cr-selector.c
+++ b/src/cr-selector.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,11 +16,10 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * See COPYRIGHTS file for copyright information.
*/
-/*
- *$Id$
- */
#include <string.h>
#include "cr-selector.h"
#include "cr-parser.h"
@@ -145,11 +142,10 @@ cr_selector_to_string (CRSelector * a_this)
if (tmp_str) {
if (cur->prev)
- g_string_append_printf
- (str_buf, ", ");
+ g_string_append (str_buf,
+ ", ");
- g_string_append_printf
- (str_buf, "%s", tmp_str);
+ g_string_append (str_buf, tmp_str);
g_free (tmp_str);
tmp_str = NULL;
diff --git a/src/cr-selector.h b/src/cr-selector.h
index 7c4a983..6bf7697 100644
--- a/src/cr-selector.h
+++ b/src/cr-selector.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,17 +16,19 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
-/*
- *$Id$
- */
#ifndef __CR_SELECTOR_H__
#define __CR_SELECTOR_H__
#include <stdio.h>
#include "cr-utils.h"
#include "cr-simple-sel.h"
+#include "cr-parsing-location.h"
/**
*@file
@@ -64,41 +64,31 @@ struct _CRSelector
/**The next selector list element*/
CRSelector *next ;
CRSelector *prev ;
-
+ CRParsingLocation location ;
glong ref_count ;
};
-CRSelector*
-cr_selector_new (CRSimpleSel *a_sel_expr) ;
+CRSelector* cr_selector_new (CRSimpleSel *a_sel_expr) ;
-CRSelector *
-cr_selector_parse_from_buf (const guchar * a_char_buf,
- enum CREncoding a_enc) ;
+CRSelector * cr_selector_parse_from_buf (const guchar * a_char_buf,
+ enum CREncoding a_enc) ;
-CRSelector*
-cr_selector_append (CRSelector *a_this, CRSelector *a_new) ;
+CRSelector* cr_selector_append (CRSelector *a_this, CRSelector *a_new) ;
-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*
-cr_selector_prepend (CRSelector *a_this, CRSelector *a_new) ;
+CRSelector* cr_selector_prepend (CRSelector *a_this, CRSelector *a_new) ;
-guchar *
-cr_selector_to_string (CRSelector *a_this) ;
+guchar * cr_selector_to_string (CRSelector *a_this) ;
-void
-cr_selector_dump (CRSelector *a_this, FILE *a_fp) ;
+void cr_selector_dump (CRSelector *a_this, FILE *a_fp) ;
-void
-cr_selector_ref (CRSelector *a_this) ;
+void cr_selector_ref (CRSelector *a_this) ;
-gboolean
-cr_selector_unref (CRSelector *a_this) ;
+gboolean cr_selector_unref (CRSelector *a_this) ;
-void
-cr_selector_destroy (CRSelector *a_this) ;
+void cr_selector_destroy (CRSelector *a_this) ;
G_END_DECLS
diff --git a/src/cr-simple-sel.c b/src/cr-simple-sel.c
index 285309f..f0fb9c5 100644
--- a/src/cr-simple-sel.c
+++ b/src/cr-simple-sel.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,6 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
/*
@@ -106,28 +107,28 @@ cr_simple_sel_to_string (CRSimpleSel * a_this)
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);
+ guchar *str = g_strndup (cur->name->stryng->str,
+ cur->name->stryng->len);
if (str) {
switch (cur->combinator) {
case COMB_WS:
- g_string_append_printf (str_buf, " ");
+ g_string_append (str_buf, " ");
break;
case COMB_PLUS:
- g_string_append_printf (str_buf, "+");
+ g_string_append (str_buf, "+");
break;
case COMB_GT:
- g_string_append_printf (str_buf, ">");
+ g_string_append (str_buf, ">");
break;
default:
break;
}
- g_string_append_printf (str_buf, "%s", str);
+ g_string_append (str_buf, str);
g_free (str);
str = NULL;
}
@@ -138,8 +139,7 @@ cr_simple_sel_to_string (CRSimpleSel * a_this)
tmp_str = cr_additional_sel_to_string (cur->add_sel);
if (tmp_str) {
- g_string_append_printf
- (str_buf, "%s", tmp_str);
+ g_string_append (str_buf, tmp_str);
g_free (tmp_str);
tmp_str = NULL;
}
@@ -155,6 +155,48 @@ cr_simple_sel_to_string (CRSimpleSel * a_this)
return result;
}
+
+guchar *
+cr_simple_sel_one_to_string (CRSimpleSel * a_this)
+{
+ GString *str_buf = NULL;
+ guchar *result = NULL;
+
+ g_return_val_if_fail (a_this, NULL);
+
+ str_buf = g_string_new (NULL);
+ if (a_this->name) {
+ guchar *str = g_strndup (a_this->name->stryng->str,
+ a_this->name->stryng->len);
+
+ if (str) {
+ g_string_append_printf (str_buf, "%s", str);
+ g_free (str);
+ str = NULL;
+ }
+ }
+
+ if (a_this->add_sel) {
+ guchar *tmp_str = NULL;
+
+ tmp_str = cr_additional_sel_to_string (a_this->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;
+ }
+
+ return result;
+}
+
/**
*Dumps the selector to a file.
*TODO: add the support of unicode in the dump.
@@ -203,7 +245,9 @@ cr_simple_sel_compute_specificity (CRSimpleSel * a_this)
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) {
+ } else if (!cur_sel->name
+ || !cur_sel->name->stryng
+ || !cur_sel->name->stryng->str) {
if (cur_sel->add_sel->type ==
PSEUDO_CLASS_ADD_SELECTOR) {
/*
@@ -249,7 +293,7 @@ cr_simple_sel_destroy (CRSimpleSel * a_this)
g_return_if_fail (a_this);
if (a_this->name) {
- g_string_free (a_this->name, TRUE);
+ cr_string_destroy (a_this->name);
a_this->name = NULL;
}
diff --git a/src/cr-simple-sel.h b/src/cr-simple-sel.h
index 589aaa6..29033af 100644
--- a/src/cr-simple-sel.h
+++ b/src/cr-simple-sel.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,11 +16,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
-/*
- *$Id$
- */
#ifndef __CR_SEL_H__
#define __CR_SEL_H__
@@ -30,6 +28,7 @@
#include <stdio.h>
#include <glib.h>
#include "cr-additional-sel.h"
+#include "cr-parsing-location.h"
G_BEGIN_DECLS
@@ -76,7 +75,7 @@ struct _CRSimpleSel
{
enum SimpleSelectorType type_mask ;
gboolean is_case_sentive ;
- GString * name ;
+ CRString * name ;
/**
*The combinator that separates
*this simple selector from the previous
@@ -102,33 +101,28 @@ struct _CRSimpleSel
CRSimpleSel *next ;
CRSimpleSel *prev ;
+ CRParsingLocation location ;
} ;
-CRSimpleSel *
-cr_simple_sel_new (void) ;
+CRSimpleSel * cr_simple_sel_new (void) ;
+
+CRSimpleSel * cr_simple_sel_append_simple_sel (CRSimpleSel *a_this,
+ CRSimpleSel *a_sel) ;
-CRSimpleSel *
-cr_simple_sel_append_simple_sel (CRSimpleSel *a_this,
- CRSimpleSel *a_sel) ;
+CRSimpleSel * cr_simple_sel_prepend_simple_sel (CRSimpleSel *a_this,
+ CRSimpleSel *a_sel) ;
-CRSimpleSel *
-cr_simple_sel_prepend_simple_sel (CRSimpleSel *a_this,
- CRSimpleSel *a_sel) ;
+guchar * cr_simple_sel_to_string (CRSimpleSel *a_this) ;
-guchar *
-cr_simple_sel_to_string (CRSimpleSel *a_this) ;
+guchar * cr_simple_sel_one_to_string (CRSimpleSel * a_this) ;
-enum CRStatus
-cr_simple_sel_dump (CRSimpleSel *a_this, FILE *a_fp) ;
+enum CRStatus cr_simple_sel_dump (CRSimpleSel *a_this, FILE *a_fp) ;
-enum CRStatus
-cr_simple_sel_dump_attr_sel_list (CRSimpleSel *a_this) ;
+enum CRStatus cr_simple_sel_dump_attr_sel_list (CRSimpleSel *a_this) ;
-enum CRStatus
-cr_simple_sel_compute_specificity (CRSimpleSel *a_this) ;
+enum CRStatus cr_simple_sel_compute_specificity (CRSimpleSel *a_this) ;
-void
-cr_simple_sel_destroy (CRSimpleSel *a_this) ;
+void cr_simple_sel_destroy (CRSimpleSel *a_this) ;
G_END_DECLS
diff --git a/src/cr-statement.c b/src/cr-statement.c
index 915a0e6..7babd08 100644
--- a/src/cr-statement.c
+++ b/src/cr-statement.c
@@ -17,10 +17,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli.
* See COPYRIGHTS files for copyrights information.
*/
-
#include <string.h>
#include "cr-statement.h"
#include "cr-parser.h"
@@ -35,7 +35,8 @@
static void cr_statement_clear (CRStatement * a_this);
static void
-parse_font_face_start_font_face_cb (CRDocHandler * a_this)
+parse_font_face_start_font_face_cb (CRDocHandler * a_this,
+ CRParsingLocation *a_location)
{
CRStatement *stmt = NULL;
enum CRStatus status = CR_OK;
@@ -72,11 +73,11 @@ parse_font_face_unrecoverable_error_cb (CRDocHandler * a_this)
static void
parse_font_face_property_cb (CRDocHandler * a_this,
- GString * a_name,
+ CRString * a_name,
CRTerm * a_value, gboolean a_important)
{
enum CRStatus status = CR_OK;
- GString *name = NULL;
+ CRString *name = NULL;
CRDeclaration *decl = NULL;
CRStatement *stmt = NULL;
CRStatement **stmtptr = NULL;
@@ -88,7 +89,7 @@ parse_font_face_property_cb (CRDocHandler * a_this,
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);
+ name = cr_string_dup (a_name) ;
g_return_if_fail (name);
decl = cr_declaration_new (stmt, name, a_value);
if (!decl) {
@@ -110,7 +111,7 @@ parse_font_face_property_cb (CRDocHandler * a_this,
decl = NULL;
}
if (name) {
- g_string_free (name, TRUE);
+ cr_string_destroy (name);
name = NULL;
}
}
@@ -135,19 +136,21 @@ parse_font_face_end_font_face_cb (CRDocHandler * a_this)
static void
parse_page_start_page_cb (CRDocHandler * a_this,
- GString * a_name, GString * a_pseudo_page)
+ CRString * a_name,
+ CRString * a_pseudo_page,
+ CRParsingLocation *a_location)
{
CRStatement *stmt = NULL;
enum CRStatus status = CR_OK;
- GString *page_name = NULL, *pseudo_name = NULL ;
+ CRString *page_name = NULL, *pseudo_name = NULL ;
if (a_name)
- page_name = g_string_new_len (a_name->str,
- a_name->len) ;
+ page_name = cr_string_dup (a_name) ;
if (a_pseudo_page)
- pseudo_name = g_string_new_len (a_pseudo_page->str,
- a_pseudo_page->len) ;
- stmt = cr_statement_new_at_page_rule (NULL, NULL, page_name,
+ pseudo_name = cr_string_dup (a_pseudo_page) ;
+
+ stmt = cr_statement_new_at_page_rule (NULL, NULL,
+ page_name,
pseudo_name);
page_name = NULL ;
pseudo_name = NULL ;
@@ -181,10 +184,10 @@ parse_page_unrecoverable_error_cb (CRDocHandler * a_this)
static void
parse_page_property_cb (CRDocHandler * a_this,
- GString * a_name,
+ CRString * a_name,
CRTerm * a_expression, gboolean a_important)
{
- GString *name = NULL;
+ CRString *name = NULL;
CRStatement *stmt = NULL;
CRStatement **stmtptr = NULL;
CRDeclaration *decl = NULL;
@@ -194,7 +197,7 @@ parse_page_property_cb (CRDocHandler * a_this,
status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr);
g_return_if_fail (status == CR_OK && stmt->type == AT_PAGE_RULE_STMT);
- name = g_string_new_len (a_name->str, a_name->len);
+ name = cr_string_dup (a_name);
g_return_if_fail (name);
decl = cr_declaration_new (stmt, name, a_expression);
@@ -207,7 +210,8 @@ parse_page_property_cb (CRDocHandler * a_this,
static void
parse_page_end_page_cb (CRDocHandler * a_this,
- GString * a_name, GString * a_pseudo_page)
+ CRString * a_name,
+ CRString * a_pseudo_page)
{
enum CRStatus status = CR_OK;
CRStatement *stmt = NULL;
@@ -223,7 +227,9 @@ parse_page_end_page_cb (CRDocHandler * a_this,
}
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,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
CRStatement *at_media = NULL;
@@ -233,7 +239,8 @@ parse_at_media_start_media_cb (CRDocHandler * a_this, GList * a_media_list)
if (a_media_list) {
/*duplicate media list */
- media_list = cr_dup_glist_of_string (a_media_list);
+ media_list = cr_utils_dup_glist_of_cr_string
+ (a_media_list);
}
g_return_if_fail (media_list);
@@ -294,7 +301,7 @@ parse_at_media_start_selector_cb (CRDocHandler * a_this,
static void
parse_at_media_property_cb (CRDocHandler * a_this,
- GString * a_name, CRTerm * a_value,
+ CRString * a_name, CRTerm * a_value,
gboolean a_important)
{
enum CRStatus status = CR_OK;
@@ -306,15 +313,16 @@ parse_at_media_property_cb (CRDocHandler * a_this,
CRStatement *stmt = NULL;
CRStatement **stmtptr = NULL;
CRDeclaration *decl = NULL;
- GString *name = NULL;
+ CRString *name = NULL;
g_return_if_fail (a_this && a_name);
- name = g_string_new_len (a_name->str, a_name->len);
+ name = cr_string_dup (a_name) ;
g_return_if_fail (name);
stmtptr = &stmt;
- status = cr_doc_handler_get_ctxt (a_this, (gpointer *) stmtptr);
+ status = cr_doc_handler_get_ctxt (a_this,
+ (gpointer *) stmtptr);
g_return_if_fail (status == CR_OK && stmt);
g_return_if_fail (stmt->type == RULESET_STMT);
@@ -326,7 +334,8 @@ parse_at_media_property_cb (CRDocHandler * a_this,
}
static void
-parse_at_media_end_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist)
+parse_at_media_end_selector_cb (CRDocHandler * a_this,
+ CRSelector * a_sellist)
{
enum CRStatus status = CR_OK;
@@ -351,7 +360,8 @@ parse_at_media_end_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist)
}
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;
@@ -360,9 +370,9 @@ parse_at_media_end_media_cb (CRDocHandler * a_this, GList * a_media_list)
g_return_if_fail (a_this && a_this->priv);
at_media_ptr = &at_media;
- status = cr_doc_handler_get_ctxt (a_this, (gpointer *) at_media_ptr);
+ status = cr_doc_handler_get_ctxt (a_this,
+ (gpointer *) at_media_ptr);
g_return_if_fail (status == CR_OK && at_media);
-
status = cr_doc_handler_set_result (a_this, at_media);
}
@@ -403,24 +413,25 @@ parse_ruleset_unrecoverable_error_cb (CRDocHandler * a_this)
static void
parse_ruleset_property_cb (CRDocHandler * a_this,
- GString * a_name,
+ CRString * a_name,
CRTerm * a_value, gboolean a_important)
{
enum CRStatus status = CR_OK;
CRStatement *ruleset = NULL;
CRStatement **rulesetptr = NULL;
CRDeclaration *decl = NULL;
- GString *stringue = NULL;
+ CRString *stringue = NULL;
g_return_if_fail (a_this && a_this->priv && a_name);
- stringue = g_string_new (a_name->str);
+ stringue = cr_string_dup (a_name);
g_return_if_fail (stringue);
rulesetptr = &ruleset;
status = cr_doc_handler_get_result (a_this, (gpointer *) rulesetptr);
g_return_if_fail (status == CR_OK
- && ruleset && ruleset->type == RULESET_STMT);
+ && ruleset
+ && ruleset->type == RULESET_STMT);
decl = cr_declaration_new (ruleset, stringue, a_value);
g_return_if_fail (decl);
@@ -430,7 +441,8 @@ parse_ruleset_property_cb (CRDocHandler * a_this,
}
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;
CRStatement **resultptr = NULL;
@@ -442,7 +454,8 @@ parse_ruleset_end_selector_cb (CRDocHandler * a_this, CRSelector * a_sellist)
status = cr_doc_handler_get_result (a_this, (gpointer *) resultptr);
g_return_if_fail (status == CR_OK
- && result && result->type == RULESET_STMT);
+ && result
+ && result->type == RULESET_STMT);
}
static void
@@ -473,7 +486,8 @@ cr_statement_clear (CRStatement * a_this)
if (!a_this->kind.import_rule)
return;
if (a_this->kind.import_rule->url) {
- g_string_free (a_this->kind.import_rule->url, TRUE);
+ cr_string_destroy
+ (a_this->kind.import_rule->url) ;
a_this->kind.import_rule->url = NULL;
}
g_free (a_this->kind.import_rule);
@@ -494,8 +508,7 @@ cr_statement_clear (CRStatement * a_this)
for (cur = a_this->kind.media_rule->media_list;
cur; cur = cur->next) {
if (cur->data) {
- g_string_free ((GString *) cur->data,
- TRUE);
+ cr_string_destroy ((CRString *) cur->data);
cur->data = NULL;
}
@@ -517,14 +530,15 @@ cr_statement_clear (CRStatement * a_this)
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);
+ cr_string_destroy
+ (a_this->kind.page_rule->name);
a_this->kind.page_rule->name = NULL;
}
if (a_this->kind.page_rule->pseudo) {
- g_string_free (a_this->kind.page_rule->pseudo, TRUE);
+ cr_string_destroy
+ (a_this->kind.page_rule->pseudo);
a_this->kind.page_rule->pseudo = NULL;
}
-
g_free (a_this->kind.page_rule);
a_this->kind.page_rule = NULL;
break;
@@ -534,8 +548,8 @@ cr_statement_clear (CRStatement * a_this)
return;
if (a_this->kind.charset_rule->charset) {
- g_string_free
- (a_this->kind.charset_rule->charset, TRUE);
+ cr_string_destroy
+ (a_this->kind.charset_rule->charset);
a_this->kind.charset_rule->charset = NULL;
}
g_free (a_this->kind.charset_rule);
@@ -586,25 +600,25 @@ cr_statement_ruleset_to_string (CRStatement * a_this, glong a_indent)
cr_selector_to_string (a_this->kind.ruleset->
sel_list);
if (tmp_str) {
- g_string_append_printf (stringue, "%s", tmp_str);
+ g_string_append (stringue, tmp_str);
g_free (tmp_str);
tmp_str = NULL;
}
}
- g_string_append_printf (stringue, " {\n");
+ g_string_append (stringue, " {\n");
if (a_this->kind.ruleset->decl_list) {
tmp_str = cr_declaration_list_to_string2
(a_this->kind.ruleset->decl_list,
a_indent + DECLARATION_INDENT_NB, TRUE);
if (tmp_str) {
- g_string_append_printf (stringue, "%s", tmp_str);
+ g_string_append (stringue, tmp_str);
g_free (tmp_str);
tmp_str = NULL;
}
- g_string_append_printf (stringue, "%s", "\n");
+ g_string_append (stringue, "\n");
cr_utils_dump_n_chars2 (' ', stringue, a_indent);
}
- g_string_append_printf (stringue, "%s", "}");
+ g_string_append (stringue, "}");
result = stringue->str;
if (stringue) {
@@ -644,17 +658,17 @@ cr_statement_font_face_rule_to_string (CRStatement * a_this,
if (a_indent)
cr_utils_dump_n_chars2 (' ', stringue,
a_indent);
- g_string_append_printf (stringue, "@font-face {\n");
+ g_string_append (stringue, "@font-face {\n");
tmp_str = cr_declaration_list_to_string2
(a_this->kind.font_face_rule->decl_list,
a_indent + DECLARATION_INDENT_NB, TRUE) ;
if (tmp_str) {
- g_string_append_printf (stringue, "%s"
- ,tmp_str) ;
+ g_string_append (stringue,
+ tmp_str) ;
g_free (tmp_str) ;
tmp_str = NULL ;
}
- g_string_append_printf (stringue, "\n}");
+ g_string_append (stringue, "\n}");
}
if (stringue) {
result = stringue->str ;
@@ -683,9 +697,11 @@ cr_statement_charset_to_string (CRStatement *a_this,
NULL) ;
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);
+ && a_this->kind.charset_rule->charset
+ && a_this->kind.charset_rule->charset->stryng
+ && a_this->kind.charset_rule->charset->stryng->str) {
+ str = g_strndup (a_this->kind.charset_rule->charset->stryng->str,
+ a_this->kind.charset_rule->charset->stryng->len);
g_return_val_if_fail (str, NULL);
stringue = g_string_new (NULL) ;
g_return_val_if_fail (stringue, NULL) ;
@@ -721,32 +737,33 @@ cr_statement_at_page_rule_to_string (CRStatement *a_this,
stringue = g_string_new (NULL) ;
cr_utils_dump_n_chars2 (' ', stringue, a_indent) ;
- g_string_append_printf (stringue, "@page");
-
- if (a_this->kind.page_rule->name) {
- g_string_append_printf
- (stringue, " %s",
- a_this->kind.page_rule->name->str) ;
+ g_string_append (stringue, "@page");
+ if (a_this->kind.page_rule->name
+ && a_this->kind.page_rule->name->stryng) {
+ g_string_append_printf
+ (stringue, " %s",
+ a_this->kind.page_rule->name->stryng->str) ;
} else {
- g_string_append_printf (stringue, " ");
+ g_string_append (stringue, " ");
}
- if (a_this->kind.page_rule->pseudo) {
- g_string_append_printf
- (stringue, " :%s",
- a_this->kind.page_rule->pseudo->str) ;
+ if (a_this->kind.page_rule->pseudo
+ && a_this->kind.page_rule->pseudo->stryng) {
+ g_string_append_printf
+ (stringue, " :%s",
+ a_this->kind.page_rule->pseudo->stryng->str) ;
}
if (a_this->kind.page_rule->decl_list) {
gchar *str = NULL ;
- g_string_append_printf (stringue, " {\n");
+ g_string_append (stringue, " {\n");
str = cr_declaration_list_to_string2
(a_this->kind.page_rule->decl_list,
a_indent + DECLARATION_INDENT_NB, TRUE) ;
if (str) {
- g_string_append_printf (stringue, "%s", str) ;
+ g_string_append (stringue, str) ;
g_free (str) ;
str = NULL ;
}
- g_string_append_printf (stringue, "%s", "\n}\n");
+ g_string_append (stringue, "\n}\n");
}
result = stringue->str ;
g_string_free (stringue, FALSE) ;
@@ -781,9 +798,8 @@ cr_statement_media_rule_to_string (CRStatement *a_this,
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);
+ guchar *str = cr_string_dup2
+ ((CRString *) cur->data);
if (str) {
if (cur->prev) {
@@ -800,7 +816,7 @@ cr_statement_media_rule_to_string (CRStatement *a_this,
}
}
g_string_append (stringue, " {\n");
- str = cr_statement_to_string
+ str = cr_statement_list_to_string
(a_this->kind.media_rule->rulesets,
a_indent + DECLARATION_INDENT_NB) ;
if (str) {
@@ -830,11 +846,12 @@ cr_statement_import_rule_to_string (CRStatement *a_this,
&& a_this->kind.import_rule,
NULL) ;
- if (a_this->kind.import_rule->url) {
+ if (a_this->kind.import_rule->url
+ && a_this->kind.import_rule->url->stryng) {
stringue = g_string_new (NULL) ;
g_return_val_if_fail (stringue, NULL) ;
- str = g_strndup (a_this->kind.import_rule->url->str,
- a_this->kind.import_rule->url->len);
+ str = g_strndup (a_this->kind.import_rule->url->stryng->str,
+ a_this->kind.import_rule->url->stryng->len);
cr_utils_dump_n_chars2 (' ', stringue, a_indent);
if (str) {
g_string_append_printf (stringue,
@@ -851,16 +868,20 @@ cr_statement_import_rule_to_string (CRStatement *a_this,
for (cur = a_this->kind.import_rule->media_list;
cur; cur = cur->next) {
if (cur->data) {
- GString *gstr = cur->data;
+ CRString *crstr = cur->data;
if (cur->prev) {
g_string_append
(stringue, ", ");
}
- g_string_append_len
- (stringue,
- gstr->str,
- gstr->len) ;
+ if (crstr
+ && crstr->stryng
+ && crstr->stryng->str) {
+ g_string_append_len
+ (stringue,
+ crstr->stryng->str,
+ crstr->stryng->len) ;
+ }
}
}
}
@@ -1257,7 +1278,7 @@ cr_statement_new_at_media_rule (CRStyleSheet * a_sheet,
*/
CRStatement *
cr_statement_new_at_import_rule (CRStyleSheet * a_container_sheet,
- GString * a_url,
+ CRString * a_url,
GList * a_media_list,
CRStyleSheet * a_imported_sheet)
{
@@ -1307,7 +1328,8 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
CRParser *parser = NULL;
CRStatement *result = NULL;
GList *media_list = NULL;
- GString *import_string = NULL;
+ CRString *import_string = NULL;
+ CRParsingLocation location = {0} ;
parser = cr_parser_new_from_buf ((guchar*)a_buf, strlen (a_buf),
a_encoding, FALSE);
@@ -1320,18 +1342,23 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
if (status != CR_OK)
goto cleanup;
- status = cr_parser_parse_import (parser, &media_list, &import_string);
+ status = cr_parser_parse_import (parser,
+ &media_list,
+ &import_string,
+ &location);
if (status != CR_OK || !import_string)
goto cleanup;
result = cr_statement_new_at_import_rule (NULL, import_string,
media_list, NULL);
if (result) {
+ cr_parsing_location_copy (&result->location,
+ &location) ;
import_string = NULL;
media_list = NULL;
}
- cleanup:
+ cleanup:
if (parser) {
cr_parser_destroy (parser);
parser = NULL;
@@ -1342,7 +1369,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
for (cur = media_list; media_list;
media_list = g_list_next (media_list)) {
if (media_list->data) {
- g_string_free (media_list->data, TRUE);
+ cr_string_destroy ((CRString*)media_list->data);
media_list->data = NULL;
}
}
@@ -1350,7 +1377,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
media_list = NULL;
}
if (import_string) {
- g_string_free (import_string, TRUE);
+ cr_string_destroy (import_string);
import_string = NULL;
}
@@ -1370,7 +1397,7 @@ cr_statement_at_import_rule_parse_from_buf (const guchar * a_buf,
CRStatement *
cr_statement_new_at_page_rule (CRStyleSheet * a_sheet,
CRDeclaration * a_decl_list,
- GString * a_name, GString * a_pseudo)
+ CRString * a_name, CRString * a_pseudo)
{
CRStatement *result = NULL;
@@ -1484,7 +1511,8 @@ 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,
+ CRString * a_charset)
{
CRStatement *result = NULL;
@@ -1528,7 +1556,7 @@ cr_statement_at_charset_rule_parse_from_buf (const guchar * a_buf,
enum CRStatus status = CR_OK;
CRParser *parser = NULL;
CRStatement *result = NULL;
- GString *charset = NULL;
+ CRString *charset = NULL;
g_return_val_if_fail (a_buf, NULL);
@@ -1543,7 +1571,7 @@ cr_statement_at_charset_rule_parse_from_buf (const guchar * a_buf,
cr_parser_try_to_skip_spaces_and_comments (parser);
if (status != CR_OK)
goto cleanup;
- status = cr_parser_parse_charset (parser, &charset);
+ status = cr_parser_parse_charset (parser, &charset, NULL);
if (status != CR_OK || !charset)
goto cleanup;
@@ -1558,7 +1586,7 @@ cr_statement_at_charset_rule_parse_from_buf (const guchar * a_buf,
parser = NULL;
}
if (charset) {
- g_string_free (charset, TRUE);
+ cr_string_destroy (charset);
}
return result;
@@ -1945,7 +1973,8 @@ cr_statement_ruleset_set_decl_list (CRStatement * a_this,
*/
enum CRStatus
cr_statement_ruleset_append_decl2 (CRStatement * a_this,
- GString * a_prop, CRTerm * a_value)
+ CRString * a_prop,
+ CRTerm * a_value)
{
CRDeclaration *new_decls = NULL;
@@ -1953,7 +1982,8 @@ cr_statement_ruleset_append_decl2 (CRStatement * a_this,
&& a_this->kind.ruleset, CR_BAD_PARAM_ERROR);
new_decls = cr_declaration_append2
- (a_this->kind.ruleset->decl_list, a_prop, a_value);
+ (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;
@@ -2034,7 +2064,8 @@ 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,
+ CRString * a_url)
{
g_return_val_if_fail (a_this
&& a_this->type == AT_IMPORT_RULE_STMT
@@ -2042,7 +2073,7 @@ cr_statement_at_import_rule_set_url (CRStatement * a_this, GString * a_url)
CR_BAD_PARAM_ERROR);
if (a_this->kind.import_rule->url) {
- g_string_free (a_this->kind.import_rule->url, TRUE);
+ cr_string_destroy (a_this->kind.import_rule->url);
}
a_this->kind.import_rule->url = a_url;
@@ -2057,7 +2088,8 @@ cr_statement_at_import_rule_set_url (CRStatement * a_this, GString * a_url)
*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,
+ CRString ** a_url)
{
g_return_val_if_fail (a_this
&& a_this->type == AT_IMPORT_RULE_STMT
@@ -2158,7 +2190,7 @@ cr_statement_at_page_rule_get_declarations (CRStatement * a_this,
*/
enum CRStatus
cr_statement_at_charset_rule_set_charset (CRStatement * a_this,
- GString * a_charset)
+ CRString * a_charset)
{
g_return_val_if_fail (a_this
&& a_this->type == AT_CHARSET_RULE_STMT
@@ -2166,9 +2198,8 @@ cr_statement_at_charset_rule_set_charset (CRStatement * a_this,
CR_BAD_PARAM_ERROR);
if (a_this->kind.charset_rule->charset) {
- g_string_free (a_this->kind.charset_rule->charset, TRUE);
+ cr_string_destroy (a_this->kind.charset_rule->charset);
}
-
a_this->kind.charset_rule->charset = a_charset;
return CR_OK;
}
@@ -2182,7 +2213,7 @@ cr_statement_at_charset_rule_set_charset (CRStatement * a_this,
*/
enum CRStatus
cr_statement_at_charset_rule_get_charset (CRStatement * a_this,
- GString ** a_charset)
+ CRString ** a_charset)
{
g_return_val_if_fail (a_this
&& a_this->type == AT_CHARSET_RULE_STMT
@@ -2251,7 +2282,7 @@ cr_statement_at_font_face_rule_get_decls (CRStatement * a_this,
*/
enum CRStatus
cr_statement_at_font_face_rule_add_decl (CRStatement * a_this,
- GString * a_prop, CRTerm * a_value)
+ CRString * a_prop, CRTerm * a_value)
{
CRDeclaration *decls = NULL;
@@ -2261,7 +2292,8 @@ cr_statement_at_font_face_rule_add_decl (CRStatement * a_this,
CR_BAD_PARAM_ERROR);
decls = cr_declaration_append2
- (a_this->kind.font_face_rule->decl_list, a_prop, a_value);
+ (a_this->kind.font_face_rule->decl_list,
+ a_prop, a_value);
g_return_val_if_fail (decls, CR_ERROR);
@@ -2326,6 +2358,39 @@ cr_statement_to_string (CRStatement * a_this, gulong a_indent)
return str ;
}
+gchar*
+cr_statement_list_to_string (CRStatement *a_this, gulong a_indent)
+{
+ CRStatement *cur_stmt = NULL ;
+ GString *stringue = NULL ;
+ gchar *str = NULL ;
+
+ g_return_val_if_fail (a_this, NULL) ;
+
+ stringue = g_string_new (NULL) ;
+ if (!stringue) {
+ cr_utils_trace_info ("Out of memory") ;
+ return NULL ;
+ }
+ for (cur_stmt = a_this ; cur_stmt;
+ cur_stmt = cur_stmt->next) {
+ str = cr_statement_to_string (cur_stmt, a_indent) ;
+ if (str) {
+ if (!cur_stmt->prev) {
+ g_string_append (stringue, str) ;
+ } else {
+ g_string_append_printf
+ (stringue, "\n%s", str) ;
+ }
+ g_free (str) ;
+ str = NULL ;
+ }
+ }
+ str = stringue->str ;
+ g_string_free (stringue, FALSE) ;
+ return str ;
+}
+
/**
*Dumps the css2 statement to a file.
*@param a_this the current css2 statement.
diff --git a/src/cr-statement.h b/src/cr-statement.h
index 0323dbb..6bb0133 100644
--- a/src/cr-statement.h
+++ b/src/cr-statement.h
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for copyright information.
*/
@@ -92,7 +93,7 @@ typedef struct _CRAtImportRule CRAtImportRule ;
struct _CRAtImportRule
{
/**the url of the import rule*/
- GString *url ;
+ CRString *url ;
GList *media_list ;
@@ -121,15 +122,15 @@ struct _CRAtPageRule
CRDeclaration *decl_list ;
/**page selector. Is a pseudo selector*/
- GString *name ;
- GString *pseudo ;
+ CRString *name ;
+ CRString *pseudo ;
} ;
/**The @charset rule abstraction*/
typedef struct _CRAtCharsetRule CRAtCharsetRule ;
struct _CRAtCharsetRule
{
- GString * charset ;
+ CRString * charset ;
};
/**The abstaction of the @font-face rule.*/
@@ -215,6 +216,8 @@ struct _CRStatement
CRStatement *next ;
CRStatement *prev ;
+ CRParsingLocation location ;
+
/**
*a custom pointer useable by
*applications that use libcroco.
@@ -251,7 +254,7 @@ cr_statement_ruleset_parse_from_buf (const guchar * a_buf,
CRStatement*
cr_statement_new_at_import_rule (CRStyleSheet *a_container_sheet,
- GString *a_url,
+ CRString *a_url,
GList *a_media_list,
CRStyleSheet *a_imported_sheet) ;
@@ -269,7 +272,7 @@ cr_statement_at_media_rule_parse_from_buf (const guchar *a_buf,
CRStatement *
cr_statement_new_at_charset_rule (CRStyleSheet *a_sheet,
- GString *a_charset) ;
+ CRString *a_charset) ;
CRStatement *
cr_statement_at_charset_rule_parse_from_buf (const guchar *a_buf,
enum CREncoding a_encoding);
@@ -285,8 +288,8 @@ cr_statement_font_face_rule_parse_from_buf (const guchar *a_buf,
CRStatement *
cr_statement_new_at_page_rule (CRStyleSheet *a_sheet,
CRDeclaration *a_decl_list,
- GString *a_name,
- GString *a_pseudo) ;
+ CRString *a_name,
+ CRString *a_pseudo) ;
CRStatement *
cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf,
enum CREncoding a_encoding) ;
@@ -328,7 +331,7 @@ cr_statement_ruleset_get_declarations (CRStatement *a_this,
enum CRStatus
cr_statement_ruleset_append_decl2 (CRStatement *a_this,
- GString *a_prop, CRTerm *a_value) ;
+ CRString *a_prop, CRTerm *a_value) ;
enum CRStatus
cr_statement_ruleset_append_decl (CRStatement *a_this,
@@ -344,11 +347,11 @@ cr_statement_at_import_rule_get_imported_sheet (CRStatement *a_this,
enum CRStatus
cr_statement_at_import_rule_set_url (CRStatement *a_this,
- GString *a_url) ;
+ CRString *a_url) ;
enum CRStatus
cr_statement_at_import_rule_get_url (CRStatement *a_this,
- GString **a_url) ;
+ CRString **a_url) ;
gint
cr_statement_at_media_nr_rules (CRStatement *a_this) ;
@@ -374,11 +377,11 @@ cr_statement_at_page_rule_get_declarations (CRStatement *a_this,
enum CRStatus
cr_statement_at_charset_rule_set_charset (CRStatement *a_this,
- GString *a_charset) ;
+ CRString *a_charset) ;
enum CRStatus
cr_statement_at_charset_rule_get_charset (CRStatement *a_this,
- GString **a_charset) ;
+ CRString **a_charset) ;
enum CRStatus
cr_statement_at_font_face_rule_set_decls (CRStatement *a_this,
@@ -390,12 +393,15 @@ cr_statement_at_font_face_rule_get_decls (CRStatement *a_this,
enum CRStatus
cr_statement_at_font_face_rule_add_decl (CRStatement *a_this,
- GString *a_prop,
+ CRString *a_prop,
CRTerm *a_value) ;
gchar *
cr_statement_to_string (CRStatement * a_this, gulong a_indent) ;
+gchar*
+cr_statement_list_to_string (CRStatement *a_this, gulong a_indent) ;
+
void
cr_statement_dump (CRStatement *a_this, FILE *a_fp, gulong a_indent) ;
diff --git a/src/cr-style.c b/src/cr-style.c
index 04557eb..09b2328 100644
--- a/src/cr-style.c
+++ b/src/cr-style.c
@@ -19,12 +19,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli.
* see COPYRIGTHS file for copyright information
*/
-/*
- *$Id$
- */
#include <string.h>
#include "cr-style.h"
@@ -52,10 +50,12 @@ enum CRPropertyID {
PROP_ID_BORDER_RIGHT_WIDTH,
PROP_ID_BORDER_BOTTOM_WIDTH,
PROP_ID_BORDER_LEFT_WIDTH,
+ PROP_ID_BORDER_WIDTH,
PROP_ID_BORDER_TOP_STYLE,
PROP_ID_BORDER_RIGHT_STYLE,
PROP_ID_BORDER_BOTTOM_STYLE,
PROP_ID_BORDER_LEFT_STYLE,
+ PROP_ID_BORDER_STYLE,
PROP_ID_BORDER_TOP_COLOR,
PROP_ID_BORDER_RIGHT_COLOR,
PROP_ID_BORDER_BOTTOM_COLOR,
@@ -84,6 +84,7 @@ enum CRPropertyID {
PROP_ID_FONT_SIZE,
PROP_ID_FONT_STYLE,
PROP_ID_FONT_WEIGHT,
+ PROP_ID_WHITE_SPACE,
/*should be the last one. */
NB_PROP_IDS
};
@@ -105,10 +106,12 @@ static CRPropertyDesc gv_prop_table[] = {
{"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-width", PROP_ID_BORDER_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-style", PROP_ID_BORDER_STYLE},
{"border-top", PROP_ID_BORDER_TOP},
{"border-right", PROP_ID_BORDER_RIGHT},
{"border-bottom", PROP_ID_BORDER_BOTTOM},
@@ -128,11 +131,16 @@ static CRPropertyDesc gv_prop_table[] = {
{"float", PROP_ID_FLOAT},
{"width", PROP_ID_WIDTH},
{"color", PROP_ID_COLOR},
+ {"border-top-color", PROP_ID_BORDER_TOP_COLOR},
+ {"border-right-color", PROP_ID_BORDER_RIGHT_COLOR},
+ {"border-bottom-color", PROP_ID_BORDER_BOTTOM_COLOR},
+ {"border-left-color", PROP_ID_BORDER_LEFT_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},
+ {"white-space", PROP_ID_WHITE_SPACE},
/*must be the last one */
{NULL, 0}
};
@@ -231,76 +239,82 @@ 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,
+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_width_from_value (CRStyle *a_style,
+ CRTerm *a_value) ;
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_border_style_from_value (CRStyle *a_style,
+ CRTerm *a_value) ;
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);
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,
+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,
+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,
+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)
@@ -419,8 +433,7 @@ 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;
+ CRNum *num_val = NULL;
g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR);
@@ -430,35 +443,18 @@ set_prop_padding_x_from_value (CRStyle * a_style,
switch (a_dir) {
case DIR_TOP:
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;
case DIR_RIGHT:
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;
- parent_num_val =
- &a_style->parent_style->
- 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 =
- &a_style->parent_style->
- 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 =
- &a_style->parent_style->
- num_props[NUM_PROP_PADDING_LEFT].sv;
break;
default:
@@ -467,11 +463,12 @@ set_prop_padding_x_from_value (CRStyle * a_style,
if (a_value->type == TERM_IDENT) {
if (a_value->content.str
- && a_value->content.str->str
- && !strncmp ((guchar *) "inherited",
- a_value->content.str->str,
- strlen ("inherited"))) {
- cr_num_copy (num_val, parent_num_val);
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strncmp ((guchar *) "inherit",
+ a_value->content.str->stryng->str,
+ sizeof ("inherit")-1)) {
+ status = cr_num_set (num_val, 0.0, NUM_INHERIT);
return CR_OK;
} else
return CR_UNKNOWN_TYPE_ERROR;
@@ -502,7 +499,8 @@ set_prop_padding_x_from_value (CRStyle * a_style,
static enum CRStatus
set_prop_border_x_width_from_value (CRStyle * a_style,
- CRTerm * a_value, enum CRDirection a_dir)
+ CRTerm * a_value,
+ enum CRDirection a_dir)
{
enum CRStatus status = CR_OK;
CRNum *num_val = NULL;
@@ -532,20 +530,23 @@ set_prop_border_x_width_from_value (CRStyle * a_style,
}
if (a_value->type == TERM_IDENT) {
- if (a_value->content.str && a_value->content.str->str) {
+ if (a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
if (!strncmp ("thin",
- a_value->content.str->str,
- strlen ("thin"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("thin")-1)) {
cr_num_set (num_val, BORDER_THIN,
NUM_LENGTH_PX);
- } else if (!strncmp ("medium",
- a_value->content.str->str,
- strlen ("medium"))) {
+ } else if (!strncmp
+ ("medium",
+ a_value->content.str->stryng->str,
+ sizeof ("medium")-1)) {
cr_num_set (num_val, BORDER_MEDIUM,
NUM_LENGTH_PX);
} else if (!strncmp ("thick",
- a_value->content.str->str,
- strlen ("thick"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("thick")-1)) {
cr_num_set (num_val, BORDER_THICK,
NUM_LENGTH_PX);
} else {
@@ -565,12 +566,55 @@ set_prop_border_x_width_from_value (CRStyle * a_style,
}
static enum CRStatus
+set_prop_border_width_from_value (CRStyle *a_style,
+ CRTerm *a_value)
+{
+ CRTerm *cur_term = NULL ;
+ enum CRDirection direction = DIR_TOP ;
+
+ g_return_val_if_fail (a_style && a_value,
+ CR_BAD_PARAM_ERROR) ;
+ cur_term = a_value ;
+
+ if (!cur_term)
+ return CR_ERROR ;
+
+ for (direction = DIR_TOP ;
+ direction < NB_DIRS ; direction ++) {
+ set_prop_border_x_width_from_value (a_style,
+ cur_term,
+ direction) ;
+ }
+
+ cur_term = cur_term->next ;
+ if (!cur_term)
+ return CR_OK ;
+ set_prop_border_x_width_from_value (a_style, cur_term,
+ DIR_RIGHT) ;
+ set_prop_border_x_width_from_value (a_style, cur_term,
+ DIR_LEFT) ;
+
+ cur_term = cur_term->next ;
+ if (!cur_term)
+ return CR_OK ;
+ set_prop_border_x_width_from_value (a_style, cur_term,
+ DIR_BOTTOM) ;
+
+ cur_term = cur_term->next ;
+ if (!cur_term)
+ return CR_OK ;
+ set_prop_border_x_width_from_value (a_style, cur_term,
+ DIR_LEFT) ;
+
+ return CR_OK ;
+}
+
+static enum CRStatus
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,
- *parent_border_style_ptr = NULL;
+ enum CRBorderStyle *border_style_ptr = NULL;
g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR);
@@ -578,35 +622,21 @@ set_prop_border_x_style_from_value (CRStyle * a_style,
case DIR_TOP:
border_style_ptr = &a_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;
-
break;
case DIR_RIGHT:
border_style_ptr =
&a_style->border_style_props[BORDER_STYLE_PROP_RIGHT];
-
- parent_border_style_ptr = (a_style->parent_style) ?
- &a_style->parent_style->
- 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) ?
- &a_style->parent_style->
- border_style_props[BORDER_STYLE_PROP_BOTTOM] : NULL;
break;
case DIR_LEFT:
border_style_ptr = &a_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;
default:
@@ -617,39 +647,46 @@ set_prop_border_x_style_from_value (CRStyle * a_style,
return CR_UNKNOWN_TYPE_ERROR;
}
- if (!strncmp ("none", a_value->content.str->str, strlen ("none"))) {
+ if (!strncmp ("none",
+ a_value->content.str->stryng->str,
+ sizeof ("none")-1)) {
*border_style_ptr = BORDER_STYLE_NONE;
} else if (!strncmp ("hidden",
- a_value->content.str->str, strlen ("hidden"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("hidden")-1)) {
*border_style_ptr = BORDER_STYLE_HIDDEN;
} else if (!strncmp ("dotted",
- a_value->content.str->str, strlen ("dotted"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("dotted")-1)) {
*border_style_ptr = BORDER_STYLE_DOTTED;
} else if (!strncmp ("dashed",
- a_value->content.str->str, strlen ("dashed"))) {
+ a_value->content.str->stryng->str, sizeof ("dashed")-1)) {
*border_style_ptr = BORDER_STYLE_DASHED;
} else if (!strncmp ("solid",
- a_value->content.str->str, strlen ("solid"))) {
+ a_value->content.str->stryng->str, sizeof ("solid")-1)) {
*border_style_ptr = BORDER_STYLE_SOLID;
} else if (!strncmp ("double",
- a_value->content.str->str, strlen ("double"))) {
+ a_value->content.str->stryng->str, sizeof ("double")-1)) {
*border_style_ptr = BORDER_STYLE_DOUBLE;
} else if (!strncmp ("groove",
- a_value->content.str->str, strlen ("groove"))) {
+ a_value->content.str->stryng->str, sizeof ("groove")-1)) {
*border_style_ptr = BORDER_STYLE_GROOVE;
} else if (!strncmp ("ridge",
- a_value->content.str->str, strlen ("ridge"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("ridge")-1)) {
*border_style_ptr = BORDER_STYLE_RIDGE;
} else if (!strncmp ("inset",
- a_value->content.str->str, strlen ("inset"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("inset")-1)) {
*border_style_ptr = BORDER_STYLE_INSET;
} else if (!strncmp ("outset",
- a_value->content.str->str, strlen ("outset"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("outset")-1)) {
*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;
+ a_value->content.str->stryng->str,
+ sizeof ("inherit")-1)) {
+ *border_style_ptr = BORDER_STYLE_INHERIT;
} else {
status = CR_UNKNOWN_TYPE_ERROR;
}
@@ -658,43 +695,78 @@ set_prop_border_x_style_from_value (CRStyle * a_style,
}
static enum CRStatus
+set_prop_border_style_from_value (CRStyle *a_style,
+ CRTerm *a_value)
+{
+ CRTerm *cur_term = NULL ;
+ enum CRDirection direction = DIR_TOP ;
+
+ g_return_val_if_fail (a_style && a_value,
+ CR_BAD_PARAM_ERROR) ;
+
+ cur_term = a_value ;
+ if (!cur_term || cur_term->type != TERM_IDENT) {
+ return CR_ERROR ;
+ }
+
+ for (direction = DIR_TOP ;
+ direction < NB_DIRS ;
+ direction ++) {
+ set_prop_border_x_style_from_value (a_style,
+ cur_term,
+ direction) ;
+ }
+
+ cur_term = cur_term->next ;
+ if (!cur_term || cur_term->type != TERM_IDENT) {
+ return CR_OK ;
+ }
+
+ set_prop_border_x_style_from_value (a_style, cur_term,
+ DIR_RIGHT) ;
+ set_prop_border_x_style_from_value (a_style, cur_term,
+ DIR_LEFT) ;
+
+ cur_term = cur_term->next ;
+ if (!cur_term || cur_term->type != TERM_IDENT) {
+ return CR_OK ;
+ }
+ set_prop_border_x_style_from_value (a_style, cur_term,
+ DIR_BOTTOM) ;
+
+ cur_term = cur_term->next ;
+ if (!cur_term || cur_term->type != TERM_IDENT) {
+ return CR_OK ;
+ }
+ set_prop_border_x_style_from_value (a_style, cur_term,
+ DIR_LEFT) ;
+ return CR_OK ;
+}
+
+static enum CRStatus
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;
+ CRNum *num_val = NULL;
g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR);
switch (a_dir) {
case DIR_TOP:
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;
case DIR_RIGHT:
num_val = &a_style->num_props[NUM_PROP_MARGIN_RIGHT].sv;
-
- parent_num_val =
- &a_style->parent_style->
- 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;
case DIR_LEFT:
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;
default:
@@ -704,14 +776,15 @@ set_prop_margin_x_from_value (CRStyle * a_style, CRTerm * a_value,
switch (a_value->type) {
case TERM_IDENT:
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);
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strncmp (a_value->content.str->stryng->str,
+ "inherit", sizeof ("inherit")-1)) {
+ status = cr_num_set (num_val, 0.0, NUM_AUTO);
} else if (a_value->content.str
- && a_value->content.str->str
- && !strncmp (a_value->content.str->str,
- "auto", strlen ("auto"))) {
+ && a_value->content.str->stryng
+ && !strncmp (a_value->content.str->stryng->str,
+ "auto", sizeof ("auto")-1)) {
status = cr_num_set (num_val, 0.0, NUM_AUTO);
} else {
status = CR_UNKNOWN_TYPE_ERROR;
@@ -737,7 +810,6 @@ struct CRPropDisplayValPair {
static enum CRStatus
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},
@@ -761,39 +833,26 @@ set_prop_display_from_value (CRStyle * a_style, CRTerm * a_value)
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)
+ || !a_value->content.str->stryng
+ || !a_value->content.str->stryng->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))) {
+ if (!strncmp
+ (disp_vals_map[i].prop_name,
+ a_value->content.str->stryng->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;
- }
- }
}
break;
@@ -818,28 +877,26 @@ set_prop_position_from_value (CRStyle * a_style, CRTerm * a_value)
{"relative", POSITION_RELATIVE},
{"absolute", POSITION_ABSOLUTE},
{"fixed", POSITION_FIXED},
- {"inherited", POSITION_INHERIT},
+ {"inherit", 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)
+ || !a_value->content.str->stryng
+ || !a_value->content.str->stryng->str)
break;
for (i = 0; position_vals_map[i].name; i++) {
if (!strncmp (position_vals_map[i].name,
- a_value->content.str->str,
+ a_value->content.str->stryng->str,
strlen (position_vals_map[i].
name))) {
a_style->position =
@@ -848,15 +905,6 @@ set_prop_position_from_value (CRStyle * a_style, CRTerm * a_value)
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;
- }
- }
}
break;
@@ -871,8 +919,7 @@ static enum CRStatus
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;
g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR);
@@ -884,32 +931,17 @@ set_prop_x_from_value (CRStyle * a_style, CRTerm * a_value,
switch (a_dir) {
case DIR_TOP:
box_offset = &a_style->num_props[NUM_PROP_TOP].sv;
- if (a_style->parent_style)
- parent_box_offset =
- &a_style->parent_style->
- num_props[NUM_PROP_TOP].sv;
break;
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;
case DIR_BOTTOM:
box_offset = &a_style->num_props[NUM_PROP_BOTTOM].sv;
- if (a_style->parent_style)
- parent_box_offset =
- &a_style->parent_style->
- num_props[NUM_PROP_BOTTOM].sv;
break;
case DIR_LEFT:
box_offset = &a_style->num_props[NUM_PROP_LEFT].sv;
- if (a_style->parent_style)
- parent_box_offset =
- &a_style->parent_style->
- num_props[NUM_PROP_LEFT].sv;
break;
default:
@@ -921,14 +953,16 @@ set_prop_x_from_value (CRStyle * a_style, CRTerm * a_value,
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) {
+ && a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
if (!strncmp ("inherit",
- a_value->content.str->str,
- strlen ("inherit"))) {
- cr_num_copy (box_offset, parent_box_offset);
+ a_value->content.str->stryng->str,
+ sizeof ("inherit")-1)) {
+ cr_num_set (box_offset, 0.0, NUM_INHERIT);
} else if (!strncmp ("auto",
- a_value->content.str->str,
- strlen ("auto"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("auto")-1)) {
box_offset->type = NUM_AUTO;
}
}
@@ -939,53 +973,63 @@ set_prop_x_from_value (CRStyle * a_style, CRTerm * a_value,
static enum CRStatus
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;
- 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 */
+ if (a_value->type != TERM_IDENT
+ || !a_value->content.str
+ || !a_value->content.str->stryng
+ || !a_value->content.str->stryng->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"))) {
+ if (!strncmp ("none",
+ a_value->content.str->stryng->str,
+ sizeof ("none")-1)) {
a_style->float_type = FLOAT_NONE;
} else if (!strncmp ("left",
- a_value->content.str->str, strlen ("left"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("left")-1)) {
a_style->float_type = FLOAT_LEFT;
} else if (!strncmp ("right",
- a_value->content.str->str, strlen ("right"))) {
+ a_value->content.str->stryng->str,
+ sizeof ("right")-1)) {
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;
+ a_value->content.str->stryng->str,
+ sizeof ("inherit")-1)) {
+ a_style->float_type = FLOAT_INHERIT;
}
-
return CR_OK;
}
static enum CRStatus
set_prop_width (CRStyle * a_style, CRTerm * a_value)
{
- g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR);
+ CRNum *width = NULL;
+ g_return_val_if_fail (a_style
+ && a_value,
+ CR_BAD_PARAM_ERROR);
- a_style->num_props[NUM_PROP_WIDTH].sv.type = NUM_AUTO;
+ width = &a_style->num_props[NUM_PROP_WIDTH].sv;
+ cr_num_set (width, 0.0, NUM_AUTO);
if (a_value->type == TERM_IDENT) {
- if (a_value->content.str && a_value->content.str->str) {
+ if (a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
if (!strncmp ("auto",
- a_value->content.str->str,
- strlen ("auto"))) {
- a_style->num_props[NUM_PROP_WIDTH].sv.type =
- NUM_AUTO;
+ a_value->content.str->stryng->str,
+ sizeof ("auto")-1)) {
+ cr_num_set (width, 0.0, 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);
+ a_value->content.str->stryng->str,
+ sizeof ("inherit")-1)) {
+ cr_num_set (width, 0.0, NUM_INHERIT);
}
}
} else if (a_value->type == TERM_NUMBER) {
@@ -994,7 +1038,6 @@ set_prop_width (CRStyle * a_style, CRTerm * a_value)
a_value->content.num);
}
}
-
return CR_OK;
}
@@ -1004,7 +1047,8 @@ set_prop_color (CRStyle * a_style, CRTerm * a_value)
enum CRStatus status = CR_OK;
CRRgb *a_rgb = &a_style->rgb_props[RGB_PROP_COLOR].sv;
- 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);
status = cr_rgb_set_from_term (a_rgb, a_value);
@@ -1071,12 +1115,14 @@ set_prop_border_x_color_from_value (CRStyle * a_style, CRTerm * a_value,
status = CR_UNKNOWN_PROP_VAL_ERROR;
if (a_value->type == TERM_IDENT) {
- if (a_value->content.str && a_value->content.str->str) {
+ if (a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
status = cr_rgb_set_from_name
- (rgb_color, a_value->content.str->str);
+ (rgb_color,
+ a_value->content.str->stryng->str);
}
-
if (status != CR_OK) {
cr_rgb_set_from_name (rgb_color, "black");
}
@@ -1086,7 +1132,6 @@ set_prop_border_x_color_from_value (CRStyle * a_style, CRTerm * a_value,
(rgb_color, a_value->content.rgb);
}
}
-
return status;
}
@@ -1100,7 +1145,9 @@ set_prop_border_x_from_value (CRStyle * a_style, CRTerm * a_value,
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) {
+ 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);
@@ -1108,13 +1155,11 @@ set_prop_border_x_from_value (CRStyle * a_style, CRTerm * a_value,
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);
}
}
-
return CR_OK;
}
@@ -1126,7 +1171,9 @@ set_prop_border_from_value (CRStyle * a_style, CRTerm * a_value)
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);
+ set_prop_border_x_from_value (a_style,
+ a_value,
+ direction);
}
return CR_OK;
@@ -1138,25 +1185,28 @@ set_prop_padding_from_value (CRStyle * a_style, CRTerm * a_value)
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);
cur_term = a_value;
+
+ /*filter the eventual non NUMBER terms some user can have written here*/
while (cur_term && cur_term->type != TERM_NUMBER) {
cur_term = cur_term->next;
}
-
if (!cur_term)
- return CR_OK;
+ return CR_ERROR ;
for (direction = 0; direction < NB_DIRS; direction++) {
set_prop_padding_x_from_value (a_style, cur_term, direction);
}
cur_term = cur_term->next;
+ /*filter non NUMBER terms that some users can have written here...*/
while (cur_term && cur_term->type != TERM_NUMBER) {
cur_term = cur_term->next;
}
+ /*the user can have just written padding: 1px*/
if (!cur_term)
return CR_OK;
@@ -1176,9 +1226,7 @@ set_prop_padding_from_value (CRStyle * a_style, CRTerm * a_value)
}
if (!cur_term)
return CR_OK;
-
status = set_prop_padding_x_from_value (a_style, cur_term, DIR_LEFT);
-
return status;
}
@@ -1192,6 +1240,7 @@ set_prop_margin_from_value (CRStyle * a_style, CRTerm * a_value)
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;
}
@@ -1227,7 +1276,7 @@ set_prop_margin_from_value (CRStyle * a_style, CRTerm * a_value)
if (!cur_term)
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;
}
@@ -1242,6 +1291,16 @@ set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value)
g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR);
+ if (a_value->type == TERM_IDENT &&
+ a_value->content.str &&
+ a_value->content.str->stryng &&
+ a_value->content.str->stryng->str &&
+ !strcmp ("inherit", a_value->content.str->stryng->str))
+ {
+ font_family = cr_font_family_new (FONT_FAMILY_INHERIT, NULL);
+ goto out;
+ }
+
for (cur_term = a_value; cur_term; cur_term = cur_term->next) {
switch (cur_term->type) {
case TERM_IDENT:
@@ -1249,29 +1308,36 @@ set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value)
enum CRFontFamilyType font_type;
if (cur_term->content.str
- && cur_term->content.str->str
- && !strcmp (cur_term->content.str->str,
- "sans-serif")) {
+ && cur_term->content.str->stryng
+ && cur_term->content.str->stryng->str
+ && !strcmp
+ (cur_term->content.str->stryng->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")) {
+ && cur_term->content.str->stryng
+ && cur_term->content.str->stryng->str
+ && !strcmp
+ (cur_term->content.str->stryng->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")) {
+ && cur_term->content.str->stryng
+ && cur_term->content.str->stryng->str
+ && !strcmp (cur_term->content.str->stryng->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")) {
+ && cur_term->content.str->stryng
+ && cur_term->content.str->stryng->str
+ && !strcmp (cur_term->content.str->stryng->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")) {
+ && cur_term->content.str->stryng
+ && cur_term->content.str->stryng->str
+ && !strcmp (cur_term->content.str->stryng->str,
+ "monospace")) {
font_type = FONT_FAMILY_MONOSPACE;
} else {
/*
@@ -1288,10 +1354,11 @@ set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value)
case TERM_STRING:
{
if (cur_term->content.str
- && cur_term->content.str->str) {
+ && cur_term->content.str->stryng
+ && cur_term->content.str->stryng->str) {
cur_ff = cr_font_family_new
(FONT_FAMILY_NON_GENERIC,
- cur_term->content.str->str);
+ cur_term->content.str->stryng->str);
}
}
break;
@@ -1306,11 +1373,14 @@ set_prop_font_family_from_value (CRStyle * a_style, CRTerm * a_value)
}
}
+ out:
if (font_family) {
if (a_style->font_family) {
cr_font_family_destroy (a_style->font_family);
- a_style->font_family = font_family;
+ a_style->font_family = NULL ;
}
+ a_style->font_family = font_family;
+ font_family = NULL ;
}
return CR_OK;
@@ -1343,8 +1413,10 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
switch (a_value->type) {
case TERM_IDENT:
if (a_value->content.str
- && a_value->content.str->str
- && !strcmp (a_value->content.str->str, "xx-small")) {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str,
+ "xx-small")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1354,9 +1426,10 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
FONT_SIZE_XX_SMALL;
} else if (a_value->content.str
- && a_value->content.str->str
- && !strcmp (a_value->content.str->str, "x-small"))
- {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str,
+ "x-small")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1365,8 +1438,10 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
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")) {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str,
+ "small")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1375,8 +1450,9 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
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")) {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str, "medium")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1385,8 +1461,10 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
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")) {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str,
+ "large")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1395,9 +1473,10 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
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"))
- {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str,
+ "x-large")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1406,9 +1485,10 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
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"))
- {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str,
+ "xx-large")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1417,17 +1497,20 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
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")) {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->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"))
- {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str,
+ "smaller")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
@@ -1435,18 +1518,13 @@ set_prop_font_size_from_value (CRStyle * a_style, CRTerm * a_value)
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"))
- {
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str
+ && !strcmp (a_value->content.str->stryng->str, "inherit")) {
status = init_style_font_size_field (a_style);
g_return_val_if_fail (status == CR_OK, status);
+ a_style->font_size->type = INHERITED_FONT_SIZE;
- if (a_style->parent_style
- && a_style->parent_style->font_style) {
- cr_font_size_copy
- (a_style->font_size,
- a_style->parent_style->font_size);
- }
} else {
return CR_UNKNOWN_PROP_VAL_ERROR;
}
@@ -1479,24 +1557,23 @@ set_prop_font_style_from_value (CRStyle * a_style, CRTerm * a_value)
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")) {
+ if (a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
+ if (!strcmp (a_value->content.str->stryng->str, "normal")) {
a_style->font_style = FONT_STYLE_NORMAL;
} else if (!strcmp
- (a_value->content.str->str, "italic")) {
+ (a_value->content.str->stryng->str,
+ "italic")) {
a_style->font_style = FONT_STYLE_ITALIC;
} else if (!strcmp
- (a_value->content.str->str, "oblique")) {
+ (a_value->content.str->stryng->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;
- else
- a_style->font_style =
- a_style->parent_style->
- font_style;
+ (a_value->content.str->stryng->str,
+ "inherit")) {
+ a_style->font_style = FONT_STYLE_INHERIT;
} else {
status = CR_UNKNOWN_PROP_VAL_ERROR;
}
@@ -1520,18 +1597,25 @@ set_prop_font_weight_from_value (CRStyle * a_style, CRTerm * a_value)
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")) {
+ if (a_value->content.str
+ && a_value->content.str->stryng
+ && a_value->content.str->stryng->str) {
+ if (!strcmp (a_value->content.str->stryng->str,
+ "normal")) {
a_style->font_weight = FONT_WEIGHT_NORMAL;
- } else if (!strcmp (a_value->content.str->str,
+ } else if (!strcmp (a_value->content.str->stryng->str,
"bold")) {
a_style->font_weight = FONT_WEIGHT_BOLD;
- } else if (!strcmp (a_value->content.str->str,
+ } else if (!strcmp (a_value->content.str->stryng->str,
"bolder")) {
a_style->font_weight = FONT_WEIGHT_BOLDER;
- } else if (!strcmp (a_value->content.str->str,
+ } else if (!strcmp (a_value->content.str->stryng->str,
"lighter")) {
a_style->font_weight = FONT_WEIGHT_LIGHTER;
+ } else if (!strcmp (a_value->content.str->stryng->str,
+ "inherit")) {
+ a_style->font_weight = FONT_WEIGHT_INHERIT;
+
} else {
status = CR_UNKNOWN_PROP_VAL_ERROR;
}
@@ -1573,15 +1657,54 @@ set_prop_font_weight_from_value (CRStyle * a_style, CRTerm * a_value)
return status;
}
+static enum CRStatus
+set_prop_white_space_from_value (CRStyle * a_style, CRTerm * a_value)
+{
+ enum CRStatus status = CR_OK;
+
+ g_return_val_if_fail (a_style && a_value, CR_BAD_PARAM_ERROR);
+
+ switch (a_value->type) {
+ case TERM_IDENT:
+ if (a_value->content.str && a_value->content.str->stryng) {
+ if (!strcmp (a_value->content.str->stryng->str, "normal")) {
+ a_style->white_space = WHITE_SPACE_NORMAL;
+ } else if (!strcmp (a_value->content.str->stryng->str,
+ "pre")) {
+ a_style->font_weight = WHITE_SPACE_PRE;
+ } else if (!strcmp (a_value->content.str->stryng->str,
+ "nowrap")) {
+ a_style->white_space = WHITE_SPACE_NOWRAP;
+ } else if (!strcmp (a_value->content.str->stryng->str,
+ "inherit")) {
+ a_style->white_space = WHITE_SPACE_INHERIT;
+ } else {
+ status = CR_UNKNOWN_PROP_VAL_ERROR;
+ }
+ }
+ break;
+ default:
+ status = CR_UNKNOWN_PROP_VAL_ERROR;
+ break;
+ }
+
+ return status;
+}
+
/******************
*Public methods
******************/
/**
*Default constructor of #CRStyle.
+ *@param a_set_props_to_initial_values if TRUE, the style properties
+ *will be set to the default values. Only the style properties of the
+ *root box should be set to their initial values.
+ *Otherwise, the style values are set to their default value.
+ *Read the CSS2 spec, chapters 6.1.1 to 6.2.
*/
CRStyle *
-cr_style_new (void)
+cr_style_new (gboolean a_set_props_to_initial_values)
{
CRStyle *result = NULL;
@@ -1593,20 +1716,121 @@ cr_style_new (void)
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);
+ if (a_set_props_to_initial_values == TRUE) {
+ cr_style_set_props_to_initial_values (result);
+ } else {
+ cr_style_set_props_to_default_values (result);
+ }
return result;
}
/**
- *Sets the style properties to their default values
- *according to the css2 spec.
+ *Sets the style properties to their default values according to the css2 spec
+ * i.e inherit if the property is inherited, its initial value otherway.
*@param a_this the current instance of #CRStyle.
*@return CR_OK upon successfull completion, an error code otherwise.
*/
-enum CRStatus
-cr_style_set_props_to_defaults (CRStyle * a_this)
+enum CRStatus
+cr_style_set_props_to_default_values (CRStyle * a_this)
+{
+ glong i = 0;
+
+ g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
+
+ 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;
+
+ case NUM_PROP_PADDING_TOP:
+ case NUM_PROP_PADDING_RIGHT:
+ case NUM_PROP_PADDING_BOTTOM:
+ case NUM_PROP_PADDING_LEFT:
+ case NUM_PROP_BORDER_TOP:
+ case NUM_PROP_BORDER_RIGHT:
+ case NUM_PROP_BORDER_BOTTOM:
+ case NUM_PROP_BORDER_LEFT:
+ case NUM_PROP_MARGIN_TOP:
+ case NUM_PROP_MARGIN_RIGHT:
+ case NUM_PROP_MARGIN_BOTTOM:
+ case NUM_PROP_MARGIN_LEFT:
+ cr_num_set (&a_this->num_props[i].sv,
+ 0, NUM_LENGTH_PX);
+ break;
+
+ default:
+ cr_utils_trace_info ("Unknown property");
+ break;
+ }
+ }
+
+ for (i = 0; i < NB_RGB_PROPS; i++) {
+
+ switch (i) {
+ /*default foreground color is black */
+ case RGB_PROP_COLOR:
+ /*
+ *REVIEW: color is inherited and the default value is
+ *ua dependant.
+ */
+ cr_rgb_set_to_inherit (&a_this->rgb_props[i].sv) ;
+ break;
+
+ /*default background color is white */
+ case RGB_PROP_BACKGROUND_COLOR:
+ /* TODO: the default value should be transparent */
+ cr_rgb_set (&a_this->rgb_props[i].sv,
+ 255, 255, 255, FALSE);
+ break;
+
+ default:
+ /*
+ *TODO: for BORDER_COLOR the initial value should
+ * be the same as COLOR
+ */
+ 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;
+ }
+
+ a_this->display = DISPLAY_INLINE;
+ a_this->position = POSITION_STATIC;
+ a_this->float_type = FLOAT_NONE;
+ a_this->parent_style = NULL;
+ a_this->font_style = FONT_STYLE_INHERIT;
+ a_this->font_variant = FONT_VARIANT_INHERIT;
+ a_this->font_weight = FONT_WEIGHT_INHERIT;
+ a_this->font_family = NULL;
+
+ /* To make the inheritance resolution possible and efficient */
+ a_this->inherited_props_resolved = FALSE ;
+ return CR_OK;
+}
+
+/**
+ *Sets the style properties to their initial value according to the css2 spec.
+ *This function should be used to initialize the style of the root element
+ *of an xml tree.
+ *Some properties are user agent dependant like font-family, and
+ *are not initialized, read the spec to make you renderer compliant.
+ *@param a_this the current instance of #CRStyle.
+ *@return CR_OK upon successfull completion, an error code otherwise.
+ */
+enum CRStatus
+cr_style_set_props_to_initial_values (CRStyle *a_this)
{
glong i = 0;
@@ -1671,15 +1895,88 @@ cr_style_set_props_to_defaults (CRStyle * a_this)
a_this->display = DISPLAY_BLOCK;
a_this->position = POSITION_STATIC;
a_this->float_type = FLOAT_NONE;
- a_this->parent_style = NULL;
a_this->font_style = FONT_STYLE_NORMAL;
a_this->font_variant = FONT_VARIANT_NORMAL;
a_this->font_weight = FONT_WEIGHT_NORMAL;
a_this->font_stretch = FONT_STRETCH_NORMAL;
+ a_this->white_space = WHITE_SPACE_NORMAL;
+
+ a_this->inherited_props_resolved = FALSE ;
+
return CR_OK;
}
/**
+ *Resolves the inherited properties.
+ *The function sets the "inherited" properties to either the value of
+ *their parent properties.
+ *This function is *NOT* recursive. So the inherited properties of
+ *the parent style must have been resolved prior to calling this function.
+ *@param a_this the instance where
+ *@return CR_OK if a root node is found and the propagation is successful,
+ *an error code otherwise
+ */
+enum CRStatus
+cr_style_resolve_inherited_properties (CRStyle *a_this)
+{
+ enum CRStatus ret = CR_OK;
+ glong i = 0;
+
+ g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
+ g_return_val_if_fail (a_this->parent_style, CR_BAD_PARAM_ERROR) ;
+
+ if (a_this->inherited_props_resolved == TRUE)
+ return CR_OK ;
+
+ if (a_this->num_props[i].sv.type == NUM_INHERIT) {
+ cr_num_copy (&a_this->num_props[i].sv,
+ &a_this->parent_style->num_props[i].sv);
+ }
+ for (i=0; i < NB_RGB_PROPS; i++) {
+ if (cr_rgb_is_set_to_inherit (&a_this->rgb_props[i].sv) == TRUE) {
+ cr_rgb_set_from_rgb(
+ &a_this->rgb_props[i].sv,
+ &a_this->parent_style->rgb_props[i].sv);
+ }
+ }
+ for (i = 0; i < NB_BORDER_STYLE_PROPS; i++) {
+ if (a_this->border_style_props[i] == BORDER_STYLE_INHERIT) {
+ a_this->border_style_props[i] =
+ a_this->parent_style->border_style_props[i];
+ }
+ }
+
+ if (a_this->display == DISPLAY_INHERIT) {
+ a_this->display = a_this->parent_style->display;
+ }
+ if (a_this->position == POSITION_INHERIT) {
+ a_this->position = a_this->parent_style->position;
+ }
+ if (a_this->float_type == FLOAT_INHERIT) {
+ a_this->float_type = a_this->parent_style->float_type;
+ }
+ if (a_this->font_style == FONT_STYLE_INHERIT) {
+ a_this->font_style = a_this->parent_style->font_style;
+ }
+ if (a_this->font_variant == FONT_VARIANT_INHERIT) {
+ a_this->font_variant = a_this->parent_style->font_variant;
+ }
+ if (a_this->font_weight == FONT_WEIGHT_INHERIT) {
+ a_this->font_weight = a_this->parent_style->font_weight;
+ }
+ if (a_this->font_stretch == FONT_STRETCH_INHERIT) {
+ a_this->font_stretch = a_this->parent_style->font_stretch;
+ }
+ /*NULL is inherit marker for font_famiy*/
+ if (a_this->font_family == NULL) {
+ a_this->font_family = a_this->parent_style->font_family;
+ }
+
+ a_this->inherited_props_resolved = TRUE ;
+ return ret;
+}
+
+/**
*Walks through a css2 property declaration, and populated the
*according field(s) in the #CRStyle structure.
*If the properties or their value(s) are/is not known,
@@ -1700,9 +1997,12 @@ cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl)
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->stryng
+ && a_decl->property->stryng->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->stryng->str);
value = a_decl->value;
switch (prop_id) {
@@ -1726,7 +2026,7 @@ cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl)
break;
case PROP_ID_PADDING:
- status = set_prop_padding_from_value (a_this, value);
+ status = set_prop_padding_from_value (a_this, value) ;
break;
case PROP_ID_BORDER_TOP_WIDTH:
@@ -1749,6 +2049,10 @@ cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl)
DIR_LEFT);
break;
+ case PROP_ID_BORDER_WIDTH:
+ status = set_prop_border_width_from_value (a_this, value) ;
+ break ;
+
case PROP_ID_BORDER_TOP_STYLE:
status = set_prop_border_x_style_from_value (a_this, value,
DIR_TOP);
@@ -1769,6 +2073,10 @@ cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl)
DIR_LEFT);
break;
+ case PROP_ID_BORDER_STYLE:
+ status = set_prop_border_style_from_value (a_this, value) ;
+ break ;
+
case PROP_ID_BORDER_TOP_COLOR:
status = set_prop_border_x_color_from_value (a_this, value,
DIR_TOP);
@@ -1893,6 +2201,10 @@ cr_style_set_style_from_decl (CRStyle * a_this, CRDeclaration * a_decl)
status = set_prop_font_weight_from_value (a_this, value);
break;
+ case PROP_ID_WHITE_SPACE:
+ status = set_prop_white_space_from_value(a_this, value);
+ break;
+
default:
return CR_UNKNOWN_TYPE_ERROR;
@@ -1956,7 +2268,7 @@ cr_style_dup (CRStyle * a_this)
g_return_val_if_fail (a_this, NULL);
- result = cr_style_new ();
+ result = cr_style_new (FALSE);
if (!result) {
cr_utils_trace_info ("Out of memory");
return NULL;
@@ -2002,7 +2314,7 @@ cr_style_num_prop_val_to_string (CRNumPropVal * a_prop_val,
str = g_string_new (NULL);
cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
- g_string_append_printf (str, "%s", "NumPropVal {");
+ g_string_append (str, "NumPropVal {");
tmp_str = cr_num_to_string (&a_prop_val->sv);
if (!tmp_str) {
status = CR_ERROR;
@@ -2019,8 +2331,8 @@ cr_style_num_prop_val_to_string (CRNumPropVal * a_prop_val,
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);
+ g_string_append (str, "}");
+ g_string_append (a_str, str->str);
status = CR_OK;
cleanup:
@@ -2047,7 +2359,7 @@ cr_style_rgb_prop_val_to_string (CRRgbPropVal * a_prop_val,
str = g_string_new (NULL);
cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
- g_string_append_printf (str, "RGBPropVal {");
+ g_string_append (str, "RGBPropVal {");
tmp_str = cr_rgb_to_string (&a_prop_val->sv);
if (!tmp_str) {
status = CR_ERROR;
@@ -2073,8 +2385,8 @@ cr_style_rgb_prop_val_to_string (CRRgbPropVal * a_prop_val,
g_free (tmp_str);
tmp_str = NULL;
- g_string_append_printf (str, "}");
- g_string_append_printf (a_str, "%s", str->str);
+ g_string_append (str, "}");
+ g_string_append (a_str, str->str);
status = CR_OK;
cleanup:
@@ -2132,7 +2444,7 @@ cr_style_border_style_to_string (enum CRBorderStyle a_prop,
break;
}
cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
- g_string_append_printf (a_str, "%s", str);
+ g_string_append (a_str, str);
return CR_OK;
}
@@ -2204,7 +2516,7 @@ cr_style_display_type_to_string (enum CRDisplayType a_code,
break;
}
cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
- g_string_append_printf (a_str, str);
+ g_string_append (a_str, str);
return CR_OK;
}
@@ -2237,7 +2549,7 @@ cr_style_position_type_to_string (enum CRPositionType a_code,
str = (gchar *) "unknown static property";
}
cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
- g_string_append_printf (a_str, "%s", str);
+ g_string_append (a_str, str);
return CR_OK;
}
@@ -2266,9 +2578,41 @@ cr_style_float_type_to_string (enum CRFloatType a_code,
str = (gchar *) "unknown float property value";
break;
}
+ cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
+ g_string_append (a_str, str);
return CR_OK;
}
+enum CRStatus
+cr_style_white_space_type_to_string (enum CRWhiteSpaceType a_code,
+ GString * a_str, guint a_nb_indent)
+{
+ gchar *str = NULL;
+
+ g_return_val_if_fail (a_str, CR_BAD_PARAM_ERROR);
+
+ switch (a_code) {
+ case WHITE_SPACE_NORMAL:
+ str = (gchar *) "normal";
+ break;
+ case WHITE_SPACE_PRE:
+ str = (gchar *) "pre";
+ break;
+ case WHITE_SPACE_NOWRAP:
+ str = (gchar *) "nowrap";
+ break;
+ case WHITE_SPACE_INHERIT:
+ str = (gchar *) "inherited";
+ break;
+ default:
+ str = (gchar *) "unknow white space property value";
+ break;
+ }
+ cr_utils_dump_n_chars2 (' ', a_str, a_nb_indent);
+ g_string_append (a_str, str);
+ return CR_OK;
+}
+
/**
*Serializes in instance of #CRStyle into
*a string
@@ -2296,7 +2640,7 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent)
str = *a_str;
}
cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
- g_string_append_printf (str, "style {\n");
+ g_string_append (str, "style {\n");
/*loop over the num_props and to_string() them */
for (i = NUM_PROP_TOP; i < NB_NUM_PROPS; i++) {
@@ -2310,13 +2654,13 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent)
if (tmp_str) {
g_string_append_printf (str, "%s: ", tmp_str);
} else {
- g_string_append_printf (str, "%s", "NULL");
+ g_string_append (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");
+ g_string_append (str, "\n");
}
/*loop over the rgb_props and to_string() them all */
for (i = RGB_PROP_BORDER_TOP_COLOR; i < NB_RGB_PROPS; i++) {
@@ -2325,13 +2669,13 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent)
if (tmp_str) {
g_string_append_printf (str, "%s: ", tmp_str);
} else {
- g_string_append_printf (str, "%s", "NULL: ");
+ g_string_append (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");
+ g_string_append (str, "\n");
}
/*loop over the border_style_props and to_string() them */
for (i = BORDER_STYLE_PROP_TOP; i < NB_BORDER_STYLE_PROPS; i++) {
@@ -2340,103 +2684,109 @@ cr_style_to_string (CRStyle * a_this, GString ** a_str, guint a_nb_indent)
if (tmp_str) {
g_string_append_printf (str, "%s: ", tmp_str);
} else {
- g_string_append_printf (str, "NULL: ");
+ g_string_append (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");
+ g_string_append (str, "\n");
}
cr_utils_dump_n_chars2 (' ', str, indent);
- g_string_append_printf (str, "display: ");
+ g_string_append (str, "display: ");
cr_style_display_type_to_string (a_this->display, str, 0);
- g_string_append_printf (str, "\n");
+ g_string_append (str, "\n");
cr_utils_dump_n_chars2 (' ', str, indent);
- g_string_append_printf (str, "position: ");
+ g_string_append (str, "position: ");
cr_style_position_type_to_string (a_this->position, str, 0);
- g_string_append_printf (str, "\n");
+ g_string_append (str, "\n");
cr_utils_dump_n_chars2 (' ', str, indent);
- g_string_append_printf (str, "float-type: ");
+ g_string_append (str, "float-type: ");
cr_style_float_type_to_string (a_this->float_type, str, 0);
- g_string_append_printf (str, "\n");
+ g_string_append (str, "\n");
+
+ cr_utils_dump_n_chars2 (' ', str, indent);
+ g_string_append (str, "white-space: ");
+ cr_style_white_space_type_to_string (a_this->white_space, str, 0);
+ g_string_append (str, "\n");
cr_utils_dump_n_chars2 (' ', str, indent);
- g_string_append_printf (str, "font-family: ");
+ g_string_append (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_string_append (str, tmp_str);
g_free (tmp_str);
tmp_str = NULL;
} else {
- g_string_append_printf (str, "NULL");
+ g_string_append (str, "NULL");
}
- g_string_append_printf (str, "\n");
+ g_string_append (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");
+ g_string_append (str, "font-size: NULL");
}
tmp_str = NULL;
- g_string_append_printf (str, "\n");
+ g_string_append (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");
+ g_string_append (str, "font-size-adjust: NULL");
}
tmp_str = NULL;
- g_string_append_printf (str, "\n");
+ g_string_append (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);
+ g_string_append_printf (str, "font-style: %s", tmp_str);
} else {
- g_string_append_printf (str, "font-size: NULL");
+ g_string_append (str, "font-style: NULL");
}
tmp_str = NULL;
- g_string_append_printf (str, "\n");
+ g_string_append (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");
+ g_string_append (str, "font-variant: NULL");
}
tmp_str = NULL;
- g_string_append_printf (str, "\n");
+ g_string_append (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");
+ g_string_append (str, "font-weight: NULL");
}
tmp_str = NULL;
- g_string_append_printf (str, "\n");
+ g_string_append (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");
+ g_string_append (str, "font-stretch: NULL");
}
tmp_str = NULL;
- g_string_append_printf (str, "\n");
+ g_string_append (str, "\n");
+
cr_utils_dump_n_chars2 (' ', str, a_nb_indent);
- g_string_append_printf (str, "}");
+ g_string_append (str, "}");
return CR_OK;
}
@@ -2452,3 +2802,4 @@ cr_style_destroy (CRStyle * a_this)
g_free (a_this);
}
+
diff --git a/src/cr-style.h b/src/cr-style.h
index 54f49eb..a48a167 100644
--- a/src/cr-style.h
+++ b/src/cr-style.h
@@ -3,7 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
@@ -18,6 +17,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * Author: Dodji Seketeli.
+ * See COPYRIGHTS file for copyright information.
*/
#ifndef __CR_STYLE_H__
@@ -46,7 +48,8 @@ enum CRBorderStyle
BORDER_STYLE_GROOVE,
BORDER_STYLE_RIDGE,
BORDER_STYLE_INSET,
- BORDER_STYLE_OUTSET
+ BORDER_STYLE_OUTSET,
+ BORDER_STYLE_INHERIT
} ;
enum CRDisplayType
@@ -88,6 +91,14 @@ enum CRFloatType
FLOAT_INHERIT
} ;
+enum CRWhiteSpaceType
+{
+ WHITE_SPACE_NORMAL,
+ WHITE_SPACE_PRE,
+ WHITE_SPACE_NOWRAP,
+ WHITE_SPACE_INHERIT
+} ;
+
#define BORDER_THIN 2
#define BORDER_MEDIUM 4
@@ -254,10 +265,19 @@ struct _CRStyle
enum CRFontWeight font_weight ;
enum CRFontStretch font_stretch ;
+ /**
+ * the 'tex' properties
+ */
+ enum CRWhiteSpaceType white_space;
+
+ gboolean inherited_props_resolved ;
CRStyle *parent_style ;
gulong ref_count ;
} ;
+enum CRStatus cr_style_white_space_type_to_string (enum CRWhiteSpaceType a_code,
+ GString * a_str, guint a_nb_indent) ;
+
enum CRStatus cr_style_num_prop_val_to_string (CRNumPropVal *a_prop_val,
GString *a_str,
guint a_nb_indent) ;
@@ -281,11 +301,16 @@ enum CRStatus cr_style_position_type_to_string (enum CRPositionType a_code,
enum CRStatus cr_style_float_type_to_string (enum CRFloatType a_code,
GString *a_str,
guint a_nb_indent) ;
-CRStyle * cr_style_new (void) ;
-enum CRStatus cr_style_set_props_to_defaults (CRStyle *a_this) ;
+CRStyle * cr_style_new (gboolean a_set_props_to_initial_values) ;
+
+enum CRStatus cr_style_set_props_to_default_values (CRStyle *a_this) ;
+enum CRStatus cr_style_set_props_to_initial_values (CRStyle *a_this) ;
+enum CRStatus cr_style_resolve_inherited_properties (CRStyle *a_this) ;
+enum CRStatus cr_style_propagate_from_parent (CRStyle *a_this);
-enum CRStatus cr_style_set_style_from_decl (CRStyle *a_this, CRDeclaration *a_decl) ;
+enum CRStatus cr_style_set_style_from_decl (CRStyle *a_this,
+ CRDeclaration *a_decl) ;
enum CRStatus cr_style_copy (CRStyle *a_dest, CRStyle *a_src) ;
diff --git a/src/cr-stylesheet.c b/src/cr-stylesheet.c
index ee6e475..97ae79e 100644
--- a/src/cr-stylesheet.c
+++ b/src/cr-stylesheet.c
@@ -3,7 +3,7 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji seketeli.org>
+ * Copyright (C) 2002-2004 Dodji Seketeli
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
diff --git a/src/cr-term.c b/src/cr-term.c
index 9828a3d..1e1d931 100644
--- a/src/cr-term.c
+++ b/src/cr-term.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,11 +16,11 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
-/*
- *$Id$
- */
#include <stdio.h>
#include <string.h>
#include "cr-term.h"
@@ -57,7 +55,7 @@ cr_term_clear (CRTerm * a_this)
case TERM_URI:
case TERM_HASH:
if (a_this->content.str) {
- g_string_free (a_this->content.str, TRUE);
+ cr_string_destroy (a_this->content.str);
a_this->content.str = NULL;
}
break;
@@ -152,7 +150,7 @@ cr_term_set_number (CRTerm * a_this, CRNum * a_num)
}
enum CRStatus
-cr_term_set_function (CRTerm * a_this, GString * a_func_name,
+cr_term_set_function (CRTerm * a_this, CRString * a_func_name,
CRTerm * a_func_param)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
@@ -166,7 +164,7 @@ cr_term_set_function (CRTerm * a_this, GString * a_func_name,
}
enum CRStatus
-cr_term_set_string (CRTerm * a_this, GString * a_str)
+cr_term_set_string (CRTerm * a_this, CRString * a_str)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
@@ -178,7 +176,7 @@ cr_term_set_string (CRTerm * a_this, GString * a_str)
}
enum CRStatus
-cr_term_set_ident (CRTerm * a_this, GString * a_str)
+cr_term_set_ident (CRTerm * a_this, CRString * a_str)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
@@ -190,7 +188,7 @@ cr_term_set_ident (CRTerm * a_this, GString * a_str)
}
enum CRStatus
-cr_term_set_uri (CRTerm * a_this, GString * a_str)
+cr_term_set_uri (CRTerm * a_this, CRString * a_str)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
@@ -214,7 +212,7 @@ cr_term_set_rgb (CRTerm * a_this, CRRgb * a_rgb)
}
enum CRStatus
-cr_term_set_hash (CRTerm * a_this, GString * a_str)
+cr_term_set_hash (CRTerm * a_this, CRString * a_str)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
@@ -299,16 +297,16 @@ cr_term_to_string (CRTerm * a_this)
switch (cur->the_operator) {
case DIVIDE:
- g_string_append_printf (str_buf, " / ");
+ g_string_append (str_buf, " / ");
break;
case COMMA:
- g_string_append_printf (str_buf, ", ");
+ g_string_append (str_buf, ", ");
break;
case NO_OP:
if (cur->prev) {
- g_string_append_printf (str_buf, " ");
+ g_string_append (str_buf, " ");
}
break;
default:
@@ -318,11 +316,11 @@ cr_term_to_string (CRTerm * a_this)
switch (cur->unary_op) {
case PLUS_UOP:
- g_string_append_printf (str_buf, "+");
+ g_string_append (str_buf, "+");
break;
case MINUS_UOP:
- g_string_append_printf (str_buf, "-");
+ g_string_append (str_buf, "-");
break;
default:
@@ -346,8 +344,8 @@ cr_term_to_string (CRTerm * a_this)
case TERM_FUNCTION:
if (cur->content.str) {
content = g_strndup
- (cur->content.str->str,
- cur->content.str->len);
+ (cur->content.str->stryng->str,
+ cur->content.str->stryng->len);
}
if (content) {
@@ -362,14 +360,13 @@ cr_term_to_string (CRTerm * a_this)
ext_content.func_param);
if (tmp_str) {
- g_string_append_printf
- (str_buf,
- "%s", 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 (str_buf, ")");
g_free (content);
content = NULL;
}
@@ -380,8 +377,8 @@ cr_term_to_string (CRTerm * a_this)
case TERM_STRING:
if (cur->content.str) {
content = g_strndup
- (cur->content.str->str,
- cur->content.str->len);
+ (cur->content.str->stryng->str,
+ cur->content.str->stryng->len);
}
if (content) {
@@ -395,8 +392,8 @@ cr_term_to_string (CRTerm * a_this)
case TERM_IDENT:
if (cur->content.str) {
content = g_strndup
- (cur->content.str->str,
- cur->content.str->len);
+ (cur->content.str->stryng->str,
+ cur->content.str->stryng->len);
}
if (content) {
@@ -409,8 +406,8 @@ cr_term_to_string (CRTerm * a_this)
case TERM_URI:
if (cur->content.str) {
content = g_strndup
- (cur->content.str->str,
- cur->content.str->len);
+ (cur->content.str->stryng->str,
+ cur->content.str->stryng->len);
}
if (content) {
@@ -425,7 +422,7 @@ cr_term_to_string (CRTerm * a_this)
if (cur->content.rgb) {
guchar *tmp_str = NULL;
- g_string_append_printf (str_buf, "rgb(");
+ g_string_append (str_buf, "rgb(");
tmp_str = cr_rgb_to_string (cur->content.rgb);
if (tmp_str) {
@@ -433,13 +430,13 @@ cr_term_to_string (CRTerm * a_this)
g_free (tmp_str);
tmp_str = NULL;
}
- g_string_append_printf (str_buf, ")");
+ g_string_append (str_buf, ")");
}
break;
case TERM_UNICODERANGE:
- g_string_append_printf
+ g_string_append
(str_buf,
"?found unicoderange: dump not supported yet?");
break;
@@ -447,8 +444,8 @@ cr_term_to_string (CRTerm * a_this)
case TERM_HASH:
if (cur->content.str) {
content = g_strndup
- (cur->content.str->str,
- cur->content.str->len);
+ (cur->content.str->stryng->str,
+ cur->content.str->stryng->len);
}
if (content) {
@@ -460,9 +457,8 @@ cr_term_to_string (CRTerm * a_this)
break;
default:
- g_string_append_printf (str_buf,
- "%s",
- "Unrecognized Term type");
+ g_string_append (str_buf,
+ "Unrecognized Term type");
break;
}
}
@@ -476,6 +472,202 @@ cr_term_to_string (CRTerm * a_this)
return result;
}
+guchar *
+cr_term_one_to_string (CRTerm * a_this)
+{
+ GString *str_buf = NULL;
+ guchar *result = NULL,
+ *content = NULL;
+
+ g_return_val_if_fail (a_this, NULL);
+
+ str_buf = g_string_new (NULL);
+ g_return_val_if_fail (str_buf, NULL);
+
+ if ((a_this->content.str == NULL)
+ && (a_this->content.num == NULL)
+ && (a_this->content.str == NULL)
+ && (a_this->content.rgb == NULL))
+ return NULL ;
+
+ switch (a_this->the_operator) {
+ case DIVIDE:
+ g_string_append_printf (str_buf, " / ");
+ break;
+
+ case COMMA:
+ g_string_append_printf (str_buf, ", ");
+ break;
+
+ case NO_OP:
+ if (a_this->prev) {
+ g_string_append_printf (str_buf, " ");
+ }
+ break;
+ default:
+
+ break;
+ }
+
+ switch (a_this->unary_op) {
+ case PLUS_UOP:
+ g_string_append_printf (str_buf, "+");
+ break;
+
+ case MINUS_UOP:
+ g_string_append_printf (str_buf, "-");
+ break;
+
+ default:
+ break;
+ }
+
+ switch (a_this->type) {
+ case TERM_NUMBER:
+ if (a_this->content.num) {
+ content = cr_num_to_string (a_this->content.num);
+ }
+
+ if (content) {
+ g_string_append (str_buf, content);
+ g_free (content);
+ content = NULL;
+ }
+
+ break;
+
+ case TERM_FUNCTION:
+ if (a_this->content.str) {
+ content = g_strndup
+ (a_this->content.str->stryng->str,
+ a_this->content.str->stryng->len);
+ }
+
+ if (content) {
+ g_string_append_printf (str_buf, "%s(",
+ content);
+
+ if (a_this->ext_content.func_param) {
+ guchar *tmp_str = NULL;
+
+ 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;
+ }
+
+ g_string_append_printf (str_buf, ")");
+ g_free (content);
+ content = NULL;
+ }
+ }
+
+ break;
+
+ case TERM_STRING:
+ if (a_this->content.str) {
+ content = g_strndup
+ (a_this->content.str->stryng->str,
+ a_this->content.str->stryng->len);
+ }
+
+ if (content) {
+ g_string_append_printf (str_buf,
+ "\"%s\"", content);
+ g_free (content);
+ content = NULL;
+ }
+ break;
+
+ case TERM_IDENT:
+ if (a_this->content.str) {
+ content = g_strndup
+ (a_this->content.str->stryng->str,
+ a_this->content.str->stryng->len);
+ }
+
+ if (content) {
+ g_string_append (str_buf, content);
+ g_free (content);
+ content = NULL;
+ }
+ break;
+
+ case TERM_URI:
+ if (a_this->content.str) {
+ content = g_strndup
+ (a_this->content.str->stryng->str,
+ a_this->content.str->stryng->len);
+ }
+
+ if (content) {
+ g_string_append_printf
+ (str_buf, "url(%s)", content);
+ g_free (content);
+ content = NULL;
+ }
+ break;
+
+ case TERM_RGB:
+ if (a_this->content.rgb) {
+ guchar *tmp_str = NULL;
+
+ g_string_append_printf (str_buf, "rgb(");
+ tmp_str = cr_rgb_to_string (a_this->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, ")");
+ }
+
+ break;
+
+ case TERM_UNICODERANGE:
+ g_string_append_printf
+ (str_buf,
+ "?found unicoderange: dump not supported yet?");
+ break;
+
+ case TERM_HASH:
+ if (a_this->content.str) {
+ content = g_strndup
+ (a_this->content.str->stryng->str,
+ a_this->content.str->stryng->len);
+ }
+
+ if (content) {
+ g_string_append_printf (str_buf,
+ "#%s", content);
+ g_free (content);
+ content = NULL;
+ }
+ break;
+
+ default:
+ g_string_append_printf (str_buf,
+ "%s",
+ "Unrecognized Term type");
+ break;
+ }
+
+ if (str_buf) {
+ result = str_buf->str;
+ g_string_free (str_buf, FALSE);
+ str_buf = NULL;
+ }
+
+ return result;
+}
+
/**
*Dumps the expression (a list of terms connected by operators)
*to a file.
diff --git a/src/cr-term.h b/src/cr-term.h
index e203ed9..41b6d78 100644
--- a/src/cr-term.h
+++ b/src/cr-term.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
#include <stdio.h>
@@ -29,6 +26,7 @@
#include "cr-utils.h"
#include "cr-rgb.h"
#include "cr-num.h"
+#include "cr-string.h"
#ifndef __CR_TERM_H__
#define __CR_TERM_H__
@@ -41,7 +39,7 @@ G_BEGIN_DECLS
*/
enum CRTermType
-{
+{
TERM_NO_TYPE = 0,
TERM_NUMBER,
TERM_FUNCTION,
@@ -108,7 +106,7 @@ struct _CRTerm
union
{
CRNum *num ;
- GString * str ;
+ CRString * str ;
CRRgb * rgb ;
} content ;
@@ -144,63 +142,48 @@ struct _CRTerm
*term.
*/
CRTerm *prev ;
+ CRParsingLocation location ;
} ;
-CRTerm *
-cr_term_parse_expression_from_buf (const guchar *a_buf,
- enum CREncoding a_encoding) ;
-CRTerm *
-cr_term_new (void) ;
+CRTerm * cr_term_parse_expression_from_buf (const guchar *a_buf,
+ enum CREncoding a_encoding) ;
+CRTerm * cr_term_new (void) ;
-enum CRStatus
-cr_term_set_number (CRTerm *a_this, CRNum *a_num) ;
+enum CRStatus cr_term_set_number (CRTerm *a_this, CRNum *a_num) ;
-enum CRStatus
-cr_term_set_function (CRTerm *a_this, GString *a_func_name,
- CRTerm *a_func_param) ;
+enum CRStatus cr_term_set_function (CRTerm *a_this,
+ CRString *a_func_name,
+ CRTerm *a_func_param) ;
-enum CRStatus
-cr_term_set_string (CRTerm *a_this, GString *a_str) ;
+enum CRStatus cr_term_set_string (CRTerm *a_this, CRString *a_str) ;
-enum CRStatus
-cr_term_set_ident (CRTerm *a_this, GString *a_str) ;
+enum CRStatus cr_term_set_ident (CRTerm *a_this, CRString *a_str) ;
-enum CRStatus
-cr_term_set_uri (CRTerm *a_this, GString *a_str) ;
+enum CRStatus cr_term_set_uri (CRTerm *a_this, CRString *a_str) ;
-enum CRStatus
-cr_term_set_rgb (CRTerm *a_this, CRRgb *a_rgb) ;
+enum CRStatus cr_term_set_rgb (CRTerm *a_this, CRRgb *a_rgb) ;
-enum CRStatus
-cr_term_set_hash (CRTerm *a_this, GString *a_str) ;
+enum CRStatus cr_term_set_hash (CRTerm *a_this, CRString *a_str) ;
-CRTerm *
-cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) ;
+CRTerm * cr_term_append_term (CRTerm *a_this, CRTerm *a_new_term) ;
-CRTerm *
-cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) ;
+CRTerm * cr_term_prepend_term (CRTerm *a_this, CRTerm *a_new_term) ;
+guchar * cr_term_to_string (CRTerm *a_this) ;
-guchar *
-cr_term_to_string (CRTerm *a_this) ;
+guchar * cr_term_one_to_string (CRTerm * a_this) ;
-void
-cr_term_dump (CRTerm *a_this, FILE *a_fp) ;
+void cr_term_dump (CRTerm *a_this, FILE *a_fp) ;
-int
-cr_term_nr_values (CRTerm *a_this) ;
+int cr_term_nr_values (CRTerm *a_this) ;
-CRTerm *
-cr_term_get_from_list (CRTerm *a_this, int itemnr) ;
+CRTerm * cr_term_get_from_list (CRTerm *a_this, int itemnr) ;
-void
-cr_term_ref (CRTerm *a_this) ;
+void cr_term_ref (CRTerm *a_this) ;
-gboolean
-cr_term_unref (CRTerm *a_this) ;
+gboolean cr_term_unref (CRTerm *a_this) ;
-void
-cr_term_destroy (CRTerm * a_term) ;
+void cr_term_destroy (CRTerm * a_term) ;
G_END_DECLS
diff --git a/src/cr-tknzr.c b/src/cr-tknzr.c
index 11f85ad..666e213 100644
--- a/src/cr-tknzr.c
+++ b/src/cr-tknzr.c
@@ -17,13 +17,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See the COPYRIGHTS file for copyrights information.
*/
-/*
- *$Id$
- */
-
/**
*@file
*The definition of the #CRTknzr (tokenizer)
@@ -213,29 +210,36 @@ 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);
+static enum CRStatus cr_tknzr_parse_nl (CRTknzr * a_this,
+ guchar ** a_start,
+ guchar ** a_end,
+ CRParsingLocation *a_location);
-static enum CRStatus
- cr_tknzr_parse_w (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,
+ CRParsingLocation *a_location) ;
-static enum CRStatus
- cr_tknzr_parse_unicode_escape (CRTknzr * a_this, guint32 * a_unicode);
+static enum CRStatus cr_tknzr_parse_unicode_escape (CRTknzr * a_this,
+ guint32 * a_unicode,
+ CRParsingLocation *a_location) ;
-static enum CRStatus
- cr_tknzr_parse_escape (CRTknzr * a_this, guint32 * a_esc_code);
+static enum CRStatus cr_tknzr_parse_escape (CRTknzr * a_this,
+ guint32 * a_esc_code,
+ CRParsingLocation *a_location);
-static enum CRStatus
- cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str);
+static enum CRStatus cr_tknzr_parse_string (CRTknzr * a_this,
+ CRString ** a_str);
-static enum CRStatus
- cr_tknzr_parse_comment (CRTknzr * a_this, GString ** a_comment);
+static enum CRStatus cr_tknzr_parse_comment (CRTknzr * a_this,
+ CRString ** a_comment);
-static enum CRStatus
- cr_tknzr_parse_nmstart (CRTknzr * a_this, guint32 * a_char);
+static enum CRStatus cr_tknzr_parse_nmstart (CRTknzr * a_this,
+ guint32 * a_char,
+ CRParsingLocation *a_location);
-static enum CRStatus
- cr_tknzr_parse_num (CRTknzr * a_this, CRNum ** a_num);
+static enum CRStatus cr_tknzr_parse_num (CRTknzr * a_this,
+ CRNum ** a_num);
/**********************************
*PRIVATE methods
@@ -254,7 +258,10 @@ static enum CRStatus
*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,
+ CRParsingLocation *a_location)
{
guint32 cur_char = 0;
CRInputPos init_pos;
@@ -262,7 +269,8 @@ cr_tknzr_parse_w (CRTknzr * a_this, guchar ** a_start, guchar ** a_end)
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);
@@ -275,7 +283,10 @@ cr_tknzr_parse_w (CRTknzr * a_this, guchar ** a_start, guchar ** a_end)
status = CR_PARSING_ERROR;
goto error;
}
-
+ if (a_location) {
+ cr_tknzr_get_parsing_location (a_this,
+ a_location) ;
+ }
RECORD_CUR_BYTE_ADDR (a_this, a_start);
*a_end = *a_start;
@@ -322,7 +333,10 @@ 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,
+ CRParsingLocation *a_location)
{
CRInputPos init_pos;
guchar next_chars[2] = { 0 };
@@ -338,6 +352,10 @@ cr_tknzr_parse_nl (CRTknzr * a_this, guchar ** a_start, guchar ** a_end)
if ((next_chars[0] == '\r' && next_chars[1] == '\n')) {
SKIP_BYTES (a_this, 1);
+ if (a_location) {
+ cr_tknzr_get_parsing_location
+ (a_this, a_location) ;
+ }
SKIP_CHARS (a_this, 1);
RECORD_CUR_BYTE_ADDR (a_this, a_end);
@@ -346,7 +364,10 @@ cr_tknzr_parse_nl (CRTknzr * a_this, guchar ** a_start, guchar ** a_end)
} else if (next_chars[0] == '\n'
|| next_chars[0] == '\r' || next_chars[0] == '\f') {
SKIP_CHARS (a_this, 1);
-
+ if (a_location) {
+ cr_tknzr_get_parsing_location
+ (a_this, a_location) ;
+ }
RECORD_CUR_BYTE_ADDR (a_this, a_start);
*a_end = *a_start;
status = CR_OK;
@@ -354,13 +375,10 @@ cr_tknzr_parse_nl (CRTknzr * a_this, guchar ** a_start, guchar ** a_end)
status = CR_PARSING_ERROR;
goto error;
}
+ 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;
}
@@ -409,71 +427,70 @@ 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,
+ CRString ** a_comment)
{
enum CRStatus status = CR_OK;
CRInputPos init_pos;
- guint32 cur_char = 0;
- GString *comment = NULL;
+ guint32 cur_char = 0, next_char= 0;
+ CRString *comment = NULL;
+ CRParsingLocation loc = {0} ;
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);
+ && PRIVATE (a_this)->input,
+ CR_BAD_PARAM_ERROR);
- READ_NEXT_CHAR (a_this, &cur_char);
+ RECORD_INITIAL_POS (a_this, &init_pos);
+ READ_NEXT_CHAR (a_this, &cur_char) ;
ENSURE_PARSING_COND (cur_char == '/');
+ cr_tknzr_get_parsing_location (a_this, &loc) ;
READ_NEXT_CHAR (a_this, &cur_char);
ENSURE_PARSING_COND (cur_char == '*');
-
- comment = g_string_new (NULL);
-
+ comment = cr_string_new ();
for (;;) {
READ_NEXT_CHAR (a_this, &cur_char);
/*make sure there are no nested comments */
if (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->stryng, '/');
+ g_string_append_unichar (comment->stryng,
+ cur_char);
continue;
}
/*Detect the end of the comments region */
if (cur_char == '*') {
- READ_NEXT_CHAR (a_this, &cur_char);
+ PEEK_NEXT_CHAR (a_this, &next_char);
- if (cur_char == '/') {
+ if (next_char == '/') {
/*
*end of comments region
*Now, call the right SAC callback.
*/
+ SKIP_CHARS (a_this, 1) ;
status = CR_OK;
break;
} else {
- g_string_append_c (comment, '*');
-
+ g_string_append_c (comment->stryng,
+ '*');
}
}
-
- g_string_append_unichar (comment, cur_char);
+ g_string_append_unichar (comment->stryng, cur_char);
}
if (status == CR_OK) {
- *a_comment = comment;
-
+ cr_parsing_location_copy (&comment->location,
+ &loc) ;
+ *a_comment = comment;
return CR_OK;
}
-
- error:
+ error:
if (comment) {
- g_string_free (comment, TRUE);
+ cr_string_destroy (comment);
comment = NULL;
}
@@ -499,7 +516,9 @@ 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,
+ CRParsingLocation *a_location)
{
guint32 cur_char;
CRInputPos init_pos;
@@ -521,7 +540,10 @@ cr_tknzr_parse_unicode_escape (CRTknzr * a_this, guint32 * a_unicode)
status = CR_PARSING_ERROR;
goto error;
}
-
+ if (a_location) {
+ cr_tknzr_get_parsing_location
+ (a_this, a_location) ;
+ }
PEEK_NEXT_CHAR (a_this, &cur_char);
for (occur = 0, unicode = 0; ((cur_char >= '0' && cur_char <= '9')
@@ -555,7 +577,8 @@ cr_tknzr_parse_unicode_escape (CRTknzr * a_this, guint32 * a_unicode)
*appear just after the unicode
*escape.
*/
- cr_tknzr_parse_w (a_this, &tmp_char_ptr1, &tmp_char_ptr2);
+ cr_tknzr_parse_w (a_this, &tmp_char_ptr1,
+ &tmp_char_ptr2, NULL);
status = CR_OK;
} else {
/*
@@ -565,7 +588,7 @@ cr_tknzr_parse_unicode_escape (CRTknzr * a_this, guint32 * a_unicode)
*must be a white space.
*/
status = cr_tknzr_parse_w (a_this, &tmp_char_ptr1,
- &tmp_char_ptr2);
+ &tmp_char_ptr2, NULL);
}
if (status == CR_OK) {
@@ -589,7 +612,8 @@ cr_tknzr_parse_unicode_escape (CRTknzr * a_this, guint32 * a_unicode)
*@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,
+ CRParsingLocation *a_location)
{
enum CRStatus status = CR_OK;
guint32 cur_char = 0;
@@ -612,11 +636,15 @@ cr_tknzr_parse_escape (CRTknzr * a_this, guint32 * a_esc_code)
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);
+ status = cr_tknzr_parse_unicode_escape (a_this, a_esc_code,
+ a_location);
} else {
/*consume the '\' char */
READ_NEXT_CHAR (a_this, &cur_char);
-
+ if (a_location) {
+ cr_tknzr_get_parsing_location (a_this,
+ a_location) ;
+ }
/*then read the char after the '\' */
READ_NEXT_CHAR (a_this, &cur_char);
@@ -624,19 +652,14 @@ cr_tknzr_parse_escape (CRTknzr * a_this, guint32 * a_esc_code)
status = CR_PARSING_ERROR;
goto error;
}
-
*a_esc_code = cur_char;
}
-
if (status == CR_OK) {
return CR_OK;
}
-
- error:
-
+ error:
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return status;
}
@@ -656,20 +679,19 @@ 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, CRString ** a_str)
{
guint32 cur_char = 0,
delim = 0;
CRInputPos init_pos;
enum CRStatus status = CR_OK;
- GString *str = NULL;
+ CRString *str = NULL;
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);
-
READ_NEXT_CHAR (a_this, &cur_char);
if (cur_char == '"')
@@ -680,9 +702,11 @@ cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str)
status = CR_PARSING_ERROR;
goto error;
}
-
- str = g_string_new (NULL);
-
+ str = cr_string_new ();
+ if (str) {
+ cr_tknzr_get_parsing_location
+ (a_this, &str->location) ;
+ }
for (;;) {
guchar next_chars[2] = { 0 };
@@ -695,16 +719,18 @@ cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str)
guint32 esc_code = 0;
if (next_chars[1] == '\'' || next_chars[1] == '"') {
- g_string_append_unichar (str, next_chars[1]);
+ g_string_append_unichar (str->stryng,
+ next_chars[1]);
SKIP_BYTES (a_this, 2);
status = CR_OK;
} else {
status = cr_tknzr_parse_escape
- (a_this, &esc_code);
+ (a_this, &esc_code, NULL);
if (status == CR_OK) {
g_string_append_unichar
- (str, esc_code);
+ (str->stryng,
+ esc_code);
}
}
@@ -717,20 +743,21 @@ cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str)
status = cr_tknzr_parse_nl
(a_this, &tmp_char_ptr1,
- &tmp_char_ptr2);
+ &tmp_char_ptr2, NULL);
}
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);
+ g_string_append_unichar (str->stryng,
+ 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);
+ g_string_append_unichar (str->stryng, cur_char);
} else if (next_chars[0] == delim) {
READ_NEXT_CHAR (a_this, &cur_char);
break;
@@ -745,22 +772,22 @@ cr_tknzr_parse_string (CRTknzr * a_this, GString ** a_str)
*a_str = str;
str = NULL;
} else {
- *a_str = g_string_append_len (*a_str,
- str->str, str->len);
- g_string_free (str, TRUE);
+ (*a_str)->stryng = g_string_append_len
+ ((*a_str)->stryng,
+ str->stryng->str,
+ str->stryng->len);
+ cr_string_destroy (str);
}
return CR_OK;
}
- error:
+ error:
if (str) {
- g_string_free (str, TRUE);
+ cr_string_destroy (str) ;
str = NULL;
}
-
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return status;
}
@@ -778,7 +805,9 @@ 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,
+ CRParsingLocation *a_location)
{
CRInputPos init_pos;
enum CRStatus status = CR_OK;
@@ -794,7 +823,8 @@ cr_tknzr_parse_nmstart (CRTknzr * a_this, guint32 * a_char)
PEEK_NEXT_CHAR (a_this, &next_char);
if (next_char == '\\') {
- status = cr_tknzr_parse_escape (a_this, a_char);
+ status = cr_tknzr_parse_escape (a_this, a_char,
+ a_location);
if (status != CR_OK)
goto error;
@@ -804,6 +834,10 @@ cr_tknzr_parse_nmstart (CRTknzr * a_this, guint32 * a_char)
|| ((next_char >= 'A') && (next_char <= 'Z'))
) {
READ_NEXT_CHAR (a_this, &cur_char);
+ if (a_location) {
+ cr_tknzr_get_parsing_location (a_this,
+ a_location) ;
+ }
*a_char = cur_char;
status = CR_OK;
} else {
@@ -839,7 +873,8 @@ 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,
+ CRParsingLocation *a_location)
{
guint32 cur_char = 0,
next_char = 0;
@@ -851,13 +886,14 @@ cr_tknzr_parse_nmchar (CRTknzr * a_this, guint32 * a_char)
RECORD_INITIAL_POS (a_this, &init_pos);
- status = cr_input_peek_char (PRIVATE (a_this)->input, &next_char);
-
+ status = cr_input_peek_char (PRIVATE (a_this)->input,
+ &next_char) ;
if (status != CR_OK)
goto error;
if (next_char == '\\') {
- status = cr_tknzr_parse_escape (a_this, a_char);
+ status = cr_tknzr_parse_escape (a_this, a_char,
+ a_location);
if (status != CR_OK)
goto error;
@@ -872,17 +908,18 @@ cr_tknzr_parse_nmchar (CRTknzr * a_this, guint32 * a_char)
READ_NEXT_CHAR (a_this, &cur_char);
*a_char = cur_char;
status = CR_OK;
+ if (a_location) {
+ cr_tknzr_get_parsing_location
+ (a_this, a_location) ;
+ }
} else {
status = CR_PARSING_ERROR;
goto error;
}
-
return CR_OK;
- error:
-
+ error:
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return status;
}
@@ -895,7 +932,7 @@ cr_tknzr_parse_nmchar (CRTknzr * a_this, guint32 * a_char)
*@param a_this the currens instance of #CRTknzr.
*
*@param a_str a pointer to parsed ident. If *a_str is NULL,
- *this function allocates a new instance of GString. If not,
+ *this function allocates a new instance of CRString. If not,
*the function just appends the parsed string to the one passed.
*In both cases it is up to the caller to free *a_str.
*
@@ -903,12 +940,13 @@ 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, CRString ** a_str)
{
guint32 tmp_char = 0;
- GString *stringue = NULL ;
+ CRString *stringue = NULL ;
CRInputPos init_pos;
enum CRStatus status = CR_OK;
+ gboolean location_is_set = FALSE ;
g_return_val_if_fail (a_this && PRIVATE (a_this)
&& PRIVATE (a_this)->input
@@ -916,34 +954,48 @@ cr_tknzr_parse_ident (CRTknzr * a_this, GString ** a_str)
RECORD_INITIAL_POS (a_this, &init_pos);
PEEK_NEXT_CHAR (a_this, &tmp_char) ;
- stringue = g_string_new (NULL) ;
- g_return_val_if_fail (stringue, CR_OUT_OF_MEMORY_ERROR) ;
+ stringue = cr_string_new () ;
+ g_return_val_if_fail (stringue,
+ CR_OUT_OF_MEMORY_ERROR) ;
if (tmp_char == '-') {
READ_NEXT_CHAR (a_this, &tmp_char) ;
- g_string_append_unichar (stringue, tmp_char) ;
+ cr_tknzr_get_parsing_location
+ (a_this, &stringue->location) ;
+ location_is_set = TRUE ;
+ g_string_append_unichar (stringue->stryng,
+ tmp_char) ;
}
- status = cr_tknzr_parse_nmstart (a_this, &tmp_char);
+ status = cr_tknzr_parse_nmstart (a_this, &tmp_char, NULL);
if (status != CR_OK) {
status = CR_PARSING_ERROR;
goto end ;
}
- g_string_append_unichar (stringue, tmp_char);
+ if (location_is_set == FALSE) {
+ cr_tknzr_get_parsing_location
+ (a_this, &stringue->location) ;
+ location_is_set = TRUE ;
+ }
+ g_string_append_unichar (stringue->stryng, tmp_char);
for (;;) {
- status = cr_tknzr_parse_nmchar (a_this, &tmp_char);
+ status = cr_tknzr_parse_nmchar (a_this,
+ &tmp_char,
+ NULL);
if (status != CR_OK) {
status = CR_OK ;
break;
}
- g_string_append_unichar (stringue, tmp_char);
+ g_string_append_unichar (stringue->stryng, tmp_char);
}
if (status == CR_OK) {
if (!*a_str) {
*a_str = stringue ;
} else {
- g_string_append_len (*a_str, stringue->str, stringue->len) ;
- g_string_free (stringue, TRUE) ;
+ g_string_append_len ((*a_str)->stryng,
+ stringue->stryng->str,
+ stringue->stryng->len) ;
+ cr_string_destroy (stringue) ;
}
stringue = NULL ;
}
@@ -951,7 +1003,7 @@ cr_tknzr_parse_ident (CRTknzr * a_this, GString ** a_str)
error:
end:
if (stringue) {
- g_string_free (stringue, TRUE) ;
+ cr_string_destroy (stringue) ;
stringue = NULL ;
}
return status ;
@@ -966,51 +1018,59 @@ cr_tknzr_parse_ident (CRTknzr * a_this, GString ** a_str)
*
*@param a_str out parameter. A pointer to the successfully parsed
*name. If *a_str is set to NULL, this function allocates a new instance
- *of GString. If not, it just appends the parsed name to the passed *a_str.
+ *of CRString. If not, it just appends the parsed name to the passed *a_str.
*In both cases, it is up to the caller to free *a_str.
*
*@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,
+ CRString ** a_str)
{
guint32 tmp_char = 0;
CRInputPos init_pos;
enum CRStatus status = CR_OK;
- gboolean str_needs_free = FALSE;
+ gboolean str_needs_free = FALSE,
+ is_first_nmchar=TRUE ;
glong i = 0;
+ CRParsingLocation loc = {0} ;
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);
if (*a_str == NULL) {
- *a_str = g_string_new (NULL);
+ *a_str = cr_string_new ();
str_needs_free = TRUE;
}
-
for (i = 0;; i++) {
- status = cr_tknzr_parse_nmchar (a_this, &tmp_char);
-
+ if (is_first_nmchar == TRUE) {
+ status = cr_tknzr_parse_nmchar
+ (a_this, &tmp_char,
+ &loc) ;
+ is_first_nmchar = FALSE ;
+ } else {
+ status = cr_tknzr_parse_nmchar
+ (a_this, &tmp_char, NULL) ;
+ }
if (status != CR_OK)
- break;
-
- g_string_append_unichar (*a_str, tmp_char);
+ break;
+ g_string_append_unichar ((*a_str)->stryng,
+ tmp_char);
}
-
if (i > 0) {
+ cr_parsing_location_copy
+ (&(*a_str)->location, &loc) ;
return CR_OK;
}
-
if (str_needs_free == TRUE && *a_str) {
- g_string_free (*a_str, TRUE);
+ cr_string_destroy (*a_str);
*a_str = NULL;
}
-
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return CR_PARSING_ERROR;
}
@@ -1019,46 +1079,44 @@ 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, CRString ** a_str)
{
guint32 cur_char = 0;
CRInputPos init_pos;
enum CRStatus status = CR_OK;
gboolean str_needs_free = FALSE;
+ CRParsingLocation loc = {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);
RECORD_INITIAL_POS (a_this, &init_pos);
READ_NEXT_CHAR (a_this, &cur_char);
-
if (cur_char != '#') {
status = CR_PARSING_ERROR;
goto error;
}
-
if (*a_str == NULL) {
- *a_str = g_string_new (NULL);
+ *a_str = cr_string_new ();
str_needs_free = TRUE;
}
-
+ cr_tknzr_get_parsing_location (a_this,
+ &loc) ;
status = cr_tknzr_parse_name (a_this, a_str);
-
+ cr_parsing_location_copy (&(*a_str)->location, &loc) ;
if (status != CR_OK) {
goto error;
}
-
return CR_OK;
- error:
-
+ error:
if (str_needs_free == TRUE && *a_str) {
- g_string_free (*a_str, TRUE);
+ cr_string_destroy (*a_str);
*a_str = NULL;
}
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return status;
}
@@ -1072,16 +1130,21 @@ 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,
+ CRString ** 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;
+ CRString *str = NULL;
+ CRParsingLocation location = {0} ;
- 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
+ && a_str,
+ CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
@@ -1094,22 +1157,24 @@ cr_tknzr_parse_uri (CRTknzr * a_this, GString ** a_str)
status = CR_PARSING_ERROR;
goto error;
}
-
- SKIP_CHARS (a_this, 4);
-
+ /*
+ *Here, we want to skip 4 bytes ('u''r''l''(').
+ *But we also need to keep track of the parsing location
+ *of the 'u'. So, we skip 1 byte, we record the parsing
+ *location, then we skip the 3 remaining bytes.
+ */
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this, &location) ;
+ SKIP_CHARS (a_this, 3);
cr_tknzr_try_to_skip_spaces (a_this);
-
status = cr_tknzr_parse_string (a_this, a_str);
if (status == CR_OK) {
guint32 next_char = 0;
-
- status = cr_tknzr_parse_w (a_this, &tmp_ptr1, &tmp_ptr2);
-
+ status = cr_tknzr_parse_w (a_this, &tmp_ptr1,
+ &tmp_ptr2, NULL);
cr_tknzr_try_to_skip_spaces (a_this);
-
PEEK_NEXT_CHAR (a_this, &next_char);
-
if (next_char == ')') {
READ_NEXT_CHAR (a_this, &cur_char);
status = CR_OK;
@@ -1117,41 +1182,34 @@ cr_tknzr_parse_uri (CRTknzr * a_this, GString ** a_str)
status = CR_PARSING_ERROR;
}
}
-
if (status != CR_OK) {
- str = g_string_new (NULL);
-
+ str = cr_string_new ();
for (;;) {
guint32 next_char = 0;
-
PEEK_NEXT_CHAR (a_this, &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);
+ g_string_append_unichar
+ (str->stryng, cur_char);
status = CR_OK;
} else {
guint32 esc_code = 0;
-
status = cr_tknzr_parse_escape
- (a_this, &esc_code);
-
+ (a_this, &esc_code, NULL);
if (status == CR_OK) {
g_string_append_unichar
- (str, esc_code);
+ (str->stryng,
+ esc_code);
} else {
status = CR_OK;
break;
}
}
}
-
cr_tknzr_try_to_skip_spaces (a_this);
-
READ_NEXT_CHAR (a_this, &cur_char);
-
if (cur_char == ')') {
status = CR_OK;
} else {
@@ -1163,24 +1221,25 @@ cr_tknzr_parse_uri (CRTknzr * a_this, GString ** a_str)
*a_str = str;
str = NULL;
} else {
- g_string_append_len (*a_str,
- str->str, str->len);
- g_string_free (str, TRUE);
+ g_string_append_len
+ ((*a_str)->stryng,
+ str->stryng->str,
+ str->stryng->len);
+ cr_parsing_location_copy
+ (&(*a_str)->location,
+ &str->location) ;
+ cr_string_destroy (str);
}
}
}
- return CR_OK;
-
- error:
-
+ return CR_OK ;
+ error:
if (str) {
- g_string_free (str, TRUE);
+ cr_string_destroy (str);
str = NULL;
}
-
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return status;
}
@@ -1204,6 +1263,7 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb)
blue = 0,
i = 0;
gboolean is_percentage = FALSE;
+ CRParsingLocation location = {0} ;
g_return_val_if_fail (a_this && PRIVATE (a_this), CR_BAD_PARAM_ERROR);
@@ -1216,52 +1276,43 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb)
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);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this, &location) ;
+ SKIP_CHARS (a_this, 2);
} else {
status = CR_PARSING_ERROR;
goto error;
}
-
READ_NEXT_BYTE (a_this, &cur_byte);
-
ENSURE_PARSING_COND (cur_byte == '(');
cr_tknzr_try_to_skip_spaces (a_this);
-
status = cr_tknzr_parse_num (a_this, &num);
-
ENSURE_PARSING_COND ((status == CR_OK) && (num != NULL));
red = num->val;
-
cr_num_destroy (num);
num = NULL;
PEEK_BYTE (a_this, 1, &next_bytes[0]);
-
if (next_bytes[0] == '%') {
SKIP_CHARS (a_this, 1);
is_percentage = TRUE;
}
-
cr_tknzr_try_to_skip_spaces (a_this);
for (i = 0; i < 2; i++) {
READ_NEXT_BYTE (a_this, &cur_byte);
-
ENSURE_PARSING_COND (cur_byte == ',');
cr_tknzr_try_to_skip_spaces (a_this);
-
status = cr_tknzr_parse_num (a_this, &num);
-
ENSURE_PARSING_COND ((status == CR_OK) && (num != NULL));
PEEK_BYTE (a_this, 1, &next_bytes[0]);
-
if (next_bytes[0] == '%') {
SKIP_CHARS (a_this, 1);
- is_percentage = TRUE;
+ is_percentage = 1;
}
if (i == 0) {
@@ -1274,12 +1325,10 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb)
cr_num_destroy (num);
num = NULL;
}
-
cr_tknzr_try_to_skip_spaces (a_this);
}
READ_NEXT_BYTE (a_this, &cur_byte);
-
if (*a_rgb == NULL) {
*a_rgb = cr_rgb_new_with_vals (red, green, blue,
is_percentage);
@@ -1299,18 +1348,21 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb)
}
if (status == CR_OK) {
+ if (a_rgb && *a_rgb) {
+ cr_parsing_location_copy
+ (&(*a_rgb)->location,
+ &location) ;
+ }
return CR_OK;
}
- error:
-
+ error:
if (num) {
cr_num_destroy (num);
num = NULL;
}
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return CR_OK;
}
@@ -1322,7 +1374,7 @@ cr_tknzr_parse_rgb (CRTknzr * a_this, CRRgb ** a_rgb)
*#CRTknzr.
*
*@param a_str out parameter. The parsed atkeyword. If *a_str is
- *set to NULL this function allocates a new instance of GString and
+ *set to NULL this function allocates a new instance of CRString and
*sets it to the parsed atkeyword. If not, this function just appends
*the parsed atkeyword to the end of *a_str. In both cases it is up to
*the caller to free *a_str.
@@ -1330,7 +1382,8 @@ 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,
+ CRString ** a_str)
{
guint32 cur_char = 0;
CRInputPos init_pos;
@@ -1351,46 +1404,43 @@ cr_tknzr_parse_atkeyword (CRTknzr * a_this, GString ** a_str)
}
if (*a_str == NULL) {
- *a_str = g_string_new (NULL);
+ *a_str = cr_string_new ();
str_needs_free = TRUE;
}
-
status = cr_tknzr_parse_ident (a_this, a_str);
-
if (status != CR_OK) {
goto error;
}
-
return CR_OK;
-
- error:
+ error:
if (str_needs_free == TRUE && *a_str) {
- g_string_free (*a_str, TRUE);
+ cr_string_destroy (*a_str);
*a_str = NULL;
}
-
cr_tknzr_set_cur_pos (a_this, &init_pos);
-
return status;
}
static enum CRStatus
-cr_tknzr_parse_important (CRTknzr * a_this)
+cr_tknzr_parse_important (CRTknzr * a_this,
+ CRParsingLocation *a_location)
{
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);
+ && PRIVATE (a_this)->input,
+ CR_BAD_PARAM_ERROR);
RECORD_INITIAL_POS (a_this, &init_pos);
-
READ_NEXT_CHAR (a_this, &cur_char);
-
ENSURE_PARSING_COND (cur_char == '!');
-
+ if (a_location) {
+ cr_tknzr_get_parsing_location (a_this,
+ a_location) ;
+ }
cr_tknzr_try_to_skip_spaces (a_this);
if (BYTE (PRIVATE (a_this)->input, 1, NULL) == 'i'
@@ -1403,12 +1453,16 @@ cr_tknzr_parse_important (CRTknzr * a_this)
&& BYTE (PRIVATE (a_this)->input, 8, NULL) == 'n'
&& BYTE (PRIVATE (a_this)->input, 9, NULL) == 't') {
SKIP_BYTES (a_this, 9);
+ if (a_location) {
+ cr_tknzr_get_parsing_location (a_this,
+ a_location) ;
+ }
return CR_OK;
} else {
status = CR_PARSING_ERROR;
}
- error:
+ error:
cr_tknzr_set_cur_pos (a_this, &init_pos);
return status;
@@ -1423,7 +1477,8 @@ 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;
@@ -1434,14 +1489,14 @@ cr_tknzr_parse_num (CRTknzr * a_this, CRNum ** a_num)
dec_part = 0,
next_char = 0;
CRInputPos init_pos;
+ CRParsingLocation location = {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);
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');
@@ -1452,6 +1507,7 @@ cr_tknzr_parse_num (CRTknzr * a_this, CRNum ** a_num)
status = CR_PARSING_ERROR;
goto error;
}
+ cr_tknzr_get_parsing_location (a_this, &location) ;
for (;;) {
status = cr_tknzr_peek_char (a_this, &next_char);
@@ -1506,11 +1562,12 @@ cr_tknzr_parse_num (CRTknzr * a_this, CRNum ** a_num)
(*a_num)->val = val;
(*a_num)->type = val_type;
}
-
+ cr_parsing_location_copy (&(*a_num)->location,
+ &location) ;
return CR_OK;
}
- error:
+ error:
cr_tknzr_set_cur_pos (a_this, &init_pos);
@@ -1547,12 +1604,9 @@ cr_tknzr_new (CRInput * a_input)
return NULL;
}
-
memset (result->priv, 0, sizeof (CRTknzrPriv));
-
if (a_input)
cr_tknzr_set_input (result, a_input);
-
return result;
}
@@ -1575,7 +1629,8 @@ cr_tknzr_new_from_buf (guchar * a_buf, gulong a_len,
}
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;
@@ -1795,6 +1850,19 @@ cr_tknzr_get_cur_pos (CRTknzr * a_this, CRInputPos * a_pos)
return cr_input_get_cur_pos (PRIVATE (a_this)->input, a_pos);
}
+enum CRStatus
+cr_tknzr_get_parsing_location (CRTknzr *a_this,
+ CRParsingLocation *a_loc)
+{
+ g_return_val_if_fail (a_this
+ && PRIVATE (a_this)
+ && a_loc,
+ CR_BAD_PARAM_ERROR) ;
+
+ return cr_input_get_parsing_location
+ (PRIVATE (a_this)->input, a_loc) ;
+}
+
enum CRStatus
cr_tknzr_get_cur_byte_addr (CRTknzr * a_this, guchar ** a_addr)
{
@@ -1890,12 +1958,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
guchar next_bytes[4] = { 0 };
gboolean reached_eof = FALSE;
CRInput *input = NULL;
- GString *str = NULL;
+ CRString *str = NULL;
CRRgb *rgb = NULL;
+ CRParsingLocation location = {0} ;
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;
@@ -1932,9 +2002,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
&& BYTE (input, 8, NULL) == 'a'
&& BYTE (input, 9, NULL) == 'c'
&& BYTE (input, 10, NULL) == 'e') {
- SKIP_CHARS (a_this, 10);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location
+ (a_this, &location) ;
+ SKIP_CHARS (a_this, 9);
status = cr_token_set_font_face_sym (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
@@ -1945,9 +2020,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
&& BYTE (input, 6, NULL) == 's'
&& BYTE (input, 7, NULL) == 'e'
&& BYTE (input, 8, NULL) == 't') {
- SKIP_CHARS (a_this, 8);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location
+ (a_this, &location) ;
+ SKIP_CHARS (a_this, 7);
status = cr_token_set_charset_sym (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
@@ -1957,9 +2037,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
&& BYTE (input, 5, NULL) == 'o'
&& BYTE (input, 6, NULL) == 'r'
&& BYTE (input, 7, NULL) == 't') {
- SKIP_CHARS (a_this, 7);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location
+ (a_this, &location) ;
+ SKIP_CHARS (a_this, 6);
status = cr_token_set_import_sym (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
@@ -1968,9 +2053,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
&& BYTE (input, 4, NULL) == 'd'
&& BYTE (input, 5, NULL) == 'i'
&& BYTE (input, 6, NULL) == 'a') {
- SKIP_CHARS (a_this, 6);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
+ SKIP_CHARS (a_this, 5);
status = cr_token_set_media_sym (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
@@ -1978,16 +2068,24 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
&& BYTE (input, 3, NULL) == 'a'
&& BYTE (input, 4, NULL) == 'g'
&& BYTE (input, 5, NULL) == 'e') {
- SKIP_CHARS (a_this, 5);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
+ SKIP_CHARS (a_this, 4);
status = cr_token_set_page_sym (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
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);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
goto done;
}
}
@@ -1998,12 +2096,16 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
if (BYTE (input, 2, NULL) == 'r'
&& BYTE (input, 3, NULL) == 'l'
&& BYTE (input, 4, NULL) == '(') {
- GString *str = NULL;
+ CRString *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);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
goto done;
}
} else {
@@ -2011,6 +2113,10 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
if (status == CR_OK && str) {
status = cr_token_set_ident (token, str);
CHECK_PARSING_STATUS (status, TRUE);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
goto done;
}
}
@@ -2024,6 +2130,10 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
if (status == CR_OK && rgb) {
status = cr_token_set_rgb (token, rgb);
CHECK_PARSING_STATUS (status, TRUE);
+ if (rgb) {
+ cr_parsing_location_copy (&token->location,
+ &rgb->location) ;
+ }
rgb = NULL;
goto done;
}
@@ -2033,6 +2143,10 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
if (status == CR_OK) {
status = cr_token_set_ident (token, str);
CHECK_PARSING_STATUS (status, TRUE);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
str = NULL;
goto done;
}
@@ -2042,9 +2156,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
case '<':
if (BYTE (input, 2, NULL) == '-'
&& BYTE (input, 3, NULL) == '-') {
- SKIP_CHARS (a_this, 3);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
+ SKIP_CHARS (a_this, 2);
status = cr_token_set_cdo (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
break;
@@ -2052,9 +2171,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
case '-':
if (BYTE (input, 2, NULL) == '-'
&& BYTE (input, 3, NULL) == '>') {
- SKIP_CHARS (a_this, 3);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
+ SKIP_CHARS (a_this, 2);
status = cr_token_set_cdc (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
} else {
status = cr_tknzr_parse_ident
@@ -2062,24 +2186,39 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
if (status == CR_OK) {
cr_token_set_ident
(token, str);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
goto done;
}
}
break;
+
case '~':
if (BYTE (input, 2, NULL) == '=') {
- SKIP_CHARS (a_this, 2);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
+ SKIP_CHARS (a_this, 1);
status = cr_token_set_includes (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
break;
case '|':
if (BYTE (input, 2, NULL) == '=') {
- SKIP_CHARS (a_this, 2);
+ SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
+ SKIP_CHARS (a_this, 1);
status = cr_token_set_dashmatch (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
break;
@@ -2092,6 +2231,10 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
status = cr_token_set_comment (token, str);
str = NULL;
CHECK_PARSING_STATUS (status, TRUE);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
goto done;
}
}
@@ -2099,44 +2242,72 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
case ';':
SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_semicolon (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
case '{':
SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_cbo (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
goto done;
case '}':
SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_cbc (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
case '(':
SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_po (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
case ')':
SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_pc (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
case '[':
SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_bo (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
case ']':
SKIP_CHARS (a_this, 1);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_bc (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
case ' ':
@@ -2148,10 +2319,13 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
guchar *start = NULL,
*end = NULL;
- status = cr_tknzr_parse_w (a_this, &start, &end);
+ status = cr_tknzr_parse_w (a_this, &start,
+ &end, &location);
if (status == CR_OK) {
status = cr_token_set_s (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
goto done;
}
}
@@ -2163,6 +2337,10 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
if (status == CR_OK && str) {
status = cr_token_set_hash (token, str);
CHECK_PARSING_STATUS (status, TRUE);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
str = NULL;
goto done;
}
@@ -2175,16 +2353,22 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
if (status == CR_OK && str) {
status = cr_token_set_string (token, str);
CHECK_PARSING_STATUS (status, TRUE);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
str = NULL;
goto done;
}
break;
case '!':
- status = cr_tknzr_parse_important (a_this);
+ status = cr_tknzr_parse_important (a_this, &location);
if (status == CR_OK) {
status = cr_token_set_important_sym (token);
CHECK_PARSING_STATUS (status, TRUE);
+ cr_parsing_location_copy (&token->location,
+ &location) ;
goto done;
}
break;
@@ -2340,13 +2524,17 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
status = cr_token_set_number
(token, num);
num = NULL;
- CHECK_PARSING_STATUS (status,
- TRUE);
+ CHECK_PARSING_STATUS (status, CR_OK);
str = NULL;
}
}
-
- goto done;
+ if (token && token->u.num) {
+ cr_parsing_location_copy (&token->location,
+ &token->u.num->location) ;
+ } else {
+ status = CR_ERROR ;
+ }
+ goto done ;
}
}
break;
@@ -2374,17 +2562,25 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
/*ownership is transfered
*to token by cr_token_set_function.
*/
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
str = NULL;
} else {
status = cr_token_set_ident (token,
str);
CHECK_PARSING_STATUS (status, TRUE);
+ if (str) {
+ cr_parsing_location_copy (&token->location,
+ &str->location) ;
+ }
str = NULL;
}
goto done;
} else {
if (str) {
- g_string_free (str, TRUE);
+ cr_string_destroy (str);
str = NULL;
}
}
@@ -2393,10 +2589,13 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
}
READ_NEXT_CHAR (a_this, &next_char);
+ cr_tknzr_get_parsing_location (a_this,
+ &location) ;
status = cr_token_set_delim (token, next_char);
CHECK_PARSING_STATUS (status, TRUE);
-
- done:
+ cr_parsing_location_copy (&token->location,
+ &location) ;
+ done:
if (status == CR_OK && token) {
*a_tk = token;
@@ -2408,14 +2607,14 @@ cr_tknzr_get_next_token (CRTknzr * a_this, CRToken ** a_tk)
return CR_OK;
}
- error:
+ error:
if (token) {
cr_token_destroy (token);
token = NULL;
}
if (str) {
- g_string_free (str, TRUE);
+ cr_string_destroy (str);
str = NULL;
}
cr_tknzr_set_cur_pos (a_this, &init_pos);
@@ -2465,7 +2664,7 @@ cr_tknzr_parse_token (CRTknzr * a_this, enum CRTokenType a_type,
case FUNCTION_TK:
case COMMENT_TK:
case URI_TK:
- *((GString **) a_res) = token->u.str;
+ *((CRString **) a_res) = token->u.str;
token->u.str = NULL;
status = CR_OK;
break;
@@ -2497,7 +2696,7 @@ cr_tknzr_parse_token (CRTknzr * a_this, enum CRTokenType a_type,
goto error;
}
- *((GString **) a_extra_res) = token->dimen;
+ *((CRString **) a_extra_res) = token->dimen;
token->u.num = NULL;
token->dimen = NULL;
status = CR_OK;
diff --git a/src/cr-tknzr.h b/src/cr-tknzr.h
index 4e3d849..13985b3 100644
--- a/src/cr-tknzr.h
+++ b/src/cr-tknzr.h
@@ -17,13 +17,10 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* See COPYRIGHTS file for coypyright information.
*/
-/*
- *$Id$
- */
-
/**
*@file
*The declaration of the #CRTknzr (tokenizer)
@@ -55,82 +52,63 @@ struct _CRTknzr
CRTknzrPriv *priv ;
} ;
-CRTknzr *
-cr_tknzr_new (CRInput *a_input) ;
+CRTknzr * cr_tknzr_new (CRInput *a_input) ;
-CRTknzr *
-cr_tknzr_new_from_uri (const guchar *a_file_uri,
- enum CREncoding a_enc) ;
+CRTknzr * cr_tknzr_new_from_uri (const guchar *a_file_uri,
+ enum CREncoding a_enc) ;
-CRTknzr *
-cr_tknzr_new_from_buf (guchar *a_buf, gulong a_len,
- enum CREncoding a_enc,
- gboolean a_free_at_destroy) ;
+CRTknzr * cr_tknzr_new_from_buf (guchar *a_buf, gulong a_len,
+ enum CREncoding a_enc,
+ gboolean a_free_at_destroy) ;
-gboolean
-cr_tknzr_unref (CRTknzr *a_this) ;
+gboolean cr_tknzr_unref (CRTknzr *a_this) ;
-void
-cr_tknzr_ref (CRTknzr *a_this) ;
+void cr_tknzr_ref (CRTknzr *a_this) ;
-enum CRStatus
-cr_tknzr_read_byte (CRTknzr *a_this, guchar *a_byte) ;
+enum CRStatus cr_tknzr_read_byte (CRTknzr *a_this, guchar *a_byte) ;
-enum CRStatus
-cr_tknzr_read_char (CRTknzr *a_this, guint32 *a_char);
+enum CRStatus cr_tknzr_read_char (CRTknzr *a_this, guint32 *a_char);
+
+enum CRStatus cr_tknzr_peek_char (CRTknzr *a_this, guint32 *a_char) ;
-enum CRStatus
-cr_tknzr_peek_char (CRTknzr *a_this, guint32 *a_char) ;
+enum CRStatus cr_tknzr_peek_byte (CRTknzr *a_this, gulong a_offset,
+ guchar *a_byte) ;
-enum CRStatus
-cr_tknzr_peek_byte (CRTknzr *a_this, gulong a_offset,
- guchar *a_byte) ;
+guchar cr_tknzr_peek_byte2 (CRTknzr *a_this, gulong a_offset,
+ gboolean *a_eof) ;
-guchar
-cr_tknzr_peek_byte2 (CRTknzr *a_this, gulong a_offset,
- gboolean *a_eof) ;
+enum CRStatus cr_tknzr_set_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) ;
-enum CRStatus
-cr_tknzr_set_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) ;
+glong cr_tknzr_get_nb_bytes_left (CRTknzr *a_this) ;
-glong
-cr_tknzr_get_nb_bytes_left (CRTknzr *a_this) ;
+enum CRStatus cr_tknzr_get_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) ;
-enum CRStatus
-cr_tknzr_get_cur_pos (CRTknzr *a_this, CRInputPos *a_pos) ;
+enum CRStatus cr_tknzr_get_parsing_location (CRTknzr *a_this,
+ CRParsingLocation *a_loc) ;
-enum CRStatus
-cr_tknzr_seek_index (CRTknzr *a_this,
- enum CRSeekPos a_origin,
- gint a_pos) ;
+enum CRStatus cr_tknzr_seek_index (CRTknzr *a_this,
+ enum CRSeekPos a_origin,
+ gint a_pos) ;
-enum CRStatus
-cr_tknzr_get_cur_byte_addr (CRTknzr *a_this, guchar **a_addr) ;
+enum CRStatus cr_tknzr_get_cur_byte_addr (CRTknzr *a_this, guchar **a_addr) ;
-enum CRStatus
-cr_tknzr_consume_chars (CRTknzr *a_this, guint32 a_char,
- glong *a_nb_char) ;
+enum CRStatus cr_tknzr_consume_chars (CRTknzr *a_this, guint32 a_char,
+ glong *a_nb_char) ;
-enum CRStatus
-cr_tknzr_get_next_token (CRTknzr *a_this, CRToken ** a_tk) ;
+enum CRStatus cr_tknzr_get_next_token (CRTknzr *a_this, CRToken ** a_tk) ;
-enum CRStatus
-cr_tknzr_unget_token (CRTknzr *a_this, CRToken *a_token) ;
+enum CRStatus cr_tknzr_unget_token (CRTknzr *a_this, CRToken *a_token) ;
-enum CRStatus
-cr_tknzr_parse_token (CRTknzr *a_this, enum CRTokenType a_type,
- enum CRTokenExtraType a_et, gpointer a_res,
- gpointer a_extra_res) ;
-enum CRStatus
-cr_tknzr_set_input (CRTknzr *a_this, CRInput *a_input) ;
+enum CRStatus cr_tknzr_parse_token (CRTknzr *a_this, enum CRTokenType a_type,
+ enum CRTokenExtraType a_et, gpointer a_res,
+ gpointer a_extra_res) ;
+enum CRStatus cr_tknzr_set_input (CRTknzr *a_this, CRInput *a_input) ;
-enum CRStatus
-cr_tknzr_get_input (CRTknzr *a_this, CRInput **a_input) ;
+enum CRStatus cr_tknzr_get_input (CRTknzr *a_this, CRInput **a_input) ;
-void
-cr_tknzr_destroy (CRTknzr *a_this) ;
+void cr_tknzr_destroy (CRTknzr *a_this) ;
G_END_DECLS
diff --git a/src/cr-token.c b/src/cr-token.c
index 7eaa218..d2bb492 100644
--- a/src/cr-token.c
+++ b/src/cr-token.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * see COPYRIGHTS file for copyright information.
*/
/**
@@ -32,6 +29,10 @@
#include <string.h>
#include "cr-token.h"
+/*
+ *TODO: write a CRToken::to_string() method.
+ */
+
/**
*Frees the attributes of the current instance
*of #CRtoken.
@@ -70,7 +71,7 @@ cr_token_clear (CRToken * a_this)
case COMMENT_TK:
case ATKEYWORD_TK:
if (a_this->u.str) {
- g_string_free (a_this->u.str, TRUE);
+ cr_string_destroy (a_this->u.str);
a_this->u.str = NULL;
}
break;
@@ -98,7 +99,7 @@ cr_token_clear (CRToken * a_this)
}
if (a_this->dimen) {
- g_string_free (a_this->dimen, TRUE);
+ cr_string_destroy (a_this->dimen);
a_this->dimen = NULL;
}
@@ -241,21 +242,18 @@ cr_token_set_dashmatch (CRToken * a_this)
}
enum CRStatus
-cr_token_set_comment (CRToken * a_this, GString * a_str)
+cr_token_set_comment (CRToken * a_this, CRString * a_str)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
cr_token_clear (a_this);
-
a_this->type = COMMENT_TK;
-
- a_this->u.str = a_str;
-
+ a_this->u.str = a_str ;
return CR_OK;
}
enum CRStatus
-cr_token_set_string (CRToken * a_this, GString * a_str)
+cr_token_set_string (CRToken * a_this, CRString * a_str)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
@@ -263,49 +261,42 @@ cr_token_set_string (CRToken * a_this, GString * a_str)
a_this->type = STRING_TK;
- a_this->u.str = a_str;
+ a_this->u.str = a_str ;
return CR_OK;
}
enum CRStatus
-cr_token_set_ident (CRToken * a_this, GString * a_ident)
+cr_token_set_ident (CRToken * a_this, CRString * a_ident)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
cr_token_clear (a_this);
-
a_this->type = IDENT_TK;
-
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, CRString * 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);
-
a_this->type = FUNCTION_TK;
-
- a_this->u.str = a_fun_name;
-
+ a_this->u.str = a_fun_name;
return CR_OK;
}
enum CRStatus
-cr_token_set_hash (CRToken * a_this, GString * a_hash)
+cr_token_set_hash (CRToken * a_this, CRString * a_hash)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
cr_token_clear (a_this);
-
a_this->type = HASH_TK;
-
a_this->u.str = a_hash;
return CR_OK;
@@ -317,9 +308,7 @@ cr_token_set_rgb (CRToken * a_this, CRRgb * a_rgb)
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
cr_token_clear (a_this);
-
a_this->type = RGB_TK;
-
a_this->u.rgb = a_rgb;
return CR_OK;
@@ -367,7 +356,6 @@ cr_token_set_font_face_sym (CRToken * a_this)
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
cr_token_clear (a_this);
-
a_this->type = FONT_FACE_SYM_TK;
return CR_OK;
@@ -379,23 +367,19 @@ cr_token_set_charset_sym (CRToken * a_this)
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
cr_token_clear (a_this);
-
a_this->type = CHARSET_SYM_TK;
return CR_OK;
}
enum CRStatus
-cr_token_set_atkeyword (CRToken * a_this, GString * a_atname)
+cr_token_set_atkeyword (CRToken * a_this, CRString * a_atname)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
cr_token_clear (a_this);
-
a_this->type = ATKEYWORD_TK;
-
a_this->u.str = a_atname;
-
return CR_OK;
}
@@ -403,11 +387,8 @@ enum CRStatus
cr_token_set_important_sym (CRToken * a_this)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
-
cr_token_clear (a_this);
-
a_this->type = IMPORTANT_SYM_TK;
-
return CR_OK;
}
@@ -415,13 +396,9 @@ enum CRStatus
cr_token_set_ems (CRToken * a_this, CRNum * a_num)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
-
cr_token_clear (a_this);
-
a_this->type = EMS_TK;
-
a_this->u.num = a_num;
-
return CR_OK;
}
@@ -429,13 +406,9 @@ enum CRStatus
cr_token_set_exs (CRToken * a_this, CRNum * a_num)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
-
cr_token_clear (a_this);
-
a_this->type = EXS_TK;
-
a_this->u.num = a_num;
-
return CR_OK;
}
@@ -448,7 +421,6 @@ cr_token_set_length (CRToken * a_this, CRNum * a_num,
cr_token_clear (a_this);
a_this->type = LENGTH_TK;
-
a_this->extra_type = a_et;
a_this->u.num = a_num;
@@ -501,16 +473,14 @@ cr_token_set_freq (CRToken * a_this, CRNum * a_num,
}
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,
+ CRString * a_dim)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
-
cr_token_clear (a_this);
-
a_this->type = DIMEN_TK;
a_this->u.num = a_num;
a_this->dimen = a_dim;
-
return CR_OK;
}
@@ -537,12 +507,11 @@ cr_token_set_number (CRToken * a_this, CRNum * a_num)
a_this->type = NUMBER_TK;
a_this->u.num = a_num;
-
return CR_OK;
}
enum CRStatus
-cr_token_set_uri (CRToken * a_this, GString * a_uri)
+cr_token_set_uri (CRToken * a_this, CRString * a_uri)
{
g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR);
diff --git a/src/cr-token.h b/src/cr-token.h
index 8eb7624..f1257b7 100644
--- a/src/cr-token.h
+++ b/src/cr-token.h
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji@seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,10 +16,9 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
#ifndef __CR_TOKEN_H__
@@ -31,6 +28,8 @@
#include "cr-input.h"
#include "cr-num.h"
#include "cr-rgb.h"
+#include "cr-string.h"
+#include "cr-parsing-location.h"
G_BEGIN_DECLS
@@ -107,129 +106,95 @@ struct _CRToken
union
{
- GString *str ;
+ CRString *str ;
CRRgb *rgb ;
CRNum *num ;
guint32 unichar ;
} u ;
- GString * dimen ;
+ CRString * dimen ;
+ CRParsingLocation location ;
} ;
-CRToken*
-cr_token_new (void) ;
-
-enum CRStatus
-cr_token_set_s (CRToken *a_this) ;
-
-enum CRStatus
-cr_token_set_cdo (CRToken *a_this) ;
-
-enum CRStatus
-cr_token_set_cdc (CRToken *a_this) ;
-
-enum CRStatus
-cr_token_set_includes (CRToken *a_this) ;
-
-enum CRStatus
-cr_token_set_dashmatch (CRToken *a_this) ;
-
-enum CRStatus
-cr_token_set_comment (CRToken *a_this, GString *a_str) ;
-
-enum CRStatus
-cr_token_set_string (CRToken *a_this, GString *a_str) ;
-
-enum CRStatus
-cr_token_set_ident (CRToken *a_this, GString * a_ident) ;
+CRToken* cr_token_new (void) ;
-enum CRStatus
-cr_token_set_hash (CRToken *a_this, GString *a_hash) ;
-
-enum CRStatus
-cr_token_set_rgb (CRToken *a_this, CRRgb *a_rgb) ;
+enum CRStatus cr_token_set_s (CRToken *a_this) ;
+
+enum CRStatus cr_token_set_cdo (CRToken *a_this) ;
+
+enum CRStatus cr_token_set_cdc (CRToken *a_this) ;
+
+enum CRStatus cr_token_set_includes (CRToken *a_this) ;
+
+enum CRStatus cr_token_set_dashmatch (CRToken *a_this) ;
+
+enum CRStatus cr_token_set_comment (CRToken *a_this, CRString *a_str) ;
+
+enum CRStatus cr_token_set_string (CRToken *a_this, CRString *a_str) ;
+
+enum CRStatus cr_token_set_ident (CRToken *a_this, CRString * a_ident) ;
+
+enum CRStatus cr_token_set_hash (CRToken *a_this, CRString *a_hash) ;
+
+enum CRStatus cr_token_set_rgb (CRToken *a_this, CRRgb *a_rgb) ;
-enum CRStatus
-cr_token_set_import_sym (CRToken *a_this) ;
+enum CRStatus cr_token_set_import_sym (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_page_sym (CRToken *a_this) ;
+enum CRStatus cr_token_set_page_sym (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_media_sym (CRToken *a_this) ;
+enum CRStatus cr_token_set_media_sym (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_font_face_sym (CRToken *a_this) ;
+enum CRStatus cr_token_set_font_face_sym (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_charset_sym (CRToken *a_this) ;
+enum CRStatus cr_token_set_charset_sym (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_atkeyword (CRToken *a_this, GString *a_atname) ;
+enum CRStatus cr_token_set_atkeyword (CRToken *a_this, CRString *a_atname) ;
-enum CRStatus
-cr_token_set_important_sym (CRToken *a_this) ;
+enum CRStatus cr_token_set_important_sym (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_ems (CRToken *a_this, CRNum *a_num) ;
+enum CRStatus cr_token_set_ems (CRToken *a_this, CRNum *a_num) ;
-enum CRStatus
-cr_token_set_exs (CRToken *a_this, CRNum *a_num) ;
+enum CRStatus cr_token_set_exs (CRToken *a_this, CRNum *a_num) ;
-enum CRStatus
-cr_token_set_length (CRToken *a_this, CRNum *a_num,
- enum CRTokenExtraType a_et) ;
+enum CRStatus cr_token_set_length (CRToken *a_this, CRNum *a_num,
+ enum CRTokenExtraType a_et) ;
-enum CRStatus
-cr_token_set_angle (CRToken *a_this, CRNum *a_num,
- enum CRTokenExtraType a_et) ;
+enum CRStatus cr_token_set_angle (CRToken *a_this, CRNum *a_num,
+ enum CRTokenExtraType a_et) ;
-enum CRStatus
-cr_token_set_time (CRToken *a_this, CRNum *a_num,
- enum CRTokenExtraType a_et) ;
+enum CRStatus cr_token_set_time (CRToken *a_this, CRNum *a_num,
+ enum CRTokenExtraType a_et) ;
-enum CRStatus
-cr_token_set_freq (CRToken *a_this, CRNum *a_num,
- enum CRTokenExtraType a_et) ;
-enum CRStatus
-cr_token_set_dimen (CRToken *a_this, CRNum *a_num,
- GString *a_dim) ;
+enum CRStatus cr_token_set_freq (CRToken *a_this, CRNum *a_num,
+ enum CRTokenExtraType a_et) ;
+
+enum CRStatus cr_token_set_dimen (CRToken *a_this, CRNum *a_num,
+ CRString *a_dim) ;
-enum CRStatus
-cr_token_set_percentage (CRToken *a_this, CRNum *a_num) ;
+enum CRStatus cr_token_set_percentage (CRToken *a_this, CRNum *a_num) ;
-enum CRStatus
-cr_token_set_number (CRToken *a_this, CRNum *a_num) ;
+enum CRStatus cr_token_set_number (CRToken *a_this, CRNum *a_num) ;
-enum CRStatus
-cr_token_set_uri (CRToken *a_this, GString *a_uri) ;
+enum CRStatus cr_token_set_uri (CRToken *a_this, CRString *a_uri) ;
-enum CRStatus
-cr_token_set_function (CRToken *a_this, GString *a_fun_name) ;
+enum CRStatus cr_token_set_function (CRToken *a_this,
+ CRString *a_fun_name) ;
-enum CRStatus
-cr_token_set_bc (CRToken *a_this) ;
+enum CRStatus cr_token_set_bc (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_bo (CRToken *a_this) ;
+enum CRStatus cr_token_set_bo (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_po (CRToken *a_this) ;
+enum CRStatus cr_token_set_po (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_pc (CRToken *a_this) ;
+enum CRStatus cr_token_set_pc (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_cbc (CRToken *a_this) ;
+enum CRStatus cr_token_set_cbc (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_cbo (CRToken *a_this) ;
+enum CRStatus cr_token_set_cbo (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_semicolon (CRToken *a_this) ;
+enum CRStatus cr_token_set_semicolon (CRToken *a_this) ;
-enum CRStatus
-cr_token_set_delim (CRToken *a_this, guint32 a_char) ;
+enum CRStatus cr_token_set_delim (CRToken *a_this, guint32 a_char) ;
/*
diff --git a/src/cr-utils.c b/src/cr-utils.c
index daceb9b..f5505c7 100644
--- a/src/cr-utils.c
+++ b/src/cr-utils.c
@@ -3,8 +3,6 @@
/*
* This file is part of The Croco Library
*
- * Copyright (C) 2002-2003 Dodji Seketeli <dodji at seketeli.org>
- *
* This program is free software; you can redistribute it and/or
* modify it under the terms of version 2.1 of the GNU Lesser General Public
* License as published by the Free Software Foundation.
@@ -18,13 +16,13 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
- */
-
-/*
- *$Id$
+ *
+ * Author: Dodji Seketeli
+ * See COPYRIGHTS file for copyright information.
*/
#include "cr-utils.h"
+#include "cr-string.h"
/**
*@file:
@@ -1313,7 +1311,7 @@ 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_utils_dup_glist_of_string (GList * a_list_of_strings)
{
GList *cur = NULL,
*result = NULL;
@@ -1331,3 +1329,27 @@ cr_dup_glist_of_string (GList * a_list_of_strings)
return result;
}
+
+/**
+ *Duplicate a GList where the GList::data is a CRString.
+ *@param a_list_of_strings the list to duplicate
+ *@return the duplicated list, or NULL if something bad
+ *happened.
+ */
+GList *
+cr_utils_dup_glist_of_cr_string (GList * a_list_of_strings)
+{
+ GList *cur = NULL, *result = NULL;
+
+ g_return_val_if_fail (a_list_of_strings, NULL);
+
+ for (cur = a_list_of_strings; cur; cur = cur->next) {
+ CRString *str = NULL;
+
+ str = cr_string_dup ((CRString *) cur->data) ;
+ if (str)
+ result = g_list_append (result, str);
+ }
+
+ return result;
+}
diff --git a/src/cr-utils.h b/src/cr-utils.h
index 64ab093..535e817 100644
--- a/src/cr-utils.h
+++ b/src/cr-utils.h
@@ -17,6 +17,7 @@
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
* USA
*
+ * Author: Dodji Seketeli
* Look at file COPYRIGHTS for copyright information
*/
@@ -24,9 +25,8 @@
#define __CR_DEFS_H__
#include <stdio.h>
-#include "libcroco-config.h"
#include <glib.h>
-
+#include "libcroco-config.h"
G_BEGIN_DECLS
@@ -239,7 +239,10 @@ gdouble
cr_utils_n_to_0_dot_n (glong a_n) ;
GList *
-cr_dup_glist_of_string (GList *a_list) ;
+cr_utils_dup_glist_of_string (GList *a_list) ;
+
+GList *
+cr_utils_dup_glist_of_cr_string (GList * a_list_of_strings) ;
G_END_DECLS