[xiph-commits] r10553 - in branches/xiph-qt/xiph-qt-win32: OggImport/src build-win32

arek at svn.xiph.org arek at svn.xiph.org
Tue Dec 6 13:53:57 PST 2005


Author: arek
Date: 2005-12-06 13:53:44 -0800 (Tue, 06 Dec 2005)
New Revision: 10553

Added:
   branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT.bat
   branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT_debug.bat
   branches/xiph-qt/xiph-qt-win32/build-win32/pxml.c
   branches/xiph-qt/xiph-qt-win32/build-win32/pxml.h
Modified:
   branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.c
   branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.r
   branches/xiph-qt/xiph-qt-win32/build-win32/XiphQT.dsp
Log:
XiphQT Win32 port: ported meta-data importing.

Modified: branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.c
===================================================================
--- branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.c	2005-12-06 15:31:51 UTC (rev 10552)
+++ branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.c	2005-12-06 21:53:44 UTC (rev 10553)
@@ -57,6 +57,10 @@
 #include "common.h"
 #include "rb.h"
 
+#if TARGET_OS_WIN32
+#include "pxml.h"
+#endif
+
 //stream-type support functions
 #include "stream_vorbis.h"
 #include "stream_speex.h"
@@ -372,70 +376,84 @@
 }
 
 
-static int InitialiseMetaDataMappings(StreamInfoPtr si) {
-	CFBundleRef bundle;
-	CFURLRef mdmurl;
-	CFDataRef data;
-	SInt32 ret = 0;
-	CFStringRef errorString;
-	SInt32 error = 0;
-	CFDictionaryRef props;
+static int InitialiseMetaDataMappings(OggImportGlobalsPtr globals, StreamInfoPtr si) {
+    SInt32 ret = 0;
+    CFDictionaryRef props = NULL;
 
-	dbg_printf("--= IMDM()\n");
-	if (si->MDmapping != NULL && si->UDmapping != NULL) {
-		return 1;
-	}
-	
-	//else? let's assume for now that they are both intialised or both are not initialised
+    dbg_printf("--= IMDM()\n");
+    if (si->MDmapping != NULL && si->UDmapping != NULL) {
+        return 1;
+    }
 
-#if !TARGET_OS_WIN32
-	bundle = CFBundleGetBundleWithIdentifier(CFSTR(kOggVorbisBundleID));
-	
-	if (bundle == NULL)
-		return 0;
+    //else? let's assume for now that they are both intialised or both are not initialised
 
-	mdmurl = CFBundleCopyResourceURL(bundle, CFSTR("MetaDataConfig"), CFSTR("plist"), NULL);
-	if (mdmurl != NULL) {
-		if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, mdmurl, &data, 
-													 NULL, NULL, &error)) {
-			props = (CFDictionaryRef) CFPropertyListCreateFromXMLData(kCFAllocatorDefault, data,
-																	  kCFPropertyListImmutable, &errorString);
-			if (props != NULL) {
-				if (CFGetTypeID(props) == CFDictionaryGetTypeID()) {
-					si->MDmapping = (CFDictionaryRef) CFDictionaryGetValue(props, CFSTR("Vorbis-to-MD"));
-					if (si->MDmapping != NULL) {
-						dbg_printf("----: MDmapping found\n");
-						CFRetain(si->MDmapping);
-						ret = 1;
-					}
-					si->UDmapping = (CFDictionaryRef) CFDictionaryGetValue(props, CFSTR("Vorbis-to-UD"));
-					if (si->UDmapping != NULL) {
-						dbg_printf("----: UDmapping found\n");
-						CFRetain(si->UDmapping);
-					} else
-						ret = 0;
-				}
-				CFRelease(props);
-			}
-			CFRelease(data);
-		}
-		CFRelease(mdmurl);
-	}
-#endif
-	return ret;
+#if TARGET_OS_WIN32
+    {
+        Handle mapplist;
+        OSErr err = GetComponentResource((Component)globals->self, 'MDCf', kImporterResID, &mapplist);
+        if (err == noErr) {
+            long mpl_size = GetHandleSize(mapplist);
+            HLock(mapplist);
+            props = pxml_parse_plist((unsigned char *) *mapplist, mpl_size);
+            HUnlock(mapplist);
+        }
+    }
+#else
+    {
+        CFBundleRef bundle;
+        CFURLRef mdmurl;
+        CFDataRef data;
+        SInt32 error = 0;
+        CFStringRef errorString;
+
+        bundle = CFBundleGetBundleWithIdentifier(CFSTR(kOggVorbisBundleID));
+
+        if (bundle == NULL)
+            return 0;
+
+        mdmurl = CFBundleCopyResourceURL(bundle, CFSTR("MetaDataConfig"), CFSTR("plist"), NULL);
+        if (mdmurl != NULL) {
+            if (CFURLCreateDataAndPropertiesFromResource(kCFAllocatorDefault, mdmurl, &data, NULL, NULL, &error)) {
+                props = (CFDictionaryRef) CFPropertyListCreateFromXMLData(kCFAllocatorDefault, data,
+                                                                          kCFPropertyListImmutable, &errorString);
+                CFRelease(data);
+            }
+            CFRelease(mdmurl);
+        }
+    }
+#endif /* TARGET_OS_WIN32 */
+
+    if (props != NULL) {
+        if (CFGetTypeID(props) == CFDictionaryGetTypeID()) {
+            si->MDmapping = (CFDictionaryRef) CFDictionaryGetValue(props, CFSTR("Vorbis-to-MD"));
+            if (si->MDmapping != NULL) {
+                dbg_printf("----: MDmapping found\n");
+                CFRetain(si->MDmapping);
+                ret = 1;
+            }
+            si->UDmapping = (CFDictionaryRef) CFDictionaryGetValue(props, CFSTR("Vorbis-to-UD"));
+            if (si->UDmapping != NULL) {
+                dbg_printf("----: UDmapping found\n");
+                CFRetain(si->UDmapping);
+            } else
+                ret = 0;
+        }
+        CFRelease(props);
+    }
+
+    return ret;
 }
 
