summaryrefslogtreecommitdiffstats
path: root/numtext-strip.c
blob: 85719af3d0921b6e75a1ac05fbb6811207879b00 (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
/* See LICENSE file for copyright and license details. */
#define LIBSIMPLY_CONFIG_MULTICALL_BINARY
#include "common.h"
#include <libsimple-arg.h>

USAGE("-l language [number ...]");


static enum libnumtext_language lang;


static ssize_t
process(char *outbuf, size_t outbuf_size, const char *num, size_t num_len)
{
	ssize_t ret;
	ret = libnumtext_remove_separators(outbuf, outbuf_size, num, num_len, lang);
	if (ret < 0) {
		fprintf(stderr, "%s: libnumtext_remove_separators %s: %s\n", argv0, num, strerror(errno));
	} else {
		if ((size_t)ret < outbuf_size)
			outbuf[ret] = '\0';
		ret += 1;
	}
	return ret;
}


int
numtext_strip_main(int argc, char *argv[])
{
	int have_lang = 0;

	ARGBEGIN {
	case 'l':
		if (!get_language(ARG(), &lang, &have_lang))
			usage();
		break;
	default:
		usage();
	} ARGEND;

	if (!have_lang)
		usage();

	return run(argc, argv, process);
}