viewvc-4intranet/tparse/tparsemodule.h

82 lines
2.7 KiB
C
Raw Normal View History

/*
# Copyright (C) 2000-2002 The ViewCVS Group. All Rights Reserved.
# This file has been rewritten in C++ from the rcsparse.py file by
# Lucas Bruand <lucas.bruand@ecl2002.ec-lyon.fr>
#
# By using this file, you agree to the terms and conditions set forth in
# the LICENSE.html file which can be found at the top level of the ViewCVS
# distribution or at http://viewcvs.sourceforge.net/license-1.html.
#
# Contact information:
# Greg Stein, PO Box 760, Palo Alto, CA, 94302
# gstein@lyra.org, http://viewcvs.sourceforge.net/
#
# -----------------------------------------------------------------------
#
# This software is being maintained as part of the ViewCVS project.
# Information is available at:
# http://viewcvs.sourceforge.net/
#
# This file was originally based on portions of the blame.py script by
# Curt Hagenlocher.
#
# -----------------------------------------------------------------------
#
*/
#ifdef __cplusplus
extern "C"
{
#endif
Exception usage cleanup. Use exceptions to terminate the parser in all cases. Also protect pointers with auto_ptr to ensure cleanup. Note: Before this change exceptions *could* occur, but all pointer-referenced memory would be leaked. * tparse/tparse.h: Change #include-s to C++ names. (RCSParseError): Change to be a public descendant of exception. Use string datatype to ensure automatic cleanup. Implement a destructor as required by exception. (RCSExpected): Use string datatype to ensure automatic cleanup. Add constructor for expected characters. (Branche): Removed. Replaced with std::list<>. (Sink): Change method definition to reflect switch to exceptions. (TokenParser::match): Add method for matching characters. (TokenParser::semicol, TokenParser::matchsemicol): Removed. Obsolete because we're now able to match single characters. (tparseParser): Change method definition to reflect the switch to exceptions. (tparseParser::parse): Adapt to changed method definitions. * tparse/tparse.cpp: Change #include-s to C++ names. (TokenParser::get): Space changes and conversion to auto_ptr. (tparseParser::parse_rcs_admin, tparseParser::parse_rcs_description, tparseParser::parse_rcs_deltatext): Conversion to auto_ptr and exceptions. (tparseParser::parse_rcs_tree): Conversion to auto_ptr and exceptions. Also adjust for removal of Branche class. * tparse/tparsemodule.h: Include Python.h, since we,re actually using python types. * tparse/tparsemodule.cpp (pyobject, pystring): New classes. Used to anchor python objects ensuring their refcounts are decremented. (chkpy): New. Function to check python return value and act appropriately. (initparse): Correctly anchor python strings. (rcstoken_to_pystring): Removed. Now integrated into the pystring class. (PythonSink): Claim ownership for the duration of the instance lifetime. Also adjust all methods for the switch to exceptions. (tparse): Adapt to the switch to exceptions. Also prevent memory leakage when an exception occurs. git-svn-id: http://viewvc.tigris.org/svn/viewvc/trunk@1060 8cb11bc2-c004-0410-86c3-e597b4017df7
2005-05-01 17:56:23 +04:00
#include <Python.h>
static char *__doc__ = \
"This python extension module is a binding to the tparse library.\n" \
"tparse is a C++ library that offers an API to a performance-oriented\n" \
"RCSFILE parser.\n" \
"It does little syntax checking.\n" \
"\n" \
"Version: $Id$\n";
static char *__version__ = "0.14";
static char *__date__ = "2002/02/11";
static char *__author__ = "Lucas Bruand <lucas.bruand@ecl2002.ec-lyon.fr>";
//static char *pyRCSStopParser__doc__ =
// "Stop parser exception: to be raised from the sink to abort parsing.";
static PyObject *pyRCSStopParser;
//static char *pyRCSParseError__doc__ =
// "Ancestor Exception";
static PyObject *pyRCSParseError;
//static char *pyRCSIllegalCharacter__doc__ =
// "Parser has encountered an Illegal Character.";
static PyObject *pyRCSIllegalCharacter;
//static char *pyRCSExpected__doc__ =
// "Parse has found something but the expected.";
static PyObject *pyRCSExpected;
static PyObject *PySink; // Sink Class from the common module.
static char *tparse__doc__ = \
"Main function: Parse a file and send the result to the sink.\n" \
"Two ways of invoking this function from python:\n" \
"* tparse.parse(filename, sink)\n" \
"where filename is a string and sink is an instance of the class Sink\n" \
"defined in the common.py module.\n" \
"* tparse.parse(file, sink)\n" \
"where file is a python file and sink is an instance of the class Sink\n" \
"defined in the common.py module.\n";
static PyObject * tparse( PyObject *self, PyObject *args);
/* Init function for this module: Invoked when the module is
imported from Python Load the stopparser expression into the
tparser's namespace */
void inittparse();
#ifdef __cplusplus
}
#endif