Exemplo n.º 1
0
Arquivo: complete.c Projeto: danrl/nsh
unsigned char
complete_args(struct ghs *c, char *word, int dolist, EditLine *el, char **table,
    int stlen, int level)
{
#ifdef CMPLDEBUG
	printf("[%s]",&c->complete[level]);
#endif
	switch (c->complete[level]) {
	case 'l':	/* local complete */
	case 'L':
		return (complete_local(word, dolist, el));
	case 'c':	/* command complete */
	case 'C':
		return (complete_command(word, dolist, el, table, stlen));
	case 'i':
	case 'I':
		return (complete_ifname(word, dolist, el));
	case 't':	/* points to a table */
	case 'T':
		if (c->table == NULL)
			return(CC_ERROR);
		return (complete_command(word, dolist, el, c->table, c->stlen));
	case 'a':
	case 'A':
		if (c->table == NULL)
			return(CC_ERROR);
		return (complete_subcommand(word, dolist, el, c->table, c->stlen));
	case 'n':			/* no complete */
		return (CC_ERROR);
	}

	return (CC_ERROR);
}
Exemplo n.º 2
0
/* ARGSUSED */
static
CPL_MATCH_FN(complete)
{
	const char *arg0, *arg1;
	size_t arg0len;
	struct cmd_info *cip;

	arg0 = line + strspn(line, whitespace);
	arg0len = strcspn(arg0, whitespace);
	if ((arg0 + arg0len) - line >= word_end ||
	    (arg0[arg0len] != ' ' && arg0[arg0len] != '\t'))
		return (complete_command(cpl, (void *)arg0, line, word_end));

	arg1 = arg0 + arg0len;
	arg1 += strspn(arg1, whitespace);

	for (cip = cmds; cip->name != NULL; ++cip) {
		if (strlen(cip->name) != arg0len)
			continue;

		if (strncmp(cip->name, arg0, arg0len) != 0)
			continue;

		if (cip->complete_args_f == NULL)
			break;

		return (cip->complete_args_f(cpl, (void *)arg1, line,
		    word_end));
	}

	return (0);
}
Exemplo n.º 3
0
Arquivo: complete.c Projeto: danrl/nsh
/*
 * Generic complete routine
 */
unsigned char
complete(EditLine *el, int ch, char **table, size_t stlen, char *arg)
{
	static char word[256];
	static int lastc_argc, lastc_argo;
	struct ghs *c;
	const LineInfo *lf;
	int celems, dolist;
	size_t len;

	ch = ch;		/* not used */
	lf = el_line(el);
	len = lf->lastchar - lf->buffer;
	if (len >= sizeof(line))
		return (CC_ERROR);
	(void)memcpy(line, lf->buffer, len);
	line[len] = '\0';
	cursor_pos = line + (lf->cursor - lf->buffer);
	lastc_argc = cursor_argc;	/* remember last cursor pos */
	lastc_argo = cursor_argo;
	makeargv();			/* build argc/argv of current line */

	if (cursor_argo >= sizeof(word))
		return (CC_ERROR);

	dolist = 0;

	/* if cursor and word is same, list alternatives */
	if (lastc_argc == cursor_argc && lastc_argo == cursor_argo
	    && strncmp(word, margv[cursor_argc], cursor_argo) == 0)
		dolist = 1;
	else if (cursor_argo)
		memcpy(word, margv[cursor_argc], cursor_argo);
	word[cursor_argo] = '\0';

	if (cursor_argc == 0)
		return (complete_command(word, dolist, el, table, stlen));

	if (arg == NULL)
		arg = margv[0];
	c = (struct ghs *) genget(arg, table, stlen);
	if (c == (struct ghs *)-1 || c == 0 || Ambiguous(c))
		return (CC_ERROR);
	celems = strlen(c->complete);

	/* check for 'continuation' completes (which are uppercase) */
	if ((cursor_argc > celems) && (celems > 0)
	    && isupper(c->complete[celems-1]))
		cursor_argc = celems;

	if (cursor_argc > celems)
		return (CC_ERROR);

	return(complete_args(c, word, dolist, el, table, stlen,
	    cursor_argc - 1));
}
Exemplo n.º 4
0
/*
 * Generic complete routine
 */
