File: load_backends.m

package info (click to toggle)
gnustep-back 0.32.0-4
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,320 kB
  • sloc: objc: 42,426; ansic: 6,623; xml: 258; makefile: 130; sh: 120
file content (73 lines) | stat: -rw-r--r-- 2,722 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
/* -*- objc -*-

   Test loading of all backends.  This minimalistic program roughly
   mimics the backend loading procedure of the GNUstep GUI library,
   grossly simplified because there is no need to guess the
   installation details.  */

#import <Foundation/Foundation.h>

void
load_backend (NSString *bundleWithVersion)
{
  NSString *path;
  NSArray *libdir;
  NSBundle *theBundle;
  Class backend = Nil;

  libdir = NSSearchPathForDirectoriesInDomains (NSLibraryDirectory,
                                                NSSystemDomainMask, YES);
  path = [[libdir firstObject] stringByAppendingPathComponent: @"Bundles"];
  path = [path stringByAppendingPathComponent: bundleWithVersion];
  NSCAssert1 ([[NSFileManager defaultManager] fileExistsAtPath: path],
              @"File %@ does not exist", path);

  theBundle = [NSBundle bundleWithPath: path];
  NSCAssert1 (theBundle != nil,
              @"Cannot create NSBundle object for backend at path %@", path);
  NSCAssert1 ([theBundle load],
              @"Cannot load object file from backend at path %@", path);

  backend = NSClassFromString (@"GSBackend");
  NSCAssert1 (backend != Nil,
              @"Backend at path %@ doesn't contain the GSBackend class", path);
}

int
main (void)
{
  CREATE_AUTORELEASE_POOL (pool);
  NSUserDefaults *defs = [NSUserDefaults standardUserDefaults];
  NSString *bundleName, *bundleWithVersion;

  bundleName = [defs stringForKey: @"GSBackend"];
  /* The default backend must be cairo (enforced via the alternatives
     system); attempt to load it from the symlink.  */
  NSCAssert (bundleName == nil, @"GSBackend set while it shouldn't");
  bundleName = @"libgnustep-back";
  bundleWithVersion = [NSString stringWithFormat: @"%@-%s.bundle",
                                bundleName, VER];
  load_backend (bundleWithVersion);

  /* Now load all the backends directly.  */
  [defs setObject: @"libgnustep-cairo" forKey: @"GSBackend"];
  bundleName = [defs stringForKey: @"GSBackend"];
  bundleWithVersion = [NSString stringWithFormat: @"%@-%s.bundle",
                                bundleName, VER];
  load_backend (bundleWithVersion);

  [defs setObject: @"libgnustep-headless" forKey: @"GSBackend"];
  bundleName = [defs stringForKey: @"GSBackend"];
  bundleWithVersion = [NSString stringWithFormat: @"%@-%s.bundle",
                                bundleName, VER];
  load_backend (bundleWithVersion);

  [defs setObject: @"libgnustep-xlib" forKey: @"GSBackend"];
  bundleName = [defs stringForKey: @"GSBackend"];
  bundleWithVersion = [NSString stringWithFormat: @"%@-%s.bundle",
                                bundleName, VER];
  load_backend (bundleWithVersion);

  RELEASE (pool);
  exit (EXIT_SUCCESS);
}