Logo Search packages:      
Sourcecode: inkscape version File versions

CRStatement* cr_statement_ruleset_parse_from_buf ( const guchar *  a_buf,
enum CREncoding  a_enc 
)

Parses a buffer that contains a ruleset statement and instanciates a CRStatement of type RULESET_STMT.

Parameters:
a_buf the buffer to parse.
a_enc the character encoding of a_buf.
the newly built instance of CRStatement in case of successful parsing, NULL otherwise.

Definition at line 1034 of file cr-statement.c.

References cr_doc_handler_get_result(), cr_doc_handler_new(), cr_doc_handler_unref(), cr_parser_destroy(), cr_parser_new_from_buf(), cr_parser_parse_ruleset(), cr_parser_set_sac_handler(), cr_parser_try_to_skip_spaces_and_comments(), and cr_statement_destroy().

Referenced by cr_statement_parse_from_buf().

{
        enum CRStatus status = CR_OK;
        CRStatement *result = NULL;
        CRStatement **resultptr = NULL;
        CRParser *parser = NULL;
        CRDocHandler *sac_handler = NULL;

        g_return_val_if_fail (a_buf, NULL);

        parser = cr_parser_new_from_buf ((guchar*)a_buf,
                                             strlen ((char *)a_buf), 
                                         a_enc, FALSE);

        g_return_val_if_fail (parser, NULL);

        sac_handler = cr_doc_handler_new ();
        g_return_val_if_fail (sac_handler, 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;
        sac_handler->unrecoverable_error =
                parse_ruleset_unrecoverable_error_cb;

        cr_parser_set_sac_handler (parser, sac_handler);
        cr_parser_try_to_skip_spaces_and_comments (parser);
        status = cr_parser_parse_ruleset (parser);
        if (status != CR_OK) {
                goto cleanup;
        }

      resultptr = &result;
        status = cr_doc_handler_get_result (sac_handler,
                                            (gpointer *) resultptr);
        if (!((status == CR_OK) && result)) {
                if (result) {
                        cr_statement_destroy (result);
                        result = NULL;
                }
        }

      cleanup:
        if (parser) {
                cr_parser_destroy (parser);
                parser = NULL;
                sac_handler = NULL ;
        }
        if (sac_handler) {
                cr_doc_handler_unref (sac_handler);
                sac_handler = NULL;
        }
        return result;
}


Generated by  Doxygen 1.6.0   Back to index