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.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1995-08-02 18:51:42 +00:00
|
|
|
Written by: Adam Fedor <fedor@boulder.colorado.edu>
|
|
|
|
Date: Jul 1995
|
2005-02-22 11:22:44 +00:00
|
|
|
|
1996-05-12 00:56:10 +00:00
|
|
|
This file is part of the GNUstep Base Library.
|
2005-02-22 11:22:44 +00:00
|
|
|
|
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
|
2003-05-30 02:54:49 +00:00
|
|
|
#include "Foundation/NSArray.h"
|
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"
|
|
|
|
|
2005-02-22 11:22:44 +00:00
|
|
|
int
|
|
|
|
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];
|
2005-02-22 11:22:44 +00:00
|
|
|
|
2002-10-15 04:55:51 +00:00
|
|
|
setbuf(stdout, 0);
|
2004-10-26 19:08:17 +00:00
|
|
|
/* Test bundle version and info files */
|
|
|
|
bundle = [NSBundle bundleForLibrary: @"gnustep-base"];
|
|
|
|
GSPrintf(stdout, @" GNUstep Base Resources: %@\n", [bundle bundlePath]);
|
|
|
|
object = [bundle infoDictionary];
|
|
|
|
GSPrintf(stdout, @" gnustep-base version string = %@\n",
|
|
|
|
[object objectForKey: @"GSBundleShortVersionString"]);
|
|
|
|
GSPrintf(stdout, @" gnustep-base version number = %g\n\n",
|
|
|
|
[[object objectForKey: @"GSBundleVersion"] doubleValue]);
|
|
|
|
|
2002-04-16 15:09:00 +00:00
|
|
|
|
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) {
|
2003-05-30 02:50:28 +00:00
|
|
|
fprintf(stdout, "* 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];
|
2003-08-24 23:07:41 +00:00
|
|
|
if ([[path lastPathComponent] isEqualToString:@"Testing"] == NO)
|
|
|
|
{
|
|
|
|
/* Delete library combo */
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
path = [path stringByDeletingLastPathComponent];
|
|
|
|
}
|
2002-05-04 19:01:24 +00:00
|
|
|
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) {
|
2003-05-30 02:50:28 +00:00
|
|
|
fprintf(stdout, "* 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) {
|
2003-05-30 02:50:28 +00:00
|
|
|
fprintf(stdout, "* ERROR: Can't init LoadMe bundle\n");
|
1995-08-02 18:51:42 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
path = [bundle pathForResource:@"NXStringTable" ofType:@"example"];
|
|
|
|
if (!path) {
|
2003-05-30 02:50:28 +00:00
|
|
|
fprintf(stdout, "* ERROR: Can't find example in LoadMe bundle\n");
|
1995-08-02 18:51:42 +00:00
|
|
|
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;
|
2003-05-30 02:50:28 +00:00
|
|
|
fprintf(stdout, " ERROR: %s\n", [[localException reason] cString]);
|
|
|
|
fprintf(stdout, " Either there is a problem with dynamic loading,\n");
|
|
|
|
fprintf(stdout, " or there is no dynamic loader on your system\n");
|
1995-08-02 18:51:42 +00:00
|
|
|
exit(1);
|
|
|
|
NS_ENDHANDLER
|
2005-02-22 11:22:44 +00:00
|
|
|
if (!object)
|
2003-05-30 02:50:28 +00:00
|
|
|
{
|
|
|
|
printf("* ERROR: Can't find principal class\n");
|
|
|
|
}
|
|
|
|
else
|
2003-08-24 23:07:41 +00:00
|
|
|
printf(" Principal class is: %s\n", GSClassNameFromObject(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];
|
2003-05-30 02:50:28 +00:00
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
printf("* ERROR: Can't find LoadMe class\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[object afterLoad];
|
|
|
|
[object release];
|
|
|
|
}
|
1995-08-02 18:51:42 +00:00
|
|
|
|
|
|
|
printf("\n This is SecondClass:\n");
|
|
|
|
object = [[[bundle classNamed:@"SecondClass"] alloc] init];
|
2003-05-30 02:50:28 +00:00
|
|
|
if (!object)
|
|
|
|
{
|
|
|
|
printf("* ERROR: Can't find SecondClass class\n");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
[object printName];
|
|
|
|
[object printMyName];
|
|
|
|
[object release];
|
|
|
|
}
|
2004-10-26 19:08:17 +00:00
|
|
|
|
|
|
|
|
1998-10-03 05:11:05 +00:00
|
|
|
[arp release];
|
1995-08-02 18:51:42 +00:00
|
|
|
return 0;
|
|
|
|
}
|