-static int LookupTagUD(StreamInfoPtr si, const char *str, long *osType) {
-	int ret = -1;
-	long len;
+static int LookupTagUD(OggImportGlobalsPtr globals, StreamInfoPtr si, const char *str, long *osType) {
+    int ret = -1;
+    long len;
 
-#if !TARGET_OS_WIN32
-	if (si->UDmapping == NULL)
+    if (si->UDmapping == NULL)
     {
-		if (!InitialiseMetaDataMappings(si))
-			return -1;
+        if (!InitialiseMetaDataMappings(globals, si))
+            return -1;
     }
-    
+
 	len = strcspn(str, "=");
 
 	if (len > 0) {
@@ -443,9 +461,10 @@
 		if (tmpkstr != NULL) {
 			CFMutableStringRef keystr = CFStringCreateMutableCopy(NULL, len + 1, tmpkstr);
 			if (keystr != NULL) {
-				CFLocaleRef loc = CFLocaleCopyCurrent();
+				//CFLocaleRef loc = CFLocaleCopyCurrent();
+				CFLocaleRef loc = NULL;
 				CFStringUppercase(keystr, loc);
-				CFRelease(loc);
+				//CFRelease(loc);
 				dbg_printf("--- luTud: %s [%s]\n", (char *)str, (char *)CFStringGetCStringPtr(keystr,kCFStringEncodingUTF8));
 				if (CFDictionaryContainsKey(si->UDmapping, keystr)) {
 					CFStringRef udkey = (CFStringRef) CFDictionaryGetValue(si->UDmapping, keystr);
@@ -463,21 +482,20 @@
 			CFRelease(tmpkstr);
 		}
 	}
-#endif
+
 	return ret;
 }
 
-static int LookupTagMD(StreamInfoPtr si, const char *str, long *osType) {
-	int ret = -1;
-	long len;
+static int LookupTagMD(OggImportGlobalsPtr globals, StreamInfoPtr si, const char *str, long *osType) {
+    int ret = -1;
+    long len;
 
-#if !TARGET_OS_WIN32
-	if (si->MDmapping == NULL)
+    if (si->MDmapping == NULL)
     {
-		if (!InitialiseMetaDataMappings(si))
-			return -1;
+        if (!InitialiseMetaDataMappings(globals, si))
+            return -1;
     }
-    
+
 	len = strcspn(str, "=");
 
 	if (len > 0) {
@@ -485,9 +503,10 @@
 		if (tmpkstr != NULL) {
 			CFMutableStringRef keystr = CFStringCreateMutableCopy(NULL, len + 1, tmpkstr);
 			if (keystr != NULL) {
-				CFLocaleRef loc = CFLocaleCopyCurrent();
+				//CFLocaleRef loc = CFLocaleCopyCurrent();
+				CFLocaleRef loc = NULL;
 				CFStringUppercase(keystr, loc);
-				CFRelease(loc);
+				//CFRelease(loc);
 				dbg_printf("--- luTmd: %s [%s]\n", (char *)str, (char *)CFStringGetCStringPtr(keystr,kCFStringEncodingUTF8));
 				if (CFDictionaryContainsKey(si->MDmapping, keystr)) {
 					CFStringRef mdkey = (CFStringRef) CFDictionaryGetValue(si->MDmapping, keystr);
@@ -505,118 +524,91 @@
 			CFRelease(tmpkstr);
 		}
 	}
-#endif
+
 	return ret;
 }
 
-#if !TARGET_OS_WIN32
-static ComponentResult ConvertUTF8toScriptCode(const char *str, Handle *h, ScriptCode *script)
+static ComponentResult ConvertUTF8toScriptCode(const char *str, Handle *h)
 {
-	TextEncoding    sourceEncoding = CreateTextEncoding(kTextEncodingUnicodeV3_0, kUnicodeNoSubset, kUnicodeUTF8Format);
-	TextEncoding    destEncoding = CreateTextEncoding(kTextEncodingMacRoman, kTextEncodingDefaultVariant, kTextEncodingDefaultFormat);
-	TECObjectRef	converter;
-    Handle          temp;
-    int             length = strlen(str);
-    int             tempLen = length * 2;
-    
-    OSErr err = TECCreateConverter(&converter, sourceEncoding, destEncoding);
-    if (err != noErr)
-        return err;
+    CFStringEncoding encoding = 0;
+    CFIndex numberOfCharsConverted = 0, usedBufferLength = 0;
+    OSStatus ret = noErr;
 
-    *script = 0;
-    *h = NULL;
+    CFStringRef tmpstr = CFStringCreateWithBytes(NULL, str, strlen(str), kCFStringEncodingUTF8, true);
+    if (tmpstr == NULL)
+        return  kTextUnsupportedEncodingErr; //!??!?!
 
-	temp = NewHandle(tempLen);
-	if (temp == NULL)
-		return memFullErr;
+    encoding = kCFStringEncodingMacRoman;
 
-	while (1)
-	{
-        ByteCount actualIn, actualOut, flushOut;
+    if (ret == noErr) {
+        CFRange range = { 0, CFStringGetLength(tmpstr)};
+        numberOfCharsConverted = CFStringGetBytes(tmpstr, range, encoding, 0, false,
+                                                  NULL, 0, &usedBufferLength);
+        if ((numberOfCharsConverted == CFStringGetLength(tmpstr)) && (usedBufferLength > 0)) {
+            *h = NewHandleClear(usedBufferLength);
+            if (*h != NULL) {
+                HLock(*h);
 
-		HLock(temp);
-		actualIn = 0;
-        flushOut = 0;
-		
-		err = TECConvertText(converter, (ConstTextPtr)str, length, &actualIn, (TextPtr)*temp, tempLen, &actualOut);
-		if (length == actualIn || actualOut < tempLen - 20)
-		{
-            if (err == noErr)
-                err = TECFlushText(converter, (TextPtr) ((*temp) + actualOut), tempLen - actualOut, &flushOut);
-			HUnlock(temp);
-            SetHandleSize(temp, actualOut + flushOut);
-            *h = temp;
-            temp = NULL;
-            err = noErr;    // ignore and supress conversion errors
-			break;
-		}
-		else
-		{
-			HUnlock(temp);
-			tempLen += length;
-			SetHandleSize(temp, tempLen);
-			err = MemError();
-			if (err != noErr)
-				break;	
-		}
-	}
-	
-	if (temp != NULL)
-		DisposeHandle(temp);
+                numberOfCharsConverted = CFStringGetBytes(tmpstr, range, encoding, 0,
+                                                          false, **h, usedBufferLength,
+                                                          &usedBufferLength);
+                HUnlock(*h);
+            } else {
+                ret = MemError();
+            }
+        } else {
+            ret = kTextUnsupportedEncodingErr;
+        }
+    }
 
-    TECDisposeConverter(converter);
+    CFRelease(tmpstr);
 
-    return err;
+    return ret;
 }
-#endif
 
-static ComponentResult AddCommentToMetaData(StreamInfoPtr si, const char *str, int len, QTMetaDataRef md) {
-	ComponentResult ret = noErr;
-	long tag;
+static ComponentResult AddCommentToMetaData(OggImportGlobalsPtr globals, StreamInfoPtr si, const char *str, int len, QTMetaDataRef md) {
+    ComponentResult ret = noErr;
+    long tag;
 
-    int	tagLen = LookupTagMD(si, str, &tag);
-	Handle h;
-	ScriptCode script;
-        
-	
+    int tagLen = LookupTagMD(globals, si, str, &tag);
+    Handle h;
+
     if (tagLen != -1 && str[tagLen] != '\0') {
-		dbg_printf("-- TAG: %08lx\n", tag);
+        dbg_printf("-- TAG: %08lx\n", tag);
 
-		ret = QTMetaDataAddItem(md, kQTMetaDataStorageFormatQuickTime, kQTMetaDataKeyFormatCommon,
-								&tag, sizeof(tag), str + tagLen, len - tagLen, kQTMetaDataTypeUTF8, NULL);
-		dbg_printf("-- TAG: %4.4s :: QT    = %ld\n", (char *)&tag, (long)ret);
-	}
-	
-    tagLen = LookupTagUD(si, str, &tag);
-	
+        ret = QTMetaDataAddItem(md, kQTMetaDataStorageFormatQuickTime, kQTMetaDataKeyFormatCommon,
+                                &tag, sizeof(tag), str + tagLen, len - tagLen, kQTMetaDataTypeUTF8, NULL);
+        dbg_printf("-- TAG: %4.4s :: QT    = %ld\n", (char *)&tag, (long)ret);
+    }
+
+    tagLen = LookupTagUD(globals, si, str, &tag);
+
     if (tagLen != -1 && str[tagLen] != '\0') {
-		QTMetaDataItem mdi;
-		char * localestr = "en";
-		Handle localeh = NewEmptyHandle();
-		
-		PtrAndHand(&localestr, localeh, strlen(localestr));
+        QTMetaDataItem mdi;
+        char * localestr = "en";
+        Handle localeh = NewEmptyHandle();
 
-		dbg_printf("-- TAG: %08lx\n", tag);
+        PtrAndHand(&localestr, localeh, strlen(localestr));
 
-#if !TARGET_OS_WIN32
-		ret = ConvertUTF8toScriptCode(str + tagLen, &h, &script);
-		if (ret == noErr) {
-			HLock(h);
-			ret = QTMetaDataAddItem(md, kQTMetaDataStorageFormatUserData, kQTMetaDataKeyFormatUserData,
-									&tag, sizeof(tag), *h, GetHandleSize(h), kQTMetaDataTypeMacEncodedText, &mdi);
-			dbg_printf("-- TAG: %4.4s :: QT[X] = %ld\n", (char *)&tag, (long)ret);
-			HUnlock(h);
-			if (ret == noErr) {
-				ret = QTMetaDataSetItemProperty(md, mdi, kPropertyClass_MetaDataItem, kQTMetaDataItemPropertyID_Locale,
-												GetHandleSize(localeh), *h);
-				dbg_printf("-- TAG: %4.4s :: QT[X] locale (%5.5s)= %ld\n", (char *)&tag, *h, (long)ret);
-			}
-			DisposeHandle(h);
-		}
-#endif
-	}
+        dbg_printf("-- TAG: %08lx\n", tag);
 
-	return ret;
+        ret = ConvertUTF8toScriptCode(str + tagLen, &h);
+        if (ret == noErr) {
+            HLock(h);
+            ret = QTMetaDataAddItem(md, kQTMetaDataStorageFormatUserData, kQTMetaDataKeyFormatUserData,
+                                    &tag, sizeof(tag), *h, GetHandleSize(h), kQTMetaDataTypeMacEncodedText, &mdi);
+            dbg_printf("-- TAG: %4.4s :: QT[X] = %ld\n", (char *)&tag, (long)ret);
+            HUnlock(h);
+            if (ret == noErr) {
+                ret = QTMetaDataSetItemProperty(md, mdi, kPropertyClass_MetaDataItem, kQTMetaDataItemPropertyID_Locale,
+                                                GetHandleSize(localeh), *h);
+                dbg_printf("-- TAG: %4.4s :: QT[X] locale (%5.5s)= %ld\n", (char *)&tag, *h, (long)ret);
+            }
+            DisposeHandle(h);
+        }
+    }
+
+    return ret;
 }
 
 ComponentResult DecodeCommentsQT(OggImportGlobalsPtr globals, StreamInfoPtr si, vorbis_comment *vc)
@@ -633,7 +625,7 @@
 	
     for (i = 0; i < vc->comments; i++)
     {
-        ret = AddCommentToMetaData(si, vc->user_comments[i], vc->comment_lengths[i], md);
+        ret = AddCommentToMetaData(globals, si, vc->user_comments[i], vc->comment_lengths[i], md);
         if (ret != noErr) {
             //break;
 			dbg_printf("AddCommentToMetaData() failed? = %d\n", ret);
@@ -650,7 +642,7 @@
 	
     for (i = 0; i < vc->comments; i++)
     {
-        ret = AddCommentToMetaData(si, vc->user_comments[i], vc->comment_lengths[i], md);
+        ret = AddCommentToMetaData(globals, si, vc->user_comments[i], vc->comment_lengths[i], md);
         if (ret != noErr) {
             //break;
 			dbg_printf("AddCommentToMetaData() failed? = %d\n", ret);

Modified: branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.r
===================================================================
--- branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.r	2005-12-06 15:31:51 UTC (rev 10552)
+++ branches/xiph-qt/xiph-qt-win32/OggImport/src/OggImport.r	2005-12-06 21:53:44 UTC (rev 10553)
@@ -265,4 +265,6 @@
     };
 };
 
-
+#if TARGET_OS_WIN32
+read 'MDCf' (kImporterResID) "../MetaDataConfig.plist";
+#endif

Modified: branches/xiph-qt/xiph-qt-win32/build-win32/XiphQT.dsp
===================================================================
--- branches/xiph-qt/xiph-qt-win32/build-win32/XiphQT.dsp	2005-12-06 15:31:51 UTC (rev 10552)
+++ branches/xiph-qt/xiph-qt-win32/build-win32/XiphQT.dsp	2005-12-06 21:53:44 UTC (rev 10553)
@@ -327,6 +327,14 @@
 # End Source File
 # Begin Source File
 
+SOURCE=.\pxml.c
+# End Source File
+# Begin Source File
+
+SOURCE=.\pxml.h
+# End Source File
+# Begin Source File
+
 SOURCE=..\utils\ringbuffer.cpp
 # End Source File
 # Begin Source File

Added: branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT.bat
===================================================================
--- branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT.bat	2005-12-06 15:31:51 UTC (rev 10552)
+++ branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT.bat	2005-12-06 21:53:44 UTC (rev 10553)
@@ -0,0 +1,22 @@
+ at echo off
+echo ---+++--- Building XiphQT ---+++---
+
+set BTARGET=build
+
+if NOT z%1==z (set BTARGET=%1)
+
+set OLDPATH=%PATH%
+set OLDINCLUDE=%INCLUDE%
+set OLDLIB=%LIB%
+
+call "c:\program files\microsoft visual studio\vc98\bin\vcvars32.bat"
+echo Setting include/lib paths for XiphQT
+set PATH=%PATH%;"C:\Program Files\QuickTime SDK\Tools"
+set INCLUDE=%INCLUDE%;"C:\Program Files\QuickTime SDK\CIncludes";"C:\Program Files\QuickTime SDK\ComponentIncludes"
+set LIB=%LIB%;"C:\Program Files\QuickTime SDK\Libraries"
+echo Compiling...
+msdev XiphQT.dsp /useenv /make "XiphQT - Win32 Release" /%BTARGET%
+
+set PATH=%OLDPATH%
+set INCLUDE=%OLDINCLUDE%
+set LIB=%OLDLIB%


Property changes on: branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT.bat
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT_debug.bat
===================================================================
--- branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT_debug.bat	2005-12-06 15:31:51 UTC (rev 10552)
+++ branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT_debug.bat	2005-12-06 21:53:44 UTC (rev 10553)
@@ -0,0 +1,22 @@
+ at echo off
+echo ---+++--- Building XiphQT ---+++---
+
+set BTARGET=build
+
+if NOT z%1==z (set BTARGET=%1)
+
+set OLDPATH=%PATH%
+set OLDINCLUDE=%INCLUDE%
+set OLDLIB=%LIB%
+
+call "c:\program files\microsoft visual studio\vc98\bin\vcvars32.bat"
+echo Setting include/lib paths for XiphQT
+set PATH=%PATH%;"C:\Program Files\QuickTime SDK\Tools"
+set INCLUDE=%INCLUDE%;"C:\Program Files\QuickTime SDK\CIncludes";"C:\Program Files\QuickTime SDK\ComponentIncludes"
+set LIB=%LIB%;"C:\Program Files\QuickTime SDK\Libraries"
+echo Compiling...
+msdev XiphQT.dsp /useenv /make "XiphQT - Win32 Debug" /%BTARGET%
+
+set PATH=%OLDPATH%
+set INCLUDE=%OLDINCLUDE%
+set LIB=%OLDLIB%


Property changes on: branches/xiph-qt/xiph-qt-win32/build-win32/build_XiphQT_debug.bat
___________________________________________________________________
Name: svn:executable
   + *

Added: branches/xiph-qt/xiph-qt-win32/build-win32/pxml.c
===================================================================
--- branches/xiph-qt/xiph-qt-win32/build-win32/pxml.c	2005-12-06 15:31:51 UTC (rev 10552)
+++ branches/xiph-qt/xiph-qt-win32/build-win32/pxml.c	2005-12-06 21:53:44 UTC (rev 10553)
@@ -0,0 +1,262 @@
+/*
+ *  pxml.c
+ *
+ *    Very simple xml plist file parser.
+ *
+ *
+ *  Copyright (c) 2005  Arek Korbik
+ *
+ *  This file is part of XiphQT, the Xiph QuickTime Components.
+ *
+ *  XiphQT is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  XiphQT 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with XiphQT; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *
+ *  Last modified: $Id$
+ *
+ */
+
+
+#include "pxml.h"
+
+#include <string.h>
+
+CFStringRef pxml_parse_key(unsigned char **str, long *str_size) {
+  CFStringRef ret = NULL;
+
+  char *l_str_pos = *str;
+  char *tmp_pos = NULL;
+  char *end_pos = NULL;
+  long l_str_size = *str_size;
+
+  if (strncmp(l_str_pos, "<key", 4) != 0)
+    return NULL;
+  else {
+    l_str_pos += 4;
+    l_str_size -= 4;
+  }
+
+  tmp_pos = memchr(l_str_pos, '>', l_str_size);
+  if (tmp_pos == NULL)
+    return NULL;
+
+  tmp_pos += 1;
+  l_str_size -= tmp_pos - l_str_pos;
+  l_str_pos = tmp_pos;
+  if (l_str_size < 0)
+    return NULL;
+
+  end_pos = memchr(l_str_pos, '<', l_str_size);
+  if (end_pos == NULL)
+    return NULL;
+
+  l_str_size -= end_pos - l_str_pos;
+  l_str_pos = end_pos;
+
+  if (l_str_size < 6 || strncmp(l_str_pos, "</key>", 6) != 0)
+    return NULL;
+
+  *str = end_pos + 6;
+  *str_size = l_str_size - 6;
+
+  ret = CFStringCreateWithBytes(NULL, tmp_pos, end_pos - tmp_pos, kCFStringEncodingUTF8, true);
+
+  return ret;
+}
+
+CFStringRef pxml_parse_string(unsigned char **str, long *str_size) {
+  CFStringRef ret = NULL;
+
+  char *l_str_pos = *str;
+  char *tmp_pos = NULL;
+  char *end_pos = NULL;
+  long l_str_size = *str_size;
+
+  if (strncmp(l_str_pos, "<string", 7) != 0)
+    return NULL;
+  else {
+    l_str_pos += 7;
+    l_str_size -= 7;
+  }
+
+  tmp_pos = memchr(l_str_pos, '>', l_str_size);
+  if (tmp_pos == NULL)
+    return NULL;
+
+  tmp_pos += 1;
+  l_str_size -= tmp_pos - l_str_pos;
+  l_str_pos = tmp_pos;
+  if (l_str_size < 0)
+    return NULL;
+
+  end_pos = memchr(l_str_pos, '<', l_str_size);
+  if (end_pos == NULL)
+    return NULL;
+
+  l_str_size -= end_pos - l_str_pos;
+  l_str_pos = end_pos;
+
+  if (l_str_size < 9 || strncmp(l_str_pos, "</string>", 9) != 0)
+    return NULL;
+
+  *str = end_pos + 9;
+  *str_size = l_str_size - 9;
+
+  ret = CFStringCreateWithBytes(NULL, tmp_pos, end_pos - tmp_pos, kCFStringEncodingUTF8, true);
+
+  return ret;
+}
+
+CFDictionaryRef pxml_parse_dict(unsigned char **str, long *str_size) {
+  CFDictionaryRef ret = NULL;
+  CFMutableDictionaryRef tmp_ret = NULL;
+  char *l_str_pos = *str;
+  char *tmp_pos = NULL;
+  long l_str_size = *str_size;
+
+  if (strncmp(l_str_pos, "<dict", 5) != 0)
+    return NULL;
+  else {
+    l_str_pos += 5;
+    l_str_size -= 5;
+  }
+
+  tmp_ret = CFDictionaryCreateMutable(NULL, 0, &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks);
+
+  while ((tmp_pos = memchr(l_str_pos, '<', l_str_size)) != NULL) {
+    CFStringRef d_key = NULL;
+    void *d_value = NULL;
+
+    l_str_size -= tmp_pos - l_str_pos;
+    l_str_pos = tmp_pos;
+
+    if (l_str_size > 7 && strncmp(l_str_pos, "</dict>", 7) == 0) {
+      l_str_size -= 7;
+      l_str_pos += 7;
+      break;
+    } else if (l_str_size < 4 || strncmp(l_str_pos, "<key", 4) != 0)
+      break;
+
+    d_key = pxml_parse_key(&l_str_pos, &l_str_size);
+    if (d_key == NULL)
+      break;
+
+    tmp_pos = memchr(l_str_pos, '<', l_str_size);
+    if (tmp_pos == NULL) {
+      CFRelease(d_key);
+      break;
+    }
+
+    l_str_size -= tmp_pos - l_str_pos;
+    l_str_pos = tmp_pos;
+
+    if (l_str_size > 7 && strncmp(l_str_pos, "</dict>", 7) == 0) {
+      l_str_size -= 7;
+      l_str_pos += 7;
+      break;
+    } else if (l_str_size > 7 && strncmp(l_str_pos, "<string", 7) == 0) {
+      d_value = pxml_parse_string(&l_str_pos, &l_str_size);
+    } else if (l_str_size > 5 && strncmp(l_str_pos, "<dict", 5) == 0) {
+      d_value = pxml_parse_dict(&l_str_pos, &l_str_size);
+    } else {
+      // other value types not supported
+      CFRelease(d_key);
+      break;
+    }
+
+    if (d_value == NULL) {
+      CFRelease(d_key);
+      break;
+    }
+    CFDictionaryAddValue(tmp_ret, d_key, d_value);
+  }
+
+
+  if (CFDictionaryGetCount(tmp_ret) > 0) {
+    ret = CFDictionaryCreateCopy(NULL, tmp_ret);
+    CFDictionaryRemoveAllValues(tmp_ret);
+  }
+
+  if (ret != NULL) {
+    *str = l_str_pos;
+    *str_size = l_str_size;
+  }
+
+  return ret;
+}
+
+
+CFDictionaryRef pxml_parse_plist(unsigned char *plist_str, long plist_size) {
+  CFDictionaryRef ret = NULL;
+  char *l_str_pos = plist_str;
+  char *tmp_pos = NULL;
+  long l_str_size = plist_size;
+
+  while (l_str_size > 6 && strncmp(l_str_pos, "<plist", 6) != 0) {
+    tmp_pos = memchr(l_str_pos + 1, '<', l_str_size - 1);
+
+    if (tmp_pos == NULL) {
+      l_str_pos = NULL;
+      break;
+    }
+
+    l_str_size -= tmp_pos - l_str_pos;
+    l_str_pos = tmp_pos;
+  }
+
+  if (l_str_pos != NULL) {
+    l_str_pos += 6;
+    l_str_size -= 6;
+
+    while (l_str_size > 5 && strncmp(l_str_pos, "<dict", 5) != 0) {
+      tmp_pos = memchr(l_str_pos + 1, '<', l_str_size - 1);
+
+      if (tmp_pos == NULL) {
+        l_str_pos = NULL;
+        break;
+      }
+
+      l_str_size -= tmp_pos - l_str_pos;
+      l_str_pos = tmp_pos;
+    }
+
+    if (l_str_pos != NULL) {
+      ret = pxml_parse_dict(&l_str_pos, &l_str_size);
+    }
+  }
+
+  return ret;
+}
+
+
+#if defined(PXML_TEST_IN_PLACE)
+
+#include <stdio.h>
+#include <fcntl.h>
+
+int main(int argc, char **argv) {
+  char fbuf[65536];
+  CFDictionaryRef dict = NULL;
+  int f = open(argv[1], O_RDONLY, 0);
+  int bytes_read = read(f, fbuf, 65535);
+  close(f);
+  fbuf[bytes_read] = '\0';
+  dict = parse_plist(fbuf, strlen(fbuf));
+
+  if (dict != NULL)
+    printf("Key count: %d\n", CFDictionaryGetCount(dict));
+
+  return 0;
+}
+#endif /* PXML_TEST_IN_PLACE */


Property changes on: branches/xiph-qt/xiph-qt-win32/build-win32/pxml.c
___________________________________________________________________
Name: svn:keywords
   + Id

Added: branches/xiph-qt/xiph-qt-win32/build-win32/pxml.h
===================================================================
--- branches/xiph-qt/xiph-qt-win32/build-win32/pxml.h	2005-12-06 15:31:51 UTC (rev 10552)
+++ branches/xiph-qt/xiph-qt-win32/build-win32/pxml.h	2005-12-06 21:53:44 UTC (rev 10553)
@@ -0,0 +1,56 @@
+/*
+ *  pxml.h
+ *
+ *    Very simple xml plist file parser - header file.
+ *
+ *
+ *  Copyright (c) 2005  Arek Korbik
+ *
+ *  This file is part of XiphQT, the Xiph QuickTime Components.
+ *
+ *  XiphQT is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public
+ *  License as published by the Free Software Foundation; either
+ *  version 2.1 of the License, or (at your option) any later version.
+ *
+ *  XiphQT 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
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with XiphQT; if not, write to the Free Software
+ *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
+ *
+ *
+ *  Last modified: $Id$
+ *
+ */
+
+
+#if !defined(__pxml_h__)
+#define __pxml_h__
+
+#if defined(__APPLE_CC__)
+#include <CoreServices/CoreServices.h>
+#include <CoreFoundation/CoreFoundation.h>
+#else
+#include <CoreServices.h>
+#include <CoreFoundation.h>
+#endif
+
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+
+extern CFDictionaryRef pxml_parse_plist(unsigned char *plist_str, long plist_size);
+
+
+#ifdef __cplusplus
+}
+#endif
+
+
+#endif /* __pxml_h__ */


Property changes on: branches/xiph-qt/xiph-qt-win32/build-win32/pxml.h
___________________________________________________________________
Name: svn:keywords
   + Id



More information about the commits mailing list