mirror of
https://github.com/yawut/SDL.git
synced 2026-10-26 08:29:46 -05:00
SDL 1.2 is moving to a branch, and SDL 1.3 is becoming the head.
This commit is contained in:
@@ -37,73 +37,79 @@
|
||||
int SDL_BeAppActive = 0;
|
||||
static SDL_Thread *SDL_AppThread = NULL;
|
||||
|
||||
static int StartBeApp(void *unused)
|
||||
static int
|
||||
StartBeApp(void *unused)
|
||||
{
|
||||
BApplication *App;
|
||||
BApplication *App;
|
||||
|
||||
App = new BApplication("application/x-SDL-executable");
|
||||
App = new BApplication("application/x-SDL-executable");
|
||||
|
||||
App->Run();
|
||||
delete App;
|
||||
return(0);
|
||||
App->Run();
|
||||
delete App;
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Initialize the Be Application, if it's not already started */
|
||||
int SDL_InitBeApp(void)
|
||||
int
|
||||
SDL_InitBeApp(void)
|
||||
{
|
||||
/* Create the BApplication that handles appserver interaction */
|
||||
if ( SDL_BeAppActive <= 0 ) {
|
||||
SDL_AppThread = SDL_CreateThread(StartBeApp, NULL);
|
||||
if ( SDL_AppThread == NULL ) {
|
||||
SDL_SetError("Couldn't create BApplication thread");
|
||||
return(-1);
|
||||
}
|
||||
|
||||
/* Change working to directory to that of executable */
|
||||
app_info info;
|
||||
if (B_OK == be_app->GetAppInfo(&info)) {
|
||||
entry_ref ref = info.ref;
|
||||
BEntry entry;
|
||||
if (B_OK == entry.SetTo(&ref)) {
|
||||
BPath path;
|
||||
if (B_OK == path.SetTo(&entry)) {
|
||||
if (B_OK == path.GetParent(&path)) {
|
||||
chdir(path.Path());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
do {
|
||||
SDL_Delay(10);
|
||||
} while ( (be_app == NULL) || be_app->IsLaunching() );
|
||||
/* Create the BApplication that handles appserver interaction */
|
||||
if (SDL_BeAppActive <= 0) {
|
||||
SDL_AppThread = SDL_CreateThread(StartBeApp, NULL);
|
||||
if (SDL_AppThread == NULL) {
|
||||
SDL_SetError("Couldn't create BApplication thread");
|
||||
return (-1);
|
||||
}
|
||||
|
||||
/* Mark the application active */
|
||||
SDL_BeAppActive = 0;
|
||||
}
|
||||
/* Change working to directory to that of executable */
|
||||
app_info info;
|
||||
if (B_OK == be_app->GetAppInfo(&info)) {
|
||||
entry_ref ref = info.ref;
|
||||
BEntry entry;
|
||||
if (B_OK == entry.SetTo(&ref)) {
|
||||
BPath path;
|
||||
if (B_OK == path.SetTo(&entry)) {
|
||||
if (B_OK == path.GetParent(&path)) {
|
||||
chdir(path.Path());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Increment the application reference count */
|
||||
++SDL_BeAppActive;
|
||||
do {
|
||||
SDL_Delay(10);
|
||||
}
|
||||
while ((be_app == NULL) || be_app->IsLaunching());
|
||||
|
||||
/* The app is running, and we're ready to go */
|
||||
return(0);
|
||||
/* Mark the application active */
|
||||
SDL_BeAppActive = 0;
|
||||
}
|
||||
|
||||
/* Increment the application reference count */
|
||||
++SDL_BeAppActive;
|
||||
|
||||
/* The app is running, and we're ready to go */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Quit the Be Application, if there's nothing left to do */
|
||||
void SDL_QuitBeApp(void)
|
||||
void
|
||||
SDL_QuitBeApp(void)
|
||||
{
|
||||
/* Decrement the application reference count */
|
||||
--SDL_BeAppActive;
|
||||
/* Decrement the application reference count */
|
||||
--SDL_BeAppActive;
|
||||
|
||||
/* If the reference count reached zero, clean up the app */
|
||||
if ( SDL_BeAppActive == 0 ) {
|
||||
if ( SDL_AppThread != NULL ) {
|
||||
if ( be_app != NULL ) { /* Not tested */
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
SDL_WaitThread(SDL_AppThread, NULL);
|
||||
SDL_AppThread = NULL;
|
||||
}
|
||||
/* be_app should now be NULL since be_app has quit */
|
||||
}
|
||||
/* If the reference count reached zero, clean up the app */
|
||||
if (SDL_BeAppActive == 0) {
|
||||
if (SDL_AppThread != NULL) {
|
||||
if (be_app != NULL) { /* Not tested */
|
||||
be_app->PostMessage(B_QUIT_REQUESTED);
|
||||
}
|
||||
SDL_WaitThread(SDL_AppThread, NULL);
|
||||
SDL_AppThread = NULL;
|
||||
}
|
||||
/* be_app should now be NULL since be_app has quit */
|
||||
}
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -31,3 +31,4 @@ extern void SDL_QuitBeApp(void);
|
||||
|
||||
/* Flag to tell whether the app is active or not */
|
||||
extern int SDL_BeAppActive;
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -4,10 +4,12 @@
|
||||
|
||||
#ifdef main
|
||||
#undef main
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
return(SDL_main(argc, argv));
|
||||
return (SDL_main(argc, argv));
|
||||
}
|
||||
#else
|
||||
/* Nothing to do on this platform */
|
||||
#endif
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -50,561 +50,598 @@
|
||||
#endif
|
||||
|
||||
#if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON
|
||||
/* In MPW, the qd global has been removed from the libraries */
|
||||
QDGlobals qd;
|
||||
/* In MPW, the qd global has been removed from the libraries */
|
||||
QDGlobals qd;
|
||||
#endif
|
||||
|
||||
/* Structure for keeping prefs in 1 variable */
|
||||
typedef struct {
|
||||
Str255 command_line;
|
||||
Str255 video_driver_name;
|
||||
typedef struct
|
||||
{
|
||||
Str255 command_line;
|
||||
Str255 video_driver_name;
|
||||
Boolean output_to_file;
|
||||
} PrefsRecord;
|
||||
} PrefsRecord;
|
||||
|
||||
/* See if the command key is held down at startup */
|
||||
static Boolean CommandKeyIsDown(void)
|
||||
static Boolean
|
||||
CommandKeyIsDown(void)
|
||||
{
|
||||
KeyMap theKeyMap;
|
||||
KeyMap theKeyMap;
|
||||
|
||||
GetKeys(theKeyMap);
|
||||
GetKeys(theKeyMap);
|
||||
|
||||
if (((unsigned char *) theKeyMap)[6] & 0x80) {
|
||||
return(true);
|
||||
}
|
||||
return(false);
|
||||
if (((unsigned char *) theKeyMap)[6] & 0x80) {
|
||||
return (true);
|
||||
}
|
||||
return (false);
|
||||
}
|
||||
|
||||
#if !(defined(__APPLE__) && defined(__MACH__))
|
||||
|
||||
/* Parse a command line buffer into arguments */
|
||||
static int ParseCommandLine(char *cmdline, char **argv)
|
||||
static int
|
||||
ParseCommandLine(char *cmdline, char **argv)
|
||||
{
|
||||
char *bufp;
|
||||
int argc;
|
||||
char *bufp;
|
||||
int argc;
|
||||
|
||||
argc = 0;
|
||||
for ( bufp = cmdline; *bufp; ) {
|
||||
/* Skip leading whitespace */
|
||||
while ( SDL_isspace(*bufp) ) {
|
||||
++bufp;
|
||||
}
|
||||
/* Skip over argument */
|
||||
if ( *bufp == '"' ) {
|
||||
++bufp;
|
||||
if ( *bufp ) {
|
||||
if ( argv ) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while ( *bufp && (*bufp != '"') ) {
|
||||
++bufp;
|
||||
}
|
||||
} else {
|
||||
if ( *bufp ) {
|
||||
if ( argv ) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while ( *bufp && ! SDL_isspace(*bufp) ) {
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if ( *bufp ) {
|
||||
if ( argv ) {
|
||||
*bufp = '\0';
|
||||
}
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if ( argv ) {
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
return(argc);
|
||||
argc = 0;
|
||||
for (bufp = cmdline; *bufp;) {
|
||||
/* Skip leading whitespace */
|
||||
while (SDL_isspace(*bufp)) {
|
||||
++bufp;
|
||||
}
|
||||
/* Skip over argument */
|
||||
if (*bufp == '"') {
|
||||
++bufp;
|
||||
if (*bufp) {
|
||||
if (argv) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while (*bufp && (*bufp != '"')) {
|
||||
++bufp;
|
||||
}
|
||||
} else {
|
||||
if (*bufp) {
|
||||
if (argv) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while (*bufp && !SDL_isspace(*bufp)) {
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if (*bufp) {
|
||||
if (argv) {
|
||||
*bufp = '\0';
|
||||
}
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if (argv) {
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
return (argc);
|
||||
}
|
||||
|
||||
/* Remove the output files if there was no output written */
|
||||
static void cleanup_output(void)
|
||||
static void
|
||||
cleanup_output(void)
|
||||
{
|
||||
FILE *file;
|
||||
int empty;
|
||||
FILE *file;
|
||||
int empty;
|
||||
|
||||
/* Flush the output in case anything is queued */
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
/* Flush the output in case anything is queued */
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
|
||||
/* See if the files have any output in them */
|
||||
file = fopen(STDOUT_FILE, "rb");
|
||||
if ( file ) {
|
||||
empty = (fgetc(file) == EOF) ? 1 : 0;
|
||||
fclose(file);
|
||||
if ( empty ) {
|
||||
remove(STDOUT_FILE);
|
||||
}
|
||||
}
|
||||
file = fopen(STDERR_FILE, "rb");
|
||||
if ( file ) {
|
||||
empty = (fgetc(file) == EOF) ? 1 : 0;
|
||||
fclose(file);
|
||||
if ( empty ) {
|
||||
remove(STDERR_FILE);
|
||||
}
|
||||
}
|
||||
/* See if the files have any output in them */
|
||||
file = fopen(STDOUT_FILE, "rb");
|
||||
if (file) {
|
||||
empty = (fgetc(file) == EOF) ? 1 : 0;
|
||||
fclose(file);
|
||||
if (empty) {
|
||||
remove(STDOUT_FILE);
|
||||
}
|
||||
}
|
||||
file = fopen(STDERR_FILE, "rb");
|
||||
if (file) {
|
||||
empty = (fgetc(file) == EOF) ? 1 : 0;
|
||||
fclose(file);
|
||||
if (empty) {
|
||||
remove(STDERR_FILE);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#endif //!(defined(__APPLE__) && defined(__MACH__))
|
||||
|
||||
static int getCurrentAppName (StrFileName name) {
|
||||
|
||||
static int
|
||||
getCurrentAppName(StrFileName name)
|
||||
{
|
||||
|
||||
ProcessSerialNumber process;
|
||||
ProcessInfoRec process_info;
|
||||
FSSpec process_fsp;
|
||||
|
||||
ProcessInfoRec process_info;
|
||||
FSSpec process_fsp;
|
||||
|
||||
process.highLongOfPSN = 0;
|
||||
process.lowLongOfPSN = kCurrentProcess;
|
||||
process_info.processInfoLength = sizeof (process_info);
|
||||
process_info.processName = NULL;
|
||||
process.lowLongOfPSN = kCurrentProcess;
|
||||
process_info.processInfoLength = sizeof(process_info);
|
||||
process_info.processName = NULL;
|
||||
process_info.processAppSpec = &process_fsp;
|
||||
|
||||
if ( noErr != GetProcessInformation (&process, &process_info) )
|
||||
return 0;
|
||||
|
||||
|
||||
if (noErr != GetProcessInformation(&process, &process_info))
|
||||
return 0;
|
||||
|
||||
SDL_memcpy(name, process_fsp.name, process_fsp.name[0] + 1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int getPrefsFile (FSSpec *prefs_fsp, int create) {
|
||||
static int
|
||||
getPrefsFile(FSSpec * prefs_fsp, int create)
|
||||
{
|
||||
|
||||
/* The prefs file name is the application name, possibly truncated, */
|
||||
/* plus " Preferences */
|
||||
|
||||
#define SUFFIX " Preferences"
|
||||
#define MAX_NAME 19 /* 31 - strlen (SUFFIX) */
|
||||
|
||||
short volume_ref_number;
|
||||
long directory_id;
|
||||
StrFileName prefs_name;
|
||||
StrFileName app_name;
|
||||
|
||||
|
||||
#define SUFFIX " Preferences"
|
||||
#define MAX_NAME 19 /* 31 - strlen (SUFFIX) */
|
||||
|
||||
short volume_ref_number;
|
||||
long directory_id;
|
||||
StrFileName prefs_name;
|
||||
StrFileName app_name;
|
||||
|
||||
/* Get Preferences folder - works with Multiple Users */
|
||||
if ( noErr != FindFolder ( kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
|
||||
&volume_ref_number, &directory_id) )
|
||||
exit (-1);
|
||||
|
||||
if ( ! getCurrentAppName (app_name) )
|
||||
exit (-1);
|
||||
|
||||
if (noErr !=
|
||||
FindFolder(kOnSystemDisk, kPreferencesFolderType, kDontCreateFolder,
|
||||
&volume_ref_number, &directory_id))
|
||||
exit(-1);
|
||||
|
||||
if (!getCurrentAppName(app_name))
|
||||
exit(-1);
|
||||
|
||||
/* Truncate if name is too long */
|
||||
if (app_name[0] > MAX_NAME )
|
||||
if (app_name[0] > MAX_NAME)
|
||||
app_name[0] = MAX_NAME;
|
||||
|
||||
SDL_memcpy(prefs_name + 1, app_name + 1, app_name[0]);
|
||||
SDL_memcpy(prefs_name + app_name[0] + 1, SUFFIX, strlen (SUFFIX));
|
||||
prefs_name[0] = app_name[0] + strlen (SUFFIX);
|
||||
|
||||
|
||||
SDL_memcpy(prefs_name + 1, app_name + 1, app_name[0]);
|
||||
SDL_memcpy(prefs_name + app_name[0] + 1, SUFFIX, strlen(SUFFIX));
|
||||
prefs_name[0] = app_name[0] + strlen(SUFFIX);
|
||||
|
||||
/* Make the file spec for prefs file */
|
||||
if ( noErr != FSMakeFSSpec (volume_ref_number, directory_id, prefs_name, prefs_fsp) ) {
|
||||
if ( !create )
|
||||
if (noErr !=
|
||||
FSMakeFSSpec(volume_ref_number, directory_id, prefs_name, prefs_fsp))
|
||||
{
|
||||
if (!create)
|
||||
return 0;
|
||||
else {
|
||||
/* Create the prefs file */
|
||||
SDL_memcpy(prefs_fsp->name, prefs_name, prefs_name[0] + 1);
|
||||
prefs_fsp->parID = directory_id;
|
||||
prefs_fsp->parID = directory_id;
|
||||
prefs_fsp->vRefNum = volume_ref_number;
|
||||
|
||||
FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph
|
||||
|
||||
if ( noErr != ResError () )
|
||||
|
||||
FSpCreateResFile(prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph
|
||||
|
||||
if (noErr != ResError())
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static int readPrefsResource (PrefsRecord *prefs) {
|
||||
|
||||
static int
|
||||
readPrefsResource(PrefsRecord * prefs)
|
||||
{
|
||||
|
||||
Handle prefs_handle;
|
||||
|
||||
prefs_handle = Get1Resource( 'CLne', 128 );
|
||||
|
||||
if (prefs_handle != NULL) {
|
||||
int offset = 0;
|
||||
// int j = 0;
|
||||
|
||||
HLock(prefs_handle);
|
||||
|
||||
/* Get command line string */
|
||||
SDL_memcpy(prefs->command_line, *prefs_handle, (*prefs_handle)[0]+1);
|
||||
prefs_handle = Get1Resource('CLne', 128);
|
||||
|
||||
if (prefs_handle != NULL) {
|
||||
int offset = 0;
|
||||
// int j = 0;
|
||||
|
||||
HLock(prefs_handle);
|
||||
|
||||
/* Get command line string */
|
||||
SDL_memcpy(prefs->command_line, *prefs_handle,
|
||||
(*prefs_handle)[0] + 1);
|
||||
|
||||
/* Get video driver name */
|
||||
offset += (*prefs_handle)[0] + 1;
|
||||
SDL_memcpy(prefs->video_driver_name, *prefs_handle + offset,
|
||||
(*prefs_handle)[offset] + 1);
|
||||
|
||||
/* Get save-to-file option (1 or 0) */
|
||||
offset += (*prefs_handle)[offset] + 1;
|
||||
prefs->output_to_file = (*prefs_handle)[offset];
|
||||
|
||||
ReleaseResource(prefs_handle);
|
||||
|
||||
/* Get video driver name */
|
||||
offset += (*prefs_handle)[0] + 1;
|
||||
SDL_memcpy(prefs->video_driver_name, *prefs_handle + offset, (*prefs_handle)[offset] + 1);
|
||||
|
||||
/* Get save-to-file option (1 or 0) */
|
||||
offset += (*prefs_handle)[offset] + 1;
|
||||
prefs->output_to_file = (*prefs_handle)[offset];
|
||||
|
||||
ReleaseResource( prefs_handle );
|
||||
|
||||
return ResError() == noErr;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int writePrefsResource (PrefsRecord *prefs, short resource_file) {
|
||||
static int
|
||||
writePrefsResource(PrefsRecord * prefs, short resource_file)
|
||||
{
|
||||
|
||||
Handle prefs_handle;
|
||||
|
||||
UseResFile (resource_file);
|
||||
|
||||
prefs_handle = Get1Resource ( 'CLne', 128 );
|
||||
|
||||
UseResFile(resource_file);
|
||||
|
||||
prefs_handle = Get1Resource('CLne', 128);
|
||||
if (prefs_handle != NULL)
|
||||
RemoveResource (prefs_handle);
|
||||
|
||||
prefs_handle = NewHandle ( prefs->command_line[0] + prefs->video_driver_name[0] + 4 );
|
||||
RemoveResource(prefs_handle);
|
||||
|
||||
prefs_handle =
|
||||
NewHandle(prefs->command_line[0] + prefs->video_driver_name[0] + 4);
|
||||
if (prefs_handle != NULL) {
|
||||
|
||||
|
||||
int offset;
|
||||
|
||||
HLock (prefs_handle);
|
||||
|
||||
|
||||
HLock(prefs_handle);
|
||||
|
||||
/* Command line text */
|
||||
offset = 0;
|
||||
SDL_memcpy(*prefs_handle, prefs->command_line, prefs->command_line[0] + 1);
|
||||
|
||||
SDL_memcpy(*prefs_handle, prefs->command_line,
|
||||
prefs->command_line[0] + 1);
|
||||
|
||||
/* Video driver name */
|
||||
offset += prefs->command_line[0] + 1;
|
||||
SDL_memcpy(*prefs_handle + offset, prefs->video_driver_name, prefs->video_driver_name[0] + 1);
|
||||
|
||||
SDL_memcpy(*prefs_handle + offset, prefs->video_driver_name,
|
||||
prefs->video_driver_name[0] + 1);
|
||||
|
||||
/* Output-to-file option */
|
||||
offset += prefs->video_driver_name[0] + 1;
|
||||
*( *((char**)prefs_handle) + offset) = (char)prefs->output_to_file;
|
||||
*( *((char**)prefs_handle) + offset + 1) = 0;
|
||||
|
||||
AddResource (prefs_handle, 'CLne', 128, "\pCommand Line");
|
||||
WriteResource (prefs_handle);
|
||||
UpdateResFile (resource_file);
|
||||
DisposeHandle (prefs_handle);
|
||||
|
||||
*(*((char **) prefs_handle) + offset) = (char) prefs->output_to_file;
|
||||
*(*((char **) prefs_handle) + offset + 1) = 0;
|
||||
|
||||
AddResource(prefs_handle, 'CLne', 128, "\pCommand Line");
|
||||
WriteResource(prefs_handle);
|
||||
UpdateResFile(resource_file);
|
||||
DisposeHandle(prefs_handle);
|
||||
|
||||
return ResError() == noErr;
|
||||
}
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int readPreferences (PrefsRecord *prefs) {
|
||||
static int
|
||||
readPreferences(PrefsRecord * prefs)
|
||||
{
|
||||
|
||||
int no_error = 1;
|
||||
int no_error = 1;
|
||||
FSSpec prefs_fsp;
|
||||
|
||||
/* Check for prefs file first */
|
||||
if ( getPrefsFile (&prefs_fsp, 0) ) {
|
||||
|
||||
short prefs_resource;
|
||||
|
||||
prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdPerm);
|
||||
if ( prefs_resource == -1 ) /* this shouldn't happen, but... */
|
||||
if (getPrefsFile(&prefs_fsp, 0)) {
|
||||
|
||||
short prefs_resource;
|
||||
|
||||
prefs_resource = FSpOpenResFile(&prefs_fsp, fsRdPerm);
|
||||
if (prefs_resource == -1) /* this shouldn't happen, but... */
|
||||
return 0;
|
||||
|
||||
UseResFile (prefs_resource);
|
||||
no_error = readPrefsResource (prefs);
|
||||
CloseResFile (prefs_resource);
|
||||
|
||||
UseResFile(prefs_resource);
|
||||
no_error = readPrefsResource(prefs);
|
||||
CloseResFile(prefs_resource);
|
||||
}
|
||||
|
||||
|
||||
/* Fall back to application's resource fork (reading only, so this is safe) */
|
||||
else {
|
||||
|
||||
no_error = readPrefsResource (prefs);
|
||||
}
|
||||
|
||||
no_error = readPrefsResource(prefs);
|
||||
}
|
||||
|
||||
return no_error;
|
||||
}
|
||||
|
||||
static int writePreferences (PrefsRecord *prefs) {
|
||||
|
||||
int no_error = 1;
|
||||
static int
|
||||
writePreferences(PrefsRecord * prefs)
|
||||
{
|
||||
|
||||
int no_error = 1;
|
||||
FSSpec prefs_fsp;
|
||||
|
||||
|
||||
/* Get prefs file, create if it doesn't exist */
|
||||
if ( getPrefsFile (&prefs_fsp, 1) ) {
|
||||
|
||||
short prefs_resource;
|
||||
|
||||
prefs_resource = FSpOpenResFile (&prefs_fsp, fsRdWrPerm);
|
||||
if (getPrefsFile(&prefs_fsp, 1)) {
|
||||
|
||||
short prefs_resource;
|
||||
|
||||
prefs_resource = FSpOpenResFile(&prefs_fsp, fsRdWrPerm);
|
||||
if (prefs_resource == -1)
|
||||
return 0;
|
||||
no_error = writePrefsResource (prefs, prefs_resource);
|
||||
CloseResFile (prefs_resource);
|
||||
no_error = writePrefsResource(prefs, prefs_resource);
|
||||
CloseResFile(prefs_resource);
|
||||
}
|
||||
|
||||
|
||||
return no_error;
|
||||
}
|
||||
|
||||
/* This is where execution begins */
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
|
||||
#if !(defined(__APPLE__) && defined(__MACH__))
|
||||
#pragma unused(argc, argv)
|
||||
#endif
|
||||
|
||||
#define DEFAULT_ARGS "\p" /* pascal string for default args */
|
||||
#define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */
|
||||
#define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */
|
||||
|
||||
#define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */
|
||||
#define DEFAULT_ARGS "\p" /* pascal string for default args */
|
||||
#define DEFAULT_VIDEO_DRIVER "\ptoolbox" /* pascal string for default video driver name */
|
||||
#define DEFAULT_OUTPUT_TO_FILE 1 /* 1 == output to file, 0 == no output */
|
||||
|
||||
#define VIDEO_ID_DRAWSPROCKET 1 /* these correspond to popup menu choices */
|
||||
#define VIDEO_ID_TOOLBOX 2
|
||||
|
||||
PrefsRecord prefs = { DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE };
|
||||
|
||||
#if !(defined(__APPLE__) && defined(__MACH__))
|
||||
int nargs;
|
||||
char **args;
|
||||
char *commandLine;
|
||||
|
||||
StrFileName appNameText;
|
||||
#endif
|
||||
int videodriver = VIDEO_ID_TOOLBOX;
|
||||
int settingsChanged = 0;
|
||||
|
||||
long i;
|
||||
PrefsRecord prefs =
|
||||
{ DEFAULT_ARGS, DEFAULT_VIDEO_DRIVER, DEFAULT_OUTPUT_TO_FILE };
|
||||
|
||||
/* Kyle's SDL command-line dialog code ... */
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
InitGraf (&qd.thePort);
|
||||
InitFonts ();
|
||||
InitWindows ();
|
||||
InitMenus ();
|
||||
InitDialogs (nil);
|
||||
#if !(defined(__APPLE__) && defined(__MACH__))
|
||||
int nargs;
|
||||
char **args;
|
||||
char *commandLine;
|
||||
|
||||
StrFileName appNameText;
|
||||
#endif
|
||||
InitCursor ();
|
||||
FlushEvents(everyEvent,0);
|
||||
int videodriver = VIDEO_ID_TOOLBOX;
|
||||
int settingsChanged = 0;
|
||||
|
||||
long i;
|
||||
|
||||
/* Kyle's SDL command-line dialog code ... */
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
MaxApplZone ();
|
||||
InitGraf(&qd.thePort);
|
||||
InitFonts();
|
||||
InitWindows();
|
||||
InitMenus();
|
||||
InitDialogs(nil);
|
||||
#endif
|
||||
MoreMasters ();
|
||||
MoreMasters ();
|
||||
InitCursor();
|
||||
FlushEvents(everyEvent, 0);
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
MaxApplZone();
|
||||
#endif
|
||||
MoreMasters();
|
||||
MoreMasters();
|
||||
#if 0
|
||||
/* Intialize SDL, and put up a dialog if we fail */
|
||||
if ( SDL_Init (0) < 0 ) {
|
||||
/* Intialize SDL, and put up a dialog if we fail */
|
||||
if (SDL_Init(0) < 0) {
|
||||
|
||||
#define kErr_OK 1
|
||||
#define kErr_Text 2
|
||||
|
||||
DialogPtr errorDialog;
|
||||
short dummyType;
|
||||
Rect dummyRect;
|
||||
Handle dummyHandle;
|
||||
short itemHit;
|
||||
|
||||
errorDialog = GetNewDialog (1001, nil, (WindowPtr)-1);
|
||||
if (errorDialog == NULL)
|
||||
return -1;
|
||||
DrawDialog (errorDialog);
|
||||
|
||||
GetDialogItem (errorDialog, kErr_Text, &dummyType, &dummyHandle, &dummyRect);
|
||||
SetDialogItemText (dummyHandle, "\pError Initializing SDL");
|
||||
|
||||
short dummyType;
|
||||
Rect dummyRect;
|
||||
Handle dummyHandle;
|
||||
short itemHit;
|
||||
|
||||
errorDialog = GetNewDialog(1001, nil, (WindowPtr) - 1);
|
||||
if (errorDialog == NULL)
|
||||
return -1;
|
||||
DrawDialog(errorDialog);
|
||||
|
||||
GetDialogItem(errorDialog, kErr_Text, &dummyType, &dummyHandle,
|
||||
&dummyRect);
|
||||
SetDialogItemText(dummyHandle, "\pError Initializing SDL");
|
||||
|
||||
#if TARGET_API_MAC_CARBON
|
||||
SetPort (GetDialogPort(errorDialog));
|
||||
SetPort(GetDialogPort(errorDialog));
|
||||
#else
|
||||
SetPort (errorDialog);
|
||||
SetPort(errorDialog);
|
||||
#endif
|
||||
do {
|
||||
ModalDialog (nil, &itemHit);
|
||||
} while (itemHit != kErr_OK);
|
||||
|
||||
DisposeDialog (errorDialog);
|
||||
exit (-1);
|
||||
}
|
||||
atexit(cleanup_output);
|
||||
atexit(SDL_Quit);
|
||||
do {
|
||||
ModalDialog(nil, &itemHit);
|
||||
}
|
||||
while (itemHit != kErr_OK);
|
||||
|
||||
DisposeDialog(errorDialog);
|
||||
exit(-1);
|
||||
}
|
||||
atexit(cleanup_output);
|
||||
atexit(SDL_Quit);
|
||||
#endif
|
||||
|
||||
/* Set up SDL's QuickDraw environment */
|
||||
#if !TARGET_API_MAC_CARBON
|
||||
SDL_InitQuickDraw(&qd);
|
||||
SDL_InitQuickDraw(&qd);
|
||||
#endif
|
||||
|
||||
if ( readPreferences (&prefs) ) {
|
||||
|
||||
if (SDL_memcmp(prefs.video_driver_name+1, "DSp", 3) == 0)
|
||||
if (readPreferences(&prefs)) {
|
||||
|
||||
if (SDL_memcmp(prefs.video_driver_name + 1, "DSp", 3) == 0)
|
||||
videodriver = 1;
|
||||
else if (SDL_memcmp(prefs.video_driver_name+1, "toolbox", 7) == 0)
|
||||
else if (SDL_memcmp(prefs.video_driver_name + 1, "toolbox", 7) == 0)
|
||||
videodriver = 2;
|
||||
}
|
||||
|
||||
if ( CommandKeyIsDown() ) {
|
||||
}
|
||||
|
||||
if (CommandKeyIsDown()) {
|
||||
|
||||
#define kCL_OK 1
|
||||
#define kCL_Cancel 2
|
||||
#define kCL_Text 3
|
||||
#define kCL_File 4
|
||||
#define kCL_Video 6
|
||||
|
||||
|
||||
DialogPtr commandDialog;
|
||||
short dummyType;
|
||||
Rect dummyRect;
|
||||
Handle dummyHandle;
|
||||
short itemHit;
|
||||
#if TARGET_API_MAC_CARBON
|
||||
short dummyType;
|
||||
Rect dummyRect;
|
||||
Handle dummyHandle;
|
||||
short itemHit;
|
||||
#if TARGET_API_MAC_CARBON
|
||||
ControlRef control;
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
/* Assume that they will change settings, rather than do exhaustive check */
|
||||
settingsChanged = 1;
|
||||
|
||||
|
||||
/* Create dialog and display it */
|
||||
commandDialog = GetNewDialog (1000, nil, (WindowPtr)-1);
|
||||
#if TARGET_API_MAC_CARBON
|
||||
SetPort ( GetDialogPort(commandDialog) );
|
||||
#else
|
||||
SetPort (commandDialog);
|
||||
#endif
|
||||
|
||||
commandDialog = GetNewDialog(1000, nil, (WindowPtr) - 1);
|
||||
#if TARGET_API_MAC_CARBON
|
||||
SetPort(GetDialogPort(commandDialog));
|
||||
#else
|
||||
SetPort(commandDialog);
|
||||
#endif
|
||||
|
||||
/* Setup controls */
|
||||
#if TARGET_API_MAC_CARBON
|
||||
#if TARGET_API_MAC_CARBON
|
||||
GetDialogItemAsControl(commandDialog, kCL_File, &control);
|
||||
SetControlValue (control, prefs.output_to_file);
|
||||
#else
|
||||
GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
SetControlValue ((ControlHandle)dummyHandle, prefs.output_to_file );
|
||||
#endif
|
||||
SetControlValue(control, prefs.output_to_file);
|
||||
#else
|
||||
GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
SetControlValue((ControlHandle) dummyHandle, prefs.output_to_file);
|
||||
#endif
|
||||
|
||||
GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect);
|
||||
SetDialogItemText (dummyHandle, prefs.command_line);
|
||||
GetDialogItem(commandDialog, kCL_Text, &dummyType, &dummyHandle,
|
||||
&dummyRect);
|
||||
SetDialogItemText(dummyHandle, prefs.command_line);
|
||||
|
||||
#if TARGET_API_MAC_CARBON
|
||||
#if TARGET_API_MAC_CARBON
|
||||
GetDialogItemAsControl(commandDialog, kCL_Video, &control);
|
||||
SetControlValue (control, videodriver);
|
||||
#else
|
||||
GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect);
|
||||
SetControlValue ((ControlRef)dummyHandle, videodriver);
|
||||
#endif
|
||||
SetControlValue(control, videodriver);
|
||||
#else
|
||||
GetDialogItem(commandDialog, kCL_Video, &dummyType, &dummyHandle,
|
||||
&dummyRect);
|
||||
SetControlValue((ControlRef) dummyHandle, videodriver);
|
||||
#endif
|
||||
|
||||
SetDialogDefaultItem (commandDialog, kCL_OK);
|
||||
SetDialogCancelItem (commandDialog, kCL_Cancel);
|
||||
SetDialogDefaultItem(commandDialog, kCL_OK);
|
||||
SetDialogCancelItem(commandDialog, kCL_Cancel);
|
||||
|
||||
do {
|
||||
|
||||
ModalDialog(nil, &itemHit); /* wait for user response */
|
||||
|
||||
/* Toggle command-line output checkbox */
|
||||
if ( itemHit == kCL_File ) {
|
||||
#if TARGET_API_MAC_CARBON
|
||||
GetDialogItemAsControl(commandDialog, kCL_File, &control);
|
||||
SetControlValue (control, !GetControlValue(control));
|
||||
#else
|
||||
GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
SetControlValue((ControlHandle)dummyHandle, !GetControlValue((ControlHandle)dummyHandle) );
|
||||
#endif
|
||||
}
|
||||
|
||||
} while (itemHit != kCL_OK && itemHit != kCL_Cancel);
|
||||
ModalDialog(nil, &itemHit); /* wait for user response */
|
||||
|
||||
/* Toggle command-line output checkbox */
|
||||
if (itemHit == kCL_File) {
|
||||
#if TARGET_API_MAC_CARBON
|
||||
GetDialogItemAsControl(commandDialog, kCL_File, &control);
|
||||
SetControlValue(control, !GetControlValue(control));
|
||||
#else
|
||||
GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
SetControlValue((ControlHandle) dummyHandle,
|
||||
!GetControlValue((ControlHandle)
|
||||
dummyHandle));
|
||||
#endif
|
||||
}
|
||||
|
||||
}
|
||||
while (itemHit != kCL_OK && itemHit != kCL_Cancel);
|
||||
|
||||
/* Get control values, even if they did not change */
|
||||
GetDialogItem (commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
GetDialogItemText (dummyHandle, prefs.command_line);
|
||||
GetDialogItem(commandDialog, kCL_Text, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
GetDialogItemText(dummyHandle, prefs.command_line);
|
||||
|
||||
#if TARGET_API_MAC_CARBON
|
||||
#if TARGET_API_MAC_CARBON
|
||||
GetDialogItemAsControl(commandDialog, kCL_File, &control);
|
||||
prefs.output_to_file = GetControlValue(control);
|
||||
#else
|
||||
GetDialogItem (commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
prefs.output_to_file = GetControlValue ((ControlHandle)dummyHandle);
|
||||
#endif
|
||||
#else
|
||||
GetDialogItem(commandDialog, kCL_File, &dummyType, &dummyHandle, &dummyRect); /* MJS */
|
||||
prefs.output_to_file = GetControlValue((ControlHandle) dummyHandle);
|
||||
#endif
|
||||
|
||||
#if TARGET_API_MAC_CARBON
|
||||
#if TARGET_API_MAC_CARBON
|
||||
GetDialogItemAsControl(commandDialog, kCL_Video, &control);
|
||||
videodriver = GetControlValue(control);
|
||||
#else
|
||||
GetDialogItem (commandDialog, kCL_Video, &dummyType, &dummyHandle, &dummyRect);
|
||||
videodriver = GetControlValue ((ControlRef)dummyHandle);
|
||||
#endif
|
||||
#else
|
||||
GetDialogItem(commandDialog, kCL_Video, &dummyType, &dummyHandle,
|
||||
&dummyRect);
|
||||
videodriver = GetControlValue((ControlRef) dummyHandle);
|
||||
#endif
|
||||
|
||||
DisposeDialog (commandDialog);
|
||||
DisposeDialog(commandDialog);
|
||||
|
||||
if (itemHit == kCL_Cancel ) {
|
||||
exit (0);
|
||||
if (itemHit == kCL_Cancel) {
|
||||
exit(0);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/* Set pseudo-environment variables for video driver, update prefs */
|
||||
switch ( videodriver ) {
|
||||
case VIDEO_ID_DRAWSPROCKET:
|
||||
SDL_putenv("SDL_VIDEODRIVER=DSp");
|
||||
SDL_memcpy(prefs.video_driver_name, "\pDSp", 4);
|
||||
break;
|
||||
case VIDEO_ID_TOOLBOX:
|
||||
SDL_putenv("SDL_VIDEODRIVER=toolbox");
|
||||
SDL_memcpy(prefs.video_driver_name, "\ptoolbox", 8);
|
||||
break;
|
||||
}
|
||||
switch (videodriver) {
|
||||
case VIDEO_ID_DRAWSPROCKET:
|
||||
SDL_putenv("SDL_VIDEODRIVER=DSp");
|
||||
SDL_memcpy(prefs.video_driver_name, "\pDSp", 4);
|
||||
break;
|
||||
case VIDEO_ID_TOOLBOX:
|
||||
SDL_putenv("SDL_VIDEODRIVER=toolbox");
|
||||
SDL_memcpy(prefs.video_driver_name, "\ptoolbox", 8);
|
||||
break;
|
||||
}
|
||||
|
||||
#if !(defined(__APPLE__) && defined(__MACH__))
|
||||
/* Redirect standard I/O to files */
|
||||
if ( prefs.output_to_file ) {
|
||||
freopen (STDOUT_FILE, "w", stdout);
|
||||
freopen (STDERR_FILE, "w", stderr);
|
||||
} else {
|
||||
fclose (stdout);
|
||||
fclose (stderr);
|
||||
}
|
||||
if (prefs.output_to_file) {
|
||||
freopen(STDOUT_FILE, "w", stdout);
|
||||
freopen(STDERR_FILE, "w", stderr);
|
||||
} else {
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
if (settingsChanged) {
|
||||
/* Save the prefs, even if they might not have changed (but probably did) */
|
||||
if ( ! writePreferences (&prefs) )
|
||||
fprintf (stderr, "WARNING: Could not save preferences!\n");
|
||||
if (!writePreferences(&prefs))
|
||||
fprintf(stderr, "WARNING: Could not save preferences!\n");
|
||||
}
|
||||
|
||||
#if !(defined(__APPLE__) && defined(__MACH__))
|
||||
appNameText[0] = 0;
|
||||
getCurrentAppName (appNameText); /* check for error here ? */
|
||||
getCurrentAppName(appNameText); /* check for error here ? */
|
||||
|
||||
commandLine = (char*) malloc (appNameText[0] + prefs.command_line[0] + 2);
|
||||
if ( commandLine == NULL ) {
|
||||
exit(-1);
|
||||
commandLine = (char *) malloc(appNameText[0] + prefs.command_line[0] + 2);
|
||||
if (commandLine == NULL) {
|
||||
exit(-1);
|
||||
}
|
||||
|
||||
/* Rather than rewrite ParseCommandLine method, let's replace */
|
||||
/* any spaces in application name with underscores, */
|
||||
/* so that the app name is only 1 argument */
|
||||
for (i = 1; i < 1+appNameText[0]; i++)
|
||||
if ( appNameText[i] == ' ' ) appNameText[i] = '_';
|
||||
/* so that the app name is only 1 argument */
|
||||
for (i = 1; i < 1 + appNameText[0]; i++)
|
||||
if (appNameText[i] == ' ')
|
||||
appNameText[i] = '_';
|
||||
|
||||
/* Copy app name & full command text to command-line C-string */
|
||||
/* Copy app name & full command text to command-line C-string */
|
||||
SDL_memcpy(commandLine, appNameText + 1, appNameText[0]);
|
||||
commandLine[appNameText[0]] = ' ';
|
||||
SDL_memcpy(commandLine + appNameText[0] + 1, prefs.command_line + 1, prefs.command_line[0]);
|
||||
commandLine[ appNameText[0] + 1 + prefs.command_line[0] ] = '\0';
|
||||
SDL_memcpy(commandLine + appNameText[0] + 1, prefs.command_line + 1,
|
||||
prefs.command_line[0]);
|
||||
commandLine[appNameText[0] + 1 + prefs.command_line[0]] = '\0';
|
||||
|
||||
/* Parse C-string into argv and argc */
|
||||
nargs = ParseCommandLine (commandLine, NULL);
|
||||
args = (char **)malloc((nargs+1)*(sizeof *args));
|
||||
if ( args == NULL ) {
|
||||
exit(-1);
|
||||
}
|
||||
ParseCommandLine (commandLine, args);
|
||||
|
||||
/* Run the main application code */
|
||||
SDL_main(nargs, args);
|
||||
free (args);
|
||||
free (commandLine);
|
||||
|
||||
/* Remove useless stdout.txt and stderr.txt */
|
||||
cleanup_output ();
|
||||
#else // defined(__APPLE__) && defined(__MACH__)
|
||||
SDL_main(argc, argv);
|
||||
#endif
|
||||
|
||||
/* Exit cleanly, calling atexit() functions */
|
||||
exit (0);
|
||||
nargs = ParseCommandLine(commandLine, NULL);
|
||||
args = (char **) malloc((nargs + 1) * (sizeof *args));
|
||||
if (args == NULL) {
|
||||
exit(-1);
|
||||
}
|
||||
ParseCommandLine(commandLine, args);
|
||||
|
||||
/* Never reached, but keeps the compiler quiet */
|
||||
return (0);
|
||||
/* Run the main application code */
|
||||
SDL_main(nargs, args);
|
||||
free(args);
|
||||
free(commandLine);
|
||||
|
||||
/* Remove useless stdout.txt and stderr.txt */
|
||||
cleanup_output();
|
||||
#else // defined(__APPLE__) && defined(__MACH__)
|
||||
SDL_main(argc, argv);
|
||||
#endif
|
||||
|
||||
/* Exit cleanly, calling atexit() functions */
|
||||
exit(0);
|
||||
|
||||
/* Never reached, but keeps the compiler quiet */
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -178,9 +178,6 @@
|
||||
SDL_GL_SetAttribute
|
||||
SDL_GL_GetAttribute
|
||||
SDL_GL_SwapBuffers
|
||||
SDL_GL_UpdateRects
|
||||
SDL_GL_Lock
|
||||
SDL_GL_Unlock
|
||||
SDL_WM_SetCaption
|
||||
SDL_WM_GetCaption
|
||||
SDL_WM_SetIcon
|
||||
|
||||
@@ -7,5 +7,5 @@
|
||||
|
||||
#import <Cocoa/Cocoa.h>
|
||||
|
||||
@interface SDLMain : NSObject
|
||||
@end
|
||||
@ interface SDLMain:NSObject @ end
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -16,14 +16,20 @@
|
||||
// some issues in Qtopia where there are left-over qcop files in /tmp/.
|
||||
// I'm guessing this will also clean up the taskbar in the Sharp version
|
||||
// of Qtopia.
|
||||
static inline void cleanupQCop() {
|
||||
QString appname(qApp->argv()[0]);
|
||||
int slash = appname.findRev("/");
|
||||
if(slash != -1) { appname = appname.mid(slash+1); }
|
||||
QString cmd = QPEApplication::qpeDir() + "bin/qcop QPE/System 'closing(QString)' '"+appname+"'";
|
||||
system(cmd.latin1());
|
||||
cmd = "/tmp/qcop-msg-"+appname;
|
||||
unlink(cmd.latin1());
|
||||
static inline void
|
||||
cleanupQCop()
|
||||
{
|
||||
QString appname(qApp->argv()[0]);
|
||||
int slash = appname.findRev("/");
|
||||
if (slash != -1) {
|
||||
appname = appname.mid(slash + 1);
|
||||
}
|
||||
QString cmd =
|
||||
QPEApplication::qpeDir() +
|
||||
"bin/qcop QPE/System 'closing(QString)' '" + appname + "'";
|
||||
system(cmd.latin1());
|
||||
cmd = "/tmp/qcop-msg-" + appname;
|
||||
unlink(cmd.latin1());
|
||||
}
|
||||
|
||||
static QPEApplication *app;
|
||||
@@ -31,17 +37,20 @@ static QPEApplication *app;
|
||||
|
||||
extern int SDL_main(int argc, char *argv[]);
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
int
|
||||
main(int argc, char *argv[])
|
||||
{
|
||||
#ifdef QWS
|
||||
// This initializes the Qtopia application. It needs to be done here
|
||||
// because it parses command line options.
|
||||
app = new QPEApplication(argc, argv);
|
||||
QWidget dummy;
|
||||
app->showMainWidget(&dummy);
|
||||
atexit(cleanupQCop);
|
||||
// This initializes the Qtopia application. It needs to be done here
|
||||
// because it parses command line options.
|
||||
app = new QPEApplication(argc, argv);
|
||||
QWidget dummy;
|
||||
app->showMainWidget(&dummy);
|
||||
atexit(cleanupQCop);
|
||||
#endif
|
||||
// Exit here because if return is used, the application
|
||||
// doesn't seem to quit correctly.
|
||||
exit(SDL_main(argc, argv));
|
||||
// Exit here because if return is used, the application
|
||||
// doesn't seem to quit correctly.
|
||||
exit(SDL_main(argc, argv));
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
@@ -10,20 +10,6 @@
|
||||
#define WIN32_LEAN_AND_MEAN
|
||||
#include <windows.h>
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
# define DIR_SEPERATOR TEXT("\\")
|
||||
# undef _getcwd
|
||||
# define _getcwd(str,len) wcscpy(str,TEXT(""))
|
||||
# define setbuf(f,b)
|
||||
# define setvbuf(w,x,y,z)
|
||||
# define fopen _wfopen
|
||||
# define freopen _wfreopen
|
||||
# define remove(x) DeleteFile(x)
|
||||
#else
|
||||
# define DIR_SEPERATOR TEXT("/")
|
||||
# include <direct.h>
|
||||
#endif
|
||||
|
||||
/* Include the SDL main definition header */
|
||||
#include "SDL.h"
|
||||
#include "SDL_main.h"
|
||||
@@ -34,135 +20,80 @@
|
||||
# endif /* _WIN32_WCE_EMULATION */
|
||||
#endif /* main */
|
||||
|
||||
/* The standard output files */
|
||||
#define STDOUT_FILE TEXT("stdout.txt")
|
||||
#define STDERR_FILE TEXT("stderr.txt")
|
||||
|
||||
#ifndef NO_STDIO_REDIRECT
|
||||
# ifdef _WIN32_WCE
|
||||
static wchar_t stdoutPath[MAX_PATH];
|
||||
static wchar_t stderrPath[MAX_PATH];
|
||||
# else
|
||||
static char stdoutPath[MAX_PATH];
|
||||
static char stderrPath[MAX_PATH];
|
||||
# endif
|
||||
#endif
|
||||
|
||||
#if defined(_WIN32_WCE) && _WIN32_WCE < 300
|
||||
/* seems to be undefined in Win CE although in online help */
|
||||
#define isspace(a) (((CHAR)a == ' ') || ((CHAR)a == '\t'))
|
||||
#endif /* _WIN32_WCE < 300 */
|
||||
|
||||
/* Parse a command line buffer into arguments */
|
||||
static int ParseCommandLine(char *cmdline, char **argv)
|
||||
static int
|
||||
ParseCommandLine(char *cmdline, char **argv)
|
||||
{
|
||||
char *bufp;
|
||||
int argc;
|
||||
char *bufp;
|
||||
int argc;
|
||||
|
||||
argc = 0;
|
||||
for ( bufp = cmdline; *bufp; ) {
|
||||
/* Skip leading whitespace */
|
||||
while ( isspace(*bufp) ) {
|
||||
++bufp;
|
||||
}
|
||||
/* Skip over argument */
|
||||
if ( *bufp == '"' ) {
|
||||
++bufp;
|
||||
if ( *bufp ) {
|
||||
if ( argv ) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while ( *bufp && (*bufp != '"') ) {
|
||||
++bufp;
|
||||
}
|
||||
} else {
|
||||
if ( *bufp ) {
|
||||
if ( argv ) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while ( *bufp && ! isspace(*bufp) ) {
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if ( *bufp ) {
|
||||
if ( argv ) {
|
||||
*bufp = '\0';
|
||||
}
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if ( argv ) {
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
return(argc);
|
||||
argc = 0;
|
||||
for (bufp = cmdline; *bufp;) {
|
||||
/* Skip leading whitespace */
|
||||
while (isspace(*bufp)) {
|
||||
++bufp;
|
||||
}
|
||||
/* Skip over argument */
|
||||
if (*bufp == '"') {
|
||||
++bufp;
|
||||
if (*bufp) {
|
||||
if (argv) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while (*bufp && (*bufp != '"')) {
|
||||
++bufp;
|
||||
}
|
||||
} else {
|
||||
if (*bufp) {
|
||||
if (argv) {
|
||||
argv[argc] = bufp;
|
||||
}
|
||||
++argc;
|
||||
}
|
||||
/* Skip over word */
|
||||
while (*bufp && !isspace(*bufp)) {
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if (*bufp) {
|
||||
if (argv) {
|
||||
*bufp = '\0';
|
||||
}
|
||||
++bufp;
|
||||
}
|
||||
}
|
||||
if (argv) {
|
||||
argv[argc] = NULL;
|
||||
}
|
||||
return (argc);
|
||||
}
|
||||
|
||||
/* Show an error message */
|
||||
static void ShowError(const char *title, const char *message)
|
||||
static void
|
||||
ShowError(const char *title, const char *message)
|
||||
{
|
||||
/* If USE_MESSAGEBOX is defined, you need to link with user32.lib */
|
||||
#ifdef USE_MESSAGEBOX
|
||||
MessageBox(NULL, message, title, MB_ICONEXCLAMATION|MB_OK);
|
||||
MessageBox(NULL, message, title, MB_ICONEXCLAMATION | MB_OK);
|
||||
#else
|
||||
fprintf(stderr, "%s: %s\n", title, message);
|
||||
fprintf(stderr, "%s: %s\n", title, message);
|
||||
#endif
|
||||
}
|
||||
|
||||
/* Pop up an out of memory message, returns to Windows */
|
||||
static BOOL OutOfMemory(void)
|
||||
static BOOL
|
||||
OutOfMemory(void)
|
||||
{
|
||||
ShowError("Fatal Error", "Out of memory - aborting");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/* SDL_Quit() shouldn't be used with atexit() directly because
|
||||
calling conventions may differ... */
|
||||
static void cleanup(void)
|
||||
{
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
/* Remove the output files if there was no output written */
|
||||
static void cleanup_output(void)
|
||||
{
|
||||
#ifndef NO_STDIO_REDIRECT
|
||||
FILE *file;
|
||||
int empty;
|
||||
#endif
|
||||
|
||||
/* Flush the output in case anything is queued */
|
||||
fclose(stdout);
|
||||
fclose(stderr);
|
||||
|
||||
#ifndef NO_STDIO_REDIRECT
|
||||
/* See if the files have any output in them */
|
||||
if ( stdoutPath[0] ) {
|
||||
file = fopen(stdoutPath, TEXT("rb"));
|
||||
if ( file ) {
|
||||
empty = (fgetc(file) == EOF) ? 1 : 0;
|
||||
fclose(file);
|
||||
if ( empty ) {
|
||||
remove(stdoutPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( stderrPath[0] ) {
|
||||
file = fopen(stderrPath, TEXT("rb"));
|
||||
if ( file ) {
|
||||
empty = (fgetc(file) == EOF) ? 1 : 0;
|
||||
fclose(file);
|
||||
if ( empty ) {
|
||||
remove(stderrPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
ShowError("Fatal Error", "Out of memory - aborting");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
#if defined(_MSC_VER) && !defined(_WIN32_WCE)
|
||||
@@ -171,187 +102,73 @@ static void cleanup_output(void)
|
||||
#endif
|
||||
|
||||
/* This is where execution begins [console apps] */
|
||||
int console_main(int argc, char *argv[])
|
||||
int
|
||||
console_main(int argc, char *argv[])
|
||||
{
|
||||
size_t n;
|
||||
char *bufp, *appname;
|
||||
int status;
|
||||
int status;
|
||||
|
||||
/* Get the class name from argv[0] */
|
||||
appname = argv[0];
|
||||
if ( (bufp=SDL_strrchr(argv[0], '\\')) != NULL ) {
|
||||
appname = bufp+1;
|
||||
} else
|
||||
if ( (bufp=SDL_strrchr(argv[0], '/')) != NULL ) {
|
||||
appname = bufp+1;
|
||||
}
|
||||
/* Run the application main() code */
|
||||
status = SDL_main(argc, argv);
|
||||
|
||||
if ( (bufp=SDL_strrchr(appname, '.')) == NULL )
|
||||
n = SDL_strlen(appname);
|
||||
else
|
||||
n = (bufp-appname);
|
||||
/* Exit cleanly, calling atexit() functions */
|
||||
exit(status);
|
||||
|
||||
bufp = SDL_stack_alloc(char, n+1);
|
||||
if ( bufp == NULL ) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
SDL_strlcpy(bufp, appname, n+1);
|
||||
appname = bufp;
|
||||
|
||||
/* Load SDL dynamic link library */
|
||||
if ( SDL_Init(SDL_INIT_NOPARACHUTE) < 0 ) {
|
||||
ShowError("WinMain() error", SDL_GetError());
|
||||
return(FALSE);
|
||||
}
|
||||
atexit(cleanup_output);
|
||||
atexit(cleanup);
|
||||
|
||||
/* Sam:
|
||||
We still need to pass in the application handle so that
|
||||
DirectInput will initialize properly when SDL_RegisterApp()
|
||||
is called later in the video initialization.
|
||||
*/
|
||||
SDL_SetModuleHandle(GetModuleHandle(NULL));
|
||||
|
||||
/* Run the application main() code */
|
||||
status = SDL_main(argc, argv);
|
||||
|
||||
/* Exit cleanly, calling atexit() functions */
|
||||
exit(status);
|
||||
|
||||
/* Hush little compiler, don't you cry... */
|
||||
return 0;
|
||||
/* Hush little compiler, don't you cry... */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* This is where execution begins [windowed apps] */
|
||||
#ifdef _WIN32_WCE
|
||||
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPWSTR szCmdLine, int sw)
|
||||
#else
|
||||
int WINAPI WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPSTR szCmdLine, int sw)
|
||||
#endif
|
||||
int WINAPI
|
||||
WinMain(HINSTANCE hInst, HINSTANCE hPrev, LPTSTR szCmdLine, int sw)
|
||||
{
|
||||
HINSTANCE handle;
|
||||
char **argv;
|
||||
int argc;
|
||||
char *cmdline;
|
||||
DWORD pathlen;
|
||||
char **argv;
|
||||
int argc;
|
||||
char *cmdline;
|
||||
#ifdef _WIN32_WCE
|
||||
wchar_t path[MAX_PATH];
|
||||
wchar_t *bufp;
|
||||
int nLen;
|
||||
#else
|
||||
char path[MAX_PATH];
|
||||
char *bufp;
|
||||
size_t nLen;
|
||||
#endif
|
||||
#ifdef _WIN32_WCE
|
||||
wchar_t *bufp;
|
||||
int nLen;
|
||||
#else
|
||||
char *bufp;
|
||||
size_t nLen;
|
||||
#endif
|
||||
#ifndef NO_STDIO_REDIRECT
|
||||
FILE *newfp;
|
||||
#endif
|
||||
|
||||
/* Start up DDHELP.EXE before opening any files, so DDHELP doesn't
|
||||
keep them open. This is a hack.. hopefully it will be fixed
|
||||
someday. DDHELP.EXE starts up the first time DDRAW.DLL is loaded.
|
||||
*/
|
||||
handle = LoadLibrary(TEXT("DDRAW.DLL"));
|
||||
if ( handle != NULL ) {
|
||||
FreeLibrary(handle);
|
||||
}
|
||||
|
||||
#ifndef NO_STDIO_REDIRECT
|
||||
pathlen = GetModuleFileName(NULL, path, SDL_arraysize(path));
|
||||
while ( pathlen > 0 && path[pathlen] != '\\' ) {
|
||||
--pathlen;
|
||||
}
|
||||
path[pathlen] = '\0';
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
wcsncpy( stdoutPath, path, SDL_arraysize(stdoutPath) );
|
||||
wcsncat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) );
|
||||
nLen = wcslen(szCmdLine) + 128 + 1;
|
||||
bufp = SDL_stack_alloc(wchar_t, nLen * 2);
|
||||
wcscpy(bufp, TEXT("\""));
|
||||
GetModuleFileName(NULL, bufp + 1, 128 - 3);
|
||||
wcscpy(bufp + wcslen(bufp), TEXT("\" "));
|
||||
wcsncpy(bufp + wcslen(bufp), szCmdLine, nLen - wcslen(bufp));
|
||||
nLen = wcslen(bufp) + 1;
|
||||
cmdline = SDL_stack_alloc(char, nLen);
|
||||
if (cmdline == NULL) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
|
||||
#else
|
||||
SDL_strlcpy( stdoutPath, path, SDL_arraysize(stdoutPath) );
|
||||
SDL_strlcat( stdoutPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) );
|
||||
#endif
|
||||
|
||||
/* Redirect standard input and standard output */
|
||||
newfp = freopen(stdoutPath, TEXT("w"), stdout);
|
||||
|
||||
#ifndef _WIN32_WCE
|
||||
if ( newfp == NULL ) { /* This happens on NT */
|
||||
#if !defined(stdout)
|
||||
stdout = fopen(stdoutPath, TEXT("w"));
|
||||
#else
|
||||
newfp = fopen(stdoutPath, TEXT("w"));
|
||||
if ( newfp ) {
|
||||
*stdout = *newfp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* _WIN32_WCE */
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
wcsncpy( stderrPath, path, SDL_arraysize(stdoutPath) );
|
||||
wcsncat( stderrPath, DIR_SEPERATOR STDOUT_FILE, SDL_arraysize(stdoutPath) );
|
||||
#else
|
||||
SDL_strlcpy( stderrPath, path, SDL_arraysize(stderrPath) );
|
||||
SDL_strlcat( stderrPath, DIR_SEPERATOR STDERR_FILE, SDL_arraysize(stderrPath) );
|
||||
/* Grab the command line */
|
||||
bufp = GetCommandLine();
|
||||
nLen = SDL_strlen(bufp) + 1;
|
||||
cmdline = SDL_stack_alloc(char, nLen);
|
||||
if (cmdline == NULL) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
SDL_strlcpy(cmdline, bufp, nLen);
|
||||
#endif
|
||||
|
||||
newfp = freopen(stderrPath, TEXT("w"), stderr);
|
||||
#ifndef _WIN32_WCE
|
||||
if ( newfp == NULL ) { /* This happens on NT */
|
||||
#if !defined(stderr)
|
||||
stderr = fopen(stderrPath, TEXT("w"));
|
||||
#else
|
||||
newfp = fopen(stderrPath, TEXT("w"));
|
||||
if ( newfp ) {
|
||||
*stderr = *newfp;
|
||||
}
|
||||
#endif
|
||||
}
|
||||
#endif /* _WIN32_WCE */
|
||||
/* Parse it into argv and argc */
|
||||
argc = ParseCommandLine(cmdline, NULL);
|
||||
argv = SDL_stack_alloc(char *, argc + 1);
|
||||
if (argv == NULL) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
ParseCommandLine(cmdline, argv);
|
||||
|
||||
setvbuf(stdout, NULL, _IOLBF, BUFSIZ); /* Line buffered */
|
||||
setbuf(stderr, NULL); /* No buffering */
|
||||
#endif /* !NO_STDIO_REDIRECT */
|
||||
/* Run the main program */
|
||||
console_main(argc, argv);
|
||||
|
||||
#ifdef _WIN32_WCE
|
||||
nLen = wcslen(szCmdLine)+128+1;
|
||||
bufp = SDL_stack_alloc(wchar_t, nLen*2);
|
||||
wcscpy (bufp, TEXT("\""));
|
||||
GetModuleFileName(NULL, bufp+1, 128-3);
|
||||
wcscpy (bufp+wcslen(bufp), TEXT("\" "));
|
||||
wcsncpy(bufp+wcslen(bufp), szCmdLine,nLen-wcslen(bufp));
|
||||
nLen = wcslen(bufp)+1;
|
||||
cmdline = SDL_stack_alloc(char, nLen);
|
||||
if ( cmdline == NULL ) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
WideCharToMultiByte(CP_ACP, 0, bufp, -1, cmdline, nLen, NULL, NULL);
|
||||
#else
|
||||
/* Grab the command line */
|
||||
bufp = GetCommandLine();
|
||||
nLen = SDL_strlen(bufp)+1;
|
||||
cmdline = SDL_stack_alloc(char, nLen);
|
||||
if ( cmdline == NULL ) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
SDL_strlcpy(cmdline, bufp, nLen);
|
||||
#endif
|
||||
|
||||
/* Parse it into argv and argc */
|
||||
argc = ParseCommandLine(cmdline, NULL);
|
||||
argv = SDL_stack_alloc(char*, argc+1);
|
||||
if ( argv == NULL ) {
|
||||
return OutOfMemory();
|
||||
}
|
||||
ParseCommandLine(cmdline, argv);
|
||||
|
||||
/* Run the main program (after a little SDL initialization) */
|
||||
console_main(argc, argv);
|
||||
|
||||
/* Hush little compiler, don't you cry... */
|
||||
return 0;
|
||||
/* Hush little compiler, don't you cry... */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
Reference in New Issue
Block a user