Ejemplo n.º 1
0
extern char *
cfuopt_get_help_str(cfuopt_t *context) {
	cfulist_t *desc_list = NULL;
	size_t max_width = 0;
	char *fmt = NULL;
	_help_lines_ds ds;
	char *help_str = NULL;

	max_width = _find_longest_help_desc(context, &desc_list);
	
	fmt = cfustring_sprintf_c_str(" %%-%us  %%s\n", max_width);
	ds.fmt = fmt;
	ds.list = cfulist_new();
	ds.desc_list = desc_list;

	cfulist_foreach(desc_list, _get_help_lines, (void *)&ds);

	help_str = cfulist_join(ds.list, "\n");

	cfulist_destroy_with_free_fn(ds.list, _list_simple_free_fn);
	cfulist_destroy_with_free_fn(desc_list, _desc_list_free);
	free(fmt);

	return help_str;
}
Ejemplo n.º 2
0
void
cfulist_destroy(cfulist_t *list) {
	if (!list) return;

	if (list->free_fn) {
		cfulist_destroy_with_free_fn(list, list->free_fn);
		return;
	}

	lock_list(list);
	if (list->entries) {
		cfulist_entry *entry = NULL;
		cfulist_entry *tmp = NULL;
		entry = list->entries;
		while (entry) {
			tmp = entry->next;
			free(entry);
			entry = tmp;
		}
	}
	unlock_list(list);
#ifdef HAVE_PTHREAD_H
	pthread_mutex_destroy(&list->mutex);
#endif
	free(list);
}
Ejemplo n.º 3
0
static int
_find_foreach_fn(void *data, size_t data_size, void *arg) {
	cfuopt_list_entry_t *opt = (cfuopt_list_entry_t *)data;
	_find_foreach_ds *ds = (_find_foreach_ds *)arg;
	size_t this_size = 0;
	cfulist_t *param_full_list = NULL;
	char *desc = NULL;
	_cfuopt_desc *desc_ds = CFU_OPT_ALLOC(_cfuopt_desc, 1);

	if (!data) return 0;

	param_full_list = cfulist_map(opt->param_names, _param_map_fn, opt);
	desc = cfulist_join(param_full_list, ", ");

	data_size = data_size;
	
	cfulist_destroy_with_free_fn(param_full_list, _simple_list_free_fn);

	desc_ds->desc = desc;
	desc_ds->entry = opt;
	cfulist_push(ds->desc_list, desc_ds);

	this_size = strlen(desc);
	if (this_size > ds->max_size) ds->max_size = this_size;

	return 0;
}
Ejemplo n.º 4
0
extern void
cfuopt_destroy(cfuopt_t *context) {
	if (!context) return;
	cfulist_destroy_with_free_fn(context->option_list, _opt_list_free_fn);
	cfuhash_destroy(context->option_map);
	cfulist_destroy(context->extra);
	free(context->progname);
	free(context);
}
Ejemplo n.º 5
0
static void
_opt_list_free_fn(void *data) {
	cfuopt_list_entry_t *entry = (cfuopt_list_entry_t *)data;
	cfulist_destroy_with_free_fn(entry->param_names, _simple_list_free_fn);
	free(data);
}