From 77829f9487e2105ced78dcb1f7378cbe26c9e1c1 Mon Sep 17 00:00:00 2001 From: Linas Vepstas Date: Sun, 30 Dec 2001 21:17:47 +0000 Subject: [PATCH] gratuitous rearrangement of parenthesis. git-svn-id: svn+ssh://svn.gnucash.org/repo/gnucash/trunk@6429 57a11ea4-9604-0410-9ed3-97b8803252fd --- src/backend/file/sixtp.c | 147 +++++++++++++++++++++++++-------------- 1 file changed, 95 insertions(+), 52 deletions(-) diff --git a/src/backend/file/sixtp.c b/src/backend/file/sixtp.c index 93b1184f8c..4278d9b954 100644 --- a/src/backend/file/sixtp.c +++ b/src/backend/file/sixtp.c @@ -1,6 +1,6 @@ /******************************************************************** * sixtp.c -- functions for XML parsing * - * Copyright 2001 Gnumatic, Inc. * + * Copyright (c) 2001 Gnumatic, Inc. * * * * This program is free software; you can redistribute it and/or * * modify it under the terms of the GNU General Public License as * @@ -39,20 +39,24 @@ static short module = MOD_IO; /************************************************************************/ gboolean -is_child_result_from_node_named(sixtp_child_result *cr, const char *tag) { +is_child_result_from_node_named(sixtp_child_result *cr, const char *tag) +{ return((cr->type == SIXTP_CHILD_RESULT_NODE) && (safe_strcmp(cr->tag, tag) == 0)); } void -sixtp_child_free_data(sixtp_child_result *result) { +sixtp_child_free_data(sixtp_child_result *result) +{ if(result->data) g_free(result->data); } void -sixtp_child_result_destroy(sixtp_child_result *r) { - if(r->should_cleanup && r->cleanup_handler) { +sixtp_child_result_destroy(sixtp_child_result *r) +{ + if(r->should_cleanup && r->cleanup_handler) + { r->cleanup_handler(r); } if(r->type == SIXTP_CHILD_RESULT_NODE) g_free(r->tag); @@ -60,7 +64,8 @@ sixtp_child_result_destroy(sixtp_child_result *r) { } void -sixtp_child_result_print(sixtp_child_result *cr, FILE *f) { +sixtp_child_result_print(sixtp_child_result *cr, FILE *f) +{ fprintf(f, "((tag %s) (data %p))", cr->tag ? cr->tag : "(null)", cr->data); @@ -70,39 +75,44 @@ sixtp_child_result_print(sixtp_child_result *cr, FILE *f) { void -sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler) { +sixtp_set_start(sixtp *parser, sixtp_start_handler start_handler) +{ parser->start_handler = start_handler; } void -sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler) { +sixtp_set_before_child(sixtp *parser, sixtp_before_child_handler handler) +{ parser->before_child = handler; } void -sixtp_set_after_child(sixtp *parser, sixtp_after_child_handler handler) { +sixtp_set_after_child(sixtp *parser, sixtp_after_child_handler handler) +{ parser->after_child = handler; } void -sixtp_set_end(sixtp *parser, sixtp_end_handler end_handler) { +sixtp_set_end(sixtp *parser, sixtp_end_handler end_handler) +{ parser->end_handler = end_handler; } void -sixtp_set_chars(sixtp *parser, sixtp_characters_handler char_handler) { +sixtp_set_chars(sixtp *parser, sixtp_characters_handler char_handler) +{ parser->characters_handler = char_handler; } void -sixtp_set_cleanup_result(sixtp *parser, - sixtp_result_handler handler) { +sixtp_set_cleanup_result(sixtp *parser, sixtp_result_handler handler) +{ parser->cleanup_result = handler; } void -sixtp_set_cleanup_chars(sixtp *parser, - sixtp_result_handler handler) { +sixtp_set_cleanup_chars(sixtp *parser, sixtp_result_handler handler) +{ parser->cleanup_chars = handler; } @@ -113,19 +123,20 @@ sixtp_set_fail(sixtp *parser, } void -sixtp_set_result_fail(sixtp *parser, - sixtp_result_handler handler) { +sixtp_set_result_fail(sixtp *parser, sixtp_result_handler handler) +{ parser->result_fail_handler = handler; } void -sixtp_set_chars_fail(sixtp *parser, - sixtp_result_handler handler) { +sixtp_set_chars_fail(sixtp *parser, sixtp_result_handler handler) +{ parser->chars_fail_handler = handler; } sixtp * -sixtp_new(void) { +sixtp_new(void) +{ sixtp *s = g_new0(sixtp, 1); if(s) { @@ -225,7 +236,8 @@ static void sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data); static void -sixtp_destroy_node(sixtp *sp, GHashTable *corpses) { +sixtp_destroy_node(sixtp *sp, GHashTable *corpses) +{ g_return_if_fail(sp); g_return_if_fail(corpses); g_hash_table_foreach(sp->children, sixtp_destroy_child, corpses); @@ -234,7 +246,8 @@ sixtp_destroy_node(sixtp *sp, GHashTable *corpses) { } static void -sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) { +sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) +{ GHashTable *corpses = (GHashTable *) user_data; sixtp *child = (sixtp *) value; gpointer lookup_key; @@ -244,19 +257,22 @@ sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) { key ? (char *) key : "(null)"); g_free(key); - if(!corpses) { + if(!corpses) + { PERR("no corpses in sixtp_destroy_child <%s>\n", key ? (char *) key : "(null)"); return; } - if(!child) { + if(!child) + { PERR("no child in sixtp_destroy_child <%s>\n", key ? (char *) key : ""); return; } if(!g_hash_table_lookup_extended(corpses, (gconstpointer) child, - &lookup_key, &lookup_value)) { + &lookup_key, &lookup_value)) + { /* haven't killed this one yet. */ g_hash_table_insert(corpses, child, (gpointer) 1); sixtp_destroy_node(child, corpses); @@ -264,7 +280,8 @@ sixtp_destroy_child(gpointer key, gpointer value, gpointer user_data) { } void -sixtp_destroy(sixtp *sp) { +sixtp_destroy(sixtp *sp) +{ GHashTable *corpses; g_return_if_fail(sp); corpses = g_hash_table_new(g_direct_hash, g_direct_equal); @@ -276,7 +293,8 @@ sixtp_destroy(sixtp *sp) { /***********************************************************************/ gboolean -sixtp_add_sub_parser(sixtp *parser, const gchar* tag, sixtp *sub_parser) { +sixtp_add_sub_parser(sixtp *parser, const gchar* tag, sixtp *sub_parser) +{ g_return_val_if_fail(parser, FALSE); g_return_val_if_fail(tag, FALSE); g_return_val_if_fail(sub_parser, FALSE); @@ -352,7 +370,8 @@ sixtp_add_some_sub_parsers(sixtp *tochange, int cleanup, ...) void sixtp_sax_start_handler(void *user_data, const xmlChar *name, - const xmlChar **attrs) { + const xmlChar **attrs) +{ sixtp_sax_data *pdata = (sixtp_sax_data *) user_data; sixtp_stack_frame *current_frame = NULL; sixtp *current_parser = NULL; @@ -378,7 +397,8 @@ sixtp_sax_start_handler(void *user_data, (gpointer) &next_parser_tag, (gpointer) &next_parser); - if(!lookup_success) { + if(!lookup_success) + { /* magic catch all value */ lookup_success = g_hash_table_lookup_extended( current_parser->children, SIXTP_MAGIC_CATCHER, @@ -392,11 +412,13 @@ sixtp_sax_start_handler(void *user_data, } } - if(current_frame->parser->before_child) { + if(current_frame->parser->before_child) + { GSList *parent_data_from_children = NULL; gpointer parent_data_for_children = NULL; - if(g_slist_length(pdata->stack) > 1) { + if(g_slist_length(pdata->stack) > 1) + { /* we're not in the top level node */ sixtp_stack_frame *parent_frame = (sixtp_stack_frame *) pdata->stack->next->data; @@ -422,7 +444,8 @@ sixtp_sax_start_handler(void *user_data, pdata->stack = g_slist_prepend(pdata->stack, (gpointer) new_frame); - if(next_parser->start_handler) { + if(next_parser->start_handler) + { pdata->parsing_ok = next_parser->start_handler(current_frame->data_from_children, current_frame->data_for_children, @@ -435,7 +458,8 @@ sixtp_sax_start_handler(void *user_data, } void -sixtp_sax_characters_handler(void *user_data, const xmlChar *text, int len) { +sixtp_sax_characters_handler(void *user_data, const xmlChar *text, int len) +{ sixtp_sax_data *pdata = (sixtp_sax_data *) user_data; sixtp_stack_frame *frame; @@ -447,7 +471,8 @@ sixtp_sax_characters_handler(void *user_data, const xmlChar *text, int len) { } frame = (sixtp_stack_frame *) pdata->stack->data; - if(frame->parser->characters_handler) { + if(frame->parser->characters_handler) + { gpointer result = NULL; pdata->parsing_ok = @@ -457,8 +482,8 @@ sixtp_sax_characters_handler(void *user_data, const xmlChar *text, int len) { &result, text, len); - if(pdata->parsing_ok) { - if(result) { + if(pdata->parsing_ok && result) + { /* push the result onto the current "child" list. */ sixtp_child_result *child_data = g_new0(sixtp_child_result, 1); @@ -470,13 +495,13 @@ sixtp_sax_characters_handler(void *user_data, const xmlChar *text, int len) { child_data->fail_handler = frame->parser->chars_fail_handler; frame->data_from_children = g_slist_prepend(frame->data_from_children, child_data); - } } } } void -sixtp_sax_end_handler(void *user_data, const xmlChar *name) { +sixtp_sax_end_handler(void *user_data, const xmlChar *name) +{ sixtp_sax_data *pdata = (sixtp_sax_data *) user_data; sixtp_stack_frame *current_frame; sixtp_stack_frame *parent_frame; @@ -495,13 +520,16 @@ sixtp_sax_end_handler(void *user_data, const xmlChar *name) { /* time to make sure we got the right closing tag. Is this really necessary? */ - if(safe_strcmp(current_frame->tag, name) != 0) { + if(safe_strcmp(current_frame->tag, name) != 0) + { + PWARN ("bad closing tag"); pdata->parsing_ok = FALSE; return; } /* tag's OK, proceed. */ - if(current_frame->parser->end_handler) { + if(current_frame->parser->end_handler) + { pdata->parsing_ok = current_frame->parser->end_handler(current_frame->data_for_children, current_frame->data_from_children, @@ -514,7 +542,8 @@ sixtp_sax_end_handler(void *user_data, const xmlChar *name) { g_return_if_fail(pdata->parsing_ok); - if(current_frame->frame_data) { + if(current_frame->frame_data) + { /* push the result onto the parent's child result list. */ child_result_data = g_new(sixtp_child_result, 1); @@ -545,12 +574,14 @@ sixtp_sax_end_handler(void *user_data, const xmlChar *name) { parent_frame = (sixtp_stack_frame *) ((g_slist_length(pdata->stack) > 1) ? (pdata->stack->next->data) : NULL); - if(current_frame->parser->after_child) { + if(current_frame->parser->after_child) + { /* reset pointer after stack pop */ GSList *parent_data_from_children = NULL; gpointer parent_data_for_children = NULL; - if(parent_frame) { + if(parent_frame) + { /* we're not in the top level node */ sixtp_stack_frame *parent_frame = (sixtp_stack_frame *) pdata->stack->next->data; @@ -574,13 +605,15 @@ sixtp_sax_end_handler(void *user_data, const xmlChar *name) { } xmlEntityPtr -sixtp_sax_get_entity_handler(void *user_data, const CHAR *name) { +sixtp_sax_get_entity_handler(void *user_data, const CHAR *name) +{ return xmlGetPredefinedEntity(name); } void -sixtp_handle_catastrophe(sixtp_sax_data *sax_data) { +sixtp_handle_catastrophe(sixtp_sax_data *sax_data) +{ /* Something has gone wrong. To handle it, we have to traverse the stack, calling, at each level, the frame failure handler (the handler for the current, unfinished block) and then the sibling @@ -595,19 +628,24 @@ sixtp_handle_catastrophe(sixtp_sax_data *sax_data) { PERR("parse failed at \n"); sixtp_print_frame_stack(sax_data->stack, stderr); - while(*stack) { + while(*stack) + { sixtp_stack_frame *current_frame = (sixtp_stack_frame *) (*stack)->data; /* cleanup the current frame */ - if(current_frame->parser->fail_handler) { + if(current_frame->parser->fail_handler) + { GSList *sibling_data; gpointer parent_data; - if((*stack)->next == NULL) { + if((*stack)->next == NULL) + { /* This is the top of the stack... */ parent_data = NULL; sibling_data = NULL; - } else { + } + else + { sixtp_stack_frame *parent_frame = (sixtp_stack_frame *) (*stack)->next->data; parent_data = parent_frame->data_for_children; @@ -624,14 +662,17 @@ sixtp_handle_catastrophe(sixtp_sax_data *sax_data) { } /* now cleanup any children's results */ - for(lp = current_frame->data_from_children; lp; lp = lp->next) { + for(lp = current_frame->data_from_children; lp; lp = lp->next) + { sixtp_child_result *cresult = (sixtp_child_result *) lp->data; - if(cresult->fail_handler) { + if(cresult->fail_handler) + { cresult->fail_handler(cresult); } } - if((*stack)->next == NULL) { + if((*stack)->next == NULL) + { /* This is the top of the stack. The top frame seems to want to * be destroyed by sixtp_context_destroy. */ break; @@ -811,3 +852,5 @@ gnc_is_our_xml_file(const char *filename, const char *first_tag) return FALSE; } + +/************************* END OF FILE *********************************/