summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: fdeb14b)
raw | patch | inline | side by side (parent: fdeb14b)
author | acspike <acspike@users.sourceforge.net> | |
Tue, 13 Jun 2006 02:13:02 +0000 (02:13 +0000) | ||
committer | acspike <acspike@users.sourceforge.net> | |
Tue, 13 Jun 2006 02:13:02 +0000 (02:13 +0000) |
13 files changed:
index f71532e8b97937cc2473f0b7927a78c7d8539bc8..2cab2b3f4d2c305db3ddc65dddba263a1b38a89a 100644 (file)
/**
* Writes the specified byte to this output stream.
*/
-void Base64OutputStream::put(XMLCh ch)
+int Base64OutputStream::put(XMLCh ch)
{
if (closed)
{
//probably throw an exception here
- return;
+ return -1;
}
outBuf <<= 8;
bitCount = 0;
outBuf = 0L;
}
+
+ return 1;
}
index 23ec1ce07b801446eda9566a055180756ac83670..c6d0ad35d1147688648cb087711dc688d74d9121 100644 (file)
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
/**
* Sets the maximum line length for base64 output. If
index 4664b07e91359f8fdb296d896965dce07fa1d42a..6c3956a60cd4fa3be6d9e6d6b2c5b3fb6f3eb070 100644 (file)
/**
* Writes the specified byte to this output stream.
*/
-void BufferOutputStream::put(XMLCh ch)
+int BufferOutputStream::put(XMLCh ch)
{
if (closed)
- return;
+ return -1;
buffer.push_back(ch);
+ return 1;
}
index a8f7ea31964be079edfbbd8fbd67709b41ae0965..bdf4eb2ab42cb4f16c8ccac8d2e156589431a17d 100644 (file)
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
virtual std::vector<unsigned char> &getBuffer()
{ return buffer; }
index 3ffba53feefab4f27719624cd18b41b7f6b0425f..7b0a7e1d2b6cfa1bd6e14d5aef2350cca49f1b27 100644 (file)
--- a/src/dom/io/domstream.cpp
+++ b/src/dom/io/domstream.cpp
*
*/
+#include <math.h>
#include <stdarg.h>
#include "domstream.h"
dest.flush();
}
+
+
+//#########################################################################
+//# F O R M A T T E D P R I N T I N G
+//#########################################################################
+
+static char *digits = "0123456789abcdefghijklmnopqrstuvwxyz";
+
+static int dprintInt(Writer &outs,
+ long arg, int base,
+ int flag, int width, int precision)
+{
+
+ DOMString buf;
+
+ //### Get the digits
+ while (arg > 0)
+ {
+ int ch = arg % base;
+ buf.insert(buf.begin(), digits[ch]);
+ arg /= base;
+ }
+
+ if (flag == '#' && base == 16)
+ {
+ buf.insert(buf.begin(), 'x');
+ buf.insert(buf.begin(), '0');
+ }
+
+ //### Output the result
+ for (unsigned int i=0 ; i<buf.size() ; i++)
+ {
+ if (outs.put(buf[i]) < 0)
+ return -1;
+ }
+
+ return 1;
+}
+
+
+
+static int dprintDouble(Writer &outs,
+ double val,
+ int flag, int width, int precision)
+{
+
+ DOMString buf;
+
+ //printf("int:%f frac:%f\n", intPart, fracPart);
+
+ bool negative = false;
+ if (val < 0)
+ {
+ negative = true;
+ val = -val;
+ }
+
+ int intDigits = 0;
+ double scale = 1.0;
+ while (scale < val)
+ {
+ intDigits++;
+ scale *= 10.0;
+ }
+
+ double intPart;
+ double fracPart = modf(val, &intPart);
+
+ if (precision <= 0)
+ precision = 5;
+
+ //### How many pad digits?
+ int pad = width - intDigits;
+ if (precision > 0)
+ pad -= precision + 1;
+ else if (flag == '#')
+ pad--;
+
+
+ //### Signs
+ if (negative)
+ buf.push_back('-');
+ else if (flag == '+')
+ buf.push_back('+');
+
+ //### Prefix pad
+ if (pad > 0 && flag == '0')
+ {
+ while (pad--)
+ buf.push_back('0');
+ }
+
+ //### Integer digits
+ intPart = (intPart + 0.1 ) / scale; // turn 12345.678 to .12345678
+ while (intDigits--)
+ {
+ intPart *= 10.0;
+ double dig;
+ intPart = modf(intPart, &dig);
+ char ch = '0' + (int)dig;
+ buf.push_back(ch);
+ }
+
+ //### Decimal point
+ if (flag == '#' || precision > 0)
+ {
+ buf.push_back('.');
+ }
+
+ //### Fractional digits
+ while (precision--)
+ {
+ fracPart *= 10.0;
+ double dig;
+ fracPart = modf(fracPart, &dig);
+ char ch = '0' + (int)dig;
+ buf.push_back(ch);
+ }
+
+ //### Left justify if requested
+ if (pad > 0 && flag == '-')
+ {
+ while (pad--)
+ buf.push_back(' ');
+ }
+
+ //### Output the result
+ for (unsigned int i=0 ; i<buf.size() ; i++)
+ {
+ if (outs.put(buf[i]) < 0)
+ return -1;
+ }
+ return 1;
+}
+
+static int dprintString(Writer &outs,
+ char *arg,
+ int flags, int width, int precision)
+{
+ while (*arg)
+ {
+ if (outs.put(*arg++) < 0)
+ return -1;
+ }
+
+ return 1;
+}
+
+
+
+static char *getint(char *s, int *ret)
+{
+ bool has_sign = false;
+ int val = 0;
+ if (*s == '-')
+ {
+ has_sign = true;
+ s++;
+ }
+ while (*s >= '0' && *s <= '9')
+ {
+ val = val * 10 + (*s - '0');
+ s++;
+ }
+ if (has_sign)
+ val = -val;
+
+ *ret = val;
+
+ return s;
+}
+
+
+
+static int dprintf(Writer &outs, const char *fmt, va_list ap)
+{
+
+ char *s = (char *) fmt;
+
+ while (*s)
+ {
+ unsigned char ch = *s++;
+
+ if (ch != '%')
+ {
+ if (outs.put(ch)<0)
+ {
+ return -1;
+ }
+ }
+ else
+ //expecting %[flag][width][.precision][length][char]
+ {
+ if (!*s)
+ {
+ return -1;
+ }
+ if (*s == '%') // escaped '%'
+ {
+ if (outs.put('%')<0)
+ {
+ return -1;
+ }
+ s++;
+ continue;
+ }
+ char flag = '\0';
+ if (*s == '-' || *s == '+' || *s == ' ' ||
+ *s == '#' || *s == '0')
+ {
+ flag = *s++;
+ if (!*s)
+ {
+ return -1;
+ }
+ }
+ int width = 0;
+ int precision = 0;
+ s = getint(s, &width);
+ if (!*s)
+ {
+ return -1;
+ }
+ if (*s == '.')
+ {
+ s++;
+ if (!*s)
+ {
+ return -1;
+ }
+ s = getint(s, &precision);
+ }
+ char length = '\0';
+ if (*s == 'l' || *s == 'h')
+ {
+ length = *s++;
+ if (!*s)
+ {
+ return -1;
+ }
+ }
+ ch = *s++;
+ if (!ch)
+ {
+ return -1;
+ }
+ switch (ch)
+ {
+ case 'f':
+ case 'g':
+ {
+ double val = va_arg(ap, double);
+ dprintDouble(outs, val, flag, width, precision);
+ break;
+ }
+ case 'd':
+ {
+ long val = 0;
+ if (length == 'l')
+ val = va_arg(ap, long);
+ else if (length == 'h')
+ val = (long)va_arg(ap, int);
+ else
+ val = (long)va_arg(ap, int);
+ dprintInt(outs, val, 10, flag, width, precision);
+ break;
+ }
+ case 'x':
+ {
+ long val = 0;
+ if (length == 'l')
+ val = va_arg(ap, long);
+ else if (length == 'h')
+ val = (long)va_arg(ap, int);
+ else
+ val = (long)va_arg(ap, int);
+ dprintInt(outs, val, 16, flag, width, precision);
+ break;
+ }
+ case 's':
+ {
+ char *val = va_arg(ap, char *);
+ dprintString(outs, val, flag, width, precision);
+ break;
+ }
+ default:
+ {
+ break;
+ }
+ }
+ }
+
+ }
+
+
+ return 1;
+}
+
+
//#########################################################################
//# B A S I C I N P U T S T R E A M
//#########################################################################
/**
* Writes the specified byte to this output stream.
*/
-void BasicOutputStream::put(XMLCh ch)
+int BasicOutputStream::put(XMLCh ch)
{
if (closed)
- return;
- destination.put(ch);
+ return -1;
+ if (destination.put(ch) < 0)
+ return -1;
+ return 1;
}
/**
* Writes the specified byte to this output writer.
*/
-void BasicWriter::put(XMLCh ch)
+int BasicWriter::put(XMLCh ch)
{
- if (destination)
- destination->put(ch);
+ if (destination && destination->put(ch)>=0)
+ return 1;
+ return -1;
}
/**
* Provide printf()-like formatting
*/
+/*
Writer &BasicWriter::printf(char *fmt, ...)
{
va_list args;
return *this;
}
+*/
+Writer &BasicWriter::printf(char *fmt, ...)
+{
+ va_list args;
+ va_start(args, fmt);
+ dprintf(*this, fmt, args);
+
+ return *this;
+}
+
+
/**
* Writes the specified character to this output writer.
*/
* Overloaded to redirect the output chars from the next Writer
* in the chain to an OutputStream instead.
*/
-void OutputStreamWriter::put(XMLCh ch)
+int OutputStreamWriter::put(XMLCh ch)
{
//Do we need conversions here?
int intCh = (int) ch;
- outputStream.put(intCh);
+ if (outputStream.put(intCh) < 0)
+ return -1;
+ return 1;
}
//#########################################################################
* Overloaded to redirect the output chars from the next Writer
* in the chain to an OutputStream instead.
*/
-void StdWriter::put(XMLCh ch)
+int StdWriter::put(XMLCh ch)
{
//Do we need conversions here?
int intCh = (int) ch;
- outputStream->put(intCh);
+ if (outputStream->put(intCh) < 0)
+ return -1;
+ return 1;
}
diff --git a/src/dom/io/domstream.h b/src/dom/io/domstream.h
index 05862f9449b2af99eba34aa7076af38de57c638a..4a68ba1c134874e4d25c28119c59839f30cf9d9e 100644 (file)
--- a/src/dom/io/domstream.h
+++ b/src/dom/io/domstream.h
/**
* Send one byte to the destination stream.
*/
- virtual void put(XMLCh ch) = 0;
+ virtual int put(XMLCh ch) = 0;
}; // class OutputStream
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
protected:
void flush()
{ }
- void put(XMLCh ch)
- { putchar(ch); }
+ int put(XMLCh ch)
+ { putchar(ch); return 1; }
};
virtual void flush() = 0;
- virtual void put(XMLCh ch) = 0;
+ virtual int put(XMLCh ch) = 0;
/* Formatted output */
virtual Writer& printf(char *fmt, ...) = 0;
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
private:
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
private:
index 19369b6dcb68dfbd2990f323f31be2f349dbe7ac..f634acbe72b895a73bc73daac088e72298025490 100644 (file)
/**
* Writes the specified byte to this output stream.
*/
-void GzipOutputStream::put(XMLCh ch)
+int GzipOutputStream::put(XMLCh ch)
{
if (closed)
{
//probably throw an exception here
- return;
+ return -1;
}
//Add char to buffer
buffer.push_back(ch);
-
+ return 1;
}
index 6396772a5eddde051253bf8d92e3c1c4e33da2ab..4af5ada2b49f05284554ada30ab448320fb653d2 100644 (file)
--- a/src/dom/io/gzipstream.h
+++ b/src/dom/io/gzipstream.h
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
private:
index 93fb0c0b5be1b7e0d433b613487334ddd55b927e..f2745a1073e62080455dd0494b1a0ab5f4602e78 100644 (file)
/**
* Writes the specified byte to this output stream.
*/
-void StringOutputStream::put(XMLCh ch)
+int StringOutputStream::put(XMLCh ch)
{
buffer.push_back(ch);
+ return 1;
}
index 8bb4e76b147946427c7bdd9b8ce43bca93ea65e6..38aaf72353777965086c3a6c13c9b6bb340237c1 100644 (file)
virtual void flush();
- virtual void put(XMLCh ch);
+ virtual int put(XMLCh ch);
virtual DOMString &getString()
{ return buffer; }
index 1cc540bd5d7b54ad49a53cd9c1989500c57a175d..8928921e4cb3bc9d41f25d6f82f47e0bbc93adc6 100644 (file)
--- a/src/dom/io/uristream.cpp
+++ b/src/dom/io/uristream.cpp
/**
* Writes the specified byte to this output stream.
*/
-void UriOutputStream::put(XMLCh ch) throw(StreamException)
+int UriOutputStream::put(XMLCh ch) throw(StreamException)
{
if (closed)
- return;
+ return -1;
switch (scheme)
{
case URI::SCHEME_FILE:
{
if (!outf)
- return;
+ return -1;
unsigned char uch = (unsigned char)(ch & 0xff);
fputc(uch, outf);
//fwrite(uch, 1, 1, outf);
}
}//switch
-
+ return 1;
}
/**
*
*/
-void UriWriter::put(XMLCh ch) throw(StreamException)
+int UriWriter::put(XMLCh ch) throw(StreamException)
{
int ich = (int)ch;
- outputStream->put(ich);
+ if (outputStream->put(ich) < 0)
+ return -1;
+ return 1;
}
diff --git a/src/dom/io/uristream.h b/src/dom/io/uristream.h
index 892ac5c688ff5f0f5e53be9a40e1b5fa7088c760..45d44b71d16241912ddaa8c68b50cdf030d00b4d 100644 (file)
--- a/src/dom/io/uristream.h
+++ b/src/dom/io/uristream.h
virtual void flush() throw(StreamException);
- virtual void put(XMLCh ch) throw(StreamException);
+ virtual int put(XMLCh ch) throw(StreamException);
private:
virtual void flush() throw(StreamException);
- virtual void put(XMLCh ch) throw(StreamException);
+ virtual int put(XMLCh ch) throw(StreamException);
private:
index 1d364804843780d23cdc42b2f68ab89bd333ba68..3e62ea999b3e33fc04bb272ba3b45d64b1d5629f 100644 (file)
outs.printf(" <style:graphic-properties draw:stroke=\"none\" draw:fill=\"none\"\n");
outs.printf(" draw:textarea-horizontal-align=\"center\"\n");
outs.printf(" draw:textarea-vertical-align=\"middle\" draw:color-mode=\"standard\"\n");
- outs.printf(" draw:luminance=\"0%\" draw:contrast=\"0%\" draw:gamma=\"100%\" draw:red=\"0%\"\n");
- outs.printf(" draw:green=\"0%\" draw:blue=\"0%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n");
- outs.printf(" draw:image-opacity=\"100%\" style:mirror=\"none\"/>\n");
+ outs.printf(" draw:luminance=\"0%%\" draw:contrast=\"0%%\" draw:gamma=\"100%%\" draw:red=\"0%%\"\n");
+ outs.printf(" draw:green=\"0%%\" draw:blue=\"0%%\" fo:clip=\"rect(0cm 0cm 0cm 0cm)\"\n");
+ outs.printf(" draw:image-opacity=\"100%%\" style:mirror=\"none\"/>\n");
outs.printf("</style:style>\n");
outs.printf("<style:style style:name=\"P1\" style:family=\"paragraph\">\n");
outs.printf(" <style:paragraph-properties fo:text-align=\"center\"/>\n");