/*
- Copyright (C) 2000-2004 SKYRIX Software AG
+ Copyright (C) 2000-2006 SKYRIX Software AG
+ Copyright (C) 2006 Helge Hess
- This file is part of OpenGroupware.org.
+ This file is part of SOPE.
- OGo is free software; you can redistribute it and/or modify it under
+ SOPE is free software; you can redistribute it and/or modify it under
the terms of the GNU Lesser General Public License as published by the
Free Software Foundation; either version 2, or (at your option) any
later version.
- OGo is distributed in the hope that it will be useful, but WITHOUT ANY
+ SOPE is distributed in the hope that it will be useful, but WITHOUT ANY
WARRANTY; without even the implied warranty of MERCHANTABILITY or
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
License for more details.
You should have received a copy of the GNU Lesser General Public
- License along with OGo; see the file COPYING. If not, write to the
+ License along with SOPE; see the file COPYING. If not, write to the
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
NSString *apath;
if (pathes != nil)
- return [pathes isNotNull] ? pathes : nil;
+ return [pathes isNotNull] ? pathes : (NSArray *)nil;
env = [[NSProcessInfo processInfo] environment];
if ((apath = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil)
- (NSArray *)fhsRootPathes {
// TODO: we probably want to make this configurable?! At least with an envvar
static NSArray *pathes = nil;
- if (pathes == nil)
- pathes = [[NSArray alloc] initWithObjects:@"/usr/local/", @"/usr/", nil];
+ if (pathes == nil) {
+ pathes = [[NSArray alloc] initWithObjects:
+#ifdef FHS_INSTALL_ROOT
+ FHS_INSTALL_ROOT,
+#endif
+ @"/usr/local/", @"/usr/", nil];
+ }
return pathes;
}
e = ([self->gsSubPath length] > 0)
? [[self gsRootPathes] objectEnumerator]
- : nil;
- while ((p = [e nextObject])) {
+ : (NSEnumerator *)nil;
+ while ((p = [e nextObject]) != nil) {
p = [p stringByAppendingPathComponent:self->gsSubPath];
if ([ma containsObject:p])
continue;
e = ([self->fhsSubPath length] > 0)
? [[self fhsRootPathes] objectEnumerator]
- : nil;
- while ((p = [e nextObject])) {
+ : (NSEnumerator *)nil;
+ while ((p = [e nextObject]) != nil) {
p = [p stringByAppendingPathComponent:self->fhsSubPath];
if ([ma containsObject:p])
continue;
if (self->nameToPathCache == nil)
self->nameToPathCache = [[NSMutableDictionary alloc] initWithCapacity:64];
- [self->nameToPathCache setObject:_path?_path:(id)[NSNull null] forKey:_name];
+ [self->nameToPathCache setObject:(_path ? _path : (NSString *)[NSNull null])
+ forKey:_name];
}
/* operation */
if (![_name isNotNull] || [_name length] == 0)
return nil;
- if ((p = [self->nameToPathCache objectForKey:_name]))
- return [p isNotNull] ? p : nil;
+ if ((p = [self->nameToPathCache objectForKey:_name]) != nil)
+ return [p isNotNull] ? p : (NSString *)nil;
e = [[self searchPathes] objectEnumerator];
- while ((p = [e nextObject])) {
+ while ((p = [e nextObject]) != nil) {
p = [p stringByAppendingPathComponent:_name];
if (![self->fileManager fileExistsAtPath:p])
}
- (NSString *)lookupFileWithName:(NSString *)_name extension:(NSString *)_ext {
- return [self lookupFileWithName:[_name stringByAppendingPathExtension:_ext]];
+ if ([_ext isNotNull] && [_ext length] > 0)
+ _name = [_name stringByAppendingPathExtension:_ext];
+ return [self lookupFileWithName:_name];
+}
+
+- (NSArray *)lookupAllFilesWithExtension:(NSString *)_ext
+ doReturnFullPath:(BOOL)_withPath
+{
+ /* only deliver each filename once */
+ NSMutableArray *pathes;
+ NSMutableSet *uniquer;
+ NSArray *lSearchPathes;
+ unsigned i, count;
+
+ _ext = ([_ext length] > 0)
+ ? [@"." stringByAppendingString:_ext]
+ : (NSString *)nil;
+
+ uniquer = [NSMutableSet setWithCapacity:128];
+ pathes = _withPath ? [NSMutableArray arrayWithCapacity:64] : nil;
+ lSearchPathes = [self searchPathes];
+
+ for (i = 0, count = [lSearchPathes count]; i < count; i++) {
+ NSArray *filenames;
+ unsigned j, jcount;
+
+ filenames = [self->fileManager directoryContentsAtPath:
+ [lSearchPathes objectAtIndex:i]];
+
+ for (j = 0, jcount = [filenames count]; j < jcount; j++) {
+ NSString *fn, *pn;
+
+ fn = [filenames objectAtIndex:j];
+ if (_ext != nil) {
+ if (![fn hasSuffix:_ext])
+ continue;
+ }
+
+ if ([uniquer containsObject:fn])
+ continue;
+
+ [uniquer addObject:fn];
+
+ /* build and cache path */
+ pn = [[lSearchPathes objectAtIndex:i] stringByAppendingPathComponent:fn];
+ [self cachePath:pn forName:fn];
+ if (_withPath) [pathes addObject:pn];
+ }
+ }
+
+ return _withPath ? (NSArray *)pathes : [uniquer allObjects];
+}
+
+/* description */
+
+- (NSString *)description {
+ NSMutableString *ms;
+
+ ms = [NSMutableString stringWithCapacity:128];
+ [ms appendFormat:@"<0x%p[%@]:", self, NSStringFromClass([self class])];
+
+ [ms appendFormat:@" gs=%@ fhs=%@", self->gsSubPath, self->fhsSubPath];
+
+ [ms appendString:@" cache"];
+ if (self->flags.cacheSearchPathes)
+ [ms appendString:@":pathes"];
+ if (self->flags.cachePathHits)
+ [ms appendString:@":hits"];
+ if (self->flags.cachePathMisses)
+ [ms appendString:@":misses"];
+ [ms appendFormat:@":#%d", [self->nameToPathCache count]];
+
+ [ms appendString:@">"];
+ return ms;
}
@end /* NGResourceLocator */