]> err.no Git - sope/blob - sope-gdl1/GDLContentStore/gcs_cat.m
fixed some NGMail framework build issue
[sope] / sope-gdl1 / GDLContentStore / gcs_cat.m
1 /*
2   Copyright (C) 2004-2005 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #import <Foundation/NSObject.h>
23
24 @class NSUserDefaults, NSArray;
25 @class GCSFolderManager;
26
27 @interface Tool : NSObject
28 {
29   NSUserDefaults   *ud;
30   GCSFolderManager *folderManager;
31 }
32
33 + (int)runWithArgs:(NSArray *)_args;
34 - (int)run;
35
36 @end
37
38 #include <GDLContentStore/GCSFolder.h>
39 #include <GDLContentStore/GCSFolderManager.h>
40 #include "common.h"
41
42 @implementation Tool
43
44 - (id)init {
45   if ((self = [super init])) {
46     self->ud            = [[NSUserDefaults standardUserDefaults]   retain];
47     self->folderManager = [[GCSFolderManager defaultFolderManager] retain];
48   }
49   return self;
50 }
51 - (void)dealloc {
52   [self->ud            release];
53   [self->folderManager release];
54   [super dealloc];
55 }
56
57 /* operation */
58
59 - (int)runOnPath:(NSString *)_path {
60   GCSFolder   *folder;
61   NSString    *dirname, *filename;
62   NSString    *content;
63   
64   dirname  = [_path stringByDeletingLastPathComponent];
65   filename = [_path lastPathComponent];
66   
67   if ((folder = [self->folderManager folderAtPath:dirname]) == nil) {
68     [self logWithFormat:@"did not find folder for file: '%@'", dirname];
69     return 1;
70   }
71   
72   if ((content = [folder fetchContentWithName:filename]) == nil) {
73     [self logWithFormat:@"did not find file: '%@'", _path];
74     return 1;
75   }
76   
77   printf("%s\n", [content cString]);
78   
79   return 0;
80 }
81
82 - (int)run {
83   NSEnumerator *e;
84   NSString *path;
85   
86   [self logWithFormat:@"manager: %@", self->folderManager];
87   
88   if (![self->folderManager canConnect]) {
89     [self logWithFormat:@"cannot connect folder-info database!"];
90     return 1;
91   }
92   
93   e = [[[NSProcessInfo processInfo] argumentsWithoutDefaults] 
94                        objectEnumerator];
95   [e nextObject]; // skip tool name
96   
97   while ((path = [e nextObject]))
98     [self runOnPath:path];
99   
100   return 0;
101 }
102 + (int)runWithArgs:(NSArray *)_args {
103   return [(Tool *)[[[self alloc] init] autorelease] run];
104 }
105
106 @end /* Tool */
107
108 int main(int argc, char **argv, char **env) {
109   NSAutoreleasePool *pool;
110   int rc;
111
112   pool = [[NSAutoreleasePool alloc] init];
113 #if LIB_FOUNDATION_LIBRARY  
114   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
115 #endif
116
117   rc = [Tool runWithArgs:
118                [[NSProcessInfo processInfo] argumentsWithoutDefaults]];
119   
120   [pool release];
121   return rc;
122 }