コード例 #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);
}
/*--------------------------------------------------------- */