mirror of
https://github.com/gnustep/libs-base.git
synced 2025-04-22 16:33:29 +00:00
Added plget utility for Dennis Leeuw
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22321 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
0812a50d13
commit
841527e634
4 changed files with 123 additions and 2 deletions
|
@ -1,3 +1,9 @@
|
|||
2006-01-17 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Tools/plget.m: New file to extract a string from a plist.
|
||||
* Tools/pldes.1: Include plget
|
||||
* Tools/GNUmakefile: build/install plget.
|
||||
|
||||
2006-01-15 Richard Frith-Macdonald <rfm@gnu.org>
|
||||
|
||||
* Source/win32/NSMessagePortNameServerWin32.m:
|
||||
|
|
|
@ -52,7 +52,7 @@ ifeq ($(add),yes)
|
|||
TOOL_NAME = autogsdoc cvtenc plmerge sfparse xmlparse
|
||||
else
|
||||
TOOL_NAME = autogsdoc cvtenc gdnc gspath defaults pl plmerge \
|
||||
plparse sfparse pldes plser pl2link xmlparse
|
||||
plparse sfparse pldes plget plser pl2link xmlparse
|
||||
CTOOL_NAME = gdomap
|
||||
|
||||
SUBPROJECTS = make_strings
|
||||
|
@ -72,6 +72,7 @@ dremove_OBJC_FILES = dremove.m
|
|||
dwrite_OBJC_FILES = dwrite.m
|
||||
pl_OBJC_FILES = pl.m
|
||||
pldes_OBJC_FILES = pldes.m
|
||||
plget_OBJC_FILES = plget.m
|
||||
plser_OBJC_FILES = plser.m
|
||||
plmerge_OBJC_FILES = plmerge.m
|
||||
plparse_OBJC_FILES = plparse.m
|
||||
|
|
|
@ -15,6 +15,8 @@ pl, pldes, plser, plmerge, plparse, pl2link \- property list tools
|
|||
.nf
|
||||
.BI "pldes " "filename(s)"
|
||||
.nl
|
||||
.BI "plget " "key"
|
||||
.nl
|
||||
.BI "plser " "filename(s)"
|
||||
.nl
|
||||
.BI "plmerge [ " "destination-file" " ] [ " "input-file(s)" " ]"
|
||||
|
@ -42,6 +44,10 @@ manipulating the various persistent property list representations as files.
|
|||
.IP "\fBpldes\fR \fIfilename(s)\fR" 4
|
||||
Converts a binary serialised property list (class instance) to a text
|
||||
representation.
|
||||
.IP "\fBplget\fR \fIkey\fR" 4
|
||||
Reads a text representation of a dictionary in property list format as
|
||||
standard input, extracts the string value held in that dictionary with
|
||||
the specified key, and writes the result to standard output.
|
||||
.IP "\fBplser\fR \fIfilename(s)\fR" 4
|
||||
Converts a text representation of a property list to a binary serialized
|
||||
representation.
|
||||
|
@ -67,7 +73,7 @@ Written 1999-2000.
|
|||
This manual page first appeared in gnustep-base 1.9.2 (March 2004).
|
||||
.P
|
||||
.SH AUTHORS
|
||||
.B pldes, plparse, plser
|
||||
.B pldes, plget, plparse, plser
|
||||
were written by Richard Frith-McDonald <rfm@gnu.org>.
|
||||
.PP
|
||||
.B plmerge
|
||||
|
|
108
Tools/plget.m
Normal file
108
Tools/plget.m
Normal file
|
@ -0,0 +1,108 @@
|
|||
/** This tool extracts a string value from a dictionary in a property list.
|
||||
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 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,
|
||||
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <Foundation/Foundation.h>
|
||||
#include <Foundation/NSArray.h>
|
||||
#include <Foundation/NSData.h>
|
||||
#include <Foundation/NSException.h>
|
||||
#include <Foundation/NSString.h>
|
||||
#include <Foundation/NSProcessInfo.h>
|
||||
#include <Foundation/NSUserDefaults.h>
|
||||
#include <Foundation/NSDebug.h>
|
||||
#include <Foundation/NSFileHandle.h>
|
||||
#include <Foundation/NSAutoreleasePool.h>
|
||||
|
||||
|
||||
/** <p> This tool extracts a string value from a dictionary in a property
|
||||
list representation.<br />
|
||||
It takes a single argument (the key to be extracted).<br />
|
||||
It expects to read the property list from STDIN.<br />
|
||||
It writes the string value (if any) on STDOUT<br />
|
||||
</p> */
|
||||
int
|
||||
main(int argc, char** argv, char **env)
|
||||
{
|
||||
CREATE_AUTORELEASE_POOL(pool);
|
||||
NSProcessInfo *proc;
|
||||
NSArray *args;
|
||||
int status = EXIT_SUCCESS;
|
||||
|
||||
#ifdef GS_PASS_ARGUMENTS
|
||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
||||
#endif
|
||||
pool = [NSAutoreleasePool new];
|
||||
proc = [NSProcessInfo processInfo];
|
||||
if (proc == nil)
|
||||
{
|
||||
NSLog(@"plget: unable to get process information.");
|
||||
RELEASE(pool);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
args = [proc arguments];
|
||||
|
||||
if ([args count] <= 1)
|
||||
{
|
||||
NSLog(@"plget: no key given to get.");
|
||||
RELEASE(pool);
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
else
|
||||
{
|
||||
NSFileHandle *fileHandle;
|
||||
NSData *inputData;
|
||||
NSString *inputString;
|
||||
NSDictionary *dictionary;
|
||||
NSString *value;
|
||||
NSData *outputData;
|
||||
|
||||
NS_DURING
|
||||
{
|
||||
fileHandle = [NSFileHandle fileHandleWithStandardInput];
|
||||
inputData = [fileHandle readDataToEndOfFile];
|
||||
inputString = [[NSString alloc] initWithData: inputData
|
||||
encoding: NSUTF8StringEncoding];
|
||||
if (inputString == nil)
|
||||
{
|
||||
inputString = [[NSString alloc] initWithData: inputData
|
||||
encoding: [NSString defaultCStringEncoding]];
|
||||
}
|
||||
dictionary = [inputString propertyList];
|
||||
RELEASE(inputString);
|
||||
value = [dictionary objectForKey: [args objectAtIndex: 1]];
|
||||
outputData = [value dataUsingEncoding:
|
||||
[NSString defaultCStringEncoding]];
|
||||
if ([outputData length] > 0)
|
||||
{
|
||||
fileHandle = [NSFileHandle fileHandleWithStandardOutput];
|
||||
[fileHandle writeData: outputData];
|
||||
}
|
||||
}
|
||||
NS_HANDLER
|
||||
{
|
||||
NSLog(@"Problem: %@", localException);
|
||||
status = EXIT_FAILURE;
|
||||
}
|
||||
NS_ENDHANDLER
|
||||
}
|
||||
RELEASE(pool);
|
||||
return status;
|
||||
}
|
Loading…
Reference in a new issue