| 1 | /* |
| 2 | Copyright (C) 2009-2017 Brazil |
| 3 | Copyright (C) 2018-2024 Sutou Kouhei <[email protected]> |
| 4 | |
| 5 | This library is free software; you can redistribute it and/or |
| 6 | modify it under the terms of the GNU Lesser General Public |
| 7 | License as published by the Free Software Foundation; either |
| 8 | version 2.1 of the License, or (at your option) any later version. |
| 9 | |
| 10 | This library is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | Lesser General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU Lesser General Public |
| 16 | License along with this library; if not, write to the Free Software |
| 17 | Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
| 18 | */ |
| 19 | |
| 20 | #pragma once |
| 21 | |
| 22 | #include "grn.h" |
| 23 | |
| 24 | #ifdef __cplusplus |
| 25 | extern "C" { |
| 26 | #endif |
| 27 | |
| 28 | #define GRN_JSON_LOAD_OPEN_BRACKET 0x40000000 |
| 29 | #define GRN_JSON_LOAD_OPEN_BRACE 0x40000001 |
| 30 | |
| 31 | typedef struct grn_load_input_ { |
| 32 | grn_content_type type; |
| 33 | grn_raw_string table; |
| 34 | grn_raw_string columns; |
| 35 | grn_raw_string values; |
| 36 | grn_raw_string if_exists; |
| 37 | grn_raw_string each; |
| 38 | bool output_ids; |
| 39 | bool output_errors; |
| 40 | bool lock_table; |
| 41 | uint32_t emit_level; |
| 42 | } grn_load_input; |
| 43 | |
| 44 | void |
| 45 | grn_load_internal(grn_ctx *ctx, grn_load_input *input); |
| 46 | |
| 47 | typedef enum { |
| 48 | GRN_LOADER_BEGIN = 0, |
| 49 | GRN_LOADER_TOKEN, |
| 50 | GRN_LOADER_STRING, |
| 51 | GRN_LOADER_SYMBOL, |
| 52 | GRN_LOADER_NUMBER, |
| 53 | GRN_LOADER_STRING_ESC, |
| 54 | GRN_LOADER_UNICODE0, |
| 55 | GRN_LOADER_UNICODE1, |
| 56 | GRN_LOADER_UNICODE2, |
| 57 | GRN_LOADER_UNICODE3, |
| 58 | GRN_LOADER_END |
| 59 | } grn_loader_stat; |
| 60 | |
| 61 | /* |
| 62 | * Status of target columns used in Format 1. |
| 63 | * Target columns are specified via --columns or the first array in a Format 1 |
| 64 | * JSON object. |
| 65 | */ |
| 66 | typedef enum { |
| 67 | GRN_LOADER_COLUMNS_UNSET = 0, /* Columns are not available. */ |
| 68 | GRN_LOADER_COLUMNS_SET, /* Columns are available. */ |
| 69 | GRN_LOADER_COLUMNS_BROKEN /* Columns are specified but broken. */ |
| 70 | } grn_loader_columns_status; |
| 71 | |
| 72 | typedef struct { |
| 73 | grn_obj values; |
| 74 | grn_obj level; |
| 75 | grn_hash *columns; |
| 76 | grn_obj ranges; |
| 77 | grn_obj indexes; |
| 78 | grn_obj ids; |
| 79 | grn_obj return_codes; |
| 80 | grn_obj error_messages; |
| 81 | uint32_t emit_level; |
| 82 | int32_t id_offset; /* Position of _id in values or -1 if _id is N/A. */ |
| 83 | int32_t key_offset; /* Position of _key in values or -1 if _key is N/A. */ |
| 84 | grn_obj *last; |
| 85 | grn_obj *table; |
| 86 | grn_obj *ifexists; |
| 87 | grn_obj *each; |
| 88 | uint32_t unichar; |
| 89 | uint32_t unichar_hi; |
| 90 | uint32_t values_size; |
| 91 | uint32_t n_records; |
| 92 | uint32_t n_record_errors; |
| 93 | uint32_t n_column_errors; |
| 94 | grn_loader_stat stat; |
| 95 | grn_content_type input_type; |
| 96 | grn_loader_columns_status columns_status; |
| 97 | struct { |
| 98 | grn_rc rc; |
| 99 | char buffer[GRN_CTX_MSGSIZE]; |
| 100 | uint32_t line; |
| 101 | const char *file; |
| 102 | const char *func; |
| 103 | } error; |
| 104 | bool output_ids; |
| 105 | bool output_errors; |
| 106 | bool lock_table; |
| 107 | } grn_loader; |
| 108 | |
| 109 | typedef struct { |
| 110 | grn_obj *table; |
| 111 | uint32_t depth; |
| 112 | grn_obj *record_value; |
| 113 | grn_id id; |
| 114 | grn_obj *key; |
| 115 | struct { |
| 116 | const char *column_name; |
| 117 | uint32_t column_name_size; |
| 118 | grn_obj *column; |
| 119 | grn_obj *value; |
| 120 | } current; |
| 121 | } grn_loader_add_record_data; |
| 122 | |
| 123 | void |
| 124 | grn_loader_save_error(grn_ctx *ctx, grn_loader *loader); |
| 125 | void |
| 126 | grn_loader_on_record_added(grn_ctx *ctx, grn_loader *loader, grn_id id); |
| 127 | void |
| 128 | grn_loader_on_column_set(grn_ctx *ctx, |
| 129 | grn_loader *loader, |
| 130 | grn_loader_add_record_data *data); |
| 131 | void |
| 132 | grn_loader_on_no_identifier_error(grn_ctx *ctx, |
| 133 | grn_loader *loader, |
| 134 | grn_obj *table); |
| 135 | void |
| 136 | grn_loader_merge(grn_ctx *ctx, grn_loader *loader, grn_loader *loader_other); |
| 137 | grn_id |
| 138 | grn_loader_add_record(grn_ctx *ctx, |
| 139 | grn_loader *loader, |
| 140 | grn_loader_add_record_data *data); |
| 141 | grn_obj * |
| 142 | grn_loader_get_column(grn_ctx *ctx, |
| 143 | grn_loader *loader, |
| 144 | const char *name, |
| 145 | size_t name_length); |
| 146 | void |
| 147 | grn_loader_apply_each(grn_ctx *ctx, grn_loader *loader, grn_id id); |
| 148 | |
| 149 | void |
| 150 | grn_p_loader(grn_ctx *ctx, grn_loader *loader); |
| 151 | |
| 152 | #ifdef __cplusplus |
| 153 | } |
| 154 | #endif |