2 Copyright (C) 2000-2004 SKYRIX Software AG
4 This file is part of OpenGroupware.org.
6 OGo 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 OGo 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 OGo; see the file COPYING. If not, write to the
18 Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
23 #import <Foundation/Foundation.h>
24 #include "WODParser.h"
26 @interface MyWODHandler : NSObject < WODParserHandler >
29 @implementation MyWODHandler
31 - (BOOL)parser:(id)_parser willParseDeclarationData:(NSData *)_data {
34 - (void)parser:(id)_parser finishedParsingDeclarationData:(NSData *)_data
35 declarations:(NSDictionary *)_decls
38 - (void)parser:(id)_parser failedParsingDeclarationData:(NSData *)_data
39 exception:(NSException *)_exception
44 - (id)parser:(id)_parser makeAssociationWithValue:(id)_value {
47 - (id)parser:(id)_parser makeAssociationWithKeyPath:(NSString *)_keyPath {
50 - (id)parser:(id)_parser makeDefinitionForComponentNamed:(NSString *)_cname
51 associations:(id)_entry
52 elementName:(NSString *)_elemName
57 @end /* MyWODHandler */
59 static void processFile(NSString *path) {
62 NSDictionary *mappings;
64 MyWODHandler *wodHandler;
66 wodHandler = [[[MyWODHandler alloc] init] autorelease];
67 ud = [NSUserDefaults standardUserDefaults];
71 if ((data = [NSData dataWithContentsOfFile:path]) == nil) {
72 fprintf(stderr, "%s: could not open file.\n", [path cString]);
76 if ([data length] == 0)
83 parser = [[[WODParser alloc] initWithHandler:(id)wodHandler] autorelease];
85 mappings = [parser parseDeclarationData:data];
88 e = [localException retain];
97 if ((ui = [e userInfo]))
98 line = [[ui objectForKey:@"line"] intValue];
101 fprintf(stderr, "%s:%i: %s\n",
102 [path cString], line,
103 [[e reason] cString]);
106 fprintf(stderr, "%s: %s\n",
108 [[e reason] cString]);
112 if ([ud objectForKey:@"print"]) {
116 e = [mappings keyEnumerator];
117 while ((key = [e nextObject])) {
120 value = [mappings objectForKey:key];
121 printf("%s: %s\n", [key cString], [[value description] cString]);
125 if ([ud objectForKey:@"list"]) {
129 keys = [mappings allKeys];
130 keys = [keys sortedArrayUsingSelector:@selector(compare:)];
131 keys = [keys objectEnumerator];
133 while ((key = [keys nextObject])) {
136 value = [mappings objectForKey:key];
137 printf("%s: %s\n", [key cString], [[value description] cString]);
142 int main(int argc, char **argv, char **env) {
144 NSAutoreleasePool *pool;
150 #if LIB_FOUNDATION_LIBRARY
151 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
154 pool = [[NSAutoreleasePool alloc] init];
155 args = [[NSProcessInfo processInfo] arguments];
160 ud = [NSUserDefaults standardUserDefaults];
161 *(&paths) = [NSMutableArray array];
163 for (*(&i) = 1; i < argc; i++) {
164 if (argv[i][0] == '-') {
166 [ud setObject:[NSNumber numberWithBool:YES]
167 forKey:[NSString stringWithCString:&(argv[i][1])]];
173 [paths addObject:[NSString stringWithCString:argv[i]]];
176 paths = [paths objectEnumerator];
178 while ((path = [paths nextObject])) {
179 NSAutoreleasePool *pool2;
181 pool2 = [[NSAutoreleasePool alloc] init];