+// ParseXMLFile(fileName)
+//
+// Open and parse the specified file in XML format,
+// and set variables appropriately.
+//
+static void ParseXMLFile(char *fileName)
+{
+ CFPropertyListRef plist;
+ CFURLRef fileURL = NULL;
+ CFStringRef filePath = NULL;
+ CFStringRef errorString = NULL;
+ CFDataRef data = NULL;
+ SInt32 errorCode = 0;
+
+ filePath = CFStringCreateWithCString(kCFAllocatorDefault, fileName, kCFStringEncodingUTF8);
+ if (filePath == NULL) {
+ errx(1, "Could not create file path string");
+ }
+
+ // Create a URL that specifies the file we will create to
+ // hold the XML data.
+ fileURL = CFURLCreateWithFileSystemPath( kCFAllocatorDefault,
+ filePath,
+ kCFURLPOSIXPathStyle,
+ false /* not a directory */ );
+ if (fileURL == NULL) {
+ errx(1, "Could not create file path URL");
+ }
+
+ CFRelease(filePath);
+
+ if (! CFURLCreateDataAndPropertiesFromResource(
+ kCFAllocatorDefault,
+ fileURL,
+ &data,
+ NULL,
+ NULL,
+ &errorCode) || data == NULL ) {
+ errx(1, "Error reading XML file (%d)", (int)errorCode);
+ }
+
+ CFRelease(fileURL);
+
+ plist = CFPropertyListCreateFromXMLData(kCFAllocatorDefault,
+ data,
+ kCFPropertyListImmutable,
+ &errorString);
+
+ CFRelease(data);
+
+ if (plist == NULL) {
+ errx(1, "Error parsing XML file");
+ }
+
+ if (errorString != NULL) {
+ errx(1, "Error parsing XML file: %s", CFStringGetCStringPtr(errorString, kCFStringEncodingUTF8));
+ }
+
+ CFDictionaryApplyFunction(plist, &SetOFVariableFromFile, 0);
+
+ CFRelease(plist);
+}
+