Changeset - r2188:6f92a4485e32
[Not reviewed]
master
0 3 2
bjarni - 19 years ago 2005-07-24 20:47:42
bjarni@openttd.org
(svn r2703) - Feature: [OSX] Added a native alert window to show whatever error() needs to print (Tobin made this, while I fixed some issued in it)
- As a bonus, we now have an objective C file (os/macosx/macos.m) to use the functions Apple made to interact with OS stuff
5 files changed with 47 insertions and 6 deletions:
0 comments (0 inline, 0 general)
Makefile
Show inline comments
 
@@ -715,12 +715,14 @@ C_SOURCES += music/null_m.c
 
C_SOURCES += sound/null_s.c
 
C_SOURCES += video/dedicated_v.c
 
C_SOURCES += video/null_v.c
 

	
 
CXX_SOURCES =
 

	
 
OBJC_SOURCES =
 

	
 
ifdef WITH_SDL
 
C_SOURCES += sdl.c
 
C_SOURCES += sound/sdl_s.c
 
C_SOURCES += video/sdl_v.c
 
endif
 

	
 
@@ -731,13 +733,17 @@ C_SOURCES += sound/win32_s.c
 
C_SOURCES += video/win32_v.c
 
else
 
C_SOURCES += unix.c
 
C_SOURCES += music/extmidi.c
 
endif
 

	
 
OBJS = $(C_SOURCES:%.c=%.o) $(CXX_SOURCES:%.cpp=%.o)
 
ifdef OSX
 
OBJC_SOURCES += os/macosx/macos.m
 
endif
 

	
 
OBJS = $(C_SOURCES:%.c=%.o) $(CXX_SOURCES:%.cpp=%.o) $(OBJC_SOURCES:%.m=%.o)
 

	
 
ifdef BEOS
 
CXX_SOURCES += music/bemidi.cpp
 
endif
 

	
 
ifdef WIN32
 
@@ -792,12 +798,15 @@ COMPILE_PARAMS=$(CFLAGS) $(CDEFS) -MD -c
 
quiet_cmd_c_compile = '===> Compiling $<'
 
      cmd_c_compile = $(CC) $(COMPILE_PARAMS)
 

	
 
quiet_cmd_cxx_compile = '===> Compiling $<'
 
      cmd_cxx_compile = $(CXX) $(COMPILE_PARAMS)
 

	
 
quiet_cmd_objc_compile = '===> Compiling $<'
 
      cmd_objc_compile = $(CC) $(COMPILE_PARAMS)
 

	
 

	
 
##############################################################################
 
#
 
# Targets
 
#
 

	
 
@@ -1033,13 +1042,13 @@ upgradeconf: $(MAKE_CONFIG)
 
.PHONY: upgradeconf
 

	
 

	
 
### Internal build rules
 

	
 
# This makes sure the .deps dir is always around.
 
DEPS_MAGIC := $(shell mkdir -p .deps .deps/music .deps/sound .deps/video)
 
DEPS_MAGIC := $(shell mkdir -p .deps .deps/music .deps/sound .deps/video .deps/os .deps/os/macosx)
 

	
 
# Introduce the dependencies
 
-include $(DEPS)
 

	
 
# This compiles the object file as well as silently updating its dependencies
 
# list at the same time. It is not an issue that they aren't around during the
 
@@ -1051,12 +1060,16 @@ DEPS_MAGIC := $(shell mkdir -p .deps .de
 
	@mv $(<:%.c=%.d) $(<:%.c=.deps/%.d)
 

	
 
%.o: %.cpp  $(MAKE_CONFIG) endian_target.h table/strings.h
 
	$(call cmd,cxx_compile)
 
	@mv $(<:%.cpp=%.d) $(<:%.cpp=.deps/%.d)
 

	
 
%.o: %.m  $(MAKE_CONFIG) endian_target.h table/strings.h
 
	$(call cmd,objc_compile)
 
	@mv $(<:%.m=%.d) $(<:%.m=.deps/%.d)
 

	
 
# Silence stale header dependencies
 
%.h:
 
	@true
 

	
 

	
 
info:
fileio.c
Show inline comments
 
@@ -162,12 +162,16 @@ void FioOpenFile(int slot, const char *f
 
		if (f == NULL) {
 
			sprintf(buf, "%s%s", _path.second_data_dir, filename);
 
			for(s=buf + strlen(_path.second_data_dir) - 1; *s != 0; s++)
 
			*s = tolower(*s);
 
		f = fopen(buf, "rb");
 
		}
 

	
 
	if (f == NULL)
 
		sprintf(buf, "%s%s", _path.data_dir, filename);	//makes it print the primary datadir path instead of the secundary one
 

	
 
#endif
 
	}
 
#endif
 

	
 
	if (f == NULL)
 
		error("Cannot open file '%s'", buf);
os/macosx/macos.h
Show inline comments
 
new file 100644
 
#ifndef MACOS_H
 
#define MACOS_H
 

	
 
void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel );
 

	
 
#endif /* MACOS_H */
 
\ No newline at end of file
os/macosx/macos.m
Show inline comments
 
new file 100644
 
#include <AppKit/AppKit.h>
 

	
 
/*
 
 * This file contains objective C
 
 * Apple uses objective C instead of plain C to interact with OS specific/native functions
 
 *
 
 * Note: TrueLight's crosscompiler can handle this, but it likely needs a manual modification for each change in this file.
 
 * To insure that the crosscompiler still works, let him try any changes before they are committed
 
 */
 

	
 
void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel )
 
{
 
	NSRunAlertPanel([NSString stringWithCString: title], [NSString stringWithCString: message], [NSString stringWithCString: buttonLabel], nil, nil);
 
}
 

	
unix.c
Show inline comments
 
@@ -50,12 +50,16 @@ ULONG __stack = (1024*1024)*2; // maybe 
 

	
 
#ifdef __AMIGA__
 
#warning add stack symbol to avoid that user needs to set stack manually (tokai)
 
// ULONG __stack =
 
#endif
 

	
 
#if defined(__APPLE__)
 
#include "os/macosx/macos.h"
 
#endif
 

	
 
static char *_fios_path;
 
static char *_fios_save_path;
 
static char *_fios_scn_path;
 
static FiosItem *_fios_items;
 
static int _fios_count, _fios_alloc;
 

	
 
@@ -464,16 +468,15 @@ void ShowInfo(const char *str)
 
	puts(str);
 
}
 

	
 
void ShowOSErrorBox(const char *buf)
 
{
 
#if defined(__APPLE__)
 
	// this creates an error in the console and then opens the console.
 
	// Colourcodes are not used in the console, so they are skipped here
 
	fprintf(stderr, "Error: %s", buf);
 
	system("/Applications/Utilities/Console.app/Contents/MacOS/Console &");
 
	// this creates an NSAlertPanel with the contents of 'buf'
 
	// this is the native and nicest way to do this on OSX
 
	ShowMacDialog( buf, "See readme for more info\nMost likely you are missing files from the original TTD", "Quit" );
 
#else
 
	// all systems, but OSX
 
	fprintf(stderr, "\033[1;31mError: %s\033[0;39m\n", buf);
 
#endif
 
}
 

	
0 comments (0 inline, 0 general)