]> err.no Git - sope/blob - sope-gdl1/GDLContentStore/gcs_ls.m
fixed a Tiger warning
[sope] / sope-gdl1 / GDLContentStore / gcs_ls.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   NSArray   *subfolders;
61   unsigned  i, count;
62   GCSFolder *folder;
63   
64   [self logWithFormat:@"ls path: '%@'", _path];
65   
66 #if 0 // we do not necessarily need the whole hierarchy
67   if (![self->folderManager folderExistsAtPath:_path])
68     [self logWithFormat:@"folder does not exist: '%@'", _path];
69 #endif
70   
71   subfolders = [self->folderManager
72                     listSubFoldersAtPath:_path
73                     recursive:[ud boolForKey:@"r"]];
74   if (subfolders == nil) {
75     [self logWithFormat:@"cannot list folder: '%@'", _path];
76     return 1;
77   }
78   
79   for (i = 0, count = [subfolders count]; i < count; i++) {
80     printf("%s\n", [[subfolders objectAtIndex:i] cString]);
81   }
82
83   folder = [self->folderManager folderAtPath:_path];
84   
85   if ([folder isNotNull]) {
86     NSLog(@"folder: %@", folder);
87     
88     NSLog(@"  can%s connect store: %@", [folder canConnectStore] ? "" : "not",
89           [[folder location] absoluteString]);
90     NSLog(@"  can%s connect quick: %@", [folder canConnectQuick] ? "" : "not",
91           [[folder quickLocation] absoluteString]);
92   }
93   else {
94     NSLog(@"ERROR: could not create folder object for path: '%@'", _path);
95   }
96   
97   return 0;
98 }
99
100 - (int)run {
101   NSEnumerator *e;
102   NSString *path;
103   
104   [self logWithFormat:@"manager: %@", self->folderManager];
105
106   if (![self->folderManager canConnect]) {
107     [self logWithFormat:@"cannot connect folder-info database!"];
108     return 1;
109   }
110   
111   e = [[[NSProcessInfo processInfo] argumentsWithoutDefaults] 
112                        objectEnumerator];
113   [e nextObject]; // skip tool name
114   
115   while ((path = [e nextObject]) != nil)
116     [self runOnPath:path];
117   
118   return 0;
119 }
120 + (int)runWithArgs:(NSArray *)_args {
121   return [(Tool *)[[[self alloc] init] autorelease] run];
122 }
123
124 @end /* Tool */
125
126 int main(int argc, char **argv, char **env) {
127   NSAutoreleasePool *pool;
128   int rc;
129
130   pool = [[NSAutoreleasePool alloc] init];
131 #if LIB_FOUNDATION_LIBRARY  
132   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
133 #endif
134
135   rc = [Tool runWithArgs:
136                [[NSProcessInfo processInfo] argumentsWithoutDefaults]];
137   
138   [pool release];
139   return rc;
140 }