[xml] Default Catalog On Windows, Deprecated API
- From: Igor Zlatkovic <igor zlatkovic com>
- To: xml gnome org
- Subject: [xml] Default Catalog On Windows, Deprecated API
- Date: Wed, 09 Jun 2004 16:16:35 +0200
Hi there,
Since I am changing the distribution paths, I can as well set a
meaningful default location for catalogs.
The attached patch to catalog.c modifies xmlInitializeCatalog function
to look for ../etc/catalog relative to the location of the libxml2
shared library. This path is discovered at runtime when the function is
first called. Of course, this is Windows only, others remain with the
hardcoded default path.
If there are no objections to this, I'll commit.
Daniel: The last two changes in the patch remove the code from the two
deprecated functions. I posted about this, the current implementation
can return an address of the local variable. Perhaps this should just be
reverted, as you said, but I find it better to call the new API instead.
Now, should I commit or revert?
Ciao,
Igor
Index: catalog.c
===================================================================
RCS file: /cvs/gnome/libxml2/catalog.c,v
retrieving revision 1.61
diff -c -r1.61 catalog.c
*** catalog.c 18 May 2004 10:49:20 -0000 1.61
--- catalog.c 9 Jun 2004 14:06:41 -0000
***************
*** 68,73 ****
--- 68,80 ----
#define XML_SGML_DEFAULT_CATALOG "file:///etc/sgml/catalog"
#endif
+ #if defined(_WIN32) && defined(_MSC_VER)
+ #undef XML_XML_DEFAULT_CATALOG
+ static char XML_XML_DEFAULT_CATALOG[256] = "file:///etc/xml/catalog";
+ void* __stdcall GetModuleHandleA(const char*);
+ unsigned long __stdcall GetModuleFileNameA(void*, char*, unsigned long);
+ #endif
+
static int xmlExpandCatalog(xmlCatalogPtr catal, const char *filename);
/************************************************************************
***************
*** 2925,2931 ****
--- 2932,2966 ----
catalogs = (const char *) getenv("XML_CATALOG_FILES");
if (catalogs == NULL)
+ #if defined(_WIN32) && defined(_MSC_VER)
+ {
+ void* hmodule;
+ hmodule = GetModuleHandleA("libxml2.dll");
+ if (hmodule == NULL)
+ hmodule = GetModuleHandleA(NULL);
+ if (hmodule != NULL) {
+ char buf[256];
+ unsigned long len = GetModuleFileNameA(hmodule, buf, 255);
+ if (len != 0) {
+ char* p = &(buf[len]);
+ while (*p != '\\' && p > buf)
+ p--;
+ if (p != buf) {
+ xmlChar* uri;
+ strncpy(p, "\\..\\etc\\catalog", 255 - (p - buf));
+ uri = xmlCanonicPath(buf);
+ if (uri != NULL) {
+ strncpy(XML_XML_DEFAULT_CATALOG, uri, 255);
+ xmlFree(uri);
+ }
+ }
+ }
+ }
+ catalogs = XML_XML_DEFAULT_CATALOG;
+ }
+ #else
catalogs = XML_XML_DEFAULT_CATALOG;
+ #endif
catal = xmlCreateNewCatalog(XML_XML_CATALOG_TYPE,
xmlCatalogDefaultPrefer);
***************
*** 3509,3545 ****
*/
const xmlChar *
xmlCatalogGetSystem(const xmlChar *sysID) {
! xmlChar *ret;
! static xmlChar result[1000];
! static int msg = 0;
!
! if (!xmlCatalogInitialized)
! xmlInitializeCatalog();
!
! if (msg == 0) {
! xmlGenericError(xmlGenericErrorContext,
! "Use of deprecated xmlCatalogGetSystem() call\n");
! msg++;
! }
!
! if (sysID == NULL)
! return(NULL);
!
! /*
! * Check first the XML catalogs
! */
! if (xmlDefaultCatalog != NULL) {
! ret = xmlCatalogListXMLResolve(xmlDefaultCatalog->xml, NULL, sysID);
! if ((ret != NULL) && (ret != XML_CATAL_BREAK)) {
! snprintf((char *) result, sizeof(result) - 1, "%s", (char *) ret);
! result[sizeof(result) - 1] = 0;
! return(result);
! }
! }
!
! if (xmlDefaultCatalog != NULL)
! return(xmlCatalogGetSGMLSystem(xmlDefaultCatalog->sgml, sysID));
! return(NULL);
}
/**
--- 3544,3550 ----
*/
const xmlChar *
xmlCatalogGetSystem(const xmlChar *sysID) {
! return xmlCatalogResolveSystem(sysID);
}
/**
***************
*** 3553,3589 ****
*/
const xmlChar *
xmlCatalogGetPublic(const xmlChar *pubID) {
! xmlChar *ret;
! static xmlChar result[1000];
! static int msg = 0;
!
! if (!xmlCatalogInitialized)
! xmlInitializeCatalog();
!
! if (msg == 0) {
! xmlGenericError(xmlGenericErrorContext,
! "Use of deprecated xmlCatalogGetPublic() call\n");
! msg++;
! }
!
! if (pubID == NULL)
! return(NULL);
!
! /*
! * Check first the XML catalogs
! */
! if (xmlDefaultCatalog != NULL) {
! ret = xmlCatalogListXMLResolve(xmlDefaultCatalog->xml, pubID, NULL);
! if ((ret != NULL) && (ret != XML_CATAL_BREAK)) {
! snprintf((char *) result, sizeof(result) - 1, "%s", (char *) ret);
! result[sizeof(result) - 1] = 0;
! return(result);
! }
! }
!
! if (xmlDefaultCatalog != NULL)
! return(xmlCatalogGetSGMLPublic(xmlDefaultCatalog->sgml, pubID));
! return(NULL);
}
#endif /* LIBXML_CATALOG_ENABLED */
--- 3558,3564 ----
*/
const xmlChar *
xmlCatalogGetPublic(const xmlChar *pubID) {
! return xmlCatalogResolvePublic(pubID);
}
#endif /* LIBXML_CATALOG_ENABLED */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]