⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sdl_main.c

📁 SDL库 在进行视频显示程序spcaview安装时必须的库文件
💻 C
📖 第 1 页 / 共 2 页
字号:
/*    SDL - Simple DirectMedia Layer    Copyright (C) 1997-2006 Sam Lantinga    This library is free software; you can redistribute it and/or    modify it under the terms of the GNU Lesser General Public    License as published by the Free Software Foundation; either    version 2.1 of the License, or (at your option) any later version.    This library is distributed in the hope that it will be useful,    but WITHOUT ANY WARRANTY; without even the implied warranty of    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU    Lesser General Public License for more details.    You should have received a copy of the GNU Lesser General Public    License along with this library; if not, write to the Free Software    Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA    Sam Lantinga    slouken@libsdl.org*//* This file takes care of command line argument parsing, and stdio redirection   in the MacOS environment. (stdio/stderr is *not* directed for Mach-O builds) */#if defined(__APPLE__) && defined(__MACH__)#include <Carbon/Carbon.h>#elif TARGET_API_MAC_CARBON && (UNIVERSAL_INTERFACES_VERSION > 0x0335)#include <Carbon.h>#else#include <Dialogs.h>#include <Fonts.h>#include <Events.h>#include <Resources.h>#include <Folders.h>#endif/* Include the SDL main definition header */#include "SDL.h"#include "SDL_main.h"#ifdef main#undef main#endif#if !(defined(__APPLE__) && defined(__MACH__))/* The standard output files */#define STDOUT_FILE	"stdout.txt"#define STDERR_FILE	"stderr.txt"#endif#if !defined(__MWERKS__) && !TARGET_API_MAC_CARBON	/* 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;    Boolean output_to_file;}  PrefsRecord;/* See if the command key is held down at startup */static Boolean CommandKeyIsDown(void){	KeyMap  theKeyMap;	GetKeys(theKeyMap);	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){	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);}/* Remove the output files if there was no output written */static void cleanup_output(void){	FILE *file;	int empty;	/* 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);		}	}}#endif //!(defined(__APPLE__) && defined(__MACH__))static int getCurrentAppName (StrFileName name) {	    ProcessSerialNumber process;    ProcessInfoRec      process_info;    FSSpec              process_fsp;        process.highLongOfPSN = 0;    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;        SDL_memcpy(name, process_fsp.name, process_fsp.name[0] + 1);    return 1;}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;        /* 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);        /* Truncate if name is too long */    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);       /* Make the file spec for prefs file */    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->vRefNum = volume_ref_number;                            FSpCreateResFile (prefs_fsp, 0x3f3f3f3f, 'pref', 0); // '????' parsed as trigraph                        if ( noErr != ResError () )                return 0;        }     }    return 1;}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);		/* 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) {    Handle prefs_handle;        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 );    if (prefs_handle != NULL) {            int offset;                HLock (prefs_handle);                /* Command line text */        offset = 0;        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);                /* 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);                return ResError() == noErr;    }        return 0;}static int readPreferences (PrefsRecord *prefs) {    int    no_error = 1;    FSSpec prefs_fsp;    /* Check for prefs file first */    if ( getPrefsFile (&prefs_fsp, 0) ) {    

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -