I found that I needed libxml2 to work on the Macintosh in Carbon, not just in OS X. The product did not work correctly without making changes to the source code. The problem was how file paths were treated. In a Mac OS X only application, the file paths were POSIX and so it worked correctly with libxml. Within a Carbon application the file paths used the Mac file system (A colon is used as the separator). Libxml internally depends on a POSIX style path. My solution was to change the path to a Mac style path just before the file path is used when calling file IO functionality.
There were other problems as well. I made a few changes to the code, and I hope I used the correct conditionals.
Below is a list of changes and the files that I made the changes into.
TRIOSTR.C:
I made the following change at around line 57. I found that USE_STRTOF was causing problems in Carbon. I used the __MACOS__ define to conditional it, but I'm not 100% sure that was the appropriate one to use.
------------------------------------------
#if defined(TRIO_COMPILER_SUPPORTS_C99)
# define USE_STRTOD
# ifndef __MACOS__
# define USE_STRTOF
# endif
#elif defined(TRIO_COMPILER_MSVC)
# define USE_STRTOD
#endif
------------------------------------------
XMLIO.C:
I added code based on the conditional CONVERT_TO_MAC_PATHS. At around line 39 I added the following lines to include a needed header file.
-------------------------------------------
#ifdef CONVERT_TO_MAC_PATHS
#include <CFURL.h>
#endif
-------------------------------------------
I added the following function too. This takes a POSIX path and returns a Mac path.
-----------------------------------------------------------
#ifdef CONVERT_TO_MAC_PATHS
static char * ConvertPosixToMac(const char *posixPath)
{
OSStatus status;
FSRef theRef;
char *ret = NULL;
CFURLRef theURL;
CFStringRef theString;
theString = CFStringCreateWithCString(kCFAllocatorDefault, posixPath, kCFStringEncodingMacRoman);
if (theString)
{
theURL = CFURLCreateWithFileSystemPath(kCFAllocatorDefault, theString, kCFURLPOSIXPathStyle, false);
CFRelease(theString);
if (theURL)
{
CFIndex strSize;
theString = CFURLCopyFileSystemPath(theURL, kCFURLHFSPathStyle);
strSize = CFStringGetLength(theString);
ret = (char *) xmlMallocAtomic((strSize + 1) * sizeof(xmlChar));
CFStringGetCString(theString, ret, (CFIndex)(strSize + 1), kCFStringEncodingMacRoman);
}
}
if (ret == NULL)
ret = (char *)xmlCharStrdup(posixPath);
return ret;
}
#endif
-----------------------------------------------------------
I changed the function xmlFileOpen_real() in xmlio.c (at around line 300) so that I convert the POSIX path to a Mac path at the last possible moment. Afterwards I free the memory allocated by the ConvertPosixToMac() call.
-----------------------------------------------------------
static void *
xmlFileOpen_real (const char *filename) {
const char *path = NULL;
FILE *fd;
if (!strcmp(filename, "-")) {
fd = stdin;
return((void *) fd);
}
if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17))
#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__)
path = &filename[17];
#else
path = &filename[16];
#endif
else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) {
#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__)
path = &filename[8];
#else
path = &filename[7];
#endif
} else
path = filename;
if (path == NULL)
return(NULL);
#ifdef CONVERT_TO_MAC_PATHS
path = ConvertPosixToMac(path);
#endif
if (!xmlCheckFilename(path))
return(NULL);
#if defined(WIN32) || defined (__DJGPP__) && !defined (__CYGWIN__)
fd = fopen(path, "rb");
#else
fd = fopen(path, "r");
#endif /* WIN32 */
#ifdef CONVERT_TO_MAC_PATHS
xmlFree((xmlChar *)path);
#endif
return((void *) fd);
}
-----------------------------------------------------------
I did a similar change for xmlFileOpenW(), also within xmlio.c at around line 371.
-----------------------------------------------------------
static void *
xmlFileOpenW (const char *filename) {
const char *path = NULL;
FILE *fd;
if (!strcmp(filename, "-")) {
fd = stdout;
return((void *) fd);
}
if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file://localhost/", 17))
#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__)
path = &filename[17];
#else
path = &filename[16];
#endif
else if (!xmlStrncasecmp(BAD_CAST filename, BAD_CAST "file:///", 8)) {
#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__)
path = &filename[8];
#else
path = &filename[7];
#endif
} else
path = filename;
if (path == NULL)
return(NULL);
#ifdef CONVERT_TO_MAC_PATHS
path = ConvertPosixToMac(path);
#endif
fd = fopen(path, "wb");
#ifdef CONVERT_TO_MAC_PATHS
xmlFree((xmlChar *)path);
#endif
return((void *) fd);
}
-----------------------------------------------------------
And I did the same thing to xmlSysIDExists() in xmlio.c at around line 2496.
-----------------------------------------------------------
static int xmlSysIDExists(const char *URL) {
#ifdef HAVE_STAT
int ret;
struct stat info;
const char *path;
if (URL == NULL)
return(0);
if (!xmlStrncasecmp(BAD_CAST URL, BAD_CAST "file://localhost/", 17))
#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__)
path = &URL[17];
#else
path = &URL[16];
#endif
else if (!xmlStrncasecmp(BAD_CAST URL, BAD_CAST "file:///", 8)) {
#if defined (_WIN32) || defined (__DJGPP__) && !defined(__CYGWIN__)
path = &URL[8];
#else
path = &URL[7];
#endif
} else
path = URL;
#ifdef CONVERT_TO_MAC_PATHS
path = ConvertPosixToMac(path);
#endif
ret = stat(path, &info);
#ifdef CONVERT_TO_MAC_PATHS
xmlFree((xmlChar*)path);
#endif
if (ret == 0)
return(1);
#endif
return(0);
}
-----------------------------------------------------------
CONFIG.H:
Finally, because I was using CodeWarrior, I had to manually create a config.h file for myself. These are the extra defines I used.
-----------------------------------------------------------
#define PACKAGE "libxml2"
#define VERSION "2.5.11"
#define HAVE_LIBZ 1
#define HAVE_ISINF 1
#define SOCKLEN_T
#define HAVE_LIBPTHREAD 1
#define HAVE_ARPA_INET_H 1
#define HAVE_ARPA_NAMESER_H 1
#define HAVE_CTYPE_H 1
#define HAVE_DIRENT_H 1
#define HAVE_ERRNO_H 1
#define HAVE_FCNTL_H 1
#define HAVE_FINITE 1
#define HAVE_FLOAT_H 1
#define HAVE_FPRINTF 1
#define HAVE_INTTYPES_H 1
#define HAVE_LOCALTIME 1
#define HAVE_MATH_H 1
#define HAVE_MEMORY_H 1
#define HAVE_NETDB_H 1
#define HAVE_NETINET_IN_H 1
#define HAVE_PRINTF 1
#define HAVE_RESOLV_H 1
#define HAVE_SIGNAL 1
#define HAVE_SIGNAL_H 1
#define HAVE_SNPRINTF 1
#define HAVE_SPRINTF 1
#define HAVE_SSCANF 1
#define HAVE_STAT 1
#define HAVE_STDARG_H 1
#define HAVE_STDINT_H 1
#define HAVE_STDLIB_H 1
#define HAVE_STRDUP 1
#define HAVE_STRERROR 1
#define HAVE_STRFTIME 1
#define HAVE_STRINGS_H 1
#define HAVE_STRING_H 1
#define HAVE_SYS_MMAN_H 1
#define HAVE_SYS_SELECT_H 1
#define HAVE_SYS_SOCKET_H 1
#define HAVE_SYS_STAT_H 1
#define HAVE_SYS_TIMEB_H 1
#define HAVE_TIME_H 1
#define HAVE_UNISTD_H 1
#define HAVE_VFPRINTF 1
#define HAVE_VSNPRINTF 1
#define HAVE_VSPRINTF 1
#define PACKAGE "libxml2"
#define PACKAGE_BUGREPORT ""
#define PACKAGE_NAME ""
#define PACKAGE_STRING ""
#define PACKAGE_TARNAME ""
#define PACKAGE_VERSION ""
#define PROTOTYPES 1
#define STDC_HEADERS 1
#define VERSION "2.5.11"
#define CONVERT_TO_MAC_PATHS
-----------------------------------------------------------
We here at FileNet would like these changes to go into the next version of Libxml if at all possible. We have not been upgrading our libxml as this can take up to 2 days of work due to the changes we have made.
Cameron C. Johnson
Software Developer
FileNet Corporation
www.FileNet.com
ccjohnson FileNet com
Phone: (780) 433-3690 ext. 2225 (phone)
Fax: (780) 437-4381 (fax)
CONFIDENTIAL NOTICE: The contents of this message, including any attachments, are confidential and are intended solely for the use of the person or entity to whom the message was addressed. If you are not the intended recipient of this message, please be advised that any dissemination, distribution, or use of the contents of this message is strictly prohibited. If you received this message in error, please notify the sender. Please also permanently delete all copies of the original message and any attached documentation. Thank you.