mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 00:11:26 +00:00
plutil: use GS text for pretty print
This commit is contained in:
parent
ee4dcec792
commit
a76677623a
2 changed files with 28 additions and 11 deletions
|
@ -2481,6 +2481,18 @@ static BOOL classInitialized = NO;
|
|||
return dest;
|
||||
}
|
||||
|
||||
/**
|
||||
* <p>Make <var>obj</var> into a plist in <var>str</var>, using the locale <var>loc</var>.</p>
|
||||
*
|
||||
* <p>If <var>*str</var> is <code>nil</code>, create a <ref>GSMutableString</ref>.
|
||||
* Otherwise <var>*str</var> must be a GSMutableString.</p>
|
||||
*
|
||||
* <p>Options:</p><ul>
|
||||
* <li><var>step</var> is the indent level.</li>
|
||||
* <li><var>forDescription</var> enables OpenStep formatting.</li>
|
||||
* <li><var>xml</var> enables XML formatting.</li>
|
||||
* </ul>
|
||||
*/
|
||||
void
|
||||
GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
||||
BOOL forDescription, unsigned step, id *str)
|
||||
|
@ -2757,7 +2769,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
|||
// not the other way round,
|
||||
NSData *data = [self dataWithPropertyList: aPropertyList
|
||||
format: aFormat
|
||||
options: 0
|
||||
options: anOption
|
||||
error: error];
|
||||
|
||||
return [stream write: [data bytes] maxLength: [data length]];
|
||||
|
|
|
@ -33,6 +33,10 @@
|
|||
#import "Foundation/NSUserDefaults.h"
|
||||
#import "Foundation/NSValue.h"
|
||||
|
||||
// From NSPropertyList.m
|
||||
extern void
|
||||
GSPropertyListMake(id, NSDictionary *, BOOL, BOOL, unsigned, id *);
|
||||
|
||||
// We don't have @[] on gcc
|
||||
#define NARRAY(...) [NSArray arrayWithObjects:__VA_ARGS__, nil]
|
||||
// And no @() or @123
|
||||
|
@ -402,7 +406,7 @@ print_help(FILE *f)
|
|||
GSPrintf(f, @"Property list utility\n");
|
||||
GSPrintf(f, @"Usage: plutil [command] [options] file\n\n");
|
||||
GSPrintf(f, @"Accepted commands:\n");
|
||||
GSPrintf(f, @"-p\tPrints the plists in a human-readable form.");
|
||||
GSPrintf(f, @"-p\tPrints the plists in a human-readable form (GNUstep ASCII).");
|
||||
GSPrintf(f, @"Accepted options:\n");
|
||||
}
|
||||
|
||||
|
@ -466,9 +470,9 @@ main(int argc, char **argv, char **env)
|
|||
NARRAY(NINT(ACTION_LINT), NINT(0)), @"-lint",
|
||||
NARRAY(NINT(ACTION_CONVERT), NINT(1)),
|
||||
@"-convert",
|
||||
NARRAY(NINT(ACTION_INSERT), NINT(2)),
|
||||
NARRAY(NINT(ACTION_INSERT), NINT(3)),
|
||||
@"-insert",
|
||||
NARRAY(NINT(ACTION_REPLACE), NINT(2)),
|
||||
NARRAY(NINT(ACTION_REPLACE), NINT(3)),
|
||||
@"-replace",
|
||||
NARRAY(NINT(ACTION_REMOVE), NINT(1)),
|
||||
@"-remove",
|
||||
|
@ -480,6 +484,8 @@ main(int argc, char **argv, char **env)
|
|||
NSPropertyListFormat aFormat;
|
||||
NSError * anError;
|
||||
id result;
|
||||
NSMutableString * outStr = nil;
|
||||
NSDictionary * locale;
|
||||
|
||||
arg = [args objectAtIndex:i];
|
||||
if (![arg hasPrefix:@"-"])
|
||||
|
@ -494,7 +500,7 @@ main(int argc, char **argv, char **env)
|
|||
action = [[command_rhs objectAtIndex:0] intValue];
|
||||
iwant = [[command_rhs objectAtIndex:1] intValue];
|
||||
|
||||
argrange.location = i;
|
||||
argrange.location = i + 1;
|
||||
argrange.length = iwant;
|
||||
cmdargs = [args subarrayWithRange:argrange];
|
||||
|
||||
|
@ -563,12 +569,11 @@ main(int argc, char **argv, char **env)
|
|||
case ACTION_LINT:
|
||||
break;
|
||||
case ACTION_PRINT:
|
||||
// Why use an ad-hoc format when description gives pretty plists?
|
||||
GSPrintf(stdout, @"%@\n",
|
||||
[result
|
||||
descriptionWithLocale:[[NSUserDefaults standardUserDefaults]
|
||||
dictionaryRepresentation]
|
||||
indent:0]);
|
||||
// Not using description because we can GS it
|
||||
locale =
|
||||
[[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
|
||||
GSPropertyListMake(result, locale, NO, NO, 2, &outStr);
|
||||
GSPrintf(stdout, @"%@\n", outStr);
|
||||
break;
|
||||
case ACTION_CONVERT:
|
||||
status = plCmdConvert(result, cmdargs, outpath);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue