summaryrefslogtreecommitdiff
path: root/tests/extlang-db.c
blob: ba141da37942d6d78207811195780634ae9407c5 (plain)
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
/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
/* 
 * extlang.c
 * Copyright (C) 2011-2012 Akira TAGOH
 * 
 * Authors:
 *   Akira TAGOH  <akira@tagoh.org>
 * 
 * You may distribute under the terms of either the GNU
 * Lesser General Public License or the Mozilla Public
 * License, as specified in the README file.
 */
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

#include <stdio.h>
#include <locale.h>
#include "langtag.h"
#include "lt-utils.h"

int
main(int    argc,
     char **argv)
{
	lt_extlang_db_t *extlangdb;
	lt_extlang_t *extlang;

	setlocale(LC_ALL, "");

	lt_db_set_datadir(TEST_DATADIR);
	extlangdb = lt_extlang_db_new();

	if (lt_strcmp0(argv[1], "list_keys") == 0) {
		const char *key;
		lt_iter_t *iter;

		iter = LT_ITER_INIT (extlangdb);
		while (lt_iter_next(iter,
				    (lt_pointer_t *)&key,
				    NULL)) {
			printf("%s\n", key);
		}
		lt_iter_finish(iter);
	} else if (lt_strcmp0(argv[1], "list_values") == 0) {
		lt_iter_t *iter;

		iter = LT_ITER_INIT (extlangdb);
		while (lt_iter_next(iter,
				    NULL,
				    (lt_pointer_t *)&extlang)) {
			lt_extlang_dump(extlang);
		}
		lt_iter_finish(iter);
	} else if (lt_strcmp0(argv[1], "lookup") == 0) {
		extlang = lt_extlang_db_lookup(extlangdb, argv[2]);

		if (extlang) {
			printf("desc: %s\n", lt_extlang_get_name(extlang));
			printf("lang: %s\n", lt_extlang_get_macro_language(extlang));
			lt_extlang_unref(extlang);
		} else {
			printf("no such extlang: %s\n", argv[2]);
		}
	}

	lt_extlang_db_unref(extlangdb);

	return 0;
}