Oops, back out that SDL_main -> SDLMain conversion
authorSam Lantinga <slouken@libsdl.org>
Sun, 23 Sep 2001 21:09:08 +0000
changeset 194ba9e0fcc2ae2
parent 193 ea31cf2d61af
child 195 3669d47b07d3
Oops, back out that SDL_main -> SDLMain conversion
PBProjects.tar.gz
configure.in
sdl-config.in
src/main/Makefile.am
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/configure.in	Sun Sep 23 20:52:11 2001 +0000
     2.2 +++ b/configure.in	Sun Sep 23 21:09:08 2001 +0000
     2.3 @@ -2073,8 +2073,8 @@
     2.4          CheckMacGL
     2.5          CheckPTHREAD
     2.6          # Set up files for the main() stub
     2.7 -        COPY_ARCH_SRC(src/main, macosx, SDL_main.m)
     2.8 -        COPY_ARCH_SRC(src/main, macosx, SDL_main.h)
     2.9 +        COPY_ARCH_SRC(src/main, macosx, SDLMain.m)
    2.10 +        COPY_ARCH_SRC(src/main, macosx, SDLMain.h)
    2.11          # Set up files for the audio library
    2.12          if test x$enable_audio = xyes; then
    2.13              AUDIO_SUBDIRS="$AUDIO_SUBDIRS macrom"
     3.1 --- a/sdl-config.in	Sun Sep 23 20:52:11 2001 +0000
     3.2 +++ b/sdl-config.in	Sun Sep 23 21:09:08 2001 +0000
     3.3 @@ -57,7 +57,7 @@
     3.4  @ENABLE_STATIC_TRUE@      echo $libdirs @SDL_LIBS@ @SYSTEM_LIBS@
     3.5  @ENABLE_STATIC_TRUE@      ;;
     3.6  @TARGET_MACOSX_TRUE@    --nib)
     3.7 -@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/SDL_main.nib
     3.8 +@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/SDLMain.nib
     3.9  @TARGET_MACOSX_TRUE@      ;;
    3.10  @TARGET_MACOSX_TRUE@    --plist)
    3.11  @TARGET_MACOSX_TRUE@      echo @datadir@/sdl/Info.plist
     4.1 --- a/src/main/Makefile.am	Sun Sep 23 20:52:11 2001 +0000
     4.2 +++ b/src/main/Makefile.am	Sun Sep 23 21:09:08 2001 +0000
     4.3 @@ -16,7 +16,7 @@
     4.4  lib_LIBRARIES = libSDLmain.a
     4.5  
     4.6  if TARGET_MACOSX
     4.7 -MAINLIB_ARCH_SRCS = SDL_main.m SDL_main.h
     4.8 +MAINLIB_ARCH_SRCS = SDLMain.m SDLMain.h
     4.9  else
    4.10  MAINLIB_ARCH_SRCS = SDL_main.c
    4.11  endif
     5.1 --- a/src/main/macosx/Info.plist.in	Sun Sep 23 20:52:11 2001 +0000
     5.2 +++ b/src/main/macosx/Info.plist.in	Sun Sep 23 21:09:08 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>SDL_main.nib</string>
     5.8 +	<string>SDLMain.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 20:52:11 2001 +0000
     6.2 +++ b/src/main/macosx/Makefile.am	Sun Sep 23 21:09:08 2001 +0000
     6.3 @@ -1,27 +1,27 @@
     6.4 -# On OS X, install the SDL_main.nib.
     6.5 +# On OS X, install the SDLMain.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/SDL_main.nib
    6.12 +masternibdatadir = $(datadir)/sdl/SDLMain.nib
    6.13  masternibdata_DATA =		\
    6.14 -	SDL_main.nib
    6.15 +	SDLMain.nib
    6.16  
    6.17  nibdatadir = $(datadir)/sdl
    6.18  nibdata_DATA =			\
    6.19 -	SDL_main.nib/classes.nib	\
    6.20 -	SDL_main.nib/info.nib	\
    6.21 -	SDL_main.nib/objects.nib	\
    6.22 +	SDLMain.nib/classes.nib	\
    6.23 +	SDLMain.nib/info.nib	\
    6.24 +	SDLMain.nib/objects.nib	\
    6.25  	Info.plist
    6.26  endif
    6.27  
    6.28 -EXTRA_DIST = SDL_main.h SDL_main.m
    6.29 +EXTRA_DIST = SDLMain.h SDLMain.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 SDL_main.nib $(distdir)
    6.36 +	cp -rp SDLMain.nib $(distdir)
    6.37  	cp -rp exports $(distdir)
    6.38  	(cd $(distdir) && rm -rf `find . -name CVS`)
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/src/main/macosx/SDLMain.h	Sun Sep 23 21:09:08 2001 +0000
     7.3 @@ -0,0 +1,15 @@
     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 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     8.2 +++ b/src/main/macosx/SDLMain.m	Sun Sep 23 21:09:08 2001 +0000
     8.3 @@ -0,0 +1,175 @@
     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 20:52:11 2001 +0000
     9.2 +++ b/src/main/macosx/SDLMain.nib/classes.nib	Sun Sep 23 21:09:08 2001 +0000
     9.3 @@ -3,7 +3,7 @@
     9.4          {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
     9.5          {
     9.6              ACTIONS = {makeFullscreen = id; quit = id; }; 
     9.7 -            CLASS = SDL_main; 
     9.8 +            CLASS = SDLMain; 
     9.9              LANGUAGE = ObjC; 
    9.10              SUPERCLASS = NSObject; 
    9.11          }
    10.1 --- a/src/main/macosx/SDL_main.h	Sun Sep 23 20:52:11 2001 +0000
    10.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    10.3 @@ -1,15 +0,0 @@
    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 --- a/src/main/macosx/SDL_main.m	Sun Sep 23 20:52:11 2001 +0000
    11.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
    11.3 @@ -1,175 +0,0 @@
    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 -}