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 #include <SaxObjC/SaxObjC.h>
24 #include <DOM/DOMSaxBuilder.h>
25 #include <DOM/DOMXMLOutputter.h>
26 #include <DOM/DOMPYXOutputter.h>
27 #include <DOM/NSObject+QPEval.h>
33 testqp [options] files
34 -xml|-pyx - output in XML or PYX format ...
37 int main(int argc, char **argv, char **env) {
40 NSAutoreleasePool *pool;
42 DOMSaxBuilder *builder;
45 #if LIB_FOUNDATION_LIBRARY
46 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
49 pool = [[NSAutoreleasePool alloc] init];
54 if ((builder = [[DOMSaxBuilder alloc] init]) == nil) {
55 fprintf(stderr, "could not load a SAX driver bundle !\n");
58 [builder autorelease];
62 paths = [[[NSProcessInfo processInfo] arguments] objectEnumerator];
63 [paths nextObject]; // skip toolname
64 while ((path = [paths nextObject])) {
65 NSAutoreleasePool *pool;
67 NSTimeInterval duration;
70 if ([path hasPrefix:@"-"]) {
71 if ([path isEqualToString:@"-pyx"]) {
72 out = [[[NGDOMPYXOutputter alloc] init] autorelease];
74 else if ([path isEqualToString:@"-xml"]) {
75 out = [[[DOMXMLOutputter alloc] init] autorelease];
78 // a default ? skip the value
85 pool = [[NSAutoreleasePool alloc] init];
88 doc = [builder buildFromContentsOfFile:path];
89 duration = [[NSDate date] timeIntervalSinceDate:date];
92 NSLog(@"couldn't build DOM from path '%@'", path);
93 [pool release]; pool = nil;
96 [out outputDocument:doc to:nil];
97 NSLog(@"doc is %@, parsed in %.3fs", doc, duration);
100 NSAutoreleasePool *pool;
103 pool = [[NSAutoreleasePool alloc] init];
104 printf("enter query path: ");
107 fgets(buf, 4000, stdin);
109 if (buf[0] == '\n' || buf[0] == 0) {
110 printf("... exit\n");
117 buf[strlen(buf) - 1] = '\0';
118 s = [NSString stringWithCString:buf];
119 NSLog(@"eval: '%@'", s);
122 if ((res = [doc evaluateQueryPath:s]))
123 NSLog(@"result: %@", res);
125 NSLog(@"no rresult ...");
127 fprintf(stderr, "%s\n", [[localException description] cString]);