You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@xerces.apache.org by ja...@apache.org on 2001/04/16 19:54:00 UTC
cvs commit: xml-xerces/perl/New_classes_perl perlDefaultHandler.cpp perlDefaultHandler.hpp perlDefaultHandler.swig.hpp
jasons 01/04/16 10:54:00
Added: perl/New_classes_perl perlDefaultHandler.cpp
perlDefaultHandler.hpp perlDefaultHandler.swig.hpp
Log:
* New_classes_perl/perlDefaultHandler.hpp (Repository):
Perl interface to DefaultHandler
Revision Changes Path
1.1 xml-xerces/perl/New_classes_perl/perlDefaultHandler.cpp
Index: perlDefaultHandler.cpp
===================================================================
#include <stdlib.h>
#include "perlDefaultHandler.hpp"
#include "util/XMLString.hpp"
#include "sax/AttributeList.hpp"
perlDefaultHandler::perlDefaultHandler() {
startElementFunction = NULL;
charactersFunction = NULL;
ignorableWhitespaceFunction = NULL;
}
perlDefaultHandler::~perlDefaultHandler() {
if (startElementFunction) {
SvREFCNT_dec(startElementFunction);
}
if (ignorableWhitespaceFunction) {
SvREFCNT_dec(ignorableWhitespaceFunction);
}
if (charactersFunction) {
SvREFCNT_dec(charactersFunction);
}
}
void
perlDefaultHandler::setIgnorableWhitespaceFunction(SV *function) {
if (SvTYPE( SvRV(function)) == SVt_PVCV) {
SvREFCNT_inc(function);
ignorableWhitespaceFunction = function;
} else {
fprintf(stderr, "setIgnorableWhitespaceFunction: invalid argument for setCharacterFunction, must be code reference\n");
}
}
void
perlDefaultHandler::setCharactersFunction(SV *function) {
if (SvTYPE( SvRV(function)) == SVt_PVCV) {
SvREFCNT_inc(function);
charactersFunction = function;
} else {
fprintf(stderr, "setCharactersFunction: invalid argument for setCharacterFunction, must be code reference\n");
}
}
void
perlDefaultHandler::setStartElementFunction(SV *function) {
if (SvTYPE( SvRV(function)) == SVt_PVCV) {
SvREFCNT_inc(function);
startElementFunction = function;
} else {
fprintf(stderr, "StartElement: invalid argument for set_StartElementFunction, must be code reference\n");
}
}
void
perlDefaultHandler::startElement(
const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname
, const Attributes& attrs)
{
if (!startElementFunction) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first argument is the uri
char *cptr1 = XMLString::transcode(uri);
SV *string1 = sv_newmortal();
sv_setpv(string1, (char *)cptr1);
XPUSHs(string1);
// next argument is the localname
char *cptr2 = XMLString::transcode(localname);
SV *string2 = sv_newmortal();
sv_setpv(string2, (char *)cptr2);
XPUSHs(string2);
// next argument is the qname
char *cptr3 = XMLString::transcode(qname);
SV *string3 = sv_newmortal();
sv_setpv(string3, (char *)cptr3);
XPUSHs(string3);
// next is the attribute list
char *class_name = "XML::Xerces::Attributes";
HV *hash = newHV();
HV *stash = gv_stashpv(class_name, FALSE);
hv_magic(hash,
(GV *)sv_setref_pv(sv_newmortal(),
class_name, (void *)&attrs),
'P');
XPUSHs(sv_bless(newRV_noinc((SV *)hash), stash));
PUTBACK;
perl_call_sv(startElementFunction, G_VOID);
FREETMPS;
LEAVE;
}
void
perlDefaultHandler::characters(const XMLCh* const chars,
const unsigned int length)
{
if (!charactersFunction) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first argument is the element name
char *cptr = XMLString::transcode(chars);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
// next is the length
XPUSHs(sv_2mortal(newSViv(length)));
PUTBACK;
perl_call_sv(charactersFunction, G_VOID);
FREETMPS;
LEAVE;
}
void
perlDefaultHandler::ignorableWhitespace(const XMLCh* const chars,
const unsigned int length)
{
if (!ignorableWhitespaceFunction) return;
dSP;
ENTER;
SAVETMPS;
PUSHMARK(SP);
// first argument is the element name
char *cptr = XMLString::transcode(chars);
SV *string = sv_newmortal();
sv_setpv(string, (char *)cptr);
XPUSHs(string);
// next is the length
XPUSHs(sv_2mortal(newSViv(length)));
PUTBACK;
perl_call_sv(ignorableWhitespaceFunction, G_VOID);
FREETMPS;
LEAVE;
}
void perlDefaultHandler::resetDocument(void){}
1.1 xml-xerces/perl/New_classes_perl/perlDefaultHandler.hpp
Index: perlDefaultHandler.hpp
===================================================================
#ifdef __cplusplus
/* Needed on some windows machines---since MS plays funny
games with the header files under C++ */
#include <math.h>
#include <stdlib.h>
extern "C" {
#endif
#include "EXTERN.h"
#include "perl.h"
#include "XSUB.h"
/* Get rid of free and malloc defined by perl */
#undef free
#undef malloc
#include <string.h>
#ifdef __cplusplus
}
#endif
#if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
#ifndef PL_sv_yes
#define PL_sv_yes PL_sv_yes
#endif
#ifndef PL_sv_undef
#define PL_sv_undef PL_sv_undef
#endif
#ifndef PL_na
#define PL_na PL_na
#endif
#endif
#include "sax2/DefaultHandler.hpp"
class Attributes;
class perlDefaultHandler : public DefaultHandler {
private:
SV *startElementFunction;
SV *charactersFunction;
SV *ignorableWhitespaceFunction;
public:
perlDefaultHandler();
~perlDefaultHandler();
void setStartElementFunction(SV *function);
void setIgnorableWhitespaceFunction(SV *function);
void setCharactersFunction(SV *function);
virtual void startElement
(
const XMLCh* const uri,
const XMLCh* const localname,
const XMLCh* const qname
, const Attributes& attrs
);
void characters(const XMLCh* const chars, const unsigned int length);
void ignorableWhitespace(const XMLCh* const chars, const unsigned int length);
void resetDocument(void);
};
1.1 xml-xerces/perl/New_classes_perl/perlDefaultHandler.swig.hpp
Index: perlDefaultHandler.swig.hpp
===================================================================
// #ifdef __cplusplus
// /* Needed on some windows machines---since MS plays funny
// games with the header files under C++ */
// #include <math.h>
// #include <stdlib.h>
// extern "C" {
// #endif
// #include "EXTERN.h"
// #include "perl.h"
// #include "XSUB.h"
//
// /* Get rid of free and malloc defined by perl */
// #undef free
// #undef malloc
//
// #include <string.h>
// #ifdef __cplusplus
// }
// #endif
//
// #if !defined(PERL_REVISION) || ((PERL_REVISION >= 5) && ((PERL_VERSION < 5) || ((PERL_VERSION == 5) && (PERL_SUBVERSION < 50))))
// #ifndef PL_sv_yes
// #define PL_sv_yes PL_sv_yes
// #endif
// #ifndef PL_sv_undef
// #define PL_sv_undef PL_sv_undef
// #endif
// #ifndef PL_na
// #define PL_na PL_na
// #endif
// #endif
//
// #include "sax2/DefaultHandler.hpp"
// class Attributes;
class perlDefaultHandler : public DefaultHandler {
private:
// SV *startElementFunction;
// SV *charactersFunction;
// SV *ignorableWhitespaceFunction;
public:
perlDefaultHandler();
~perlDefaultHandler();
void setStartElementFunction(SV *function);
void setIgnorableWhitespaceFunction(SV *function);
void setCharactersFunction(SV *function);
virtual void startElement
(
const XMLCh* /*const*/ uri,
const XMLCh* /*const*/ localname,
const XMLCh* /*const*/ qname
, const Attributes& attrs
);
void characters(const XMLCh* /*const*/ chars, const unsigned int length);
void ignorableWhitespace(const XMLCh* /*const*/ chars, const unsigned int length);
void resetDocument(void);
};
---------------------------------------------------------------------
To unsubscribe, e-mail: xerces-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xerces-cvs-help@xml.apache.org