New plmerge tool, small fix in plser.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@6490 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Jonathan Gapen 2000-04-21 05:41:31 +00:00
parent 050c45599e
commit 57d43e571a
3 changed files with 129 additions and 1 deletions

View file

@ -1,3 +1,8 @@
2000-04-20 Jonathan Gapen <jagapen@whitewater.chem.wisc.edu>
* Tools/plmerge.m: New tool to merge property lists.
* Tools/plser.m: Fix error message. (deserialize => serialize)
2000-04-20 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/gdomap.c: Don't do chdir/chroot on sysv - it screws up

123
Tools/plmerge.m Normal file
View file

@ -0,0 +1,123 @@
/* 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/NSArray.h>
#import <Foundation/NSAutoreleasePool.h>
#import <Foundation/NSException.h>
#import <Foundation/NSFileManager.h>
#import <Foundation/NSProcessInfo.h>
#import <Foundation/NSString.h>
int
main(int argc, char** argv)
{
NSAutoreleasePool *pool = [NSAutoreleasePool new];
NSProcessInfo *procinfo;
NSArray *args;
NSString *destName;
NSString *fileContents;
NSMutableDictionary *plist;
unsigned i;
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);
}

View file

@ -50,7 +50,7 @@ main(int argc, char** argv)
if ([args count] <= 1)
{
NSLog(@"No file names given to deserialize.");
NSLog(@"No file names given to serialize.");
}
else
{