2 Copyright (C) 2000-2005 SKYRIX Software AG
4 This file is part of SOPE.
6 SOPE is free software; you can redistribute it and/or modify it under
7 the terms of the GNU Lesser General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
11 SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
12 WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
14 License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with SOPE; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
22 #import <Foundation/Foundation.h>
23 #include "WODParser.h"
25 @interface MyWODHandler : NSObject < WODParserHandler >
28 @implementation MyWODHandler
30 - (BOOL)parser:(id)_parser willParseDeclarationData:(NSData *)_data {
33 - (void)parser:(id)_parser finishedParsingDeclarationData:(NSData *)_data
34 declarations:(NSDictionary *)_decls
37 - (void)parser:(id)_parser failedParsingDeclarationData:(NSData *)_data
38 exception:(NSException *)_exception
43 - (id)parser:(id)_parser makeAssociationWithValue:(id)_value {
46 - (id)parser:(id)_parser makeAssociationWithKeyPath:(NSString *)_keyPath {
49 - (id)parser:(id)_parser makeDefinitionForComponentNamed:(NSString *)_cname
50 associations:(id)_entry
51 elementName:(NSString *)_elemName
56 @end /* MyWODHandler */
58 static void processFile(NSString *path) {
61 NSDictionary *mappings;
63 MyWODHandler *wodHandler;
65 wodHandler = [[[MyWODHandler alloc] init] autorelease];
66 ud = [NSUserDefaults standardUserDefaults];
70 if ((data = [NSData dataWithContentsOfFile:path]) == nil) {
71 fprintf(stderr, "%s: could not open file.\n", [path cString]);
75 if ([data length] == 0)
82 parser = [[[WODParser alloc] initWithHandler:(id)wodHandler] autorelease];
84 mappings = [parser parseDeclarationData:data];
87 e = [localException retain];
96 if ((ui = [e userInfo]))
97 line = [[ui objectForKey:@"line"] intValue];
100 fprintf(stderr, "%s:%i: %s\n",
101 [path cString], line,
102 [[e reason] cString]);
105 fprintf(stderr, "%s: %s\n",
107 [[e reason] cString]);
111 if ([ud objectForKey:@"print"]) {
115 e = [mappings keyEnumerator];
116 while ((key = [e nextObject])) {
119 value = [mappings objectForKey:key];
120 printf("%s: %s\n", [key cString], [[value description] cString]);
124 if ([ud objectForKey:@"list"]) {
128 keys = [mappings allKeys];
129 keys = [keys sortedArrayUsingSelector:@selector(compare:)];
130 keys = [keys objectEnumerator];
132 while ((key = [keys nextObject])) {
135 value = [mappings objectForKey:key];
136 printf("%s: %s\n", [key cString], [[value description] cString]);
141 int main(int argc, char **argv, char **env) {
143 NSAutoreleasePool *pool;
149 #if LIB_FOUNDATION_LIBRARY
150 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
153 pool = [[NSAutoreleasePool alloc] init];
154 args = [[NSProcessInfo processInfo] arguments];
159 ud = [NSUserDefaults standardUserDefaults];
160 *(&paths) = [NSMutableArray array];
162 for (*(&i) = 1; i < argc; i++) {
163 if (argv[i][0] == '-') {
165 [ud setObject:[NSNumber numberWithBool:YES]
166 forKey:[NSString stringWithCString:&(argv[i][1])]];
172 [paths addObject:[NSString stringWithCString:argv[i]]];
175 paths = [paths objectEnumerator];
177 while ((path = [paths nextObject])) {
178 NSAutoreleasePool *pool2;
180 pool2 = [[NSAutoreleasePool alloc] init];