repr-io.cpp revision 58907c44e360596b34a9ab0826b8af201cdb2247
#define __SP_REPR_IO_C__
/*
* Dirty DOM-like tree
*
* Authors:
* Lauris Kaplinski <lauris@kaplinski.com>
* bulia byak <buliabyak@users.sf.net>
*
* Copyright (C) 1999-2002 Lauris Kaplinski
*
* Released under GNU GPL, read the file 'COPYING' for more information
*/
#ifdef HAVE_CONFIG_H
# include <config.h>
#endif
#include <cstring>
#include <string>
#include <stdexcept>
#include "xml/attribute-record.h"
#include "xml/rebase-hrefs.h"
#include "xml/simple-document.h"
#include "io/uristream.h"
#include "io/stringstream.h"
#include "io/gzipstream.h"
#include "extension/extension.h"
#include "preferences.h"
static Node *sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map);
static gint sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar *default_ns, GHashTable *prefix_map);
int inlineattrs, int indent,
gchar const *old_href_abs_base,
gchar const *new_href_abs_base);
int inlineattrs, int indent,
gchar const *old_href_abs_base,
gchar const *new_href_abs_base);
#ifdef HAVE_LIBWMF
static char * sp_wmf_image_name (void * context);
#endif /* HAVE_LIBWMF */
class XmlSource
{
public:
: filename(0),
encoding(0),
fp(0),
firstFewLen(0),
dummy("x"),
instr(0),
gzin(0)
{
}
virtual ~XmlSource()
{
close();
if ( encoding ) {
encoding = 0;
}
}
char const* getEncoding() const { return encoding; }
int close();
private:
const char* filename;
char* encoding;
unsigned char firstFew[4];
int firstFewLen;
};
{
int retVal = -1;
if ( fp ) {
// First peek in the file to see what it is
if ( fp ) {
// first check for compression
//g_message(" the file being read is gzip'd. extract it");
fp = 0;
some = 0;
int single = 0;
{
if ( single >= 0 ) {
} else {
break;
}
}
}
int encSkip = 0;
encSkip = 2;
encSkip = 2;
} else if ( (some >= 3) && (firstFew[0] == 0xef) && (firstFew[1] == 0xbb) && (firstFew[2] == 0xbf) ) {
encSkip = 3;
}
if ( encSkip ) {
}
firstFewLen = some;
retVal = 0; // no error
}
}
return retVal;
}
{
int retVal = -1;
if ( context ) {
}
return retVal;
}
{
if ( context ) {
}
return 0;
}
{
int retVal = 0;
if ( firstFewLen > 0 ) {
if ( len < firstFewLen ) {
}
firstFewLen -= some;
} else if ( gzin ) {
int single = 0;
{
if ( single >= 0 ) {
} else {
break;
}
}
} else {
}
retVal = -1;
} else {
}
return retVal;
}
{
if ( gzin ) {
delete gzin;
gzin = 0;
}
if ( instr ) {
fp = 0;
delete instr;
instr = 0;
}
if ( fp ) {
fp = 0;
}
return 0;
}
/**
* Reads XML from a file, including WMF files, and returns the Document.
* The default namespace can also be specified, if desired.
*/
Document *
{
/* fixme: A file can disappear at any time, including between now and when we actually try to
* open it. Get rid of the above test once we're sure that we correctly handle
* non-existence. */
// TODO: bulia, please look over
gsize bytesWritten = 0;
// TODO: need to replace with our own fopen and reading
#ifdef HAVE_LIBWMF
}
}
#endif // !HAVE_LIBWMF
if ( !doc ) {
&src,
src.getEncoding(),
}
}
if ( doc ) {
xmlFreeDoc( doc );
}
if ( localFilename ) {
g_free( localFilename );
}
return rdoc;
}
/**
* Reads and parses XML from a buffer, returning it as an Document
*/
Document *
{
if (doc) {
xmlFreeDoc (doc);
}
return rdoc;
}
/**
* Reads and parses XML from a buffer, returning it as an Document
*/
Document *
{
}
namespace Inkscape {
struct compare_quark_ids {
}
};
}
namespace {
static PrefixMap prefix_map;
} else {
if (prefix_end) {
return prefix;
} else {
return GQuark(0);
}
}
}
}
namespace {
}
}
}
}
}
/**
* Reads in a XML file to create a Document
*/
Document *
{
return NULL;
}
return NULL;
}
if (!root) {
} else {
break;
}
}
}
/* promote elements of some XML documents that don't use namespaces
* into their default namespace */
}
}
}
}
return rdoc;
}
sp_repr_qualified_name (gchar *p, gint len, xmlNsPtr ns, const xmlChar *name, const gchar */*default_ns*/, GHashTable *prefix_map)
{
prefix = reinterpret_cast<const xmlChar*>( sp_xml_ns_uri_prefix(reinterpret_cast<const gchar*>(ns->href),
} else {
}
if (prefix) {
} else {
}
}
static Node *
sp_repr_svg_read_node (Document *xml_doc, xmlNodePtr node, const gchar *default_ns, GHashTable *prefix_map)
{
gchar c[256];
return NULL; // empty text node
}
xmlChar *p;
; // skip all whitespace
if (!(*p)) { // this is an all-whitespace node, and preserve == default
return NULL; // we do not preserve all-whitespace nodes unless we are asked to
}
}
}
}
return NULL;
}
/* TODO remember node->ns->prefix if node->ns != NULL */
/* TODO remember prop->ns->prefix if prop->ns != NULL */
}
}
}
if (crepr) {
}
}
return repr;
}
static void
gchar const *default_ns,
gchar const *old_href_abs_base,
gchar const *new_href_abs_base)
{
/* fixme: do this The Right Way */
if (str) {
}
{
} else {
}
}
}
}
{
return buf;
}
void
gchar const *const old_href_abs_base,
gchar const *const new_href_abs_base)
{
Inkscape::IO::OutputStreamWriter *out = compress ? new Inkscape::IO::OutputStreamWriter( *gout ) : new Inkscape::IO::OutputStreamWriter( bout );
delete out;
delete gout;
}
/**
* Returns true iff file successfully saved.
*
* \param filename The actual file to do I/O to, which might be a temp file.
*
* \param for_filename The base URI [actually filename] to assume for purposes of rewriting
* xlink:href attributes.
*/
bool
{
if (!filename) {
return false;
}
bool compress;
{
}
return false;
}
if (for_filename) {
if (g_path_is_absolute(for_filename)) {
} else {
}
/* effic: Once we're confident that we never need (or never want) to resort
* to using sodipodi:absref instead of the xlink:href value,
* then we should do `if streq() { free them and set both to NULL; }'. */
}
return false;
}
return true;
}
/**
* Returns true iff file successfully saved.
*/
bool
{
}
/* (No doubt this function already exists elsewhere.) */
static void
{
if (val) {
switch (*val) {
}
}
}
}
static void repr_write_comment( Writer &out, const gchar * val, bool addWhitespace, gint indentLevel, int indent )
{
if ( indentLevel > 16 ) {
indentLevel = 16;
}
if (addWhitespace && indent) {
for (gint i = 0; i < indentLevel; i++) {
}
}
}
// WARNING out.printf() and out.writeString() are *NOT* non-ASCII friendly.
if (val) {
}
} else {
}
if (addWhitespace) {
}
}
namespace {
typedef std::map<Glib::QueryQuark, Inkscape::Util::ptr_shared<char>, Inkscape::compare_quark_ids> NSMap;
static LocalNameMap local_name_map;
} else {
if (prefix_end) {
return prefix_end + 1;
} else {
return name_string;
}
}
}
if (uri) {
} else if ( prefix != xml_prefix ) {
}
} else {
}
}
}
{
}
}
{
}
}
}
}
static void
int inlineattrs, int indent,
gchar const *const old_href_base,
gchar const *const new_href_base)
{
}
{
if ( prefix != xml_prefix ) {
if ( elide_prefix == prefix ) {
}
}
} else {
// if there are non-namespaced elements, we can't globally
// use a default namespace
elide_prefix = GQuark(0);
}
}
}
int inlineattrs, int indent,
gchar const *const old_href_base,
gchar const *const new_href_base)
{
break;
}
break;
}
break;
}
repr->attributeList(),
break;
}
break;
}
default: {
}
}
}
static void
bool add_whitespace,
int inlineattrs, int indent,
gchar const *const old_href_base,
gchar const *const new_href_base)
{
bool loose;
if ( indent_level > 16 ) {
indent_level = 16;
}
if (add_whitespace && indent) {
for (gint i = 0; i < indent_level; i++) {
}
}
}
gchar const *element_name;
} else {
}
// if this is a <text> element, suppress formatting whitespace
// for its content and children:
add_whitespace = false;
}
{
if (!inlineattrs) {
if (indent) {
}
}
}
}
}
break;
}
}
if (repr->firstChild()) {
if (loose && add_whitespace) {
}
}
for (gint i = 0; i < indent_level; i++) {
}
}
}
} else {
}
// text elements cannot nest, so we can output newline
// after closing text
}
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :