summaryrefslogtreecommitdiffstats
path: root/common.h
blob: e51652ec9acaaec824609cd05a25b1ecda707b79 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/* See LICENSE file for copyright and license details. */
#include "libnumtext.h"
#include <ctype.h>
#include <errno.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <unistd.h>


#if defined(__clang__)
# pragma clang diagnostic ignored "-Wcovered-switch-default"
# pragma clang diagnostic ignored "-Wpadded"
#endif


#if defined(__clang__)
# define FALL_THROUGH __attribute__((fallthrough));
#else
# define FALL_THROUGH
#endif

#if defined(__GNUC__)
# define PURE __attribute__((pure))
#else
# define PURE
#endif


#define UNICODE_MINUS "−" /* \xe2\x88\x92 */
#define UNICODE_NBSP  " " /* \xc2\xa0 */

#define IS_CHAR__(S, LEN, C) ((LEN) >= sizeof(C) - 1 && !memcmp((S), (C), sizeof(C) - 1))

#define IS_UNICODE_MINUS(S, LEN) IS_CHAR__(S, LEN, UNICODE_MINUS)
#define IS_UNICODE_NBSP(S, LEN)  IS_CHAR__(S, LEN, UNICODE_NBSP)

#define IS_UTF8_CHAR_CONTINUATION(B) (((B) & 0xC0) == 0x80)


struct common_num2text_params {
	char *outbuf;
	size_t outbuf_size;
	size_t sign_length;
	size_t number_offset;
	size_t trailing_zeroes;
};


struct option {
	const char *option_pattern;
	const char *option;
	uint32_t flag;
	uint32_t mask;
};


int run(int argc, char *argv[], ssize_t (*callback)(char *outbuf, size_t outbuf_size, const char *num, size_t num_len));
int get_language(const char *arg, enum libnumtext_language *langp, int *have_langp);
void process_options(char **optss, size_t n_optss, struct option *options, uint32_t *flagsp, uint32_t *maskedp);

int numtext_strip_main(int argc, char *argv[]);
int card2ord_main(int argc, char *argv[]);
int num2text_main(int argc, char *argv[]);


ssize_t libnumtext_num2text_swedish__(struct common_num2text_params *params, const char *num, size_t num_len, uint32_t flags);
ssize_t libnumtext_card2ord_swedish__(char *outbuf, size_t outbuf_size, const char *num, size_t num_len, uint32_t flags);