Beispiel #1
0
static int list_devices(void)
{
	struct vector v;

	vector_init(&v, sizeof(const char *));
	if (fet_db_enum(add_fet_device, &v) < 0) {
		pr_error("couldn't allocate memory");
		vector_destroy(&v);
		return -1;
	}

	printc("Devices supported by FET driver:\n");
	namelist_print(&v);
	vector_destroy(&v);

	vector_init(&v, sizeof(const char *));
	if (fet_olimex_db_enum(add_fet_olimex_device, &v) < 0) {
		pr_error("couldn't allocate memory");
		vector_destroy(&v);
		return -1;
	}

	printc("\n");
	printc("Devices supported by Olimex FET driver:\n");
	namelist_print(&v);
	vector_destroy(&v);

	return 0;
}
Beispiel #2
0
int cmd_help(char **arg)
{
	const char *topic = get_arg(arg);

	if (topic) {
		struct cmddb_record cmd;
		struct opdb_key key;

		if (!cmddb_get(topic, &cmd)) {
			printc("\x1b[1mCOMMAND: %s\x1b[0m\n\n%s\n",
			       cmd.name, cmd.help);
			return 0;
		}

		if (!opdb_get(topic, &key, NULL)) {
			printc("\x1b[1mOPTION: %s (%s)\x1b[0m\n\n%s\n",
			       key.name, type_text(key.type), key.help);
			return 0;
		}

		printc_err("help: unknown command: %s\n", topic);
		return -1;
	} else {
		struct vector v;

		vector_init(&v, sizeof(const char *));

		if (!cmddb_enum(push_command_name, &v)) {
			printc("Available commands:\n");
			namelist_print(&v);
			printc("\n");
		} else {
			pr_error("help: can't allocate memory for command list");
		}

		vector_realloc(&v, 0);

		if (!opdb_enum(push_option_name, &v)) {
			printc("Available options:\n");
			namelist_print(&v);
			printc("\n");
		} else {
			pr_error("help: can't allocate memory for option list");
		}

		vector_destroy(&v);

		printc("Type \"help <topic>\" for more information.\n");
		printc("Use the \"opt\" command (\"help opt\") to set "
			"options.\n");
#if defined(__Windows__) && !defined(USE_READLINE)
		printc("Press Ctrl+Z, Enter to quit.\n");
#else
		printc("Press Ctrl+D to quit.\n");
#endif
	}

	return 0;
}
Beispiel #3
0
int main(int argc, char *argv[]) {
	struct namelist *list;
	struct namelist_node *node;

	list = namelist_new();

	node = namelist_node_new("testing1", "*****@*****.**");
	namelist_add(list, node);

	node = namelist_node_new("testing2", "*****@*****.**");
	namelist_add(list, node);

	node = namelist_node_new("testing3", "*****@*****.**");
	namelist_add(list, node);

	namelist_print(list);

	return 0;
}