mirror of
https://github.com/inverse-inc/sogo.git
synced 2026-10-06 12:30:31 +00:00
Monotone-Parent: 3f8608c82d9c379cc9e0fea6ffe853cc1949a24b
Monotone-Revision: 905276f295d6f28a6946297f6a7af9ad60f71842 Monotone-Author: wsourdeau@inverse.ca Monotone-Date: 2012-06-29T17:59:38 Monotone-Branch: ca.inverse.sogo
This commit is contained in:
+3
-148
@@ -23,164 +23,19 @@
|
||||
/* A format-agnostic property list dumper.
|
||||
Usage: plreader [filename] */
|
||||
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSArray.h>
|
||||
#import <Foundation/NSData.h>
|
||||
#import <Foundation/NSDictionary.h>
|
||||
#import <Foundation/NSAutoreleasePool.h>
|
||||
#import <Foundation/NSProcessInfo.h>
|
||||
#import <Foundation/NSPropertyList.h>
|
||||
#import <Foundation/NSString.h>
|
||||
#import <Foundation/NSValue.h>
|
||||
#import <NGExtensions/NSNull+misc.h>
|
||||
|
||||
const char *indentationStep = " ";
|
||||
|
||||
@interface NSObject (plext)
|
||||
|
||||
- (void) displayWithIndentation: (NSInteger) anInt;
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSObject (plext)
|
||||
|
||||
- (void) _outputIndentation: (NSInteger) anInt
|
||||
{
|
||||
NSInteger i;
|
||||
|
||||
for (i = 0; i < anInt; i++)
|
||||
printf ("%s", indentationStep);
|
||||
}
|
||||
|
||||
- (void) displayWithIndentation: (NSInteger) anInt
|
||||
{
|
||||
printf ("(%s) %s",
|
||||
[NSStringFromClass (isa) UTF8String],
|
||||
[[self description] UTF8String]);
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSDictionary (plext)
|
||||
|
||||
- (void) displayKey: (NSString *) key
|
||||
withIndentation: (NSInteger) anInt
|
||||
{
|
||||
[self _outputIndentation: anInt];
|
||||
|
||||
printf ("%s ", [[key description] UTF8String]);
|
||||
if ([key isKindOfClass: [NSValue class]])
|
||||
printf ("(%s: 0x%.8x) ", [(NSValue *) key objCType], [key intValue]);
|
||||
|
||||
printf ("= ");
|
||||
}
|
||||
|
||||
- (void) displayWithIndentation: (NSInteger) anInt
|
||||
{
|
||||
NSUInteger i, max;
|
||||
NSArray *keys;
|
||||
NSInteger subIndent;
|
||||
NSString *key;
|
||||
|
||||
keys = [self allKeys];
|
||||
max = [keys count];
|
||||
|
||||
printf ("{ (%ld) items\n", (long) max);
|
||||
|
||||
subIndent = anInt + 1;
|
||||
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
key = [keys objectAtIndex: i];
|
||||
[self displayKey: key withIndentation: subIndent];
|
||||
[[self objectForKey: key] displayWithIndentation: subIndent];
|
||||
if (i < (max - 1))
|
||||
printf (",");
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
[self _outputIndentation: anInt];
|
||||
printf ("}");
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
@implementation NSArray (plext)
|
||||
|
||||
- (void) displayCount: (NSUInteger) count
|
||||
withIndentation: (NSInteger) anInt
|
||||
{
|
||||
[self _outputIndentation: anInt];
|
||||
printf ("%lu = ", (unsigned long) count);
|
||||
}
|
||||
|
||||
- (void) displayWithIndentation: (NSInteger) anInt
|
||||
{
|
||||
NSUInteger i, max;
|
||||
NSInteger subIndent;
|
||||
|
||||
max = [self count];
|
||||
|
||||
printf ("[ (%ld) items\n", (long) max);
|
||||
|
||||
subIndent = anInt + 1;
|
||||
|
||||
for (i = 0; i < max; i++)
|
||||
{
|
||||
[self displayCount: i withIndentation: subIndent];
|
||||
[[self objectAtIndex: i] displayWithIndentation: subIndent];
|
||||
if (i < (max - 1))
|
||||
printf (",");
|
||||
printf ("\n");
|
||||
}
|
||||
|
||||
[self _outputIndentation: anInt];
|
||||
printf ("]");
|
||||
}
|
||||
|
||||
@end
|
||||
#import "NSObject+PropertyList.m"
|
||||
|
||||
static void
|
||||
PLReaderDumpPListFile (NSString *filename)
|
||||
{
|
||||
NSData *content;
|
||||
NSDictionary *d;
|
||||
NSPropertyListFormat format;
|
||||
NSString *error = nil;
|
||||
const char *formatName;
|
||||
|
||||
content = [NSData dataWithContentsOfFile: filename];
|
||||
d = [NSPropertyListSerialization propertyListFromData: content
|
||||
mutabilityOption: NSPropertyListImmutable
|
||||
format: &format
|
||||
errorDescription: &error];
|
||||
if (d)
|
||||
{
|
||||
switch (format)
|
||||
{
|
||||
case NSPropertyListOpenStepFormat:
|
||||
formatName = "OpenStep";
|
||||
break;
|
||||
case NSPropertyListXMLFormat_v1_0:
|
||||
formatName = "XML";
|
||||
break;
|
||||
case NSPropertyListBinaryFormat_v1_0:
|
||||
formatName = "Binary";
|
||||
break;
|
||||
case NSPropertyListGNUstepFormat:
|
||||
formatName = "GNUstep";
|
||||
break;
|
||||
case NSPropertyListGNUstepBinaryFormat:
|
||||
formatName = "GNUstep binary";
|
||||
break;
|
||||
default: formatName = "unknown";
|
||||
}
|
||||
|
||||
printf ("File format is: %s\n", formatName);
|
||||
[d displayWithIndentation: 0];
|
||||
printf ("\n");
|
||||
}
|
||||
else
|
||||
printf ("an error occurred: %s\n", [error UTF8String]);
|
||||
OCDumpPListData (content);
|
||||
}
|
||||
|
||||
int main()
|
||||
|
||||
Reference in New Issue
Block a user