diff options
-rw-r--r-- | ChangeLog | 42 | ||||
-rw-r--r-- | src/layeng/cr-lay-eng.c | 2 | ||||
-rw-r--r-- | src/parser/cr-declaration.c | 21 | ||||
-rw-r--r-- | src/parser/cr-doc-handler.c | 102 | ||||
-rw-r--r-- | src/parser/cr-doc-handler.h | 34 | ||||
-rw-r--r-- | src/parser/cr-om-parser.c | 148 | ||||
-rw-r--r-- | src/parser/cr-parser.c | 613 | ||||
-rw-r--r-- | src/parser/cr-parser.h | 12 | ||||
-rw-r--r-- | src/parser/cr-selector.c | 17 | ||||
-rw-r--r-- | src/parser/cr-selector.h | 4 | ||||
-rw-r--r-- | src/parser/cr-statement.c | 155 | ||||
-rw-r--r-- | src/parser/cr-statement.h | 4 | ||||
-rw-r--r-- | src/parser/cr-term.h | 2 | ||||
-rw-r--r-- | tests/test4-main.c | 40 |
14 files changed, 839 insertions, 357 deletions
@@ -1,5 +1,47 @@ +2003-06-15 dodji <dodji@seketeli.org> + + * tests/test4-main.c: updated this to test the new + cr_statement_ruleset_parse_from_buf () method. + + * src/parser/cr-statement.[ch]: + Added a cr_statement_ruleset_parse_from_buf () method. This + is based on the changes made in cr-parser.[ch]. + + * src/parser/cr-selector.[ch]: + added a method cr_selector_parse_from_buf (). This is based + on the changes made in cr-parser.[ch]. + + * src/parser/cr-parser.[ch]: + Some rather important changes occured here ... + revisited the way selectors and rulesets are parsed + so that one could parse a buffer that contains only a ruleset. + A visible implication of this is that cr_parser_parse_selector () and + cr_parser_parse_ruleset () become public methods callable independantly. + In the past, this was not possible. Only cr_parser_parse_stylesheet () + was public. + + * src/parser/cr-om-parser.c: updated this to comply with the + changes made in cr-doc-handler.[ch]. + + * src/parser/cr-doc-handler.[ch]: + 1/ Created an explicitely private field of CRDocHandler + to store parsing context, parsing result and any eventually + needed private data structure. The privates fields are + accessible through getters/setters though. + 2/ made sure to increment the ref count of each instance + of CRDocHandler at instanciation time. This may + introduce some memleaks in the working code. I will + fix them in next commits. + + * src/parser/cr-declaration.c: + (cr_declaration_append2() ): modified this so that + we can append declaration to a list of declarations that + don't belong to a ruleset. + 2003-06-14 dodji <dodji@seketeli.org> + * src/parser/cr-term.h (struct _CRTerm): fixed a typo. + * src/layeng/cr-lay-eng.c, src/seleng/cr-style.[hc]: more fonts selection implementation. diff --git a/src/layeng/cr-lay-eng.c b/src/layeng/cr-lay-eng.c index 2338806..5fb005f 100644 --- a/src/layeng/cr-lay-eng.c +++ b/src/layeng/cr-lay-eng.c @@ -894,7 +894,7 @@ layout_text_in_box (CRLayEng *a_this, CRBox *a_text_box) pgo_attr_list, strlen (a_text_box->content->u.text)) ; - gtk_label_set_attributes (label, pgo_attr_list) ; + gtk_label_set_attributes (GTK_LABEL (label), pgo_attr_list) ; return status ; } diff --git a/src/parser/cr-declaration.c b/src/parser/cr-declaration.c index a3e9683..91bc2a6 100644 --- a/src/parser/cr-declaration.c +++ b/src/parser/cr-declaration.c @@ -280,17 +280,16 @@ cr_declaration_append2 (CRDeclaration *a_this, { CRDeclaration *new_elem = NULL ; - g_return_val_if_fail (a_this && a_this->parent_statement - && ((a_this->parent_statement->type - == RULESET_STMT) - || (a_this->parent_statement->type - == AT_FONT_FACE_RULE_STMT) - || (a_this->parent_statement->type - == AT_PAGE_RULE_STMT)), - NULL) ; - - new_elem = cr_declaration_new (a_this->parent_statement, - a_prop, a_value) ; + if (a_this) + { + new_elem = cr_declaration_new (a_this->parent_statement, + a_prop, a_value) ; + } + else + { + new_elem = cr_declaration_new (NULL, a_prop, a_value) ; + } + g_return_val_if_fail (new_elem, NULL) ; return cr_declaration_append (a_this, new_elem) ; diff --git a/src/parser/cr-doc-handler.c b/src/parser/cr-doc-handler.c index 811cee9..165e5da 100644 --- a/src/parser/cr-doc-handler.c +++ b/src/parser/cr-doc-handler.c @@ -32,6 +32,25 @@ *to custom values. */ +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 + *#CROMParser does. #CROMParser allocates this pointer at + *the beginning of the css document, and frees it at the end + *of the document. + */ + gpointer context ; + + /** + *The place where #CROMParser puts the result of its parsing, if + *any. + */ + gpointer result ; +} ; + /** *Constructor of #CRDocHandler. @@ -49,6 +68,15 @@ cr_doc_handler_new (void) memset (result, 0, sizeof (CRDocHandler)) ; + result->priv = g_try_malloc (sizeof (CRDocHandlerPriv)) ; + if (!result->priv) + { + cr_utils_trace_info ("Out of memory exception") ; + g_free (result) ; + return NULL ; + } + + cr_doc_handler_ref (result) ; cr_doc_handler_set_default_sac_handler (result) ; return result ; @@ -56,6 +84,75 @@ cr_doc_handler_new (void) /** + *Returns the private parsing context. + *The private parsing context is used by libcroco only. + *@param a_this the current instance of #CRDocHandler. + *@param a_ctxt out parameter. The new parsing context. + *@return CR_OK upon successfull completion, an error code otherwise. + *@return the parsing context, or NULL if an error occured. + */ +enum CRStatus +cr_doc_handler_get_ctxt (CRDocHandler *a_this, gpointer * a_ctxt) +{ + g_return_val_if_fail (a_this && a_this->priv, + CR_BAD_PARAM_ERROR) ; + + *a_ctxt = a_this->priv->context ; + + return CR_OK ; +} + +/** + *Sets the private parsing context. + *This is used by libcroco only. + *@param a_this the current instance of #CRDocHandler + *@param a_ctxt a pointer to the parsing context. + *@return CR_OK upon successfull completion, an error code otherwise. + */ +enum CRStatus +cr_doc_handler_set_ctxt (CRDocHandler *a_this, gpointer a_ctxt) +{ + g_return_val_if_fail (a_this && a_this->priv, + CR_BAD_PARAM_ERROR) ; + a_this->priv->context = a_ctxt ; + return CR_OK ; +} + +/** + *Returns the private parsing result. + *The private parsing result is used by libcroco only. + *@param a_this the current instance of #CRDocHandler + *@param a_result out parameter. The returned result. + *@return CR_OK upon successfull completion, an error code otherwise. + */ +enum CRStatus +cr_doc_handler_get_result (CRDocHandler *a_this, gpointer * a_result) +{ + g_return_val_if_fail (a_this && a_this->priv, + CR_BAD_PARAM_ERROR) ; + + *a_result = a_this->priv->result ; + + return CR_OK ; +} + +/** + *Sets the private parsing context. + *This is used by libcroco only. + *@param a_this the current instance of #CRDocHandler + *@param a_result the new result. + *@return CR_OK upon successfull completion, an error code otherwise. + */ +enum CRStatus +cr_doc_handler_set_result (CRDocHandler *a_this, gpointer a_result) +{ + g_return_val_if_fail (a_this && a_this->priv, + CR_BAD_PARAM_ERROR) ; + a_this->priv->result = a_result ; + return CR_OK ; +} + +/** *Sets the sac handlers contained in the current *instance of DocHandler to the default handlers. *For the time being the default handlers are @@ -138,5 +235,10 @@ cr_doc_handler_destroy (CRDocHandler *a_this) { g_return_if_fail (a_this) ; + if (a_this->priv) + { + g_free (a_this->priv) ; + a_this->priv = NULL ; + } g_free (a_this) ; } diff --git a/src/parser/cr-doc-handler.h b/src/parser/cr-doc-handler.h index 4d5326c..c8eda0f 100644 --- a/src/parser/cr-doc-handler.h +++ b/src/parser/cr-doc-handler.h @@ -39,6 +39,10 @@ G_BEGIN_DECLS typedef struct _CRDocHandler CRDocHandler ; +struct _CRDocHandlerPriv ; +typedef struct _CRDocHandlerPriv CRDocHandlerPriv ; + + /** *The SAC document handler. *An instance of this class is to @@ -48,6 +52,8 @@ typedef struct _CRDocHandler CRDocHandler ; */ struct _CRDocHandler { + CRDocHandlerPriv *priv ; + /** *This pointer is to be used by the application for *it custom needs. It is there to extend the doc handler. @@ -55,22 +61,6 @@ struct _CRDocHandler gpointer app_data ; /** - *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 - *#CROMParser does. #CROMParser allocates this pointer at - *the beginning of the css document, and frees it at the end - *of the document. - */ - gpointer context ; - - /** - *The place where #CROMParser put the result of it parsing, if - *any. - */ - gpointer result ; - - /** *Is called at the beginning of the parsing of the document. *@param a_this a pointer to the current instance of *#CRDocHandler. @@ -272,6 +262,18 @@ 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_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_get_ctxt (CRDocHandler *a_this, gpointer * a_ctxt) ; + +enum CRStatus cr_doc_handler_set_default_sac_handler (CRDocHandler *a_this) ; void cr_doc_handler_ref (CRDocHandler *a_this) ; diff --git a/src/parser/cr-om-parser.c b/src/parser/cr-om-parser.c index 8515eef..c2c007a 100644 --- a/src/parser/cr-om-parser.c +++ b/src/parser/cr-om-parser.c @@ -224,17 +224,19 @@ start_document (CRDocHandler *a_this) stylesheet = cr_stylesheet_new (NULL) ; ctxt->stylesheet = stylesheet ; - a_this->context = ctxt ; + cr_doc_handler_set_ctxt (a_this, ctxt) ; } static void start_font_face (CRDocHandler *a_this) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; g_return_if_fail (a_this) ; - g_return_if_fail (a_this && a_this->context) ; - ctxt = a_this->context ; + g_return_if_fail (a_this) ; + status = cr_doc_handler_get_ctxt (a_this, (gpointer*) &ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt->cur_stmt == NULL) ; ctxt->cur_stmt = @@ -247,13 +249,16 @@ start_font_face (CRDocHandler *a_this) static void end_font_face (CRDocHandler *a_this) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; CRStatement *stmts = NULL ; g_return_if_fail (a_this) ; - g_return_if_fail (a_this && a_this->context) ; - ctxt = a_this->context ; + g_return_if_fail (a_this) ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*) &ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_FONT_FACE_RULE_STMT @@ -289,21 +294,24 @@ end_font_face (CRDocHandler *a_this) static void end_document (CRDocHandler *a_this) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this) ; - g_return_if_fail (a_this && a_this->context) ; - ctxt = a_this->context ; + g_return_if_fail (a_this) ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; if (!ctxt->stylesheet || ctxt->cur_stmt) goto error ; - a_this->result = ctxt->stylesheet ; + status = cr_doc_handler_set_result (a_this, ctxt->stylesheet) ; + g_return_if_fail (status == CR_OK) ; + ctxt->stylesheet = NULL ; - destroy_context (ctxt) ; + cr_doc_handler_set_ctxt (a_this, NULL) ; - a_this->context = NULL ; return ; error: @@ -316,13 +324,16 @@ end_document (CRDocHandler *a_this) static void charset (CRDocHandler *a_this, GString *a_charset) { + enum CRStatus status = CR_OK ; CRStatement *stmt = NULL, *stmt2 = NULL ; GString * charset = NULL ; ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this && a_this->context) ; + g_return_if_fail (a_this) ; - ctxt = a_this->context ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt->stylesheet) ; charset = g_string_new_len (a_charset->str, @@ -357,10 +368,14 @@ static void start_page (CRDocHandler *a_this, GString *a_page, GString *a_pseudo) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this && a_this->context) ; - ctxt = a_this->context ; + g_return_if_fail (a_this) ; + + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt->cur_stmt == NULL) ; ctxt->cur_stmt = cr_statement_new_at_page_rule @@ -403,12 +418,15 @@ static void end_page (CRDocHandler *a_this, GString *a_page, GString *a_pseudo_page) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; CRStatement *stmt = NULL ; - g_return_if_fail (a_this && a_this->context) ; + g_return_if_fail (a_this) ; - ctxt = a_this->context ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt->cur_stmt && ctxt->cur_stmt->type == AT_PAGE_RULE_STMT && ctxt->stylesheet) ; @@ -435,12 +453,15 @@ end_page (CRDocHandler *a_this, GString *a_page, static void start_media (CRDocHandler *a_this, GList *a_media_list) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; GList * media_list = NULL ; - g_return_if_fail (a_this && a_this->context) ; - ctxt = a_this->context ; - + g_return_if_fail (a_this) ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; + g_return_if_fail (ctxt && ctxt->cur_stmt == NULL && ctxt->cur_media_stmt == NULL @@ -472,12 +493,14 @@ start_media (CRDocHandler *a_this, GList *a_media_list) static void end_media (CRDocHandler *a_this, GList *a_media_list) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; CRStatement * stmts = NULL ; - g_return_if_fail (a_this && a_this->context) ; - ctxt = a_this->context ; - + g_return_if_fail (a_this) ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt && ctxt->cur_media_stmt && ctxt->cur_media_stmt->type == AT_MEDIA_RULE_STMT @@ -502,14 +525,16 @@ static void import_style (CRDocHandler *a_this, GList *a_media_list, GString *a_uri, GString *a_uri_default_ns) { + enum CRStatus status = CR_OK ; GString *uri = NULL ; CRStatement *stmt = NULL, *stmt2 = NULL ; ParsingContext *ctxt = NULL ; GList *media_list = NULL, *cur = NULL ; - g_return_if_fail (a_this && a_this->context) ; - - ctxt = a_this->context ; + g_return_if_fail (a_this) ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt->stylesheet) ; uri = g_string_new_len (a_uri->str, a_uri->len) ; @@ -572,10 +597,13 @@ static void start_selector (CRDocHandler *a_this, CRSelector *a_selector_list) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this && a_this->context) ; - - ctxt = a_this->context ; + g_return_if_fail (a_this) ; + + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; if (ctxt->cur_stmt) { /*hmm, this should be NULL so free it*/ @@ -592,10 +620,13 @@ static void end_selector (CRDocHandler *a_this, CRSelector *a_selector_list) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this && a_this->context) ; + g_return_if_fail (a_this) ; - ctxt = a_this->context ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; g_return_if_fail (ctxt->cur_stmt && ctxt->stylesheet) ; @@ -651,12 +682,15 @@ property (CRDocHandler *a_this, GString *a_name, CRTerm *a_expression) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; CRDeclaration *decl = NULL, *decl2 = NULL ; GString *str = NULL ; - g_return_if_fail (a_this && a_this->context) ; - ctxt = a_this->context ; + g_return_if_fail (a_this) ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; /* *make sure a current ruleset statement has been allocated @@ -756,10 +790,13 @@ property (CRDocHandler *a_this, static void error (CRDocHandler *a_this) { + enum CRStatus status = CR_OK ; ParsingContext *ctxt = NULL ; - g_return_if_fail (a_this && a_this->context) ; + g_return_if_fail (a_this) ; - ctxt = a_this->context ; + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK && ctxt) ; if (ctxt->cur_stmt) { @@ -773,16 +810,23 @@ error (CRDocHandler *a_this) static void unrecoverable_error (CRDocHandler *a_this) { - if (a_this->context) + enum CRStatus status = CR_OK ; + ParsingContext *ctxt = NULL ; + + status = cr_doc_handler_get_ctxt (a_this, + (gpointer*)&ctxt) ; + g_return_if_fail (status == CR_OK) ; + + if (ctxt) { - if (((ParsingContext*)a_this->context)->stylesheet) + if (ctxt->stylesheet) { - a_this->result = - ((ParsingContext*)a_this->context)-> - stylesheet ; + status = cr_doc_handler_set_result + (a_this, ctxt->stylesheet) ; + g_return_if_fail (status == CR_OK) ; } - g_free (a_this->context) ; - a_this->context = NULL ; + g_free (ctxt) ; + cr_doc_handler_set_ctxt (a_this, NULL) ; } } @@ -880,13 +924,19 @@ cr_om_parser_parse_buf (CROMParser *a_this, if (status == CR_OK) { + CRStyleSheet *result = NULL ; CRDocHandler *sac_handler = NULL ; + cr_parser_get_sac_handler (PRIVATE (a_this)->parser, &sac_handler) ; g_return_val_if_fail (sac_handler, CR_ERROR) ; - if (sac_handler->result) - *a_result = sac_handler->result ; + status = cr_doc_handler_get_result (sac_handler, + (gpointer*)&result) ; + g_return_val_if_fail (status == CR_OK, status) ; + + if (result) + *a_result = result ; } return status ; @@ -963,13 +1013,19 @@ cr_om_parser_parse_file (CROMParser *a_this, if (status == CR_OK) { + CRStyleSheet *result = NULL ; CRDocHandler *sac_handler = NULL ; + cr_parser_get_sac_handler (PRIVATE (a_this)->parser, &sac_handler) ; g_return_val_if_fail (sac_handler, CR_ERROR) ; - if (sac_handler->result) - *a_result = sac_handler->result ; + status = cr_doc_handler_get_result + (sac_handler, + (gpointer *)&result) ; + g_return_val_if_fail (status == CR_OK, status) ; + if (result) + *a_result = result ; } return status ; diff --git a/src/parser/cr-parser.c b/src/parser/cr-parser.c index b3034b3..e88906d 100644 --- a/src/parser/cr-parser.c +++ b/src/parser/cr-parser.c @@ -409,9 +409,6 @@ static enum CRStatus cr_parser_parse_simple_sels (CRParser *a_this, CRSimpleSel **a_sel) ; static enum CRStatus -cr_parser_parse_ruleset (CRParser *a_this) ; - -static enum CRStatus cr_parser_parse_expr (CRParser *a_this, CRTerm **a_expr) ; static CRParserError * @@ -1861,93 +1858,6 @@ cr_parser_parse_any_core (CRParser *a_this) return status ; } -/** - *Parses a "declaration" as defined by the css2 spec in appendix D.1: - *declaration ::= [property ':' S* expr prio?]? - * - *@param a_this the "this pointer" of the current instance of #CRParser. - *@param a_property the successfully parsed property. The caller - * *must* free the returned pointer. - *@param a_expr the expression that represents the attribute value. - *The caller *must* free the returned pointer. - *@return CR_OK upon successfull completion, an error code otherwise. - */ -enum CRStatus -cr_parser_parse_declaration (CRParser *a_this, GString **a_property, - CRTerm **a_expr) -{ - enum CRStatus status = CR_ERROR ; - CRInputPos init_pos ; - guint32 cur_char = 0 ; - CRTerm *expr = NULL ; - - g_return_val_if_fail (a_this && PRIVATE (a_this) - && a_property && a_expr, - CR_BAD_PARAM_ERROR) ; - - RECORD_INITIAL_POS (a_this, &init_pos) ; - - status = cr_parser_parse_property (a_this, a_property) ; - - CHECK_PARSING_STATUS_ERR - (a_this, status, FALSE, - "while parsing declaration: next property is malformed", - CR_SYNTAX_ERROR) ; - - - READ_NEXT_CHAR (a_this, &cur_char) ; - - if (cur_char != ':') - { - status = CR_PARSING_ERROR ; - cr_parser_push_error - (a_this, - "while parsing declaration: this char must be ':'", - CR_SYNTAX_ERROR) ; - goto error ; - } - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - status = cr_parser_parse_expr (a_this, &expr) ; - - CHECK_PARSING_STATUS_ERR - (a_this, status, FALSE, - "while parsing declaration: next expression is malformed", - CR_SYNTAX_ERROR) ; - - if (*a_expr) - { - cr_term_append_term (*a_expr, expr) ; - expr = NULL ; - } - else - { - *a_expr = expr ; - expr = NULL ; - } - - cr_parser_clear_errors (a_this) ; - return CR_OK ; - - error: - - if (expr) - { - cr_term_destroy (expr) ; - expr = NULL ; - } - - if (*a_property) - { - g_string_free (*a_property, TRUE) ; - *a_property = NULL ; - } - - cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; - - return status ; -} /** @@ -3725,25 +3635,17 @@ cr_parser_parse_font_face (CRParser *a_this) } -/** - *Parses a "ruleset" as defined in the css2 spec at appendix D.1. - *ruleset ::= selector [ ',' S* selector ]* - *'{' S* declaration? [ ';' S* declaration? ]* '}' S*; - * - *@param a_this the "this pointer" of the current instance of #CRParser. - *@return CR_OK upon successfull completion, an error code otherwise. - */ static enum CRStatus -cr_parser_parse_ruleset (CRParser *a_this) +cr_parser_parse_selector (CRParser *a_this, CRSelector **a_selector) { enum CRStatus status = CR_OK ; CRInputPos init_pos ; guint32 cur_char = 0, next_char = 0 ; - GString * property = NULL ; - CRTerm *expr = NULL ; CRSimpleSel * simple_sels = NULL ; CRSelector *selector = NULL ; - gboolean start_selector = FALSE ; + + g_return_val_if_fail (a_this && a_selector, + CR_BAD_PARAM_ERROR) ; RECORD_INITIAL_POS (a_this, &init_pos) ; @@ -3758,7 +3660,20 @@ cr_parser_parse_ruleset (CRParser *a_this) simple_sels = NULL ; } - PEEK_NEXT_CHAR (a_this, &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 ; + goto okay ; + } + else + { + goto error ; + } + } if (next_char == ',') { @@ -3766,8 +3681,21 @@ cr_parser_parse_ruleset (CRParser *a_this) { simple_sels = NULL ; - PEEK_NEXT_CHAR (a_this, &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 ; + break ; + } + else + { + goto error ; + } + } + if (next_char != ',') break ; /*consume the ',' char*/ @@ -3791,184 +3719,31 @@ cr_parser_parse_ruleset (CRParser *a_this) } } } - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - READ_NEXT_CHAR (a_this, &cur_char) ; - - ENSURE_PARSING_COND_ERR - (a_this, cur_char == '{', - "while parsing rulset: current char should be '{'", - CR_SYNTAX_ERROR) ; - - - if (PRIVATE (a_this)->sac_handler - &&PRIVATE (a_this)->sac_handler->start_selector) - { - /* - *the selector if ref counted so that the parser's user - *can choose to keep it. - */ - if (selector) - { - cr_selector_ref (selector) ; - } - - PRIVATE (a_this)->sac_handler->start_selector - (PRIVATE (a_this)->sac_handler, selector) ; - start_selector = TRUE ; - } + okay: cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - PRIVATE (a_this)->state = TRY_PARSE_RULESET_STATE ; - status = cr_parser_parse_declaration (a_this, &property, &expr) ; - - if (expr) + if (!*a_selector) { - cr_term_ref (expr) ; - } - - if ( status == CR_OK - && PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->property) - { - PRIVATE (a_this)->sac_handler->property - (PRIVATE (a_this)->sac_handler, property, expr) ; - } - - if (status == CR_OK) - { - /* - *free the allocated - *'property' and 'term' before parsing - *next declarations. - */ - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; - } - - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; - } + *a_selector = selector ; } - - CHECK_PARSING_STATUS_ERR - (a_this, status, FALSE, - "while parsing ruleset: next construction should be a declaration", - CR_SYNTAX_ERROR) ; - - for (;;) - { - PEEK_NEXT_CHAR (a_this, &next_char) ; - if (next_char != ';') break ; - - /*consume the ';' char*/ - READ_NEXT_CHAR (a_this, &cur_char) ; - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - status = cr_parser_parse_declaration (a_this, &property, - &expr) ; - if (expr) - { - cr_term_ref (expr) ; - } - - if (status == CR_OK - && PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->property) - { - PRIVATE (a_this)->sac_handler->property - (PRIVATE (a_this)->sac_handler, - property, expr) ; - } - - if (property) - { - g_string_free (property, TRUE) ; - property = NULL ; - } - - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; - } - } - - cr_parser_try_to_skip_spaces_and_comments (a_this) ; - - READ_NEXT_CHAR (a_this, &cur_char) ; - - ENSURE_PARSING_COND_ERR - (a_this, cur_char == '}', - "while parsing rulset: current char must be a '}'", - CR_SYNTAX_ERROR) ; - - if (PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->end_selector) - { - PRIVATE (a_this)->sac_handler->end_selector - (PRIVATE (a_this)->sac_handler, selector) ; - start_selector = FALSE ; - } - - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; - } - - if (simple_sels) - { - cr_simple_sel_destroy (simple_sels) ; - simple_sels = NULL ; - } - - if (selector) + else { - cr_selector_unref (selector) ; - selector = NULL ; + *a_selector = cr_selector_append (*a_selector, + selector) ; } - cr_parser_clear_errors (a_this) ; - PRIVATE (a_this)->state = RULESET_PARSED_STATE ; - + selector = NULL ; return CR_OK ; error: - - if (start_selector == TRUE - && PRIVATE (a_this)->sac_handler - && PRIVATE (a_this)->sac_handler->error) - { - PRIVATE (a_this)->sac_handler->error - (PRIVATE (a_this)->sac_handler) ; - } - - if (expr) - { - cr_term_unref (expr) ; - expr = NULL ; - } - + if (simple_sels) { cr_simple_sel_destroy (simple_sels) ; simple_sels = NULL ; } - if (property) - { - g_string_free (property, TRUE) ; - } - if (selector) { cr_selector_unref (selector) ; @@ -3980,6 +3755,7 @@ cr_parser_parse_ruleset (CRParser *a_this) return status ; } + /** *Parses a "function" as defined in css spec at appendix D.1: *function ::= FUNCTION S* expr ')' S* @@ -4740,6 +4516,311 @@ cr_parser_parse_stylesheet (CRParser *a_this) ****************************************/ /** + *Parses a "declaration" as defined by the css2 spec in appendix D.1: + *declaration ::= [property ':' S* expr prio?]? + * + *@param a_this the "this pointer" of the current instance of #CRParser. + *@param a_property the successfully parsed property. The caller + * *must* free the returned pointer. + *@param a_expr the expression that represents the attribute value. + *The caller *must* free the returned pointer. + *@return CR_OK upon successfull completion, an error code otherwise. + */ +enum CRStatus +cr_parser_parse_declaration (CRParser *a_this, GString **a_property, + CRTerm **a_expr) +{ + enum CRStatus status = CR_ERROR ; + CRInputPos init_pos ; + guint32 cur_char = 0 ; + CRTerm *expr = NULL ; + + g_return_val_if_fail (a_this && PRIVATE (a_this) + && a_property && a_expr, + CR_BAD_PARAM_ERROR) ; + + RECORD_INITIAL_POS (a_this, &init_pos) ; + + status = cr_parser_parse_property (a_this, a_property) ; + + CHECK_PARSING_STATUS_ERR + (a_this, status, FALSE, + "while parsing declaration: next property is malformed", + CR_SYNTAX_ERROR) ; + + + READ_NEXT_CHAR (a_this, &cur_char) ; + + if (cur_char != ':') + { + status = CR_PARSING_ERROR ; + cr_parser_push_error + (a_this, + "while parsing declaration: this char must be ':'", + CR_SYNTAX_ERROR) ; + goto error ; + } + + cr_parser_try_to_skip_spaces_and_comments (a_this) ; + + status = cr_parser_parse_expr (a_this, &expr) ; + + CHECK_PARSING_STATUS_ERR + (a_this, status, FALSE, + "while parsing declaration: next expression is malformed", + CR_SYNTAX_ERROR) ; + + if (*a_expr) + { + cr_term_append_term (*a_expr, expr) ; + expr = NULL ; + } + else + { + *a_expr = expr ; + expr = NULL ; + } + + cr_parser_clear_errors (a_this) ; + return CR_OK ; + + error: + + if (expr) + { + cr_term_destroy (expr) ; + expr = NULL ; + } + + if (*a_property) + { + g_string_free (*a_property, TRUE) ; + *a_property = NULL ; + } + + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + + return status ; +} + +/** + *Parses a "ruleset" as defined in the css2 spec at appendix D.1. + *ruleset ::= selector [ ',' S* selector ]* + *'{' S* declaration? [ ';' S* declaration? ]* '}' S*; + * + *This methods calls the the SAC handler on the relevant SAC handler + *callbacks whenever it encounters some specific constructions. + *See the documentation of #CRDocHandler (the SAC handler) to know + *when which SAC handler is called. + *@param a_this the "this pointer" of the current instance of #CRParser. + *@return CR_OK upon successfull completion, an error code otherwise. + */ +enum CRStatus +cr_parser_parse_ruleset (CRParser *a_this) +{ + enum CRStatus status = CR_OK ; + CRInputPos init_pos ; + guint32 cur_char = 0, next_char = 0 ; + GString * property = NULL ; + CRTerm *expr = NULL ; + CRSimpleSel * simple_sels = NULL ; + CRSelector *selector = NULL ; + gboolean start_selector = FALSE ; + + g_return_val_if_fail (a_this, CR_BAD_PARAM_ERROR) ; + + RECORD_INITIAL_POS (a_this, &init_pos) ; + + status = cr_parser_parse_selector (a_this, &selector) ; + CHECK_PARSING_STATUS (status, FALSE) ; + + READ_NEXT_CHAR (a_this, &cur_char) ; + + ENSURE_PARSING_COND_ERR + (a_this, cur_char == '{', + "while parsing rulset: current char should be '{'", + CR_SYNTAX_ERROR) ; + + + if (PRIVATE (a_this)->sac_handler + &&PRIVATE (a_this)->sac_handler->start_selector) + { + /* + *the selector if ref counted so that the parser's user + *can choose to keep it. + */ + if (selector) + { + cr_selector_ref (selector) ; + } + + PRIVATE (a_this)->sac_handler->start_selector + (PRIVATE (a_this)->sac_handler, selector) ; + start_selector = TRUE ; + } + + cr_parser_try_to_skip_spaces_and_comments (a_this) ; + + PRIVATE (a_this)->state = TRY_PARSE_RULESET_STATE ; + + status = cr_parser_parse_declaration (a_this, &property, &expr) ; + + if (expr) + { + cr_term_ref (expr) ; + } + + if ( status == CR_OK + && PRIVATE (a_this)->sac_handler + && PRIVATE (a_this)->sac_handler->property) + { + PRIVATE (a_this)->sac_handler->property + (PRIVATE (a_this)->sac_handler, property, expr) ; + } + + if (status == CR_OK) + { + /* + *free the allocated + *'property' and 'term' before parsing + *next declarations. + */ + if (property) + { + g_string_free (property, TRUE) ; + property = NULL ; + } + + if (expr) + { + cr_term_unref (expr) ; + expr = NULL ; + } + } + + CHECK_PARSING_STATUS_ERR + (a_this, status, FALSE, + "while parsing ruleset: next construction should be a declaration", + CR_SYNTAX_ERROR) ; + + for (;;) + { + PEEK_NEXT_CHAR (a_this, &next_char) ; + if (next_char != ';') break ; + + /*consume the ';' char*/ + READ_NEXT_CHAR (a_this, &cur_char) ; + + cr_parser_try_to_skip_spaces_and_comments (a_this) ; + + status = cr_parser_parse_declaration (a_this, &property, + &expr) ; + if (expr) + { + cr_term_ref (expr) ; + } + + if (status == CR_OK + && PRIVATE (a_this)->sac_handler + && PRIVATE (a_this)->sac_handler->property) + { + PRIVATE (a_this)->sac_handler->property + (PRIVATE (a_this)->sac_handler, + property, expr) ; + } + + if (property) + { + g_string_free (property, TRUE) ; + property = NULL ; + } + + if (expr) + { + cr_term_unref (expr) ; + expr = NULL ; + } + } + + cr_parser_try_to_skip_spaces_and_comments (a_this) ; + + READ_NEXT_CHAR (a_this, &cur_char) ; + + ENSURE_PARSING_COND_ERR + (a_this, cur_char == '}', + "while parsing rulset: current char must be a '}'", + CR_SYNTAX_ERROR) ; + + if (PRIVATE (a_this)->sac_handler + && PRIVATE (a_this)->sac_handler->end_selector) + { + PRIVATE (a_this)->sac_handler->end_selector + (PRIVATE (a_this)->sac_handler, selector) ; + start_selector = FALSE ; + } + + if (expr) + { + cr_term_unref (expr) ; + expr = NULL ; + } + + if (simple_sels) + { + cr_simple_sel_destroy (simple_sels) ; + simple_sels = NULL ; + } + + if (selector) + { + cr_selector_unref (selector) ; + selector = NULL ; + } + + cr_parser_clear_errors (a_this) ; + PRIVATE (a_this)->state = RULESET_PARSED_STATE ; + + return CR_OK ; + + error: + + if (start_selector == TRUE + && PRIVATE (a_this)->sac_handler + && PRIVATE (a_this)->sac_handler->error) + { + PRIVATE (a_this)->sac_handler->error + (PRIVATE (a_this)->sac_handler) ; + } + + if (expr) + { + cr_term_unref (expr) ; + expr = NULL ; + } + + if (simple_sels) + { + cr_simple_sel_destroy (simple_sels) ; + simple_sels = NULL ; + } + + if (property) + { + g_string_free (property, TRUE) ; + } + + if (selector) + { + cr_selector_unref (selector) ; + selector = NULL ; + } + + cr_tknzr_set_cur_pos (PRIVATE (a_this)->tknzr, &init_pos) ; + + return status ; +} + +/** *Creates a new parser to parse data *coming the input stream given in parameter. *@param a_input the input stream of the parser. diff --git a/src/parser/cr-parser.h b/src/parser/cr-parser.h index dc5d881..1455fa8 100644 --- a/src/parser/cr-parser.h +++ b/src/parser/cr-parser.h @@ -73,13 +73,10 @@ cr_parser_new_from_input (CRInput *a_input) ; enum CRStatus cr_parser_set_tknzr (CRParser *a_this, CRTknzr *a_tknzr) ; - enum CRStatus cr_parser_try_to_skip_spaces_and_comments (CRParser *a_this) ; -enum CRStatus -cr_parser_parse_declaration (CRParser *a_this, GString **a_property, - CRTerm **a_expr) ; + enum CRStatus cr_parser_set_sac_handler (CRParser *a_this, CRDocHandler *a_handler) ; @@ -109,6 +106,13 @@ cr_parser_parse_buf (CRParser *a_this, const guchar *a_buf, enum CRStatus cr_parser_set_default_sac_handler (CRParser *a_this) ; + +enum CRStatus +cr_parser_parse_declaration (CRParser *a_this, GString **a_property, + CRTerm **a_expr) ; +enum CRStatus +cr_parser_parse_ruleset (CRParser *a_this) ; + void cr_parser_destroy (CRParser *a_this) ; diff --git a/src/parser/cr-selector.c b/src/parser/cr-selector.c index b35642e..be1a069 100644 --- a/src/parser/cr-selector.c +++ b/src/parser/cr-selector.c @@ -25,6 +25,7 @@ */ #include <string.h> #include "cr-selector.h" +#include "cr-parser.h" /** *Creates a new instance of #CRSelector. @@ -49,6 +50,22 @@ cr_selector_new (CRSimpleSel *a_simple_sel) return result ; } +CRSelector * +cr_selector_parse_from_buf (const guchar * a_char_buf, + enum CREncoding a_enc) +{ + CRParser * parser = NULL ; + + g_return_val_if_fail (a_char_buf, NULL) ; + + parser = cr_parser_new_from_buf (a_char_buf, strlen (a_char_buf), + a_enc, FALSE) ; + g_return_val_if_fail (parser, NULL) ; + + + return NULL ; +} + /** *Appends a new instance of #CRSelector to the current selector list. *@param a_this the current instance of #CRSelector. diff --git a/src/parser/cr-selector.h b/src/parser/cr-selector.h index 2a67ebf..1003fc9 100644 --- a/src/parser/cr-selector.h +++ b/src/parser/cr-selector.h @@ -70,6 +70,10 @@ struct _CRSelector 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_append (CRSelector *a_this, CRSelector *a_new) ; diff --git a/src/parser/cr-statement.c b/src/parser/cr-statement.c index ec29932..8157b7c 100644 --- a/src/parser/cr-statement.c +++ b/src/parser/cr-statement.c @@ -26,7 +26,7 @@ #include <string.h> #include "cr-statement.h" - +#include "cr-parser.h" /** *@file @@ -36,6 +36,88 @@ #define DECLARATION_INDENT_NB 2 static void +cr_statement_clear (CRStatement *a_this) ; + +static void +cr_statement_dump_ruleset (CRStatement *a_this, FILE *a_fp, glong a_indent) ; + +static void +cr_statement_dump_charset (CRStatement *a_this, FILE *a_fp, + gulong a_indent) ; + +static void +cr_statement_dump_page (CRStatement *a_this, FILE *a_fp, gulong a_indent) ; + +static void +cr_statement_dump_media_rule (CRStatement *a_this, FILE *a_fp, + gulong a_indent) ; + +static void +cr_statement_dump_import_rule (CRStatement *a_this, FILE *a_fp, + gulong a_indent) ; + +static void +parse_ruleset_start_selector_cb (CRDocHandler *a_this, + CRSelector *a_sellist) +{ + CRStatement *ruleset = NULL ; + + g_return_if_fail (a_this + && a_this->priv + && a_sellist) ; + + cr_selector_ref (a_sellist) ; + + ruleset = cr_statement_new_ruleset (NULL, a_sellist, + NULL, NULL) ; + g_return_if_fail (ruleset) ; + + cr_doc_handler_set_result (a_this, ruleset) ; +} + +static void +parse_ruleset_property_cb (CRDocHandler *a_this, + GString *a_name, CRTerm *a_value) +{ + enum CRStatus status = CR_OK ; + CRStatement *ruleset = NULL ; + GString * stringue = NULL ; + + g_return_if_fail (a_this && a_this->priv && a_name) ; + + stringue = g_string_new (a_name->str) ; + g_return_if_fail (stringue) ; + + status = cr_doc_handler_get_result (a_this, (gpointer *)&ruleset) ; + g_return_if_fail (status == CR_OK + && ruleset && ruleset->type == RULESET_STMT) ; + + if (a_value) + { + cr_term_ref (a_value) ; + } + + status = cr_statement_ruleset_append_decl2 (ruleset, stringue, a_value) ; + g_return_if_fail (status == CR_OK) ; +} + +static void +parse_ruleset_end_selector_cb (CRDocHandler *a_this, + CRSelector *a_sellist) +{ + CRStatement *result = NULL ; + enum CRStatus status = CR_OK ; + + g_return_if_fail (a_this && a_sellist) ; + + status = cr_doc_handler_get_result (a_this, (gpointer *)&result) ; + + g_return_if_fail (status == CR_OK + && result + && result->type == RULESET_STMT) ; +} + +static void cr_statement_clear (CRStatement *a_this) { g_return_if_fail (a_this) ; @@ -437,6 +519,67 @@ cr_statement_dump_import_rule (CRStatement *a_this, FILE *a_fp, } +/******************* + *public functions + ******************/ + +CRStatement * +cr_statement_ruleset_parse_from_buf (const guchar * a_buf, + enum CREncoding a_enc) +{ + enum CRStatus status = CR_OK ; + CRStatement *result = NULL; + CRParser *parser = NULL ; + CRDocHandler *sac_handler = NULL ; + + g_return_val_if_fail (a_buf, NULL) ; + + parser = cr_parser_new_from_buf (a_buf, strlen (a_buf), + a_enc, FALSE) ; + + g_return_val_if_fail (parser, NULL) ; + + sac_handler = cr_doc_handler_new () ; + g_return_val_if_fail (parser, NULL) ; + + sac_handler->start_selector = parse_ruleset_start_selector_cb ; + sac_handler->end_selector = parse_ruleset_end_selector_cb ; + sac_handler->property = parse_ruleset_property_cb ; + + + cr_parser_set_sac_handler (parser, sac_handler) ; + cr_parser_try_to_skip_spaces_and_comments (parser) ; + cr_parser_parse_ruleset (parser) ; + + status = cr_doc_handler_get_result (sac_handler, + (gpointer*)&result) ; + if (! ((status == CR_OK) && result) ) + { + if (result) + { + cr_statement_destroy (result) ; + result = NULL ; + } + } + +/* cleanup:*/ + if (parser) + { + cr_parser_destroy (parser) ; + parser = NULL ; + } + if (sac_handler) + { + cr_doc_handler_unref (sac_handler) ; + sac_handler = NULL ; + } + return result ; +} + +/********************** + *public functions + **********************/ + /** *Creates a new instance of #CRStatement of type *#CRRulSet. @@ -457,7 +600,7 @@ cr_statement_new_ruleset (CRStyleSheet * a_sheet, { CRStatement *result = NULL ; - g_return_val_if_fail (a_sheet, NULL) ; + g_return_val_if_fail (a_sel_list, NULL) ; if (a_parent_media_rule) { @@ -511,8 +654,6 @@ cr_statement_new_at_media_rule (CRStyleSheet *a_sheet, { CRStatement *result = NULL ; - g_return_val_if_fail (a_sheet, NULL) ; - if (a_rulesets) g_return_val_if_fail (a_rulesets->type == RULESET_STMT, NULL) ; @@ -538,7 +679,11 @@ cr_statement_new_at_media_rule (CRStyleSheet *a_sheet, memset (result->kind.media_rule, 0, sizeof (CRAtMediaRule)) ; result->kind.media_rule->rulesets = a_rulesets ; result->kind.media_rule->media_list = a_media ; - cr_statement_set_parent_sheet (result, a_sheet) ; + + if (a_sheet) + { + cr_statement_set_parent_sheet (result, a_sheet) ; + } return result ; } diff --git a/src/parser/cr-statement.h b/src/parser/cr-statement.h index 4cb2509..06455e3 100644 --- a/src/parser/cr-statement.h +++ b/src/parser/cr-statement.h @@ -57,6 +57,7 @@ struct _CRAtMediaRule ; typedef struct _CRAtMediaRule CRAtMediaRule ; typedef struct _CRRuleSet CRRuleSet ; + /** *The abstraction of a css ruleset. *A ruleset is made of a list of selectors, @@ -281,6 +282,9 @@ CRStatement * cr_statement_unlink (CRStatement *a_this, CRStatement *a_to_unlink) ; +CRStatement * +cr_statement_ruleset_parse_from_buf (const guchar * a_buf, + enum CREncoding a_enc) ; enum CRStatus cr_statement_ruleset_set_sel_list (CRStatement *a_this, CRSelector *a_sel_list) ; diff --git a/src/parser/cr-term.h b/src/parser/cr-term.h index b39817f..3194d0a 100644 --- a/src/parser/cr-term.h +++ b/src/parser/cr-term.h @@ -128,7 +128,7 @@ struct _CRTerm *A spare pointer, just in case. *Can be used by the application. */ - gpointer custom_data ; + gpointer app_data ; glong ref_count ; diff --git a/tests/test4-main.c b/tests/test4-main.c index 83ff06f..c6fbf0f 100644 --- a/tests/test4-main.c +++ b/tests/test4-main.c @@ -35,9 +35,13 @@ CRDocHandler * gv_test_handler = {0} ; -const guchar * gv_decl= +const guchar * gv_decl_buf = "toto: tutu, tata" ; +const guchar *gv_ruleset_buf = +"s1 > s2 {toto: tutu, tata} " +; + static void display_help (char *prg_name) ; @@ -123,7 +127,7 @@ test_cr_declaration_parse (void) guchar * tmp_str = NULL ; CRDeclaration * decl = NULL ; - decl = cr_declaration_parse (NULL, gv_decl, + decl = cr_declaration_parse (NULL, gv_decl_buf, CR_UTF_8) ; tmp_str = cr_declaration_to_string (decl, 2) ; @@ -142,6 +146,24 @@ test_cr_declaration_parse (void) return CR_ERROR ; } +static enum CRStatus +test_cr_statement_ruleset_parse (void) +{ + CRStatement *stmt = NULL ; + + stmt = cr_statement_ruleset_parse_from_buf (gv_ruleset_buf, + CR_UTF_8) ; + g_return_val_if_fail (stmt, CR_ERROR) ; + + if (stmt) + { + cr_statement_destroy (stmt) ; + stmt = NULL ; + } + + return CR_OK ; +} + /** *The entry point of the testing routine. */ @@ -152,13 +174,19 @@ main (int argc, char ** argv) enum CRStatus status = CR_OK ; status = test_cr_declaration_parse () ; + if (status != CR_OK) + { + g_print ("\nKO\n") ; + return 0 ; + } + status = test_cr_statement_ruleset_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) @@ -179,13 +207,11 @@ main (int argc, char ** argv) return 0 ; } - status = test_cr_parser_parse (options.files_list[0]) ; - - + status = test_cr_parser_parse (options.files_list[0]) ; if (status != CR_OK) { g_print ("\nKO\n") ; } - + return 0 ; } |