[Groonga-commit] groonga/groonga at 59fe618 [master] plugin:add initial setting API for command plugin

Back to archive index

naoa null+****@clear*****
Fri Jun 20 10:06:50 JST 2014


naoa	2014-06-20 10:06:50 +0900 (Fri, 20 Jun 2014)

  New Revision: 59fe6185175f22bd974c6120fc6cfda000134635
  https://github.com/groonga/groonga/commit/59fe6185175f22bd974c6120fc6cfda000134635

  Merged aff6a36: Merge pull request #175 from naoa/add-initial-setting-api-for-command-plugin

  Message:
    plugin:add initial setting API for command plugin
    
    New functions:
    
    * grn_plugin_expr_var_init()
    * grn_plugin_command_create()

  Modified files:
    include/groonga/plugin.h
    lib/plugin.c

  Modified: include/groonga/plugin.h (+24 -0)
===================================================================
--- include/groonga/plugin.h    2014-06-16 23:43:14 +0900 (3a78b19)
+++ include/groonga/plugin.h    2014-06-20 10:06:50 +0900 (9c77a66)
@@ -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

  Modified: lib/plugin.c (+40 -7)
===================================================================
--- lib/plugin.c    2014-06-16 23:43:14 +0900 (a0180a8)
+++ lib/plugin.c    2014-06-20 10:06:50 +0900 (1e206b1)
@@ -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)
 {
@@ -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);
 }
 
@@ -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;
+}
-------------- next part --------------
HTML����������������������������...
Télécharger 



More information about the Groonga-commit mailing list
Back to archive index