2004-03-29 03:37:46 +00:00
|
|
|
/** This tool merges text property lists into a single property list.
|
2000-04-21 05:41:31 +00:00
|
|
|
Copyright (C) 2000 Free Software Foundation, Inc.
|
|
|
|
|
|
|
|
Written by: Jonathan Gapen <jagapen@whitewater.chem.wisc.edu>
|
|
|
|
Created: April 2000
|
|
|
|
|
|
|
|
This file is part of the GNUstep Project
|
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or
|
|
|
|
modify it under the terms of the GNU General Public License
|
|
|
|
as published by the Free Software Foundation; either version 2
|
|
|
|
of the License, or (at your option) any later version.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public
|
|
|
|
License along with this library; see the file COPYING.LIB.
|
|
|
|
If not, write to the Free Software Foundation,
|
2005-05-22 03:32:16 +00:00
|
|
|
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2000-04-21 05:41:31 +00:00
|
|
|
|
|
|
|
*/
|
|
|
|
|
2004-01-15 04:07:08 +00:00
|
|
|
#include "config.h"
|
2001-10-13 08:51:54 +00:00
|
|
|
#include <Foundation/Foundation.h>
|
|
|
|
#include <Foundation/NSArray.h>
|
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
|
|
|
#include <Foundation/NSData.h>
|
|
|
|
#include <Foundation/NSDictionary.h>
|
|
|
|
#include <Foundation/NSException.h>
|
|
|
|
#include <Foundation/NSFileManager.h>
|
|
|
|
#include <Foundation/NSProcessInfo.h>
|
|
|
|
#include <Foundation/NSString.h>
|
2004-01-15 04:07:08 +00:00
|
|
|
#ifdef NeXT_Foundation_LIBRARY
|
|
|
|
#include "GNUstepBase/GSCategories.h"
|
|
|
|
#include "GNUstepBase/GSObjCRuntime.h"
|
|
|
|
#endif
|
2000-04-21 05:41:31 +00:00
|
|
|
|
2004-03-29 03:37:46 +00:00
|
|
|
|
|
|
|
/** <p> This tool merges text property lists into a single property list.
|
|
|
|
</p> */
|
2000-04-21 05:41:31 +00:00
|
|
|
int
|
2000-06-29 03:51:06 +00:00
|
|
|
main(int argc, char** argv, char **env)
|
2000-04-21 05:41:31 +00:00
|
|
|
{
|
2000-06-29 03:51:06 +00:00
|
|
|
NSAutoreleasePool *pool;
|
2000-04-21 05:41:31 +00:00
|
|
|
NSProcessInfo *procinfo;
|
|
|
|
NSArray *args;
|
|
|
|
NSString *destName;
|
|
|
|
NSString *fileContents;
|
2003-07-28 16:50:05 +00:00
|
|
|
NSMutableDictionary *plist = nil;
|
2000-04-21 05:41:31 +00:00
|
|
|
unsigned i;
|
|
|
|
|
2000-06-29 03:51:06 +00:00
|
|
|
#ifdef GS_PASS_ARGUMENTS
|
|
|
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
|
|
|
#endif
|
|
|
|
pool = [NSAutoreleasePool new];
|
2000-04-21 05:41:31 +00:00
|
|
|
procinfo = [NSProcessInfo processInfo];
|
|
|
|
if (procinfo == nil)
|
|
|
|
{
|
|
|
|
NSLog(@"plmerge: unable to get process information!");
|
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2000-04-21 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
args = [procinfo arguments];
|
|
|
|
|
|
|
|
if ([args count] < 3)
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Usage: %@ [destination-file] [input-file ...]\n",
|
|
|
|
[procinfo processName]);
|
2000-04-21 05:41:31 +00:00
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2000-04-21 05:41:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
destName = [args objectAtIndex: 1];
|
|
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath: destName])
|
|
|
|
{
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
fileContents = [NSString stringWithContentsOfFile: destName];
|
|
|
|
plist = [fileContents propertyList];
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - %@\n", destName,
|
|
|
|
[localException reason]);
|
2000-04-21 05:41:31 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]])
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr,
|
|
|
|
@"The destination property list must contain an NSDictionary.\n");
|
2000-04-21 05:41:31 +00:00
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_FAILURE);
|
2000-04-21 05:41:31 +00:00
|
|
|
}
|
2004-07-03 08:46:16 +00:00
|
|
|
plist = [plist mutableCopy];
|
2000-04-21 05:41:31 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
plist = [NSMutableDictionary new];
|
|
|
|
}
|
|
|
|
|
|
|
|
for (i = 2; i < [args count]; i++)
|
|
|
|
{
|
|
|
|
NSString *filename = [args objectAtIndex: i];
|
2002-06-17 15:47:09 +00:00
|
|
|
NSString *key = filename;
|
|
|
|
id object = nil;
|
2000-04-21 05:41:31 +00:00
|
|
|
|
|
|
|
NS_DURING
|
|
|
|
{
|
|
|
|
fileContents = [NSString stringWithContentsOfFile: filename];
|
|
|
|
object = [fileContents propertyList];
|
|
|
|
}
|
|
|
|
NS_HANDLER
|
|
|
|
{
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - %@\n", filename,
|
|
|
|
[localException reason]);
|
2000-04-21 05:41:31 +00:00
|
|
|
}
|
|
|
|
NS_ENDHANDLER
|
|
|
|
|
|
|
|
if ([[filename pathExtension] isEqualToString: @"plist"])
|
2002-06-17 15:47:09 +00:00
|
|
|
{
|
|
|
|
key = [filename stringByDeletingPathExtension];
|
|
|
|
}
|
2000-04-21 05:41:31 +00:00
|
|
|
|
|
|
|
if (object == nil)
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - nil property list\n", filename);
|
2000-04-21 05:41:31 +00:00
|
|
|
else if ([object isKindOfClass: [NSArray class]] == YES)
|
|
|
|
[plist setObject: object forKey: key];
|
|
|
|
else if ([object isKindOfClass: [NSData class]] == YES)
|
|
|
|
[plist setObject: object forKey: key];
|
|
|
|
else if ([object isKindOfClass: [NSDictionary class]] == YES)
|
|
|
|
[plist addEntriesFromDictionary: object];
|
|
|
|
else if ([object isKindOfClass: [NSString class]] == YES)
|
|
|
|
[plist setObject: object forKey: key];
|
|
|
|
else
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Parsing '%@' - unexpected class - %@\n",
|
2000-04-21 05:41:31 +00:00
|
|
|
filename, [[object class] description]);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ([plist writeToFile: destName atomically: YES] == NO)
|
2002-10-11 09:14:14 +00:00
|
|
|
GSPrintf(stderr, @"Error writing property list to '%@'\n", destName);
|
2000-04-21 05:41:31 +00:00
|
|
|
|
2004-07-03 08:46:16 +00:00
|
|
|
RELEASE(plist);
|
2000-04-21 05:41:31 +00:00
|
|
|
[pool release];
|
2003-05-12 20:42:47 +00:00
|
|
|
exit(EXIT_SUCCESS);
|
2000-04-21 05:41:31 +00:00
|
|
|
}
|