[Groonga-commit] groonga/groonga at 714f54e [master] Add grndb command

Zurück zum Archiv-Index

Kouhei Sutou null+****@clear*****
Wed Dec 17 12:04:24 JST 2014


Kouhei Sutou	2014-12-17 12:04:24 +0900 (Wed, 17 Dec 2014)

  New Revision: 714f54e58990ef47614fc7df036a925246a819ea
  https://github.com/groonga/groonga/commit/714f54e58990ef47614fc7df036a925246a819ea

  Message:
    Add grndb command
    
    It does nothing for now. It will implement --check option and --recover
    option.

  Added files:
    lib/mrb/scripts/command/grndb.rb
    src/grndb.c
    src/grndb_sources.am
  Modified files:
    .gitignore
    src/Makefile.am

  Modified: .gitignore (+1 -0)
===================================================================
--- .gitignore    2014-12-17 11:49:35 +0900 (e575346)
+++ .gitignore    2014-12-17 12:04:24 +0900 (5a8022a)
@@ -53,6 +53,7 @@ aclocal.m4
 /src/groonga-benchmark
 /src/grnslap
 /src/groonga-mruby
+/src/grndb
 Makefile
 Makefile.in
 version.sh

  Added: lib/mrb/scripts/command/grndb.rb (+13 -0) 100644
===================================================================
--- /dev/null
+++ lib/mrb/scripts/command/grndb.rb    2014-12-17 12:04:24 +0900 (7eed931)
@@ -0,0 +1,13 @@
+module Groonga
+  module Command
+    class Grndb
+      def initialize(argv)
+        @argv = argv
+      end
+
+      def run
+        p @argv
+      end
+    end
+  end
+end

  Modified: src/Makefile.am (+7 -0)
===================================================================
--- src/Makefile.am    2014-12-17 11:49:35 +0900 (c8680b2)
+++ src/Makefile.am    2014-12-17 12:04:24 +0900 (a4d57e8)
@@ -7,6 +7,7 @@ NONEXISTENT_CXX_SOURCE = nonexistent.cpp
 bin_PROGRAMS = groonga groonga-benchmark
 noinst_PROGRAMS = grnslap
 if WITH_MRUBY
+bin_PROGRAMS += grndb
 noinst_PROGRAMS += groonga-mruby
 endif
 
@@ -49,6 +50,12 @@ groonga_benchmark_LDADD =			\
 	$(top_builddir)/lib/libgroonga.la	\
 	$(MESSAGE_PACK_LIBS)
 
+include grndb_sources.am
+nodist_EXTRA_grndb_SOURCES = $(NONEXISTENT_CXX_SOURCE)
+grndb_LDADD =					\
+	$(top_builddir)/lib/libgroonga.la	\
+	$(MESSAGE_PACK_LIBS)
+
 include groonga_mruby_sources.am
 nodist_EXTRA_groonga_mruby_SOURCES = $(NONEXISTENT_CXX_SOURCE)
 groonga_mruby_LDADD =				\

  Added: src/grndb.c (+99 -0) 100644
===================================================================
--- /dev/null
+++ src/grndb.c    2014-12-17 12:04:24 +0900 (8b305b1)
@@ -0,0 +1,99 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2014 Brazil
+
+  This library is free software; you can redistribute it and/or
+  modify it under the terms of the GNU Lesser General Public
+  License version 2.1 as published by the Free Software Foundation.
+
+  This library is distributed in the hope that it will be useful,
+  but WITHOUT ANY WARRANTY; without even the implied warranty of
+  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+  Lesser General Public License for more details.
+
+  You should have received a copy of the GNU Lesser General Public
+  License along with this library; if not, write to the Free Software
+  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+*/
+
+#ifdef WIN32
+# define GROONGA_MAIN
+#endif /* WIN32 */
+
+#include <grn_mrb.h>
+#include <grn_ctx_impl.h>
+
+#include <mruby/variable.h>
+#include <mruby/array.h>
+
+static int
+run(grn_ctx *ctx, int argc, char **argv)
+{
+  const char *grndb_rb = "command/grndb.rb";
+
+  grn_mrb_load(ctx, grndb_rb);
+  if (ctx->rc != GRN_SUCCESS) {
+      fprintf(stderr, "Failed to load Ruby script: <%s>: %s",
+              grndb_rb, ctx->errbuf);
+      goto exit;
+  }
+
+  /* TODO: Handle error. */
+  {
+    grn_mrb_data *data = &(ctx->impl->mrb);
+    mrb_state *mrb = data->state;
+    mrb_value mrb_command_module;
+    mrb_value mrb_grndb_class;
+    int arena_index;
+
+    arena_index = mrb_gc_arena_save(mrb);
+    mrb_command_module = mrb_const_get(mrb,
+                                       mrb_obj_value(data->module),
+                                       mrb_intern_cstr(mrb, "Command"));
+    mrb_grndb_class = mrb_const_get(mrb,
+                                    mrb_command_module,
+                                    mrb_intern_cstr(mrb, "Grndb"));
+    {
+      int i;
+      mrb_value mrb_argv;
+      mrb_value mrb_grndb;
+      mrb_value mrb_result;
+
+      mrb_argv = mrb_ary_new_capa(mrb, argc);
+      for (i = 0; i < argc; i++) {
+        mrb_ary_push(mrb, mrb_argv, mrb_str_new_cstr(mrb, argv[i]));
+      }
+      mrb_grndb = mrb_funcall(mrb, mrb_grndb_class, "new", 1, mrb_argv);
+      mrb_result = mrb_funcall(mrb, mrb_grndb, "run", 0);
+    }
+    mrb_gc_arena_restore(mrb, arena_index);
+  }
+
+exit :
+  if (ctx->rc == GRN_SUCCESS) {
+    return EXIT_SUCCESS;
+  } else {
+    return EXIT_FAILURE;
+  }
+}
+
+int
+main(int argc, char **argv)
+{
+  int exit_code = EXIT_SUCCESS;
+
+  if (grn_init() != GRN_SUCCESS) {
+    return EXIT_FAILURE;
+  }
+
+  {
+    grn_ctx ctx;
+    grn_ctx_init(&ctx, 0);
+    exit_code = run(&ctx, argc, argv);
+    grn_ctx_fin(&ctx);
+  }
+
+  grn_fin();
+
+  return exit_code;
+}

  Added: src/grndb_sources.am (+2 -0) 100644
===================================================================
--- /dev/null
+++ src/grndb_sources.am    2014-12-17 12:04:24 +0900 (ce2e2bb)
@@ -0,0 +1,2 @@
+grndb_SOURCES =					\
+	grndb.c
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index