Exemple #1
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;
}
Exemple #2
0
Fichier : rc.c Projet : gamma62/eda
/*
** show_commands - show table of commands with keyboard shortcuts
*/
int
show_commands (void)
{
	int ret=1;
	LINE *lp=NULL;
	char circle_line[1024];
	char key_buff[90];
	char name_buff[30];
	int ti, ki, i, j, mi;

	/* open or reopen? */
	ret = scratch_buffer("*cmds*");
	if (ret) {
		return (ret);
	}
	/* cnf.ring_curr is set now -- CURR_FILE and CURR_LINE alive */
	if (CURR_FILE.num_lines > 0) {
		clean_buffer();
	}
	CURR_FILE.fflag |= FSTAT_SPECW;
	CURR_FILE.fflag &= ~FSTAT_NOEDIT;	/* temporary */

	ret = type_text("\n\
command name          function name         keyboard shortcut\n\
--------------------  --------------------  -------------------------\n");

	if (!ret) {

		CURR_LINE = CURR_FILE.bottom->prev;
		memset(circle_line, '\0', sizeof(circle_line));
		memset(name_buff, '\0', sizeof(name_buff));
		memset(key_buff, '\0', sizeof(key_buff));

		for (ti=0; ret == 0 && ti < TLEN; ti++) {

			if (table[ti].minlen == -1 && table[ti].fkey == -1) {
				/* only for macros */
				continue;
			}

			/* command name with mandatory or optional arguments */
			name_buff[0] = '\0';
			if (table[ti].minlen >= 1) {
				i = 0;
				for (j=0; i < 20 && table[ti].name[j] != '\0'; j++) {
					if (i == table[ti].minlen)
						name_buff[i++] = '.';
					name_buff[i++] = table[ti].name[j];
				}
				name_buff[i++] = '\0';
				if (table[ti].tflag & TSTAT_ARGS) {
					strncat(name_buff, ((table[ti].tflag & TSTAT_OPTARG) ? " [<arg>]" : " <arg>"), 10);
				}
			} else {
				strncpy(name_buff, "n/a", 10);
			}

			/* list of keys, pretty printing, space limitation */
			key_buff[0] = '\0';
			if (table[ti].fkey == -1) {
				strncpy(key_buff, "n/a", 10);
			} else {
				for (ki=0; ki < KLEN; ki++) {
					if (keys[ki].table_index == ti) {
						if (pretty_print_key_names(ki, key_buff, sizeof(key_buff)))
							break;
					}
				}
				if (key_buff[0] == '\0') {
					strncat(key_buff, "none", 10);
				}
			}

			snprintf(circle_line, sizeof(circle_line)-1, "%-20s  %-20s  %s\n",
				name_buff, table[ti].fullname, key_buff);

			ret = type_text(circle_line);
		}
	}

	if (!ret && macros) {

		ret = type_text("\n\
macro key             macro name\n\
--------------------  ----------------------------------------\n");

		for (mi=0; ret == 0 && mi < MLEN; mi++) {
			key_buff[0] = '\0';
			ki = index_key_value( macros[mi].fkey );
			if (ki >= 0 && ki < KLEN && ki != RES_KLEN) { // KEY_NONE index is RES_KLEN
				pretty_print_key_names(ki, key_buff, sizeof(key_buff));
			} else {
				strncpy(key_buff, "none", 10);
			}

			name_buff[0] = '\0';
			if (macros[mi].name[0] == '\0') {
				strncpy(name_buff, "n/a", 10);
			} else {
				strncpy(name_buff, macros[mi].name, 20);
				if (macros[mi].mflag & TSTAT_ARGS) {
					strncat(name_buff, ((macros[mi].mflag & TSTAT_OPTARG) ? " [<arg>]" : " <arg>"), 10);
				}
			}

			snprintf(circle_line, sizeof(circle_line)-1, "%-20s  %s\n",
				key_buff, name_buff);

			ret = type_text(circle_line);
		}
	}