unsigned char
complete(EditLine *el, int ch)
{
	static char word[FTPBUFLEN];
	static int lastc_argc, lastc_argo;
	const struct cmd *c;
	const LineInfo *lf;
	int celems, dolist;
	size_t len;

	ch = ch;		/* not used */
	lf = el_line(el);
	len = lf->lastchar - lf->buffer;
	if (len >= sizeof(line))
		return (CC_ERROR);
	(void)memcpy(line, lf->buffer, len);
	line[len] = '\0';
	cursor_pos = line + (lf->cursor - lf->buffer);
	lastc_argc = cursor_argc;	/* remember last cursor pos */
	lastc_argo = cursor_argo;
	makeargv();			/* build argc/argv of current line */

	if (cursor_argo >= sizeof(word))
		return (CC_ERROR);

	dolist = 0;
			/* if cursor and word is same, list alternatives */
	if (lastc_argc == cursor_argc && lastc_argo == cursor_argo
	    && strncmp(word, margv[cursor_argc], cursor_argo) == 0)
		dolist = 1;
	else if (cursor_argo)
		memcpy(word, margv[cursor_argc], cursor_argo);
	word[cursor_argo] = '\0';

	if (cursor_argc == 0)
		return (complete_command(word, dolist));

	c = getcmd(margv[0]);
	if (c == (struct cmd *)-1 || c == 0)
		return (CC_ERROR);
	celems = strlen(c->c_complete);

		/* check for 'continuation' completes (which are uppercase) */
	if ((cursor_argc > celems) && (celems > 0)
	    && isupper(c->c_complete[celems-1]))
		cursor_argc = celems;

	if (cursor_argc > celems)
		return (CC_ERROR);

	switch (c->c_complete[cursor_argc - 1]) {
	case 'l':			/* local complete */
	case 'L':
		return (complete_local(word, dolist));
	case 'r':			/* remote complete */
	case 'R':
		if (connected != -1) {
			fputs("\nMust be logged in to complete.\n", ttyout);
			return (CC_REDISPLAY);
		}
		return (complete_remote(word, dolist));
	case 'c':			/* command complete */
	case 'C':
		return (complete_command(word, dolist));
	case 'n':			/* no complete */
		return (CC_ERROR);
	}

	return (CC_ERROR);
}
Exemplo n.º 5
0
/*
 * Generic complete routine
 */
unsigned char
complete(EditLine *cel, int ch)
{
	static char word[FTPBUFLEN];
	static size_t lastc_argc, lastc_argo;

	struct cmd *c;
	const LineInfo *lf;
	int dolist, cmpltype;
	size_t celems, len;

	lf = el_line(cel);
	len = lf->lastchar - lf->buffer;
	if (len >= sizeof(line))
		return (CC_ERROR);
	(void)strlcpy(line, lf->buffer, len + 1);
	cursor_pos = line + (lf->cursor - lf->buffer);
	lastc_argc = cursor_argc;	/* remember last cursor pos */
	lastc_argo = cursor_argo;
	makeargv();			/* build argc/argv of current line */

	if (cursor_argo >= sizeof(word))
		return (CC_ERROR);

	dolist = 0;
			/* if cursor and word is same, list alternatives */
	if (lastc_argc == cursor_argc && lastc_argo == cursor_argo
	    && strncmp(word, margv[cursor_argc] ? margv[cursor_argc] : "",
			cursor_argo) == 0)
		dolist = 1;
	else if (cursor_argc < (size_t)margc)
		(void)strlcpy(word, margv[cursor_argc], cursor_argo + 1);
	word[cursor_argo] = '\0';

	if (cursor_argc == 0)
		return (complete_command(word, dolist));

	c = getcmd(margv[0]);
	if (c == (struct cmd *)-1 || c == 0)
		return (CC_ERROR);
	celems = strlen(c->c_complete);

		/* check for 'continuation' completes (which are uppercase) */
	if ((cursor_argc > celems) && (celems > 0)
	    && isupper((unsigned char) c->c_complete[celems-1]))
		cursor_argc = celems;

	if (cursor_argc > celems)
		return (CC_ERROR);

	cmpltype = c->c_complete[cursor_argc - 1];
	switch (cmpltype) {
		case 'c':			/* command complete */
		case 'C':
			return (complete_command(word, dolist));
		case 'l':			/* local complete */
		case 'L':
			return (complete_local(word, dolist));
		case 'n':			/* no complete */
		case 'N':			/* no complete */
			return (CC_ERROR);
		case 'o':			/* local complete */
		case 'O':
			return (complete_option(word, dolist));
		case 'r':			/* remote complete */
		case 'R':
			if (connected != -1) {
				fputs("\nMust be logged in to complete.\n",
				    ttyout);
				return (CC_REDISPLAY);
			}
			return (complete_remote(word, dolist));
		default:
			errx(1, "complete: unknown complete type `%c'",
			    cmpltype);
			return (CC_ERROR);
	}
	/* NOTREACHED */
}
Exemplo n.º 6
0
/*
 * A generic complete routine for the mail command line.
 */
