summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordodji <dodji@seketeli.org>2003-06-17 21:50:03 +0000
committerDodji Seketeli <dodji@src.gnome.org>2003-06-17 21:50:03 +0000
commita938c19b86709a0c3ea97d2d0090a01861e38236 (patch)
tree591cff2e8e1042650cce45895c20e4d51745d13c
parentd14f86ba72cde186e4e323f2c7819b82fc0cd3a9 (diff)
downloadlibcroco-a938c19b86709a0c3ea97d2d0090a01861e38236.tar.gz
added test_cr_statement_at_page_rule_parse () to test the new
2003-06-17 dodji <dodji@seketeli.org> * tests/test4-main.c: added test_cr_statement_at_page_rule_parse () to test the new cr_statement_at_page_rule_parse_from_buf() function. * src/parser/cr-statement.[ch]: added a first version of cr_statement_at_page_rule_parse_from_buf(). This doesn't work. I need to debug it first. Dodji.
-rw-r--r--ChangeLog7
-rw-r--r--TODO2
-rw-r--r--src/parser/cr-doc-handler.h2
-rw-r--r--src/parser/cr-om-parser.c2
-rw-r--r--src/parser/cr-statement.c140
-rw-r--r--src/parser/cr-statement.h4
-rw-r--r--tests/test4-main.c30
7 files changed, 180 insertions, 7 deletions
diff --git a/ChangeLog b/ChangeLog
index 92c3f02..a447dd6 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2003-06-17 dodji <dodji@seketeli.org>
+ * tests/test4-main.c: added test_cr_statement_at_page_rule_parse ()
+ to test the new cr_statement_at_page_rule_parse_from_buf() function.
+
+ * src/parser/cr-statement.[ch]:
+ added a first version of cr_statement_at_page_rule_parse_from_buf().
+ This doesn't work. I need to debug it first.
+
* tests/test4-main.c: updated this to test
cr_statement_at_media_rule_parse_from_buf().
diff --git a/TODO b/TODO
index b98b5f0..5dd5676 100644
--- a/TODO
+++ b/TODO
@@ -1,7 +1,7 @@
*coding:)
-test/debug the new cr_statement_at_media_rule_parse_from_buf().
+test/debug cr_statement_at_page_rule_parse_from_buf().
Provide support for font selection. (hard, started well underway.)
First make sure to be able to gather all the font related property
diff --git a/src/parser/cr-doc-handler.h b/src/parser/cr-doc-handler.h
index c8eda0f..0d654d9 100644
--- a/src/parser/cr-doc-handler.h
+++ b/src/parser/cr-doc-handler.h
@@ -220,7 +220,7 @@ struct _CRDocHandler
*/
void (*start_page) (CRDocHandler *a_this,
GString *a_name,
- GString *pseudo_page) ;
+ GString *a_pseudo_page) ;
/**
*Is called to notify the end of a page statement.
diff --git a/src/parser/cr-om-parser.c b/src/parser/cr-om-parser.c
index 0bceb4c..19d9708 100644
--- a/src/parser/cr-om-parser.c
+++ b/src/parser/cr-om-parser.c
@@ -469,8 +469,6 @@ start_media (CRDocHandler *a_this, GList *a_media_list)
if (a_media_list)
{
- GList *cur = NULL ;
-
/*duplicate the media_list*/
media_list = cr_dup_glist_of_string (a_media_list) ;
}
diff --git a/src/parser/cr-statement.c b/src/parser/cr-statement.c
index 8ce749e..d66bb8e 100644
--- a/src/parser/cr-statement.c
+++ b/src/parser/cr-statement.c
@@ -56,6 +56,63 @@ static void
cr_statement_dump_import_rule (CRStatement *a_this, FILE *a_fp,
gulong a_indent) ;
+
+static void
+parse_page_start_page_cb (CRDocHandler *a_this,
+ GString *a_name,
+ GString *a_pseudo_page)
+{
+ CRStatement *stmt = NULL ;
+ enum CRStatus status = CR_OK ;
+
+ stmt = cr_statement_new_at_page_rule (NULL, NULL, a_name,
+ a_pseudo_page) ;
+ g_return_if_fail (stmt) ;
+ status = cr_doc_handler_set_ctxt (a_this, stmt) ;
+ g_return_if_fail (status == CR_OK) ;
+}
+
+static void
+parse_page_property_cb (CRDocHandler *a_this,
+ GString *a_name,
+ CRTerm *a_expression)
+{
+ GString *name = NULL ;
+ CRStatement *stmt = NULL ;
+ CRDeclaration *decl = NULL ;
+ enum CRStatus status = CR_OK ;
+
+ status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ;
+ g_return_if_fail (status == CR_OK && stmt->type == AT_PAGE_RULE_STMT) ;
+
+ name = g_string_new_len (a_name->str, a_name->len) ;
+ g_return_if_fail (name) ;
+
+ decl = cr_declaration_new (stmt, name, a_expression) ;
+ g_return_if_fail (decl) ;
+
+ stmt->kind.page_rule->decls_list =
+ cr_declaration_append (stmt->kind.page_rule->decls_list,
+ decl) ;
+ g_return_if_fail (stmt->kind.page_rule->decls_list) ;
+}
+
+static void
+parse_page_end_page_cb (CRDocHandler *a_this,
+ GString *a_name,
+ GString *a_pseudo_page)
+{
+ enum CRStatus status = CR_OK ;
+ CRStatement *stmt = NULL ;
+
+ status = cr_doc_handler_get_ctxt (a_this, (gpointer*)&stmt) ;
+ g_return_if_fail (status == CR_OK && stmt);
+ g_return_if_fail (stmt->type == AT_PAGE_RULE_STMT);
+
+ status = cr_doc_handler_set_result (a_this, stmt) ;
+ g_return_if_fail (status == CR_OK) ;
+}
+
static void
parse_at_media_start_media_cb (CRDocHandler *a_this,
GList *a_media_list)
@@ -965,7 +1022,6 @@ cr_statement_new_at_page_rule (CRStyleSheet *a_sheet,
{
CRStatement *result = NULL ;
- g_return_val_if_fail (a_sheet, NULL) ;
result = g_try_malloc (sizeof (CRStatement)) ;
@@ -988,15 +1044,93 @@ cr_statement_new_at_page_rule (CRStyleSheet *a_sheet,
}
memset (result->kind.page_rule, 0, sizeof (CRAtPageRule)) ;
- result->kind.page_rule->decls_list = a_decl_list;
+ if (a_decl_list)
+ {
+ result->kind.page_rule->decls_list = a_decl_list;
+ cr_declaration_ref (a_decl_list) ;
+ }
result->kind.page_rule->name = a_name ;
result->kind.page_rule->name = a_pseudo ;
- cr_statement_set_parent_sheet (result, a_sheet) ;
+ if (a_sheet)
+ cr_statement_set_parent_sheet (result, a_sheet) ;
return result ;
}
/**
+ *Parses a buffer that contains an "@page" production and,
+ *if the parsing succeeds, builds the page statement.
+ *@param a_buf the character buffer to parse.
+ *@param a_encoding the character encoding of a_buf.
+ *@return the newly built at page statement in case of successfull parsing,
+ *NULL otherwise.
+ */
+CRStatement *
+cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf,
+ enum CREncoding a_encoding)
+{
+ enum CRStatus status = CR_OK ;
+ CRParser *parser = NULL ;
+ CRDocHandler *sac_handler = NULL ;
+ CRStatement *result = NULL ;
+
+ g_return_val_if_fail (a_buf, NULL) ;
+
+ parser = cr_parser_new_from_buf (a_buf, strlen (a_buf),
+ a_encoding, FALSE) ;
+ if (!parser)
+ {
+ cr_utils_trace_info ("Instanciation of the parser failed.") ;
+ goto cleanup ;
+ }
+
+ sac_handler = cr_doc_handler_new () ;
+ if (!sac_handler)
+ {
+ cr_utils_trace_info
+ ("Instanciation of the sac handler failed.") ;
+ goto cleanup ;
+ }
+
+ sac_handler->start_page =
+ parse_page_start_page_cb ;
+ sac_handler->property =
+ parse_page_property_cb ;
+ sac_handler->end_page =
+ parse_page_end_page_cb ;
+
+ status = cr_parser_set_sac_handler (parser, sac_handler) ;
+ if (status != CR_OK)
+ goto cleanup ;
+
+ /*Now, invoke the parser to parse the "@page production"*/
+ cr_parser_try_to_skip_spaces_and_comments (parser) ;
+ if (status != CR_OK)
+ goto cleanup ;
+ status = cr_parser_parse_page (parser) ;
+ if (status != CR_OK)
+ goto cleanup ;
+
+ status = cr_doc_handler_get_result (sac_handler,
+ (gpointer*)&result) ;
+
+ cleanup:
+
+ if (parser)
+ {
+ cr_parser_destroy (parser) ;
+ parser = NULL ;
+ }
+ if (sac_handler)
+ {
+ cr_doc_handler_unref (sac_handler) ;
+ sac_handler = NULL ;
+ }
+ return result ;
+
+}
+
+/**
*Creates a new instance of #CRStatement of type
*#CRAtCharsetRule.
*@param a_charset the string representing the charset.
diff --git a/src/parser/cr-statement.h b/src/parser/cr-statement.h
index 9db62f9..23c8895 100644
--- a/src/parser/cr-statement.h
+++ b/src/parser/cr-statement.h
@@ -268,6 +268,10 @@ cr_statement_new_at_page_rule (CRStyleSheet *a_sheet,
CRDeclaration *a_decl_list,
GString *a_name,
GString *a_pseudo) ;
+CRStatement *
+cr_statement_at_page_rule_parse_from_buf (const guchar *a_buf,
+ enum CREncoding a_encoding) ;
+
enum CRStatus
cr_statement_set_parent_sheet (CRStatement *a_this,
CRStyleSheet *a_sheet) ;
diff --git a/tests/test4-main.c b/tests/test4-main.c
index 4563fa7..1d48a39 100644
--- a/tests/test4-main.c
+++ b/tests/test4-main.c
@@ -48,6 +48,10 @@ const guchar *gv_at_media_buf =
" }"
;
+const guchar *gv_at_page_buf =
+"@page { size 8.5in 11in; margin: 2cm }"
+;
+
static void
display_help (char *prg_name) ;
@@ -188,6 +192,25 @@ test_cr_statement_at_media_rule_parse (void)
return CR_OK ;
}
+static enum CRStatus
+test_cr_statement_at_page_rule_parse (void)
+{
+ CRStatement *stmt = NULL ;
+
+ stmt = cr_statement_at_page_rule_parse_from_buf (gv_at_page_buf,
+ CR_UTF_8) ;
+
+ g_return_val_if_fail (stmt, CR_ERROR) ;
+
+ if (stmt)
+ {
+ cr_statement_destroy (stmt) ;
+ stmt = NULL ;
+ }
+
+ return CR_OK ;
+}
+
/**
*The entry point of the testing routine.
*/
@@ -218,6 +241,13 @@ main (int argc, char ** argv)
return 0 ;
}
+ test_cr_statement_at_page_rule_parse () ;
+ if (status != CR_OK)
+ {
+ g_print ("\nKO\n") ;
+ return 0 ;
+ }
+
cr_test_utils_parse_cmd_line (argc, argv, &options) ;
if (options.display_help == TRUE)