Navigation Menu

Skip to content

Commit

Permalink
plugin:add initial setting API for command plugin
Browse files Browse the repository at this point in the history
New functions:

* grn_plugin_expr_var_init()
* grn_plugin_command_create()
  • Loading branch information
naoa committed Jun 20, 2014
1 parent 07d636d commit 59fe618
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 7 deletions.
24 changes: 24 additions & 0 deletions include/groonga/plugin.h
Expand Up @@ -215,6 +215,30 @@ GRN_API int grn_plugin_charlen(grn_ctx *ctx, const char *str_ptr,
GRN_API int grn_plugin_isspace(grn_ctx *ctx, const char *str_ptr,
unsigned int str_length, grn_encoding encoding);

/*
grn_plugin_expr_var_init() initializes a grn_expr_var.
If `name_size` is negative, `name` must be
NUL-terminated. `name_size` is computed by `strlen(name)` for the case.
*/

GRN_API grn_rc grn_plugin_expr_var_init(grn_ctx *ctx,
grn_expr_var *var,
const char *name,
int name_size);

/*
grn_plugin_command_create() creates a command.
If `name_size` is negative, `name` must be
NUL-terminated. `name_size` is computed by `strlen(name)` for the case.
*/
GRN_API grn_obj * grn_plugin_command_create(grn_ctx *ctx,
const char *name,
int name_size,
grn_proc_func func,
unsigned int n_vars,
grn_expr_var *vars);


#ifdef __cplusplus
Expand Down
47 changes: 40 additions & 7 deletions lib/plugin.c
Expand Up @@ -51,6 +51,19 @@ static grn_critical_section grn_plugins_lock;
# define grn_dl_clear_error()
#endif

static int
compute_name_size(const char *name, int name_size)
{
if (name_size < 0) {
if (name) {
name_size = strlen(name);
} else {
name_size = 0;
}
}
return name_size;
}

grn_id
grn_plugin_reference(grn_ctx *ctx, const char *filename)
{
Expand Down Expand Up @@ -638,13 +651,7 @@ grn_obj *
grn_plugin_proc_get_var(grn_ctx *ctx, grn_user_data *user_data,
const char *name, int name_size)
{
if (name_size < 0) {
if (name) {
name_size = strlen(name);
} else {
name_size = 0;
}
}
name_size = compute_name_size(name, name_size);
return grn_proc_get_var(ctx, user_data, name, name_size);
}

Expand Down Expand Up @@ -717,3 +724,29 @@ grn_plugin_isspace(grn_ctx *ctx, const char *str_ptr,
}
return 0;
}

grn_rc
grn_plugin_expr_var_init(grn_ctx *ctx,
grn_expr_var *var,
const char *name,
int name_size)
{
var->name = name;
var->name_size = compute_name_size(name, name_size);
GRN_TEXT_INIT(&var->value, 0);
return GRN_SUCCESS;
}

grn_obj *
grn_plugin_command_create(grn_ctx *ctx,
const char *name,
int name_size,
grn_proc_func func,
unsigned int n_vars,
grn_expr_var *vars)
{
name_size = compute_name_size(name, name_size);
grn_proc_create(ctx, name, name_size, GRN_PROC_COMMAND,
func, NULL, NULL, n_vars, vars);
return GRN_SUCCESS;
}

0 comments on commit 59fe618

Please sign in to comment.