X-Git-Url: https://git.artsoft.org/?p=rocksndiamonds.git;a=blobdiff_plain;f=src%2Flibgame%2Fjoystick.c;h=dfe1cca4ab1e520be35cf402393fd373135555d6;hp=61d0a113970302c70e1337d20096cab32b5102b9;hb=e02c111162d5d8a13715de71d93494120380ec9b;hpb=becf6867226b0c3d24f12a9ed76440f36234c9e8 diff --git a/src/libgame/joystick.c b/src/libgame/joystick.c index 61d0a113..dfe1cca4 100644 --- a/src/libgame/joystick.c +++ b/src/libgame/joystick.c @@ -119,6 +119,39 @@ char *getDeviceNameFromJoystickNr(int joystick_nr) joystick_device_name[joystick_nr] : ""); } +char *getFormattedJoystickName(const char *name_raw) +{ + static char name[MAX_JOYSTICK_NAME_LEN + 1]; + boolean name_skip_space = TRUE; + int i, j; + + if (name_raw == NULL) + name_raw = "(unknown joystick)"; + + // copy joystick name, cutting leading and multiple spaces + for (i = 0, j = 0; i < strlen(name_raw) && i < MAX_JOYSTICK_NAME_LEN; i++) + { + if (name_raw[i] != ' ') + { + name[j++] = name_raw[i]; + name_skip_space = FALSE; + } + else if (!name_skip_space) + { + name[j++] = name_raw[i]; + name_skip_space = TRUE; + } + } + + // cut trailing space + if (j > 0 && name[j - 1] == ' ') + j--; + + name[j] = '\0'; + + return name; +} + static int JoystickPositionPercent(int center, int border, int actual) { int range, position;