mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 08:21:25 +00:00
Make plget a bit more flexible.
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@22322 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
a753b38f67
commit
c31205a461
2 changed files with 23 additions and 6 deletions
|
@ -15,7 +15,7 @@ pl, pldes, plser, plmerge, plparse, pl2link \- property list tools
|
||||||
.nf
|
.nf
|
||||||
.BI "pldes " "filename(s)"
|
.BI "pldes " "filename(s)"
|
||||||
.nl
|
.nl
|
||||||
.BI "plget " "key"
|
.BI "plget " "key" [ more keys ]
|
||||||
.nl
|
.nl
|
||||||
.BI "plser " "filename(s)"
|
.BI "plser " "filename(s)"
|
||||||
.nl
|
.nl
|
||||||
|
@ -48,6 +48,7 @@ representation.
|
||||||
Reads a text representation of a dictionary in property list format as
|
Reads a text representation of a dictionary in property list format as
|
||||||
standard input, extracts the string value held in that dictionary with
|
standard input, extracts the string value held in that dictionary with
|
||||||
the specified key, and writes the result to standard output.
|
the specified key, and writes the result to standard output.
|
||||||
|
Multiple keys may be used to extract values from nested dictionaries.
|
||||||
.IP "\fBplser\fR \fIfilename(s)\fR" 4
|
.IP "\fBplser\fR \fIfilename(s)\fR" 4
|
||||||
Converts a text representation of a property list to a binary serialized
|
Converts a text representation of a property list to a binary serialized
|
||||||
representation.
|
representation.
|
||||||
|
|
|
@ -33,9 +33,13 @@
|
||||||
|
|
||||||
/** <p> This tool extracts a string value from a dictionary in a property
|
/** <p> This tool extracts a string value from a dictionary in a property
|
||||||
list representation.<br />
|
list representation.<br />
|
||||||
It takes a single argument (the key to be extracted).<br />
|
It takes one or more argument (the key to be extracted).<br />
|
||||||
It expects to read the property list from STDIN.<br />
|
It expects to read the property list from STDIN.<br />
|
||||||
It writes the string value (if any) on STDOUT<br />
|
It writes the string value (if any) on STDOUT<br />
|
||||||
|
Where multiple keys are specified, they are used to extract nested
|
||||||
|
values from dictionaries within the outermost dictionary.<br />
|
||||||
|
Where the resulting object exists and is not a string,
|
||||||
|
its description is written to STDOUT.
|
||||||
</p> */
|
</p> */
|
||||||
int
|
int
|
||||||
main(int argc, char** argv, char **env)
|
main(int argc, char** argv, char **env)
|
||||||
|
@ -44,6 +48,7 @@ main(int argc, char** argv, char **env)
|
||||||
NSProcessInfo *proc;
|
NSProcessInfo *proc;
|
||||||
NSArray *args;
|
NSArray *args;
|
||||||
int status = EXIT_SUCCESS;
|
int status = EXIT_SUCCESS;
|
||||||
|
int count;
|
||||||
|
|
||||||
#ifdef GS_PASS_ARGUMENTS
|
#ifdef GS_PASS_ARGUMENTS
|
||||||
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
||||||
|
@ -59,7 +64,7 @@ main(int argc, char** argv, char **env)
|
||||||
|
|
||||||
args = [proc arguments];
|
args = [proc arguments];
|
||||||
|
|
||||||
if ([args count] <= 1)
|
if ((count = [args count]) <= 1)
|
||||||
{
|
{
|
||||||
NSLog(@"plget: no key given to get.");
|
NSLog(@"plget: no key given to get.");
|
||||||
RELEASE(pool);
|
RELEASE(pool);
|
||||||
|
@ -71,11 +76,13 @@ main(int argc, char** argv, char **env)
|
||||||
NSData *inputData;
|
NSData *inputData;
|
||||||
NSString *inputString;
|
NSString *inputString;
|
||||||
NSDictionary *dictionary;
|
NSDictionary *dictionary;
|
||||||
NSString *value;
|
|
||||||
NSData *outputData;
|
NSData *outputData;
|
||||||
|
|
||||||
NS_DURING
|
NS_DURING
|
||||||
{
|
{
|
||||||
|
int i = 1;
|
||||||
|
id value;
|
||||||
|
|
||||||
fileHandle = [NSFileHandle fileHandleWithStandardInput];
|
fileHandle = [NSFileHandle fileHandleWithStandardInput];
|
||||||
inputData = [fileHandle readDataToEndOfFile];
|
inputData = [fileHandle readDataToEndOfFile];
|
||||||
inputString = [[NSString alloc] initWithData: inputData
|
inputString = [[NSString alloc] initWithData: inputData
|
||||||
|
@ -85,9 +92,18 @@ main(int argc, char** argv, char **env)
|
||||||
inputString = [[NSString alloc] initWithData: inputData
|
inputString = [[NSString alloc] initWithData: inputData
|
||||||
encoding: [NSString defaultCStringEncoding]];
|
encoding: [NSString defaultCStringEncoding]];
|
||||||
}
|
}
|
||||||
dictionary = [inputString propertyList];
|
value = [inputString propertyList];
|
||||||
RELEASE(inputString);
|
RELEASE(inputString);
|
||||||
value = [dictionary objectForKey: [args objectAtIndex: 1]];
|
while (i < count-1)
|
||||||
|
{
|
||||||
|
value = [(NSDictionary*)value objectForKey:
|
||||||
|
[args objectAtIndex: i++]];
|
||||||
|
}
|
||||||
|
value = [(NSDictionary*)value objectForKey: [args objectAtIndex: i]];
|
||||||
|
if ([value isKindOfClass: [NSString class]] == NO)
|
||||||
|
{
|
||||||
|
value = [value description];
|
||||||
|
}
|
||||||
outputData = [value dataUsingEncoding:
|
outputData = [value dataUsingEncoding:
|
||||||
[NSString defaultCStringEncoding]];
|
[NSString defaultCStringEncoding]];
|
||||||
if ([outputData length] > 0)
|
if ([outputData length] > 0)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue