Another overhaul of nib2cib.

- Added support for userland NS classes.
- Added support for auxiliary themes.
- NSView should be writing _themeClass, otherwise custom themed classes do not get the correct _themeClass when unarchived.
- Added support for stored options, this is critical. For example, if you are using custom frameworks, you have to ensure they are loaded during automatic nib2cib'ing that occurs when building an app or using xcodecapp. Stored options makes this easy to do.
- Finally did the right thing and made nib2cib into an Objective-J class.
This commit is contained in:
Aparajita Fishman committed 2011-06-04 16:07:00 -07:00
1 parent d038c50531
commit 94df530580
6 files changed
+1045 -733

No files matched your search

+7 -8
View File
@@ -40,18 +40,16 @@ ConverterConversionException = @"ConverterConversionException";
@implementation Converter : CPObject
{
CPString inputPath @accessors(readonly);
CPString outputPath @accessors;
CPString resourcesPath @accessors;
NibFormat format @accessors(readonly);
CPArray themes @accessors(readonly);
CPString inputPath @accessors(readonly);
CPString outputPath @accessors;
CPString resourcesPath @accessors;
NibFormat format @accessors(readonly);
CPArray themes @accessors(readonly);
CPArray frameworkNSClasses @accessors;
}
+ (Converter)sharedConverter
{
if (!SharedConverter)
SharedConverter = [[Converter alloc] init];
return SharedConverter;
}
@@ -61,6 +59,7 @@ ConverterConversionException = @"ConverterConversionException";
if (self)
{
SharedConverter = self;
inputPath = aPath;
format = nibFormat;
themes = themeList;
+40 -2
View File
@@ -1,3 +1,26 @@
/*
* NSClassSwapper.j
* nib2cib
*
* Created by Francisco Tolmasky
* Copyright 2009, 280 North, Inc.
*
* This library 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.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import "Converter.j"
var NSClassSwapperClassNames = {},
NSClassSwapperOriginalClassNames = {};
@@ -16,7 +39,13 @@ var _CPCibClassSwapperClassNameKey = @"_CPCibClassSwapperClassNameKey",
if (!swapperClass)
{
var originalClass = objj_lookUpClass(anOriginalClassName);
// If this is a framework NS class, call its KVC methods directly
var nsClass = nil;
if ([[[Converter sharedConverter] frameworkNSClasses] containsObject:aClassName])
nsClass = objj_lookUpClass("NS_" + aClassName);
var originalClass = nsClass || objj_lookUpClass(anOriginalClassName);
swapperClass = objj_allocateClassPair(originalClass, swapperClassName);
@@ -46,7 +75,16 @@ var _CPCibClassSwapperClassNameKey = @"_CPCibClassSwapperClassNameKey",
{
objj_msgSendSuper({super_class:originalClass, receiver:self}, _cmd, aCoder);
// FIXME: map class name as well?
// If this is a custom NS class, lookup its archiver class so that
// the correct class is swapped during unarchiving.
if (nsClass)
{
var classForArchiver = objj_msgSend(nsClass, "classForKeyedArchiver");
if (classForArchiver)
aClassName = [classForArchiver className];
}
[aCoder encodeObject:aClassName forKey:_CPCibClassSwapperClassNameKey];
[aCoder encodeObject:CP_NSMapClassName(anOriginalClassName) forKey:_CPCibClassSwapperOriginalClassNameKey];
}, "");
+1
View File
@@ -68,6 +68,7 @@ var NSViewAutoresizingMask = 0x3F,
_isHidden = vFlags & NSViewHiddenMask;
_opacity = 1.0;//[aCoder decodeIntForKey:CPViewOpacityKey];
_themeClass = [self themeClass];
_themeAttributes = {};
_themeState = CPThemeStateNormal;
[self _loadThemeAttributes];
+942
View File
@@ -0,0 +1,942 @@
/*
* Nib2Cib.j
* nib2cib
*
* Created by Francisco Tolmasky and Aparajita Fishman.
* Copyright 2008, 280 North, Inc.
*
* This library 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.
*
* This library 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 this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import <BlendKit/BlendKit.j>
@import "NSFoundation.j"
@import "NSAppKit.j"
@import "Nib2CibKeyedUnarchiver.j"
@import "Converter.j"
var FILE = require("file"),
OS = require("os"),
SYS = require("system"),
FileList = require("jake").FileList,
stream = require("narwhal/term").stream,
StaticResource = require("objective-j").StaticResource,
DefaultTheme = "Aristo",
BuildTypes = ["Debug", "Release"],
DefaultFile = "MainMenu",
AllowedStoredOptionsRe = new RegExp("^(defaultTheme|auxThemes|verbosity|quiet|frameworks|format)$");
ArgsRe = /"[^\"]+"|'[^\']+'|\S+/g;
@implementation Nib2Cib : CPObject
{
CPArray commandLineArgs;
JSObject parser;
JSObject nibInfo;
CPString appDirectory;
CPString resourcesDirectory;
CPDictionary infoPlist;
CPArray frameworkNSClasses;
}
- (id)initWithArgs:(CPArray)theArgs
{
self = [super init];
if (self)
{
commandLineArgs = theArgs;
parser = new (require("narwhal/args").Parser)();
nibInfo = {};
appDirectory = @"";
resourcesDirectory = @"";
infoPlist = [CPDictionary dictionary];
frameworkNSClasses = [];
}
return self;
}
- (void)run
{
try
{
var options = [self parseOptionsFromArgs:commandLineArgs];
[self setLogLevel:options.quiet ? -1 : options.verbosity];
if (options.watch)
[self watchWithOptions:options];
else
[self convertWithOptions:options inputFile:nil];
}
catch (anException)
{
CPLog.fatal([self exceptionReason:anException]);
OS.exit(1);
}
}
- (BOOL)convertWithOptions:(JSObject)options inputFile:(CPString)inputFile
{
try
{
inputFile = inputFile || [self getInputFile:options.args];
[self getAppAndResourceDirectoriesFromInputFile:inputFile options:options];
if (options.readStoredOptions)
{
options = [self mergeOptionsWithStoredOptions:options inputFile:inputFile];
[self setLogLevel:options.quiet ? -1 : options.verbosity];
}
if (!options.quiet && options.verbosity > 0)
[self printVersion];
var outputFile = [self getOutputFileFromInputFile:inputFile args:options.args],
configInfo = [self readConfigFile:options.configFile || @"" inputFile:inputFile];
infoPlist = configInfo.plist;
if (infoPlist)
{
var systemFontFace = [infoPlist valueForKey:@"CPSystemFontFace"];
if (systemFontFace)
[CPFont setSystemFontFace:systemFontFace];
var systemFontSize = [infoPlist valueForKey:@"CPSystemFontSize"];
if (systemFontSize)
[CPFont setSystemFontSize:parseFloat(systemFontSize, 10)];
}
var themeList = [self getThemeList:options],
themes = [self loadThemesFromList:themeList];
CPLog.info("\n-------------------------------------------------------------");
CPLog.info("Input : " + inputFile);
CPLog.info("Output : " + outputFile);
CPLog.info("Format : " + ["Auto", "Mac", "iPhone"][options.format]);
CPLog.info("Application : " + appDirectory);
CPLog.info("Resources : " + resourcesDirectory);
CPLog.info("Frameworks : " + (options.frameworks || ""));
CPLog.info("Default theme : " + themeList[0]);
CPLog.info("Aux themes : " + themeList.slice(1).join(", "));
CPLog.info("Config file : " + (configInfo.path || ""));
CPLog.info("System Font : " + [CPFont systemFontSize] + "px " + [CPFont systemFontFace]);
CPLog.info("-------------------------------------------------------------\n");
var converter = [[Converter alloc] initWithInputPath:inputFile
format:options.format
themes:themes];
[converter setOutputPath:outputFile];
[converter setResourcesPath:resourcesDirectory];
var loadFrameworksCallback = function()
{
[converter setFrameworkNSClasses:frameworkNSClasses];
[converter convert];
};
[self loadFrameworks:options.frameworks verbosity:options.verbosity callback:loadFrameworksCallback];
return YES;
}
catch (anException)
{
CPLog.fatal([self exceptionReason:anException]);
return NO;
}
}
- (void)watchWithOptions:(JSObject)options
{
var verbosity = options.quiet ? -1 : options.verbosity,
watchDir = options.args[0];
if (!watchDir)
watchDir = FILE.canonical(FILE.isDirectory("Resources") ? "Resources" : ".");
else
{
watchDir = FILE.canonical(watchDir);
if (FILE.basename(watchDir) !== "Resources")
{
var path = FILE.join(watchDir, "Resources");
if (FILE.isDirectory(path))
watchDir = path;
}
}
if (!FILE.isDirectory(watchDir))
[self failWithMessage:@"Cannot find the directory: " + watchDir];
// Turn on info messages
[self setLogLevel:1];
var nibs = new FileList(FILE.join(watchDir, "*.[nx]ib")).items(),
count = nibs.length;
// First time through only IB files with no corresponding cib
// or a cib with an earlier or equal mtime are converted.
while (count--)
{
var nib = nibs[count],
cib = nib.substr(0, nib.length - 4) + ".cib";
if (FILE.exists(cib) && (FILE.mtime(nib) - FILE.mtime(cib)) <= 0)
nibInfo[nib] = FILE.mtime(nib);
}
CPLog.info("Watching: " + CPLogColorize(watchDir, "debug"));
CPLog.info("Press Control-C to stop...");
while (true)
{
var modifiedNibs = [self getModifiedNibsInDirectory:watchDir];
for (var i = 0; i < modifiedNibs.length; ++i)
{
var action = modifiedNibs[i][0],
nib = modifiedNibs[i][1],
label = action === "add" ? "Added" : "Modified",
level = action === "add" ? "info" : "debug";
CPLog.info(">> %s: %s", CPLogColorize(label, level), nib);
// Don't convert an add if there is an existing cib with a later mtime
if (action === "add")
{
var cib = nib.substr(0, nib.length - 4) + ".cib";
if (FILE.exists(cib) && (FILE.mtime(nib) - FILE.mtime(cib)) < 0)
continue;
}
// Let the converter log however the user configured it
[self setLogLevel:verbosity];
var success = [self convertWithOptions:options inputFile:nib];
[self setLogLevel:1];
if (success)
{
if (verbosity > 0)
stream.print();
else
CPLog.warn("Conversion successful");
}
}
OS.sleep(1);
}
}
- (JSObject)parseOptionsFromArgs:(CPArray)theArgs
{
parser.usage("[--watch DIRECTORY] [INPUT_FILE [OUTPUT_FILE]]");
parser.option("--watch", "watch")
.set(true)
.help("Ask nib2cib to watch a directory for changes");
parser.option("-R", "resourcesDir")
.set()
.displayName("directory")
.help("Set the Resources directory, usually unnecessary as it is inferred from the input path");
parser.option("--default-theme", "defaultTheme")
.set()
.displayName("name")
.help("Specify a custom default theme which is not set in your Info.plist");
parser.option("-t", "--theme", "auxThemes")
.push()
.displayName("name")
.help("An additional theme loaded dynamically by your application");
parser.option("--config", "configFile")
.set()
.displayName("path")
.help("A path to an Info.plist file from which the system font and/or size can be retrieved");
parser.option("-v", "--verbose", "verbosity")
.inc()
.help("Increase verbosity level");
parser.option("-q", "--quiet", "quiet")
.set(true)
.help("No output");
parser.option("-F", "--framework", "frameworks")
.push()
.help("Add a framework to load");
parser.option("--no-stored-options", "readStoredOptions")
.set(false)
.def(true)
.help("Do not read stored options");
parser.option("--mac", "format")
.set(NibFormatMac)
.def(NibFormatUndetermined)
.help("Set format to Mac");
parser.option("--version", "showVersion")
.action(function() { [self printVersionAndExit]; })
.help("Show the version of nib2cib and quit");
parser.helpful();
var options = parser.parse(theArgs, null, null, true);
if (options.args.length > 2)
{
parser.printUsage(options);
OS.exit(0);
}
return options;
}
- (JSObject)mergeOptionsWithStoredOptions:(JSObject)options inputFile:(CPString)inputFile
{
// We have to clone options
var userOptions = [self readStoredOptionsAtPath:FILE.join(SYS.env["HOME"], ".nib2cibconfig")],
appOptions = [self readStoredOptionsAtPath:FILE.join(appDirectory, "nib2cib.conf")],
filename = FILE.basename(inputFile, FILE.extension(inputFile)) + ".conf",
fileOptions = [self readStoredOptionsAtPath:FILE.join(FILE.dirname(inputFile), filename)];
// At this point we have an array of args without the initial command in args[0],
// add the command and parse the options.
userOptions = [self parseOptionsFromArgs:[options.command].concat(userOptions)];
appOptions = [self parseOptionsFromArgs:[options.command].concat(appOptions)];
fileOptions = [self parseOptionsFromArgs:[options.command].concat(fileOptions)];
// The increasing order of precedence is: user -> app -> file -> command line
var mergedOptions = userOptions;
[self mergeOptions:appOptions with:mergedOptions];
[self mergeOptions:fileOptions with:mergedOptions];
[self mergeOptions:options with:mergedOptions];
mergedOptions.args = options.args;
return mergedOptions;
}
- (CPArray)readStoredOptionsAtPath:(CPString)path
{
path = FILE.canonical(path);
if (!FILE.isReadable(path))
return [];
var file = FILE.open(path, "r"),
line = file.readLine(),
matches = line.match(ArgsRe) || [];
file.close();
CPLog.debug("Reading stored options: " + path);
if (matches)
{
for (var i = 0; i < matches.length; ++i)
{
var str = matches[i];
if ((str.charAt(0) === '"' && str.substr(-1) === '"') || (str.charAt(0) === "'" && str.substr(-1) === "'"))
matches[i] = str.substr(1, str.length - 2);
}
return matches;
}
else
return [];
}
- (void)printOptions:options
{
for (option in options)
{
var value = options[option];
if (value)
{
var show = value.length !== undefined ? value.length > 0 : !!value;
if (show)
print(option + ": " + value);
}
}
}
// Merges properties in sourceOptions into targetOptions, overriding properties in targetOptions
- (void)mergeOptions:(JSObject)sourceOptions with:(JSObject)targetOptions
{
for (option in sourceOptions)
{
// Make sure only a supported option is given
if (!AllowedStoredOptionsRe.test(option))
continue;
if (sourceOptions.hasOwnProperty(option))
{
var value = sourceOptions[option];
if (value)
{
var copy = value.length !== undefined ? value.length > 0 : !!value;
if (copy)
targetOptions[option] = value;
}
}
}
}
- (void)setLogLevel:(int)level
{
CPLogUnregister(CPLogPrint);
if (level === 0)
CPLogRegister(CPLogPrint, "warn", logFormatter);
else if (level === 1)
CPLogRegister(CPLogPrint, "info", logFormatter);
else if (level > 1)
CPLogRegister(CPLogPrint, null, logFormatter);
}
- (CPString)getInputFile:(CPArray)theArgs
{
var inputFile = theArgs[0] || DefaultFile,
path = "";
if (!/^.+\.[nx]ib$/.test(inputFile))
{
if (path = [self findInputFile:inputFile extension:@".xib"])
inputFile = path;
else if (path = [self findInputFile:inputFile extension:@".nib"])
inputFile = path;
else
[self failWithMessage:@"Cannot find the input file (.xib or .nib): " + FILE.canonical(inputFile)];
}
else if (path = [self findInputFile:inputFile extension:nil])
inputFile = path;
else
[self failWithMessage:@"Could not read the input file: " + FILE.canonical(inputFile)];
return FILE.canonical(inputFile);
}
- (void)findInputFile:(CPString)inputFile extension:(CPString)extension
{
var path = inputFile;
if (extension)
path += extension;
if (FILE.isReadable(path))
return path;
if (FILE.basename(FILE.dirname(inputFile)) !== "Resources" && FILE.isDirectory("Resources"))
{
path = FILE.resolve(path, FILE.join("Resources", FILE.basename(path)));
if (FILE.isReadable(path))
return path;
}
return null;
}
- (void)getAppAndResourceDirectoriesFromInputFile:(CPString)inputFile options:(JSObject)options
{
appDirectory = resourcesDirectory = "";
if (options.resourcesDir)
{
var path = FILE.canonical(options.resourcesDir);
if (!FILE.isDirectory(path))
[self failWithMessage:@"Cannot read resources at: " + path];
resourcesDirectory = path;
}
var parentDir = FILE.dirname(inputFile);
if (FILE.basename(parentDir) === "Resources")
{
appDirectory = FILE.dirname(parentDir);
resourcesDirectory = resourcesDirectory || parentDir;
}
else
{
appDirectory = parentDir;
if (!resourcesDirectory)
{
var path = FILE.join(appDirectory, "Resources");
if (FILE.isDirectory(path))
resourcesDirectory = path;
}
}
}
- (CPString)getOutputFileFromInputFile:(CPString)inputFile args:(CPArray)theArgs
{
var outputFile = null;
if (theArgs.length > 1)
{
outputFile = theArgs[1];
if (!/^.+\.cib$/.test(outputFile))
outputFile += ".cib";
}
else
outputFile = FILE.join(FILE.dirname(inputFile), FILE.basename(inputFile, FILE.extension(inputFile))) + ".cib";
outputFile = FILE.canonical(outputFile);
if (!FILE.isWritable(FILE.dirname(outputFile)))
[self failWithMessage:@"Cannot write the output file at: " + outputFile];
return outputFile;
}
- (void)loadFrameworks:(CPArray)frameworks verbosity:(int)verbosity callback:(JSObject)aCallback
{
if (!frameworks || frameworks.length === 0)
return aCallback();
var returnPath = function(path) { return path; };
frameworks.forEach(function(aFramework)
{
[self setLogLevel:verbosity];
var frameworkPath = nil;
// If it is just a name with no path components, try to locate it
if (aFramework.indexOf("/") === -1)
{
frameworkPath = [self findInCappBuild:aFramework isDirectory:YES callback:returnPath];
if (!frameworkPath)
frameworkPath = [self findInInstalledFrameworks:aFramework isDirectory:YES callback:returnPath];
if (!frameworkPath)
frameworkPath = [self findInFrameworks:FILE.join(appDirectory, "Frameworks")
path:aFramework
isDirectory:YES
callback:returnPath];
}
else
frameworkPath = FILE.canonical(aFramework);
if (!frameworkPath)
[self failWithMessage:@"Cannot find the framework \"" + aFramework + "\""];
CPLog.debug("Loading framework: " + frameworkPath);
try
{
// CPBundle is a bit loquacious with logging, we will defer
// logging its exceptions till later.
[self setLogLevel:-1];
var frameworkBundle = [[CPBundle alloc] initWithPath:frameworkPath];
[frameworkBundle loadWithDelegate:nil];
[self setLogLevel:verbosity];
// See if the framework defines NS classes
var nsClasses = [frameworkBundle objectForInfoDictionaryKey:@"IBClasses"] || [];
for (var i = 0; i < nsClasses.length; ++i)
{
var filename = "NS_" + nsClasses[i] + ".j";
objj_importFile(FILE.join(frameworkPath, filename), YES);
CPLog.debug("Imported framework NS class: %s", filename);
frameworkNSClasses.push(nsClasses[i]);
}
}
finally
{
[self setLogLevel:verbosity];
}
require("browser/timeout").serviceTimeouts();
});
aCallback();
}
- (CPArray)getThemeList:(JSObject)options
{
var defaultTheme = options.defaultTheme;
if (!defaultTheme)
defaultTheme = [infoPlist valueForKey:@"CPDefaultTheme"];
if (!defaultTheme)
defaultTheme = [self getAppKitDefaultThemeName];
var themes = [CPSet setWithObject:defaultTheme];
if (options.auxThemes)
[themes addObjectsFromArray:options.auxThemes];
var auxThemes = infoPlist.valueForKey("CPAuxiliaryThemes");
if (auxThemes)
[themes addObjectsFromArray:auxThemes];
// Now remove the default theme, get the list as an array, and insert the default at the beginning
[themes removeObject:defaultTheme];
var allThemes = [themes allObjects];
[allThemes insertObject:defaultTheme atIndex:0];
return allThemes;
}
// Returns undefined if $CAPP_BUILD is not defined, false if path cannot be found in $CAPP_BUILD
- (id)findInCappBuild:(CPString)path isDirectory:(BOOL)isDirectory callback:(JSObject)callback
{
var cappBuild = SYS.env["CAPP_BUILD"];
if (!cappBuild)
return undefined;
cappBuild = FILE.canonical(cappBuild);
if (FILE.isDirectory(cappBuild))
{
var result = null;
for (var i = 0; i < BuildTypes.length && !result; ++i)
{
var findPath = FILE.join(cappBuild, BuildTypes[i], path);
if ((isDirectory && FILE.isDirectory(findPath)) || (!isDirectory && FILE.exists(findPath)))
result = callback(findPath);
}
return result;
}
else
return false;
}
- (id)findInInstalledFrameworks:(CPString)path isDirectory:(BOOL)isDirectory callback:(JSObject)callback
{
// NOTE: It's safe to use '/' directly in the path, we're guaranteed to be on a Mac
return [self findInFrameworks:FILE.canonical(FILE.join(SYS.prefix, "packages/cappuccino/Frameworks"))
path:path
isDirectory:isDirectory
callback:callback];
}
- (id)findInFrameworks:(CPString)frameworksPath path:(CPString)path isDirectory:(BOOL)isDirectory callback:(JSObject)callback
{
var result = null,
findPath = FILE.join(frameworksPath, "Debug", path);
if ((isDirectory && FILE.isDirectory(findPath)) || (!isDirectory && FILE.exists(findPath)))
result = callback(findPath);
if (!result)
{
findPath = FILE.join(frameworksPath, path);
if ((isDirectory && FILE.isDirectory(findPath)) || (!isDirectory && FILE.exists(findPath)))
result = callback(findPath);
}
return result;
}
- (CPString)getAppKitDefaultThemeName
{
var callback = function(path) { return [self themeNameFromPropertyList:path]; },
themeName = [self findInCappBuild:@"AppKit/Info.plist" isDirectory:NO callback:callback];
if (!themeName)
themeName = [self findInInstalledFrameworks:@"AppKit/Info.plist" isDirectory:NO callback:callback];
return themeName || DefaultTheme;
}
- (CPString)themeNameFromPropertyList:(CPString)path
{
if (!FILE.isReadable(path))
return nil;
var themeName = nil,
plist = CFPropertyList.readPropertyListFromFile(path);
if (plist)
themeName = plist.valueForKey("CPDefaultTheme");
return themeName;
}
- (CPArray)loadThemesFromList:(CPArray)themeList
{
var themes = [];
for (var i = 0; i < themeList.length; ++i)
themes.push([self loadThemeNamed:themeList[i] directory:resourcesDirectory]);
return themes;
}
- (CPTheme)loadThemeNamed:(CPString)themeName directory:(CPString)themeDir
{
if (/^.+\.blend$/.test(themeName))
themeName = themeName.substr(0, themeName.length - ".blend".length);
var blendName = themeName + ".blend",
themePath = "";
if (themeDir)
{
themePath = FILE.join(FILE.canonical(themeDir), blendName);
if (!FILE.isDirectory(themePath))
themePath = themeDir = null;
}
if (!themeDir)
{
var returnPath = function(path) { return path; };
themePath = [self findInCappBuild:blendName isDirectory:YES callback:returnPath];
if (!themePath)
themePath = [self findInInstalledFrameworks:@"AppKit/Resources/" + blendName isDirectory:YES callback:returnPath];
// Last resort, try the cwd
if (!themePath)
{
var path = FILE.canonical(blendName);
if (FILE.isDirectory(path))
themePath = path;
}
}
if (!themePath)
[self failWithMessage:@"Cannot find the theme \"" + themeName + "\""];
return [self readThemeWithName:themeName atPath:themePath];
}
- (CPTheme)readThemeWithName:(CPString)name atPath:(CPString)path
{
var themeBundle = new CFBundle(path);
// By default when we try to load the bundle it will use the CommonJS environment,
// but we want the Browser environment. So we override mostEligibleEnvironment().
themeBundle.mostEligibleEnvironment = function() { return "Browser"; }
themeBundle.load();
var keyedThemes = themeBundle.valueForInfoDictionaryKey("CPKeyedThemes");
if (!keyedThemes)
[self failWithMessage:@"Could not find the keyed themes in the theme: " + path];
var index = keyedThemes.indexOf(name + ".keyedtheme");
if (index < 0)
[self failWithMessage:@"Could not find the main theme data (" + name + ".keyedtheme" + ") in the theme: " + path];
// Load the keyed theme data, making sure to resolve it
var resourcePath = themeBundle.pathForResource(keyedThemes[index]),
themeData = new CFMutableData();
themeData.setRawString(StaticResource.resourceAtURL(new CFURL(resourcePath), true).contents());
var theme = [CPKeyedUnarchiver unarchiveObjectWithData:themeData];
if (!theme)
[self failWithMessage:@"Could not unarchive the theme at: " + path];
CPLog.debug("Loaded theme: " + path);
return theme;
}
- (JSObject)readConfigFile:(CPString)configFile inputFile:(CPString)inputFile
{
var configPath = null,
path;
// First see if the user passed a config file path
if (configFile)
{
path = FILE.canonical(configFile);
if (!FILE.isReadable(path))
[self failWithMessage:@"Cannot find the config file: " + path];
configPath = path;
}
else
{
path = FILE.join(appDirectory, "Info.plist");
if (FILE.isReadable(path))
configPath = path;
}
var plist = null;
if (configPath)
{
var plist = FILE.read(configPath);
if (!plist)
[self failWithMessage:@"Could not read the Info.plist at: " + configPath];
plist = CFPropertyList.propertyListFromString(plist);
if (!plist)
[self failWithMessage:@"Could not parse the Info.plist at: " + configPath];
}
return {path: configPath, plist: plist};
}
- (CPArray)getModifiedNibsInDirectory:(CPString)path
{
var nibs = new FileList(FILE.join(path, "*.[nx]ib")).items(),
count = nibs.length,
newNibInfo = {},
modifiedNibs = [];
while (count--)
{
var nib = nibs[count];
newNibInfo[nib] = FILE.mtime(nib);
if (!nibInfo.hasOwnProperty(nib))
modifiedNibs.push(["add", nib]);
else
{
if (newNibInfo[nib] - nibInfo[nib] !== 0)
modifiedNibs.push(["mod", nib]);
// Remove matching nibs so that we leave
// deleted nibs in nibInfo.
delete nibInfo[nib];
}
}
for (var nib in nibInfo)
if (nibInfo.hasOwnProperty(nib))
CPLog.info(">> %s: %s", CPLogColorize("Deleted", "warn"), nib);
nibInfo = newNibInfo;
return modifiedNibs;
}
- (void)printVersionAndExit
{
[self printVersion];
OS.exit(0);
}
- (void)printVersion
{
/*
There are two usual possibilities for the location of the nib2cib binary.
If we are executing the installed narwhal binary, the location is:
<narwhal>/packages/cappuccino/bin/nib2cib
If we are executing the built binary, the location is:
<CAPP_BUILD>/Debug|Release/CommonJS/cappuccino/bin/nib2cib
Base on these paths we can locate nib2cib's Info.plist.
*/
var path = FILE.dirname(FILE.dirname(FILE.canonical(SYS.args[0]))),
version = null;
if (FILE.basename(path) === "narwhal")
path = FILE.join(path, "packages", "cappuccino");
path = FILE.join(path, "lib", "nib2cib", "Info.plist");
if (FILE.isReadable(path))
{
var plist = FILE.read(path);
if (!plist)
return;
plist = CFPropertyList.propertyListFromString(plist);
if (!plist)
return;
version = plist.valueForKey("CPBundleVersion");
if (version)
stream.print("nib2cib v" + version);
}
if (!version)
stream.print("<No version info available>");
}
- (CPString)exceptionReason:(JSObject)exception
{
if (typeof(exception) === "string")
return exception;
else if (exception.isa && [exception respondsToSelector:@selector(reason)])
return [exception reason];
else
return @"An unknown error occurred";
}
- (void)failWithMessage:(CPString)message
{
[CPException raise:ConverterConversionException reason:message];
}
@end
function logFormatter(aString, aLevel, aTitle)
{
if (aLevel === "info")
return aString;
else
return CPLogColorize(aString, aLevel);
}
+3 -720
View File
@@ -20,728 +20,11 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
@import <Foundation/Foundation.j>
@import <AppKit/AppKit.j>
@import <BlendKit/BlendKit.j>
@import "NSFoundation.j"
@import "NSAppKit.j"
@import "Nib2CibKeyedUnarchiver.j"
@import "Converter.j"
var FILE = require("file"),
OS = require("os"),
SYS = require("system"),
FileList = require("jake").FileList,
stream = require("narwhal/term").stream,
StaticResource = require("objective-j").StaticResource,
DefaultTheme = "Aristo",
BuildTypes = ["Debug", "Release"],
DefaultFile = "MainMenu";
var parser = new (require("narwhal/args").Parser)(),
nibInfo = {},
appDirectory = "",
resourcesDirectory = "";
@import "Nib2Cib.j"
function main(args)
{
try
{
var options = parseOptions(args);
var nib2cib = [[Nib2Cib alloc] initWithArgs:args];
if (options.watch)
watch(options);
else
convert(options);
}
catch (anException)
{
CPLog.fatal(exceptionReason(anException));
OS.exit(1);
}
}
function convert(options, inputFile)
{
try
{
inputFile = inputFile || getInputFile(options.args);
getAppAndResourceDirectoriesFromInputFile(inputFile, options);
var outputFile = getOutputFile(inputFile, options.args),
configInfo = readConfigFile(options.configFile || "", inputFile),
defaultTheme = null;
if (configInfo.plist)
{
var systemFontFace = configInfo.plist.valueForKey("CPSystemFontFace");
if (systemFontFace)
[CPFont setSystemFontFace:systemFontFace];
var systemFontSize = configInfo.plist.valueForKey("CPSystemFontSize");
if (systemFontSize)
[CPFont setSystemFontSize:parseFloat(systemFontSize, 10)];
if (!options.defaultTheme)
defaultTheme = configInfo.plist.valueForKey("CPDefaultTheme");
}
var themeList = getThemeList(defaultTheme || options.defaultTheme, options),
themes = loadThemes(themeList);
CPLog.info("\n-------------------------------------------------------------");
CPLog.info("Input : " + inputFile);
CPLog.info("Output : " + outputFile);
CPLog.info("Format : " + ["Auto", "Mac", "iPhone"][options.format]);
CPLog.info("Application : " + appDirectory);
CPLog.info("Resources : " + resourcesDirectory);
CPLog.info("Frameworks : " + (options.frameworks || ""));
CPLog.info("Default theme : " + themeList[0]);
CPLog.info("Extra themes : " + themeList.slice(1).join(", "));
CPLog.info("Config file : " + (configInfo.path || ""));
CPLog.info("System Font : " + [CPFont systemFontSize] + "px " + [CPFont systemFontFace]);
CPLog.info("-------------------------------------------------------------\n");
var converter = [[Converter alloc] initWithInputPath:inputFile
format:options.format
themes:themes];
[converter setOutputPath:outputFile];
[converter setResourcesPath:resourcesDirectory];
loadFrameworks(options.frameworks, options.verbosity, function()
{
[converter convert];
});
return true;
}
catch (anException)
{
CPLog.fatal(exceptionReason(anException));
return false;
}
}
function watch(options)
{
var verbosity = options.quiet ? -1 : options.verbosity,
watchDir = options.args[0];
if (!watchDir)
watchDir = FILE.canonical(FILE.isDirectory("Resources") ? "Resources" : ".");
else
{
watchDir = FILE.canonical(watchDir);
if (FILE.basename(watchDir) !== "Resources")
{
var path = FILE.join(watchDir, "Resources");
if (FILE.isDirectory(path))
watchDir = path;
}
}
if (!FILE.isDirectory(watchDir))
fail("Cannot find the directory: " + watchDir);
// Turn on info messages
setLogLevel(1);
var nibs = new FileList(FILE.join(watchDir, "*.[nx]ib")).items(),
count = nibs.length;
// First time through only IB files with no corresponding cib
// or a cib with an earlier or equal mtime are converted.
while (count--)
{
var nib = nibs[count],
cib = nib.substr(0, nib.length - 4) + ".cib";
if (FILE.exists(cib) && (FILE.mtime(nib) - FILE.mtime(cib)) <= 0)
nibInfo[nib] = FILE.mtime(nib);
}
CPLog.info("Watching: " + CPLogColorize(watchDir, "debug"));
CPLog.info("Press Control-C to stop...");
while (true)
{
var modifiedNibs = getModifiedNibs(watchDir);
for (var i = 0; i < modifiedNibs.length; ++i)
{
var action = modifiedNibs[i][0],
nib = modifiedNibs[i][1],
label = action === "add" ? "Added" : "Modified",
level = action === "add" ? "info" : "debug";
CPLog.info(">> %s: %s", CPLogColorize(label, level), nib);
// Don't convert an add if there is an existing cib with a later mtime
if (action === "add")
{
var cib = nib.substr(0, nib.length - 4) + ".cib";
if (FILE.exists(cib) && (FILE.mtime(nib) - FILE.mtime(cib)) < 0)
continue;
}
// Let the converter log however the user configured it
setLogLevel(verbosity);
var success = convert(options, nib);
setLogLevel(1);
if (success)
{
if (verbosity > 0)
stream.print();
else
CPLog.warn("Conversion successful");
}
}
OS.sleep(1);
}
}
function parseOptions(args)
{
parser.usage("[--watch DIRECTORY] [INPUT_FILE [OUTPUT_FILE]]");
parser.option("--watch", "watch")
.set(true)
.help("Ask nib2cib to watch a directory for changes");
parser.option("-R", "resourcesDir")
.set()
.displayName("directory")
.help("Set the Resources directory, usually unnecessary as it is inferred from the input path");
parser.option("--default-theme", "defaultTheme")
.set()
.displayName("name")
.help("Specify a custom default theme which is not set in your Info.plist");
parser.option("-t", "--theme", "extraThemes")
.push()
.displayName("name")
.help("An additional theme loaded dynamically by your application");
parser.option("--config", "configFile")
.set()
.displayName("path")
.help("A path to an Info.plist file from which the system font and/or size can be retrieved");
// parser.option("--iphone", "format")
// .set(NibFormatIPhone)
// .help("Set format to iPhone");
parser.option("-v", "--verbose", "verbosity")
.inc()
.help("Increase verbosity level");
parser.option("-q", "--quiet", "quiet")
.set(true)
.help("No output");
parser.option("-F", "framework", "frameworks")
.push()
.help("Add a framework to load");
parser.option("--mac", "format")
.set(NibFormatMac)
.def(NibFormatUndetermined)
.help("Set format to Mac");
parser.option("--version", "showVersion")
.action(printVersionAndExit)
.help("Show the version of nib2cib and quit");
parser.helpful();
var options = parser.parse(args, null, null, true);
if (options.args.length > 2)
{
parser.printUsage(options);
OS.exit(0);
}
setLogLevel(options.quiet ? -1 : options.verbosity);
if (!options.quiet && options.verbosity > 0)
printVersion();
return options;
}
function setLogLevel(level)
{
CPLogUnregister(CPLogPrint);
if (level === 0)
CPLogRegister(CPLogPrint, "warn", logFormatter);
else if (level === 1)
CPLogRegister(CPLogPrint, "info", logFormatter);
else if (level > 1)
CPLogRegister(CPLogPrint, null, logFormatter);
}
function getInputFile(args)
{
var inputFile = args[0] || DefaultFile,
path = "";
if (!/^.+\.[nx]ib$/.test(inputFile))
{
if (path = findInputFile(inputFile, ".xib"))
inputFile = path;
else if (path = findInputFile(inputFile, ".nib"))
inputFile = path;
else
fail("Cannot find the input file (.xib or .nib): " + FILE.canonical(inputFile));
}
else if (path = findInputFile(inputFile))
inputFile = path;
else
fail("Could not read the input file: " + FILE.canonical(inputFile));
return FILE.canonical(inputFile);
}
function findInputFile(inputFile, extension)
{
var path = inputFile;
if (extension)
path += extension;
if (FILE.isReadable(path))
return path;
if (FILE.basename(FILE.dirname(inputFile)) !== "Resources" && FILE.isDirectory("Resources"))
{
path = FILE.resolve(path, FILE.join("Resources", FILE.basename(path)));
if (FILE.isReadable(path))
return path;
}
return null;
}
function getAppAndResourceDirectoriesFromInputFile(inputFile, options)
{
appDirectory = resourcesDirectory = "";
if (options.resourcesDir)
{
var path = FILE.canonical(options.resourcesDir);
if (!FILE.isDirectory(path))
fail("Cannot read resources at: " + path);
resourcesDirectory = path;
}
var parentDir = FILE.dirname(inputFile);
if (FILE.basename(parentDir) === "Resources")
{
appDirectory = FILE.dirname(parentDir);
resourcesDirectory = resourcesDirectory || parentDir;
}
else
{
appDirectory = parentDir;
if (!resourcesDirectory)
{
var path = FILE.join(appDirectory, "Resources");
if (FILE.isDirectory(path))
resourcesDirectory = path;
}
}
}
function getOutputFile(inputFile, args)
{
var outputFile = null;
if (args.length > 1)
{
outputFile = args[1];
if (!/^.+\.cib$/.test(outputFile))
outputFile += ".cib";
}
else
outputFile = FILE.join(FILE.dirname(inputFile), FILE.basename(inputFile, FILE.extension(inputFile))) + ".cib";
outputFile = FILE.canonical(outputFile);
if (!FILE.isWritable(FILE.dirname(outputFile)))
fail("Cannot write the output file at: " + outputFile);
return outputFile;
}
function loadFrameworks(frameworkPaths, verbosity, aCallback)
{
if (!frameworkPaths || frameworkPaths.length === 0)
return aCallback();
frameworkPaths.forEach(function(aFrameworkPath)
{
setLogLevel(verbosity);
CPLog.info("Loading " + aFrameworkPath);
try
{
// CPBundle is a bit loquacious with logging, we will defer
// logging its exceptions till later.
setLogLevel(-1);
var frameworkBundle = [[CPBundle alloc] initWithPath:aFrameworkPath];
[frameworkBundle loadWithDelegate:nil];
}
finally
{
setLogLevel(verbosity);
}
require("browser/timeout").serviceTimeouts();
});
aCallback();
}
function logFormatter(aString, aLevel, aTitle)
{
if (aLevel === "info")
return aString;
else
return CPLogColorize(aString, aLevel);
}
function getThemeList(defaultTheme, options)
{
var themes = [defaultTheme || getAppKitDefaultThemeName()];
if (options.extraThemes)
for (var i = 0; i < options.extraThemes.length; ++i)
if (themes.indexOf(options.extraThemes[i]) < 0)
themes.push(options.extraThemes[i]);
return themes;
}
// Returns undefined if $CAPP_BUILD is not defined, false if path cannot be found in $CAPP_BUILD
function findInCappBuild(path, isDirectory, callback)
{
var cappBuild = SYS.env["CAPP_BUILD"];
if (!cappBuild)
return undefined;
cappBuild = FILE.canonical(cappBuild);
if (FILE.isDirectory(cappBuild))
{
var result = null;
for (var i = 0; i < BuildTypes.length && !result; ++i)
{
var findPath = FILE.join(cappBuild, BuildTypes[i], path);
if ((isDirectory && FILE.isDirectory(findPath)) || (!isDirectory && FILE.exists(findPath)))
result = callback(findPath);
}
return result;
}
else
return false;
}
function findInInstalledFrameworks(path, isDirectory, callback)
{
// NOTE: It's safe to use '/' directly in the path, we're guaranteed to be on a Mac
var frameworks = FILE.canonical(FILE.join(SYS.prefix, "packages/cappuccino/Frameworks")),
result = null,
findPath = FILE.join(frameworks, "Debug", path);
if ((isDirectory && FILE.isDirectory(findPath)) || (!isDirectory && FILE.exists(findPath)))
result = callback(findPath);
if (!result)
{
findPath = FILE.join(frameworks, path);
if ((isDirectory && FILE.isDirectory(findPath)) || (!isDirectory && FILE.exists(findPath)))
result = callback(findPath);
}
return result;
}
function getAppKitDefaultThemeName()
{
var callback = function(path) { return themeNameFromPropertyList(path); },
themeName = findInCappBuild("AppKit/Info.plist", false, callback);
if (!themeName)
themeName = findInInstalledFrameworks("AppKit/Info.plist", false, callback);
return themeName || DefaultTheme;
}
function themeNameFromPropertyList(path)
{
if (!FILE.isReadable(path))
return nil;
var themeName = nil,
plist = CFPropertyList.readPropertyListFromFile(path);
if (plist)
themeName = plist.valueForKey("CPDefaultTheme");
return themeName;
}
function loadThemes(themeList)
{
var themes = [];
for (var i = 0; i < themeList.length; ++i)
themes.push(loadTheme(themeList[i], resourcesDirectory));
return themes;
}
function loadTheme(themeName, themeDir)
{
if (/^.+\.blend$/.test(themeName))
themeName = themeName.substr(0, themeName.length - ".blend".length);
var blendName = themeName + ".blend",
themePath = "";
if (themeDir)
{
themePath = FILE.join(FILE.canonical(themeDir), blendName);
if (!FILE.isDirectory(themePath))
themePath = themeDir = null;
}
if (!themeDir)
{
var returnPath = function(path) { return path; };
themePath = findInCappBuild(blendName, true, returnPath);
if (!themePath)
themePath = findInInstalledFrameworks("AppKit/Resources/" + blendName, true, returnPath);
// Last resort, try the cwd
if (!themePath)
{
var path = FILE.canonical(blendName);
if (FILE.isDirectory(path))
themePath = path;
}
}
if (!themePath)
fail('Cannot find the theme "' + themeName + '"');
return readTheme(themeName, themePath);
}
function readTheme(name, path)
{
var themeBundle = new CFBundle(path);
// By default when we try to load the bundle it will use the CommonJS environment,
// but we want the Browser environment. So we override mostEligibleEnvironment().
themeBundle.mostEligibleEnvironment = function() { return "Browser"; }
themeBundle.load();
var keyedThemes = themeBundle.valueForInfoDictionaryKey("CPKeyedThemes");
if (!keyedThemes)
fail("Could not find the keyed themes in the theme: " + path);
var index = keyedThemes.indexOf(name + ".keyedtheme");
if (index < 0)
fail("Could not find the main theme data (" + name + ".keyedtheme" + ") in the theme: " + path);
// Load the keyed theme data, making sure to resolve it
var resourcePath = themeBundle.pathForResource(keyedThemes[index]),
themeData = new CFMutableData();
themeData.setRawString(StaticResource.resourceAtURL(new CFURL(resourcePath), true).contents());
var theme = [CPKeyedUnarchiver unarchiveObjectWithData:themeData];
if (!theme)
fail("Could not unarchive the theme at: " + path);
CPLog.debug("Loaded theme: " + path);
return theme;
}
function readConfigFile(configFile, inputFile)
{
var configPath = null,
path;
// First see if the user passed a config file path
if (configFile)
{
path = FILE.canonical(configFile);
if (!FILE.isReadable(path))
fail("Cannot find the config file: " + path);
configPath = path;
}
else
{
path = FILE.join(appDirectory, "Info.plist");
if (FILE.isReadable(path))
configPath = path;
}
var plist = null;
if (configPath)
{
var plist = FILE.read(configPath);
if (!plist)
fail("Could not read the Info.plist at: " + configPath);
plist = CFPropertyList.propertyListFromString(plist);
if (!plist)
fail("Could not parse the Info.plist at: " + configPath);
}
return {path: configPath, plist: plist};
}
function getModifiedNibs(path)
{
var nibs = new FileList(FILE.join(path, "*.[nx]ib")).items(),
count = nibs.length,
newNibInfo = {},
modifiedNibs = [];
while (count--)
{
var nib = nibs[count];
newNibInfo[nib] = FILE.mtime(nib);
if (!nibInfo.hasOwnProperty(nib))
modifiedNibs.push(["add", nib]);
else
{
if (newNibInfo[nib] - nibInfo[nib] !== 0)
modifiedNibs.push(["mod", nib]);
// Remove matching nibs so that we leave
// deleted nibs in nibInfo.
delete nibInfo[nib];
}
}
for (var nib in nibInfo)
if (nibInfo.hasOwnProperty(nib))
CPLog.info(">> %s: %s", CPLogColorize("Deleted", "warn"), nib);
nibInfo = newNibInfo;
return modifiedNibs;
}
function printVersionAndExit()
{
printVersion();
OS.exit(0);
}
function printVersion()
{
/*
There are two usual possibilities for the location of the nib2cib binary.
If we are executing the installed narwhal binary, the location is:
<narwhal>/packages/cappuccino/bin/nib2cib
If we are executing the built binary, the location is:
<CAPP_BUILD>/Debug|Release/CommonJS/cappuccino/bin/nib2cib
Base on these paths we can locate nib2cib's Info.plist.
*/
var path = FILE.dirname(FILE.dirname(FILE.canonical(SYS.args[0]))),
version = null;
if (FILE.basename(path) === "narwhal")
path = FILE.join(path, "packages", "cappuccino");
path = FILE.join(path, "lib", "nib2cib", "Info.plist");
if (FILE.isReadable(path))
{
var plist = FILE.read(path);
if (!plist)
return;
plist = CFPropertyList.propertyListFromString(plist);
if (!plist)
return;
version = plist.valueForKey("CPBundleVersion");
if (version)
stream.print("nib2cib v" + version);
}
if (!version)
stream.print("<No version info available>");
}
function exceptionReason(exception)
{
if (typeof(exception) === "string")
return exception;
else if (exception.isa && [exception respondsToSelector:@selector(reason)])
return [exception reason];
else
return "An unknown error occurred";
}
function fail(message)
{
[CPException raise:ConverterConversionException reason:message];
[nib2cib run];
}
+52 -3
View File
@@ -1,6 +1,7 @@
.Dd April 3, 2011
.Os "Cappuccino"
.Dt NIB2CIB 1 "PRM"
.nh
.\"-----------------------------------------------------------------------------------------
.Sh NAME
.\"-----------------------------------------------------------------------------------------
@@ -155,7 +156,7 @@ options, one for each theme that you load.
Themes are searched for in the Resources, $CAPP_BUILD/Debug and
$CAPP_BUILD/Release directories.
.\"-----------------------------------------------------------------------------------------
.Sh "COMMON OPTIONS"
.Sh "OPTIONS"
.\"-----------------------------------------------------------------------------------------
The following options are available in watch mode or single mode:
.Bl -tag -width 4n
@@ -208,7 +209,16 @@ Tells
.Nm
to output nothing. This is useful if you are using
.Nm
in a shell script and are only interested in the return value.
in a shell script and are only interested in the return value. Note that this
option overrides the
.Fl v
option.
.It Fl \-no-stored-options
Tells
.Nm
not to read stored options. See
.Sy Stored Options
below for more information.
.It Fl \-version
Prints the current version of
.Nm
@@ -221,7 +231,46 @@ Displays
usage and options.
.El
.\"-----------------------------------------------------------------------------------------
.Ss "Stored Options"
.\"-----------------------------------------------------------------------------------------
To make it easier to use nib2cib in an automated way, you can store command line options
that will apply to converted xibs/nibs. To store command line options, you enter the
options on a single line into a text file. For example, if you always want to set
"MyTheme" as the default theme, you would create a text file with this line:
.Pp
.D1 --default-theme MyTheme
.Pp
If an option takes a parameter and the parameter contains spaces, it must be enclosed in
single or double quotes. You may store options in the following three places, in increasing
order of precedence:
.Bl -ohang -offset 4n
.It Em ~/.nib2cibconfig
nib2cib options that apply to all nibs converted under your user account.
.It Em <app>/nib2cib.conf
nib2cib options that apply to all nibs in <app>/Resources.
.It Em <app>/Resources/<xib-or-nib-basename>.conf
nib2cib options that apply to a specific xib or nib. For example, if the xib
is called MainMenu.xib, the stored options file would be MainMenu.conf.
.El
.Pp
Each of these files is read in the order listed above, and if it exists, its options
are merged with the previous file's options. Options in later files (more specific)
override options in earlier files (more generic). After all of the stored options
are merged, the command line options are merged in. Thus command line options always
override stored options.
.Pp
Using stored options is especially useful if your xibs/nibs use custom themes or
frameworks. By using stored options, you can avoid remembering (or forgetting!) to
specify the theme or framework every time you invoke
.Nm .
.Pp
To prevent
.Nm
from reading stored options, and thus only use command line options, use the
.Fl \-no-stored-options
option on the command line.
.\"-----------------------------------------------------------------------------------------
.Sh "RETURN VALUES"
.\"-----------------------------------------------------------------------------------------
.Nm
returns 0 for a successful conversion and >0 if an error occurred.
returns 0 for a successful conversion and >0 if an error occurred.