mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 00:30:53 +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;
|
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
|
void
|
||||||
GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
||||||
BOOL forDescription, unsigned step, id *str)
|
BOOL forDescription, unsigned step, id *str)
|
||||||
|
@ -2757,7 +2769,7 @@ GSPropertyListMake(id obj, NSDictionary *loc, BOOL xml,
|
||||||
// not the other way round,
|
// not the other way round,
|
||||||
NSData *data = [self dataWithPropertyList: aPropertyList
|
NSData *data = [self dataWithPropertyList: aPropertyList
|
||||||
format: aFormat
|
format: aFormat
|
||||||
options: 0
|
options: anOption
|
||||||
error: error];
|
error: error];
|
||||||
|
|
||||||
return [stream write: [data bytes] maxLength: [data length]];
|
return [stream write: [data bytes] maxLength: [data length]];
|
||||||
|
|
|
@ -33,6 +33,10 @@
|
||||||
#import "Foundation/NSUserDefaults.h"
|
#import "Foundation/NSUserDefaults.h"
|
||||||
#import "Foundation/NSValue.h"
|
#import "Foundation/NSValue.h"
|
||||||
|
|
||||||
|
// From NSPropertyList.m
|
||||||
|
extern void
|
||||||
|
GSPropertyListMake(id, NSDictionary *, BOOL, BOOL, unsigned, id *);
|
||||||
|
|
||||||
// We don't have @[] on gcc
|
// We don't have @[] on gcc
|
||||||
#define NARRAY(...) [NSArray arrayWithObjects:__VA_ARGS__, nil]
|
#define NARRAY(...) [NSArray arrayWithObjects:__VA_ARGS__, nil]
|
||||||
// And no @() or @123
|
// And no @() or @123
|
||||||
|
@ -402,7 +406,7 @@ print_help(FILE *f)
|
||||||
GSPrintf(f, @"Property list utility\n");
|
GSPrintf(f, @"Property list utility\n");
|
||||||
GSPrintf(f, @"Usage: plutil [command] [options] file\n\n");
|
GSPrintf(f, @"Usage: plutil [command] [options] file\n\n");
|
||||||
GSPrintf(f, @"Accepted commands:\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");
|
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_LINT), NINT(0)), @"-lint",
|
||||||
NARRAY(NINT(ACTION_CONVERT), NINT(1)),
|
NARRAY(NINT(ACTION_CONVERT), NINT(1)),
|
||||||
@"-convert",
|
@"-convert",
|
||||||
NARRAY(NINT(ACTION_INSERT), NINT(2)),
|
NARRAY(NINT(ACTION_INSERT), NINT(3)),
|
||||||
@"-insert",
|
@"-insert",
|
||||||
NARRAY(NINT(ACTION_REPLACE), NINT(2)),
|
NARRAY(NINT(ACTION_REPLACE), NINT(3)),
|
||||||
@"-replace",
|
@"-replace",
|
||||||
NARRAY(NINT(ACTION_REMOVE), NINT(1)),
|
NARRAY(NINT(ACTION_REMOVE), NINT(1)),
|
||||||
@"-remove",
|
@"-remove",
|
||||||
|
@ -480,6 +484,8 @@ main(int argc, char **argv, char **env)
|
||||||
NSPropertyListFormat aFormat;
|
NSPropertyListFormat aFormat;
|
||||||
NSError * anError;
|
NSError * anError;
|
||||||
id result;
|
id result;
|
||||||
|
NSMutableString * outStr = nil;
|
||||||
|
NSDictionary * locale;
|
||||||
|
|
||||||
arg = [args objectAtIndex:i];
|
arg = [args objectAtIndex:i];
|
||||||
if (![arg hasPrefix:@"-"])
|
if (![arg hasPrefix:@"-"])
|
||||||
|
@ -494,7 +500,7 @@ main(int argc, char **argv, char **env)
|
||||||
action = [[command_rhs objectAtIndex:0] intValue];
|
action = [[command_rhs objectAtIndex:0] intValue];
|
||||||
iwant = [[command_rhs objectAtIndex:1] intValue];
|
iwant = [[command_rhs objectAtIndex:1] intValue];
|
||||||
|
|
||||||
argrange.location = i;
|
argrange.location = i + 1;
|
||||||
argrange.length = iwant;
|
argrange.length = iwant;
|
||||||
cmdargs = [args subarrayWithRange:argrange];
|
cmdargs = [args subarrayWithRange:argrange];
|
||||||
|
|
||||||
|
@ -563,12 +569,11 @@ main(int argc, char **argv, char **env)
|
||||||
case ACTION_LINT:
|
case ACTION_LINT:
|
||||||
break;
|
break;
|
||||||
case ACTION_PRINT:
|
case ACTION_PRINT:
|
||||||
// Why use an ad-hoc format when description gives pretty plists?
|
// Not using description because we can GS it
|
||||||
GSPrintf(stdout, @"%@\n",
|
locale =
|
||||||
[result
|
[[NSUserDefaults standardUserDefaults] dictionaryRepresentation];
|
||||||
descriptionWithLocale:[[NSUserDefaults standardUserDefaults]
|
GSPropertyListMake(result, locale, NO, NO, 2, &outStr);
|
||||||
dictionaryRepresentation]
|
GSPrintf(stdout, @"%@\n", outStr);
|
||||||
indent:0]);
|
|
||||||
break;
|
break;
|
||||||
case ACTION_CONVERT:
|
case ACTION_CONVERT:
|
||||||
status = plCmdConvert(result, cmdargs, outpath);
|
status = plCmdConvert(result, cmdargs, outpath);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue