]> err.no Git - scalable-opengroupware.org/blob - SOPE/NGCards/samples/vcfparsetest.m
git-svn-id: http://svn.opengroupware.org/SOGo/inverse/trunk@1013 d1b88da0-ebda-0310...
[scalable-opengroupware.org] / SOPE / NGCards / samples / vcfparsetest.m
1 /*
2   Copyright (C) 2005 Helge Hess
3
4   This file is part of SOPE.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <Foundation/Foundation.h>
23 #import <NGCards/NGVCard.h>
24
25 @interface vcsparsetest : NSObject
26 {
27 }
28
29 - (int)runWithArguments:(NSArray *)_args;
30
31 @end
32
33 @implementation vcsparsetest
34
35 - (id)init {
36   if ((self = [super init])) {
37   }
38   return self;
39 }
40
41 - (void)dealloc {
42   [super dealloc];
43 }
44
45 /* parsing */
46
47 - (id)parseFile:(NSString *)_path {
48   if ([_path length] == 0) return nil;
49   return [NGVCard parseVCardsFromSource:[NSURL fileURLWithPath:_path]];
50 }
51
52 - (void)printParsedObject: (NSArray *)_cards
53 {
54   NSEnumerator *cardObjects;
55   NGVCard *card;
56
57   cardObjects = [_cards objectEnumerator];
58   card = [cardObjects nextObject];
59   while (card)
60     {
61       NSLog (@"-------s\n%@\ne-------", [card versitString]);
62       card = [cardObjects nextObject];
63     }
64
65 #if 0
66   NSLog(@"  subcomponents: %@", [_object subComponents]);
67   
68   printf("%s", [[_object icalString] cString]);
69 #endif
70 }
71
72 /* run */
73
74 - (int)runWithArguments:(NSArray *)_args {
75   NSEnumerator      *args;
76   NSString          *arg;
77   
78   args = [_args objectEnumerator];
79   [args nextObject]; // process name ...
80
81   while ((arg = [args nextObject])) {
82     NSAutoreleasePool *pool2;
83
84     if ([arg hasPrefix:@"-"]) { /* consume defaults */
85       [args nextObject];
86       continue;
87     }
88     
89     pool2 = [[NSAutoreleasePool alloc] init];
90     {    
91       NSArray *cards;
92       
93       NS_DURING
94         cards = [self parseFile:arg];
95       NS_HANDLER
96         abort();
97       NS_ENDHANDLER;
98       
99       if (!cards)
100         NSLog(@"could not parse file: '%@'", arg);
101       else
102         [self printParsedObject:cards];
103     }
104     [pool2 release];
105   }
106   return 0;
107 }
108
109 @end /* vcsparsetest */
110
111 int main(int argc, char **argv, char **env)  {
112   NSAutoreleasePool *pool;
113   vcsparsetest *tool;
114   int rc;
115
116   pool = [[NSAutoreleasePool alloc] init];
117 #if LIB_FOUNDATION_LIBRARY  
118   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
119 #endif
120   
121   if ((tool = [[vcsparsetest alloc] init]) != nil) {
122     NS_DURING
123       rc = [tool runWithArguments:[[NSProcessInfo processInfo] arguments]];
124     NS_HANDLER
125       abort();
126     NS_ENDHANDLER;
127     
128     [tool release];
129   }
130   else
131     rc = 1;
132   
133   [pool release];
134   return rc;
135 }