sckstrm.cpp C S
socket.cpp C S
stream.cpp C
+strconv.cpp C
string.cpp C
tbarbase.cpp C
tbarsmpl.cpp C 16
wincmn.cpp C
wxchar.cpp C
wxexpr.cpp C
-zipstream.cpp C
+zipstrm.cpp C
zstream.cpp C
accel.cpp M
statline.h I WX
stattext.h I WX
statusbr.h I WX
+strconv.h I WX
stream.h I WX
string.h I WX
tab.h I WX
wxhtml.h I WX
wxprec.h I WX
xpmhand.h I WX
-zipstream.h I WX
+zipstrm.h I WX
zstream.h I WX
accel.h I GTK
stattext.h \
statusbr.h \
stream.h \
+ strconv.h \
string.h \
tab.h \
tabctrl.h \
wxhtml.h \
wxprec.h \
xpmhand.h \
- zipstream.h \
+ zipstrm.h \
zstream.h
# setup.h is installed in another directory because several versions of wxwin
--- /dev/null
+///////////////////////////////////////////////////////////////////////////////
+// Name: strconv.h
+// Purpose: conversion routines for char sets any Unicode
+// Author: Robert Roebling, Ove Kaaven
+// Modified by:
+// Created: 29/01/98
+// RCS-ID: $Id$
+// Copyright: (c) 1998 Ove Kaaven, Robert Roebling, Vadim Zeitlin
+// Licence: wxWindows license
+///////////////////////////////////////////////////////////////////////////////
+
+#ifndef _WX_WXSTRCONVH__
+#define _WX_WXSTRCONVH__
+
+#ifdef __GNUG__
+ #pragma interface "strconv.h"
+#endif
+
+#include "wx/defs.h"
+#include "wx/wxchar.h"
+#include "wx/buffer.h"
+
+#include <stdlib.h>
+
+#if wxUSE_WCHAR_T
+
+//---------------------------------------------------------------------------
+// wxMBConv (base class for conversions, using libc conversion itself)
+//---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxMBConv
+{
+public:
+
+ // the actual conversion takes place here
+ virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
+ virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
+
+ // No longer inline since BC++ complains.
+ const wxWCharBuffer cMB2WC(const char *psz) const;
+ const wxCharBuffer cWC2MB(const wchar_t *psz) const;
+#if wxUSE_UNICODE
+ const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
+ const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
+ const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
+ const wchar_t* cMB2WC(const wchar_t *psz) const { return psz; }
+#else
+ const char* cMB2WX(const char *psz) const { return psz; }
+ const char* cWX2MB(const char *psz) const { return psz; }
+ const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
+ const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
+#endif
+};
+
+WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
+
+//---------------------------------------------------------------------------
+// wxMBConvFile (for conversion to filenames)
+//---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxMBConvFile: public wxMBConv
+{
+public:
+ virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
+ virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
+};
+
+WXDLLEXPORT_DATA(extern wxMBConvFile) wxConvFile;
+
+//---------------------------------------------------------------------------
+// wxMBConvUTF7 (for conversion using UTF7 encoding)
+//---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxMBConvUTF7: public wxMBConv
+{
+public:
+ virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
+ virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
+};
+
+WXDLLEXPORT_DATA(extern wxMBConvUTF7) wxConvUTF7;
+
+//---------------------------------------------------------------------------
+// wxMBConvUTF8 (for conversion using UTF8 encoding)
+//---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxMBConvUTF8: public wxMBConv
+{
+public:
+ virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
+ virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
+};
+
+WXDLLEXPORT_DATA(extern wxMBConvUTF8) wxConvUTF8;
+
+#ifdef __WXGTK12__
+//---------------------------------------------------------------------------
+// wxMBConvUTF8 (for conversion using GDK's internal converions)
+//---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxMBConvGdk: public wxMBConv
+{
+public:
+ virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
+ virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
+};
+
+WXDLLEXPORT_DATA(extern wxMBConvGdk) wxConvGdk;
+#endif
+
+//---------------------------------------------------------------------------
+// wxCSConv (for conversion based on laodable char sets)
+//---------------------------------------------------------------------------
+
+class wxCharacterSet;
+
+class WXDLLEXPORT wxCSConv: public wxMBConv
+{
+private:
+ wxChar *m_name;
+ wxCharacterSet *m_cset;
+ bool m_deferred;
+ void SetName(const wxChar *charset);
+
+public:
+ wxCSConv(const wxChar *charset);
+ virtual ~wxCSConv();
+ void LoadNow();
+ virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
+ virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
+};
+
+WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
+#define wxConv_local wxConvLocal
+
+WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
+#define wxConv_current wxConvCurrent
+
+//---------------------------------------------------------------------------
+// filename conversion macros
+//---------------------------------------------------------------------------
+
+// filenames are multibyte on Unix and probably widechar on Windows?
+#if defined(__UNIX__) || defined(__BORLANDC__)
+#define wxMBFILES 1
+#else
+#define wxMBFILES 0
+#endif
+
+#if wxMBFILES
+#define wxFNCONV(name) wxConvFile.cWX2MB(name)
+#define FNSTRINGCAST MBSTRINGCAST
+#else
+#define wxFNCONV(name) name
+#define FNSTRINGCAST WXSTRINGCAST
+#endif
+
+#else
+ // !wxUSE_WCHAR_T
+
+//---------------------------------------------------------------------------
+// stand-ins in absence of wchar_t
+//---------------------------------------------------------------------------
+
+class WXDLLEXPORT wxMBConv
+{
+public:
+ const char* cMB2WX(const char *psz) const { return psz; }
+ const char* cWX2MB(const char *psz) const { return psz; }
+};
+WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
+WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
+
+#define wxFNCONV(name) name
+#define FNSTRINGCAST WXSTRINGCAST
+
+#endif
+ // wxUSE_WCHAR_T
+
+#endif
+ // _WX_WXSTRCONVH__
+
// implementation only
#define ASSERT_VALID_INDEX(i) wxASSERT( (unsigned)(i) <= Len() )
+// include conversion classes
+#include "wx/strconv.h"
+
// ---------------------------------------------------------------------------
// Global functions complementing standard C string library replacements for
// strlen() and portable strcasecmp()
bool IsValid() const { return (nRefs != 0); }
};
-// ---------------------------------------------------------------------------
-// types of multibyte<->Unicode conversions
-// ---------------------------------------------------------------------------
-#if wxUSE_WCHAR_T
-class WXDLLEXPORT wxMBConv
-{
- public:
- virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
- virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
- // No longer inline since BC++ complains.
- const wxWCharBuffer cMB2WC(const char *psz) const;
- const wxCharBuffer cWC2MB(const wchar_t *psz) const;
-#if wxUSE_UNICODE
- const wxWCharBuffer cMB2WX(const char *psz) const { return cMB2WC(psz); }
- const wxCharBuffer cWX2MB(const wchar_t *psz) const { return cWC2MB(psz); }
- const wchar_t* cWC2WX(const wchar_t *psz) const { return psz; }
- const wchar_t* cMB2WC(const wchar_t *psz) const { return psz; }
-#else
- const char* cMB2WX(const char *psz) const { return psz; }
- const char* cWX2MB(const char *psz) const { return psz; }
- const wxCharBuffer cWC2WX(const wchar_t *psz) const { return cWC2MB(psz); }
- const wxWCharBuffer cWX2WC(const char *psz) const { return cMB2WC(psz); }
-#endif
-};
-WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc;
-
-#define wxANOTHER_MBCONV(type) \
-class type : public wxMBConv { \
- public: \
- virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const; \
- virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const; \
-}
-
-WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvFile)) wxConvFile;
-WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvUTF7)) wxConvUTF7;
-WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvUTF8)) wxConvUTF8;
-#ifdef __WXGTK12__
- WXDLLEXPORT_DATA(extern wxANOTHER_MBCONV(wxMBConvGdk)) wxConvGdk;
-#endif
-
-class wxCharacterSet;
-class WXDLLEXPORT wxCSConv : public wxMBConv
-{
- private:
- wxChar *m_name;
- wxCharacterSet *m_cset;
- bool m_deferred;
- void SetName(const wxChar *charset);
- public:
- wxCSConv(const wxChar *charset);
- virtual ~wxCSConv();
- void LoadNow();
- virtual size_t MB2WC(wchar_t *buf, const char *psz, size_t n) const;
- virtual size_t WC2MB(char *buf, const wchar_t *psz, size_t n) const;
-};
-
-WXDLLEXPORT_DATA(extern wxCSConv) wxConvLocal;
-#define wxConv_local wxConvLocal
-
-WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
-#define wxConv_current wxConvCurrent
-
-// filenames are multibyte on Unix and probably widechar on Windows?
-#if defined(__UNIX__) || defined(__BORLANDC__)
-#define wxMBFILES 1
-#else
-#define wxMBFILES 0
-#endif
-
-#if wxMBFILES
-#define wxFNCONV(name) wxConvFile.cWX2MB(name)
-#define FNSTRINGCAST MBSTRINGCAST
-#else
-#define wxFNCONV(name) name
-#define FNSTRINGCAST WXSTRINGCAST
-#endif
-#else//!wxUSE_WCHAR_T
-class WXDLLEXPORT wxMBConv {
-public:
- const char* cMB2WX(const char *psz) const { return psz; }
- const char* cWX2MB(const char *psz) const { return psz; }
-};
-WXDLLEXPORT_DATA(extern wxMBConv) wxConvLibc, wxConvFile;
-WXDLLEXPORT_DATA(extern wxMBConv *) wxConvCurrent;
-#define wxFNCONV(name) name
-#define FNSTRINGCAST WXSTRINGCAST
-#endif//wxUSE_WCHAR_T
-
// ---------------------------------------------------------------------------
// This is (yet another one) String class for C++ programmers. It doesn't use
// any of "advanced" C++ features (i.e. templates, exceptions, namespaces...)
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: zipstream.h
-// Purpose: wxZipInputStream for reading files from ZIP archive
-// Author: Vaclav Slavik
-// Copyright: (c) 1999 Vaclav Slavik
-// Licence: wxWindows Licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifndef __ZIPSTREAM_H__
-#define __ZIPSTREAM_H__
-
-#ifdef __GNUG__
-#pragma interface
-#endif
-
-#include "wx/defs.h"
-
-#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
-
-#include "wx/stream.h"
-
-//--------------------------------------------------------------------------------
-// wxZipInputStream
-// This class is input stream from ZIP archive. The archive
-// must be local file (accessible via FILE*)
-//--------------------------------------------------------------------------------
-
-
-class WXDLLEXPORT wxZipInputStream : public wxInputStream
-{
- private:
- size_t m_Size;
- off_t m_Pos;
- void *m_Archive;
- // this void* is handle of archive .
- // I'm sorry it is void and not proper type but I don't want
- // to make unzip.h header public.
-
- public:
- wxZipInputStream(const wxString& archive, const wxString& file);
- // archive is name of .zip archive, file is name of file to be extracted.
- // Remember that archive must be local file accesible via fopen, fread functions!
- ~wxZipInputStream();
-
- protected:
- virtual size_t GetSize() const {return m_Size;}
- virtual size_t OnSysRead(void *buffer, size_t bufsize);
- virtual off_t OnSysSeek(off_t seek, wxSeekMode mode);
- virtual off_t OnSysTell() const {return m_Pos;}
-};
-
-
-#endif
- // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
-
-#endif
- // __ZIPSTREAM_H__
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: zipstream.h
+// Purpose: wxZipInputStream for reading files from ZIP archive
+// Author: Vaclav Slavik
+// Copyright: (c) 1999 Vaclav Slavik
+// Licence: wxWindows Licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifndef __ZIPSTREAM_H__
+#define __ZIPSTREAM_H__
+
+#ifdef __GNUG__
+#pragma interface
+#endif
+
+#include "wx/defs.h"
+
+#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
+
+#include "wx/stream.h"
+
+//--------------------------------------------------------------------------------
+// wxZipInputStream
+// This class is input stream from ZIP archive. The archive
+// must be local file (accessible via FILE*)
+//--------------------------------------------------------------------------------
+
+
+class WXDLLEXPORT wxZipInputStream : public wxInputStream
+{
+ private:
+ size_t m_Size;
+ off_t m_Pos;
+ void *m_Archive;
+ // this void* is handle of archive .
+ // I'm sorry it is void and not proper type but I don't want
+ // to make unzip.h header public.
+
+ public:
+ wxZipInputStream(const wxString& archive, const wxString& file);
+ // archive is name of .zip archive, file is name of file to be extracted.
+ // Remember that archive must be local file accesible via fopen, fread functions!
+ ~wxZipInputStream();
+
+ protected:
+ virtual size_t GetSize() const {return m_Size;}
+ virtual size_t OnSysRead(void *buffer, size_t bufsize);
+ virtual off_t OnSysSeek(off_t seek, wxSeekMode mode);
+ virtual off_t OnSysTell() const {return m_Pos;}
+};
+
+
+#endif
+ // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
+
+#endif
+ // __ZIPSTREAM_H__
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
#endif
#include "wx/filesys.h"
-#include "wx/zipstream.h"
+#include "wx/zipstrm.h"
#include "wx/fs_zip.h"
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: strconv.cpp
+// Purpose: Unicode conversion classes
+// Author: Ove Kaaven, Robert Roebling, Vadim Zeitlin
+// Modified by:
+// Created: 29/01/98
+// RCS-ID: $Id$
+// Copyright: (c) 1999 Ove Kaaven, Robert Roebling, Vadim Zeitlin
+// Licence: wxWindows license
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+ #pragma implementation "strconv.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#include <ctype.h>
+#include <string.h>
+#include <stdlib.h>
+
+#ifdef __SALFORDC__
+ #include <clib.h>
+#endif
+
+#include "wx/debug.h"
+#include "wx/strconv.h"
+
+//----------------------------------------------------------------------------
+// wxConvCurrent
+//----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc;
+
+#if !wxUSE_WCHAR_T
+//----------------------------------------------------------------------------
+// stand-ins in absence of wchar_t
+//----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConv) wxConvLibc, wxConvFile;
+
+#else
+
+//----------------------------------------------------------------------------
+// wxMBConv
+//----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConv) wxConvLibc;
+
+size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ return wxMB2WC(buf, psz, n);
+}
+
+size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ return wxWC2MB(buf, psz, n);
+}
+
+const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
+{
+ if (psz)
+ {
+ size_t nLen = MB2WC((wchar_t *) NULL, psz, 0);
+ wxWCharBuffer buf(nLen);
+ MB2WC((wchar_t *)(const wchar_t *) buf, psz, nLen);
+ return buf;
+ }
+ else
+ return wxWCharBuffer((wchar_t *) NULL);
+}
+
+const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
+{
+ if (psz)
+ {
+ size_t nLen = WC2MB((char *) NULL, psz, 0);
+ wxCharBuffer buf(nLen);
+ WC2MB((char *)(const char *) buf, psz, nLen);
+ return buf;
+ }
+ else
+ return wxCharBuffer((char *) NULL);
+}
+
+//----------------------------------------------------------------------------
+// standard file conversion
+//----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConvFile) wxConvFile;
+
+// just use the libc conversion for now
+size_t wxMBConvFile::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ return wxMB2WC(buf, psz, n);
+}
+
+size_t wxMBConvFile::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ return wxWC2MB(buf, psz, n);
+}
+
+#ifdef __WXGTK12__
+
+//----------------------------------------------------------------------------
+// standard gdk conversion
+//----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConvGdk) wxConvGdk;
+
+#include <gdk/gdk.h>
+
+size_t wxMBConvGdk::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ if (buf) {
+ return gdk_mbstowcs((GdkWChar *)buf, psz, n);
+ } else {
+ GdkWChar *nbuf = new GdkWChar[n=strlen(psz)];
+ size_t len = gdk_mbstowcs(nbuf, psz, n);
+ delete [] nbuf;
+ return len;
+ }
+}
+
+size_t wxMBConvGdk::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ char *mbstr = gdk_wcstombs((GdkWChar *)psz);
+ size_t len = mbstr ? strlen(mbstr) : 0;
+ if (buf) {
+ if (len > n) len = n;
+ memcpy(buf, psz, len);
+ if (len < n) buf[len] = 0;
+ }
+ return len;
+}
+#endif // GTK > 1.0
+
+// ----------------------------------------------------------------------------
+// UTF-7
+// ----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConvUTF7) wxConvUTF7;
+
+#if 0
+static char utf7_setD[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789'(),-./:?";
+static char utf7_setO[]="!\"#$%&*;<=>@[]^_`{|}";
+static char utf7_setB[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
+ "abcdefghijklmnopqrstuvwxyz"
+ "0123456789+/";
+#endif
+
+// TODO: write actual implementations of UTF-7 here
+size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf),
+ const char * WXUNUSED(psz),
+ size_t WXUNUSED(n)) const
+{
+ return 0;
+}
+
+size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf),
+ const wchar_t * WXUNUSED(psz),
+ size_t WXUNUSED(n)) const
+{
+ return 0;
+}
+
+//----------------------------------------------------------------------------
+// UTF-8
+//----------------------------------------------------------------------------
+
+WXDLLEXPORT_DATA(wxMBConvUTF8) wxConvUTF8;
+
+static unsigned long utf8_max[]={0x7f,0x7ff,0xffff,0x1fffff,0x3ffffff,0x7fffffff,0xffffffff};
+
+size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ size_t len = 0;
+
+ while (*psz && ((!buf) || (len<n))) {
+ unsigned char cc=*psz++, fc=cc;
+ unsigned cnt;
+ for (cnt=0; fc&0x80; cnt++) fc<<=1;
+ if (!cnt) {
+ // plain ASCII char
+ if (buf) *buf++=cc;
+ len++;
+ } else {
+ cnt--;
+ if (!cnt) {
+ // invalid UTF-8 sequence
+ return (size_t)-1;
+ } else {
+ unsigned ocnt=cnt-1;
+ unsigned long res=cc&(0x3f>>cnt);
+ while (cnt--) {
+ cc = *psz++;
+ if ((cc&0xC0)!=0x80) {
+ // invalid UTF-8 sequence
+ return (size_t)-1;
+ }
+ res=(res<<6)|(cc&0x3f);
+ }
+ if (res<=utf8_max[ocnt]) {
+ // illegal UTF-8 encoding
+ return (size_t)-1;
+ }
+ if (buf) *buf++=res;
+ len++;
+ }
+ }
+ }
+ if (buf && (len<n)) *buf = 0;
+ return len;
+}
+
+size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ size_t len = 0;
+
+ while (*psz && ((!buf) || (len<n))) {
+ unsigned long cc=(*psz++)&0x7fffffff;
+ unsigned cnt;
+ for (cnt=0; cc>utf8_max[cnt]; cnt++);
+ if (!cnt) {
+ // plain ASCII char
+ if (buf) *buf++=cc;
+ len++;
+ } else {
+ len+=cnt+1;
+ if (buf) {
+ *buf++=(-128>>cnt)|((cc>>(cnt*6))&(0x3f>>cnt));
+ while (cnt--)
+ *buf++=0x80|((cc>>(cnt*6))&0x3f);
+ }
+ }
+ }
+ if (buf && (len<n)) *buf = 0;
+ return len;
+}
+
+// ----------------------------------------------------------------------------
+// specified character set
+// ----------------------------------------------------------------------------
+
+#ifndef WX_PRECOMP
+ #include "wx/dynarray.h"
+ #include "wx/filefn.h"
+ #include "wx/textfile.h"
+ #include "wx/tokenzr.h"
+ #include "wx/utils.h"
+#endif
+
+class wxCharacterSet
+{
+public:
+ wxArrayString names;
+ wchar_t *data;
+};
+
+WX_DECLARE_OBJARRAY(wxCharacterSet, wxCSArray);
+#include "wx/arrimpl.cpp"
+WX_DEFINE_OBJARRAY(wxCSArray);
+
+static wxCSArray wxCharsets;
+
+static void wxLoadCharacterSets(void)
+{
+ static bool already_loaded = FALSE;
+
+ if (already_loaded) return;
+
+ already_loaded = TRUE;
+#if defined(__UNIX__) && wxUSE_TEXTFILE
+ // search through files in /usr/share/i18n/charmaps
+ wxString fname;
+ for (fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
+ !fname.IsEmpty();
+ fname = ::wxFindNextFile()) {
+ wxTextFile cmap(fname);
+ if (cmap.Open()) {
+ wxCharacterSet *cset = new wxCharacterSet;
+ wxString comchar,escchar;
+ bool in_charset = FALSE;
+
+ // wxFprintf(stderr,_T("Loaded: %s\n"),fname.c_str());
+
+ wxString line;
+ for (line = cmap.GetFirstLine();
+ !cmap.Eof();
+ line = cmap.GetNextLine()) {
+ // wxFprintf(stderr,_T("line contents: %s\n"),line.c_str());
+ wxStringTokenizer token(line);
+ wxString cmd = token.GetNextToken();
+ if (cmd == comchar) {
+ if (token.GetNextToken() == _T("alias"))
+ cset->names.Add(token.GetNextToken());
+ }
+ else if (cmd == _T("<code_set_name>"))
+ cset->names.Add(token.GetNextToken());
+ else if (cmd == _T("<comment_char>"))
+ comchar = token.GetNextToken();
+ else if (cmd == _T("<escape_char>"))
+ escchar = token.GetNextToken();
+ else if (cmd == _T("<mb_cur_min>")) {
+ delete cset;
+ cset = (wxCharacterSet *) NULL;
+ break; // we don't support multibyte charsets ourselves (yet)
+ }
+ else if (cmd == _T("CHARMAP")) {
+ cset->data = (wchar_t *)calloc(256, sizeof(wchar_t));
+ in_charset = TRUE;
+ }
+ else if (cmd == _T("END")) {
+ if (token.GetNextToken() == _T("CHARMAP"))
+ in_charset = FALSE;
+ }
+ else if (in_charset) {
+ // format: <NUL> /x00 <U0000> NULL (NUL)
+ // <A> /x41 <U0041> LATIN CAPITAL LETTER A
+ wxString hex = token.GetNextToken();
+ // skip whitespace (why doesn't wxStringTokenizer do this?)
+ while (wxIsEmpty(hex) && token.HasMoreTokens()) hex = token.GetNextToken();
+ wxString uni = token.GetNextToken();
+ // skip whitespace again
+ while (wxIsEmpty(uni) && token.HasMoreTokens()) uni = token.GetNextToken();
+ if ((hex.Len() > 2) && (wxString(hex.GetChar(0)) == escchar) && (hex.GetChar(1) == _T('x')) &&
+ (uni.Left(2) == _T("<U"))) {
+ hex.MakeUpper(); uni.MakeUpper();
+ int pos = ::wxHexToDec(hex.Mid(2,2));
+ if (pos>=0) {
+ unsigned long uni1 = ::wxHexToDec(uni.Mid(2,2));
+ unsigned long uni2 = ::wxHexToDec(uni.Mid(4,2));
+ cset->data[pos] = (uni1 << 16) | uni2;
+ // wxFprintf(stderr,_T("char %02x mapped to %04x (%c)\n"),pos,cset->data[pos],cset->data[pos]);
+ }
+ }
+ }
+ }
+ if (cset) {
+ cset->names.Shrink();
+ wxCharsets.Add(cset);
+ }
+ }
+ }
+#endif
+ wxCharsets.Shrink();
+}
+
+static wxCharacterSet *wxFindCharacterSet(const wxChar *charset)
+{
+ if (!charset) return (wxCharacterSet *)NULL;
+ wxLoadCharacterSets();
+ for (size_t n=0; n<wxCharsets.GetCount(); n++)
+ if (wxCharsets[n].names.Index(charset) != wxNOT_FOUND)
+ return &(wxCharsets[n]);
+ return (wxCharacterSet *)NULL;
+}
+
+WXDLLEXPORT_DATA(wxCSConv) wxConvLocal((const wxChar *)NULL);
+
+wxCSConv::wxCSConv(const wxChar *charset)
+{
+ m_name = (wxChar *) NULL;
+ m_cset = (wxCharacterSet *) NULL;
+ m_deferred = TRUE;
+ SetName(charset);
+}
+
+wxCSConv::~wxCSConv()
+{
+ if (m_name) free(m_name);
+}
+
+void wxCSConv::SetName(const wxChar *charset)
+{
+ if (charset) {
+#ifdef __UNIX__
+ // first, convert the character set name to standard form
+ wxString codeset;
+ if (wxString(charset,3).CmpNoCase(_T("ISO")) == 0) {
+ // make sure it's represented in the standard form: ISO_8859-1
+ codeset = _T("ISO_");
+ charset += 3;
+ if ((*charset == _T('-')) || (*charset == _T('_'))) charset++;
+ if (wxStrlen(charset)>4) {
+ if (wxString(charset,4) == _T("8859")) {
+ codeset << _T("8859-");
+ if (*charset == _T('-')) charset++;
+ }
+ }
+ }
+ codeset << charset;
+ codeset.MakeUpper();
+ m_name = wxStrdup(codeset.c_str());
+ m_deferred = TRUE;
+#endif
+ }
+}
+
+void wxCSConv::LoadNow()
+{
+// wxPrintf(_T("Conversion request\n"));
+ if (m_deferred) {
+ if (!m_name) {
+#ifdef __UNIX__
+ wxChar *lang = wxGetenv(_T("LANG"));
+ wxChar *dot = lang ? wxStrchr(lang, _T('.')) : (wxChar *)NULL;
+ if (dot) SetName(dot+1);
+#endif
+ }
+ m_cset = wxFindCharacterSet(m_name);
+ m_deferred = FALSE;
+ }
+}
+
+size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
+{
+ ((wxCSConv *)this)->LoadNow(); // discard constness
+ if (buf) {
+ if (m_cset) {
+ for (size_t c=0; c<n; c++)
+ buf[c] = m_cset->data[(unsigned char)(psz[c])];
+ } else {
+ // latin-1 (direct)
+ for (size_t c=0; c<n; c++)
+ buf[c] = (unsigned char)(psz[c]);
+ }
+ return n;
+ }
+ return strlen(psz);
+}
+
+size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
+{
+ ((wxCSConv *)this)->LoadNow(); // discard constness
+ if (buf) {
+ if (m_cset) {
+ for (size_t c=0; c<n; c++) {
+ size_t n;
+ for (n=0; (n<256) && (m_cset->data[n] != psz[c]); n++);
+ buf[c] = (n>0xff) ? '?' : n;
+ }
+ } else {
+ // latin-1 (direct)
+ for (size_t c=0; c<n; c++)
+ buf[c] = (psz[c]>0xff) ? '?' : psz[c];
+ }
+ return n;
+ }
+ return wcslen(psz);
+}
+
+#endif
+ //wxUSE_WCHAR_T
+
+
qsort(m_pItems, m_nCount, sizeof(wxChar *), wxStringCompareFunction);
}
-// ============================================================================
-// MBConv
-// ============================================================================
-
-WXDLLEXPORT_DATA(wxMBConv *) wxConvCurrent = &wxConvLibc;
-#if !wxUSE_WCHAR_T
-WXDLLEXPORT_DATA(wxMBConv) wxConvLibc, wxConvFile;
-#endif
-
-#if wxUSE_WCHAR_T
-
-// ----------------------------------------------------------------------------
-// standard libc conversion
-// ----------------------------------------------------------------------------
-
-WXDLLEXPORT_DATA(wxMBConv) wxConvLibc;
-
-size_t wxMBConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
-{
- return wxMB2WC(buf, psz, n);
-}
-
-size_t wxMBConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
-{
- return wxWC2MB(buf, psz, n);
-}
-
-// ----------------------------------------------------------------------------
-// standard file conversion
-// ----------------------------------------------------------------------------
-
-WXDLLEXPORT_DATA(wxMBConvFile) wxConvFile;
-
-// just use the libc conversion for now
-size_t wxMBConvFile::MB2WC(wchar_t *buf, const char *psz, size_t n) const
-{
- return wxMB2WC(buf, psz, n);
-}
-
-size_t wxMBConvFile::WC2MB(char *buf, const wchar_t *psz, size_t n) const
-{
- return wxWC2MB(buf, psz, n);
-}
-
-// ----------------------------------------------------------------------------
-// standard gdk conversion
-// ----------------------------------------------------------------------------
-
-#ifdef __WXGTK12__
-WXDLLEXPORT_DATA(wxMBConvGdk) wxConvGdk;
-
-#include <gdk/gdk.h>
-
-size_t wxMBConvGdk::MB2WC(wchar_t *buf, const char *psz, size_t n) const
-{
- if (buf) {
- return gdk_mbstowcs((GdkWChar *)buf, psz, n);
- } else {
- GdkWChar *nbuf = new GdkWChar[n=strlen(psz)];
- size_t len = gdk_mbstowcs(nbuf, psz, n);
- delete [] nbuf;
- return len;
- }
-}
-
-size_t wxMBConvGdk::WC2MB(char *buf, const wchar_t *psz, size_t n) const
-{
- char *mbstr = gdk_wcstombs((GdkWChar *)psz);
- size_t len = mbstr ? strlen(mbstr) : 0;
- if (buf) {
- if (len > n) len = n;
- memcpy(buf, psz, len);
- if (len < n) buf[len] = 0;
- }
- return len;
-}
-#endif // GTK > 1.0
-
-// ----------------------------------------------------------------------------
-// UTF-7
-// ----------------------------------------------------------------------------
-
-WXDLLEXPORT_DATA(wxMBConvUTF7) wxConvUTF7;
-
-#if 0
-static char utf7_setD[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789'(),-./:?";
-static char utf7_setO[]="!\"#$%&*;<=>@[]^_`{|}";
-static char utf7_setB[]="ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- "abcdefghijklmnopqrstuvwxyz"
- "0123456789+/";
-#endif
-
-// TODO: write actual implementations of UTF-7 here
-size_t wxMBConvUTF7::MB2WC(wchar_t * WXUNUSED(buf),
- const char * WXUNUSED(psz),
- size_t WXUNUSED(n)) const
-{
- return 0;
-}
-
-size_t wxMBConvUTF7::WC2MB(char * WXUNUSED(buf),
- const wchar_t * WXUNUSED(psz),
- size_t WXUNUSED(n)) const
-{
- return 0;
-}
-
-// ----------------------------------------------------------------------------
-// UTF-8
-// ----------------------------------------------------------------------------
-
-WXDLLEXPORT_DATA(wxMBConvUTF8) wxConvUTF8;
-
-static unsigned long utf8_max[]={0x7f,0x7ff,0xffff,0x1fffff,0x3ffffff,0x7fffffff,0xffffffff};
-
-size_t wxMBConvUTF8::MB2WC(wchar_t *buf, const char *psz, size_t n) const
-{
- size_t len = 0;
-
- while (*psz && ((!buf) || (len<n))) {
- unsigned char cc=*psz++, fc=cc;
- unsigned cnt;
- for (cnt=0; fc&0x80; cnt++) fc<<=1;
- if (!cnt) {
- // plain ASCII char
- if (buf) *buf++=cc;
- len++;
- } else {
- cnt--;
- if (!cnt) {
- // invalid UTF-8 sequence
- return (size_t)-1;
- } else {
- unsigned ocnt=cnt-1;
- unsigned long res=cc&(0x3f>>cnt);
- while (cnt--) {
- cc = *psz++;
- if ((cc&0xC0)!=0x80) {
- // invalid UTF-8 sequence
- return (size_t)-1;
- }
- res=(res<<6)|(cc&0x3f);
- }
- if (res<=utf8_max[ocnt]) {
- // illegal UTF-8 encoding
- return (size_t)-1;
- }
- if (buf) *buf++=res;
- len++;
- }
- }
- }
- if (buf && (len<n)) *buf = 0;
- return len;
-}
-
-size_t wxMBConvUTF8::WC2MB(char *buf, const wchar_t *psz, size_t n) const
-{
- size_t len = 0;
-
- while (*psz && ((!buf) || (len<n))) {
- unsigned long cc=(*psz++)&0x7fffffff;
- unsigned cnt;
- for (cnt=0; cc>utf8_max[cnt]; cnt++);
- if (!cnt) {
- // plain ASCII char
- if (buf) *buf++=cc;
- len++;
- } else {
- len+=cnt+1;
- if (buf) {
- *buf++=(-128>>cnt)|((cc>>(cnt*6))&(0x3f>>cnt));
- while (cnt--)
- *buf++=0x80|((cc>>(cnt*6))&0x3f);
- }
- }
- }
- if (buf && (len<n)) *buf = 0;
- return len;
-}
-
-// ----------------------------------------------------------------------------
-// specified character set
-// ----------------------------------------------------------------------------
-
-class wxCharacterSet
-{
-public:
- wxArrayString names;
- wchar_t *data;
-};
-
-#ifndef WX_PRECOMP
- #include "wx/dynarray.h"
- #include "wx/filefn.h"
- #include "wx/textfile.h"
- #include "wx/tokenzr.h"
- #include "wx/utils.h"
-#endif
-
-WX_DECLARE_OBJARRAY(wxCharacterSet, wxCSArray);
-#include "wx/arrimpl.cpp"
-WX_DEFINE_OBJARRAY(wxCSArray);
-
-static wxCSArray wxCharsets;
-
-static void wxLoadCharacterSets(void)
-{
- static bool already_loaded = FALSE;
-
- if (already_loaded) return;
-
- already_loaded = TRUE;
-#if defined(__UNIX__) && wxUSE_TEXTFILE
- // search through files in /usr/share/i18n/charmaps
- wxString fname;
- for (fname = ::wxFindFirstFile(_T("/usr/share/i18n/charmaps/*"));
- !fname.IsEmpty();
- fname = ::wxFindNextFile()) {
- wxTextFile cmap(fname);
- if (cmap.Open()) {
- wxCharacterSet *cset = new wxCharacterSet;
- wxString comchar,escchar;
- bool in_charset = FALSE;
-
- // wxFprintf(stderr,_T("Loaded: %s\n"),fname.c_str());
-
- wxString line;
- for (line = cmap.GetFirstLine();
- !cmap.Eof();
- line = cmap.GetNextLine()) {
- // wxFprintf(stderr,_T("line contents: %s\n"),line.c_str());
- wxStringTokenizer token(line);
- wxString cmd = token.GetNextToken();
- if (cmd == comchar) {
- if (token.GetNextToken() == _T("alias"))
- cset->names.Add(token.GetNextToken());
- }
- else if (cmd == _T("<code_set_name>"))
- cset->names.Add(token.GetNextToken());
- else if (cmd == _T("<comment_char>"))
- comchar = token.GetNextToken();
- else if (cmd == _T("<escape_char>"))
- escchar = token.GetNextToken();
- else if (cmd == _T("<mb_cur_min>")) {
- delete cset;
- cset = (wxCharacterSet *) NULL;
- break; // we don't support multibyte charsets ourselves (yet)
- }
- else if (cmd == _T("CHARMAP")) {
- cset->data = (wchar_t *)calloc(256, sizeof(wchar_t));
- in_charset = TRUE;
- }
- else if (cmd == _T("END")) {
- if (token.GetNextToken() == _T("CHARMAP"))
- in_charset = FALSE;
- }
- else if (in_charset) {
- // format: <NUL> /x00 <U0000> NULL (NUL)
- // <A> /x41 <U0041> LATIN CAPITAL LETTER A
- wxString hex = token.GetNextToken();
- // skip whitespace (why doesn't wxStringTokenizer do this?)
- while (wxIsEmpty(hex) && token.HasMoreTokens()) hex = token.GetNextToken();
- wxString uni = token.GetNextToken();
- // skip whitespace again
- while (wxIsEmpty(uni) && token.HasMoreTokens()) uni = token.GetNextToken();
- if ((hex.Len() > 2) && (wxString(hex.GetChar(0)) == escchar) && (hex.GetChar(1) == _T('x')) &&
- (uni.Left(2) == _T("<U"))) {
- hex.MakeUpper(); uni.MakeUpper();
- int pos = ::wxHexToDec(hex.Mid(2,2));
- if (pos>=0) {
- unsigned long uni1 = ::wxHexToDec(uni.Mid(2,2));
- unsigned long uni2 = ::wxHexToDec(uni.Mid(4,2));
- cset->data[pos] = (uni1 << 16) | uni2;
- // wxFprintf(stderr,_T("char %02x mapped to %04x (%c)\n"),pos,cset->data[pos],cset->data[pos]);
- }
- }
- }
- }
- if (cset) {
- cset->names.Shrink();
- wxCharsets.Add(cset);
- }
- }
- }
-#endif
- wxCharsets.Shrink();
-}
-
-static wxCharacterSet *wxFindCharacterSet(const wxChar *charset)
-{
- if (!charset) return (wxCharacterSet *)NULL;
- wxLoadCharacterSets();
- for (size_t n=0; n<wxCharsets.GetCount(); n++)
- if (wxCharsets[n].names.Index(charset) != wxNOT_FOUND)
- return &(wxCharsets[n]);
- return (wxCharacterSet *)NULL;
-}
-
-WXDLLEXPORT_DATA(wxCSConv) wxConvLocal((const wxChar *)NULL);
-
-wxCSConv::wxCSConv(const wxChar *charset)
-{
- m_name = (wxChar *) NULL;
- m_cset = (wxCharacterSet *) NULL;
- m_deferred = TRUE;
- SetName(charset);
-}
-
-wxCSConv::~wxCSConv()
-{
- if (m_name) free(m_name);
-}
-
-void wxCSConv::SetName(const wxChar *charset)
-{
- if (charset) {
-#ifdef __UNIX__
- // first, convert the character set name to standard form
- wxString codeset;
- if (wxString(charset,3).CmpNoCase(_T("ISO")) == 0) {
- // make sure it's represented in the standard form: ISO_8859-1
- codeset = _T("ISO_");
- charset += 3;
- if ((*charset == _T('-')) || (*charset == _T('_'))) charset++;
- if (wxStrlen(charset)>4) {
- if (wxString(charset,4) == _T("8859")) {
- codeset << _T("8859-");
- if (*charset == _T('-')) charset++;
- }
- }
- }
- codeset << charset;
- codeset.MakeUpper();
- m_name = wxStrdup(codeset.c_str());
- m_deferred = TRUE;
-#endif
- }
-}
-
-void wxCSConv::LoadNow()
-{
-// wxPrintf(_T("Conversion request\n"));
- if (m_deferred) {
- if (!m_name) {
-#ifdef __UNIX__
- wxChar *lang = wxGetenv(_T("LANG"));
- wxChar *dot = lang ? wxStrchr(lang, _T('.')) : (wxChar *)NULL;
- if (dot) SetName(dot+1);
-#endif
- }
- m_cset = wxFindCharacterSet(m_name);
- m_deferred = FALSE;
- }
-}
-
-size_t wxCSConv::MB2WC(wchar_t *buf, const char *psz, size_t n) const
-{
- ((wxCSConv *)this)->LoadNow(); // discard constness
- if (buf) {
- if (m_cset) {
- for (size_t c=0; c<n; c++)
- buf[c] = m_cset->data[(unsigned char)(psz[c])];
- } else {
- // latin-1 (direct)
- for (size_t c=0; c<n; c++)
- buf[c] = (unsigned char)(psz[c]);
- }
- return n;
- }
- return strlen(psz);
-}
-
-size_t wxCSConv::WC2MB(char *buf, const wchar_t *psz, size_t n) const
-{
- ((wxCSConv *)this)->LoadNow(); // discard constness
- if (buf) {
- if (m_cset) {
- for (size_t c=0; c<n; c++) {
- size_t n;
- for (n=0; (n<256) && (m_cset->data[n] != psz[c]); n++);
- buf[c] = (n>0xff) ? '?' : n;
- }
- } else {
- // latin-1 (direct)
- for (size_t c=0; c<n; c++)
- buf[c] = (psz[c]>0xff) ? '?' : psz[c];
- }
- return n;
- }
- return wcslen(psz);
-}
-
-#endif//wxUSE_WCHAR_T
-
-#if wxUSE_WCHAR_T
-const wxWCharBuffer wxMBConv::cMB2WC(const char *psz) const
- {
- if (psz) {
- size_t nLen = MB2WC((wchar_t *) NULL, psz, 0);
- wxWCharBuffer buf(nLen);
- MB2WC(WCSTRINGCAST buf, psz, nLen);
- return buf;
- } else return wxWCharBuffer((wchar_t *) NULL);
- }
-
-const wxCharBuffer wxMBConv::cWC2MB(const wchar_t *psz) const
- {
- if (psz) {
- size_t nLen = WC2MB((char *) NULL, psz, 0);
- wxCharBuffer buf(nLen);
- WC2MB(MBSTRINGCAST buf, psz, nLen);
- return buf;
- } else return wxCharBuffer((char *) NULL);
- }
-
-#endif//wxUSE_WCHAR_T
-
+++ /dev/null
-/////////////////////////////////////////////////////////////////////////////
-// Name: zipstream.cpp
-// Purpose: input stream for ZIP archive access
-// Author: Vaclav Slavik
-// Copyright: (c) 1999 Vaclav Slavik
-// Licence: wxWindows Licence
-/////////////////////////////////////////////////////////////////////////////
-
-#ifdef __GNUG__
-#pragma implementation "zipstream.h"
-#endif
-
-// For compilers that support precompilation, includes "wx.h".
-#include "wx/wxprec.h"
-
-#ifdef __BORLANDC__
- #pragma hdrstop
-#endif
-
-#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
-
-#include "wx/log.h"
-#include "wx/intl.h"
-#include "wx/stream.h"
-#include "wx/wfstream.h"
-#include "wx/zipstream.h"
-
-/* Not the right solution (paths in makefiles) but... */
-#ifdef __BORLANDC__
-#include "../common/unzip.h"
-#else
-#include "unzip.h"
-#endif
-
-
-wxZipInputStream::wxZipInputStream(const wxString& archive, const wxString& file) : wxInputStream()
-{
- unz_file_info zinfo;
-
- m_Pos = 0;
- m_Size = 0;
- m_Archive = (void*) unzOpen(archive.mb_str(wxConvFile));
- if (m_Archive == NULL)
- {
- m_lasterror = wxStream_READ_ERR;
- return;
- }
- if (unzLocateFile((unzFile)m_Archive, file.mb_str(wxConvFile), 0) != UNZ_OK)
- {
- m_lasterror = wxStream_READ_ERR;
- return;
- }
-
- unzGetCurrentFileInfo((unzFile)m_Archive, &zinfo, (char*) NULL, 0, (void*) NULL, 0, (char*) NULL, 0);
-
- if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK)
- {
- m_lasterror = wxStream_READ_ERR;
- return;
- }
- m_Size = zinfo.uncompressed_size;
-}
-
-
-
-wxZipInputStream::~wxZipInputStream()
-{
- if (m_Archive)
- {
- if (m_Size != 0)
- unzCloseCurrentFile((unzFile)m_Archive);
- unzClose((unzFile)m_Archive);
- }
-}
-
-
-
-size_t wxZipInputStream::OnSysRead(void *buffer, size_t bufsize)
-{
- if (m_Pos + bufsize > m_Size) bufsize = m_Size - m_Pos;
- unzReadCurrentFile((unzFile)m_Archive, buffer, bufsize);
- m_Pos += bufsize;
- return bufsize;
-}
-
-
-
-off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
-{
- off_t nextpos;
- void *buf;
-
- switch (mode)
- {
- case wxFromCurrent : nextpos = seek + m_Pos; break;
- case wxFromStart : nextpos = seek; break;
- case wxFromEnd : nextpos = m_Size - 1 + seek; break;
- default : nextpos = m_Pos; break; /* just to fool compiler, never happens */
- }
-
- // cheated seeking :
- if (nextpos > m_Pos)
- {
- buf = malloc(nextpos - m_Pos);
- unzReadCurrentFile((unzFile)m_Archive, buf, nextpos - m_Pos);
- free(buf);
- }
- else if (nextpos < m_Pos) {
- unzCloseCurrentFile((unzFile)m_Archive);
- if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK)
- {
- m_lasterror = wxStream_READ_ERR;
- return m_Pos;
- }
- buf = malloc(nextpos);
- unzReadCurrentFile((unzFile)m_Archive, buf, nextpos);
- free(buf);
- }
-
- m_Pos = nextpos;
- return m_Pos;
-}
-
-#endif
- // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
--- /dev/null
+/////////////////////////////////////////////////////////////////////////////
+// Name: zipstream.cpp
+// Purpose: input stream for ZIP archive access
+// Author: Vaclav Slavik
+// Copyright: (c) 1999 Vaclav Slavik
+// Licence: wxWindows Licence
+/////////////////////////////////////////////////////////////////////////////
+
+#ifdef __GNUG__
+#pragma implementation "zipstream.h"
+#endif
+
+// For compilers that support precompilation, includes "wx.h".
+#include "wx/wxprec.h"
+
+#ifdef __BORLANDC__
+ #pragma hdrstop
+#endif
+
+#if wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
+
+#include "wx/log.h"
+#include "wx/intl.h"
+#include "wx/stream.h"
+#include "wx/wfstream.h"
+#include "wx/zipstrm.h"
+
+/* Not the right solution (paths in makefiles) but... */
+#ifdef __BORLANDC__
+#include "../common/unzip.h"
+#else
+#include "unzip.h"
+#endif
+
+
+wxZipInputStream::wxZipInputStream(const wxString& archive, const wxString& file) : wxInputStream()
+{
+ unz_file_info zinfo;
+
+ m_Pos = 0;
+ m_Size = 0;
+ m_Archive = (void*) unzOpen(archive.mb_str(wxConvFile));
+ if (m_Archive == NULL)
+ {
+ m_lasterror = wxStream_READ_ERR;
+ return;
+ }
+ if (unzLocateFile((unzFile)m_Archive, file.mb_str(wxConvFile), 0) != UNZ_OK)
+ {
+ m_lasterror = wxStream_READ_ERR;
+ return;
+ }
+
+ unzGetCurrentFileInfo((unzFile)m_Archive, &zinfo, (char*) NULL, 0, (void*) NULL, 0, (char*) NULL, 0);
+
+ if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK)
+ {
+ m_lasterror = wxStream_READ_ERR;
+ return;
+ }
+ m_Size = zinfo.uncompressed_size;
+}
+
+
+
+wxZipInputStream::~wxZipInputStream()
+{
+ if (m_Archive)
+ {
+ if (m_Size != 0)
+ unzCloseCurrentFile((unzFile)m_Archive);
+ unzClose((unzFile)m_Archive);
+ }
+}
+
+
+
+size_t wxZipInputStream::OnSysRead(void *buffer, size_t bufsize)
+{
+ if (m_Pos + bufsize > m_Size) bufsize = m_Size - m_Pos;
+ unzReadCurrentFile((unzFile)m_Archive, buffer, bufsize);
+ m_Pos += bufsize;
+ return bufsize;
+}
+
+
+
+off_t wxZipInputStream::OnSysSeek(off_t seek, wxSeekMode mode)
+{
+ off_t nextpos;
+ void *buf;
+
+ switch (mode)
+ {
+ case wxFromCurrent : nextpos = seek + m_Pos; break;
+ case wxFromStart : nextpos = seek; break;
+ case wxFromEnd : nextpos = m_Size - 1 + seek; break;
+ default : nextpos = m_Pos; break; /* just to fool compiler, never happens */
+ }
+
+ // cheated seeking :
+ if (nextpos > m_Pos)
+ {
+ buf = malloc(nextpos - m_Pos);
+ unzReadCurrentFile((unzFile)m_Archive, buf, nextpos - m_Pos);
+ free(buf);
+ }
+ else if (nextpos < m_Pos) {
+ unzCloseCurrentFile((unzFile)m_Archive);
+ if (unzOpenCurrentFile((unzFile)m_Archive) != UNZ_OK)
+ {
+ m_lasterror = wxStream_READ_ERR;
+ return m_Pos;
+ }
+ buf = malloc(nextpos);
+ unzReadCurrentFile((unzFile)m_Archive, buf, nextpos);
+ free(buf);
+ }
+
+ m_Pos = nextpos;
+ return m_Pos;
+}
+
+#endif
+ // wxUSE_STREAMS && wxUSE_ZIPSTREAM && wxUSE_ZLIB
sckstrm.cpp \
serbase.cpp \
socket.cpp \
+ strconv.cpp \
stream.cpp \
string.cpp \
tbarbase.cpp \
wxchar.cpp \
wxexpr.cpp \
zstream.cpp \
- zipstream.cpp \
+ zipstrm.cpp \
\
db.cpp \
dbtable.cpp \
sckstrm.cpp \
serbase.cpp \
socket.cpp \
+ strconv.cpp \
stream.cpp \
string.cpp \
tbarbase.cpp \
wxchar.cpp \
wxexpr.cpp \
zstream.cpp \
- zipstream.cpp \
+ zipstrm.cpp \
\
db.cpp \
dbtable.cpp \
memory.cpp \
module.cpp \
object.cpp \
+ strconv.cpp \
string.cpp \
timercmn.cpp \
utilscmn.cpp \
wincmn.cpp \
wxexpr.cpp \
unzip.c \
- zipstream.cpp \
+ zipstrm.cpp \
zstream.cpp \
\
busyinfo.cpp \
##
## Process this file with automake to produce Makefile.in
-AUTOMAKE_OPTIONS =
-# 1.3 no-dependencies
+AUTOMAKE_OPTIONS = 1.3
+# no-dependencies
SUFFIXES = .cpp .c
module.cpp \
object.cpp \
string.cpp \
+ strconv.cpp \
timercmn.cpp \
utilscmn.cpp \
tokenzr.cpp \
wfstream.cpp \
wincmn.cpp \
wxexpr.cpp \
- zipstream.cpp \
+ zipstrm.cpp \
zstream.cpp \
\
busyinfo.cpp \