Oops, back out that SDL_main -> SDLMain conversion
authorSam Lantinga <slouken@libsdl.org>
Sun, 23 Sep 2001 21:09:08 +0000
changeset 194 ba9e0fcc2ae2
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
Binary file PBProjects.tar.gz has changed
--- a/configure.in	Sun Sep 23 20:52:11 2001 +0000
+++ b/configure.in	Sun Sep 23 21:09:08 2001 +0000
@@ -2073,8 +2073,8 @@
         CheckMacGL
         CheckPTHREAD
         # Set up files for the main() stub
-        COPY_ARCH_SRC(src/main, macosx, SDL_main.m)
-        COPY_ARCH_SRC(src/main, macosx, SDL_main.h)
+        COPY_ARCH_SRC(src/main, macosx, SDLMain.m)
+        COPY_ARCH_SRC(src/main, macosx, SDLMain.h)
         # Set up files for the audio library
         if test x$enable_audio = xyes; then
             AUDIO_SUBDIRS="$AUDIO_SUBDIRS macrom"
--- a/sdl-config.in	Sun Sep 23 20:52:11 2001 +0000
+++ b/sdl-config.in	Sun Sep 23 21:09:08 2001 +0000
@@ -57,7 +57,7 @@
 @ENABLE_STATIC_TRUE@      echo $libdirs @SDL_LIBS@ @SYSTEM_LIBS@
 @ENABLE_STATIC_TRUE@      ;;
 @TARGET_MACOSX_TRUE@    --nib)
-@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/SDL_main.nib
+@TARGET_MACOSX_TRUE@      echo @datadir@/sdl/SDLMain.nib
 @TARGET_MACOSX_TRUE@      ;;
 @TARGET_MACOSX_TRUE@    --plist)
 @TARGET_MACOSX_TRUE@      echo @datadir@/sdl/Info.plist
--- a/src/main/Makefile.am	Sun Sep 23 20:52:11 2001 +0000
+++ b/src/main/Makefile.am	Sun Sep 23 21:09:08 2001 +0000
@@ -16,7 +16,7 @@
 lib_LIBRARIES = libSDLmain.a
 
 if TARGET_MACOSX
-MAINLIB_ARCH_SRCS = SDL_main.m SDL_main.h
+MAINLIB_ARCH_SRCS = SDLMain.m SDLMain.h
 else
 MAINLIB_ARCH_SRCS = SDL_main.c
 endif
--- a/src/main/macosx/Info.plist.in	Sun Sep 23 20:52:11 2001 +0000
+++ b/src/main/macosx/Info.plist.in	Sun Sep 23 21:09:08 2001 +0000
@@ -17,7 +17,7 @@
 	<key>CFBundleSignature</key>
 	<string>????</string>
 	<key>NSMainNibFile</key>
-	<string>SDL_main.nib</string>
+	<string>SDLMain.nib</string>
 	<key>NSPrincipalClass</key>
 	<string>NSApplication</string>
 </dict>
--- a/src/main/macosx/Makefile.am	Sun Sep 23 20:52:11 2001 +0000
+++ b/src/main/macosx/Makefile.am	Sun Sep 23 21:09:08 2001 +0000
@@ -1,27 +1,27 @@
-# On OS X, install the SDL_main.nib.
+# On OS X, install the SDLMain.nib.
 # We use an ugly hack to force the creation of the
 # destination dir, maybe somebody with more automake
 # experience knows how to do this properly?
 
 if TARGET_MACOSX
-masternibdatadir = $(datadir)/sdl/SDL_main.nib
+masternibdatadir = $(datadir)/sdl/SDLMain.nib
 masternibdata_DATA =		\
-	SDL_main.nib
+	SDLMain.nib
 
 nibdatadir = $(datadir)/sdl
 nibdata_DATA =			\
-	SDL_main.nib/classes.nib	\
-	SDL_main.nib/info.nib	\
-	SDL_main.nib/objects.nib	\
+	SDLMain.nib/classes.nib	\
+	SDLMain.nib/info.nib	\
+	SDLMain.nib/objects.nib	\
 	Info.plist
 endif
 
-EXTRA_DIST = SDL_main.h SDL_main.m
+EXTRA_DIST = SDLMain.h SDLMain.m
 
 # The nib and exports directories need to be copied into place
 # when building a distribution.
 dist-hook:
 	(cd $(distdir) && rm -f $(BUILT_SOURCES))
