-
Notifications
You must be signed in to change notification settings - Fork 13
/
TMDCommand.mm
57 lines (47 loc) · 1.41 KB
/
TMDCommand.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
#import "TMDCommand.h"
static NSMutableDictionary* Commands = nil;
@implementation TMDCommand
+ (void)registerObject:(id)anObject forCommand:(NSString*)aCommand
{
if(!Commands)
Commands = [NSMutableDictionary new];
[Commands setObject:anObject forKey:aCommand];
}
+ (NSDictionary*)registeredCommands
{
return [Commands copy];
}
+ (id)objectForCommand:(NSString*)aCommand
{
return [Commands objectForKey:aCommand];
}
+ (id)readPropertyList:(NSFileHandle*)aFileHandle error:(NSError**)error;
{
NSData* data = [aFileHandle readDataToEndOfFile];
if([data length] == 0)
return nil;
id plist = [NSPropertyListSerialization propertyListWithData:data options:NSPropertyListMutableContainersAndLeaves format:nil error:error];
return plist;
}
+ (void)writePropertyList:(id)aPlist toFileHandle:(NSFileHandle*)aFileHandle
{
NSError* error = nil;
if(NSData* data = [NSPropertyListSerialization dataWithPropertyList:aPlist format:NSPropertyListXMLFormat_v1_0 options:0 error:&error])
{
[aFileHandle writeData:data];
}
else
{
fprintf(stderr, "%s\n", [[error localizedDescription] UTF8String] ?: "unknown error serializing returned property list");
fprintf(stderr, "%s\n", [[aPlist description] UTF8String]);
}
}
- (NSString*)commandDescription
{
return @"No information available for this command";
}
- (NSString*)usageForInvocation:(NSString*)invocation;
{
return @"No usage information available for this command";
}
@end