]> err.no Git - sope/blob - sope-core/samples/sope-rsrclookup.m
include config.make in makefiles
[sope] / sope-core / samples / sope-rsrclookup.m
1 /*
2   Copyright (C) 2000-2004 SKYRIX Software AG
3
4   This file is part of OpenGroupware.org.
5
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
9   later version.
10
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.
15
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
19   02111-1307, USA.
20 */
21
22 #include <NGExtensions/NGResourceLocator.h>
23 #include "common.h"
24
25 static void usage(void) {
26   fprintf(stderr, 
27           "usage: sope-rsrclookup <gnustep-subdir> <fhs-subdir> <rsrc>\n");
28 }
29
30 static void testit(NSArray *args) {
31   NGResourceLocator *loc;
32   NSString *gs, *fhs, *rsrc;
33   
34   if ([args count] < 3) {
35     usage();
36     exit(2);
37   }
38   
39   gs   = [args objectAtIndex:1];
40   fhs  = [args objectAtIndex:2];
41   loc  = [NGResourceLocator resourceLocatorForGNUstepPath:gs fhsPath:fhs];
42   rsrc = [args count] < 4 ? nil : [args objectAtIndex:3];
43   
44   if (rsrc == nil) {
45     NSArray *a;
46     
47     if ((a = [loc gsRootPathes]) != nil)
48       NSLog(@"GNUstep Lookup Pathes: %@", a);
49
50     if ((a = [loc fhsRootPathes]) != nil)
51       NSLog(@"FHS Lookup Pathes: %@", a);
52
53     if ((a = [loc searchPathes]) != nil)
54       NSLog(@"Pathes: %@", a);
55   }
56   else {
57     NSString *p;
58     
59     p = [loc lookupFileWithName:rsrc];
60     if (p == nil) {
61       fprintf(stderr, "did not find resource: %s\n", [rsrc cString]);
62       exit(1);
63     }
64     printf("%s\n", [p cString]);
65   }
66 }
67
68 int main(int argc, char **argv, char **env) {
69   NSAutoreleasePool *pool;
70
71   pool = [[NSAutoreleasePool alloc] init];
72 #if LIB_FOUNDATION_LIBRARY  
73   [NSProcessInfo initializeWithArguments:argv count:argc environment:env];
74 #endif
75   
76   testit([[NSProcessInfo processInfo] argumentsWithoutDefaults]);
77   
78   [pool release];
79   return 0;
80 }