summaryrefslogtreecommitdiff
path: root/src/utilfuns
diff options
context:
space:
mode:
Diffstat (limited to 'src/utilfuns')
-rw-r--r--src/utilfuns/Makefile.am1
-rw-r--r--src/utilfuns/ftplib.c63
-rw-r--r--src/utilfuns/roman.cpp13
-rw-r--r--src/utilfuns/swbuf.cpp50
-rw-r--r--src/utilfuns/swobject.cpp45
-rw-r--r--src/utilfuns/swunicod.cpp138
-rw-r--r--src/utilfuns/swversion.cpp18
-rw-r--r--src/utilfuns/url.cpp90
-rw-r--r--src/utilfuns/utilstr.cpp217
-rw-r--r--src/utilfuns/utilxml.cpp18
-rw-r--r--src/utilfuns/zlib/untgz.c27
11 files changed, 367 insertions, 313 deletions
diff --git a/src/utilfuns/Makefile.am b/src/utilfuns/Makefile.am
index fcbdaeb..f934eeb 100644
--- a/src/utilfuns/Makefile.am
+++ b/src/utilfuns/Makefile.am
@@ -8,7 +8,6 @@ utilfunsdir = $(top_srcdir)/src/utilfuns
libsword_la_SOURCES += $(utilfunsdir)/swobject.cpp
libsword_la_SOURCES += $(utilfunsdir)/utilstr.cpp
libsword_la_SOURCES += $(utilfunsdir)/utilxml.cpp
-libsword_la_SOURCES += $(utilfunsdir)/swunicod.cpp
libsword_la_SOURCES += $(utilfunsdir)/swversion.cpp
libsword_la_SOURCES += $(utilfunsdir)/swbuf.cpp
libsword_la_SOURCES += $(utilfunsdir)/ftpparse.c
diff --git a/src/utilfuns/ftplib.c b/src/utilfuns/ftplib.c
index b184a91..a211973 100644
--- a/src/utilfuns/ftplib.c
+++ b/src/utilfuns/ftplib.c
@@ -1,23 +1,23 @@
/***************************************************************************/
-/* ftplib.c - callable ftp access routines */
-/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */
-/* 73 Catherine Street, South Bound Brook, NJ, 08880 */
-/* */
-/* This library is free software; you can redistribute it and/or */
-/* modify it under the terms of the GNU Library General Public */
-/* License as published by the Free Software Foundation; either */
-/* version 2 of the License, or (at your option) any later version. */
-/* */
-/* This library is distributed in the hope that it will be useful, */
-/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
-/* Library General Public License for more details. */
-/* */
-/* You should have received a copy of the GNU Library General Public */
-/* License along with this progam; if not, write to the */
-/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
-/* Boston, MA 02111-1307, USA. */
-/* */
+/* ftplib.c - callable ftp access routines */
+/* Copyright (C) 1996-2000 Thomas Pfau, pfau@cnj.digex.net */
+/* 73 Catherine Street, South Bound Brook, NJ, 08880 */
+/* */
+/* This library is free software; you can redistribute it and/or */
+/* modify it under the terms of the GNU Library General Public */
+/* License as published by the Free Software Foundation; either */
+/* version 2 of the License, or (at your option) any later version. */
+/* */
+/* This library is distributed in the hope that it will be useful, */
+/* but WITHOUT ANY WARRANTY; without even the implied warranty of */
+/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU */
+/* Library General Public License for more details. */
+/* */
+/* You should have received a copy of the GNU Library General Public */
+/* License along with this progam; if not, write to the */
+/* Free Software Foundation, Inc., 59 Temple Place - Suite 330, */
+/* Boston, MA 02111-1307, USA. */
+/* */
/***************************************************************************/
// changes made by Lorn Potter <llornkcor@handhelds.org>
//
@@ -126,15 +126,19 @@ struct NetBuf {
int cmode;
struct timeval idletime;
FtpCallback idlecb;
+ FtpCallbackWriter writercb;
void *idlearg;
+ void *writerarg;
int xfered;
int cbbytes;
int xfered1;
char response[256];
};
+#if 0
static char *version =
"ftplib Release 3.1-1 9/16/00, copyright 1996-2000 Thomas Pfau";
+#endif
GLOBALDEF int ftplib_debug = 0;
@@ -569,8 +573,10 @@ GLOBALDEF int FtpConnect(const char *host, netbuf **nControl)
ctrl->ctrl = NULL;
ctrl->cmode = FTPLIB_DEFMODE;
ctrl->idlecb = NULL;
+ ctrl->writercb = NULL;
ctrl->idletime.tv_sec = ctrl->idletime.tv_usec = 0;
ctrl->idlearg = NULL;
+ ctrl->writerarg = NULL;
ctrl->xfered = 0;
ctrl->xfered1 = 0;
ctrl->cbbytes = 0;
@@ -607,6 +613,10 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
nControl->idlecb = (FtpCallback) val;
rv = 1;
break;
+ case FTPLIB_CALLBACK_WRITER:
+ nControl->writercb = (FtpCallbackWriter) val;
+ rv = 1;
+ break;
case FTPLIB_IDLETIME:
v = (int) val;
rv = 1;
@@ -617,6 +627,10 @@ GLOBALDEF int FtpOptions(int opt, long val, netbuf *nControl)
rv = 1;
nControl->idlearg = (void *) val;
break;
+ case FTPLIB_CALLBACK_WRITERARG:
+ rv = 1;
+ nControl->writerarg = (void *) val;
+ break;
case FTPLIB_CALLBACKBYTES:
rv = 1;
nControl->cbbytes = (int) val;
@@ -807,6 +821,7 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
ctrl->dir = dir;
ctrl->idletime = nControl->idletime;
ctrl->idlearg = nControl->idlearg;
+ ctrl->writerarg = nControl->writerarg;
ctrl->xfered = 0;
ctrl->xfered1 = 0;
ctrl->cbbytes = nControl->cbbytes;
@@ -814,6 +829,7 @@ static int FtpOpenPort(netbuf *nControl, netbuf **nData, int mode, int dir)
ctrl->idlecb = nControl->idlecb;
else
ctrl->idlecb = NULL;
+ ctrl->writercb = nControl->writercb;
*nData = ctrl;
return 1;
}
@@ -1203,6 +1219,7 @@ static int FtpXfer(const char *localfile, const char *path,
FILE *local = NULL;
netbuf *nData;
int rv=1;
+ int writeResult = 0;
if (localfile != NULL)
{
@@ -1237,13 +1254,15 @@ static int FtpXfer(const char *localfile, const char *path,
}
else
{
- while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0)
- if (fwrite(dbuf, 1, l, local) <= 0)
+ while ((l = FtpRead(dbuf, FTPLIB_BUFSIZ, nData)) > 0) {
+ writeResult = (nData->writercb) ? nData->writercb(nData, dbuf, l, nData->writerarg) : fwrite(dbuf, 1, l, local);
+ if (writeResult <= 0)
{
- perror("localfile write");
+ perror("localstore write");
rv = 0;
break;
}
+ }
}
free(dbuf);
fflush(local);
diff --git a/src/utilfuns/roman.cpp b/src/utilfuns/roman.cpp
index 4db9540..d436b19 100644
--- a/src/utilfuns/roman.cpp
+++ b/src/utilfuns/roman.cpp
@@ -1,7 +1,10 @@
-/*
- * roman.c
+/******************************************************************************
*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+ * roman.cpp -
+ *
+ * $Id: roman.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2002-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -21,8 +24,10 @@
#include <string.h>
#include <roman.h>
+
SWORD_NAMESPACE_START
+
char isroman (const char *str, int maxchars) {
char *ch = (char*)str;
for (; *ch && (!maxchars || (ch-str) <= maxchars); ch++)
@@ -82,4 +87,6 @@ int from_rom(const char* str) {
return n;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/utilfuns/swbuf.cpp b/src/utilfuns/swbuf.cpp
index 53dd43a..9c4908b 100644
--- a/src/utilfuns/swbuf.cpp
+++ b/src/utilfuns/swbuf.cpp
@@ -1,23 +1,24 @@
/******************************************************************************
-* swbuf.cpp - code for SWBuf used as a transport and utility for data buffers
-*
-* $Id: swbuf.cpp 2198 2008-09-11 20:59:30Z scribe $
-*
-* Copyright 2003 CrossWire Bible Society (http://www.crosswire.org)
-* CrossWire Bible Society
-* P. O. Box 2528
-* Tempe, AZ 85280-2528
-*
-* This program is free software; you can redistribute it and/or modify it
-* under the terms of the GNU General Public License as published by the
-* Free Software Foundation version 2.
-*
-* This program is distributed in the hope that it will be useful, but
-* WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* General Public License for more details.
-*
-*/
+ *
+ * swbuf.cpp - used as a transport and utility for data buffers
+ *
+ * $Id: swbuf.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
#include <swbuf.h>
@@ -25,10 +26,11 @@
#include <stdarg.h>
#include <stdio.h>
+
SWORD_NAMESPACE_START
+
char *SWBuf::nullStr = (char *)"";
-char SWBuf::junkBuf[JUNKBUFSIZE];
/******************************************************************************
* SWBuf Constructor - Creates an empty SWBuf object or an SWBuf initialized
@@ -81,6 +83,7 @@ SWBuf &SWBuf::setFormatted(const char *format, ...) {
va_start(argptr, format);
#ifdef NO_VSNPRINTF
+ static char junkBuf[JUNKBUFSIZE];
int len = vsprintf(junkBuf, format, argptr)+1;
#else
int len = vsnprintf(0, 0, format, argptr)+1;
@@ -97,7 +100,7 @@ SWBuf &SWBuf::setFormatted(const char *format, ...) {
* SWBuf::append - appends a value to the current value of this SWBuf
*
*/
-void SWBuf::append(const char *str, long max) {
+SWBuf &SWBuf::append(const char *str, long max) {
// if (!str) //A null string was passed
// return;
if (max < 0)
@@ -106,6 +109,7 @@ void SWBuf::append(const char *str, long max) {
for (;((max)&&(*str));max--)
*end++ = *str++;
*end = 0;
+ return *this;
}
/******************************************************************************
@@ -124,11 +128,12 @@ void SWBuf::setSize(unsigned long len) {
* WARNING: This function can only write at most
* JUNKBUFSIZE to the string per call.
*/
-void SWBuf::appendFormatted(const char *format, ...) {
+SWBuf &SWBuf::appendFormatted(const char *format, ...) {
va_list argptr;
va_start(argptr, format);
#ifdef NO_VSNPRINTF
+ static char junkBuf[JUNKBUFSIZE];
int len = vsprintf(junkBuf, format, argptr)+1;
#else
int len = vsnprintf(0, 0, format, argptr)+1;
@@ -138,6 +143,7 @@ void SWBuf::appendFormatted(const char *format, ...) {
va_start(argptr, format);
end += vsprintf(end, format, argptr);
va_end(argptr);
+ return *this;
}
void SWBuf::insert(unsigned long pos, const char* str, unsigned long start, signed long max) {
diff --git a/src/utilfuns/swobject.cpp b/src/utilfuns/swobject.cpp
index 227911b..2316111 100644
--- a/src/utilfuns/swobject.cpp
+++ b/src/utilfuns/swobject.cpp
@@ -1,24 +1,25 @@
/******************************************************************************
-* swobject.cpp - code for SWObject used as lowest base class for many
-* SWORD objects
-*
-* $Id: swobject.cpp 1785 2005-04-30 19:11:12Z scribe $
-*
-* Copyright 2005 CrossWire Bible Society (http://www.crosswire.org)
-* CrossWire Bible Society
-* P. O. Box 2528
-* Tempe, AZ 85280-2528
-*
-* This program is free software; you can redistribute it and/or modify it
-* under the terms of the GNU General Public License as published by the
-* Free Software Foundation version 2.
-*
-* This program is distributed in the hope that it will be useful, but
-* WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* General Public License for more details.
-*
-*/
+ *
+ * swobject.cpp - code for SWClass used as lowest base class for many
+ * SWORD objects
+ *
+ * $Id: swobject.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2005-2013 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
#include <swobject.h>
@@ -29,8 +30,10 @@
#include <string.h>
#endif
+
SWORD_NAMESPACE_START
+
bool SWClass::isAssignableFrom(const char *className) const {
for (int i = 0; descends[i]; i++) {
#ifndef __CYGWIN__
@@ -43,4 +46,6 @@ bool SWClass::isAssignableFrom(const char *className) const {
return false;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/utilfuns/swunicod.cpp b/src/utilfuns/swunicod.cpp
deleted file mode 100644
index 4b338eb..0000000
--- a/src/utilfuns/swunicod.cpp
+++ /dev/null
@@ -1,138 +0,0 @@
-/*
- *
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
- * CrossWire Bible Society
- * P. O. Box 2528
- * Tempe, AZ 85280-2528
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation version 2.
- *
- * This program is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * General Public License for more details.
- *
- */
-
-#include "swunicod.h"
-SWORD_NAMESPACE_START
-unsigned char* UTF32to8 (unsigned long utf32, unsigned char * utf8) {
- unsigned int i;
- for (i = 0; i < 6; i++) utf8[i] = 0;
-
- if (utf32 < 0x80) {
- utf8[0] = (char)utf32;
- }
- else if (utf32 < 0x800) {
- i = utf32 & 0x3f;
- utf8[1] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x1f;
- utf8[0] = 0xc0 | i;
- }
- else if (utf32 < 0x10000) {
- i = utf32 & 0x3f;
- utf8[2] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[1] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x0f;
- utf8[0] = 0xe0 | i;
- }
- else if (utf32 < 0x200000) {
- i = utf32 & 0x3f;
- utf8[3] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[2] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[1] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x07;
- utf8[0] = 0xf0 | i;
- }
- else if (utf32 < 0x4000000) {
- i = utf32 & 0x3f;
- utf8[4] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[3] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[2] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[1] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x03;
- utf8[0] = 0xf8 | i;
- }
- else if (utf32 < 0x80000000) {
- i = utf32 & 0x3f;
- utf8[5] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[4] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[3] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[2] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x3f;
- utf8[1] = 0x80 | i;
- utf32 >>= 6;
-
- i = utf32 & 0x01;
- utf8[0] = 0xfc | i;
- }
- return utf8;
-}
-
-unsigned long UTF8to32 (unsigned char * utf8) {
-
- unsigned char i = utf8[0];
- unsigned char count;
- unsigned long utf32 = 0;
-
- for (count = 0; i & 0x80; count++) i <<= 1;
- if (!count) {
- return utf8[0];
- }
- else if (count == 1) {
- return 0xffff;
- }
- else {
- count--;
- utf32 = i >> count;
- for (i = 1; i <= count; i++) {
- if ((0xc0 & utf8[i]) != 0x80) {
- return 0xffff;
- }
- utf32 <<= 6;
- utf32 |= (utf8[i] & 0x3f);
- }
- }
- return utf32;
-}
-
-SWORD_NAMESPACE_END
diff --git a/src/utilfuns/swversion.cpp b/src/utilfuns/swversion.cpp
index fe112db..78a00ba 100644
--- a/src/utilfuns/swversion.cpp
+++ b/src/utilfuns/swversion.cpp
@@ -1,5 +1,10 @@
-/*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+/******************************************************************************
+ *
+ * swversion.cpp - SWVersion: version number utility class
+ *
+ * $Id: swversion.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2001-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -15,16 +20,17 @@
*
*/
-#include <config.h>
-
#include <swversion.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+
SWORD_NAMESPACE_START
-SWVersion SWVersion::currentVersion( VERSION );
+
+SWVersion SWVersion::currentVersion( SWORD_VERSION_STR );
+
/******************************************************************************
* SWVersion c-tor - Constructs a new SWVersion
@@ -97,4 +103,6 @@ const char *SWVersion::getText() const {
return buf;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/utilfuns/url.cpp b/src/utilfuns/url.cpp
index 549c283..a909a04 100644
--- a/src/utilfuns/url.cpp
+++ b/src/utilfuns/url.cpp
@@ -1,25 +1,25 @@
/******************************************************************************
-* url.cpp - code for an URL parser utility class
-*
-* $Id: url.cpp 2250 2009-02-14 05:48:58Z scribe $
-*
-* Copyright 2003 CrossWire Bible Society (http://www.crosswire.org)
-* CrossWire Bible Society
-* P. O. Box 2528
-* Tempe, AZ 85280-2528
-*
-* This program is free software; you can redistribute it and/or modify it
-* under the terms of the GNU General Public License as published by the
-* Free Software Foundation version 2.
-*
-* This program is distributed in the hope that it will be useful, but
-* WITHOUT ANY WARRANTY; without even the implied warranty of
-* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-* General Public License for more details.
-*
-*/
+ *
+ * url.cpp - code for an URL parser utility class
+ *
+ * $Id: url.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2004-2013 CrossWire Bible Society (http://www.crosswire.org)
+ * CrossWire Bible Society
+ * P. O. Box 2528
+ * Tempe, AZ 85280-2528
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation version 2.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ */
-//Sword includes
#include <url.h>
#include <swlog.h>
@@ -29,10 +29,12 @@
#include <stdio.h>
#include <iostream>
+
SWORD_NAMESPACE_START
+
namespace {
- typedef std::map< unsigned char, SWBuf > DataMap;
+ typedef std::map<unsigned char, SWBuf> DataMap;
DataMap m;
static class __init {
public:
@@ -52,10 +54,11 @@ namespace {
} ___init;
}
+
/**
* Constructors/Destructors
*/
-URL::URL(const char* url)
+URL::URL(const char *url)
: url(""),
protocol(""),
hostname(""),
@@ -67,27 +70,32 @@ URL::URL(const char* url)
}
}
-const char* URL::getProtocol() const {
+
+const char *URL::getProtocol() const {
return protocol.c_str();
}
-const char* URL::getHostName () const {
+
+const char *URL::getHostName () const {
return hostname.c_str();
}
-const char* URL::getPath() const {
+
+const char *URL::getPath() const {
return path.c_str();
}
+
const URL::ParameterMap &URL::getParameters() const {
return parameterMap;
}
+
/**
* Returns the value of an URL parameter. For the URL "http://www.crosswire.org/index.jsp?page=test&amp;user=nobody" the value of the parameter "page" would be "test".
* If the parameter is not set an empty string is returned.
*/
-const char* URL::getParameterValue(const char* name) const {
+const char *URL::getParameterValue(const char *name) const {
static SWBuf emptyStr("");
ParameterMap::const_iterator it = parameterMap.find(name);
@@ -106,22 +114,22 @@ const char* URL::getParameterValue(const char* name) const {
* Parse the URL into the protocol, the hostname, the path and the paramters with their values
*
*/
-void URL::parse () {
+void URL::parse() {
/* format example protocol://hostname/path/path/path.pl?param1=value1&amp;param2=value2
- * we include the script name in the path, so the path would be /path/path/path.pl in this example
- * &amp; could also be &
- */
+ * we include the script name in the path, so the path would be /path/path/path.pl in this example
+ * &amp; could also be &
+ */
+
+ //1. Init
+ const char *urlPtr = url.c_str();
- //1. Init
- const char* urlPtr = url.c_str();
-
- protocol = "";
- hostname = "";
- path = "";
- parameterMap.clear();
+ protocol = "";
+ hostname = "";
+ path = "";
+ parameterMap.clear();
// 2. Get the protocol, which is from the begining to the first ://
- const char* end = strchr( urlPtr, ':' );
+ const char *end = strchr( urlPtr, ':' );
if (end) { //protocol was found
protocol.append(urlPtr, end-urlPtr);
urlPtr = end + 1;
@@ -174,6 +182,7 @@ void URL::parse () {
SWBuf paramName;
SWBuf paramValue;
+ if (checkAnchor) checkAnchor = false;
/*
end = strchr(urlPtr, '#');
if (!end) {
@@ -188,7 +197,7 @@ void URL::parse () {
paramValue = "";
//search for the equal sign to find the value part
- const char* valueStart = strchr(end, '=');
+ const char *valueStart = strchr(end, '=');
if (valueStart) {
const char* valueEnd = strstr(valueStart, "&amp;") ? strstr(valueStart, "&amp;") : strstr(valueStart, "&"); //try to find a new paramter part
@@ -234,6 +243,7 @@ const SWBuf URL::encode(const char *urlText) {
return url;
}
+
const SWBuf URL::decode(const char *encoded) {
/*static*/ SWBuf text;
text = encoded;
@@ -274,4 +284,6 @@ const SWBuf URL::decode(const char *encoded) {
return text;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/utilfuns/utilstr.cpp b/src/utilfuns/utilstr.cpp
index 67ffcd5..cabd455 100644
--- a/src/utilfuns/utilstr.cpp
+++ b/src/utilfuns/utilstr.cpp
@@ -1,5 +1,10 @@
-/*
- * Copyright 2009 CrossWire Bible Society (http://www.crosswire.org)
+/******************************************************************************
+ *
+ * utilstr.cpp - String utility functions
+ *
+ * $Id: utilstr.cpp 2982 2013-09-15 13:33:03Z scribe $
+ *
+ * Copyright 1997-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -26,42 +31,40 @@
SWORD_NAMESPACE_START
-const unsigned char SW_toupper_array[256] =
- {
- 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1a, 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+ 0x58, 0x59, 0x5a, 0x7b, 0x7c, 0x7d, 0x7e, 0x7f,
+ 0x80, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
+ 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
+ 0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97,
+ 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
+ 0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7,
+ 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
+ 0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7,
+ 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
+ 0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,
+ 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
+ 0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xf7,
+ 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xff
+};
/******************************************************************************
@@ -243,6 +246,103 @@ __u32 getUniCharFromUTF8(const unsigned char **buf) {
}
+SWBuf getUTF8FromUniChar(__u32 uchar) {
+ SWBuf retVal("", 7);
+ unsigned int i;
+
+ if (uchar < 0x80) {
+ retVal.append((unsigned char)uchar);
+ retVal.setSize(1);
+ }
+ else if (uchar < 0x800) {
+ retVal.setSize(2);
+ i = uchar & 0x3f;
+ retVal[1] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x1f;
+ retVal[0] = (unsigned char)(0xc0 | i);
+ }
+ else if (uchar < 0x10000) {
+ retVal.setSize(3);
+ i = uchar & 0x3f;
+ retVal[2] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[1] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x0f;
+ retVal[0] = (unsigned char)(0xe0 | i);
+ }
+ else if (uchar < 0x200000) {
+ retVal.setSize(4);
+ i = uchar & 0x3f;
+ retVal[3] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[2] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[1] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x07;
+ retVal[0] = (unsigned char)(0xf0 | i);
+ }
+ else if (uchar < 0x4000000) {
+ retVal.setSize(5);
+ i = uchar & 0x3f;
+ retVal[4] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[3] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[2] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[1] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x03;
+ retVal[0] = (unsigned char)(0xf8 | i);
+ }
+ else if (uchar < 0x80000000) {
+ retVal.setSize(6);
+ i = uchar & 0x3f;
+ retVal[5] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[4] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[3] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[2] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x3f;
+ retVal[1] = (unsigned char)(0x80 | i);
+ uchar >>= 6;
+
+ i = uchar & 0x01;
+ retVal[0] = (unsigned char)(0xfc | i);
+ }
+
+ return retVal;
+}
+
SWBuf assureValidUTF8(const char *buf) {
@@ -269,4 +369,45 @@ SWBuf assureValidUTF8(const char *buf) {
return myCopy;
}
+
+/****
+ * This can be called to convert a UTF8 stream to an SWBuf which manages
+ * a wchar_t[]
+ * access buffer with (wchar_t *)SWBuf::getRawData();
+ *
+ */
+SWBuf utf8ToWChar(const char *buf) {
+
+ const char *q = 0;
+ SWBuf wcharBuf;
+ while (*buf) {
+ q = buf;
+ wchar_t wc = getUniCharFromUTF8((const unsigned char **)&buf);
+ if (!wc) {
+ // if my buffer was advanced but nothing was converted, I had invalid data
+ if (buf - q) {
+ // invalid bytes in UTF8 stream
+ wcharBuf.append((wchar_t)0x1a); // unicode replacement character
+ }
+ }
+ else wcharBuf.append(wc);
+ }
+ return wcharBuf;
+}
+
+
+/****
+ * This can be called to convert a wchar_t[] to a UTF-8 SWBuf
+ *
+ */
+SWBuf wcharToUTF8(const wchar_t *buf) {
+
+ SWBuf utf8Buf;
+ while (*buf) {
+ utf8Buf.append(getUTF8FromUniChar(*buf++));
+ }
+ return utf8Buf;
+}
+
+
SWORD_NAMESPACE_END
diff --git a/src/utilfuns/utilxml.cpp b/src/utilfuns/utilxml.cpp
index d3af7e5..1537499 100644
--- a/src/utilfuns/utilxml.cpp
+++ b/src/utilfuns/utilxml.cpp
@@ -1,9 +1,11 @@
/******************************************************************************
- * utilxml.cpp - implementaion of utility classes to handle XML processing
*
- * $Id: utilxml.cpp 2378 2009-05-04 23:18:51Z scribe $
+ * utilxml.cpp - Implementaion of utility classes to handle
+ * XML processing
*
- * Copyright 1998 CrossWire Bible Society (http://www.crosswire.org)
+ * $Id: utilxml.cpp 2980 2013-09-14 21:51:47Z scribe $
+ *
+ * Copyright 2003-2013 CrossWire Bible Society (http://www.crosswire.org)
* CrossWire Bible Society
* P. O. Box 2528
* Tempe, AZ 85280-2528
@@ -23,9 +25,10 @@
#include <ctype.h>
#include <utilstr.h>
+
SWORD_NAMESPACE_START
-const char *XMLTag::nullstr = "";
+
void XMLTag::parse() const {
int i;
int start;
@@ -121,6 +124,7 @@ XMLTag::XMLTag(const char *tagString) {
setText(tagString);
}
+
XMLTag::XMLTag(const XMLTag& t) : attributes(t.attributes) {
parsed = t.parsed;
empty = t.empty;
@@ -137,6 +141,7 @@ XMLTag::XMLTag(const XMLTag& t) : attributes(t.attributes) {
}
}
+
void XMLTag::setText(const char *tagString) {
parsed = false;
empty = false;
@@ -173,6 +178,7 @@ void XMLTag::setText(const char *tagString) {
}
}
+
XMLTag::~XMLTag() {
if (buf)
delete [] buf;
@@ -180,6 +186,7 @@ XMLTag::~XMLTag() {
delete [] name;
}
+
const StringList XMLTag::getAttributeNames() const {
StringList retVal;
@@ -276,6 +283,7 @@ const char *XMLTag::setAttribute(const char *attribName, const char *attribValue
return attribValue;
}
+
const char *XMLTag::toString() const {
SWBuf tag = "<";
if (!parsed)
@@ -318,4 +326,6 @@ bool XMLTag::isEndTag(const char *eID) const {
return endTag;
}
+
SWORD_NAMESPACE_END
+
diff --git a/src/utilfuns/zlib/untgz.c b/src/utilfuns/zlib/untgz.c
index 2919656..a7b7164 100644
--- a/src/utilfuns/zlib/untgz.c
+++ b/src/utilfuns/zlib/untgz.c
@@ -12,7 +12,10 @@
#include <errno.h>
#include <fcntl.h>
#ifdef unix
-# include <unistd.h>
+#include <unistd.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
#else
# include <direct.h>
# include <io.h>
@@ -80,7 +83,6 @@ union tar_buffer {
enum { TGZ_EXTRACT = 0, TGZ_LIST };
-static char *TGZfname OF((const char *));
void TGZnotfound OF((const char *));
int getoct OF((char *, int));
@@ -105,23 +107,6 @@ static char *TGZprefix[] = { "\0", ".tgz", ".tar.gz", ".tar", NULL };
/* Return the real name of the TGZ archive */
/* or NULL if it does not exist. */
-static char *TGZfname OF((const char *fname))
-{
- static char buffer[1024];
- int origlen,i;
-
- strcpy(buffer,fname);
- origlen = strlen(buffer);
-
- for (i=0; TGZprefix[i]; i++)
- {
- strcpy(buffer+origlen,TGZprefix[i]);
- if (access(buffer,F_OK) == 0)
- return buffer;
- }
- return NULL;
-}
-
/* error message for the filename */
void TGZnotfound OF((const char *fname))
@@ -419,12 +404,12 @@ void help(int exitval)
void error(const char *msg)
{
fprintf(stderr, "%s: %s\n", prog, msg);
- exit(1);
+// exit(1); // don't exit on error
}
int untargz(int fd, const char *dest) {
- gzFile *f;
+ gzFile f;
f = gzdopen(fd, "rb");
if (f == NULL) {