From 9279dbb2741de7bc599699a95728b1b7c2b6790a Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 10 Sep 2021 17:33:40 +0200 Subject: m + add card2ord MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- card2ord.c | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 card2ord.c (limited to 'card2ord.c') diff --git a/card2ord.c b/card2ord.c new file mode 100644 index 0000000..632e6a1 --- /dev/null +++ b/card2ord.c @@ -0,0 +1,79 @@ +/* See LICENSE file for copyright and license details. */ +#define LIBSIMPLY_CONFIG_MULTICALL_BINARY +#include "common.h" +#include + +USAGE("-l language [-o options ...] [cardinal ...]"); + + +static enum libnumtext_language lang; +static uint32_t flags = 0; + + +static struct option swedish_options[] = { + {"gender=c[ommon]|u|t", "gender=common", LIBNUMTEXT_C2O_SWEDISH_COMMON_GENDER, UINT32_C(0x00000003)}, + {NULL, "gender=c", LIBNUMTEXT_C2O_SWEDISH_COMMON_GENDER, UINT32_C(0x00000003)}, + {NULL, "gender=u", LIBNUMTEXT_C2O_SWEDISH_COMMON_GENDER, UINT32_C(0x00000003)}, + {NULL, "gender=t", LIBNUMTEXT_C2O_SWEDISH_COMMON_GENDER, UINT32_C(0x00000003)}, + {"gender=n[euter]", "gender=neuter", LIBNUMTEXT_C2O_SWEDISH_NEUTER_GENDER, UINT32_C(0x00000003)}, + {NULL, "gender=n", LIBNUMTEXT_C2O_SWEDISH_NEUTER_GENDER, UINT32_C(0x00000003)}, + {"gender=m[asculine]", "gender=masculine", LIBNUMTEXT_C2O_SWEDISH_MASCULINE_GENDER, UINT32_C(0x00000003)}, + {NULL, "gender=m", LIBNUMTEXT_C2O_SWEDISH_MASCULINE_GENDER, UINT32_C(0x00000003)}, + {"gender=f[eminine]", "gender=feminine", LIBNUMTEXT_C2O_SWEDISH_FEMININE_GENDER, UINT32_C(0x00000003)}, + {NULL, "gender=f", LIBNUMTEXT_C2O_SWEDISH_FEMININE_GENDER, UINT32_C(0x00000003)}, + {"case=l[ower]", "case=lower", LIBNUMTEXT_C2O_SWEDISH_LOWER_CASE, UINT32_C(0x00000004)}, + {NULL, "case=l", LIBNUMTEXT_C2O_SWEDISH_LOWER_CASE, UINT32_C(0x00000004)}, + {"case=u[pper]", "case=upper", LIBNUMTEXT_C2O_SWEDISH_UPPER_CASE, UINT32_C(0x00000004)}, + {NULL, "case=u", LIBNUMTEXT_C2O_SWEDISH_UPPER_CASE, UINT32_C(0x00000004)}, + {NULL, NULL, 0, 0} +}; + +static struct option *options[] = { + [LIBNUMTEXT_SWEDISH] = swedish_options +}; + + +static ssize_t +process(char *outbuf, size_t outbuf_size, const char *num, size_t num_len) +{ + ssize_t ret; + ret = libnumtext_card2ord(outbuf, outbuf_size, num, num_len, lang, flags); + if (ret < 0) + fprintf(stderr, "%s: libnumtext_card2ord %s: %s\n", argv0, num, strerror(errno)); + return ret; +} + + +int +card2ord_main(int argc, char *argv[]) +{ + int have_lang = 0; + char **optionses; + size_t n_optionses = 0; + + optionses = calloc((size_t)argc, sizeof(optionses)); + if (!optionses) { + fprintf(stderr, "%s: calloc %zu %zu: %s\n", argv0, (size_t)argc, sizeof(optionses), strerror(errno)); + return 1; + } + + ARGBEGIN { + case 'l': + if (!get_language(ARG(), &lang, &have_lang)) + usage(); + break; + case 'o': + optionses[n_optionses++] = ARG(); + break; + default: + usage(); + } ARGEND; + + if (!have_lang) + usage(); + + process_options(optionses, n_optionses, options[lang], &flags, NULL); + free(optionses); + + return run(argc, argv, process); +} -- cgit v1.2.3-70-g09d2