2 Copyright (C) 2000-2003 SKYRIX Software AG
4 This file is part of OGo
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
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.
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
23 #import <Foundation/Foundation.h>
24 #import <EOControl/EOControl.h>
25 #include <NGExtensions/NSFileManager+Extensions.h>
26 #include <NGExtensions/NGFileFolderInfoDataSource.h>
27 #include <NGExtensions/NGExtensions.h>
29 int main(int argc, char **argv, char **env) {
30 NSAutoreleasePool *pool;
35 #if LIB_FOUNDATION_LIBRARY
36 [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
38 pool = [[NSAutoreleasePool alloc] init];
40 args = [[NSProcessInfo processInfo] arguments];
41 if ([args count] < 1) {
42 NSLog(@"usage: %@ <files>", [args objectAtIndex:0]);
45 else if ([args count] == 1)
46 args = [args arrayByAddingObject:@"."];
48 fm = [NSFileManager defaultManager];
50 for (i = 1; i < [args count]; i++) {
54 path = [args objectAtIndex:i];
56 if ([path hasPrefix:@"-"]) {
61 if (![fm fileExistsAtPath:path isDirectory:&isDir]) {
62 NSLog(@"file/directory does not exist: %@", path);
68 NSEnumerator *records;
70 NSArray *sortOrderings;
71 EOQualifier *qualifier;
74 if ((ds = [fm dataSourceAtPath:path]) == nil) {
75 NSLog(@"could not get datasource for path: '%@'", path);
79 /* build fetch specification */
81 tmp = [[NSUserDefaults standardUserDefaults] stringForKey:@"qualifier"];
82 if ([tmp length] > 0) {
83 qualifier = [EOQualifier qualifierWithQualifierFormat:tmp];
85 NSLog(@"could not parse qualifier: %@", tmp);
90 tmp = [EOSortOrdering sortOrderingWithKey:@"NSFileName"
91 selector:EOCompareAscending];
92 sortOrderings = [NSArray arrayWithObject:tmp];
94 if ((qualifier != nil) || (sortOrderings != nil)) {
95 EOFetchSpecification *fs;
97 fs = [[EOFetchSpecification alloc] init];
98 [fs setQualifier:qualifier];
99 [fs setSortOrderings:sortOrderings];
101 [(id)ds setFetchSpecification:fs];
102 [fs release]; fs = nil;
107 records = [[ds fetchObjects] objectEnumerator];
111 while ((record = [records nextObject])) {
112 /* id uid gid date name */
121 fileId = [[record objectForKey:@"NSFileIdentifier"] description];
122 owner = [record objectForKey:NSFileOwnerAccountName];
123 gid = [[record objectForKey:@"NSFileGroupOwnerAccountNumber"] intValue];
124 size = [[record objectForKey:NSFileSize] intValue];
125 modDate = [[record objectForKey:NSFileModificationDate] description];
126 fname = [record objectForKey:@"NSFileName"];
127 ftype = [record objectForKey:NSFileType];
129 if ([ftype isEqualToString:NSFileTypeDirectory])
130 fname = [fname stringByAppendingString:@"/"];
131 else if ([ftype isEqualToString:NSFileTypeSocket])
132 fname = [fname stringByAppendingString:@"="];
133 else if ([ftype isEqualToString:NSFileTypeSymbolicLink])
134 fname = [fname stringByAppendingString:@"@"];
136 //NSLog(@"record: %@", record);
138 printf("%8s %8s %8i %8i %8s %s\n",