1995-08-02 18:51:42 +00:00
|
|
|
/* nsbundle - Program to test out dynamic linking via NSBundle.
|
1996-04-16 22:03:52 +00:00
|
|
|
Copyright (C) 1993,1994,1995, 1996 Free Software Foundation, Inc.
|
1995-08-02 18:51:42 +00:00
|
|
|
|
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Date: Jul 1995
|
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
1995-08-02 18:51:42 +00:00
|
|
|
|
|
|
|
*/
|
1997-09-13 17:52:31 +00:00
|
|
|
#ifndef __MINGW32__
|
1995-08-02 18:51:42 +00:00
|
|
|
#include <sys/param.h>
|
1997-09-13 17:52:31 +00:00
|
|
|
#endif
|
1995-08-02 18:51:42 +00:00
|
|
|
#include "Foundation/NSBundle.h"
|
|
|
|
#include "Foundation/NSException.h"
|
|
|
|
#include "Foundation/NSString.h"
|
1998-10-03 05:11:05 +00:00
|
|
|
#include <Foundation/NSAutoreleasePool.h>
|
2001-04-10 03:27:01 +00:00
|
|
|
#include <Foundation/NSProcessInfo.h>
|
1995-08-02 18:51:42 +00:00
|
|
|
#include "LoadMe.h"
|
|
|
|
#include "SecondClass.h"
|
|
|
|
#include "MyCategory.h"
|
|
|
|
|
|
|
|
int
|
2001-04-10 03:27:01 +00:00
|
|
|
main(int argc, char *argv[], char **env)
|
1995-08-02 18:51:42 +00:00
|
|
|
{
|
|
|
|
NSBundle *bundle;
|
|
|
|
NSString *path;
|
|
|
|
id object;
|
2001-04-10 03:27:01 +00:00
|
|
|
NSAutoreleasePool *arp;
|
|
|
|
|
|
|
|
#if LIB_FOUNDATION_LIBRARY || defined(GS_PASS_ARGUMENTS)
|
|
|
|
[NSProcessInfo initializeWithArguments:argv count:argc environment:env];
|
|
|
|
#endif
|
|
|
|
arp = [NSAutoreleasePool new];
|
1995-08-02 18:51:42 +00:00
|
|
|
|
2002-04-16 15:09:00 +00:00
|
|
|
printf(" GNUstep bundle directory is %s\n", [[[NSBundle gnustepBundle] bundlePath] cString]);
|
|
|
|
|
2002-05-04 19:01:24 +00:00
|
|
|
path = [[[NSProcessInfo processInfo] arguments] objectAtIndex: 0];
|
|
|
|
printf(" Executable is in %s\n", [path cString]);
|
|
|
|
path = [NSBundle _absolutePathOfExecutable: path];
|
|
|
|
if (!path) {
|
|
|
|
fprintf(stderr, "* ERROR: Can't find executable\n");
|
1995-08-02 18:51:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
2002-05-04 19:01:24 +00:00
|
|
|
printf(" Full directory is %s\n", [path cString]);
|
1995-08-02 18:51:42 +00:00
|
|
|
|
|
|
|
printf("Looking for LoadMe bundle...\n");
|
2002-05-04 19:01:24 +00:00
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
printf(" Bundle directory is %s\n", [path cString]);
|
|
|
|
path = [NSBundle pathForResource:@"LoadMe" ofType:@"bundle"
|
|
|
|
inDirectory: path];
|
1995-08-02 18:51:42 +00:00
|
|
|
if (!path) {
|
2002-05-04 19:01:24 +00:00
|
|
|
fprintf(stderr, "* ERROR: Can't find LoadMe bundle\n");
|
1995-08-02 18:51:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
printf(" Found LoadMe in: %s\n\n", [path cString]);
|
|
|
|
|
|
|
|
printf("Initializing LoadMe bundle...\n");
|
|
|
|
bundle = [[NSBundle alloc] initWithPath:path];
|
|
|
|
if (!bundle) {
|
|
|
|
fprintf(stderr, "* ERROR: Can't init LoadMe bundle\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
path = [bundle pathForResource:@"NXStringTable" ofType:@"example"];
|
|
|
|
if (!path) {
|
|
|
|
fprintf(stderr, "* ERROR: Can't find example in LoadMe bundle\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
printf(" Found example file: %s\n\n", [path cString]);
|
|
|
|
|
|
|
|
printf("Retreiving principal class...\n");
|
|
|
|
NS_DURING
|
|
|
|
object = [bundle principalClass];
|
|
|
|
NS_HANDLER
|
|
|
|
object = nil;
|
1996-09-02 20:06:14 +00:00
|
|
|
fprintf(stderr, " ERROR: %s\n", [[localException reason] cString]);
|
1995-08-02 18:51:42 +00:00
|
|
|
fprintf(stderr, " Either there is a problem with dynamic loading,\n");
|
|
|
|
fprintf(stderr, " or there is no dynamic loader on your system\n");
|
|
|
|
exit(1);
|
|
|
|
NS_ENDHANDLER
|
|
|
|
if (!object) {
|
|
|
|
fprintf(stderr, "* ERROR: Can't find principal class\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
1996-04-16 22:03:52 +00:00
|
|
|
printf(" Principal class is: %s\n", object_get_class_name (object));
|
1995-08-02 18:51:42 +00:00
|
|
|
|
|
|
|
printf("Testing LoadMe bundle classes...\n");
|
|
|
|
printf(" This is LoadMe:\n");
|
|
|
|
object = [[[bundle classNamed:@"LoadMe"] alloc] init];
|
|
|
|
[object afterLoad];
|
|
|
|
[object release];
|
|
|
|
|
|
|
|
printf("\n This is SecondClass:\n");
|
|
|
|
object = [[[bundle classNamed:@"SecondClass"] alloc] init];
|
|
|
|
[object printName];
|
|
|
|
[object printMyName];
|
|
|
|
[object release];
|
|
|
|
|
1998-10-03 05:11:05 +00:00
|
|
|
[arp release];
|
1995-08-02 18:51:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|