本文整理汇总了C++中SDL_strlen函数的典型用法代码示例。如果您正苦于以下问题:C++ SDL_strlen函数的具体用法?C++ SDL_strlen怎么用?C++ SDL_strlen使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了SDL_strlen函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: SetMMerror
static void SetMMerror(char *function, MMRESULT code)
{
int len;
char errbuf[MAXERRORLENGTH];
SDL_snprintf(errbuf, SDL_arraysize(errbuf), "%s: ", function);
len = SDL_strlen(errbuf);
waveOutGetErrorText(code, errbuf+len, MAXERRORLENGTH-len);
SDL_SetError("%s",errbuf);
}
示例2: LogOutput
void LogOutput( void* userData, int category, SDL_LogPriority priority, const char* message )
{
size_t strLen = SDL_strlen( message );
SDL_RWwrite( logFile, message, 1, strLen );
#ifdef WIN32
SDL_RWwrite( logFile, "\r\n", 1, 2 );
#else
#warning "NO END OF LINE DEFINED FOR THIS PLATFORM!"
#endif
}
示例3: SDL_SYS_CDInit
int SDL_SYS_CDInit(void)
{
/* checklist: /dev/cdrom,/dev/cd?c /dev/acd?c
/dev/matcd?c /dev/mcd?c /dev/scd?c */
static char *checklist[] = {
"cdrom", "?0 cd?", "?0 acd?", "?0 matcd?", "?0 mcd?", "?0 scd?",NULL
};
char *SDLcdrom;
int i, j, exists;
char drive[32];
struct stat stbuf;
/* Fill in our driver capabilities */
SDL_CDcaps.Name = SDL_SYS_CDName;
SDL_CDcaps.Open = SDL_SYS_CDOpen;
SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
SDL_CDcaps.Status = SDL_SYS_CDStatus;
SDL_CDcaps.Play = SDL_SYS_CDPlay;
SDL_CDcaps.Pause = SDL_SYS_CDPause;
SDL_CDcaps.Resume = SDL_SYS_CDResume;
SDL_CDcaps.Stop = SDL_SYS_CDStop;
SDL_CDcaps.Eject = SDL_SYS_CDEject;
SDL_CDcaps.Close = SDL_SYS_CDClose;
/* Look in the environment for our CD-ROM drive list */
SDLcdrom = SDL_getenv("SDL_CDROM"); /* ':' separated list of devices */
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(char, len);
if ( cdpath != NULL ) {
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
if ( delim ) {
*delim++ = '\0';
}
if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
AddDrive(SDLcdrom, &stbuf);
}
if ( delim ) {
SDLcdrom = delim;
} else {
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_stack_free(cdpath);
}
/* If we found our drives, there's nothing left to do */
if ( SDL_numcds > 0 ) {
return(0);
}
}
示例4: SDL_strlen
bool SDLFileHandler::writeString(std::stringstream text)
{
std::string sText = text.str();
size_t len = SDL_strlen(sText.c_str());
if (SDL_RWwrite(file, &sText, sizeof(text), len) != len)
{
std::cout << "[ERROR]: text couldn't be written" << std::endl;
return false;
}
return true;
}
示例5: SDL_strlen
char *SDL_strstr(const char *haystack, const char *needle)
{
size_t length = SDL_strlen(needle);
while ( *haystack ) {
if ( SDL_strncmp(haystack, needle, length) == 0 ) {
return (char *)haystack;
}
++haystack;
}
return NULL;
}
示例6: SDL_SYS_CDInit
int SDL_SYS_CDInit(void)
{
static char *checklist[] = {
"?0 rsr?", NULL
};
char *SDLcdrom;
int i, j, exists;
char drive[32];
struct stat stbuf;
SDL_CDcaps.Name = SDL_SYS_CDName;
SDL_CDcaps.Open = SDL_SYS_CDOpen;
SDL_CDcaps.GetTOC = SDL_SYS_CDGetTOC;
SDL_CDcaps.Status = SDL_SYS_CDStatus;
SDL_CDcaps.Play = SDL_SYS_CDPlay;
SDL_CDcaps.Pause = SDL_SYS_CDPause;
SDL_CDcaps.Resume = SDL_SYS_CDResume;
SDL_CDcaps.Stop = SDL_SYS_CDStop;
SDL_CDcaps.Eject = SDL_SYS_CDEject;
SDL_CDcaps.Close = SDL_SYS_CDClose;
SDLcdrom = SDL_getenv("SDL_CDROM");
if ( SDLcdrom != NULL ) {
char *cdpath, *delim;
size_t len = SDL_strlen(SDLcdrom)+1;
cdpath = SDL_stack_alloc(char, len);
if ( cdpath != NULL ) {
SDL_strlcpy(cdpath, SDLcdrom, len);
SDLcdrom = cdpath;
do {
delim = SDL_strchr(SDLcdrom, ':');
if ( delim ) {
*delim++ = '\0';
}
if ( CheckDrive(SDLcdrom, &stbuf) > 0 ) {
AddDrive(SDLcdrom, &stbuf);
}
if ( delim ) {
SDLcdrom = delim;
} else {
SDLcdrom = NULL;
}
} while ( SDLcdrom );
SDL_stack_free(cdpath);
}
if ( SDL_numcds > 0 ) {
return(0);
}
}
示例7: SDL_strlcpy
size_t
SDL_strlcpy(char *dst, const char *src, size_t maxlen)
{
size_t srclen = SDL_strlen(src);
if (maxlen > 0) {
size_t len = SDL_min(srclen, maxlen - 1);
SDL_memcpy(dst, src, len);
dst[len] = '\0';
}
return srclen;
}
示例8: SDL_GameControllerMappingForGUID
/*
* Get the mapping string for this GUID
*/
char *
SDL_GameControllerMappingForGUID(SDL_JoystickGUID guid)
{
char *pMappingString = NULL;
ControllerMapping_t *mapping = SDL_PrivateGetControllerMappingForGUID(&guid);
if (mapping) {
char pchGUID[33];
size_t needed;
SDL_JoystickGetGUIDString(guid, pchGUID, sizeof(pchGUID));
/* allocate enough memory for GUID + ',' + name + ',' + mapping + \0 */
needed = SDL_strlen(pchGUID) + 1 + SDL_strlen(mapping->name) + 1 + SDL_strlen(mapping->mapping) + 1;
pMappingString = SDL_malloc(needed);
if (!pMappingString) {
SDL_OutOfMemory();
return NULL;
}
SDL_snprintf(pMappingString, needed, "%s,%s,%s", pchGUID, mapping->name, mapping->mapping);
}
return pMappingString;
}
示例9: DIB_CreateWindow
int DIB_CreateWindow(_THIS)
{
char *windowid;
SDL_RegisterApp(NULL, 0, 0);
windowid = SDL_getenv("SDL_WINDOWID");
SDL_windowid = (windowid != NULL);
if ( SDL_windowid ) {
#if defined(_WIN32_WCE) && (_WIN32_WCE < 300)
wchar_t *windowid_t = SDL_malloc((SDL_strlen(windowid) + 1) * sizeof(wchar_t));
MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, windowid, -1, windowid_t, SDL_strlen(windowid) + 1);
SDL_Window = (HWND)wcstol(windowid_t, NULL, 0);
SDL_free(windowid_t);
#else
SDL_Window = (HWND)((size_t)SDL_strtoull(windowid, NULL, 0));
#endif
if ( SDL_Window == NULL ) {
SDL_SetError("Couldn't get user specified window");
return(-1);
}
userWindowProc = (WNDPROCTYPE)GetWindowLongPtr(SDL_Window, GWLP_WNDPROC);
SetWindowLongPtr(SDL_Window, GWLP_WNDPROC, (LONG_PTR)WinMessage);
} else {
SDL_Window = CreateWindow(SDL_Appname, SDL_Appname,
(WS_OVERLAPPED|WS_CAPTION|WS_SYSMENU|WS_MINIMIZEBOX),
CW_USEDEFAULT, CW_USEDEFAULT, 0, 0, NULL, NULL, SDL_Instance, NULL);
if ( SDL_Window == NULL ) {
SDL_SetError("Couldn't create window");
return(-1);
}
ShowWindow(SDL_Window, SW_HIDE);
}
WIN_FlushMessageQueue();
return(0);
}
示例10: SDL_AddTouch
int
SDL_AddTouch(const SDL_Touch * touch, char *name)
{
SDL_Touch **touchPads;
int index;
size_t length;
if (SDL_GetTouchIndexId(touch->id) != -1) {
SDL_SetError("Touch ID already in use");
}
/* Add the touch to the list of touch */
touchPads = (SDL_Touch **) SDL_realloc(SDL_touchPads,
(SDL_num_touch + 1) * sizeof(*touch));
if (!touchPads) {
SDL_OutOfMemory();
return -1;
}
SDL_touchPads = touchPads;
index = SDL_num_touch++;
SDL_touchPads[index] = (SDL_Touch *) SDL_malloc(sizeof(*SDL_touchPads[index]));
if (!SDL_touchPads[index]) {
SDL_OutOfMemory();
return -1;
}
SDL_memcpy(SDL_touchPads[index], touch, sizeof(*touch));
/* we're setting the touch properties */
length = 0;
length = SDL_strlen(name);
SDL_touchPads[index]->focus = 0;
SDL_touchPads[index]->name = SDL_malloc((length + 2) * sizeof(char));
SDL_strlcpy(SDL_touchPads[index]->name, name, length + 1);
SDL_touchPads[index]->num_fingers = 0;
SDL_touchPads[index]->max_fingers = 1;
SDL_touchPads[index]->fingers = (SDL_Finger **) SDL_malloc(sizeof(SDL_Finger*));
SDL_touchPads[index]->fingers[0] = NULL;
SDL_touchPads[index]->buttonstate = 0;
SDL_touchPads[index]->relative_mode = SDL_FALSE;
SDL_touchPads[index]->flush_motion = SDL_FALSE;
SDL_touchPads[index]->xres = (1<<(16-1));
SDL_touchPads[index]->yres = (1<<(16-1));
SDL_touchPads[index]->pressureres = (1<<(16-1));
//Do I want this here? Probably
SDL_GestureAddTouch(SDL_touchPads[index]);
return index;
}
示例11: RWopsSetUp
void
RWopsSetUp(void *arg)
{
int fileLen;
FILE *handle;
int writtenLen;
int result;
/* Clean up from previous runs (if any); ignore errors */
remove(RWopsReadTestFilename);
remove(RWopsWriteTestFilename);
remove(RWopsAlphabetFilename);
/* Create a test file */
handle = fopen(RWopsReadTestFilename, "w");
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsReadTestFilename);
if (handle == NULL) return;
/* Write some known text into it */
fileLen = SDL_strlen(RWopsHelloWorldTestString);
writtenLen = (int)fwrite(RWopsHelloWorldTestString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
/* Create a second test file */
handle = fopen(RWopsAlphabetFilename, "w");
SDLTest_AssertCheck(handle != NULL, "Verify creation of file '%s' returned non NULL handle", RWopsAlphabetFilename);
if (handle == NULL) return;
/* Write alphabet text into it */
fileLen = SDL_strlen(RWopsAlphabetString);
writtenLen = (int)fwrite(RWopsAlphabetString, 1, fileLen, handle);
SDLTest_AssertCheck(fileLen == writtenLen, "Verify number of written bytes, expected %i, got %i", fileLen, writtenLen);
result = fclose(handle);
SDLTest_AssertCheck(result == 0, "Verify result from fclose, expected 0, got %i", result);
SDLTest_AssertPass("Creation of test file completed");
}
示例12: inputhandleText
/*!
* Handle text events (if we were to use SDL2)
*/
void inputhandleText(SDL_TextInputEvent *Tevent)
{
size_t *newtextsize = NULL;
int size = SDL_strlen(Tevent->text);
if (size)
{
if (utf8Buf)
{
// clean up memory from last use.
free(utf8Buf);
utf8Buf = NULL;
}
utf8Buf = UTF8toUTF32(Tevent->text, newtextsize);
debug(LOG_INPUT, "Keyboard: text input \"%s\"", Tevent->text);
inputAddBuffer(CurrentKey, *utf8Buf);
if (SDL_strlen(text) + SDL_strlen(Tevent->text) < sizeof(text))
{
SDL_strlcat(text, Tevent->text, sizeof(text));
}
debug(LOG_INPUT, "adding text inputed: %s, to string [%s]", Tevent->text, text);
}
}
示例13: PrintText
static void
PrintText(char *text)
{
unsigned char *spot, expanded[1024];
expanded[0] = '\0';
for ( spot = text; *spot; ++spot )
{
size_t length = SDL_strlen(expanded);
SDL_snprintf(expanded + length, sizeof(expanded) - length, "\\x%.2x", *spot);
}
SDL_Log("Text (%s): \"%s%s\"\n", expanded, *text == '"' ? "\\" : "", text);
}
示例14: SDL_strdup
char *
SDL_strdup(const char *string)
{
#if defined(HAVE_STRDUP)
return strdup(string);
#else
size_t len = SDL_strlen(string) + 1;
char *newstr = SDL_malloc(len);
if (newstr) {
SDL_strlcpy(newstr, string, len);
}
return newstr;
#endif /* HAVE_STRDUP */
}
示例15: cfg_SaveFile
// Saves out the file.
int cfg_SaveFile( void* cfgFile )
{
assert( cfgFile != NULL );
int success = 0;
CFGFile* file = (CFGFile*)cfgFile;
char* outBuffer = NULL;
SDL_RWops* rwopsFile = NULL;
char strVal[32];
int writeNewLine = 0;
int count = sb_Count( file->sbAttributes );
for( int i = 0; i < count; ++i ) {
char* c = NULL;
if( writeNewLine ) {
c = sb_Add( outBuffer, 1 );
(*c) = '\n';
}
writeNewLine = 1;
// write out attribute name
size_t attrLen = SDL_strlen( file->sbAttributes[i].fileName );
c = sb_Add( outBuffer, attrLen );
SDL_memcpy( c, file->sbAttributes[i].fileName, attrLen );
// write out separator
c = sb_Add( outBuffer, 3 );
SDL_memcpy( c, " = ", 3 );
// write out value
int pl = SDL_snprintf( strVal, sizeof( strVal ), "%i", file->sbAttributes[i].value );
if( pl >= ARRAY_SIZE( strVal ) ) {
llog( LOG_ERROR, "Problem writing out configuration file value, value to long. File: %s Name: %s", file->filePath, file->sbAttributes[i].fileName );
goto clean_up;
} else {
c = sb_Add( outBuffer, pl );
SDL_memcpy( c, strVal, pl );
}
}
rwopsFile = SDL_RWFromFile( file->filePath, "w" );
SDL_RWwrite( rwopsFile, outBuffer, sizeof( char ), sb_Count( outBuffer ) );
clean_up:
SDL_RWclose( rwopsFile );
sb_Release( outBuffer );
return success;
}