[Groonga-commit] groonga/groonga at 265f108 [master] Add grn_plugin_proc_get_var_int32()

Back to archive index

Kouhei Sutou null+****@clear*****
Thu Feb 25 23:35:11 JST 2016


Kouhei Sutou	2016-02-25 23:35:11 +0900 (Thu, 25 Feb 2016)

  New Revision: 265f108a89775521f1dd3bf473c0d9d1db93e7f4
  https://github.com/groonga/groonga/commit/265f108a89775521f1dd3bf473c0d9d1db93e7f4

  Message:
    Add grn_plugin_proc_get_var_int32()

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

  Modified: include/groonga/plugin.h (+5 -0)
===================================================================
--- include/groonga/plugin.h    2016-02-25 22:21:30 +0900 (027810d)
+++ include/groonga/plugin.h    2016-02-25 23:35:11 +0900 (f855cd0)
@@ -150,6 +150,11 @@ GRN_API grn_bool grn_plugin_proc_get_var_bool(grn_ctx *ctx,
                                               const char *name,
                                               int name_size,
                                               grn_bool default_value);
+GRN_API int32_t grn_plugin_proc_get_var_int32(grn_ctx *ctx,
+                                              grn_user_data *user_data,
+                                              const char *name,
+                                              int name_size,
+                                              grn_int32 default_value);
 
 GRN_API grn_obj *grn_plugin_proc_get_var_by_offset(grn_ctx *ctx,
                                                    grn_user_data *user_data,

  Modified: lib/grn_proc.h (+3 -0)
===================================================================
--- lib/grn_proc.h    2016-02-25 22:21:30 +0900 (1df053c)
+++ lib/grn_proc.h    2016-02-25 23:35:11 +0900 (885bc65)
@@ -57,6 +57,9 @@ void grn_proc_init_table_rename(grn_ctx *ctx);
 grn_bool grn_proc_option_value_bool(grn_ctx *ctx,
                                     grn_obj *option,
                                     grn_bool default_value);
+int32_t grn_proc_option_value_int32(grn_ctx *ctx,
+                                    grn_obj *option,
+                                    int32_t default_value);
 
 void grn_proc_output_object_name(grn_ctx *ctx, grn_obj *obj);
 void grn_proc_output_object_id_name(grn_ctx *ctx, grn_id id);

  Modified: lib/plugin.c (+14 -1)
===================================================================
--- lib/plugin.c    2016-02-25 22:21:30 +0900 (301017f)
+++ lib/plugin.c    2016-02-25 23:35:11 +0900 (c578dc6)
@@ -1,6 +1,6 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
-  Copyright(C) 2012-2015 Brazil
+  Copyright(C) 2012-2016 Brazil
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -1150,6 +1150,19 @@ grn_plugin_proc_get_var_bool(grn_ctx *ctx,
   return grn_proc_option_value_bool(ctx, var, default_value);
 }
 
+int32_t
+grn_plugin_proc_get_var_int32(grn_ctx *ctx,
+                              grn_user_data *user_data,
+                              const char *name,
+                              int name_size,
+                              grn_int32 default_value)
+{
+  grn_obj *var;
+
+  var = grn_plugin_proc_get_var(ctx, user_data, name, name_size);
+  return grn_proc_option_value_int32(ctx, var, default_value);
+}
+
 grn_obj *
 grn_plugin_proc_get_var_by_offset(grn_ctx *ctx, grn_user_data *user_data,
                                   unsigned int offset)

  Modified: lib/proc.c (+25 -0)
===================================================================
--- lib/proc.c    2016-02-25 22:21:30 +0900 (acb5c23)
+++ lib/proc.c    2016-02-25 23:35:11 +0900 (58c4e38)
@@ -2745,6 +2745,31 @@ grn_proc_option_value_bool(grn_ctx *ctx,
   }
 }
 
+int32_t
+grn_proc_option_value_int32(grn_ctx *ctx,
+                            grn_obj *option,
+                            int32_t default_value)
+{
+  const char *value;
+  size_t value_length;
+  int32_t int32_value;
+  const char *rest;
+
+  value = GRN_TEXT_VALUE(option);
+  value_length = GRN_TEXT_LEN(option);
+
+  if (value_length == 0) {
+    return default_value;
+  }
+
+  int32_value = grn_atoi(value, value + value_length, &rest);
+  if (rest == value + value_length) {
+    return int32_value;
+  } else {
+    return default_value;
+  }
+}
+
 static grn_obj *
 proc_dump(grn_ctx *ctx, int nargs, grn_obj **args, grn_user_data *user_data)
 {
-------------- next part --------------
HTML����������������������������...
Download 



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