libs-base/Tools/plser.m
rfm e263f96f16 more header reorganisation
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@29731 72102866-910b-0410-8b05-ffd578937521
2010-02-25 08:36:34 +00:00

97 lines
2.4 KiB
Objective-C

/** This tool converts a text property list to a serialised representation.
Copyright (C) 1999 Free Software Foundation, Inc.
Written by: Richard Frith-Macdonald <richard@brainstorm.co.uk>
Created: may 1999
This file is part of the GNUstep Project
This program 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 3 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 program; see the file COPYINGv3.
If not, write to the Free Software Foundation,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#import "common.h"
#import "Foundation/NSArray.h"
#import "Foundation/NSData.h"
#import "Foundation/NSException.h"
#import "Foundation/NSProcessInfo.h"
#import "Foundation/NSUserDefaults.h"
#import "Foundation/NSFileHandle.h"
#import "Foundation/NSAutoreleasePool.h"
/** <p> This tool converts a text property list to a binary serialised
representation.
</p> */
int
main(int argc, char** argv, char **env)
{
NSAutoreleasePool *pool;
NSProcessInfo *proc;
NSArray *args;
unsigned i;
#ifdef GS_PASS_ARGUMENTS
GSInitializeProcess(argc, argv, env);
#endif
pool = [NSAutoreleasePool new];
proc = [NSProcessInfo processInfo];
if (proc == nil)
{
NSLog(@"plser: unable to get process information!\n");
[pool release];
exit(EXIT_SUCCESS);
}
args = [proc arguments];
if ([args count] <= 1)
{
GSPrintf(stderr, @"No file names given to serialize.\n");
}
else
{
for (i = 1; i < [args count]; i++)
{
NSString *file = [args objectAtIndex: i];
NS_DURING
{
NSData *myData;
NSString *myString;
id result;
myString = [NSString stringWithContentsOfFile: file];
result = [myString propertyList];
if (result == nil)
GSPrintf(stderr, @"Loading '%@' - nil property list\n", file);
else
{
NSFileHandle *out;
myData = [NSSerializer serializePropertyList: result];
out = [NSFileHandle fileHandleWithStandardOutput];
[out writeData: myData];
[out synchronizeFile];
}
}
NS_HANDLER
{
GSPrintf(stderr, @"Loading '%@' - %@\n", file,
[localException reason]);
}
NS_ENDHANDLER
}
}
[pool release];
return 0;
}