Пример #1
0
void
iconvlist(int (*do_one) (unsigned int, const char * const *,
    void *), void *data)
{
	char **list, **names;
	const char * const *np;
	char *curitem, *curkey, *slashpos;
	size_t sz;
	unsigned int i, j;

	i = 0;

	if (__iconv_get_list(&list, &sz, true))
		list = NULL;
	qsort((void *)list, sz, sizeof(char *), qsort_helper);
	while (i < sz) {
		j = 0;
		slashpos = strchr(list[i], '/');
		curkey = (char *)malloc(slashpos - list[i] + 2);
		names = (char **)malloc(sz * sizeof(char *));
		if ((curkey == NULL) || (names == NULL)) {
			__iconv_free_list(list, sz);
			return;
		}
		strlcpy(curkey, list[i], slashpos - list[i] + 1);
		names[j++] = curkey;
		for (; (i < sz) && (memcmp(curkey, list[i], strlen(curkey)) == 0); i++) {
			slashpos = strchr(list[i], '/');
			curitem = (char *)malloc(strlen(slashpos) + 1);
			if (curitem == NULL) {
				__iconv_free_list(list, sz);
				return;
			}
			strlcpy(curitem, &slashpos[1], strlen(slashpos) + 1);
			if (strcmp(curkey, curitem) == 0) {
				continue;
			}
			names[j++] = curitem;
		}
		np = (const char * const *)names;
		do_one(j, np, data);
		free(names);
	}

	__iconv_free_list(list, sz);
}
Пример #2
0
static void
show_codesets(void)
{
	char **list;
	size_t sz, i;

	if (__iconv_get_list(&list, &sz))
		err(EXIT_FAILURE, "__iconv_get_list()");

	qsort(list, sz, sizeof(char *), scmp);

	for (i=0; i<sz; i++) {
		printf("%s\n", list[i]);
	}

	__iconv_free_list(list, sz);
}