ciderpress/util/Util.cpp

775 lines
19 KiB
C++
Raw Normal View History

2007-03-27 17:47:10 +00:00
/*
* CiderPress
* Copyright (C) 2007 by faddenSoft, LLC. All Rights Reserved.
* See the file LICENSE for distribution terms.
*/
/*
* Miscellaneous utility classes.
*/
#include "stdafx.h"
#include "Util.h"
#include <stdarg.h>
/*
* ===========================================================================
* CGripper
2007-03-27 17:47:10 +00:00
* ===========================================================================
*/
/*
* Fake out the hit testing so that it thinks we're over the scrollable bit
* when we're over the gripper.
*/
BEGIN_MESSAGE_MAP(CGripper, CScrollBar)
ON_WM_NCHITTEST()
2007-03-27 17:47:10 +00:00
END_MESSAGE_MAP()
LRESULT CGripper::OnNcHitTest(CPoint point)
2007-03-27 17:47:10 +00:00
{
UINT ht = CScrollBar::OnNcHitTest(point);
if (ht == HTCLIENT) {
ht = HTBOTTOMRIGHT;
}
return ht;
2007-03-27 17:47:10 +00:00
}
/*
* ===========================================================================
* RichEditXfer
2007-03-27 17:47:10 +00:00
* ===========================================================================
*/
/*
* At the behest of a RichEditCtrl, copy "cb" bytes of data into "pbBuff".
* The actual number of bytes transferred is placed in "*pcb".
*
* (A complete implementation would allow copying either direction.)
*
* Returns 0 on success, nonzero on error.
*/
DWORD RichEditXfer::EditStreamCallback(DWORD dwCookie, LPBYTE pbBuff,
LONG cb, LONG* pcb)
2007-03-27 17:47:10 +00:00
{
RichEditXfer* pThis = (RichEditXfer*) dwCookie;
2007-03-27 17:47:10 +00:00
2014-11-18 05:13:13 +00:00
ASSERT(dwCookie != NULL);
ASSERT(pbBuff != NULL);
ASSERT(cb != 0);
2014-11-18 05:13:13 +00:00
ASSERT(pcb != NULL);
2007-03-27 17:47:10 +00:00
long copyLen = pThis->fLen;
if (copyLen > cb)
copyLen = cb;
if (copyLen == 0) {
ASSERT(pThis->fLen == 0);
goto bail;
}
2007-03-27 17:47:10 +00:00
::memcpy(pbBuff, pThis->fBuf, copyLen);
2007-03-27 17:47:10 +00:00
pThis->fBuf += copyLen;
pThis->fLen -= copyLen;
2007-03-27 17:47:10 +00:00
//LOGI("ESC: copyLen=%d, now fLen=%d", copyLen, pThis->fLen);
2007-03-27 17:47:10 +00:00
bail:
*pcb = copyLen;
return 0;
2007-03-27 17:47:10 +00:00
}
/*
* ===========================================================================
* ExpandBuffer
2007-03-27 17:47:10 +00:00
* ===========================================================================
*/
int ExpandBuffer::CreateWorkBuf(void)
2007-03-27 17:47:10 +00:00
{
2014-11-18 05:13:13 +00:00
if (fWorkBuf != NULL) {
ASSERT(fWorkMax > 0);
return 0;
}
2007-03-27 17:47:10 +00:00
assert(fInitialSize > 0);
2007-03-27 17:47:10 +00:00
fWorkBuf = new char[fInitialSize];
2014-11-18 05:13:13 +00:00
if (fWorkBuf == NULL)
return -1;
2007-03-27 17:47:10 +00:00
fWorkCount = 0;
fWorkMax = fInitialSize;
2007-03-27 17:47:10 +00:00
return 0;
2007-03-27 17:47:10 +00:00
}
void ExpandBuffer::SeizeBuffer(char** ppBuf, long* pLen)
2007-03-27 17:47:10 +00:00
{
*ppBuf = fWorkBuf;
*pLen = fWorkCount;
2007-03-27 17:47:10 +00:00
fWorkBuf = NULL; // discard pointer so we don't free it
fWorkCount = 0;
fWorkMax = 0;
2007-03-27 17:47:10 +00:00
}
int ExpandBuffer::GrowWorkBuf(void)
2007-03-27 17:47:10 +00:00
{
int newIncr = fWorkMax;
if (newIncr > kWorkBufMaxIncrement)
newIncr = kWorkBufMaxIncrement;
2007-03-27 17:47:10 +00:00
LOGV("Extending buffer by %d (count=%d, max=%d)",
newIncr, fWorkCount, fWorkMax);
2007-03-27 17:47:10 +00:00
fWorkMax += newIncr;
2007-03-27 17:47:10 +00:00
/* debug-only check to catch runaways */
// ASSERT(fWorkMax < 1024*1024*24);
2007-03-27 17:47:10 +00:00
char* newBuf = new char[fWorkMax];
2014-11-18 05:13:13 +00:00
if (newBuf == NULL) {
LOGE("ALLOC FAILURE (%ld)", fWorkMax);
ASSERT(false);
fWorkMax -= newIncr; // put it back so we don't overrun
return -1;
}
2007-03-27 17:47:10 +00:00
memcpy(newBuf, fWorkBuf, fWorkCount);
delete[] fWorkBuf;
fWorkBuf = newBuf;
2007-03-27 17:47:10 +00:00
return 0;
2007-03-27 17:47:10 +00:00
}
void ExpandBuffer::Write(const unsigned char* buf, long len)
2007-03-27 17:47:10 +00:00
{
2014-11-18 05:13:13 +00:00
if (fWorkBuf == NULL)
CreateWorkBuf();
while (fWorkCount + len >= fWorkMax) {
if (GrowWorkBuf() != 0)
return;
}
ASSERT(fWorkCount + len < fWorkMax);
memcpy(fWorkBuf + fWorkCount, buf, len);
fWorkCount += len;
2007-03-27 17:47:10 +00:00
}
void ExpandBuffer::Putc(char ch)
2007-03-27 17:47:10 +00:00
{
Write((const unsigned char*) &ch, 1);
2007-03-27 17:47:10 +00:00
}
void ExpandBuffer::Printf(_Printf_format_string_ const char* format, ...)
2007-03-27 17:47:10 +00:00
{
va_list args;
2014-11-18 05:13:13 +00:00
ASSERT(format != NULL);
2007-03-27 17:47:10 +00:00
2014-11-18 05:13:13 +00:00
if (fWorkBuf == NULL)
CreateWorkBuf();
2007-03-27 17:47:10 +00:00
va_start(args, format);
2014-11-18 05:13:13 +00:00
if (format != NULL) {
int count;
2007-03-27 17:47:10 +00:00
count = _vsnprintf(fWorkBuf + fWorkCount, fWorkMax - fWorkCount,
format, args);
if (count < 0) {
if (GrowWorkBuf() != 0)
return;
/* try one more time, then give up */
count = _vsnprintf(fWorkBuf + fWorkCount, fWorkMax - fWorkCount,
format, args);
ASSERT(count >= 0);
if (count < 0)
return;
}
fWorkCount += count;
ASSERT(fWorkCount <= fWorkMax);
2007-03-27 17:47:10 +00:00
}
va_end(args);
}
/*
* ===========================================================================
* Windows helpers
2007-03-27 17:47:10 +00:00
* ===========================================================================
*/
void EnableControl(CDialog* pDlg, int id, bool enable)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd = pDlg->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
if (pWnd == NULL) {
LOGI("GLITCH: control %d not found in dialog", id);
ASSERT(false);
} else {
pWnd->EnableWindow(enable);
}
2007-03-27 17:47:10 +00:00
}
void MoveControl(CDialog* pDlg, int id, int deltaX, int deltaY, bool redraw)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd;
CRect rect;
2007-03-27 17:47:10 +00:00
pWnd = pDlg->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
ASSERT(pWnd != NULL);
if (pWnd == NULL)
return;
2007-03-27 17:47:10 +00:00
pWnd->GetWindowRect(&rect);
pDlg->ScreenToClient(&rect);
rect.left += deltaX;
rect.right += deltaX;
rect.top += deltaY;
rect.bottom += deltaY;
pWnd->MoveWindow(&rect, redraw);
2007-03-27 17:47:10 +00:00
}
void StretchControl(CDialog* pDlg, int id, int deltaX, int deltaY, bool redraw)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd;
CRect rect;
2007-03-27 17:47:10 +00:00
pWnd = pDlg->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
ASSERT(pWnd != NULL);
if (pWnd == NULL)
return;
2007-03-27 17:47:10 +00:00
pWnd->GetWindowRect(&rect);
pDlg->ScreenToClient(&rect);
rect.right += deltaX;
rect.bottom += deltaY;
pWnd->MoveWindow(&rect, redraw);
2007-03-27 17:47:10 +00:00
}
void
MoveStretchControl(CDialog* pDlg, int id, int moveX, int moveY,
int stretchX, int stretchY, bool redraw)
2007-03-27 17:47:10 +00:00
{
MoveControl(pDlg, id, moveX, moveY, redraw);
StretchControl(pDlg, id, stretchX, stretchY, redraw);
2007-03-27 17:47:10 +00:00
}
HDWP MoveControl(HDWP hdwp, CDialog* pDlg, int id, int deltaX, int deltaY,
bool redraw)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd;
CRect rect;
2007-03-27 17:47:10 +00:00
pWnd = pDlg->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
ASSERT(pWnd != NULL);
if (pWnd == NULL)
return hdwp;
2007-03-27 17:47:10 +00:00
pWnd->GetWindowRect(&rect);
pDlg->ScreenToClient(&rect);
rect.left += deltaX;
rect.right += deltaX;
rect.top += deltaY;
rect.bottom += deltaY;
2014-11-18 05:13:13 +00:00
hdwp = DeferWindowPos(hdwp, pWnd->m_hWnd, NULL, rect.left, rect.top,
rect.Width(), rect.Height(), 0);
2007-03-27 17:47:10 +00:00
return hdwp;
2007-03-27 17:47:10 +00:00
}
HDWP StretchControl(HDWP hdwp, CDialog* pDlg, int id, int deltaX, int deltaY,
bool redraw)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd;
CRect rect;
2007-03-27 17:47:10 +00:00
pWnd = pDlg->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
ASSERT(pWnd != NULL);
if (pWnd == NULL)
return hdwp;
2007-03-27 17:47:10 +00:00
pWnd->GetWindowRect(&rect);
pDlg->ScreenToClient(&rect);
rect.right += deltaX;
rect.bottom += deltaY;
2014-11-18 05:13:13 +00:00
hdwp = DeferWindowPos(hdwp, pWnd->m_hWnd, NULL, rect.left, rect.top,
rect.Width(), rect.Height(), 0);
2007-03-27 17:47:10 +00:00
return hdwp;
2007-03-27 17:47:10 +00:00
}
HDWP MoveStretchControl(HDWP hdwp, CDialog* pDlg, int id, int moveX, int moveY,
int stretchX, int stretchY, bool redraw)
2007-03-27 17:47:10 +00:00
{
CWnd* pWnd;
CRect rect;
2007-03-27 17:47:10 +00:00
pWnd = pDlg->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
ASSERT(pWnd != NULL);
if (pWnd == NULL)
return hdwp;
2007-03-27 17:47:10 +00:00
pWnd->GetWindowRect(&rect);
pDlg->ScreenToClient(&rect);
rect.left += moveX;
rect.right += moveX;
rect.top += moveY;
rect.bottom += moveY;
rect.right += stretchX;
rect.bottom += stretchY;
2014-11-18 05:13:13 +00:00
hdwp = DeferWindowPos(hdwp, pWnd->m_hWnd, NULL, rect.left, rect.top,
rect.Width(), rect.Height(), 0);
2007-03-27 17:47:10 +00:00
return hdwp;
2007-03-27 17:47:10 +00:00
}
int GetDlgButtonCheck(CWnd* pWnd, int id)
2007-03-27 17:47:10 +00:00
{
CButton* pButton;
pButton = (CButton*) pWnd->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
ASSERT(pButton != NULL);
if (pButton == NULL)
return -1;
return pButton->GetCheck();
2007-03-27 17:47:10 +00:00
}
void SetDlgButtonCheck(CWnd* pWnd, int id, int checkVal)
2007-03-27 17:47:10 +00:00
{
CButton* pButton;
pButton = (CButton*) pWnd->GetDlgItem(id);
2014-11-18 05:13:13 +00:00
ASSERT(pButton != NULL);
if (pButton == NULL)
return;
pButton->SetCheck(checkVal);
2007-03-27 17:47:10 +00:00
}
void CreateSimpleFont(CFont* pFont, CWnd* pWnd, const WCHAR* typeFace,
int pointSize)
2007-03-27 17:47:10 +00:00
{
CClientDC dc(pWnd);
int height;
2007-03-27 17:47:10 +00:00
height = -((dc.GetDeviceCaps(LOGPIXELSY) * pointSize) / 72);
pFont->CreateFont(height, 0, 0, 0, FW_NORMAL, 0, 0, 0,
DEFAULT_CHARSET, OUT_CHARACTER_PRECIS, CLIP_CHARACTER_PRECIS,
DEFAULT_QUALITY, DEFAULT_PITCH | FF_DONTCARE, typeFace);
2007-03-27 17:47:10 +00:00
}
void GetWin32ErrorString(DWORD err, CString* pStr)
2007-03-27 17:47:10 +00:00
{
DWORD count;
LPVOID lpMsgBuf;
count = FormatMessage(
FORMAT_MESSAGE_ALLOCATE_BUFFER |
FORMAT_MESSAGE_FROM_SYSTEM |
FORMAT_MESSAGE_IGNORE_INSERTS,
NULL,
err /*GetLastError()*/,
MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT), // Default language
(LPTSTR) &lpMsgBuf,
0,
NULL
);
if (!count) {
LOGI("FormatMessage on err=0x%08lx failed", err);
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
pStr->Format(L"system error 0x%08lx.\n", err);
} else {
*pStr = (LPCTSTR)lpMsgBuf;
//MessageBox( NULL, (LPCTSTR)lpMsgBuf, "Error", MB_OK | MB_ICONINFORMATION );
LocalFree( lpMsgBuf );
}
2007-03-27 17:47:10 +00:00
}
void ShowFailureMsg(CWnd* pWnd, const CString& msg, int titleStrID)
2007-03-27 17:47:10 +00:00
{
2014-12-17 23:45:28 +00:00
CString title;
2007-03-27 17:47:10 +00:00
2014-12-17 23:45:28 +00:00
CheckedLoadString(&title, titleStrID);
pWnd->MessageBox(msg, title, MB_OK | MB_ICONERROR);
2007-03-27 17:47:10 +00:00
}
2014-12-17 23:45:28 +00:00
void ShowFailureMsg(CWnd* pWnd, int msgId, int titleStrID)
{
CString msg, title;
CheckedLoadString(&title, titleStrID);
CheckedLoadString(&msg, msgId);
pWnd->MessageBox(msg, title, MB_OK | MB_ICONERROR);
}
bool IsWin9x(void)
2007-03-27 17:47:10 +00:00
{
return false;
2007-03-27 17:47:10 +00:00
}
void CheckedLoadString(CString* pString, UINT nID)
{
if (!pString->LoadString(nID)) {
LOGW("WARNING: failed to load string %u", nID);
*pString = L"!Internal failure!";
}
}
2007-03-27 17:47:10 +00:00
/*
* ===========================================================================
* Miscellaneous
2007-03-27 17:47:10 +00:00
* ===========================================================================
*/
int GetPascalString(const uint8_t* buf, long maxLen, CString* pStr)
2007-03-27 17:47:10 +00:00
{
int len = *buf++;
int retLen = len;
*pStr = "";
2007-03-27 17:47:10 +00:00
if (len > maxLen) {
LOGW("Invalid pascal string -- len=%d, maxLen=%d", len, maxLen);
return -1;
}
2007-03-27 17:47:10 +00:00
while (len--) {
if (*buf == '\0') {
/* this suggests that we're not reading a pascal string */
LOGW("Found pascal string with '\\0' in it");
return -1;
}
2007-03-27 17:47:10 +00:00
/* not the fastest approach, but it'll do */
*pStr += *buf++;
}
2007-03-27 17:47:10 +00:00
return retLen;
2007-03-27 17:47:10 +00:00
}
void LogHexDump(const void* vbuf, long len)
2007-03-27 17:47:10 +00:00
{
const unsigned char* buf = (const unsigned char*) vbuf;
char outBuf[10 + 16*3 +1 +8]; // addr: 00 11 22 ... + 8 bytes slop
bool skipFirst;
uintptr_t addr;
2014-11-18 05:13:13 +00:00
char* cp = NULL;
int i;
LOGI(" Memory at 0x%p %ld bytes:", buf, len);
if (len <= 0)
return;
addr = (uintptr_t)buf & ~0x0f;
if (addr != (uintptr_t) buf) {
sprintf(outBuf, "%08lx: ", addr);
for (i = addr; i < (int) buf; i++)
strcat(outBuf, " ");
cp = outBuf + strlen(outBuf);
skipFirst = false;
} else {
skipFirst = true;
}
while (len--) {
if (((uintptr_t) buf & 0x0f) == 0) {
/* output the old, start a new line */
if (skipFirst) {
skipFirst = false;
} else {
LOGI(" %hs", outBuf);
addr += 16;
}
sprintf(outBuf, "%08lx: ", addr);
cp = outBuf + strlen(outBuf);
}
sprintf(cp, "%02x ", *buf++);
cp += 3;
}
/* output whatever is left */
LOGI(" %hs", outBuf);
2007-03-27 17:47:10 +00:00
}
int ComputePercent(LONGLONG part, LONGLONG full)
2007-03-27 17:47:10 +00:00
{
LONGLONG perc;
if (!part && !full)
return 100; /* file is zero bytes long */
if (part < 21474836)
perc = (part * 100) / full;
else
perc = part / (full/100);
/* don't say "0%" if it's not actually zero... it looks dumb */
if (!perc && full)
perc = 1;
return (int) perc;
}
void FormatDate(time_t when, CString* pStr)
2007-03-27 17:47:10 +00:00
{
if (when == kDateNone) {
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
*pStr = L"[No Date]";
} else if (when == kDateInvalid) {
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
*pStr = L"<invalid>";
} else {
CTime modWhen(when);
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
*pStr = modWhen.Format(L"%d-%b-%y %H:%M");
}
2007-03-27 17:47:10 +00:00
}
const WCHAR* Stristr(const WCHAR* string1, const WCHAR* string2)
2007-03-27 17:47:10 +00:00
{
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
WCHAR *cp1 = (WCHAR*)string1, *cp2, *cp1a;
WCHAR first; // get the first char in string to find
first = string2[0]; // first char often won't be alpha
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
if (iswalpha(first)) {
first = towlower(first);
for ( ; *cp1 != '\0'; cp1++)
{
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
if (towlower(*cp1) == first)
{
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
for (cp1a = &cp1[1], cp2 = (WCHAR*) &string2[1];;
cp1a++, cp2++)
{
if (*cp2 == '\0')
return cp1;
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
if (towlower(*cp1a) != towlower(*cp2))
break;
}
}
}
}
else
{
for ( ; *cp1 != '\0' ; cp1++)
{
if (*cp1 == first)
{
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
for (cp1a = &cp1[1], cp2 = (WCHAR*) &string2[1];;
cp1a++, cp2++)
{
if (*cp2 == '\0')
return cp1;
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
if (towlower(*cp1a) != towlower(*cp2))
break;
}
}
}
}
return NULL;
2007-03-27 17:47:10 +00:00
}
void VectorizeString(WCHAR* mangle, WCHAR** argv, int* pArgc)
2007-03-27 17:47:10 +00:00
{
bool inWhiteSpace = true;
bool inQuote = false;
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
WCHAR* cp = mangle;
int idx = 0;
while (*cp != '\0') {
ASSERT(!inWhiteSpace || !inQuote);
if (!inQuote && (*cp == ' ' || *cp == '\t')) {
if (!inWhiteSpace && !inQuote) {
/* end of token */
*cp = '\0';
}
inWhiteSpace = true;
} else {
if (inWhiteSpace) {
/* start of token */
if (idx >= *pArgc) {
//LOGI("Max #of args (%d) exceeded, ignoring '%ls'",
// *pArgc, cp);
break;
}
argv[idx++] = cp;
}
if (*cp == '"') {
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
/* consume the quote; move the last '\0' down too */
memmove(cp, cp+1, wcslen(cp) * sizeof(WCHAR));
cp--;
inQuote = !inQuote;
}
inWhiteSpace = false;
}
cp++;
}
if (inQuote) {
LOGW("WARNING: ended in quote");
}
*pArgc = idx;
2007-03-27 17:47:10 +00:00
}
/*
* Convert a sub-string to lower case according to rules for English book
* titles. Assumes the initial string is in all caps.
*/
static void DowncaseSubstring(CStringA* pStr, int startPos, int endPos,
bool prevWasSpace)
{
static const char* shortWords[] = {
"of", "the", "a", "an", "and", "to", "in"
};
static const char* leaveAlone[] = {
"BBS", "3D"
};
static const char* justLikeThis[] = {
"ProDOS", "IIe", "IIc", "IIgs"
};
CStringA token;
bool firstCap = true;
int i;
token = pStr->Mid(startPos, endPos - startPos);
LOGV(" TOKEN: '%s'", (LPCSTR) token);
/* these words are left alone */
for (i = 0; i < NELEM(leaveAlone); i++) {
if (token.CompareNoCase(leaveAlone[i]) == 0) {
LOGV(" Leaving alone '%s'", (LPCSTR) token);
return;
}
}
/* words with specific capitalization */
for (i = 0; i < NELEM(justLikeThis); i++) {
if (token.CompareNoCase(justLikeThis[i]) == 0) {
LOGI(" Setting '%s' to '%s'", (LPCSTR) token, justLikeThis[i]);
for (int j = startPos; j < endPos; j++)
pStr->SetAt(j, justLikeThis[i][j - startPos]);
return;
}
}
/* these words are not capitalized unless they start a phrase */
if (prevWasSpace) {
for (i = 0; i < NELEM(shortWords); i++) {
if (token.CompareNoCase(shortWords[i]) == 0) {
LOGV(" No leading cap for '%s'", (LPCSTR) token);
firstCap = false;
break;
}
}
}
/* check for roman numerals; we leave those capitalized */
CString romanTest = token.SpanIncluding("IVX");
if (romanTest.GetLength() == token.GetLength()) {
LOGV(" Looks like roman numerals '%s'", (LPCSTR) token);
return;
}
if (firstCap)
startPos++;
for (i = startPos; i < endPos; i++) {
pStr->SetAt(i, tolower(pStr->GetAt(i)));
}
2007-03-27 17:47:10 +00:00
}
void InjectLowercase(CStringA* pStr)
2007-03-27 17:47:10 +00:00
{
int len = pStr->GetLength();
static const char kGapChars[] = " .:&-+/\\()<>@*";
int startPos, endPos;
//*pStr = "AND PRODOS FOR THE IIGS";
//len = pStr->GetLength();
//LOGI("InjectLowercase: '%ls'", (LPCWSTR) *pStr);
for (int i = 0; i < len; i++) {
char ch = pStr->GetAt(i);
if (ch >= 'a' && ch <= 'z') {
LOGI("Found lowercase 0x%04x, skipping InjectLower", ch);
return;
}
}
startPos = 0;
while (startPos < len) {
/* find start of token */
char ch;
do {
ch = pStr->GetAt(startPos);
if (strchr(kGapChars, ch) == NULL)
break;
startPos++;
} while (startPos < len);
if (startPos == len)
break;
/* find end of token */
endPos = startPos + 1;
while (endPos < len) {
ch = pStr->GetAt(endPos);
if (strchr(kGapChars, ch) != NULL)
break;
endPos++;
}
/* endPos now points at first char past end of token */
bool prevWasSpace;
if (startPos == 0)
prevWasSpace = false;
else
prevWasSpace = (pStr->GetAt(startPos-1) == ' ');
DowncaseSubstring(pStr, startPos, endPos, prevWasSpace);
startPos = endPos;
}
2007-03-27 17:47:10 +00:00
}
bool MatchSemicolonList(const CString set, const CString match)
2007-03-27 17:47:10 +00:00
{
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
const WCHAR* cp;
CString mangle(set);
int matchLen = match.GetLength();
if (!matchLen)
return false;
mangle.Remove(' ');
for (cp = mangle; *cp != '\0'; ) {
Large set of changes to restore CiderPress build. CiderPress and MDC now compile, and execute far enough to open their respective "about" boxes, but I doubt they'll do much more than that. * Switch from MBCS to UNICODE APIs Microsoft switched to UTF-16 (by way of UCS-2) a long time ago, and the support for MBCS seems to be getting phased out. So it's time to switch to wide strings. This is a bit awkward for CiderPress because it works with disk and file archives with 8-bit filenames, and I want NufxLib and DiskImgLib to continue to work on Linux (which has largely taken the UTF-8 approach to Unicode). The libraries will continue to work with 8-bit filenames, with CiderPress/MDC doing the conversion at the appropriate point. There were a couple of places where strings from a structure handed back by one of the libraries were used directly in the UI, or vice-versa, which is a problem because we have nowhere to store the result of the conversion. These currently have fixed place-holder "xyzzy" strings. All UI strings are now wide. Various format strings now use "%ls" and "%hs" to explicitly specify wide and narrow. This doesn't play well with gcc, so only the Windows-specific parts use those. * Various updates to vcxproj files The project-file conversion had some cruft that is now largely gone. The build now has a common output directory for the EXEs and libraries, avoiding the old post-build copy steps. * Added zlib 1.2.8 and nufxlib 2.2.2 source snapshots The old "prebuilts" directory is now gone. The libraries are now built as part of building the apps. I added a minimal set of files for zlib, and a full set for nufxlib. The Linux-specific nufxlib goodies are included for the benefit of the Linux utilities, which are currently broken (don't build). * Replace symbols used for include guards Symbols with a leading "__" are reserved.
2014-11-10 23:32:55 +00:00
if (wcsnicmp(cp, match, matchLen) == 0 &&
(cp[matchLen] == ';' || cp[matchLen] == '\0'))
{
LOGI("+++ Found '%ls' at '%ls'", (LPCWSTR) match, cp);
return true;
}
while (*cp != ';' && *cp != '\0')
cp++;
if (*cp == ';')
cp++;
}
2007-03-27 17:47:10 +00:00
LOGI("--- No match for '%ls' in '%ls'", (LPCWSTR) match, (LPCWSTR) set);
return false;
2007-03-27 17:47:10 +00:00
}
char* StrcpyNew(const char* str)
2007-03-27 17:47:10 +00:00
{
char* newStr;
2007-03-27 17:47:10 +00:00
2014-11-18 05:13:13 +00:00
if (str == NULL)
return NULL;
newStr = new char[strlen(str)+1];
2014-11-18 05:13:13 +00:00
if (newStr != NULL)
strcpy(newStr, str);
return newStr;
2007-03-27 17:47:10 +00:00
}