summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES4
-rw-r--r--INSTALL.MacOS56
-rw-r--r--MacOS/GetHTTPS.src/CPStringUtils.cpp2753
-rw-r--r--MacOS/GetHTTPS.src/CPStringUtils.hpp104
-rw-r--r--MacOS/GetHTTPS.src/ErrorHandling.cpp170
-rw-r--r--MacOS/GetHTTPS.src/ErrorHandling.hpp147
-rw-r--r--MacOS/GetHTTPS.src/GetHTTPS.cpp206
-rw-r--r--MacOS/GetHTTPS.src/MacSocket.cpp1607
-rw-r--r--MacOS/GetHTTPS.src/MacSocket.h103
-rw-r--r--MacOS/OpenSSL.mcp.hqx5103
-rw-r--r--MacOS/TODO18
-rw-r--r--MacOS/_MWERKS_prefix.h5
-rw-r--r--MacOS/buildinf.h5
-rw-r--r--MacOS/mklinks.as.hqx820
-rw-r--r--MacOS/opensslconf.h118
-rw-r--r--crypto/perlasm/x86unix.pl6
16 files changed, 11222 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index 14208b984d..65c8178d42 100644
--- a/CHANGES
+++ b/CHANGES
@@ -4,6 +4,10 @@
Changes between 0.9.4 and 0.9.5 [xx XXX 1999]
+ *) Initial support for MacOS is now provided. Examine INSTALL.MacOS
+ for details.
+ [Andy Polyakov, Roy Woods <roy@centicsystems.ca>]
+
*) Rebuild of the memory allocation routines used by OpenSSL code and
possibly others as well. The purpose is to make an interface that
provide hooks so anyone can build a separate set of allocation and
diff --git a/INSTALL.MacOS b/INSTALL.MacOS
new file mode 100644
index 0000000000..922fca48e9
--- /dev/null
+++ b/INSTALL.MacOS
@@ -0,0 +1,56 @@
+OpenSSL - Port To The Macintosh
+===============================
+
+Thanks to Roy Wood <roy@centricsystems.ca> initial support for MacOS (pre
+X) is now provided. "Initial" means that unlike other platforms where you
+get an SDK and a "swiss army" openssl application, on Macintosh you only
+get one sample application which fetches a page over HTTPS(*) and dumps it
+in a window. We don't even build the test applications so that we can't
+guarantee that all algorithms are operational.
+
+Required software:
+
+- StuffIt Expander (or any program capable to "unbinhex");
+- DropStuff w/EE (or MacGzip and SUNtar);
+- CodeWarrior Pro 5;
+
+Installation procedure:
+
+- fetch the source at ftp://ftp.openssl.org/ (well, you probably already
+ did, huh?)
+- unpack the .tar.gz file:
+ - if you have DropStuff w/EE installed then just drag it over
+ StuffIt Expander;
+ - otherwise process it first with MacGzip and then with SUNtar;
+- locate MacOS folder in OpenSSL source tree and open it;
+- unbinhex mklinks.as.hqx and OpenSSL.mcp.hqx in place;
+- double-click on mklinks.as;
+- open OpenSSL.mcp and compile 'GetHTTPS PPC' target;
+- that's it;
+
+(*) URL is hardcoded into GetHTTPS Sources/GetHTTPS.cpp
+
+Finally some essential comments from our generous contributor:-)
+
+"I've gotten OpenSSL working on the Macintosh. It's probably a bit of a
+hack, but it works for what I'm doing. If you don't like the way I've done
+it, then feel free to change what I've done. I freely admit that I've done
+some less-than-ideal things in my port, and if you don't like the way I've
+done something, then feel free to change it-- I won't be offended!
+
+... I've tweaked "bss_sock.c" a little to call routines in a "MacSocket"
+library I wrote. My MacSocket library is a wrapper around OpenTransport,
+handling stuff like endpoint creation, reading, writing, etc. It is not
+designed as a high-performance package such as you'd use in a webserver,
+but is fine for lots of other applications. MacSocket also uses some other
+code libraries I've written to deal with string manipulations and error
+handling. Feel free to use these things in your own code, but give me
+credit and/or send me free stuff in appreciation! :-)
+
+...
+
+If you have any questions, feel free to email me as the following:
+
+roy@centricsystems.ca
+
+-Roy Wood"
diff --git a/MacOS/GetHTTPS.src/CPStringUtils.cpp b/MacOS/GetHTTPS.src/CPStringUtils.cpp
new file mode 100644
index 0000000000..5f64afe967
--- /dev/null
+++ b/MacOS/GetHTTPS.src/CPStringUtils.cpp
@@ -0,0 +1,2753 @@
+/* ====================================================================
+ * Copyright (c) 1998-1999 The OpenSSL Project. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in
+ * the documentation and/or other materials provided with the
+ * distribution.
+ *
+ * 3. All advertising materials mentioning features or use of this
+ * software must display the following acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit. (http://www.openssl.org/)"
+ *
+ * 4. The names "OpenSSL Toolkit" and "OpenSSL Project" must not be used to
+ * endorse or promote products derived from this software without
+ * prior written permission. For written permission, please contact
+ * openssl-core@openssl.org.
+ *
+ * 5. Products derived from this software may not be called "OpenSSL"
+ * nor may "OpenSSL" appear in their names without prior written
+ * permission of the OpenSSL Project.
+ *
+ * 6. Redistributions of any form whatsoever must retain the following
+ * acknowledgment:
+ * "This product includes software developed by the OpenSSL Project
+ * for use in the OpenSSL Toolkit (http://www.openssl.org/)"
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE OpenSSL PROJECT ``AS IS'' AND ANY
+ * EXPRESSED OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE OpenSSL PROJECT OR
+ * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
+ * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ * ====================================================================
+ *
+ * This product includes cryptographic software written by Eric Young
+ * (eay@cryptsoft.com). This product includes software written by Tim
+ * Hudson (tjh@cryptsoft.com).
+ *
+ */
+
+
+
+ #include "CPStringUtils.hpp"
+#include "ErrorHandling.hpp"
+
+
+
+#define kNumberFormatString "\p########0.00#######;-########0.00#######"
+
+
+
+// Useful utility functions which could be optimized a whole lot
+
+
+void CopyPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength)
+{
+int i,numPChars;
+
+
+ if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
+ {
+ numPChars = thePStr[0];
+
+ for (i = 0;;i++)
+ {
+ if (i >= numPChars || i >= maxCStrLength - 1)
+ {
+ theCStr[i] = 0;
+
+ break;
+ }
+
+ else
+ {
+ theCStr[i] = thePStr[i + 1];
+ }
+ }
+ }
+}
+
+
+void CopyPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength)
+{
+int theMaxDstStrLength;
+
+
+ theMaxDstStrLength = maxDstStrLength;
+
+
+ if (theDstPStr != nil && theSrcPStr != nil && theMaxDstStrLength > 0)
+ {
+ if (theMaxDstStrLength > 255)
+ {
+ theMaxDstStrLength = 255;
+ }
+
+
+ if (theMaxDstStrLength - 1 < theSrcPStr[0])
+ {
+ BlockMove(theSrcPStr + 1,theDstPStr + 1,theMaxDstStrLength - 1);
+
+ theDstPStr[0] = theMaxDstStrLength - 1;
+ }
+
+ else
+ {
+ BlockMove(theSrcPStr,theDstPStr,theSrcPStr[0] + 1);
+ }
+ }
+}
+
+
+void CopyCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxDstStrLength)
+{
+int i;
+
+
+ if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
+ {
+ for (i = 0;;i++)
+ {
+ if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1)
+ {
+ theDstCStr[i] = 0;
+
+ break;
+ }
+
+ else
+ {
+ theDstCStr[i] = theSrcCStr[i];
+ }
+ }
+ }
+}
+
+
+
+void CopyCSubstrToCStr(const char *theSrcCStr,const int maxCharsToCopy,char *theDstCStr,const int maxDstStrLength)
+{
+int i;
+
+
+ if (theDstCStr != nil && theSrcCStr != nil && maxDstStrLength > 0)
+ {
+ for (i = 0;;i++)
+ {
+ if (theSrcCStr[i] == 0 || i >= maxDstStrLength - 1 || i >= maxCharsToCopy)
+ {
+ theDstCStr[i] = 0;
+
+ break;
+ }
+
+ else
+ {
+ theDstCStr[i] = theSrcCStr[i];
+ }
+ }
+ }
+}
+
+
+
+void CopyCSubstrToPStr(const char *theSrcCStr,const int maxCharsToCopy,unsigned char *theDstPStr,const int maxDstStrLength)
+{
+int i;
+int theMaxDstStrLength;
+
+
+ theMaxDstStrLength = maxDstStrLength;
+
+ if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
+ {
+ if (theMaxDstStrLength > 255)
+ {
+ theMaxDstStrLength = 255;
+ }
+
+
+ for (i = 0;;i++)
+ {
+ if (theSrcCStr[i] == 0 || i >= theMaxDstStrLength - 1 || i >= maxCharsToCopy)
+ {
+ theDstPStr[0] = i;
+
+ break;
+ }
+
+ else
+ {
+ theDstPStr[i + 1] = theSrcCStr[i];
+ }
+ }
+ }
+}
+
+
+
+void CopyCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength)
+{
+int i;
+int theMaxDstStrLength;
+
+
+ theMaxDstStrLength = maxDstStrLength;
+
+ if (theDstPStr != nil && theSrcCStr != nil && theMaxDstStrLength > 0)
+ {
+ if (theMaxDstStrLength > 255)
+ {
+ theMaxDstStrLength = 255;
+ }
+
+
+ for (i = 0;;i++)
+ {
+ if (i >= theMaxDstStrLength - 1 || theSrcCStr[i] == 0)
+ {
+ theDstPStr[0] = i;
+
+ break;
+ }
+
+ else
+ {
+ theDstPStr[i + 1] = theSrcCStr[i];
+ }
+ }
+ }
+}
+
+
+void ConcatPStrToCStr(const unsigned char *thePStr,char *theCStr,const int maxCStrLength)
+{
+int i,numPChars,cStrLength;
+
+
+ if (thePStr != nil && theCStr != nil && maxCStrLength > 0)
+ {
+ for (cStrLength = 0;theCStr[cStrLength] != 0;cStrLength++)
+ {
+
+ }
+
+
+ numPChars = thePStr[0];
+
+
+ for (i = 0;;i++)
+ {
+ if (i >= numPChars || cStrLength >= maxCStrLength - 1)
+ {
+ theCStr[cStrLength++] = 0;
+
+ break;
+ }
+
+ else
+ {
+ theCStr[cStrLength++] = thePStr[i + 1];
+ }
+ }
+ }
+}
+
+
+
+void ConcatPStrToPStr(const unsigned char *theSrcPStr,unsigned char *theDstPStr,const int maxDstStrLength)
+{
+int theMaxDstStrLength;
+
+
+ theMaxDstStrLength = maxDstStrLength;
+
+ if (theSrcPStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
+ {
+ if (theMaxDstStrLength > 255)
+ {
+ theMaxDstStrLength = 255;
+ }
+
+
+ if (theMaxDstStrLength - theDstPStr[0] - 1 < theSrcPStr[0])
+ {
+ BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theMaxDstStrLength - 1 - theDstPStr[0]);
+
+ theDstPStr[0] = theMaxDstStrLength - 1;
+ }
+
+ else
+ {
+ BlockMove(theSrcPStr + 1,theDstPStr + theDstPStr[0] + 1,theSrcPStr[0]);
+
+ theDstPStr[0] += theSrcPStr[0];
+ }
+ }
+}
+
+
+
+void ConcatCStrToPStr(const char *theSrcCStr,unsigned char *theDstPStr,const int maxDstStrLength)
+{
+int i,thePStrLength;
+int theMaxDstStrLength;
+
+
+ theMaxDstStrLength = maxDstStrLength;
+
+ if (theSrcCStr != nil && theDstPStr != nil && theMaxDstStrLength > 0)
+ {
+ if (theMaxDstStrLength > 255)
+ {
+ theMaxDstStrLength = 255;
+ }
+
+
+ thePStrLength = theDstPStr[0];
+
+ for (i = 0;;i++)
+ {
+ if (theSrcCStr[i] == 0 || thePStrLength >= theMaxDstStrLength - 1)
+ {
+ theDstPStr[0] = thePStrLength;
+
+ break;
+ }
+
+ else
+ {
+ theDstPStr[thePStrLength + 1] = theSrcCStr[i];
+
+ thePStrLength++;
+ }
+ }
+ }
+}
+
+
+
+void ConcatCStrToCStr(const char *theSrcCStr,char *theDstCStr,const int maxCStrLength)
+{
+int cStrLength;
+
+
+ if (theSrcCStr != nil && theDstCStr != nil && maxCStrLength > 0)
+ {
+ for (cStrLength = 0;theDstCStr[cStrLength] != 0;cStrLength++)
+ {
+
+ }
+
+
+ for (;;)
+ {
+ if (*theSrcCStr == 0 || cStrLength >= maxCStrLength - 1)
+ {
+ theDstCStr[cStrLength++] = 0;
+
+ break;
+ }
+
+ else
+ {
+ theDstCStr[cStrLength++] = *theSrcCStr++;
+ }
+ }
+ }
+}
+
+
+
+void ConcatCharToCStr(const char theChar,char *theDstCStr,const int maxCStrLength)
+{
+int cStrLength;
+
+
+ if (theDstCStr != nil && maxCStrLength > 0)
+ {
+ cStrLength = CStrLength(theDstCStr);
+
+ if (cStrLength < maxCStrLength - 1)
+ {
+ theDstCStr[cStrLength++] = theChar;
+ theDstCStr[cStrLength++] = '\0';
+ }
+ }
+}
+
+
+
+void ConcatCharToPStr(const char theChar,unsigned char *theDstPStr,const int maxPStrLength)
+{
+int pStrLength;
+
+
+ if (theDstPStr != nil && maxPStrLength > 0)
+ {
+ pStrLength = PStrLength(theDstPStr);
+
+ if (pStrLength < maxPStrLength - 1 && pStrLength < 255)
+ {
+ theDstPStr[pStrLength + 1] = theChar;
+ theDstPStr[0] += 1;
+ }
+ }
+}
+
+
+
+
+int CompareCStrs(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase)
+{
+int returnValue;
+char firstChar,secondChar;
+
+
+ returnValue = 0;
+
+
+ if (theFirstCStr != nil && theSecondCStr != nil)
+ {
+ for (;;)
+ {
+ firstChar = *theFirstCStr;
+ secondChar = *theSecondCStr;
+
+ if (ignoreCase == true)
+ {
+ if (firstChar >= 'A' && firstChar <= 'Z')
+ {
+ firstChar = 'a' + (firstChar - 'A');
+ }
+
+ if (secondChar >= 'A' && secondChar <= 'Z')
+ {
+ secondChar = 'a' + (secondChar - 'A');
+ }
+ }
+
+
+ if (firstChar == 0 && secondChar != 0)
+ {
+ returnValue = -1;
+
+ break;
+ }
+
+ else if (firstChar != 0 && secondChar == 0)
+ {
+ returnValue = 1;
+
+ break;
+ }
+
+ else if (firstChar == 0 && secondChar == 0)
+ {
+ returnValue = 0;
+
+ break;
+ }
+
+ else if (firstChar < secondChar)
+ {
+ returnValue = -1;
+
+ break;
+ }
+
+ else if (firstChar > secondChar)
+ {
+ returnValue = 1;
+
+ break;
+ }
+
+ theFirstCStr++;
+ theSecondCStr++;
+ }
+ }
+
+
+ return(returnValue);
+}
+
+
+
+Boolean CStrsAreEqual(const char *theFirstCStr,const char *theSecondCStr,const Boolean ignoreCase)
+{
+ if (CompareCStrs(theFirstCStr,theSecondCStr,ignoreCase) == 0)
+ {
+ return true;
+ }
+
+ else
+ {
+ return false;
+ }
+}
+
+
+Boolean PStrsAreEqual(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase)
+{
+ if (ComparePStrs(theFirstPStr,theSecondPStr,ignoreCase) == 0)
+ {
+ return true;
+ }
+
+ else
+ {
+ return false;
+ }
+}
+
+
+
+int ComparePStrs(const unsigned char *theFirstPStr,const unsigned char *theSecondPStr,const Boolean ignoreCase)
+{
+int i,returnValue;
+char firstChar,secondChar;
+
+
+ returnValue = 0;
+
+
+ if (theFirstPStr != nil && theSecondPStr != nil)
+ {
+ for (i = 1;;i++)
+ {
+ firstChar = theFirstPStr[i];
+ secondChar = theSecondPStr[i];
+
+ if (ignoreCase == true)
+ {
+ if (firstChar >= 'A' && firstChar <= 'Z')
+ {
+ firstChar = 'a' + (firstChar - 'A');
+ }
+
+ if (secondChar >= 'A' && secondChar <= 'Z')
+ {
+ secondChar = 'a' + (secondChar - 'A');
+ }
+ }
+
+
+ if (theFirstPStr[0] < i && theSecondPStr[0] >= i)
+ {
+ returnValue = -1;
+
+ break;
+ }
+
+ else if (theFirstPStr[0] >= i && theSecondPStr[0] < i)
+ {
+ returnValue = 1;
+
+ break;
+ }
+
+ else if (theFirstPStr[0] < i && theSecondPStr[0] < i)
+ {
+ returnValue = 0;
+
+ break;
+ }
+
+ else if (firstChar < secondChar)
+ {
+ returnValue = -1;
+
+ break;
+ }
+
+ else if (firstChar > secondChar)
+ {
+ returnValue = 1;
+
+ break;
+ }
+ }
+ }
+
+
+ return(returnValue);
+}
+
+
+
+int CompareCStrToPStr(const char *theCStr,const unsigned char *thePStr,const Boolean ignoreCase)
+{
+int returnValue;
+char tempString[256];
+
+
+ returnValue = 0;
+
+ if (theCStr != nil && thePStr != nil)
+ {
+ CopyPStrToCStr(thePStr,tempString,sizeof(tempString));
+
+ returnValue = CompareCStrs(theCStr,tempString,ignoreCase);
+ }
+
+
+ return(returnValue);
+}
+
+
+
+void ConcatLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits)
+{
+Str255 theStr255;
+
+
+ NumToString(theNum,theStr255);
+
+
+ if (numDigits > 0)
+ {
+ int charsToInsert;
+
+
+ charsToInsert = numDigits - PStrLength(theStr255);
+
+ if (charsToInsert > 0)
+ {
+ char tempString[256];
+
+ CopyCStrToCStr("",tempString,sizeof(tempString));
+
+ for (;charsToInsert > 0;charsToInsert--)
+ {
+ ConcatCStrToCStr("0",tempString,sizeof(tempString));
+ }
+
+ ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
+
+ CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
+ }
+ }
+
+
+ ConcatPStrToCStr(theStr255,theCStr,maxCStrLength);
+}
+
+
+
+
+void ConcatLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits)
+{
+Str255 theStr255;
+
+
+ NumToString(theNum,theStr255);
+
+
+ if (numDigits > 0)
+ {
+ int charsToInsert;
+
+
+ charsToInsert = numDigits - PStrLength(theStr255);
+
+ if (charsToInsert > 0)
+ {
+ char tempString[256];
+
+ CopyCStrToCStr("",tempString,sizeof(tempString));
+
+ for (;charsToInsert > 0;charsToInsert--)
+ {
+ ConcatCStrToCStr("0",tempString,sizeof(tempString));
+ }
+
+ ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
+
+ CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
+ }
+ }
+
+
+ ConcatPStrToPStr(theStr255,thePStr,maxPStrLength);
+}
+
+
+
+void CopyCStrAndConcatLongIntToCStr(const char *theSrcCStr,const long theNum,char *theDstCStr,const int maxDstStrLength)
+{
+ CopyCStrToCStr(theSrcCStr,theDstCStr,maxDstStrLength);
+
+ ConcatLongIntToCStr(theNum,theDstCStr,maxDstStrLength);
+}
+
+
+
+void CopyLongIntToCStr(const long theNum,char *theCStr,const int maxCStrLength,const int numDigits)
+{
+Str255 theStr255;
+
+
+ NumToString(theNum,theStr255);
+
+
+ if (numDigits > 0)
+ {
+ int charsToInsert;
+
+
+ charsToInsert = numDigits - PStrLength(theStr255);
+
+ if (charsToInsert > 0)
+ {
+ char tempString[256];
+
+ CopyCStrToCStr("",tempString,sizeof(tempString));
+
+ for (;charsToInsert > 0;charsToInsert--)
+ {
+ ConcatCStrToCStr("0",tempString,sizeof(tempString));
+ }
+
+ ConcatPStrToCStr(theStr255,tempString,sizeof(tempString));
+
+ CopyCStrToPStr(tempString,theStr255,sizeof(theStr255));
+ }
+ }
+
+
+ CopyPStrToCStr(theStr255,theCStr,maxCStrLength);
+}
+
+
+
+
+
+void CopyUnsignedLongIntToCStr(const unsigned long theNum,char *theCStr,const int maxCStrLength)
+{
+char tempString[256];
+int srcCharIndex,dstCharIndex;
+unsigned long tempNum,quotient,remainder;
+
+
+ if (theNum == 0)
+ {
+ CopyCStrToCStr("0",theCStr,maxCStrLength);
+ }
+
+ else
+ {
+ srcCharIndex = 0;
+
+ tempNum = theNum;
+
+ for (;;)
+ {
+ if (srcCharIndex >= sizeof(tempString) - 1 || tempNum == 0)
+ {
+ for (dstCharIndex = 0;;)
+ {
+ if (dstCharIndex >= maxCStrLength - 1 || srcCharIndex <= 0)
+ {
+ theCStr[dstCharIndex] = 0;
+
+ break;
+ }
+
+ theCStr[dstCharIndex++] = tempString[--srcCharIndex];
+ }
+
+ break;
+ }
+
+
+ quotient = tempNum / 10;
+
+ remainder = tempNum - (quotient * 10);
+
+ tempString[srcCharIndex] = '0' + remainder;
+
+ srcCharIndex++;
+
+ tempNum = quotient;
+ }
+ }
+}
+
+
+
+
+void CopyLongIntToPStr(const long theNum,unsigned char *thePStr,const int maxPStrLength,const int numDigits)
+{
+char tempString[256];
+
+
+ CopyLongIntToCStr(theNum,tempString,sizeof(tempString),numDigits);
+
+ CopyCStrToPStr(tempString,thePStr,maxPStrLength);
+}
+
+
+
+OSErr CopyLongIntToNewHandle(const long inTheLongInt,Handle *theHandle)
+{
+OSErr errCode = noErr;
+char tempString[32];
+
+
+ CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
+
+ errCode = CopyCStrToNewHandle(tempString,theHandle);
+
+ return(errCode);
+}
+
+
+OSErr CopyLongIntToExistingHandle(const long inTheLongInt,Handle theHandle)
+{
+OSErr errCode = noErr;
+char tempString[32];
+
+
+ CopyLongIntToCStr(inTheLongInt,tempString,sizeof(tempString));
+
+ errCode = CopyCStrToExistingHandle(tempString,theHandle);
+
+ return(errCode);
+}
+
+
+
+
+OSErr CopyCStrToExistingHandle(const char *theCString,Handle theHandle)
+{
+OSErr errCode = noErr;
+long stringLength;
+
+
+ if (theCString == nil)
+ {
+ SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theCString == nil"));
+ }
+
+ if (theHandle == nil)
+ {
+ SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, theHandle == nil"));
+ }
+
+ if (*theHandle == nil)
+ {
+ SetErrorMessageAndBail(("CopyCStrToExistingHandle: Bad parameter, *theHandle == nil"));
+ }
+
+
+
+ stringLength = CStrLength(theCString) + 1;
+
+ SetHandleSize(theHandle,stringLength);
+
+ if (GetHandleSize(theHandle) < stringLength)
+ {
+ SetErrorMessageAndLongIntAndBail("CopyCStrToExistingHandle: Can't set Handle size, MemError() = ",MemError());
+ }
+
+
+ ::BlockMove(theCString,*theHandle,stringLength);
+
+
+EXITPOINT:
+
+ return(errCode);
+}
+
+
+
+
+
+OSErr CopyCStrToNewHandle(const char *theCString,Handle *theHandle)
+{
+OSErr errCode = noErr;
+long stringLength;
+
+
+ if (theCString == nil)
+ {
+ SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theCString == nil"));
+ }
+
+ if (theHandle == nil)
+ {
+ SetErrorMessageAndBail(("CopyCStrToNewHandle: Bad parameter, theHandle == nil"));
+ }
+
+
+
+ stringLength = CStrLength(theCString) + 1;
+
+ *theHandle = NewHandle(stringLength);
+
+ if (*theHandle == nil)
+ {
+ SetErrorMessageAndLongIntAndBail("CopyCStrToNewHandle: Can't allocate Handle, MemError() = ",MemError());
+ }
+
+
+ ::BlockMove(theCString,**theHandle,stringLength);
+
+
+EXITPOINT:
+
+ return(errCode);
+}
+
+
+
+OSErr CopyPStrToNewHandle(const unsigned char *thePString,Handle *theHandle)
+{
+OSErr errCode = noErr;
+long stringLength;
+
+
+ if (thePString == nil)
+ {
+ SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, thePString == nil"));
+ }
+
+ if (theHandle == nil)
+ {
+ SetErrorMessageAndBail(("CopyPStrToNewHandle: Bad parameter, theHandle == nil"));
+ }
+
+
+
+ stringLength = PStrLength(thePString) + 1;
+
+ *theHandle = NewHandle(stringLength);
+
+ if (*theHandle == nil)
+ {
+ SetErrorMessageAndLongIntAndBail("CopyPStrToNewHandle: Can't allocate Handle, MemError() = ",MemError());
+ }
+
+
+ if (stringLength > 1)
+ {
+ BlockMove(thePString + 1,**theHandle,stringLength - 1);
+ }
+
+ (**theHandle)[stringLength - 1] = 0;
+
+
+EXITPOINT:
+
+ return(errCode);
+}
+
+
+OSErr AppendPStrToHandle(const unsigned char *thePString,Handle theHandle,long *currentLength)
+{
+OSErr errCode = noErr;
+char tempString[256];
+
+
+ CopyPStrToCStr(thePString,tempString,sizeof(tempString));
+
+ errCode = AppendCStrToHandle(tempString,theHandle,currentLength);
+
+
+EXITPOINT:
+
+ return(errCode);
+}
+
+
+
+OSErr AppendCStrToHandle(const char *theCString,Handle theHandle,long *currentLength,long *maxLength)
+{
+OSErr errCode = noErr;
+long handleMaxLength,handleCurrentLength,stringLength,byteCount;
+
+
+ if (theCString == nil)
+ {
+ SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theCString == nil"));
+ }
+
+ if (theHandle == nil)
+ {
+ SetErrorMessageAndBail(("AppendCStrToHandle: Bad parameter, theHandle == nil"));
+ }
+
+
+ if (maxLength != nil)
+ {
+ handleMaxLength = *maxLength;
+ }
+
+ else
+ {
+ handleMaxLength = GetHandleSize(theHandle);
+ }
+
+
+ if (currentLength != nil && *currentLength >= 0)
+ {
+ handleCurrentLength = *currentLength;
+ }
+
+ else
+ {
+ handleCurrentLength = CStrLength(*theHandle);
+ }
+
+
+ stringLength = CStrLength(theCString);
+
+ byteCount = handleCurrentLength + stringLength + 1;
+
+ if (byteCount > handleMaxLength)
+ {
+ SetHandleSize(theHandle,handleCurrentLength + stringLength + 1);
+
+ if (maxLength != nil)
+ {
+ *maxLength = GetHandleSize(theHandle);
+
+ handleMaxLength = *maxLength;
+ }
+
+ else
+ {
+ handleMaxLength = GetHandleSize(theHandle);
+ }
+
+ if (byteCount > handleMaxLength)
+ {
+ SetErrorMessageAndLongIntAndBail("AppendCStrToHandle: Can't increase Handle allocation, MemError() = ",MemError());
+ }
+ }
+
+
+ BlockMove(theCString,*theHandle + handleCurrentLength,stringLength + 1);
+
+
+ if (currentLength != nil)
+ {
+ *currentLength += stringLength;
+ }
+
+
+ errCode = noErr;
+
+
+EXITPOINT:
+
+ return(errCode);
+}
+
+
+
+OSErr AppendCharsToHandle(const char *theChars,const int numChars,Handle theHandle,long *currentLength,long *maxLength)
+{
+OSErr errCode = noErr;
+long handleMaxLength,handleCurrentLength,byteCount;
+
+
+ if (theChars == nil)
+ {
+ SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theChars == nil"));
+ }
+
+ if (theHandle == nil)
+ {
+ SetErrorMessageAndBail(("AppendCharsToHandle: Bad parameter, theHandle == nil"));
+ }
+
+
+ if (maxLength != nil)
+ {
+ handleMaxLength = *maxLength;
+ }
+
+ else
+ {
+ handleMaxLength = GetHandleSize(theHandle);
+ }
+
+
+ if (currentLength != nil && *currentLength >= 0)
+ {
+ handleCurrentLength = *currentLength;
+ }
+
+ else
+ {
+ handleCurrentLength = CStrLength(*theHandle);
+ }
+
+
+ byteCount = handleCurrentLength + numChars + 1;
+
+ if (byteCount > handleMaxLength)
+ {
+ SetHandleSize(theHandle,handleCurrentLength + numChars + 1);
+
+ if (maxLength != nil)
+ {
+ *maxLength = GetHandleSize(theHandle);
+
+ handleMaxLength = *maxLength;
+ }
+
+ else
+ {
+