Fix error reporting in x52cli

Prior to this change, x52cli assumed that the return code from the
handler was a standard error code, but negated. This is an incorrect
assumption as the libx52 API returns a `libx52_error_code` enum, which
is a positive integer.

This change fixes the printing of the error message to call
`libx52_strerror`, which translates it correctly. It also adds error
printing to any failure of `libx52_init`, as well as explicitly
specifying `LIBX52_SUCCESS` instead of `0`.

Addresses #19.
debian-packaging
nirenjan 2020-05-18 14:38:49 -07:00
parent 665dba187d
commit 16b4ad693b
1 changed files with 3 additions and 3 deletions

View File

@ -378,13 +378,13 @@ int main(int argc, char **argv)
rc = libx52_init(&x52); rc = libx52_init(&x52);
if (rc != LIBX52_SUCCESS) { if (rc != LIBX52_SUCCESS) {
fprintf(stderr, "Unable to find X52 joystick!\n"); fprintf(stderr, "Error initializing X52 joystick: %s\n", libx52_strerror(rc));
return 1; return 1;
} }
rc = (*(cmd->handler))(x52, args); rc = (*(cmd->handler))(x52, args);
if (rc != 0) { if (rc != LIBX52_SUCCESS) {
fprintf(stderr, "Error: %s\n", strerror(-rc)); fprintf(stderr, "Error: %s\n", libx52_strerror(rc));
} }
libx52_update(x52); libx52_update(x52);