-	cp -rp SDL_main.nib $(distdir)
+	cp -rp SDLMain.nib $(distdir)
 	cp -rp exports $(distdir)
 	(cd $(distdir) && rm -rf `find . -name CVS`)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/macosx/SDLMain.h	Sun Sep 23 21:09:08 2001 +0000
@@ -0,0 +1,15 @@
+/*   SDLMain.h - main entry point for our Cocoa-ized SDL app
+       Darrell Walisser - dwaliss1@purdue.edu
+
+    Feel free to customize this file to suit your needs
+*/
+
+#import <Cocoa/Cocoa.h>
+
+@interface SDLMain : NSObject
+{
+}
+- (IBAction)quit:(id)sender;
+- (IBAction)makeFullscreen:(id)sender;
+- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
+@end
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/main/macosx/SDLMain.m	Sun Sep 23 21:09:08 2001 +0000
@@ -0,0 +1,175 @@
+/*   SDLMain.m - main entry point for our Cocoa-ized SDL app
+       Darrell Walisser - dwaliss1@purdue.edu
+
+    Feel free to customize this file to suit your needs
+*/
+
+#import "SDL.h"
+#import "SDLMain.h"
+#import <sys/param.h> /* for MAXPATHLEN */
+#import <unistd.h>
+
+static int    gArgc;
+static char  **gArgv;
+static NSString *gAppName = 0;
+static BOOL   gFinderLaunch;
+
+@interface NSString (ReplaceSubString)
+- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
+@end
+
+
+/* The main class of the application, the application's delegate */
+@implementation SDLMain
+
+/* Invoked from the Quit menu item */
+- (void) quit:(id)sender
+{
+    SDL_Event event;
+    event.type = SDL_QUIT;
+    SDL_PushEvent(&event);
+}
+
+/* Invoked from the Make Full-Screen menu item */
+- (void) makeFullscreen:(id)sender
+{
+    /* TODO */
+}
+
+/* Set the working directory to the .app's parent directory */
+- (void) setupWorkingDirectory:(BOOL)shouldChdir
+{
+    char parentdir[MAXPATHLEN];
+    char *c;
+    
+    strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
+    c = (char*) parentdir;
+
+    while (*c != '\0')     /* go to end */
+        c++;
+    
+    while (*c != '/')      /* back up to parent */
+        c--;
+    
+    *c++ = '\0';             /* cut off last part (binary name) */
+  
+    if (shouldChdir)
+    {
+      assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
+      assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
+    }
+    /* gAppName = [ NSString stringWithCString: c ]; */
+}
+
+/* Fix menu to contain the real app name instead of "SDL App" */
+- (void) fixMenu:(NSMenu *)aMenu
+{
+    NSRange aRange;
+    NSEnumerator *enumerator;
+    NSMenuItem *menuItem;
+
+    aRange = [[aMenu title] rangeOfString:@"SDL App"];
+    if (aRange.length != 0)
+        [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:gAppName]];
+
+    enumerator = [[aMenu itemArray] objectEnumerator];
+    while ((menuItem = [enumerator nextObject]))
+    {
+        aRange = [[menuItem title] rangeOfString:@"SDL App"];
+        if (aRange.length != 0)
+            [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:gAppName]];
+        if ([menuItem hasSubmenu])
+            [self fixMenu: [menuItem submenu]];
+    }
+    [ aMenu sizeToFit ];
+}
+
+/* Called when the internal event loop has just started running */
+- (void) applicationDidFinishLaunching: (NSNotification *) note
+{
+    int status;
+
+    /* Set the working directory to the .app's parent directory */
+    [ self setupWorkingDirectory: gFinderLaunch ];
+
+    /* Set the main menu to contain the real app name instead of "SDL App" */
+    gAppName = [ [ NSBundle mainBundle ] bundleIdentifier ];
+    [ self fixMenu: [ NSApp mainMenu ] ];
+
+    /* Hand off to main application code */
+    status = SDL_main (gArgc, gArgv);
+
+    /* We're done, thank you for playing */
+    exit(status);
+}
+@end
+
+
+@implementation NSString (ReplaceSubString)
+
+- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
+{
+    unsigned int bufferSize;
+    unsigned int selfLen = [self length];
+    unsigned int aStringLen = [aString length];
+    unichar *buffer;
+    NSRange localRange;
+    NSString *result;
+
+    bufferSize = selfLen + aStringLen - aRange.length;
+    buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
+    
+    // Get first part into buffer
+    localRange.location = 0;
+    localRange.length = aRange.location;
+    [self getCharacters:buffer range:localRange];
+    
+    // Get middle part into buffer
+    localRange.location = 0;
+    localRange.length = aStringLen;
+    [aString getCharacters:(buffer+aRange.location) range:localRange];
+     
+    // Get last part into buffer
+    localRange.location = aRange.location + aRange.length;
+    localRange.length = selfLen - localRange.location;
+    [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
+    
+    // Build output string
+    result = [NSString stringWithCharacters:buffer length:bufferSize];
+    
+    NSDeallocateMemoryPages(buffer, bufferSize);
+    
+    return result;
+}
+
+@end
+
+
+#ifdef main
+#  undef main
+#endif
+
+/* Main entry point to executible - should *not* be SDL_main! */
+int main (int argc, char **argv) {
+
+    /* Copy the arguments into a global variable */
+    int i;
+    
+    /* This is passed if we are launched by double-clicking */
+    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
+        gArgc = 1;
+	gFinderLaunch = YES;
+    } else {
+        gArgc = argc;
+	gFinderLaunch = NO;
+    }
+    gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
+    assert (gArgv != NULL);
+    for (i = 0; i < gArgc; i++) {
+        gArgv[i] = argv[i];
+    }
+    gArgv[i] = NULL;
+
+    NSApplicationMain (argc, argv);
+    return 0;
+}
--- a/src/main/macosx/SDLMain.nib/classes.nib	Sun Sep 23 20:52:11 2001 +0000
+++ b/src/main/macosx/SDLMain.nib/classes.nib	Sun Sep 23 21:09:08 2001 +0000
@@ -3,7 +3,7 @@
         {CLASS = FirstResponder; LANGUAGE = ObjC; SUPERCLASS = NSObject; }, 
         {
             ACTIONS = {makeFullscreen = id; quit = id; }; 
-            CLASS = SDL_main; 
+            CLASS = SDLMain; 
             LANGUAGE = ObjC; 
             SUPERCLASS = NSObject; 
         }
--- a/src/main/macosx/SDL_main.h	Sun Sep 23 20:52:11 2001 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,15 +0,0 @@
-/*   SDL_main.h - main entry point for our Cocoa-ized SDL app
-       Darrell Walisser - dwaliss1@purdue.edu
-
-    Feel free to customize this file to suit your needs
-*/
-
-#import <Cocoa/Cocoa.h>
-
-@interface SDL_main : NSObject
-{
-}
-- (IBAction)quit:(id)sender;
-- (IBAction)makeFullscreen:(id)sender;
-- (void)applicationDidFinishLaunching:(NSNotification *)aNotification;
-@end
--- a/src/main/macosx/SDL_main.m	Sun Sep 23 20:52:11 2001 +0000
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,175 +0,0 @@
-/*   SDL_main.m - main entry point for our Cocoa-ized SDL app
-       Darrell Walisser - dwaliss1@purdue.edu
-
-    Feel free to customize this file to suit your needs
-*/
-
-#import "SDL.h"
-#import "SDL_main.h"
-#import <sys/param.h> /* for MAXPATHLEN */
-#import <unistd.h>
-
-static int    gArgc;
-static char  **gArgv;
-static NSString *gAppName = 0;
-static BOOL   gFinderLaunch;
-
-@interface NSString (ReplaceSubString)
-- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString;
-@end
-
-
-/* The main class of the application, the application's delegate */
-@implementation SDL_main
-
-/* Invoked from the Quit menu item */
-- (void) quit:(id)sender
-{
-    SDL_Event event;
-    event.type = SDL_QUIT;
-    SDL_PushEvent(&event);
-}
-
-/* Invoked from the Make Full-Screen menu item */
-- (void) makeFullscreen:(id)sender
-{
-    /* TODO */
-}
-
-/* Set the working directory to the .app's parent directory */
-- (void) setupWorkingDirectory:(BOOL)shouldChdir
-{
-    char parentdir[MAXPATHLEN];
-    char *c;
-    
-    strncpy ( parentdir, gArgv[0], sizeof(parentdir) );
-    c = (char*) parentdir;
-
-    while (*c != '\0')     /* go to end */
-        c++;
-    
-    while (*c != '/')      /* back up to parent */
-        c--;
-    
-    *c++ = '\0';             /* cut off last part (binary name) */
-  
-    if (shouldChdir)
-    {
-      assert ( chdir (parentdir) == 0 );   /* chdir to the binary app's parent */
-      assert ( chdir ("../../../") == 0 ); /* chdir to the .app's parent */
-    }
-    /* gAppName = [ NSString stringWithCString: c ]; */
-}
-
-/* Fix menu to contain the real app name instead of "SDL App" */
-- (void) fixMenu:(NSMenu *)aMenu
-{
-    NSRange aRange;
-    NSEnumerator *enumerator;
-    NSMenuItem *menuItem;
-
-    aRange = [[aMenu title] rangeOfString:@"SDL App"];
-    if (aRange.length != 0)
-        [aMenu setTitle: [[aMenu title] stringByReplacingRange:aRange with:gAppName]];
-
-    enumerator = [[aMenu itemArray] objectEnumerator];
-    while ((menuItem = [enumerator nextObject]))
-    {
-        aRange = [[menuItem title] rangeOfString:@"SDL App"];
-        if (aRange.length != 0)
-            [menuItem setTitle: [[menuItem title] stringByReplacingRange:aRange with:gAppName]];
-        if ([menuItem hasSubmenu])
-            [self fixMenu: [menuItem submenu]];
-    }
-    [ aMenu sizeToFit ];
-}
-
-/* Called when the internal event loop has just started running */
-- (void) applicationDidFinishLaunching: (NSNotification *) note
-{
-    int status;
-
-    /* Set the working directory to the .app's parent directory */
-    [ self setupWorkingDirectory: gFinderLaunch ];
-
-    /* Set the main menu to contain the real app name instead of "SDL App" */
-    gAppName = [ [ NSBundle mainBundle ] bundleIdentifier ];
-    [ self fixMenu: [ NSApp mainMenu ] ];
-
-    /* Hand off to main application code */
-    status = SDL_main (gArgc, gArgv);
-
-    /* We're done, thank you for playing */
-    exit(status);
-}
-@end
-
-
-@implementation NSString (ReplaceSubString)
-
-- (NSString *)stringByReplacingRange:(NSRange)aRange with:(NSString *)aString
-{
-    unsigned int bufferSize;
-    unsigned int selfLen = [self length];
-    unsigned int aStringLen = [aString length];
-    unichar *buffer;
-    NSRange localRange;
-    NSString *result;
-
-    bufferSize = selfLen + aStringLen - aRange.length;
-    buffer = NSAllocateMemoryPages(bufferSize*sizeof(unichar));
-    
-    // Get first part into buffer
-    localRange.location = 0;
-    localRange.length = aRange.location;
-    [self getCharacters:buffer range:localRange];
-    
-    // Get middle part into buffer
-    localRange.location = 0;
-    localRange.length = aStringLen;
-    [aString getCharacters:(buffer+aRange.location) range:localRange];
-     
-    // Get last part into buffer
-    localRange.location = aRange.location + aRange.length;
-    localRange.length = selfLen - localRange.location;
-    [self getCharacters:(buffer+aRange.location+aStringLen) range:localRange];
-    
-    // Build output string
-    result = [NSString stringWithCharacters:buffer length:bufferSize];
-    
-    NSDeallocateMemoryPages(buffer, bufferSize);
-    
-    return result;
-}
-
-@end
-
-
-#ifdef main
-#  undef main
-#endif
-
-/* Main entry point to executible - should *not* be SDL_main! */
-int main (int argc, char **argv) {
-
-    /* Copy the arguments into a global variable */
-    int i;
-    
-    /* This is passed if we are launched by double-clicking */
-    if ( argc >= 2 && strncmp (argv[1], "-psn", 4) == 0 ) {
-        gArgc = 1;
-	gFinderLaunch = YES;
-    } else {
-        gArgc = argc;
-	gFinderLaunch = NO;
-    }
-    gArgv = (char**) malloc (sizeof(*gArgv) * (gArgc+1));
-    assert (gArgv != NULL);
-    for (i = 0; i < gArgc; i++) {
-        gArgv[i] = argv[i];
-    }
-    gArgv[i] = NULL;
-
-    NSApplicationMain (argc, argv);
-    return 0;
-}