2015-07-01 19:25:47 +00:00
|
|
|
#include "taxonomy.h"
|
|
|
|
#include "gettext.h"
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
2015-07-02 17:21:35 +00:00
|
|
|
char *taxonomy_category_names[TC_NR_CATEGORIES] = {
|
2015-07-01 19:25:47 +00:00
|
|
|
QT_TRANSLATE_NOOP("getTextFromC", "None"),
|
|
|
|
QT_TRANSLATE_NOOP("getTextFromC", "Ocean"),
|
|
|
|
QT_TRANSLATE_NOOP("getTextFromC", "Country"),
|
|
|
|
QT_TRANSLATE_NOOP("getTextFromC", "State"),
|
|
|
|
QT_TRANSLATE_NOOP("getTextFromC", "County"),
|
2015-07-10 16:51:50 +00:00
|
|
|
QT_TRANSLATE_NOOP("getTextFromC", "Town"),
|
2015-07-01 19:25:47 +00:00
|
|
|
QT_TRANSLATE_NOOP("getTextFromC", "City")
|
|
|
|
};
|
|
|
|
|
|
|
|
// these are the names for geoname.org
|
2015-07-02 17:21:35 +00:00
|
|
|
char *taxonomy_api_names[TC_NR_CATEGORIES] = {
|
2015-07-01 19:25:47 +00:00
|
|
|
"none",
|
|
|
|
"name",
|
|
|
|
"countryName",
|
|
|
|
"adminName1",
|
|
|
|
"adminName2",
|
2015-07-10 16:51:50 +00:00
|
|
|
"toponymName",
|
|
|
|
"adminName3"
|
2015-07-01 19:25:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct taxonomy *alloc_taxonomy()
|
|
|
|
{
|
2015-07-02 17:21:35 +00:00
|
|
|
return calloc(TC_NR_CATEGORIES, sizeof(struct taxonomy));
|
2015-07-01 19:25:47 +00:00
|
|
|
}
|
|
|
|
|
2015-07-13 14:09:55 +00:00
|
|
|
void free_taxonomy(struct taxonomy_data *t)
|
2015-07-01 19:25:47 +00:00
|
|
|
{
|
|
|
|
if (t) {
|
2015-07-13 14:09:55 +00:00
|
|
|
for (int i = 0; i < t->nr; i++)
|
|
|
|
free((void *)t->category[i].value);
|
|
|
|
free(t->category);
|
|
|
|
t->category = NULL;
|
|
|
|
t->nr = 0;
|
2015-07-01 19:25:47 +00:00
|
|
|
}
|
|
|
|
}
|
2015-07-13 22:18:52 +00:00
|
|
|
|
|
|
|
int taxonomy_index_for_category(struct taxonomy_data *t, enum taxonomy_category cat)
|
|
|
|
{
|
|
|
|
for (int i = 0; i < t->nr; i++)
|
|
|
|
if (t->category[i].category == cat)
|
|
|
|
return i;
|
|
|
|
return -1;
|
|
|
|
}
|