static unsigned char
mail_complete(EditLine *el, int ch)
{
	LineInfo *li;
	const LineInfo *lf;
	const char *cmplarray;
	int dolist;
	int cmpltype;
	char *word;

	lf = el_line(el);

#ifdef EMACS_CTRL_D_BINDING_HACK
	{
		int cc_ret;
		if ((cc_ret = emacs_ctrl_d(el, lf, ch)) != -1)
			return cc_ret;
	}
#endif /* EMACS_CTRL_D_BINDING_HACK */

	if ((dolist = get_dolist(lf)) == -1)
		return CC_ERROR;

	if ((li = split_line(&cmplarray, lf)) == NULL)
		return CC_ERROR;

	if ((word = split_word(&cmpltype, cmplarray, li)) == NULL)
		return CC_ERROR;

	switch (cmpltype) {
	case 'a':			/* alias complete */
	case 'A':
		return complete_alias(el, word, dolist);

	case 'c':			/* command complete */
	case 'C':
		return complete_command(el, word, dolist);

	case 'f':			/* filename complete */
	case 'F':
		return complete_filename(el, word, dolist);

	case 'm':
	case 'M':
		return complete_smopts(el, word, dolist);

	case 'n':			/* no complete */
	case 'N':			/* no complete */
		return CC_ERROR;

	case 's':
	case 'S':
		return complete_set(el, word, dolist);
#ifdef THREAD_SUPPORT
	case 't':
	case 'T':
		return complete_thread_key(el, word, dolist);
#endif
		case 'x':			/* executable complete */
	case 'X':
		return complete_executable(el, word, dolist);

	default:
		warnx("unknown complete type `%c'", cmpltype);
#if 0
		assert(/*CONSTCOND*/0);
#endif
		return CC_ERROR;
	}
	/* NOTREACHED */
}
Exemplo n.º 7
0
int
ng_hci_process_command_complete(ng_hci_unit_p unit, struct mbuf *e)
{
	ng_hci_command_compl_ep		*ep = NULL;
	struct mbuf			*cp = NULL;
	int				 error = 0;

	/* Get event packet and update command buffer info */
	NG_HCI_M_PULLUP(e, sizeof(*ep));
	if (e == NULL)
		return (ENOBUFS); /* XXX this is bad */

	ep = mtod(e, ng_hci_command_compl_ep *);
        NG_HCI_BUFF_CMD_SET(unit->buffer, ep->num_cmd_pkts);

	/* Check for special NOOP command */
	if (ep->opcode == 0x0000) {
		NG_FREE_M(e);
		goto out;
	}

	/* Try to match first command item in the queue */
	error = complete_command(unit, ep->opcode, &cp);
	if (error != 0) {
		NG_FREE_M(e);
		goto out;
	}

	/* 
	 * Perform post processing on command parameters and return parameters
	 * do it only if status is OK (status == 0). Status is the first byte
	 * of any command return parameters.
	 */

	ep->opcode = le16toh(ep->opcode);
	m_adj(e, sizeof(*ep));

	if (*mtod(e, u_int8_t *) == 0) { /* XXX m_pullup here? */
		switch (NG_HCI_OGF(ep->opcode)) {
		case NG_HCI_OGF_LINK_CONTROL:
			error = process_link_control_params(unit,
					NG_HCI_OCF(ep->opcode), cp, e);
			break;

		case NG_HCI_OGF_LINK_POLICY:
			error = process_link_policy_params(unit,
					NG_HCI_OCF(ep->opcode), cp, e);
			break;

		case NG_HCI_OGF_HC_BASEBAND:
			error = process_hc_baseband_params(unit,
					NG_HCI_OCF(ep->opcode), cp, e);
			break;

		case NG_HCI_OGF_INFO:
			error = process_info_params(unit,
					NG_HCI_OCF(ep->opcode), cp, e);
			break;

		case NG_HCI_OGF_STATUS:
			error = process_status_params(unit,
					NG_HCI_OCF(ep->opcode), cp, e);
			break;

		case NG_HCI_OGF_TESTING:
			error = process_testing_params(unit,
					NG_HCI_OCF(ep->opcode), cp, e);
			break;

		case NG_HCI_OGF_BT_LOGO:
		case NG_HCI_OGF_VENDOR:
			NG_FREE_M(cp);
			NG_FREE_M(e);
			break;

		default:
			NG_FREE_M(cp);
			NG_FREE_M(e);
			error = EINVAL;
			break;
		}
	} else {