int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { #ifdef HAVE_STRNCASECMP return strncasecmp(str1, str2, maxlen); #elif defined(HAVE__STRNICMP) return _strnicmp(str1, str2, maxlen); #else char a = 0; char b = 0; while (*str1 && *str2 && maxlen) { a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); if (a != b) break; ++str1; ++str2; --maxlen; } if (maxlen == 0) { return 0; } else { a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); return (int) ((unsigned char) a - (unsigned char) b); } #endif /* HAVE_STRNCASECMP */ }
int SDL_strcasecmp(const char *str1, const char *str2) { char a = 0; char b = 0; while ( *str1 && *str2 ) { a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); if ( a != b ) break; ++str1; ++str2; } return (int)((unsigned char)a - (unsigned char)b); }
char *SDL_strlwr(char *string) { char *bufp = string; while ( *bufp ) { *bufp = SDL_tolower((unsigned char) *bufp); ++bufp; } return string; }
int SDL_strncasecmp(const char *str1, const char *str2, size_t maxlen) { char a = 0; char b = 0; while (*str1 && *str2 && maxlen) { a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); if (a != b) break; ++str1; ++str2; --maxlen; } a = SDL_tolower((unsigned char) *str1); b = SDL_tolower((unsigned char) *str2); return (int) ((unsigned char) a - (unsigned char) b); }
char * SDL_strlwr(char *string) { #if defined(HAVE__STRLWR) return _strlwr(string); #else char *bufp = string; while (*bufp) { *bufp = SDL_tolower((unsigned char) *bufp); ++bufp; } return string; #endif /* HAVE__STRLWR */ }
int SDL_sscanf(const char *text, const char *fmt, ...) { va_list ap; int retval = 0; va_start(ap, fmt); while ( *fmt ) { if ( *fmt == ' ' ) { while ( SDL_isspace((unsigned char) *text) ) { ++text; } ++fmt; continue; } if ( *fmt == '%' ) { SDL_bool done = SDL_FALSE; long count = 0; int radix = 10; enum { DO_SHORT, DO_INT, DO_LONG, DO_LONGLONG } inttype = DO_INT; SDL_bool suppress = SDL_FALSE; ++fmt; if ( *fmt == '%' ) { if ( *text == '%' ) { ++text; ++fmt; continue; } break; } if ( *fmt == '*' ) { suppress = SDL_TRUE; ++fmt; } fmt += SDL_ScanLong(fmt, 10, &count); if ( *fmt == 'c' ) { if ( ! count ) { count = 1; } if ( suppress ) { while ( count-- ) { ++text; } } else { char *valuep = va_arg(ap, char*); while ( count-- ) { *valuep++ = *text++; } ++retval; } continue; } while ( SDL_isspace((unsigned char) *text) ) { ++text; } /* FIXME: implement more of the format specifiers */ while (!done) { switch(*fmt) { case '*': suppress = SDL_TRUE; break; case 'h': if ( inttype > DO_SHORT ) { ++inttype; } break; case 'l': if ( inttype < DO_LONGLONG ) { ++inttype; } break; case 'I': if ( SDL_strncmp(fmt, "I64", 3) == 0 ) { fmt += 2; inttype = DO_LONGLONG; } break; case 'i': { int index = 0; if ( text[index] == '-' ) { ++index; } if ( text[index] == '0' ) { if ( SDL_tolower((unsigned char) text[index+1]) == 'x' ) { radix = 16; } else { radix = 8; } } } /* Fall through to %d handling */ case 'd': #ifdef SDL_HAS_64BIT_TYPE if ( inttype == DO_LONGLONG ) { Sint64 value; text += SDL_ScanLongLong(text, radix, &value); if ( ! suppress ) { Sint64 *valuep = va_arg(ap, Sint64*); *valuep = value; ++retval; } } else #endif /* SDL_HAS_64BIT_TYPE */ { long value; text += SDL_ScanLong(text, radix, &value); if ( ! suppress ) { switch (inttype) { case DO_SHORT: { short* valuep = va_arg(ap, short*); *valuep = (short)value; } break; case DO_INT: { int* valuep = va_arg(ap, int*); *valuep = (int)value; } break; case DO_LONG: { long* valuep = va_arg(ap, long*); *valuep = value; } break; case DO_LONGLONG: /* Handled above */ break; } ++retval; } } done = SDL_TRUE; break; case 'o': if ( radix == 10 ) { radix = 8; } /* Fall through to unsigned handling */ case 'x': case 'X': if ( radix == 10 ) { radix = 16; } /* Fall through to unsigned handling */ case 'u': #ifdef SDL_HAS_64BIT_TYPE if ( inttype == DO_LONGLONG ) { Uint64 value; text += SDL_ScanUnsignedLongLong(text, radix, &value); if ( ! suppress ) { Uint64 *valuep = va_arg(ap, Uint64*); *valuep = value; ++retval; }
void WIN_InitMouse(_THIS) { int index = 0; RAWINPUTDEVICELIST *deviceList = NULL; int devCount = 0; int i; int tmp = 0; char *buffer = NULL; char *tab = "wacom"; /* since windows does't give us handles to tablets, we have to detect a tablet by it's name */ const char *rdp = "rdp_mou"; SDL_VideoData *data = (SDL_VideoData *) _this->driverdata; /* WinCE has no RawInputDeviceList */ #ifdef _WIN32_WCE SDL_Mouse mouse; SDL_zero(mouse); mouse.id = 0; SDL_AddMouse(&mouse, "Stylus", 0, 0, 1); #else /* we're checking for the number of rawinput devices */ if (GetRawInputDeviceList(NULL, &devCount, sizeof(RAWINPUTDEVICELIST))) { return; } deviceList = SDL_malloc(sizeof(RAWINPUTDEVICELIST) * devCount); /* we're getting the raw input device list */ GetRawInputDeviceList(deviceList, &devCount, sizeof(RAWINPUTDEVICELIST)); mice = SDL_malloc(devCount * sizeof(HANDLE)); /* we're getting the details of the devices */ for (i = 0; i < devCount; ++i) { int is_rdp = 0; int j; int k; char *default_device_name = "Pointing device xx"; const char *reg_key_root = "System\\CurrentControlSet\\Enum\\"; char *device_name = SDL_malloc(256 * sizeof(char)); char *key_name = NULL; char *tmp_name = NULL; LONG rc = 0; HKEY hkey; DWORD regtype = REG_SZ; DWORD out = 256 * sizeof(char); SDL_Mouse mouse; int l; if (deviceList[i].dwType != RIM_TYPEMOUSE) { /* if a device isn't a mouse type we don't want it */ continue; } if (GetRawInputDeviceInfoA (deviceList[i].hDevice, RIDI_DEVICENAME, NULL, &tmp) < 0) { continue; } buffer = SDL_malloc((tmp + 1) * sizeof(char)); key_name = SDL_malloc((tmp + SDL_strlen(reg_key_root) + 1) * sizeof(char)); /* we're getting the device registry path and polishing it to get it's name, surely there must be an easier way, but we haven't found it yet */ if (GetRawInputDeviceInfoA (deviceList[i].hDevice, RIDI_DEVICENAME, buffer, &tmp) < 0) { continue; } buffer += 4; tmp -= 4; tmp_name = buffer; for (j = 0; j < tmp; ++j) { if (*tmp_name == '#') { *tmp_name = '\\'; } else if (*tmp_name == '{') { break; } ++tmp_name; } *tmp_name = '\0'; SDL_memcpy(key_name, reg_key_root, SDL_strlen(reg_key_root)); SDL_memcpy(key_name + (SDL_strlen(reg_key_root)), buffer, j + 1); l = SDL_strlen(key_name); is_rdp = 0; if (l >= 7) { for (j = 0; j < l - 7; ++j) { for (k = 0; k < 7; ++k) { if (rdp[k] != SDL_tolower((unsigned char) key_name[j + k])) { break; } } if (k == 7) { is_rdp = 1; break; } } } buffer -= 4; if (is_rdp == 1) { SDL_free(buffer); SDL_free(key_name); SDL_free(device_name); is_rdp = 0; continue; } /* we're opening the registry key to get the mouse name */ rc = RegOpenKeyExA(HKEY_LOCAL_MACHINE, key_name, 0, KEY_READ, &hkey); if (rc != ERROR_SUCCESS) { SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); } rc = RegQueryValueExA(hkey, "DeviceDesc", NULL, ®type, device_name, &out); RegCloseKey(hkey); if (rc != ERROR_SUCCESS) { SDL_memcpy(device_name, default_device_name, SDL_strlen(default_device_name)); } /* we're saving the handle to the device */ mice[index] = deviceList[i].hDevice; SDL_zero(mouse); mouse.id = index; l = SDL_strlen(device_name); /* we're checking if the device isn't by any chance a tablet */ if (data->wintabDLL && tablet == -1) { for (j = 0; j < l - 5; ++j) { for (k = 0; k < 5; ++k) { if (tab[k] != SDL_tolower((unsigned char) device_name[j + k])) { break; } } if (k == 5) { tablet = index; break; } } } /* if it's a tablet, let's read it's maximum and minimum pressure */ if (tablet == index) { AXIS pressure; int cursors; data->WTInfoA(WTI_DEVICES, DVC_NPRESSURE, &pressure); data->WTInfoA(WTI_DEVICES, DVC_NCSRTYPES, &cursors); SDL_AddMouse(&mouse, device_name, pressure.axMax, pressure.axMin, cursors); } else { SDL_AddMouse(&mouse, device_name, 0, 0, 1); } ++index; SDL_free(buffer); SDL_free(key_name); } total_mice = index; SDL_free(deviceList); #endif /*_WIN32_WCE*/ }