diff --git a/ChangeLog b/ChangeLog index 497c900b5..d7f75b529 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,9 @@ +2006-01-17 Richard Frith-Macdonald + + * 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 * Source/win32/NSMessagePortNameServerWin32.m: diff --git a/Tools/GNUmakefile b/Tools/GNUmakefile index 310359af2..af03b88b8 100644 --- a/Tools/GNUmakefile +++ b/Tools/GNUmakefile @@ -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 diff --git a/Tools/pldes.1 b/Tools/pldes.1 index a44ef21b2..d79b551c4 100644 --- a/Tools/pldes.1 +++ b/Tools/pldes.1 @@ -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 . .PP .B plmerge diff --git a/Tools/plget.m b/Tools/plget.m new file mode 100644 index 000000000..f69aa059a --- /dev/null +++ b/Tools/plget.m @@ -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 + 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 +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +/**

This tool extracts a string value from a dictionary in a property + list representation.
+ It takes a single argument (the key to be extracted).
+ It expects to read the property list from STDIN.
+ It writes the string value (if any) on STDOUT
+

*/ +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; +}