mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-25 09:41:15 +00:00
* Tools/pl*.m: added #include <Foundation/Foundation.h> to avoid GNUSTEP Internal Error git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@9386 72102866-910b-0410-8b05-ffd578937521
130 lines
3.8 KiB
Objective-C
130 lines
3.8 KiB
Objective-C
/* This tool merges text property lists into a single property list.
|
|
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,
|
|
59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
*/
|
|
|
|
#import <Foundation/Foundation.h>
|
|
#import <Foundation/NSArray.h>
|
|
#import <Foundation/NSAutoreleasePool.h>
|
|
#import <Foundation/NSData.h>
|
|
#import <Foundation/NSDictionary.h>
|
|
#import <Foundation/NSException.h>
|
|
#import <Foundation/NSFileManager.h>
|
|
#import <Foundation/NSProcessInfo.h>
|
|
#import <Foundation/NSString.h>
|
|
|
|
int
|
|
main(int argc, char** argv, char **env)
|
|
{
|
|
NSAutoreleasePool *pool;
|
|
NSProcessInfo *procinfo;
|
|
NSArray *args;
|
|
NSString *destName;
|
|
NSString *fileContents;
|
|
NSMutableDictionary *plist;
|
|
unsigned i;
|
|
|
|
#ifdef GS_PASS_ARGUMENTS
|
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
|
#endif
|
|
pool = [NSAutoreleasePool new];
|
|
procinfo = [NSProcessInfo processInfo];
|
|
if (procinfo == nil)
|
|
{
|
|
NSLog(@"plmerge: unable to get process information!");
|
|
[pool release];
|
|
exit(0);
|
|
}
|
|
|
|
args = [procinfo arguments];
|
|
|
|
if ([args count] < 3)
|
|
{
|
|
NSLog(@"Usage: %@ [destination-file] [input-file ...]",
|
|
[procinfo processName]);
|
|
[pool release];
|
|
exit(0);
|
|
}
|
|
|
|
destName = [args objectAtIndex: 1];
|
|
if ([[NSFileManager defaultManager] fileExistsAtPath: destName])
|
|
{
|
|
NS_DURING
|
|
{
|
|
fileContents = [NSString stringWithContentsOfFile: destName];
|
|
plist = [fileContents propertyList];
|
|
}
|
|
NS_HANDLER
|
|
{
|
|
NSLog(@"Parsing '%@' - %@", destName, [localException reason]);
|
|
}
|
|
NS_ENDHANDLER
|
|
|
|
if ((plist == nil) || ![plist isKindOfClass: [NSDictionary class]])
|
|
{
|
|
NSLog(@"The destination property list must contain an NSDictionary.");
|
|
[pool release];
|
|
exit(1);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
plist = [NSMutableDictionary new];
|
|
}
|
|
|
|
for (i = 2; i < [args count]; i++)
|
|
{
|
|
NSString *filename = [args objectAtIndex: i];
|
|
NSString *key;
|
|
id object;
|
|
|
|
NS_DURING
|
|
{
|
|
fileContents = [NSString stringWithContentsOfFile: filename];
|
|
object = [fileContents propertyList];
|
|
}
|
|
NS_HANDLER
|
|
{
|
|
NSLog(@"Parsing '%@' - %@", filename, [localException reason]);
|
|
}
|
|
NS_ENDHANDLER
|
|
|
|
if ([[filename pathExtension] isEqualToString: @"plist"])
|
|
key = [filename stringByDeletingPathExtension];
|
|
|
|
if (object == nil)
|
|
NSLog(@"Parsing '%@' - nil property list", filename);
|
|
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
|
|
NSLog(@"Parsing '%@' - unexpected class - %@",
|
|
filename, [[object class] description]);
|
|
}
|
|
|
|
if ([plist writeToFile: destName atomically: YES] == NO)
|
|
NSLog(@"Error writing property list to '%@'", destName);
|
|
|
|
[pool release];
|
|
exit(0);
|
|
}
|