Changed SDLMain to SDL_main for MacOS X stuff
authorSam Lantinga <slouken@libsdl.org>
Sun, 23 Sep 2001 20:42:00 +0000
changeset 191c151cfc43c07
parent 190 e4af2c852c09
child 192 e31f8d815aaa
Changed SDLMain to SDL_main for MacOS X stuff
PBProjects.tar.gz
README.MacOSX
configure.in
sdl-config.in
src/main/macosx/Info.plist.in
src/main/macosx/Makefile.am
src/main/macosx/SDLMain.h
src/main/macosx/SDLMain.m
src/main/macosx/SDLMain.nib/classes.nib
src/main/macosx/SDL_main.h
src/main/macosx/SDL_main.m
     1.1 Binary file PBProjects.tar.gz has changed
     2.1 --- a/README.MacOSX	Sun Sep 23 18:19:44 2001 +0000
     2.2 +++ b/README.MacOSX	Sun Sep 23 20:42:00 2001 +0000
     2.3 @@ -51,7 +51,7 @@
     2.4     tasks when used on MacOS X
     2.5  
     2.6     Rationale: AM_PATH_SDL copies /usr/local/share/sdl/Info.plist and the folder
     2.7 -   /usr/local/share/sdl/SDLMain.nib/ into the directory where configure is invoked.
     2.8 +   /usr/local/share/sdl/SDL_main.nib/ into the directory where configure is invoked.
     2.9     This is essential for the configure script to be able to run the test code
    2.10     that detects SDL.
    2.11  
    2.12 @@ -68,10 +68,10 @@
    2.13  APP_NAME.app: EXE_NAME
    2.14  	mkdir -p $@/Contents/MacOS
    2.15  	mkdir -p $@/Contents/Resources
    2.16 -	mkdir -p $@/Contents/Resources/SDLMain.nib
    2.17 +	mkdir -p $@/Contents/Resources/SDL_main.nib
    2.18  	echo "APPL????" > $@/Contents/PkgInfo
    2.19  	$(INSTALL_DATA) Info.plist $@/Contents/
    2.20 -	$(INSTALL_DATA) SDLMain.nib/*.nib $@/Contents/Resources/
    2.21 +	$(INSTALL_DATA) SDL_main.nib/*.nib $@/Contents/Resources/
    2.22  	$(INSTALL_PROGRAM) $< $@/Contents/MacOS/
    2.23  
    2.24     You should replace EXE_NAME with the name of the executable. APP_NAME is what
    2.25 @@ -153,13 +153,13 @@
    2.26  - Setting up a new project by hand
    2.27      Some of you won't want to use the Stationary so I'll give some tips:
    2.28      * Create a new "Cocoa Application"
    2.29 -    * Add src/main/macosx/SDLMain.m , .h and .nib to your project
    2.30 +    * Add src/main/macosx/SDL_main.m , .h and .nib to your project
    2.31      * Remove "main.c" from your project
    2.32      * Remove "MainMenu.nib" from your project
    2.33      * Add "$(HOME)/Library/Frameworks/SDL.framework/Headers" to include path
    2.34      * Add "$(HOME)/Library/Frameworks" to the frameworks search path
    2.35      * Add "-framework SDL" to the "OTHER_LDFLAGS" variable
    2.36 -    * Set the "Main Nib File" under "Application Settings" to "SDLMain.nib"
    2.37 +    * Set the "Main Nib File" under "Application Settings" to "SDL_main.nib"
    2.38      * Add your files
    2.39      * Clean and build
    2.40  
    2.41 @@ -174,7 +174,7 @@
    2.42  - Implementation Notes
    2.43      Some things that may be of interest about how it all works...
    2.44      * Working directory
    2.45 -        As defined in the SDLMain.m file, the working directory of your SDL app
    2.46 +        As defined in the SDL_main.m file, the working directory of your SDL app
    2.47          is by default set to its parent. You may wish to change this to better
    2.48          suit your needs.
    2.49      * You have a Cocoa App!
     3.1 --- a/configure.in	Sun Sep 23 18:19:44 2001 +0000
     3.2 +++ b/configure.in	Sun Sep 23 20:42:00 2001 +0000
     3.3 @@ -1379,13 +1379,12 @@
     3.4              CDROM_DRIVERS="$CDROM_DRIVERS bsdi/libcdrom_bsdi.la"
     3.5          fi
     3.6          # Set up files for the thread library
     3.7 -        SDL_LIBS="$SDL_LIBS -lsem"
     3.8          if test x$enable_threads = xyes; then
     3.9              COPY_ARCH_SRC(src/thread, linux, SDL_systhread.c)
    3.10              COPY_ARCH_SRC(src/thread, linux, SDL_systhread_c.h)
    3.11              COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex.c)
    3.12              COPY_ARCH_SRC(src/thread, linux, SDL_sysmutex_c.h)
    3.13 -            COPY_ARCH_SRC(src/thread, linux, SDL_syssem.c)
    3.14 +            COPY_ARCH_SRC(src/thread, bsdi, SDL_syssem.c)
    3.15              COPY_ARCH_SRC(src/thread, generic, SDL_syssem_c.h)
    3.16              COPY_ARCH_SRC(src/thread, linux, SDL_syscond.c)
    3.17              COPY_ARCH_SRC(src/thread, generic, SDL_syscond_c.h)
    3.18 @@ -2074,8 +2073,8 @@
    3.19          CheckMacGL
    3.20          CheckPTHREAD
    3.21          # Set up files for the main() stub
    3.22 -        COPY_ARCH_SRC(src/main, macosx, SDLmain.m)
    3.23 -        COPY_ARCH_SRC(src/main, macosx, SDLmain.h)
    3.24 +        COPY_ARCH_SRC(src/main, macosx, SDL_main.m)
    3.25 +        COPY_ARCH_SRC(src/main, macosx, SDL_main.h)
    3.26          # Set up files for the audio library
    3.27          if test x$enable_audio = xyes; then
    3.28              AUDIO_SUBDIRS="$AUDIO_SUBDIRS macrom"
     4.1 --- a/sdl-config.in	Sun Sep 23 18:19:44 2001 +0000
     4.2 +++ b/sdl-config.in	Sun Sep 23 20:42:00 2001 +0000
     4.3 @@ -57,7 +57,7 @@
     4.4  @ENABLE_STATIC_TRUE@      echo $libdirs @SDL_LIBS@ @SYSTEM_LIBS@
     4.5  @ENABLE_STATIC_TRUE@      ;;
     4.6  @TARGET_MACOSX_TRUE@    --nib)
     4.7 -@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/SDLMain.nib
     4.8 +@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/SDL_main.nib
     4.9  @TARGET_MACOSX_TRUE@      ;;
    4.10  @TARGET_MACOSX_TRUE@    --plist)
    4.11  @TARGET_MACOSX_TRUE@      echo @datadir@/sdl/Info.plist
     5.1 --- a/src/main/macosx/Info.plist.in	Sun Sep 23 18:19:44 2001 +0000
     5.2 +++ b/src/main/macosx/Info.plist.in	Sun Sep 23 20:42:00 2001 +0000
     5.3 @@ -17,7 +17,7 @@
     5.4  	<key>CFBundleSignature</key>
     5.5  	<string>????</string>
     5.6  	<key>NSMainNibFile</key>
     5.7 -	<string>SDLMain.nib</string>
     5.8 +	<string>SDL_main.nib</string>
     5.9  	<key>NSPrincipalClass</key>
    5.10  	<string>NSApplication</string>
    5.11  </dict>
     6.1 --- a/src/main/macosx/Makefile.am	Sun Sep 23 18:19:44 2001 +0000
     6.2 +++ b/src/main/macosx/Makefile.am	Sun Sep 23 20:42:00 2001 +0000
     6.3 @@ -1,27 +1,27 @@
     6.4 -# On OS X, install the SDLMain.nib.
     6.5 +# On OS X, install the SDL_main.nib.
     6.6  # We use an ugly hack to force the creation of the
     6.7  # destination dir, maybe somebody with more automake
     6.8  # experience knows how to do this properly?
     6.9  
    6.10  if TARGET_MACOSX
    6.11 -masternibdatadir = $(datadir)/sdl/SDLMain.nib
    6.12 +masternibdatadir = $(datadir)/sdl/SDL_main.nib
    6.13  masternibdata_DATA =		\
    6.14 -	SDLMain.nib
    6.15 +	SDL_main.nib
    6.16  
    6.17  nibdatadir = $(datadir)/sdl
    6.18  nibdata_DATA =			\
    6.19 -	SDLMain.nib/classes.nib	\
    6.20 -	SDLMain.nib/info.nib	\
    6.21 -	SDLMain.nib/objects.nib	\
    6.22 +	SDL_main.nib/classes.nib	\
    6.23 +	SDL_main.nib/info.nib	\
    6.24 +	SDL_main.nib/objects.nib	\
    6.25  	Info.plist
    6.26  endif
    6.27  
    6.28 -EXTRA_DIST = SDLMain.h SDLMain.m
    6.29 +EXTRA_DIST = SDL_main.h SDL_main.m
    6.30  
    6.31  # The nib and exports directories need to be copied into place
    6.32  # when building a distribution.
    6.33  dist-hook:
    6.34  	(cd $(distdir) && rm -f $(BUILT_SOURCES))
    6.35 -	cp -rp SDLMain.nib $(distdir)
    6.36 +	cp -rp SDL_main.nib $(distdir)
    6.37  	cp -rp exports $(distdir)
    6.38  	(cd $(distdir) && rm -rf `find . -name CVS`)
     7.1 --- a/src/main/macosx/SDLMain.h	Sun Sep 23 18:19:44 2001 +0000
     7.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.3 @@ -1,15 +0,0 @@
     7.4 -/*   SDLMain.h - main entry point for our Cocoa-ized SDL app
     7.5 -       Darrell Walisser - dwaliss1@purdue.edu
     7.6 -
     7.7 -    Feel free to customize this file to suit your needs
     7.8 -*/
     7.9 -
    7.10 -#import <Cocoa/Cocoa.h>
    7.11 -
    7.12 -@interface SDLMain : NSObject
    7.13 -{
    7.14 -}
    7.15 -- (IBAction)quit:(id)sender;
    7.16 -- (IBAction)makeFullscreen:(id)sender;
    7.17 -- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
    7.18 -@end
     8.1 --- a/src/main/macosx/SDLMain.m	Sun Sep 23 18:19:44 2001 +0000
     8.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.3 @@ -1,175 +0,0 @@
     8.4 -/*   SDLMain.m - main entry point for our Cocoa-ized SDL app
     8.5 -       Darrell Walisser - dwaliss1@purdue.edu
     8.6 -
     8.7 -    Feel free to customize this file to suit your needs
     8.8 -*/
     8.9 -
    8.10 -#import "SDL.h"
    8.11 -#import "SDLMain.h"
    8.12 -#import <sys/param.h> /* for MAXPATHLEN */
    8.13 -#import <unistd.h>
    8.14 -
    8.15 -static int    gArgc;
    8.16 -static char  **gArgv;
    8.17 -static NSString *gAppName = 0;
    8.18 -static BOOL   gFinderLaunch;
    8.19 -
    8.20 -@interface NSString (ReplaceSubString)
    8.21 -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
    8.22 -@end
    8.23 -
    8.24 -
    8.25 -/* The main class of the application, the application's delegate */
    8.26 -@implementation SDLMain
    8.27 -
    8.28 -/* Invoked from the Quit menu item */
    8.29 -- (void) quit:(id)sender
    8.30 -{
    8.31 -    SDL_Event event;
    8.32 -    event.type = SDL_QUIT;
    8.33 -    SDL_PushEvent(&event);
    8.34 -}
    8.35 -
    8.36 -/* Invoked from the Make Full-Screen menu item */
    8.37 -- (void) makeFullscreen:(id)sender
    8.38 -{
    8.39 -    /* TODO */
    8.40 -}
    8.41 -
    8.42 -/* Set the working directory to the .app's parent directory */
    8.43 -- (void) setupWorkingDirectory:(BOOL)shouldChdir
    8.44 -{
    8.45 -    char parentdir[MAXPATHLEN];
    8.46 -    char *c;
    8.47 -    
    8.48 -    strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
    8.49 -    c = (char*) parentdir;
    8.50 -
    8.51 -    while (*c != '\0')     /* go to end */
    8.52 -        c++;
    8.53 -    
    8.54 -    while (*c != '/')      /* back up to parent */
    8.55 -        c--;
    8.56 -    
    8.57 -    *c++ = '\0';             /* cut off last part (binary name) */
    8.58 -  
    8.59 -    if (shouldChdir)
    8.60 -    {
    8.61 -      assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
    8.62 -      assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
    8.63 -    }
    8.64 -    /* gAppName = [ NSString stringWithCString: c ]; */
    8.65 -}
    8.66 -
    8.67 -/* Fix menu to contain the real app name instead of "SDL App" */
    8.68 -- (void) fixMenu:(NSMenu *)aMenu
    8.69 -{
    8.70 -    NSRange aRange;
    8.71 -    NSEnumerator *enumerator;
    8.72 -    NSMenuItem *menuItem;
    8.73 -
    8.74 -    aRange = [[aMenu title] rangeOfString:@"SDL App"];
    8.75 -    if (aRange.length != 0)
    8.76 -        [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:gAppName]];
    8.77 -
    8.78 -    enumerator = [[aMenu itemArray] objectEnumerator];
    8.79 -    while ((menuItem = [enumerator nextObject]))
    8.80 -    {
    8.81 -        aRange = [[menuItem title] rangeOfString:@"SDL App"];
    8.82 -        if (aRange.length != 0)
    8.83 -            [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:gAppName]];
    8.84 -        if ([menuItem hasSubmenu])
    8.85 -            [self fixMenu: [menuItem submenu]];
    8.86 -    }
    8.87 -    [ aMenu sizeToFit ];
    8.88 -}
    8.89 -
    8.90 -/* Called when the internal event loop has just started running */
    8.91 -- (void) applicationDidFinishLaunching: (NSNotification *) note
    8.92 -{
    8.93 -    int status;
    8.94 -
    8.95 -    /* Set the working directory to the .app's parent directory */
    8.96 -    [ self setupWorkingDirectory: gFinderLaunch ];
    8.97 -
    8.98 -    /* Set the main menu to contain the real app name instead of "SDL App" */
    8.99 -    gAppName = [ [ NSBundle mainBundle ] bundleIdentifier ];
   8.100 -    [ self fixMenu: [ NSApp mainMenu ] ];
   8.101 -
   8.102 -    /* Hand off to main application code */
   8.103 -    status = SDL_main (gArgc, gArgv);
   8.104 -
   8.105 -    /* We're done, thank you for playing */
   8.106 -    exit(status);
   8.107 -}
   8.108 -@end
   8.109 -
   8.110 -
   8.111 -@implementation NSString (ReplaceSubString)
   8.112 -
   8.113 -- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
   8.114 -{
   8.115 -    unsigned int bufferSize;
   8.116 -    unsigned int selfLen = [self length];
   8.117 -    unsigned int aStringLen = [aString length];
   8.118 -    unichar *buffer;
   8.119 -    NSRange localRange;
   8.120 -    NSString *result;
   8.121 -
   8.122 -    bufferSize = selfLen + aStringLen - aRange.length;
   8.123 -    buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
   8.124 -    
   8.125 -    // Get first part into buffer
   8.126 -    localRange.location = 0;
   8.127 -    localRange.length = aRange.location;
   8.128 -    [self getCharacters:buffer range:localRange];
   8.129 -    
   8.130 -    // Get middle part into buffer
   8.131 -    localRange.location = 0;
   8.132 -    localRange.length = aStringLen;
   8.133 -    [aString getCharacters:(buffer+aRange.location) range:localRange];
   8.134 -     
   8.135 -    // Get last part into buffer
   8.136 -    localRange.location = aRange.location + aRange.length;
   8.137 -    localRange.length = selfLen - localRange.location;
   8.138 -    [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
   8.139 -    
   8.140 -    // Build output string
   8.141 -    result = [NSString stringWithCharacters:buffer length:bufferSize];
   8.142 -    
   8.143 -    NSDeallocateMemoryPages(buffer, bufferSize);
   8.144 -    
   8.145 -    return result;
   8.146 -}
   8.147 -
   8.148 -@end
   8.149 -
   8.150 -
   8.151 -#ifdef main
   8.152 -#  undef main
   8.153 -#endif
   8.154 -
   8.155 -/* Main entry point to executible - should *not* be SDL_main! */
   8.156 -int main (int argc, char **argv) {
   8.157 -
   8.158 -    /* Copy the arguments into a global variable */
   8.159 -    int i;
   8.160 -    
   8.161 -    /* This is passed if we are launched by double-clicking */
   8.162 -    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
   8.163 -        gArgc = 1;
   8.164 -	gFinderLaunch = YES;
   8.165 -    } else {
   8.166 -        gArgc = argc;
   8.167 -	gFinderLaunch = NO;
   8.168 -    }
   8.169 -    gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
   8.170 -    assert (gArgv != NULL);
   8.171 -    for (i = 0; i < gArgc; i++) {
   8.172 -        gArgv[i] = argv[i];
   8.173 -    }
   8.174 -    gArgv[i] = NULL;
   8.175 -
   8.176 -    NSApplicationMain (argc, argv);
   8.177 -    return 0;
   8.178 -}
     9.1 --- a/src/main/macosx/SDLMain.nib/classes.nib	Sun Sep 23 18:19:44 2001 +0000
     9.2 +++ b/src/main/macosx/SDLMain.nib/classes.nib	Sun Sep 23 20:42:00 2001 +0000
     9.3 @@ -3,10 +3,10 @@
     9.4          {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
     9.5          {
     9.6              ACTIONS = {makeFullscreen = id; quit = id; }; 
     9.7 -            CLASS = SDLMain; 
     9.8 +            CLASS = SDL_main; 
     9.9              LANGUAGE = ObjC; 
    9.10              SUPERCLASS = NSObject; 
    9.11          }
    9.12      ); 
    9.13      IBVersion = 1; 
    9.14 -}
    9.15 \ No newline at end of file
    9.16 +}
    10.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.2 +++ b/src/main/macosx/SDL_main.h	Sun Sep 23 20:42:00 2001 +0000
    10.3 @@ -0,0 +1,15 @@
    10.4 +/*   SDL_main.h - main entry point for our Cocoa-ized SDL app
    10.5 +       Darrell Walisser - dwaliss1@purdue.edu
    10.6 +
    10.7 +    Feel free to customize this file to suit your needs
    10.8 +*/
    10.9 +
   10.10 +#import <Cocoa/Cocoa.h>
   10.11 +
   10.12 +@interface SDL_main : NSObject
   10.13 +{
   10.14 +}
   10.15 +- (IBAction)quit:(id)sender;
   10.16 +- (IBAction)makeFullscreen:(id)sender;
   10.17 +- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
   10.18 +@end
    11.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.2 +++ b/src/main/macosx/SDL_main.m	Sun Sep 23 20:42:00 2001 +0000
    11.3 @@ -0,0 +1,175 @@
    11.4 +/*   SDL_main.m - main entry point for our Cocoa-ized SDL app
    11.5 +       Darrell Walisser - dwaliss1@purdue.edu
    11.6 +
    11.7 +    Feel free to customize this file to suit your needs
    11.8 +*/
    11.9 +
   11.10 +#import "SDL.h"
   11.11 +#import "SDL_main.h"
   11.12 +#import <sys/param.h> /* for MAXPATHLEN */
   11.13 +#import <unistd.h>
   11.14 +
   11.15 +static int    gArgc;
   11.16 +static char  **gArgv;
   11.17 +static NSString *gAppName = 0;
   11.18 +static BOOL   gFinderLaunch;
   11.19 +
   11.20 +@interface NSString (ReplaceSubString)
   11.21 +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
   11.22 +@end
   11.23 +
   11.24 +
   11.25 +/* The main class of the application, the application's delegate */
   11.26 +@implementation SDL_main
   11.27 +
   11.28 +/* Invoked from the Quit menu item */
   11.29 +- (void) quit:(id)sender
   11.30 +{
   11.31 +    SDL_Event event;
   11.32 +    event.type = SDL_QUIT;
   11.33 +    SDL_PushEvent(&event);
   11.34 +}
   11.35 +
   11.36 +/* Invoked from the Make Full-Screen menu item */
   11.37 +- (void) makeFullscreen:(id)sender
   11.38 +{
   11.39 +    /* TODO */
   11.40 +}
   11.41 +
   11.42 +/* Set the working directory to the .app's parent directory */
   11.43 +- (void) setupWorkingDirectory:(BOOL)shouldChdir
   11.44 +{
   11.45 +    char parentdir[MAXPATHLEN];
   11.46 +    char *c;
   11.47 +    
   11.48 +    strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
   11.49 +    c = (char*) parentdir;
   11.50 +
   11.51 +    while (*c != '\0')     /* go to end */
   11.52 +        c++;
   11.53 +    
   11.54 +    while (*c != '/')      /* back up to parent */
   11.55 +        c--;
   11.56 +    
   11.57 +    *c++ = '\0';             /* cut off last part (binary name) */
   11.58 +  
   11.59 +    if (shouldChdir)
   11.60 +    {
   11.61 +      assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
   11.62 +      assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
   11.63 +    }
   11.64 +    /* gAppName = [ NSString stringWithCString: c ]; */
   11.65 +}
   11.66 +
   11.67 +/* Fix menu to contain the real app name instead of "SDL App" */
   11.68 +- (void) fixMenu:(NSMenu *)aMenu
   11.69 +{
   11.70 +    NSRange aRange;
   11.71 +    NSEnumerator *enumerator;
   11.72 +    NSMenuItem *menuItem;
   11.73 +
   11.74 +    aRange = [[aMenu title] rangeOfString:@"SDL App"];
   11.75 +    if (aRange.length != 0)
   11.76 +        [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:gAppName]];
   11.77 +
   11.78 +    enumerator = [[aMenu itemArray] objectEnumerator];
   11.79 +    while ((menuItem = [enumerator nextObject]))
   11.80 +    {
   11.81 +        aRange = [[menuItem title] rangeOfString:@"SDL App"];
   11.82 +        if (aRange.length != 0)
   11.83 +            [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:gAppName]];
   11.84 +        if ([menuItem hasSubmenu])
   11.85 +            [self fixMenu: [menuItem submenu]];
   11.86 +    }
   11.87 +    [ aMenu sizeToFit ];
   11.88 +}
   11.89 +
   11.90 +/* Called when the internal event loop has just started running */
   11.91 +- (void) applicationDidFinishLaunching: (NSNotification *) note
   11.92 +{
   11.93 +    int status;
   11.94 +
   11.95 +    /* Set the working directory to the .app's parent directory */
   11.96 +    [ self setupWorkingDirectory: gFinderLaunch ];
   11.97 +
   11.98 +    /* Set the main menu to contain the real app name instead of "SDL App" */
   11.99 +    gAppName = [ [ NSBundle mainBundle ] bundleIdentifier ];
  11.100 +    [ self fixMenu: [ NSApp mainMenu ] ];
  11.101 +
  11.102 +    /* Hand off to main application code */
  11.103 +    status = SDL_main (gArgc, gArgv);
  11.104 +
  11.105 +    /* We're done, thank you for playing */
  11.106 +    exit(status);
  11.107 +}
  11.108 +@end
  11.109 +
  11.110 +
  11.111 +@implementation NSString (ReplaceSubString)
  11.112 +
  11.113 +- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
  11.114 +{
  11.115 +    unsigned int bufferSize;
  11.116 +    unsigned int selfLen = [self length];
  11.117 +    unsigned int aStringLen = [aString length];
  11.118 +    unichar *buffer;
  11.119 +    NSRange localRange;
  11.120 +    NSString *result;
  11.121 +
  11.122 +    bufferSize = selfLen + aStringLen - aRange.length;
  11.123 +    buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
  11.124 +    
  11.125 +    // Get first part into buffer
  11.126 +    localRange.location = 0;
  11.127 +    localRange.length = aRange.location;
  11.128 +    [self getCharacters:buffer range:localRange];
  11.129 +    
  11.130 +    // Get middle part into buffer
  11.131 +    localRange.location = 0;
  11.132 +    localRange.length = aStringLen;
  11.133 +    [aString getCharacters:(buffer+aRange.location) range:localRange];
  11.134 +     
  11.135 +    // Get last part into buffer
  11.136 +    localRange.location = aRange.location + aRange.length;
  11.137 +    localRange.length = selfLen - localRange.location;
  11.138 +    [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
  11.139 +    
  11.140 +    // Build output string
  11.141 +    result = [NSString stringWithCharacters:buffer length:bufferSize];
  11.142 +    
  11.143 +    NSDeallocateMemoryPages(buffer, bufferSize);
  11.144 +    
  11.145 +    return result;
  11.146 +}
  11.147 +
  11.148 +@end
  11.149 +
  11.150 +
  11.151 +#ifdef main
  11.152 +#  undef main
  11.153 +#endif
  11.154 +
  11.155 +/* Main entry point to executible - should *not* be SDL_main! */
  11.156 +int main (int argc, char **argv) {
  11.157 +
  11.158 +    /* Copy the arguments into a global variable */
  11.159 +    int i;
  11.160 +    
  11.161 +    /* This is passed if we are launched by double-clicking */
  11.162 +    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
  11.163 +        gArgc = 1;
  11.164 +	gFinderLaunch = YES;
  11.165 +    } else {
  11.166 +        gArgc = argc;
  11.167 +	gFinderLaunch = NO;
  11.168 +    }
  11.169 +    gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
  11.170 +    assert (gArgv != NULL);
  11.171 +    for (i = 0; i < gArgc; i++) {
  11.172 +        gArgv[i] = argv[i];
  11.173 +    }
  11.174 +    gArgv[i] = NULL;
  11.175 +
  11.176 +    NSApplicationMain (argc, argv);
  11.177 +    return 0;
  11.178 +}