comparison src/joystick/bsd/SDL_sysjoystick.c @ 1668:4da1ee79c9af SDL-1.3

more tweaking indent options
author Sam Lantinga <slouken@libsdl.org>
date Mon, 29 May 2006 04:04:35 +0000
parents 782fd950bd46
children
comparison
equal deleted inserted replaced
1667:1fddae038bc8 1668:4da1ee79c9af
133 }; 133 };
134 134
135 static char *joynames[MAX_JOYS]; 135 static char *joynames[MAX_JOYS];
136 static char *joydevnames[MAX_JOYS]; 136 static char *joydevnames[MAX_JOYS];
137 137
138 static int report_alloc (struct report *, struct report_desc *, int); 138 static int report_alloc(struct report *, struct report_desc *, int);
139 static void report_free (struct report *); 139 static void report_free(struct report *);
140 140
141 #ifdef USBHID_UCR_DATA 141 #ifdef USBHID_UCR_DATA
142 #define REP_BUF_DATA(rep) ((rep)->buf->ucr_data) 142 #define REP_BUF_DATA(rep) ((rep)->buf->ucr_data)
143 #else 143 #else
144 #define REP_BUF_DATA(rep) ((rep)->buf->data) 144 #define REP_BUF_DATA(rep) ((rep)->buf->data)
145 #endif 145 #endif
146 146
147 int 147 int
148 SDL_SYS_JoystickInit (void) 148 SDL_SYS_JoystickInit(void)
149 { 149 {
150 char s[16]; 150 char s[16];
151 int i, fd; 151 int i, fd;
152 152
153 SDL_numjoysticks = 0; 153 SDL_numjoysticks = 0;
154 154
155 SDL_memset (joynames, 0, sizeof (joynames)); 155 SDL_memset(joynames, 0, sizeof(joynames));
156 SDL_memset (joydevnames, 0, sizeof (joydevnames)); 156 SDL_memset(joydevnames, 0, sizeof(joydevnames));
157 157
158 for (i = 0; i < MAX_UHID_JOYS; i++) { 158 for (i = 0; i < MAX_UHID_JOYS; i++) {
159 SDL_Joystick nj; 159 SDL_Joystick nj;
160 160
161 SDL_snprintf (s, SDL_arraysize (s), "/dev/uhid%d", i); 161 SDL_snprintf(s, SDL_arraysize(s), "/dev/uhid%d", i);
162 162
163 nj.index = SDL_numjoysticks; 163 nj.index = SDL_numjoysticks;
164 joynames[nj.index] = strdup (s); 164 joynames[nj.index] = strdup(s);
165 165
166 if (SDL_SYS_JoystickOpen (&nj) == 0) { 166 if (SDL_SYS_JoystickOpen(&nj) == 0) {
167 SDL_SYS_JoystickClose (&nj); 167 SDL_SYS_JoystickClose(&nj);
168 SDL_numjoysticks++; 168 SDL_numjoysticks++;
169 } else { 169 } else {
170 SDL_free (joynames[nj.index]); 170 SDL_free(joynames[nj.index]);
171 joynames[nj.index] = NULL; 171 joynames[nj.index] = NULL;
172 } 172 }
173 } 173 }
174 for (i = 0; i < MAX_JOY_JOYS; i++) { 174 for (i = 0; i < MAX_JOY_JOYS; i++) {
175 SDL_snprintf (s, SDL_arraysize (s), "/dev/joy%d", i); 175 SDL_snprintf(s, SDL_arraysize(s), "/dev/joy%d", i);
176 fd = open (s, O_RDONLY); 176 fd = open(s, O_RDONLY);
177 if (fd != -1) { 177 if (fd != -1) {
178 joynames[SDL_numjoysticks++] = strdup (s); 178 joynames[SDL_numjoysticks++] = strdup(s);
179 close (fd); 179 close(fd);
180 } 180 }
181 } 181 }
182 182
183 /* Read the default USB HID usage table. */ 183 /* Read the default USB HID usage table. */
184 hid_init (NULL); 184 hid_init(NULL);
185 185
186 return (SDL_numjoysticks); 186 return (SDL_numjoysticks);
187 } 187 }
188 188
189 const char * 189 const char *
190 SDL_SYS_JoystickName (int index) 190 SDL_SYS_JoystickName(int index)
191 { 191 {
192 if (joydevnames[index] != NULL) { 192 if (joydevnames[index] != NULL) {
193 return (joydevnames[index]); 193 return (joydevnames[index]);
194 } 194 }
195 return (joynames[index]); 195 return (joynames[index]);
196 } 196 }
197 197
198 static int 198 static int
199 usage_to_joyaxe (unsigned usage) 199 usage_to_joyaxe(unsigned usage)
200 { 200 {
201 int joyaxe; 201 int joyaxe;
202 switch (usage) { 202 switch (usage) {
203 case HUG_X: 203 case HUG_X:
204 joyaxe = JOYAXE_X; 204 joyaxe = JOYAXE_X;
229 } 229 }
230 return joyaxe; 230 return joyaxe;
231 } 231 }
232 232
233 static unsigned 233 static unsigned
234 hatval_to_sdl (Sint32 hatval) 234 hatval_to_sdl(Sint32 hatval)
235 { 235 {
236 static const unsigned hat_dir_map[8] = { 236 static const unsigned hat_dir_map[8] = {
237 SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN, 237 SDL_HAT_UP, SDL_HAT_RIGHTUP, SDL_HAT_RIGHT, SDL_HAT_RIGHTDOWN,
238 SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP 238 SDL_HAT_DOWN, SDL_HAT_LEFTDOWN, SDL_HAT_LEFT, SDL_HAT_LEFTUP
239 }; 239 };
245 return result; 245 return result;
246 } 246 }
247 247
248 248
249 int 249 int
250 SDL_SYS_JoystickOpen (SDL_Joystick * joy) 250 SDL_SYS_JoystickOpen(SDL_Joystick * joy)
251 { 251 {
252 char *path = joynames[joy->index]; 252 char *path = joynames[joy->index];
253 struct joystick_hwdata *hw; 253 struct joystick_hwdata *hw;
254 struct hid_item hitem; 254 struct hid_item hitem;
255 struct hid_data *hdata; 255 struct hid_data *hdata;
256 struct report *rep; 256 struct report *rep;
257 int fd; 257 int fd;
258 int i; 258 int i;
259 259
260 fd = open (path, O_RDONLY); 260 fd = open(path, O_RDONLY);
261 if (fd == -1) { 261 if (fd == -1) {
262 SDL_SetError ("%s: %s", path, strerror (errno)); 262 SDL_SetError("%s: %s", path, strerror(errno));
263 return (-1); 263 return (-1);
264 } 264 }
265 265
266 hw = (struct joystick_hwdata *) 266 hw = (struct joystick_hwdata *)
267 SDL_malloc (sizeof (struct joystick_hwdata)); 267 SDL_malloc(sizeof(struct joystick_hwdata));
268 if (hw == NULL) { 268 if (hw == NULL) {
269 SDL_OutOfMemory (); 269 SDL_OutOfMemory();
270 close (fd); 270 close(fd);
271 return (-1); 271 return (-1);
272 } 272 }
273 joy->hwdata = hw; 273 joy->hwdata = hw;
274 hw->fd = fd; 274 hw->fd = fd;
275 hw->path = strdup (path); 275 hw->path = strdup(path);
276 if (!SDL_strncmp (path, "/dev/joy", 8)) { 276 if (!SDL_strncmp(path, "/dev/joy", 8)) {
277 hw->type = BSDJOY_JOY; 277 hw->type = BSDJOY_JOY;
278 joy->naxes = 2; 278 joy->naxes = 2;
279 joy->nbuttons = 2; 279 joy->nbuttons = 2;
280 joy->nhats = 0; 280 joy->nhats = 0;
281 joy->nballs = 0; 281 joy->nballs = 0;
282 joydevnames[joy->index] = strdup ("Gameport joystick"); 282 joydevnames[joy->index] = strdup("Gameport joystick");
283 goto usbend; 283 goto usbend;
284 } else { 284 } else {
285 hw->type = BSDJOY_UHID; 285 hw->type = BSDJOY_UHID;
286 } 286 }
287 287
288 { 288 {
289 int ax; 289 int ax;
290 for (ax = 0; ax < JOYAXE_count; ax++) 290 for (ax = 0; ax < JOYAXE_count; ax++)
291 hw->axis_map[ax] = -1; 291 hw->axis_map[ax] = -1;
292 } 292 }
293 hw->repdesc = hid_get_report_desc (fd); 293 hw->repdesc = hid_get_report_desc(fd);
294 if (hw->repdesc == NULL) { 294 if (hw->repdesc == NULL) {
295 SDL_SetError ("%s: USB_GET_REPORT_DESC: %s", hw->path, 295 SDL_SetError("%s: USB_GET_REPORT_DESC: %s", hw->path,
296 strerror (errno)); 296 strerror(errno));
297 goto usberr; 297 goto usberr;
298 } 298 }
299 299
300 rep = &hw->inreport; 300 rep = &hw->inreport;
301 if (ioctl (fd, USB_GET_REPORT_ID, &rep->rid) < 0) { 301 if (ioctl(fd, USB_GET_REPORT_ID, &rep->rid) < 0) {
302 rep->rid = -1; /* XXX */ 302 rep->rid = -1; /* XXX */
303 } 303 }
304 if (report_alloc (rep, hw->repdesc, REPORT_INPUT) < 0) { 304 if (report_alloc(rep, hw->repdesc, REPORT_INPUT) < 0) {
305 goto usberr; 305 goto usberr;
306 } 306 }
307 if (rep->size <= 0) { 307 if (rep->size <= 0) {
308 SDL_SetError ("%s: Input report descriptor has invalid length", 308 SDL_SetError("%s: Input report descriptor has invalid length",
309 hw->path); 309 hw->path);
310 goto usberr; 310 goto usberr;
311 } 311 }
312 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111) 312 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111)
313 hdata = hid_start_parse (hw->repdesc, 1 << hid_input, rep->rid); 313 hdata = hid_start_parse(hw->repdesc, 1 << hid_input, rep->rid);
314 #else 314 #else
315 hdata = hid_start_parse (hw->repdesc, 1 << hid_input); 315 hdata = hid_start_parse(hw->repdesc, 1 << hid_input);
316 #endif 316 #endif
317 if (hdata == NULL) { 317 if (hdata == NULL) {
318 SDL_SetError ("%s: Cannot start HID parser", hw->path); 318 SDL_SetError("%s: Cannot start HID parser", hw->path);
319 goto usberr; 319 goto usberr;
320 } 320 }
321 joy->naxes = 0; 321 joy->naxes = 0;
322 joy->nbuttons = 0; 322 joy->nbuttons = 0;
323 joy->nhats = 0; 323 joy->nhats = 0;
324 joy->nballs = 0; 324 joy->nballs = 0;
325 for (i = 0; i < JOYAXE_count; i++) 325 for (i = 0; i < JOYAXE_count; i++)
326 hw->axis_map[i] = -1; 326 hw->axis_map[i] = -1;
327 327
328 while (hid_get_item (hdata, &hitem) > 0) { 328 while (hid_get_item(hdata, &hitem) > 0) {
329 char *sp; 329 char *sp;
330 const char *s; 330 const char *s;
331 331
332 switch (hitem.kind) { 332 switch (hitem.kind) {
333 case hid_collection: 333 case hid_collection:
334 switch (HID_PAGE (hitem.usage)) { 334 switch (HID_PAGE(hitem.usage)) {
335 case HUP_GENERIC_DESKTOP: 335 case HUP_GENERIC_DESKTOP:
336 switch (HID_USAGE (hitem.usage)) { 336 switch (HID_USAGE(hitem.usage)) {
337 case HUG_JOYSTICK: 337 case HUG_JOYSTICK:
338 case HUG_GAME_PAD: 338 case HUG_GAME_PAD:
339 s = hid_usage_in_page (hitem.usage); 339 s = hid_usage_in_page(hitem.usage);
340 sp = SDL_malloc (SDL_strlen (s) + 5); 340 sp = SDL_malloc(SDL_strlen(s) + 5);
341 SDL_snprintf (sp, SDL_strlen (s) + 5, "%s (%d)", 341 SDL_snprintf(sp, SDL_strlen(s) + 5, "%s (%d)",
342 s, joy->index); 342 s, joy->index);
343 joydevnames[joy->index] = sp; 343 joydevnames[joy->index] = sp;
344 } 344 }
345 } 345 }
346 break; 346 break;
347 case hid_input: 347 case hid_input:
348 switch (HID_PAGE (hitem.usage)) { 348 switch (HID_PAGE(hitem.usage)) {
349 case HUP_GENERIC_DESKTOP: 349 case HUP_GENERIC_DESKTOP:
350 { 350 {
351 unsigned usage = HID_USAGE (hitem.usage); 351 unsigned usage = HID_USAGE(hitem.usage);
352 int joyaxe = usage_to_joyaxe (usage); 352 int joyaxe = usage_to_joyaxe(usage);
353 if (joyaxe >= 0) { 353 if (joyaxe >= 0) {
354 hw->axis_map[joyaxe] = 1; 354 hw->axis_map[joyaxe] = 1;
355 } else if (usage == HUG_HAT_SWITCH) { 355 } else if (usage == HUG_HAT_SWITCH) {
356 joy->nhats++; 356 joy->nhats++;
357 } 357 }
366 break; 366 break;
367 default: 367 default:
368 break; 368 break;
369 } 369 }
370 } 370 }
371 hid_end_parse (hdata); 371 hid_end_parse(hdata);
372 for (i = 0; i < JOYAXE_count; i++) 372 for (i = 0; i < JOYAXE_count; i++)
373 if (hw->axis_map[i] > 0) 373 if (hw->axis_map[i] > 0)
374 hw->axis_map[i] = joy->naxes++; 374 hw->axis_map[i] = joy->naxes++;
375 375
376 usbend: 376 usbend:
377 /* The poll blocks the event thread. */ 377 /* The poll blocks the event thread. */
378 fcntl (fd, F_SETFL, O_NONBLOCK); 378 fcntl(fd, F_SETFL, O_NONBLOCK);
379 379
380 return (0); 380 return (0);
381 usberr: 381 usberr:
382 close (hw->fd); 382 close(hw->fd);
383 SDL_free (hw->path); 383 SDL_free(hw->path);
384 SDL_free (hw); 384 SDL_free(hw);
385 return (-1); 385 return (-1);
386 } 386 }
387 387
388 void 388 void
389 SDL_SYS_JoystickUpdate (SDL_Joystick * joy) 389 SDL_SYS_JoystickUpdate(SDL_Joystick * joy)
390 { 390 {
391 struct hid_item hitem; 391 struct hid_item hitem;
392 struct hid_data *hdata; 392 struct hid_data *hdata;
393 struct report *rep; 393 struct report *rep;
394 int nbutton, naxe = -1; 394 int nbutton, naxe = -1;
397 #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H 397 #if defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H
398 struct joystick gameport; 398 struct joystick gameport;
399 static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0; 399 static int x, y, xmin = 0xffff, ymin = 0xffff, xmax = 0, ymax = 0;
400 400
401 if (joy->hwdata->type == BSDJOY_JOY) { 401 if (joy->hwdata->type == BSDJOY_JOY) {
402 if (read (joy->hwdata->fd, &gameport, sizeof gameport) != 402 if (read(joy->hwdata->fd, &gameport, sizeof gameport) !=
403 sizeof gameport) 403 sizeof gameport)
404 return; 404 return;
405 if (abs (x - gameport.x) > 8) { 405 if (abs(x - gameport.x) > 8) {
406 x = gameport.x; 406 x = gameport.x;
407 if (x < xmin) { 407 if (x < xmin) {
408 xmin = x; 408 xmin = x;
409 } 409 }
410 if (x > xmax) { 410 if (x > xmax) {
415 xmax++; 415 xmax++;
416 } 416 }
417 v = (Sint32) x; 417 v = (Sint32) x;
418 v -= (xmax + xmin + 1) / 2; 418 v -= (xmax + xmin + 1) / 2;
419 v *= 32768 / ((xmax - xmin + 1) / 2); 419 v *= 32768 / ((xmax - xmin + 1) / 2);
420 SDL_PrivateJoystickAxis (joy, 0, v); 420 SDL_PrivateJoystickAxis(joy, 0, v);
421 } 421 }
422 if (abs (y - gameport.y) > 8) { 422 if (abs(y - gameport.y) > 8) {
423 y = gameport.y; 423 y = gameport.y;
424 if (y < ymin) { 424 if (y < ymin) {
425 ymin = y; 425 ymin = y;
426 } 426 }
427 if (y > ymax) { 427 if (y > ymax) {
432 ymax++; 432 ymax++;
433 } 433 }
434 v = (Sint32) y; 434 v = (Sint32) y;
435 v -= (ymax + ymin + 1) / 2; 435 v -= (ymax + ymin + 1) / 2;
436 v *= 32768 / ((ymax - ymin + 1) / 2); 436 v *= 32768 / ((ymax - ymin + 1) / 2);
437 SDL_PrivateJoystickAxis (joy, 1, v); 437 SDL_PrivateJoystickAxis(joy, 1, v);
438 } 438 }
439 if (gameport.b1 != joy->buttons[0]) { 439 if (gameport.b1 != joy->buttons[0]) {
440 SDL_PrivateJoystickButton (joy, 0, gameport.b1); 440 SDL_PrivateJoystickButton(joy, 0, gameport.b1);
441 } 441 }
442 if (gameport.b2 != joy->buttons[1]) { 442 if (gameport.b2 != joy->buttons[1]) {
443 SDL_PrivateJoystickButton (joy, 1, gameport.b2); 443 SDL_PrivateJoystickButton(joy, 1, gameport.b2);
444 } 444 }
445 return; 445 return;
446 } 446 }
447 #endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */ 447 #endif /* defined(__FREEBSD__) || SDL_JOYSTICK_USBHID_MACHINE_JOYSTICK_H */
448 448
449 rep = &joy->hwdata->inreport; 449 rep = &joy->hwdata->inreport;
450 450
451 if (read (joy->hwdata->fd, REP_BUF_DATA (rep), rep->size) != rep->size) { 451 if (read(joy->hwdata->fd, REP_BUF_DATA(rep), rep->size) != rep->size) {
452 return; 452 return;
453 } 453 }
454 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111) 454 #if defined(USBHID_NEW) || (defined(__FREEBSD__) && __FreeBSD_version >= 500111)
455 hdata = hid_start_parse (joy->hwdata->repdesc, 1 << hid_input, rep->rid); 455 hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input, rep->rid);
456 #else 456 #else
457 hdata = hid_start_parse (joy->hwdata->repdesc, 1 << hid_input); 457 hdata = hid_start_parse(joy->hwdata->repdesc, 1 << hid_input);
458 #endif 458 #endif
459 if (hdata == NULL) { 459 if (hdata == NULL) {
460 fprintf (stderr, "%s: Cannot start HID parser\n", joy->hwdata->path); 460 fprintf(stderr, "%s: Cannot start HID parser\n", joy->hwdata->path);
461 return; 461 return;
462 } 462 }
463 463
464 for (nbutton = 0; hid_get_item (hdata, &hitem) > 0;) { 464 for (nbutton = 0; hid_get_item(hdata, &hitem) > 0;) {
465 switch (hitem.kind) { 465 switch (hitem.kind) {
466 case hid_input: 466 case hid_input:
467 switch (HID_PAGE (hitem.usage)) { 467 switch (HID_PAGE(hitem.usage)) {
468 case HUP_GENERIC_DESKTOP: 468 case HUP_GENERIC_DESKTOP:
469 { 469 {
470 unsigned usage = HID_USAGE (hitem.usage); 470 unsigned usage = HID_USAGE(hitem.usage);
471 int joyaxe = usage_to_joyaxe (usage); 471 int joyaxe = usage_to_joyaxe(usage);
472 if (joyaxe >= 0) { 472 if (joyaxe >= 0) {
473 naxe = joy->hwdata->axis_map[joyaxe]; 473 naxe = joy->hwdata->axis_map[joyaxe];
474 /* scaleaxe */ 474 /* scaleaxe */
475 v = (Sint32) hid_get_data (REP_BUF_DATA (rep), 475 v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
476 &hitem);
477 v -= (hitem.logical_maximum + 476 v -= (hitem.logical_maximum +
478 hitem.logical_minimum + 1) / 2; 477 hitem.logical_minimum + 1) / 2;
479 v *= 32768 / 478 v *= 32768 /
480 ((hitem.logical_maximum - 479 ((hitem.logical_maximum -
481 hitem.logical_minimum + 1) / 2); 480 hitem.logical_minimum + 1) / 2);
482 if (v != joy->axes[naxe]) { 481 if (v != joy->axes[naxe]) {
483 SDL_PrivateJoystickAxis (joy, naxe, v); 482 SDL_PrivateJoystickAxis(joy, naxe, v);
484 } 483 }
485 } else if (usage == HUG_HAT_SWITCH) { 484 } else if (usage == HUG_HAT_SWITCH) {
486 v = (Sint32) hid_get_data (REP_BUF_DATA (rep), 485 v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
487 &hitem); 486 SDL_PrivateJoystickHat(joy, 0,
488 SDL_PrivateJoystickHat (joy, 0, 487 hatval_to_sdl(v) -
489 hatval_to_sdl (v) - 488 hitem.logical_minimum);
490 hitem.logical_minimum);
491 } 489 }
492 break; 490 break;
493 } 491 }
494 case HUP_BUTTON: 492 case HUP_BUTTON:
495 v = (Sint32) hid_get_data (REP_BUF_DATA (rep), &hitem); 493 v = (Sint32) hid_get_data(REP_BUF_DATA(rep), &hitem);
496 if (joy->buttons[nbutton] != v) { 494 if (joy->buttons[nbutton] != v) {
497 SDL_PrivateJoystickButton (joy, nbutton, v); 495 SDL_PrivateJoystickButton(joy, nbutton, v);
498 } 496 }
499 nbutton++; 497 nbutton++;
500 break; 498 break;
501 default: 499 default:
502 continue; 500 continue;
504 break; 502 break;
505 default: 503 default:
506 break; 504 break;
507 } 505 }
508 } 506 }
509 hid_end_parse (hdata); 507 hid_end_parse(hdata);
510 508
511 return; 509 return;
512 } 510 }
513 511
514 /* Function to close a joystick after use */ 512 /* Function to close a joystick after use */
515 void 513 void
516 SDL_SYS_JoystickClose (SDL_Joystick * joy) 514 SDL_SYS_JoystickClose(SDL_Joystick * joy)
517 { 515 {
518 if (SDL_strncmp (joy->hwdata->path, "/dev/joy", 8)) { 516 if (SDL_strncmp(joy->hwdata->path, "/dev/joy", 8)) {
519 report_free (&joy->hwdata->inreport); 517 report_free(&joy->hwdata->inreport);
520 hid_dispose_report_desc (joy->hwdata->repdesc); 518 hid_dispose_report_desc(joy->hwdata->repdesc);
521 } 519 }
522 close (joy->hwdata->fd); 520 close(joy->hwdata->fd);
523 SDL_free (joy->hwdata->path); 521 SDL_free(joy->hwdata->path);
524 SDL_free (joy->hwdata); 522 SDL_free(joy->hwdata);
525 523
526 return; 524 return;
527 } 525 }
528 526
529 void 527 void
530 SDL_SYS_JoystickQuit (void) 528 SDL_SYS_JoystickQuit(void)
531 { 529 {
532 int i; 530 int i;
533 531
534 for (i = 0; i < MAX_JOYS; i++) { 532 for (i = 0; i < MAX_JOYS; i++) {
535 if (joynames[i] != NULL) 533 if (joynames[i] != NULL)
536 SDL_free (joynames[i]); 534 SDL_free(joynames[i]);
537 if (joydevnames[i] != NULL) 535 if (joydevnames[i] != NULL)
538 SDL_free (joydevnames[i]); 536 SDL_free(joydevnames[i]);
539 } 537 }
540 538
541 return; 539 return;
542 } 540 }
543 541
544 static int 542 static int
545 report_alloc (struct report *r, struct report_desc *rd, int repind) 543 report_alloc(struct report *r, struct report_desc *rd, int repind)
546 { 544 {
547 int len; 545 int len;
548 546
549 #ifdef __DragonFly__ 547 #ifdef __DragonFly__
550 len = hid_report_size (rd, r->rid, repinfo[repind].kind); 548 len = hid_report_size(rd, r->rid, repinfo[repind].kind);
551 #elif __FREEBSD__ 549 #elif __FREEBSD__
552 # if (__FreeBSD_version >= 460000) 550 # if (__FreeBSD_version >= 460000)
553 # if (__FreeBSD_version <= 500111) 551 # if (__FreeBSD_version <= 500111)
554 len = hid_report_size (rd, r->rid, repinfo[repind].kind); 552 len = hid_report_size(rd, r->rid, repinfo[repind].kind);
555 # else 553 # else
556 len = hid_report_size (rd, repinfo[repind].kind, r->rid); 554 len = hid_report_size(rd, repinfo[repind].kind, r->rid);
557 # endif 555 # endif
558 # else 556 # else
559 len = hid_report_size (rd, repinfo[repind].kind, &r->rid); 557 len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
560 # endif 558 # endif
561 #else 559 #else
562 # ifdef USBHID_NEW 560 # ifdef USBHID_NEW
563 len = hid_report_size (rd, repinfo[repind].kind, r->rid); 561 len = hid_report_size(rd, repinfo[repind].kind, r->rid);
564 # else 562 # else
565 len = hid_report_size (rd, repinfo[repind].kind, &r->rid); 563 len = hid_report_size(rd, repinfo[repind].kind, &r->rid);
566 # endif 564 # endif
567 #endif 565 #endif
568 566
569 if (len < 0) { 567 if (len < 0) {
570 SDL_SetError ("Negative HID report size"); 568 SDL_SetError("Negative HID report size");
571 return (-1); 569 return (-1);
572 } 570 }
573 r->size = len; 571 r->size = len;
574 572
575 if (r->size > 0) { 573 if (r->size > 0) {
576 r->buf = SDL_malloc (sizeof (*r->buf) - sizeof (REP_BUF_DATA (r)) + 574 r->buf = SDL_malloc(sizeof(*r->buf) - sizeof(REP_BUF_DATA(r)) +
577 r->size); 575 r->size);
578 if (r->buf == NULL) { 576 if (r->buf == NULL) {
579 SDL_OutOfMemory (); 577 SDL_OutOfMemory();
580 return (-1); 578 return (-1);
581 } 579 }
582 } else { 580 } else {
583 r->buf = NULL; 581 r->buf = NULL;
584 } 582 }
586 r->status = SREPORT_CLEAN; 584 r->status = SREPORT_CLEAN;
587 return (0); 585 return (0);
588 } 586 }
589 587
590 static void 588 static void
591 report_free (struct report *r) 589 report_free(struct report *r)
592 { 590 {
593 if (r->buf != NULL) { 591 if (r->buf != NULL) {
594 SDL_free (r->buf); 592 SDL_free(r->buf);
595 } 593 }
596 r->status = SREPORT_UNINIT; 594 r->status = SREPORT_UNINIT;
597 } 595 }
598 596
599 #endif /* SDL_JOYSTICK_USBHID */ 597 #endif /* SDL_JOYSTICK_USBHID */