]> err.no Git - sope/blob - sope-core/samples/testdirenum.m
Drop apache 1 build-dependency
[sope] / sope-core / samples / testdirenum.m
1 /*
2   Copyright (C) 2000-2005 SKYRIX Software AG
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 <EOControl/EOControl.h>
24 #include <NGExtensions/NSFileManager+Extensions.h>
25 #include <NGExtensions/NGFileFolderInfoDataSource.h>
26 #include <NGExtensions/NGDirectoryEnumerator.h>
27
28 @interface TestDirEnumTool : NSObject
29 @end
30
31 @implementation TestDirEnumTool
32
33 - (void)runWithArguments:(NSArray *)args {
34   NSFileManager *fm;
35   NGDirectoryEnumerator *e;
36   NSString      *cpath;
37
38   fm = [NSFileManager defaultManager];
39   
40   e = [[NGDirectoryEnumerator alloc] initWithFileManager:fm
41                                      directoryPath:[args objectAtIndex:1]];
42
43   NSLog(@"enum: %@", e);
44   
45   while ((cpath = [e nextObject])) {
46 #if 1
47     printf("%s\n", [cpath cString]);
48 #else
49     NSDictionary *record;
50
51     record = [e fileAttributes];
52     {
53       /* id uid gid date name */
54       NSString *fileId;
55       NSString *owner;
56       int      gid;
57       unsigned size;
58       NSString *modDate;
59       NSString *fname;
60       NSString *ftype;
61         
62       fileId  = [[record objectForKey:NSFileIdentifier] description];
63       owner   = [record  objectForKey:NSFileOwnerAccountName];
64       gid     = [[record objectForKey:NSFileGroupOwnerAccountNumber] intValue];
65       size    = [[record  objectForKey:NSFileSize] intValue];
66       modDate = [[record objectForKey:NSFileModificationDate] description];
67       fname   = [record  objectForKey:NSFileName];
68       ftype   = [record  objectForKey:NSFileType];
69       
70       if ([ftype isEqualToString:NSFileTypeDirectory])
71         fname = [fname stringByAppendingString:@"/"];
72       else if ([ftype isEqualToString:NSFileTypeSocket])
73         fname = [fname stringByAppendingString:@"="];
74       else if ([ftype isEqualToString:NSFileTypeSymbolicLink])
75         fname = [fname stringByAppendingString:@"@"];
76         
77       //NSLog(@"record: %@", record);
78         
79       printf("%8s  %8s  %8i  %8i  %8s  %s\n",
80              [fileId cString],
81              [owner  cString],
82              gid,
83              size,
84              [modDate cString],
85              [fname cString]);
86     }
87 #endif
88   }
89 }
90
91 @end /* TestDirEnumTool */
92
93 int main(int argc, char **argv, char **env) {
94   NSAutoreleasePool *pool;
95   NSArray *args;
96   id tool;
97   
98   pool = [[NSAutoreleasePool alloc] init];
99 #if LIB_FOUNDATION_LIBRARY
100   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
101 #endif
102   
103   args = [[NSProcessInfo processInfo] arguments];
104   if ([args count] < 1) {
105     NSLog(@"usage: %@ dir", [args objectAtIndex:0]);
106     exit(1);
107   }
108   else if ([args count] == 1)
109     args = [args arrayByAddingObject:@"."];
110   
111   tool = [[TestDirEnumTool alloc] init];
112   [tool runWithArguments:args];
113   
114   exit(0);
115   return 0;
116 }