コード例 #1
0
static sixtp*
gnc_pricedb_parser_new(void)
{
    sixtp *top_level;
    sixtp *price_parser;

    top_level =
        sixtp_set_any(sixtp_new(), TRUE,
                      SIXTP_START_HANDLER_ID, pricedb_start_handler,
                      SIXTP_AFTER_CHILD_HANDLER_ID, pricedb_after_child_handler,
                      SIXTP_CHARACTERS_HANDLER_ID,
                      allow_and_ignore_only_whitespace,
                      SIXTP_RESULT_FAIL_ID, pricedb_cleanup_result_handler,
                      SIXTP_CLEANUP_RESULT_ID, pricedb_cleanup_result_handler,
                      SIXTP_NO_MORE_HANDLERS);

    if (!top_level) return NULL;

    price_parser = gnc_price_parser_new();

    if (!price_parser)
    {
        sixtp_destroy(top_level);
        return NULL;
    }

    sixtp_add_sub_parser(top_level, "price", price_parser);

    return top_level;
}
コード例 #2
0
sixtp *
generic_timespec_parser_new(sixtp_end_handler end_handler)
{
    sixtp *top_level =
        sixtp_set_any(sixtp_new(), FALSE,
                      SIXTP_START_HANDLER_ID, generic_timespec_start_handler,
                      SIXTP_CHARACTERS_HANDLER_ID, allow_and_ignore_only_whitespace,
                      SIXTP_END_HANDLER_ID, end_handler,
                      SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
                      SIXTP_FAIL_HANDLER_ID, generic_free_data_for_children,
                      SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
                      SIXTP_NO_MORE_HANDLERS);
    g_return_val_if_fail(top_level, NULL);

    if (!sixtp_add_some_sub_parsers(
                top_level, TRUE,
                "s", timespec_sixtp_new(generic_timespec_secs_end_handler),
                "ns", timespec_sixtp_new(generic_timespec_nsecs_end_handler),
                0))
    {
        return NULL;
    }

    return(top_level);
}
コード例 #3
0
ファイル: test-dom-parser1.cpp プロジェクト: Isendir/gnucash
static sixtp*
simple_parser(void)
{
    sixtp*ret;
    ret = sixtp_new();
    sixtp_set_chars(ret, allow_and_ignore_only_whitespace);
    return ret;
}
コード例 #4
0
void
test_files_in_dir(int argc, char **argv, gxpf_callback cb,
                  sixtp *parser, const char *parser_tag,
                  QofBook *book)
{
    int count;
    sixtp *main_parser;
    sixtp *top_parser;


    top_parser = sixtp_new();
    main_parser = sixtp_new();

    if (!sixtp_add_some_sub_parsers(top_parser, TRUE, "gnc-v2", main_parser,
                                    NULL, NULL))
        return;

    if (!sixtp_add_some_sub_parsers(main_parser, TRUE, parser_tag, parser,
                                    NULL, NULL))
        return;


    for (count = 1; count < argc; count++)
    {
        struct stat file_info;
        const char *to_open = argv[count];
        if (g_stat(to_open, &file_info) != 0)
        {
            printf("cannot stat %s.\n", to_open);
            failure("unable to stat file");
        }
        else
        {
            if (!S_ISDIR(file_info.st_mode))
            {
#ifdef __DEBUG
                printf( "testing load of file \"%s\":\n", argv[count] );
#endif
                test_load_file(to_open, cb, top_parser, book);
            }
        }
    }

    sixtp_destroy(top_parser);
}
コード例 #5
0
static void
test_db (GNCPriceDB* db)
{
    xmlNodePtr test_node;
    gchar* filename1;
    int fd;
    QofBook* book = qof_instance_get_book (QOF_INSTANCE (db));

    test_node = gnc_pricedb_dom_tree_create (db);

    if (!test_node && db)
    {
        failure_args ("pricedb_xml", __FILE__, __LINE__,
                      "gnc_pricedb_dom_tree_create returned NULL");
        return;
    }

    if (!db)
        return;

    filename1 = g_strdup_printf ("test_file_XXXXXX");

    fd = g_mkstemp (filename1);

    write_dom_node_to_file (test_node, fd);

    close (fd);

    {
        sixtp *parser;
	load_counter lc = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0};
        sixtp_gdv2 data = {book, lc, NULL, NULL, FALSE};

        parser = sixtp_new ();

        if (!sixtp_add_some_sub_parsers
            (parser, TRUE,
             "gnc:pricedb", gnc_pricedb_sixtp_parser_create (),
             NULL, NULL))
        {
            failure_args ("sixtp_add_some_sub_parsers failed",
                          __FILE__, __LINE__, "%d", iter);
        }
        else if (!gnc_xml_parse_file (parser, filename1, test_add_pricedb,
                                      (gpointer)&data,
                                      qof_session_get_book (session)))
        {
            failure_args ("gnc_xml_parse_file returned FALSE",
                          __FILE__, __LINE__, "%d", iter);
        }
    }

    g_unlink (filename1);
    g_free (filename1);
    xmlFreeNode (test_node);
}
コード例 #6
0
sixtp*
restore_char_generator(sixtp_end_handler ender)
{
    return sixtp_set_any(
               sixtp_new(), FALSE,
               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
               SIXTP_END_HANDLER_ID, ender,
               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
               SIXTP_NO_MORE_HANDLERS);
}
コード例 #7
0
sixtp*
generic_gnc_numeric_parser_new(void)
{
    return sixtp_set_any(
               sixtp_new(), FALSE,
               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
               SIXTP_END_HANDLER_ID, generic_gnc_numeric_end_handler,
               SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
               SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
               SIXTP_NO_MORE_HANDLERS);
}
コード例 #8
0
ファイル: test-dom-parser1.cpp プロジェクト: Isendir/gnucash
static sixtp*
get_parser1_1_parser1(void)
{
    sixtp *ret;

    ret = sixtp_new();
    g_return_val_if_fail(ret, NULL);
    sixtp_set_chars(ret, allow_and_ignore_only_whitespace);

    sixtp_add_sub_parser(ret, "foobar",
                         sixtp_dom_parser_new(print_dom_tree, NULL, NULL));

    return ret;
}
コード例 #9
0
sixtp*
simple_chars_only_parser_new(sixtp_end_handler end_handler)
{
    return sixtp_set_any(
               sixtp_new(), FALSE,
               SIXTP_END_HANDLER_ID, (end_handler
                                      ? end_handler
                                      : generic_return_chars_end_handler),
               SIXTP_CHARACTERS_HANDLER_ID, generic_accumulate_chars,
               SIXTP_CLEANUP_RESULT_ID, sixtp_child_free_data,
               SIXTP_CLEANUP_CHARS_ID, sixtp_child_free_data,
               SIXTP_RESULT_FAIL_ID, sixtp_child_free_data,
               SIXTP_CHARS_FAIL_ID, sixtp_child_free_data,
               SIXTP_NO_MORE_HANDLERS);
}