mirror of https://github.com/nirenjan/libx52.git
Add stringification functions to libx52
parent
77606ae906
commit
018852a012
|
@ -12,11 +12,11 @@ lib_LTLIBRARIES = libx52.la
|
|||
# This library handles the USB communication between the host and the X52
|
||||
# Libtool Version Info
|
||||
# See: https://www.gnu.org/software/libtool/manual/html_node/Updating-version-info.html
|
||||
libx52_v_CUR=5
|
||||
libx52_v_AGE=3
|
||||
libx52_v_CUR=6
|
||||
libx52_v_AGE=4
|
||||
libx52_v_REV=0
|
||||
libx52_la_SOURCES = x52_control.c x52_core.c x52_date_time.c x52_mfd_led.c \
|
||||
x52_strerror.c
|
||||
x52_strerror.c x52_stringify.c
|
||||
libx52_la_CFLAGS = @LIBUSB_CFLAGS@ -DLOCALEDIR=\"$(localedir)\" -I $(top_srcdir) $(WARN_CFLAGS)
|
||||
libx52_la_LDFLAGS = \
|
||||
-export-symbols-regex '^libx52_' \
|
||||
|
|
|
@ -673,6 +673,16 @@ int libx52_vendor_command(libx52_device *x52, uint16_t index, uint16_t value);
|
|||
*/
|
||||
int libx52_check_feature(libx52_device *x52, libx52_feature feature);
|
||||
|
||||
/** @} */
|
||||
|
||||
/**
|
||||
* @defgroup libx52str Stringification
|
||||
*
|
||||
* Translation APIs from enumerations to string, primarily for logging.
|
||||
*
|
||||
* @{
|
||||
*/
|
||||
|
||||
/**
|
||||
* @brief Return a string representation of the error code
|
||||
*
|
||||
|
@ -683,6 +693,56 @@ int libx52_check_feature(libx52_device *x52, libx52_feature feature);
|
|||
*/
|
||||
const char * libx52_strerror(libx52_error_code error);
|
||||
|
||||
/**
|
||||
* @brief Returns a string representation of the clock ID
|
||||
*
|
||||
* @param[in] id Clock ID
|
||||
*
|
||||
* @returns Pointer to a NULL terminated string describing the clock ID.
|
||||
* Returned pointer must not be freed.
|
||||
*/
|
||||
const char * libx52_str_clock_id(libx52_clock_id id);
|
||||
|
||||
/**
|
||||
* @brief Returns a string representation of the clock format
|
||||
*
|
||||
* @param[in] format Clock format
|
||||
*
|
||||
* @returns Pointer to a NULL terminated string describing the clock format.
|
||||
* Returned pointer must not be freed.
|
||||
*/
|
||||
const char * libx52_str_clock_format(libx52_clock_format format);
|
||||
|
||||
/**
|
||||
* @brief Returns a string representation of the date format
|
||||
*
|
||||
* @param[in] format Date format
|
||||
*
|
||||
* @returns Pointer to a NULL terminated string describing the date format.
|
||||
* Returned pointer must not be freed.
|
||||
*/
|
||||
const char * libx52_str_date_format(libx52_date_format format);
|
||||
|
||||
/**
|
||||
* @brief Returns a string representation of the LED
|
||||
*
|
||||
* @param[in] id LED ID
|
||||
*
|
||||
* @returns Pointer to a NULL terminated string describing the LED.
|
||||
* Returned pointer must not be freed.
|
||||
*/
|
||||
const char * libx52_str_led_id(libx52_led_id id);
|
||||
|
||||
/**
|
||||
* @brief Returns a string representation of the LED state
|
||||
*
|
||||
* @param[in] state LED state
|
||||
*
|
||||
* @returns Pointer to a NULL terminated string describing the LED state.
|
||||
* Returned pointer must not be freed.
|
||||
*/
|
||||
const char * libx52_str_led_state(libx52_led_state state);
|
||||
|
||||
/** @} */
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -0,0 +1,96 @@
|
|||
/*
|
||||
* Saitek X52 Pro MFD & LED driver - stringification
|
||||
*
|
||||
* Copyright (C) 2012-2021 Nirenjan Krishnan (nirenjan@nirenjan.org)
|
||||
*
|
||||
* SPDX-License-Identifier: GPL-2.0-only WITH Classpath-exception-2.0
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
#include <stdio.h>
|
||||
|
||||
#include "libx52.h"
|
||||
#include "gettext.h"
|
||||
|
||||
#define N_(str) gettext_noop(str)
|
||||
#define _(str) dgettext(PACKAGE, str)
|
||||
|
||||
#define STRINGIFY(name, max_id, errstr, ...) \
|
||||
const char * libx52_str_ ## name (libx52_ ## name param) { \
|
||||
static char invalid[256]; \
|
||||
static const char *desc[] = { __VA_ARGS__ }; \
|
||||
if (param >= 0 && param <= max_id) { \
|
||||
return _(desc[param]); \
|
||||
} \
|
||||
snprintf(invalid, sizeof(invalid), _(errstr), param); \
|
||||
return invalid; \
|
||||
}
|
||||
|
||||
STRINGIFY(clock_id, LIBX52_CLOCK_3, N_("Unknown clock ID %d"),
|
||||
N_("primary"),
|
||||
N_("secondary"),
|
||||
N_("tertiary"),
|
||||
)
|
||||
|
||||
STRINGIFY(clock_format, LIBX52_CLOCK_FORMAT_24HR, N_("Unknown clock format %d"),
|
||||
N_("12 hour"),
|
||||
N_("24 hour"),
|
||||
)
|
||||
|
||||
STRINGIFY(date_format, LIBX52_DATE_FORMAT_YYMMDD, N_("Unknown date format %d"),
|
||||
N_("DD-MM-YY"),
|
||||
N_("MM-DD-YY"),
|
||||
N_("YY-MM-DD"),
|
||||
)
|
||||
|
||||
STRINGIFY(led_state, LIBX52_LED_STATE_GREEN, N_("Unknown LED state %d")
|
||||
N_("off"),
|
||||
N_("on"),
|
||||
N_("red"),
|
||||
N_("amber"),
|
||||
N_("green"),
|
||||
)
|
||||
|
||||
const char * libx52_str_led_id(libx52_led_id id)
|
||||
{
|
||||
static char invalid[256];
|
||||
|
||||
switch (id) {
|
||||
case LIBX52_LED_FIRE:
|
||||
return _("Fire");
|
||||
|
||||
case LIBX52_LED_A:
|
||||
return _("A");
|
||||
|
||||
case LIBX52_LED_B:
|
||||
return _("B");
|
||||
|
||||
case LIBX52_LED_D:
|
||||
return _("D");
|
||||
|
||||
case LIBX52_LED_E:
|
||||
return _("E");
|
||||
|
||||
case LIBX52_LED_T1:
|
||||
return _("T1");
|
||||
|
||||
case LIBX52_LED_T2:
|
||||
return _("T2");
|
||||
|
||||
case LIBX52_LED_T3:
|
||||
return _("T3");
|
||||
|
||||
case LIBX52_LED_POV:
|
||||
return _("POV");
|
||||
|
||||
case LIBX52_LED_CLUTCH:
|
||||
return _("Clutch");
|
||||
|
||||
case LIBX52_LED_THROTTLE:
|
||||
return _("Throttle");
|
||||
|
||||
default:
|
||||
snprintf(invalid, sizeof(invalid), _("Unknown LED ID %d"), id);
|
||||
return invalid;
|
||||
}
|
||||
}
|
|
@ -1,5 +1,6 @@
|
|||
# List of source files which contain translatable strings.
|
||||
lib/libx52/x52_strerror.c
|
||||
lib/libx52/x52_stringify.c
|
||||
|
||||
lib/libx52io/io_strings.c
|
||||
|
||||
|
|
|
@ -8,7 +8,7 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
||||
"POT-Creation-Date: 2021-07-27 01:34-0700\n"
|
||||
"POT-Creation-Date: 2021-07-27 01:56-0700\n"
|
||||
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
|
||||
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
|
||||
"Language-Team: LANGUAGE <LL@li.org>\n"
|
||||
|
@ -90,6 +90,127 @@ msgstr ""
|
|||
msgid "Unknown error %d"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:29
|
||||
#, c-format
|
||||
msgid "Unknown clock ID %d"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:30
|
||||
msgid "primary"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:31
|
||||
msgid "secondary"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:32
|
||||
msgid "tertiary"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:35
|
||||
#, c-format
|
||||
msgid "Unknown clock format %d"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:36 daemon/x52d_clock.c:124
|
||||
msgid "12 hour"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:37 daemon/x52d_clock.c:124
|
||||
msgid "24 hour"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:40
|
||||
#, c-format
|
||||
msgid "Unknown date format %d"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:41
|
||||
msgid "DD-MM-YY"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:42
|
||||
msgid "MM-DD-YY"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:43
|
||||
msgid "YY-MM-DD"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:46
|
||||
#, c-format
|
||||
msgid "Unknown LED state %d"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:47 daemon/x52d_clock.c:28
|
||||
msgid "off"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:48 daemon/x52d_clock.c:28
|
||||
msgid "on"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:49
|
||||
msgid "red"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:50
|
||||
msgid "amber"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:51
|
||||
msgid "green"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:60
|
||||
msgid "Fire"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:63
|
||||
msgid "A"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:66
|
||||
msgid "B"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:69
|
||||
msgid "D"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:72
|
||||
msgid "E"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:75
|
||||
msgid "T1"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:78
|
||||
msgid "T2"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:81
|
||||
msgid "T3"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:84
|
||||
msgid "POV"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:87
|
||||
msgid "Clutch"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:90
|
||||
msgid "Throttle"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52/x52_stringify.c:93
|
||||
#, c-format
|
||||
msgid "Unknown LED ID %d"
|
||||
msgstr ""
|
||||
|
||||
#: lib/libx52io/io_strings.c:103
|
||||
msgid "No device"
|
||||
msgstr ""
|
||||
|
@ -436,14 +557,6 @@ msgstr ""
|
|||
msgid "Setting clock enable to %s"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_clock.c:28
|
||||
msgid "on"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_clock.c:28
|
||||
msgid "off"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_clock.c:34
|
||||
#, c-format
|
||||
msgid "Setting primary clock timezone to %s"
|
||||
|
@ -475,14 +588,6 @@ msgstr ""
|
|||
msgid "Setting %s clock format to %s"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_clock.c:124
|
||||
msgid "12 hour"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_clock.c:124
|
||||
msgid "24 hour"
|
||||
msgstr ""
|
||||
|
||||
#: daemon/x52d_clock.c:150
|
||||
#, c-format
|
||||
msgid "Setting date format to %s"
|
||||
|
|
141
po/xx_PL.po
141
po/xx_PL.po
|
@ -7,8 +7,8 @@ msgid ""
|
|||
msgstr ""
|
||||
"Project-Id-Version: x52pro-linux 0.2.1\n"
|
||||
"Report-Msgid-Bugs-To: https://github.com/nirenjan/x52pro-linux/issues\n"
|
||||
"POT-Creation-Date: 2021-07-27 01:34-0700\n"
|
||||
"PO-Revision-Date: 2021-07-26 11:00-0700\n"
|
||||
"POT-Creation-Date: 2021-07-27 01:56-0700\n"
|
||||
"PO-Revision-Date: 2021-07-27 01:59-0700\n"
|
||||
"Last-Translator: Nirenjan Krishnan <nirenjan@gmail.com>\n"
|
||||
"Language-Team: Dummy Language for testing i18n\n"
|
||||
"Language: xx_PL\n"
|
||||
|
@ -90,6 +90,127 @@ msgstr "Ystemsay allcay interrupteday"
|
|||
msgid "Unknown error %d"
|
||||
msgstr "Unknownay erroray %d"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:29
|
||||
#, c-format
|
||||
msgid "Unknown clock ID %d"
|
||||
msgstr "Unknownay ockclay IDay %d"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:30
|
||||
msgid "primary"
|
||||
msgstr "imarypray"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:31
|
||||
msgid "secondary"
|
||||
msgstr "econdarysay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:32
|
||||
msgid "tertiary"
|
||||
msgstr "ertiarytay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:35
|
||||
#, c-format
|
||||
msgid "Unknown clock format %d"
|
||||
msgstr "Unknownay ockclay ormatfay %d"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:36 daemon/x52d_clock.c:124
|
||||
msgid "12 hour"
|
||||
msgstr "12 ourhay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:37 daemon/x52d_clock.c:124
|
||||
msgid "24 hour"
|
||||
msgstr "24 ourhay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:40
|
||||
#, c-format
|
||||
msgid "Unknown date format %d"
|
||||
msgstr "Unknownay ateday ormatfay %d"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:41
|
||||
msgid "DD-MM-YY"
|
||||
msgstr "DDay-MMay-YYay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:42
|
||||
msgid "MM-DD-YY"
|
||||
msgstr "MMay-DDay-YYay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:43
|
||||
msgid "YY-MM-DD"
|
||||
msgstr "YYay-MMay-DDay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:46
|
||||
#, c-format
|
||||
msgid "Unknown LED state %d"
|
||||
msgstr "Unknownay EDLay atestay %d"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:47 daemon/x52d_clock.c:28
|
||||
msgid "off"
|
||||
msgstr "offay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:48 daemon/x52d_clock.c:28
|
||||
msgid "on"
|
||||
msgstr "onay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:49
|
||||
msgid "red"
|
||||
msgstr "edray"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:50
|
||||
msgid "amber"
|
||||
msgstr "amberay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:51
|
||||
msgid "green"
|
||||
msgstr "eengray"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:60
|
||||
msgid "Fire"
|
||||
msgstr "Irefay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:63
|
||||
msgid "A"
|
||||
msgstr "Ay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:66
|
||||
msgid "B"
|
||||
msgstr "Bay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:69
|
||||
msgid "D"
|
||||
msgstr "Day"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:72
|
||||
msgid "E"
|
||||
msgstr "Eay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:75
|
||||
msgid "T1"
|
||||
msgstr "Tay1"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:78
|
||||
msgid "T2"
|
||||
msgstr "Tay2"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:81
|
||||
msgid "T3"
|
||||
msgstr "Tay3"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:84
|
||||
msgid "POV"
|
||||
msgstr "OVPay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:87
|
||||
msgid "Clutch"
|
||||
msgstr "Utchclay"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:90
|
||||
msgid "Throttle"
|
||||
msgstr "Ottlethray"
|
||||
|
||||
#: lib/libx52/x52_stringify.c:93
|
||||
#, c-format
|
||||
msgid "Unknown LED ID %d"
|
||||
msgstr "Unknownay EDLay IDay %d"
|
||||
|
||||
#: lib/libx52io/io_strings.c:103
|
||||
msgid "No device"
|
||||
msgstr "Onay eviceday"
|
||||
|
@ -481,14 +602,6 @@ msgstr "Uttingshay ownday X52 aemonday"
|
|||
msgid "Setting clock enable to %s"
|
||||
msgstr "Ettingsay ockclay enableay otay %s"
|
||||
|
||||
#: daemon/x52d_clock.c:28
|
||||
msgid "on"
|
||||
msgstr "onay"
|
||||
|
||||
#: daemon/x52d_clock.c:28
|
||||
msgid "off"
|
||||
msgstr "offay"
|
||||
|
||||
#: daemon/x52d_clock.c:34
|
||||
#, c-format
|
||||
msgid "Setting primary clock timezone to %s"
|
||||
|
@ -523,14 +636,6 @@ msgstr "Ettingsay ertiarytay ockclay imezonetay otay %s"
|
|||
msgid "Setting %s clock format to %s"
|
||||
msgstr "Ettingsay %s ockclay ormatfay otay %s"
|
||||
|
||||
#: daemon/x52d_clock.c:124
|
||||
msgid "12 hour"
|
||||
msgstr "12 ourhay"
|
||||
|
||||
#: daemon/x52d_clock.c:124
|
||||
msgid "24 hour"
|
||||
msgstr "24 ourhay"
|
||||
|
||||
#: daemon/x52d_clock.c:150
|
||||
#, c-format
|
||||
msgid "Setting date format to %s"
|
||||
|
|
Loading…
Reference in New Issue