Kouhei Sutou
null+****@clear*****
Tue Jan 12 14:16:56 JST 2016
Kouhei Sutou 2016-01-12 14:16:56 +0900 (Tue, 12 Jan 2016) New Revision: 334122c13cd07687b897014be77b6c497ed4f525 https://github.com/groonga/groonga/commit/334122c13cd07687b897014be77b6c497ed4f525 Message: Export grn_dump_table_create_flags() It's a function that dumps grn_obj_flags for creating table as Groonga command format. Added files: lib/dump.c Copied files: include/groonga/dump.h (from include/groonga.h) Modified files: include/groonga.h lib/proc.c lib/sources.am Modified: include/groonga.h (+1 -0) =================================================================== --- include/groonga.h 2016-01-12 12:53:00 +0900 (634d647) +++ include/groonga.h 2016-01-12 14:16:56 +0900 (a3d492d) @@ -24,6 +24,7 @@ #include "groonga/array.h" #include "groonga/conf.h" #include "groonga/dat.h" +#include "groonga/dump.h" #include "groonga/expr.h" #include "groonga/file_reader.h" #include "groonga/geo.h" Copied: include/groonga/dump.h (+11 -20) 56% =================================================================== --- include/groonga.h 2016-01-12 12:53:00 +0900 (634d647) +++ include/groonga/dump.h 2016-01-12 14:16:56 +0900 (df201b0) @@ -1,5 +1,5 @@ /* - Copyright(C) 2014-2016 Brazil + Copyright(C) 2016 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -18,23 +18,14 @@ #pragma once -#include "groonga/portability.h" -#include "groonga/groonga.h" +#ifdef __cplusplus +extern "C" { +#endif -#include "groonga/array.h" -#include "groonga/conf.h" -#include "groonga/dat.h" -#include "groonga/expr.h" -#include "groonga/file_reader.h" -#include "groonga/geo.h" -#include "groonga/hash.h" -#include "groonga/ii.h" -#include "groonga/obj.h" -#include "groonga/output.h" -#include "groonga/pat.h" -#include "groonga/request_canceler.h" -#include "groonga/thread.h" -#include "groonga/type.h" -#include "groonga/util.h" -#include "groonga/windows.h" -#include "groonga/windows_event_logger.h" +GRN_API grn_rc grn_dump_table_create_flags(grn_ctx *ctx, + grn_obj_flags flags, + grn_obj *buffer); + +#ifdef __cplusplus +} +#endif Added: lib/dump.c (+53 -0) 100644 =================================================================== --- /dev/null +++ lib/dump.c 2016-01-12 14:16:56 +0900 (b7256e5) @@ -0,0 +1,53 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2016 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 +*/ + +#include "grn_ctx.h" + +grn_rc +grn_dump_table_create_flags(grn_ctx *ctx, + grn_obj_flags flags, + grn_obj *buffer) +{ + GRN_API_ENTER; + + switch (flags & GRN_OBJ_TABLE_TYPE_MASK) { + case GRN_OBJ_TABLE_HASH_KEY: + GRN_TEXT_PUTS(ctx, buffer, "TABLE_HASH_KEY"); + break; + case GRN_OBJ_TABLE_PAT_KEY: + GRN_TEXT_PUTS(ctx, buffer, "TABLE_PAT_KEY"); + break; + case GRN_OBJ_TABLE_DAT_KEY: + GRN_TEXT_PUTS(ctx, buffer, "TABLE_DAT_KEY"); + break; + case GRN_OBJ_TABLE_NO_KEY: + GRN_TEXT_PUTS(ctx, buffer, "TABLE_NO_KEY"); + break; + } + if (flags & GRN_OBJ_KEY_WITH_SIS) { + GRN_TEXT_PUTS(ctx, buffer, "|KEY_WITH_SIS"); + } + if (flags & GRN_OBJ_KEY_NORMALIZE) { + GRN_TEXT_PUTS(ctx, buffer, "|KEY_NORMALIZE"); + } + if (flags & GRN_OBJ_PERSISTENT) { + GRN_TEXT_PUTS(ctx, buffer, "|PERSISTENT"); + } + + GRN_API_RETURN(ctx->rc); +} Modified: lib/proc.c (+5 -35) =================================================================== --- lib/proc.c 2016-01-12 12:53:00 +0900 (aca87b0) +++ lib/proc.c 2016-01-12 14:16:56 +0900 (fa0ddee) @@ -1529,35 +1529,6 @@ grn_parse_column_create_flags(grn_ctx *ctx, const char *nptr, const char *end) } static void -grn_table_create_flags_to_text(grn_ctx *ctx, grn_obj *buf, grn_obj_flags flags) -{ - GRN_BULK_REWIND(buf); - switch (flags & GRN_OBJ_TABLE_TYPE_MASK) { - case GRN_OBJ_TABLE_HASH_KEY: - GRN_TEXT_PUTS(ctx, buf, "TABLE_HASH_KEY"); - break; - case GRN_OBJ_TABLE_PAT_KEY: - GRN_TEXT_PUTS(ctx, buf, "TABLE_PAT_KEY"); - break; - case GRN_OBJ_TABLE_DAT_KEY: - GRN_TEXT_PUTS(ctx, buf, "TABLE_DAT_KEY"); - break; - case GRN_OBJ_TABLE_NO_KEY: - GRN_TEXT_PUTS(ctx, buf, "TABLE_NO_KEY"); - break; - } - if (flags & GRN_OBJ_KEY_WITH_SIS) { - GRN_TEXT_PUTS(ctx, buf, "|KEY_WITH_SIS"); - } - if (flags & GRN_OBJ_KEY_NORMALIZE) { - GRN_TEXT_PUTS(ctx, buf, "|KEY_NORMALIZE"); - } - if (flags & GRN_OBJ_PERSISTENT) { - GRN_TEXT_PUTS(ctx, buf, "|PERSISTENT"); - } -} - -static void grn_column_create_flags_to_text(grn_ctx *ctx, grn_obj *buf, grn_obj_flags flags) { GRN_BULK_REWIND(buf); @@ -2315,7 +2286,8 @@ output_table_info(grn_ctx *ctx, grn_obj *table) GRN_OUTPUT_INT64(id); output_object_id_name(ctx, id); GRN_OUTPUT_CSTR(path); - grn_table_create_flags_to_text(ctx, &o, table->header.flags); + GRN_BULK_REWIND(&o); + grn_dump_table_create_flags(ctx, table->header.flags, &o); GRN_OUTPUT_OBJ(&o, NULL); output_object_id_name(ctx, table->header.domain); output_object_id_name(ctx, grn_obj_get_range(ctx, table)); @@ -3302,7 +3274,6 @@ dump_table(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table, grn_obj_flags default_flags = GRN_OBJ_PERSISTENT; grn_obj *default_tokenizer; grn_obj *normalizer; - grn_obj buf; switch (table->header.type) { case GRN_TABLE_HASH_KEY: @@ -3322,10 +3293,9 @@ dump_table(grn_ctx *ctx, grn_obj *outbuf, grn_obj *table, GRN_TEXT_PUTS(ctx, outbuf, "table_create "); dump_obj_name(ctx, outbuf, table); GRN_TEXT_PUTC(ctx, outbuf, ' '); - GRN_TEXT_INIT(&buf, 0); - grn_table_create_flags_to_text(ctx, &buf, table->header.flags & ~default_flags); - GRN_TEXT_PUT(ctx, outbuf, GRN_TEXT_VALUE(&buf), GRN_TEXT_LEN(&buf)); - GRN_OBJ_FIN(ctx, &buf); + grn_dump_table_create_flags(ctx, + table->header.flags & ~default_flags, + outbuf); if (domain) { GRN_TEXT_PUTC(ctx, outbuf, ' '); dump_obj_name(ctx, outbuf, domain); Modified: lib/sources.am (+1 -0) =================================================================== --- lib/sources.am 2016-01-12 12:53:00 +0900 (3e91219) +++ lib/sources.am 2016-01-12 14:16:56 +0900 (8fa3b58) @@ -12,6 +12,7 @@ libgroonga_la_SOURCES = \ grn_dat.h \ db.c \ grn_db.h \ + dump.c \ ts.c \ grn_ts.h \ type.c \ -------------- next part -------------- HTML����������������������������...ダウンロード