2004-09-23 Helge Hess <helge.hess@skyrix.com>
+ * added NGResourceLocator class (v4.2.116)
+
* moved NGCString to Recycler (was not compiled since v4.2.93)
2004-09-21 Marcus Mueller <znek@mulle-kybernetik.com>
NGStack.h \
NGObjectMacros.h \
NGCalendarDateRange.h \
+ NGResourceLocator.h \
libNGExtensions_OBJC_FILES = \
NGExtensions.m \
NGQuotedPrintableCoding.m \
NGStack.m \
NGCalendarDateRange.m \
+ NGResourceLocator.m \
ifeq ($(FOUNDATION_LIB), apple)
libNGExtensions_OBJC_FILES += FileObjectHolder.m
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#include "NGBase64Coding.h"
#include "common.h"
/*
- Copyright (C) 2000-2003 SKYRIX Software AG
+ Copyright (C) 2000-2004 SKYRIX Software AG
- This file is part of OGo
+ This file is part of OpenGroupware.org.
OGo 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, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#ifndef __NGExtensions_EOCacheDataSource_H__
#define __NGExtensions_EOCacheDataSource_H__
--- /dev/null
+/*
+ Copyright (C) 2000-2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo 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
+ 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
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#ifndef __NGExtensions_NGResourceLocator_H__
+#define __NGExtensions_NGResourceLocator_H__
+
+#import <Foundation/NSObject.h>
+
+/*
+ NGResourceLocator
+
+ This class can be used by libraries to lookup resources in either the GNUstep
+ hierarchy or in FHS locations (/usr/local etc).
+*/
+
+@class NSString, NSArray, NSFileManager, NSMutableDictionary;
+
+@interface NGResourceLocator : NSObject
+{
+ NSString *gsSubPath;
+ NSString *fhsSubPath;
+ NSFileManager *fileManager;
+
+ NSArray *searchPathes;
+ NSMutableDictionary *nameToPathCache;
+
+ struct {
+ int cacheSearchPathes:1;
+ int cachePathHits:1;
+ int cachePathMisses:1;
+ int reserved:29;
+ } flags;
+}
+
++ (id)resourceLocatorForGNUstepPath:(NSString *)_path fhsPath:(NSString *)_fhs;
+- (id)initWithGNUstepPath:(NSString *)_path fhsPath:(NSString *)_fhs;
+
+/* resource pathes */
+
+- (NSArray *)gsRootPathes; /* GNUSTEP_PATHPREFIX_LIST or MacOSX */
+- (NSArray *)fhsRootPathes;
+- (NSArray *)searchPathes;
+
+/* operations */
+
+- (NSString *)lookupFileWithName:(NSString *)_name;
+- (NSString *)lookupFileWithName:(NSString *)_name extension:(NSString *)_ext;
+
+@end
+
+#endif /* __NGExtensions_NGResourceLocator_H__ */
--- /dev/null
+/*
+ Copyright (C) 2000-2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo 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
+ 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
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include "NGResourceLocator.h"
+#include "NSNull+misc.h"
+#include "common.h"
+
+@implementation NGResourceLocator
+
++ (id)resourceLocatorForGNUstepPath:(NSString *)_path fhsPath:(NSString *)_fhs{
+ return [[[self alloc] initWithGNUstepPath:_path fhsPath:_fhs] autorelease];
+}
+
+- (id)initWithGNUstepPath:(NSString *)_path fhsPath:(NSString *)_fhs {
+ if ((self = [super init])) {
+ self->gsSubPath = [_path copy];
+ self->fhsSubPath = [_fhs copy];
+ self->fileManager = [[NSFileManager defaultManager] retain];
+
+ self->flags.cacheSearchPathes = 1;
+ self->flags.cachePathMisses = 1;
+ self->flags.cachePathHits = 1;
+ }
+ return self;
+}
+- (id)init {
+ return [self initWithGNUstepPath:@"Library/Resources" fhsPath:@"share"];
+}
+
+- (void)dealloc {
+ [self->nameToPathCache release];
+ [self->searchPathes release];
+ [self->fhsSubPath release];
+ [self->gsSubPath release];
+ [self->fileManager release];
+ [super dealloc];
+}
+
+/* search pathes */
+
+- (NSArray *)gsRootPathes {
+ static NSArray *pathes = nil;
+ NSDictionary *env;
+ NSString *apath;
+
+ if (pathes != nil)
+ return [pathes isNotNull] ? pathes : nil;
+
+ env = [[NSProcessInfo processInfo] environment];
+ if ((apath = [env objectForKey:@"GNUSTEP_PATHPREFIX_LIST"]) == nil)
+ apath = [env objectForKey:@"GNUSTEP_PATHLIST"];
+
+ if (![apath isNotNull]) return nil;
+ pathes = [[apath componentsSeparatedByString:@":"] copy];
+ return pathes;
+}
+
+- (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];
+ return pathes;
+}
+
+- (NSArray *)collectSearchPathes {
+ NSMutableArray *ma;
+ NSEnumerator *e;
+ NSString *p;
+
+ ma = [NSMutableArray arrayWithCapacity:6];
+
+ e = ([self->gsSubPath length] > 0)
+ ? [[self gsRootPathes] objectEnumerator]
+ : nil;
+ while ((p = [e nextObject])) {
+ p = [p stringByAppendingPathComponent:self->gsSubPath];
+ if ([ma containsObject:p])
+ continue;
+
+ if (![self->fileManager fileExistsAtPath:p])
+ continue;
+
+ [ma addObject:p];
+ }
+
+ e = ([self->fhsSubPath length] > 0)
+ ? [[self fhsRootPathes] objectEnumerator]
+ : nil;
+ while ((p = [e nextObject])) {
+ p = [p stringByAppendingPathComponent:self->fhsSubPath];
+ if ([ma containsObject:p])
+ continue;
+
+ if (![self->fileManager fileExistsAtPath:p])
+ continue;
+
+ [ma addObject:p];
+ }
+
+ return ma;
+}
+
+- (NSArray *)searchPathes {
+ NSArray *a;
+
+ if (self->searchPathes != nil)
+ return self->searchPathes;
+
+ a = [self collectSearchPathes];
+ if (self->flags.cacheSearchPathes) {
+ ASSIGNCOPY(self->searchPathes, a);
+ return self->searchPathes; /* return copy */
+ }
+
+ return a;
+}
+
+/* cache */
+
+- (void)cachePath:(NSString *)_path forName:(NSString *)_name {
+ if (self->nameToPathCache == nil)
+ self->nameToPathCache = [[NSMutableDictionary alloc] initWithCapacity:64];
+
+ [self->nameToPathCache setObject:_path?_path:(id)[NSNull null] forKey:_name];
+}
+
+/* operation */
+
+- (NSString *)lookupFileWithName:(NSString *)_name {
+ NSEnumerator *e;
+ NSString *p;
+
+ if (![_name isNotNull] || [_name length] == 0)
+ return nil;
+ if ((p = [self->nameToPathCache objectForKey:_name]))
+ return [p isNotNull] ? p : nil;
+
+ e = [[self searchPathes] objectEnumerator];
+ while ((p = [e nextObject])) {
+ p = [p stringByAppendingPathComponent:_name];
+
+ if (![self->fileManager fileExistsAtPath:p])
+ continue;
+
+ [self cachePath:p forName:_name];
+ return p;
+ }
+
+ if (self->flags.cachePathMisses)
+ [self cachePath:nil forName:_name];
+ return nil;
+}
+
+- (NSString *)lookupFileWithName:(NSString *)_name extension:(NSString *)_ext {
+ return [self lookupFileWithName:[_name stringByAppendingPathExtension:_ext]];
+}
+
+@end /* NGResourceLocator */
# version
-SUBMINOR_VERSION:=115
+SUBMINOR_VERSION:=116
# v4.3.115 requires libFoundation v1.0.59
# v4.2.72 requires libEOControl v4.2.39
+2004-09-23 Helge Hess <helge.hess@skyrix.com>
+
+ * addd sope-rsrclookup.m tool for tetsing NGResourceLocator
+
+ * fmdls.m: some code cleanups
+
2004-08-29 Helge Hess <helge.hess@opengroupware.org>
* moved test_qpdecode to NGMime/samples
httpu_notify \
parserule \
testurl \
+ sope-rsrclookup
ifneq ($(OBJC_RUNTIME_LIB),apple)
TOOL_NAME += subclassing
parserule_OBJC_FILES = parserule.m
httpu_notify_OBJC_FILES = httpu_notify.m
testurl_OBJC_FILES = testurl.m
+sope-rsrclookup_OBJC_FILES = sope-rsrclookup.m
-include GNUmakefile.preamble
include $(GNUSTEP_MAKEFILES)/tool.make
/*
- Copyright (C) 2000-2003 SKYRIX Software AG
+ Copyright (C) 2000-2004 SKYRIX Software AG
- This file is part of OGo
+ This file is part of OpenGroupware.org.
OGo 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, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#import "EOQualTool.h"
#include "common.h"
EOQualTool *tool;
int res;
- pool = [NSAutoreleasePool new];
-
+ pool = [[NSAutoreleasePool alloc] init];
#if LIB_FOUNDATION_LIBRARY
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
#endif
/*
- Copyright (C) 2000-2003 SKYRIX Software AG
+ Copyright (C) 2000-2004 SKYRIX Software AG
- This file is part of OGo
+ This file is part of OpenGroupware.org.
OGo 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, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#import <Foundation/Foundation.h>
#import <EOControl/EOControl.h>
#include <NGExtensions/NGFileFolderInfoDataSource.h>
#include <NGExtensions/NGExtensions.h>
+static void printDirRecord(NSString *path, NSDictionary *record) {
+ /* id uid gid date name */
+ NSString *fileId;
+ NSString *owner;
+ int gid;
+ unsigned size;
+ NSString *modDate;
+ NSString *fname;
+ NSString *ftype;
+
+ fileId = [[record objectForKey:@"NSFileIdentifier"] description];
+ owner = [record objectForKey:NSFileOwnerAccountName];
+ gid = [[record objectForKey:@"NSFileGroupOwnerAccountNumber"] intValue];
+ size = [[record objectForKey:NSFileSize] intValue];
+ modDate = [[record objectForKey:NSFileModificationDate] description];
+ fname = [record objectForKey:@"NSFileName"];
+ ftype = [record objectForKey:NSFileType];
+
+ if ([ftype isEqualToString:NSFileTypeDirectory])
+ fname = [fname stringByAppendingString:@"/"];
+ else if ([ftype isEqualToString:NSFileTypeSocket])
+ fname = [fname stringByAppendingString:@"="];
+ else if ([ftype isEqualToString:NSFileTypeSymbolicLink])
+ fname = [fname stringByAppendingString:@"@"];
+
+ //NSLog(@"record: %@", record);
+
+ printf("%8s %8s %8i %8i %8s %s\n",
+ [fileId cString],
+ [owner cString],
+ gid,
+ size,
+ [modDate cString],
+ [fname cString]);
+}
+
+static void runOnDirPath(NSString *path) {
+ NSFileManager *fm;
+ EODataSource *ds;
+ NSEnumerator *records;
+ NSDictionary *record;
+ NSArray *sortOrderings;
+ EOQualifier *qualifier;
+ id tmp;
+
+ fm = [NSFileManager defaultManager];
+
+ if ((ds = [fm dataSourceAtPath:path]) == nil) {
+ NSLog(@"could not get datasource for path: '%@'", path);
+ return;
+ }
+
+ /* build fetch specification */
+
+ tmp = [[NSUserDefaults standardUserDefaults] stringForKey:@"qualifier"];
+ if ([tmp length] > 0) {
+ qualifier = [EOQualifier qualifierWithQualifierFormat:tmp];
+ if (qualifier == nil)
+ NSLog(@"could not parse qualifier: %@", tmp);
+ }
+ else
+ qualifier = nil;
+
+ tmp = [EOSortOrdering sortOrderingWithKey:@"NSFileName"
+ selector:EOCompareAscending];
+ sortOrderings = [NSArray arrayWithObject:tmp];
+
+ if ((qualifier != nil) || (sortOrderings != nil)) {
+ EOFetchSpecification *fs;
+
+ fs = [[EOFetchSpecification alloc] init];
+ [fs setQualifier:qualifier];
+ [fs setSortOrderings:sortOrderings];
+
+ [(id)ds setFetchSpecification:fs];
+ [fs release]; fs = nil;
+ }
+
+ /* perform fetch */
+
+ records = [[ds fetchObjects] objectEnumerator];
+
+ /* print out */
+
+ while ((record = [records nextObject]))
+ printDirRecord(path, record);
+}
+
+static void runOnPath(NSString *path) {
+ NSFileManager *fm;
+ BOOL isDir;
+
+ fm = [NSFileManager defaultManager];
+
+ if (![fm fileExistsAtPath:path isDirectory:&isDir]) {
+ NSLog(@"file/directory does not exist: %@", path);
+ return;
+ }
+
+ if (isDir)
+ runOnDirPath(path);
+ else
+ /* a file */;
+}
+
+static void runit(NSArray *args) {
+ int i;
+
+ for (i = 1; i < [args count]; i++) {
+ NSString *path;
+
+ path = [args objectAtIndex:i];
+
+ if ([path hasPrefix:@"-"]) { // TODO: there is a NSProcessInfo ext for that
+ i++;
+ continue;
+ }
+
+ runOnPath(path);
+ }
+}
+
int main(int argc, char **argv, char **env) {
NSAutoreleasePool *pool;
NSArray *args;
- NSFileManager *fm;
- int i;
#if LIB_FOUNDATION_LIBRARY
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
else if ([args count] == 1)
args = [args arrayByAddingObject:@"."];
- fm = [NSFileManager defaultManager];
-
- for (i = 1; i < [args count]; i++) {
- NSString *path;
- BOOL isDir;
-
- path = [args objectAtIndex:i];
-
- if ([path hasPrefix:@"-"]) {
- i++;
- continue;
- }
-
- if (![fm fileExistsAtPath:path isDirectory:&isDir]) {
- NSLog(@"file/directory does not exist: %@", path);
- continue;
- }
-
- if (isDir) {
- EODataSource *ds;
- NSEnumerator *records;
- NSDictionary *record;
- NSArray *sortOrderings;
- EOQualifier *qualifier;
- id tmp;
-
- if ((ds = [fm dataSourceAtPath:path]) == nil) {
- NSLog(@"could not get datasource for path: '%@'", path);
- continue;
- }
-
- /* build fetch specification */
-
- tmp = [[NSUserDefaults standardUserDefaults] stringForKey:@"qualifier"];
- if ([tmp length] > 0) {
- qualifier = [EOQualifier qualifierWithQualifierFormat:tmp];
- if (qualifier == nil)
- NSLog(@"could not parse qualifier: %@", tmp);
- }
- else
- qualifier = nil;
-
- tmp = [EOSortOrdering sortOrderingWithKey:@"NSFileName"
- selector:EOCompareAscending];
- sortOrderings = [NSArray arrayWithObject:tmp];
-
- if ((qualifier != nil) || (sortOrderings != nil)) {
- EOFetchSpecification *fs;
-
- fs = [[EOFetchSpecification alloc] init];
- [fs setQualifier:qualifier];
- [fs setSortOrderings:sortOrderings];
-
- [(id)ds setFetchSpecification:fs];
- [fs release]; fs = nil;
- }
-
- /* perform fetch */
-
- records = [[ds fetchObjects] objectEnumerator];
-
- /* print out */
-
- while ((record = [records nextObject])) {
- /* id uid gid date name */
- NSString *fileId;
- NSString *owner;
- int gid;
- unsigned size;
- NSString *modDate;
- NSString *fname;
- NSString *ftype;
-
- fileId = [[record objectForKey:@"NSFileIdentifier"] description];
- owner = [record objectForKey:NSFileOwnerAccountName];
- gid = [[record objectForKey:@"NSFileGroupOwnerAccountNumber"] intValue];
- size = [[record objectForKey:NSFileSize] intValue];
- modDate = [[record objectForKey:NSFileModificationDate] description];
- fname = [record objectForKey:@"NSFileName"];
- ftype = [record objectForKey:NSFileType];
-
- if ([ftype isEqualToString:NSFileTypeDirectory])
- fname = [fname stringByAppendingString:@"/"];
- else if ([ftype isEqualToString:NSFileTypeSocket])
- fname = [fname stringByAppendingString:@"="];
- else if ([ftype isEqualToString:NSFileTypeSymbolicLink])
- fname = [fname stringByAppendingString:@"@"];
-
- //NSLog(@"record: %@", record);
-
- printf("%8s %8s %8i %8i %8s %s\n",
- [fileId cString],
- [owner cString],
- gid,
- size,
- [modDate cString],
- [fname cString]);
- }
- }
- else {
- /* a file */
- }
- }
+ runit(args);
[pool release];
exit(0);
--- /dev/null
+/*
+ Copyright (C) 2000-2004 SKYRIX Software AG
+
+ This file is part of OpenGroupware.org.
+
+ OGo 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
+ 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
+ Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
+ 02111-1307, USA.
+*/
+
+#include <NGExtensions/NGResourceLocator.h>
+#include "common.h"
+
+static void usage(void) {
+ fprintf(stderr,
+ "usage: sope-rsrclookup <gnustep-subdir> <fhs-subdir> <rsrc>\n");
+}
+
+static void testit(NSArray *args) {
+ NGResourceLocator *loc;
+ NSString *gs, *fhs, *rsrc;
+
+ if ([args count] < 3) {
+ usage();
+ exit(2);
+ }
+
+ gs = [args objectAtIndex:1];
+ fhs = [args objectAtIndex:2];
+ loc = [NGResourceLocator resourceLocatorForGNUstepPath:gs fhsPath:fhs];
+ rsrc = [args count] < 4 ? nil : [args objectAtIndex:3];
+
+ if (rsrc == nil) {
+ NSArray *a;
+
+ if ((a = [loc gsRootPathes]) != nil)
+ NSLog(@"GNUstep Lookup Pathes: %@", a);
+
+ if ((a = [loc fhsRootPathes]) != nil)
+ NSLog(@"FHS Lookup Pathes: %@", a);
+
+ if ((a = [loc searchPathes]) != nil)
+ NSLog(@"Pathes: %@", a);
+ }
+ else {
+ NSString *p;
+
+ p = [loc lookupFileWithName:rsrc];
+ if (p == nil) {
+ fprintf(stderr, "did not find resource: %s\n", [rsrc cString]);
+ exit(1);
+ }
+ printf("%s\n", [p cString]);
+ }
+}
+
+int main(int argc, char **argv, char **env) {
+ NSAutoreleasePool *pool;
+
+ pool = [[NSAutoreleasePool alloc] init];
+#if LIB_FOUNDATION_LIBRARY
+ [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
+#endif
+
+ testit([[NSProcessInfo processInfo] argumentsWithoutDefaults]);
+
+ [pool release];
+ return 0;
+}
Free Software Foundation, 59 Temple Place - Suite 330, Boston, MA
02111-1307, USA.
*/
-// $Id$
#import <Foundation/Foundation.h>
#include <NGExtensions/NGObjCRuntime.h>