This repository was archived by the owner on Aug 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathMPWBridgeReader.m
118 lines (95 loc) · 2.67 KB
/
MPWBridgeReader.m
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
//
// MPWBridgeReader.m
// MPWXmlKit
//
// Created by Marcel Weiher on 6/4/07.
// Copyright 2007 Marcel Weiher. All rights reserved.
//
#import "MPWBridgeReader.h"
#import "MPWMAXParser.h"
#import "mpwfoundation_imports.h"
#ifndef WINDOWS
#include <dlfcn.h>
#endif
@interface NSObject(valueBinding)
-(void)bindValue:value toVariableNamed:name;
@end
@implementation MPWBridgeReader
idAccessor( context ,setContext )
idAccessor( loadedSet, setLoadedSet )
-(NSUInteger)count { return count; }
-initWithContext:aContext
{
self=[super init];
[self setContext:aContext];
[self setLoadedSet:[NSMutableSet new]];
return self;
}
+(void)parseBridgeDict:aDict forContext:aContext
{
id pool=[NSAutoreleasePool new];
id reader = [[[self alloc] initWithContext:aContext] autorelease];
[reader parse:aDict];
// NSLog(@"%d total elements",(int)[reader count]);
[pool release];
}
-enumTag:attrs parser:parser
{
[context bindValue:[NSNumber numberWithInt:[[attrs objectForKey:@"value"] intValue]] toVariableNamed:[[attrs objectForKey:@"name"] stringValue]];
return nil;
}
-defaultElement:children attributes:a parser:p { count++; /* NSLog(@"<%@ > ",[p currentTag]); */ return nil; }
-depends_onElement:children attributes:attributes parser:parser
{
id path = [[[attributes objectForKey:@"path"] copy] autorelease];
// NSLog(@"dependency: %@",path);
if ( path ) {
if ( ![[self loadedSet] containsObject:path] ) {
[[self loadedSet] addObject:path];
[self parseFrameworkAtPath:path];
} else {
// NSLog(@"skipping %@, already seen",path);
}
}
return nil;
}
-constantTag:attrs parser:parser
{
if ( [[attrs objectForKey:@"type"] isEqual:@"@"] ) {
char symbol[255]="";
id name = [attrs objectForKey:@"name"];
[name getCString:symbol maxLength:250 encoding:NSISOLatin1StringEncoding];
symbol[ [name length] ] =0;
#if !WINDOWS && !LINUX
id* ptr=dlsym( RTLD_DEFAULT, symbol );
if ( ptr && *ptr ) {
[context bindValue:*ptr toVariableNamed:[name stringValue]];
}
#endif
}
return nil;
}
-(BOOL)parse:xmlData
{
id pool=[NSAutoreleasePool new];
if ( xmlData ) {
id parser=[MPWMAXParser parser];
[parser setHandler:self forTags:[NSArray arrayWithObjects:@"enum",@"constant",@"depends_on",nil]];
[parser parse:xmlData];
[pool release];
}
return YES;
}
-(void)parseFrameworkAtPath:(NSString*)frameworkPath
{
id frameworkName=[[frameworkPath lastPathComponent] stringByDeletingPathExtension];
id bridgeSupportFilePath = [NSString stringWithFormat:@"%@/Resources/BridgeSupport/%@.bridgesupport",
frameworkPath,frameworkName];
[self parse:[NSData dataWithContentsOfFile:bridgeSupportFilePath]];
}
-(void)dealloc
{
[context release];
[super dealloc];
}
@end