diff options
author | Dodji Seketeli <dodji@gnome.org> | 2004-01-26 22:45:11 +0000 |
---|---|---|
committer | Dodji Seketeli <dodji@src.gnome.org> | 2004-01-26 22:45:11 +0000 |
commit | e308f9a5106738d56a3b0dd01731cc3a92c9dcaf (patch) | |
tree | dc492b578b76eb7bcb00a8d1a0072e5fac883bb2 | |
parent | 88a477f4643dd040e8f0ea5200d2be1541d25dee (diff) | |
download | libcroco-e308f9a5106738d56a3b0dd01731cc3a92c9dcaf.tar.gz |
new convenience function added these new parsing methods.
2004-01-26 Dodji Seketeli <dodji@gnome.org>
* src/cr-cascade.[ch]:
(cr_cascade_ref),(cr_cascade_unref): new convenience function
* src/cr-om-parser.[ch]:
(cr_om_parser_parse_paths_to_cascade),
(cr_om_parser_simply_parse_paths_to_cascade): added these new
parsing methods.
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | src/cr-cascade.c | 35 | ||||
-rw-r--r-- | src/cr-cascade.h | 16 | ||||
-rw-r--r-- | src/cr-om-parser.c | 102 | ||||
-rw-r--r-- | src/cr-om-parser.h | 28 |
5 files changed, 174 insertions, 15 deletions
@@ -1,5 +1,13 @@ 2004-01-26 Dodji Seketeli <dodji@gnome.org> + * src/cr-cascade.[ch]: + (cr_cascade_ref),(cr_cascade_unref): new convenience function + * src/cr-om-parser.[ch]: + (cr_om_parser_parse_paths_to_cascade), + (cr_om_parser_simply_parse_paths_to_cascade): added these new parsing methods. + +2004-01-26 Dodji Seketeli <dodji@gnome.org> + * src/cr-utils.h: added CR_FILE_NOT_FOUND_ERROR to the CRStatus enum. diff --git a/src/cr-cascade.c b/src/cr-cascade.c index 14e9264..e971470 100644 --- a/src/cr-cascade.c +++ b/src/cr-cascade.c @@ -41,6 +41,7 @@ struct _CRCascadePriv *of sheets[ORIGIN_UA] ; */ CRStyleSheet *sheets[3] ; + guint ref_count ; } ; @@ -154,6 +155,40 @@ cr_cascade_set_sheet (CRCascade *a_this, return CR_OK ; } +/** + *Increases the reference counter of the current instance + *of #CRCascade. + *@param a_this the current instance of #CRCascade + * + */ +void +cr_cascade_ref (CRCascade *a_this) +{ + g_return_if_fail (a_this && PRIVATE (a_this)) ; + + PRIVATE (a_this)->ref_count++ ; +} + +/** + *Decrements the reference counter associated + *to this instance of #CRCascade. If the reference + *counter reaches zero, the instance is destroyed + *using cr_cascade_destroy() + *@param a_this the current instance of + *#CRCascade. + */ +void +cr_cascade_unref (CRCascade *a_this) +{ + g_return_if_fail (a_this && PRIVATE (a_this)) ; + + if (PRIVATE (a_this)->ref_count) + PRIVATE (a_this)->ref_count -- ; + if (!PRIVATE (a_this)->ref_count) + { + cr_cascade_destroy (a_this) ; + } +} /** *Destructor of #CRCascade. diff --git a/src/cr-cascade.h b/src/cr-cascade.h index f139721..7432707 100644 --- a/src/cr-cascade.h +++ b/src/cr-cascade.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 @@ -20,6 +18,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 * USA + * */ /* @@ -60,12 +59,13 @@ CRStyleSheet * cr_cascade_get_sheet (CRCascade *a_this, enum CRStyleOrigin a_origin) ; -enum CRStatus -cr_cascade_set_sheet (CRCascade *a_this, - CRStyleSheet *a_sheet, - enum CRStyleOrigin a_origin) ; -void -cr_cascade_destroy (CRCascade *a_this) ; +enum CRStatus cr_cascade_set_sheet (CRCascade *a_this, + CRStyleSheet *a_sheet, + enum CRStyleOrigin a_origin) ; + +void cr_cascade_unref (CRCascade *a_this) ; + +void cr_cascade_destroy (CRCascade *a_this) ; G_END_DECLS diff --git a/src/cr-om-parser.c b/src/cr-om-parser.c index da9cf01..352c3c1 100644 --- a/src/cr-om-parser.c +++ b/src/cr-om-parser.c @@ -1043,7 +1043,7 @@ cr_om_parser_simply_parse_file (const guchar *a_file_path, if (!parser) { cr_utils_trace_info ("Could not allocate om parser") ; - cr_utils_trace_info ("System maybe out of memory") ; + cr_utils_trace_info ("System may be out of memory") ; return CR_ERROR ; } @@ -1058,6 +1058,106 @@ cr_om_parser_simply_parse_file (const guchar *a_file_path, return status ; } +/** + *Parses three sheets located by their paths and build a cascade + *@param a_this the current instance of #CROMParser + *@param a_author_path the path to the author stylesheet + *@param a_user_path the path to the user stylesheet + *@param a_ua_path the path to the User Agent stylesheet + *@param a_result out parameter. The resulting cascade if the parsing + *was okay + *@return CR_OK upon successful completion, an error code otherwise + */ +enum CRStatus +cr_om_parser_parse_paths_to_cascade (CROMParser *a_this, + const guchar *a_author_path, + const guchar *a_user_path, + const guchar *a_ua_path, + enum CREncoding a_encoding, + CRCascade ** a_result) +{ + enum CRStatus status = CR_OK ; + /*0->author sheet, 1->user sheet, 2->UA sheet*/ + CRStyleSheet *sheets[3] ; + guchar * paths[3] ; + CRCascade *result = NULL ; + gint i = 0 ; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + + memset (sheets, 0, sizeof (CRStyleSheet) * 3) ; + paths[0] = (guchar*) a_author_path ; + paths[1] = (guchar*) a_user_path ; + paths[2] = (guchar*) a_ua_path ; + + for (i=0 ;i < 3; i++) + { + status = cr_om_parser_parse_file (a_this, paths[i], + a_encoding, + &sheets[i]) ; + if (status != CR_OK) + { + if (sheets[i]) + { + cr_stylesheet_unref (sheets[i]) ; + sheets[i] = NULL ; + } + continue ; + } + } + result = cr_cascade_new (sheets[0], sheets[1], sheets[2]) ; + if (!result) + { + for (i=0 ; i < 3 ; i++) + { + cr_stylesheet_unref (sheets[i]) ; + sheets[i] = 0 ; + } + return CR_ERROR ; + } + *a_result = result ; + return CR_OK ; +} + +/** + *Parses three sheets located by their paths and build a cascade + *@param a_author_path the path to the author stylesheet + *@param a_user_path the path to the user stylesheet + *@param a_ua_path the path to the User Agent stylesheet + *@param a_result out parameter. The resulting cascade if the parsing + *was okay + *@return CR_OK upon successful completion, an error code otherwise + */ +enum CRStatus +cr_om_parser_simply_parse_paths_to_cascade (const guchar *a_author_path, + const guchar *a_user_path, + const guchar *a_ua_path, + enum CREncoding a_encoding, + CRCascade ** a_result) +{ + enum CRStatus status = CR_OK ; + CROMParser *parser = NULL ; + + parser = cr_om_parser_new (NULL) ; + if (!parser) + { + cr_utils_trace_info ("could not allocated om parser") ; + cr_utils_trace_info ("System may be out of memory") ; + return CR_ERROR ; + } + status = cr_om_parser_parse_paths_to_cascade (parser, + a_author_path, + a_user_path, + a_ua_path, + a_encoding, + a_result) ; + if (parser) + { + cr_om_parser_destroy (parser) ; + parser = NULL ; + } + return status ; +} /** *Destructor of the #CROMParser. diff --git a/src/cr-om-parser.h b/src/cr-om-parser.h index 475016c..0213c5d 100644 --- a/src/cr-om-parser.h +++ b/src/cr-om-parser.h @@ -29,7 +29,8 @@ #define __CR_OM_PARSER_H__ #include "cr-parser.h" -#include "cr-stylesheet.h" +#include "cr-cascade.h" + /** *@file @@ -57,11 +58,6 @@ struct _CROMParser CROMParser * cr_om_parser_new (CRInput *a_input) ; -enum CRStatus -cr_om_parser_parse_file (CROMParser *a_this, - const guchar *a_file_uri, - enum CREncoding a_enc, - CRStyleSheet **a_result) ; enum CRStatus cr_om_parser_simply_parse_file (const guchar *a_file_path, @@ -69,6 +65,11 @@ cr_om_parser_simply_parse_file (const guchar *a_file_path, CRStyleSheet **a_result) ; enum CRStatus +cr_om_parser_parse_file (CROMParser *a_this, + const guchar *a_file_uri, + enum CREncoding a_enc, + CRStyleSheet **a_result) ; +enum CRStatus cr_om_parser_simply_parse_buf (const guchar *a_buf, gulong a_len, enum CREncoding a_enc, @@ -81,6 +82,21 @@ cr_om_parser_parse_buf (CROMParser *a_this, enum CREncoding a_enc, CRStyleSheet **a_result) ; +enum CRStatus +cr_om_parser_parse_paths_to_cascade (CROMParser *a_this, + const guchar *a_author_path, + const guchar *a_user_path, + const guchar *a_ua_path, + enum CREncoding a_encoding, + CRCascade ** a_result) ; + +enum CRStatus +cr_om_parser_simply_parse_paths_to_cascade (const guchar *a_author_path, + const guchar *a_user_path, + const guchar *a_ua_path, + enum CREncoding a_encoding, + CRCascade ** a_result) ; + void cr_om_parser_destroy (CROMParser *a_this) ; |