예제 #1
0
파일: plugin.c 프로젝트: abehterev/klish
/*--------------------------------------------------------- */
clish_sym_t *clish_sym_new(const char *name, void *func, int type)
{
	clish_sym_t *this;

	this = malloc(sizeof(*this));
	this->name = lub_string_dup(name);
	this->func = func;
	this->type = type;
	this->permanent = BOOL_FALSE;

	return this;
}
예제 #2
0
파일: string.c 프로젝트: nawawi/klish
/*
 * This needs to escape any dangerous characters within the command line
 * to prevent gaining access to the underlying system shell.
 */
char *lub_string_encode(const char *string, const char *escape_chars)
{
	char *result = NULL;
	const char *p;

	if (!escape_chars)
		return lub_string_dup(string);
	if (string && !(*string)) /* Empty string */
		return lub_string_dup(string);

	for (p = string; p && *p; p++) {
		/* find any special characters and prefix them with '\' */
		size_t len = strcspn(p, escape_chars);
		lub_string_catn(&result, p, len);
		p += len;
		if (*p) {
			lub_string_catn(&result, "\\", 1);
			lub_string_catn(&result, p, 1);
		} else {
			break;
		}
	}
	return result;
}
예제 #3
0
파일: view.c 프로젝트: rixrix/zafu
{
    const clish_view_t *this = clientnode;

    /* fill out the opaque key */
    strcpy((char *)key,this->name);
}
/*---------------------------------------------------------
 * PRIVATE METHODS
 *--------------------------------------------------------- */
static void
clish_view_init(clish_view_t *this,
                const char   *name,
                const char   *prompt)
{
    /* set up defaults */
    this->name   = lub_string_dup(name);
    this->prompt = NULL;

    /* Be a good binary tree citizen */
    lub_bintree_node_init(&this->bt_node);

    /* initialise the tree of commands for this view */
    lub_bintree_init(&this->tree,
                     clish_command_bt_offset(),
                     clish_command_bt_compare,
                     clish_command_bt_getkey);

    /* set up the defaults */
    clish_view__set_prompt(this,prompt);
}
/*--------------------------------------------------------- */