[Groonga-commit] groonga/groonga at 9c7cb19 [master] Extract grn_output_columns_parse()

Back to archive index
Kouhei Sutou null+****@clear*****
Tue Dec 18 17:14:58 JST 2018


Kouhei Sutou	2018-12-18 17:14:58 +0900 (Tue, 18 Dec 2018)

  Revision: 9c7cb1985a19e95a410514a7b3e789b3e20366ec
  https://github.com/groonga/groonga/commit/9c7cb1985a19e95a410514a7b3e789b3e20366ec

  Message:
    Extract grn_output_columns_parse()

  Added files:
    lib/grn_output_columns.h
    lib/output_columns.c
  Modified files:
    lib/c_sources.am
    lib/output.c

  Modified: lib/c_sources.am (+2 -0)
===================================================================
--- lib/c_sources.am    2018-12-18 17:03:50 +0900 (d1f818079)
+++ lib/c_sources.am    2018-12-18 17:14:58 +0900 (637bb2ebd)
@@ -71,6 +71,8 @@ libgroonga_c_sources =				\
 	grn_options.h				\
 	output.c				\
 	grn_output.h				\
+	output_columns.c			\
+	grn_output_columns.h			\
 	pat.c					\
 	grn_pat.h				\
 	plugin.c				\

  Added: lib/grn_output_columns.h (+35 -0) 100644
===================================================================
--- /dev/null
+++ lib/grn_output_columns.h    2018-12-18 17:14:58 +0900 (fd475849c)
@@ -0,0 +1,35 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
+
+  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
+*/
+
+#pragma once
+
+#include "grn.h"
+
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+GRN_API grn_obj *
+grn_output_columns_parse(grn_ctx *ctx,
+                         grn_obj *table,
+                         const char *raw_output_columns,
+                         size_t raw_output_columns_size);
+
+#ifdef __cplusplus
+}
+#endif

  Modified: lib/output.c (+10 -8)
===================================================================
--- lib/output.c    2018-12-18 17:03:50 +0900 (f4b020df7)
+++ lib/output.c    2018-12-18 17:14:58 +0900 (21a53392b)
@@ -1,6 +1,7 @@
 /* -*- c-basic-offset: 2 -*- */
 /*
   Copyright(C) 2009-2018 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
 
   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Lesser General Public
@@ -19,11 +20,13 @@
 #include "grn.h"
 
 #include <string.h>
-#include "grn_str.h"
+
 #include "grn_db.h"
 #include "grn_expr.h"
-#include "grn_util.h"
 #include "grn_output.h"
+#include "grn_output_columns.h"
+#include "grn_str.h"
+#include "grn_util.h"
 
 #define LEVELS (&ctx->impl->output.levels)
 #define DEPTH (GRN_BULK_VSIZE(LEVELS)>>2)
@@ -2897,12 +2900,11 @@ grn_output_format_set_columns(grn_ctx *ctx, grn_obj_format *format,
   if (is_output_columns_format_v1(ctx, columns, columns_len)) {
     rc = grn_obj_columns(ctx, table, columns, columns_len, &(format->columns));
   } else {
-    grn_obj *variable;
-    GRN_EXPR_CREATE_FOR_QUERY(ctx, table, format->expression, variable);
-    rc = grn_expr_parse(ctx, format->expression,
-                        columns, columns_len, NULL,
-                        GRN_OP_MATCH, GRN_OP_AND,
-                        GRN_EXPR_SYNTAX_OUTPUT_COLUMNS);
+    format->expression = grn_output_columns_parse(ctx,
+                                                  table,
+                                                  columns,
+                                                  columns_len);
+    rc = ctx->rc;
   }
 
   return rc;

  Added: lib/output_columns.c (+47 -0) 100644
===================================================================
--- /dev/null
+++ lib/output_columns.c    2018-12-18 17:14:58 +0900 (317498047)
@@ -0,0 +1,47 @@
+/* -*- c-basic-offset: 2 -*- */
+/*
+  Copyright(C) 2009-2018 Brazil
+  Copyright(C) 2018 Kouhei Sutou <kou****@clear*****>
+
+  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
+*/
+
+#include "grn_expr.h"
+#include "grn_output_columns.h"
+
+grn_obj *
+grn_output_columns_parse(grn_ctx *ctx,
+                         grn_obj *table,
+                         const char *raw_output_columns,
+                         size_t raw_output_columns_size)
+{
+  grn_obj *output_columns = NULL;
+  grn_obj *variable;
+
+  GRN_API_ENTER;
+
+  GRN_EXPR_CREATE_FOR_QUERY(ctx, table, output_columns, variable);
+  if (ctx->rc == GRN_SUCCESS) {
+    grn_expr_parse(ctx,
+                   output_columns,
+                   raw_output_columns,
+                   raw_output_columns_size,
+                   NULL,
+                   GRN_OP_MATCH,
+                   GRN_OP_AND,
+                   GRN_EXPR_SYNTAX_OUTPUT_COLUMNS);
+  }
+
+  GRN_API_RETURN(output_columns);
+}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20181218/8fe193e6/attachment-0001.html>


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