From b849be0b02d6ffbfb8c10fed07f1c1cc57ff7f4c Mon Sep 17 00:00:00 2001 From: Jan Borsodi Date: Thu, 4 Jan 2001 12:30:20 +0000 Subject: [PATCH] Removed some stupid header text. Implemented functions for returning the error string and starting and stopping the message handler. Added comments for all functions. --- ext/qtdom/qtdom_qt.cpp | 148 +++++++++++++++++++++++++++++++++++++++-- 1 file changed, 143 insertions(+), 5 deletions(-) diff --git a/ext/qtdom/qtdom_qt.cpp b/ext/qtdom/qtdom_qt.cpp index 89b0491fd2..6cc5050e49 100644 --- a/ext/qtdom/qtdom_qt.cpp +++ b/ext/qtdom/qtdom_qt.cpp @@ -1,13 +1,9 @@ // // $Id$ // -// Implementation of ||| class -// // Jan Borsodi // Created on: <09-Nov-2000 11:18:46 root> // -// Copyright (C) 1999-2000 eZ Systems. All rights reserved. -// extern "C" @@ -21,18 +17,50 @@ extern "C" //#if HAVE_QTDOM -// #include "ezxmlparser.hpp" #include #include #include struct qdom_node *qdom_to_node( QDomNode *node ); +/*! + Initialises certain global variables, they are: + g_qdom_message_log : A global variable for handling error logs and message handler function. +*/ + +extern "C" void qdom_init() +{ + g_qdom_message_log = new qdom_message; + g_qdom_message_log->Log = 0; + g_qdom_message_log->OldHandler = 0; +} + +/*! + Frees global variables initialised in the init function. +*/ + +extern "C" void qdom_shutdown() +{ + if ( g_qdom_message_log->Log ) + delete []g_qdom_message_log->Log; + delete g_qdom_message_log; + g_qdom_message_log = 0; +} + +/*! + Copies the version number for Qt into the \c ver variable, + the variable must be allocated by user and must have enough characters (20 should suffice). +*/ + extern "C" void qdom_do_version( char **ver ) { strcpy( *ver, QT_VERSION_STR ); } +/*! + Moves the DOM node to the next sibling if any and returns the node. +*/ + extern "C" struct qdom_node *qdom_do_next_node( struct qdom_node *node ) { QDomNode *q_node = (QDomNode *)node->Q_Node; @@ -56,6 +84,10 @@ extern "C" struct qdom_node *qdom_do_next_node( struct qdom_node *node ) return node; } +/*! + Finds the first child of the current node and returns it if any. +*/ + extern "C" struct qdom_node *qdom_do_first_child( struct qdom_node *node ) { QDomNode *q_node = (QDomNode *)node->Q_Node; @@ -79,6 +111,10 @@ extern "C" struct qdom_node *qdom_do_first_child( struct qdom_node *node ) return node; } +/*! + Returns the number of the children for the current node. +*/ + extern "C" int qdom_do_node_children_count( struct qdom_node *node ) { if ( !node ) @@ -89,6 +125,10 @@ extern "C" int qdom_do_node_children_count( struct qdom_node *node ) return q_node->childNodes().count(); } +/*! + Returns the number of attributes for the current node. +*/ + extern "C" int qdom_do_node_attribute_count( struct qdom_node *node ) { if ( !node ) @@ -99,6 +139,10 @@ extern "C" int qdom_do_node_attribute_count( struct qdom_node *node ) return q_node->attributes().length(); } +/*! + Returns the attribute map for the current node. +*/ + extern "C" struct qdom_attribute *qdom_do_node_attributes( struct qdom_node *node ) { struct qdom_attribute *attr = new struct qdom_attribute; @@ -109,6 +153,10 @@ extern "C" struct qdom_attribute *qdom_do_node_attributes( struct qdom_node *nod return attr; } +/*! + Returns the node at a given index taken from the attribute list if any. +*/ + extern "C" struct qdom_node *qdom_do_attribute_at( struct qdom_attribute *attr, int index ) { if ( !attr ) @@ -120,6 +168,10 @@ extern "C" struct qdom_node *qdom_do_attribute_at( struct qdom_attribute *attr, return qdom_to_node( &node ); } +/*! + Frees an attribute map. +*/ + extern "C" void qdom_do_attributes_free( struct qdom_attribute *attr ) { if ( !attr ) @@ -129,6 +181,10 @@ extern "C" void qdom_do_attributes_free( struct qdom_attribute *attr ) delete attr; } +/*! + Makes a copy of a node. +*/ + extern "C" struct qdom_node *qdom_do_copy_node( struct qdom_node *node ) { if ( !node ) @@ -159,6 +215,10 @@ extern "C" struct qdom_node *qdom_do_copy_node( struct qdom_node *node ) return tmp; } +/*! + Frees a node. +*/ + extern "C" void qdom_do_node_free( struct qdom_node *node ) { if ( !node ) @@ -170,6 +230,10 @@ extern "C" void qdom_do_node_free( struct qdom_node *node ) delete node; } +/*! + Wraps a qdom_node struct around a QDomNode object which can be used by the C code. +*/ + struct qdom_node *qdom_to_node( QDomNode *node ) { if ( !node ) @@ -186,6 +250,11 @@ struct qdom_node *qdom_to_node( QDomNode *node ) return q_node; } +/*! + Copies the doctype name taken from the the qdom_doc object to the + \c name variable, the variable is initialised by the function. +*/ + extern "C" void qdom_do_doc_type( struct qdom_doc *doc, char **name ) { if ( !doc ) @@ -207,6 +276,10 @@ extern "C" void qdom_do_doc_type( struct qdom_doc *doc, char **name ) } } +/*! + Initialises a qdom_doc struct with the string taken from \c arg. +*/ + extern "C" struct qdom_doc *qdom_do_init( const char *arg ) { struct qdom_doc *doc = new struct qdom_doc; @@ -220,6 +293,10 @@ extern "C" struct qdom_doc *qdom_do_init( const char *arg ) return doc; } +/*! + Frees a qdom_doc struct. +*/ + extern "C" void qdom_do_free( struct qdom_doc *doc ) { QDomNode *node = (QDomNode *)doc->CurrentNode; @@ -230,4 +307,65 @@ extern "C" void qdom_do_free( struct qdom_doc *doc ) delete doc; } +/*! + The custom message output used for catching Qt error messages when parsing with QDOM. +*/ + +void qdom_messageOutput( QtMsgType , const char *msg ) +{ + if ( !g_qdom_message_log ) + return; + int msg_len = strlen( msg ); + int log_len = 0; + if ( g_qdom_message_log->Log ) + log_len = strlen( g_qdom_message_log->Log ); + int total_len = log_len+msg_len+2; + char *log = new char[total_len]; + if ( g_qdom_message_log->Log ) + strncpy( log, g_qdom_message_log->Log, log_len ); + strncpy( log+log_len, msg, msg_len ); + log[log_len+msg_len] = '\n'; + log[total_len - 1] = '\0'; + if ( g_qdom_message_log->Log ) + delete []g_qdom_message_log->Log; + g_qdom_message_log->Log = log; +} + +/*! + Installs the custom message handler and clears the log entries. +*/ + +extern "C" void qdom_do_install_message_handler() +{ + if ( !g_qdom_message_log ) + g_qdom_message_log = new qdom_message; + msg_handler *old_handler = new msg_handler; + g_qdom_message_log->OldHandler = (void *)old_handler; + if ( g_qdom_message_log->Log ) + delete []g_qdom_message_log->Log; + g_qdom_message_log->Log = 0; + *old_handler = qInstallMsgHandler( qdom_messageOutput ); +} + +/*! + Frees the custom message handler. +*/ + +extern "C" void qdom_do_free_message_handler() +{ + msg_handler *old_handler = (msg_handler *)g_qdom_message_log->OldHandler; + qInstallMsgHandler( *old_handler ); +} + +/*! + Returns the string containg the error log, or 0 if no log is available. +*/ + +extern "C" char *qdom_error_log() +{ + if ( !g_qdom_message_log ) + return 0; + return g_qdom_message_log->Log; +} + //#endif // HAVE_QTDOM -- 2.50.1