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 #import <Foundation/Foundation.h>
23 #import <EOControl/EOControl.h>
24 #include <NGExtensions/NSFileManager+Extensions.h>
25 #include <NGExtensions/NGFileFolderInfoDataSource.h>
26 #include <NGExtensions/NGExtensions.h>
28 static void printDirRecord(NSString *path, NSDictionary *record) {
29 /* id uid gid date name */
38 fileId = [[record objectForKey:@"NSFileIdentifier"] description];
39 owner = [record objectForKey:NSFileOwnerAccountName];
40 gid = [[record objectForKey:@"NSFileGroupOwnerAccountNumber"] intValue];
41 size = [[record objectForKey:NSFileSize] intValue];
42 modDate = [[record objectForKey:NSFileModificationDate] description];
43 fname = [record objectForKey:@"NSFileName"];
44 ftype = [record objectForKey:NSFileType];
46 if ([ftype isEqualToString:NSFileTypeDirectory])
47 fname = [fname stringByAppendingString:@"/"];
48 else if ([ftype isEqualToString:NSFileTypeSocket])
49 fname = [fname stringByAppendingString:@"="];
50 else if ([ftype isEqualToString:NSFileTypeSymbolicLink])
51 fname = [fname stringByAppendingString:@"@"];
53 //NSLog(@"record: %@", record);
55 printf("%8s %8s %8i %8i %8s %s\n",
64 static void runOnDirPath(NSString *path) {
67 NSEnumerator *records;
69 NSArray *sortOrderings;
70 EOQualifier *qualifier;
73 fm = [NSFileManager defaultManager];
75 if ((ds = [fm dataSourceAtPath:path]) == nil) {
76 NSLog(@"could not get datasource for path: '%@'", path);
80 /* build fetch specification */
82 tmp = [[NSUserDefaults standardUserDefaults] stringForKey:@"qualifier"];
83 if ([tmp length] > 0) {
84 qualifier = [EOQualifier qualifierWithQualifierFormat:tmp];
86 NSLog(@"could not parse qualifier: %@", tmp);
91 tmp = [EOSortOrdering sortOrderingWithKey:@"NSFileName"
92 selector:EOCompareAscending];
93 sortOrderings = [NSArray arrayWithObject:tmp];
95 if ((qualifier != nil) || (sortOrderings != nil)) {
96 EOFetchSpecification *fs;
98 fs = [[EOFetchSpecification alloc] init];
99 [fs setQualifier:qualifier];
100 [fs setSortOrderings:sortOrderings];
102 [(id)ds setFetchSpecification:fs];
103 [fs release]; fs = nil;
108 records = [[ds fetchObjects] objectEnumerator];
112 while ((record = [records nextObject]))
113 printDirRecord(path, record);
116 static void runOnPath(NSString *path) {
120 fm = [NSFileManager defaultManager];
122 if (![fm fileExistsAtPath:path isDirectory:&isDir]) {
123 NSLog(@"file/directory does not exist: %@", path);
133 static void runit(NSArray *args) {
136 for (i = 1; i < [args count]; i++) {
139 path = [args objectAtIndex:i];
141 if ([path hasPrefix:@"-"]) { // TODO: there is a NSProcessInfo ext for that
150 int main(int argc, char **argv, char **env) {
151 NSAutoreleasePool *pool;
154 #if LIB_FOUNDATION_LIBRARY
155 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
157 pool = [[NSAutoreleasePool alloc] init];
159 args = [[NSProcessInfo processInfo] arguments];
160 if ([args count] < 1) {
161 NSLog(@"usage: %@ <files>", [args objectAtIndex:0]);
164 else if ([args count] == 1)
165 args = [args arrayByAddingObject:@"."];