Kouhei Sutou
null+****@clear*****
Sat Oct 17 17:49:39 JST 2015
Kouhei Sutou 2015-10-17 17:49:39 +0900 (Sat, 17 Oct 2015) New Revision: ec931d9b918d69842465f8996eb28d75b288d6e2 https://github.com/groonga/groonga/commit/ec931d9b918d69842465f8996eb28d75b288d6e2 Message: windows: use "windows" instead of "win32" Because we also support win64. Added files: lib/windows.c Copied files: include/groonga/windows.h (from include/groonga.h) Modified files: include/groonga.h include/groonga/plugin.h lib/grn_util.h lib/mrb.c lib/plugin.c lib/sources.am lib/util.c src/groonga.c Modified: include/groonga.h (+1 -0) =================================================================== --- include/groonga.h 2015-10-17 16:43:12 +0900 (57143d0) +++ include/groonga.h 2015-10-17 17:49:39 +0900 (e155127) @@ -29,6 +29,7 @@ #include "groonga/util.h" #include "groonga/request_canceler.h" #include "groonga/thread.h" +#include "groonga/windows.h" #include "groonga/windows_event_logger.h" #endif /* GROONGA_H */ Modified: include/groonga/plugin.h (+2 -0) =================================================================== --- include/groonga/plugin.h 2015-10-17 16:43:12 +0900 (98ca696) +++ include/groonga/plugin.h 2015-10-17 17:49:39 +0900 (eb4d2ad) @@ -146,7 +146,9 @@ GRN_API grn_obj *grn_plugin_proc_get_var_by_offset(grn_ctx *ctx, grn_user_data *user_data, unsigned int offset); +/* Deprecated since 5.0.9. Use grn_plugin_windows_base_dir() instead. */ GRN_API const char *grn_plugin_win32_base_dir(void); +GRN_API const char *grn_plugin_windows_base_dir(void); GRN_API int grn_plugin_charlen(grn_ctx *ctx, const char *str_ptr, unsigned int str_length, grn_encoding encoding); Copied: include/groonga/windows.h (+18 -18) 62% =================================================================== --- include/groonga.h 2015-10-17 16:43:12 +0900 (57143d0) +++ include/groonga/windows.h 2015-10-17 17:49:39 +0900 (290b276) @@ -1,5 +1,5 @@ /* - Copyright(C) 2014-2015 Brazil + Copyright(C) 2015 Brazil This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public @@ -15,20 +15,20 @@ License along with this library; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ -#ifndef GROONGA_H -#define GROONGA_H - -#include "groonga/portability.h" -#include "groonga/groonga.h" -#include "groonga/conf.h" -#include "groonga/obj.h" -#include "groonga/ii.h" -#include "groonga/geo.h" -#include "groonga/expr.h" -#include "groonga/output.h" -#include "groonga/util.h" -#include "groonga/request_canceler.h" -#include "groonga/thread.h" -#include "groonga/windows_event_logger.h" - -#endif /* GROONGA_H */ + +#ifndef GROONGA_WINDOWS_H +#define GROONGA_WINDOWS_H + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef WIN32 +GRN_API const char *grn_windows_base_dir(void); +#endif /* WIN32 */ + +#ifdef __cplusplus +} +#endif + +#endif /* GROONGA_WINDOWS_H */ Modified: lib/grn_util.h (+0 -1) =================================================================== --- lib/grn_util.h 2015-10-17 16:43:12 +0900 (258a429) +++ lib/grn_util.h 2015-10-17 17:49:39 +0900 (b658786) @@ -26,7 +26,6 @@ extern "C" { GRN_API grn_rc grn_normalize_offset_and_limit(grn_ctx *ctx, int size, int *offset, int *limit); -GRN_API const char *grn_win32_base_dir(void); GRN_API char *grn_path_separator_to_system(char *dest, char *groonga_path); int grn_mkstemp(char *path_template); Modified: lib/mrb.c (+9 -9) =================================================================== --- lib/mrb.c 2015-10-17 16:43:12 +0900 (d406c2d) +++ lib/mrb.c 2015-10-17 17:49:39 +0900 (9bbbab4) @@ -49,24 +49,24 @@ grn_mrb_init_from_env(void) #ifdef GRN_WITH_MRUBY # ifdef WIN32 -static char *win32_ruby_scripts_dir = NULL; -static char win32_ruby_scripts_dir_buffer[PATH_MAX]; +static char *windows_ruby_scripts_dir = NULL; +static char windows_ruby_scripts_dir_buffer[PATH_MAX]; static const char * grn_mrb_get_default_system_ruby_scripts_dir(void) { - if (!win32_ruby_scripts_dir) { + if (!windows_ruby_scripts_dir) { const char *base_dir; const char *relative_path = GRN_RELATIVE_RUBY_SCRIPTS_DIR; size_t base_dir_length; - base_dir = grn_win32_base_dir(); + base_dir = grn_windows_base_dir(); base_dir_length = strlen(base_dir); - grn_strcpy(win32_ruby_scripts_dir_buffer, PATH_MAX, base_dir); - grn_strcat(win32_ruby_scripts_dir_buffer, PATH_MAX, "/"); - grn_strcat(win32_ruby_scripts_dir_buffer, PATH_MAX, relative_path); - win32_ruby_scripts_dir = win32_ruby_scripts_dir_buffer; + grn_strcpy(windows_ruby_scripts_dir_buffer, PATH_MAX, base_dir); + grn_strcat(windows_ruby_scripts_dir_buffer, PATH_MAX, "/"); + grn_strcat(windows_ruby_scripts_dir_buffer, PATH_MAX, relative_path); + windows_ruby_scripts_dir = windows_ruby_scripts_dir_buffer; } - return win32_ruby_scripts_dir; + return windows_ruby_scripts_dir; } # else /* WIN32 */ Modified: lib/plugin.c (+16 -10) =================================================================== --- lib/plugin.c 2015-10-17 16:43:12 +0900 (7db19c1) +++ lib/plugin.c 2015-10-17 17:49:39 +0900 (7f8afe7) @@ -492,24 +492,24 @@ grn_plugin_register_by_path(grn_ctx *ctx, const char *path) } #ifdef WIN32 -static char *win32_plugins_dir = NULL; -static char win32_plugins_dir_buffer[PATH_MAX]; +static char *windows_plugins_dir = NULL; +static char windows_plugins_dir_buffer[PATH_MAX]; static const char * grn_plugin_get_default_system_plugins_dir(void) { - if (!win32_plugins_dir) { + if (!windows_plugins_dir) { const char *base_dir; const char *relative_path = GRN_RELATIVE_PLUGINS_DIR; size_t base_dir_length; - base_dir = grn_win32_base_dir(); + base_dir = grn_windows_base_dir(); base_dir_length = strlen(base_dir); - grn_strcpy(win32_plugins_dir_buffer, PATH_MAX, base_dir); - grn_strcat(win32_plugins_dir_buffer, PATH_MAX, "/"); - grn_strcat(win32_plugins_dir_buffer, PATH_MAX, relative_path); - win32_plugins_dir = win32_plugins_dir_buffer; + grn_strcpy(windows_plugins_dir_buffer, PATH_MAX, base_dir); + grn_strcat(windows_plugins_dir_buffer, PATH_MAX, "/"); + grn_strcat(windows_plugins_dir_buffer, PATH_MAX, relative_path); + windows_plugins_dir = windows_plugins_dir_buffer; } - return win32_plugins_dir; + return windows_plugins_dir; } #else /* WIN32 */ @@ -1024,8 +1024,14 @@ grn_plugin_proc_get_var_by_offset(grn_ctx *ctx, grn_user_data *user_data, const char * grn_plugin_win32_base_dir(void) { + return grn_plugin_windows_base_dir(); +} + +const char * +grn_plugin_windows_base_dir(void) +{ #ifdef WIN32 - return grn_win32_base_dir(); + return grn_windows_base_dir(); #else /* WIN32 */ return NULL; #endif /* WIN32 */ Modified: lib/sources.am (+1 -0) =================================================================== --- lib/sources.am 2015-10-17 16:43:12 +0900 (631c407) +++ lib/sources.am 2015-10-17 17:49:39 +0900 (f56aef3) @@ -76,4 +76,5 @@ libgroonga_la_SOURCES = \ token_filter.c \ util.c \ grn_util.h \ + windows.c \ windows_event_logger.c Modified: lib/util.c (+0 -55) =================================================================== --- lib/util.c 2015-10-17 16:43:12 +0900 (80ad384) +++ lib/util.c 2015-10-17 17:49:39 +0900 (d21b973) @@ -1318,61 +1318,6 @@ grn_p_expr_code(grn_ctx *ctx, grn_expr_code *code) } #ifdef WIN32 -static char *win32_base_dir = NULL; -const char * -grn_win32_base_dir(void) -{ - if (!win32_base_dir) { - HMODULE dll; - const wchar_t *dll_filename = GRN_DLL_FILENAME; - wchar_t absolute_dll_filename[MAX_PATH]; - DWORD absolute_dll_filename_size; - dll = GetModuleHandleW(dll_filename); - absolute_dll_filename_size = GetModuleFileNameW(dll, - absolute_dll_filename, - MAX_PATH); - if (absolute_dll_filename_size == 0) { - win32_base_dir = grn_strdup_raw("."); - } else { - DWORD ansi_dll_filename_size; - ansi_dll_filename_size = - WideCharToMultiByte(CP_ACP, 0, - absolute_dll_filename, absolute_dll_filename_size, - NULL, 0, NULL, NULL); - if (ansi_dll_filename_size == 0) { - win32_base_dir = grn_strdup_raw("."); - } else { - char *path; - win32_base_dir = malloc(ansi_dll_filename_size + 1); - WideCharToMultiByte(CP_ACP, 0, - absolute_dll_filename, absolute_dll_filename_size, - win32_base_dir, ansi_dll_filename_size, - NULL, NULL); - win32_base_dir[ansi_dll_filename_size] = '\0'; - if ((path = strrchr(win32_base_dir, '\\'))) { - *path = '\0'; - } - path = strrchr(win32_base_dir, '\\'); - if (path && (grn_strcasecmp(path + 1, "bin") == 0 || - grn_strcasecmp(path + 1, "lib") == 0)) { - *path = '\0'; - } else { - path = win32_base_dir + strlen(win32_base_dir); - *path = '\0'; - } - for (path = win32_base_dir; *path; path++) { - if (*path == '\\') { - *path = '/'; - } - } - } - } - } - return win32_base_dir; -} -#endif - -#ifdef WIN32 int grn_mkstemp(char *path_template) { Added: lib/windows.c (+74 -0) 100644 =================================================================== --- /dev/null +++ lib/windows.c 2015-10-17 17:49:39 +0900 (5e1f723) @@ -0,0 +1,74 @@ +/* -*- c-basic-offset: 2 -*- */ +/* + Copyright(C) 2010-2015 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 <groonga.h> + +#ifdef WIN32 +static char *windows_base_dir = NULL; +const char * +grn_windows_base_dir(void) +{ + if (!windows_base_dir) { + HMODULE dll; + const wchar_t *dll_filename = GRN_DLL_FILENAME; + wchar_t absolute_dll_filename[MAX_PATH]; + DWORD absolute_dll_filename_size; + dll = GetModuleHandleW(dll_filename); + absolute_dll_filename_size = GetModuleFileNameW(dll, + absolute_dll_filename, + MAX_PATH); + if (absolute_dll_filename_size == 0) { + windows_base_dir = grn_strdup_raw("."); + } else { + DWORD ansi_dll_filename_size; + ansi_dll_filename_size = + WideCharToMultiByte(CP_ACP, 0, + absolute_dll_filename, absolute_dll_filename_size, + NULL, 0, NULL, NULL); + if (ansi_dll_filename_size == 0) { + windows_base_dir = grn_strdup_raw("."); + } else { + char *path; + windows_base_dir = malloc(ansi_dll_filename_size + 1); + WideCharToMultiByte(CP_ACP, 0, + absolute_dll_filename, absolute_dll_filename_size, + windows_base_dir, ansi_dll_filename_size, + NULL, NULL); + windows_base_dir[ansi_dll_filename_size] = '\0'; + if ((path = strrchr(windows_base_dir, '\\'))) { + *path = '\0'; + } + path = strrchr(windows_base_dir, '\\'); + if (path && (grn_strcasecmp(path + 1, "bin") == 0 || + grn_strcasecmp(path + 1, "lib") == 0)) { + *path = '\0'; + } else { + path = windows_base_dir + strlen(windows_base_dir); + *path = '\0'; + } + for (path = windows_base_dir; *path; path++) { + if (*path == '\\') { + *path = '/'; + } + } + } + } + } + return windows_base_dir; +} +#endif Modified: src/groonga.c (+8 -6) =================================================================== --- src/groonga.c 2015-10-17 16:43:12 +0900 (0e06f0b) +++ src/groonga.c 2015-10-17 17:49:39 +0900 (8a35b6b) @@ -2477,17 +2477,19 @@ init_default_settings(void) #ifdef WIN32 { - static char win32_default_document_root[PATH_MAX]; - size_t document_root_length = strlen(grn_win32_base_dir()) + 1 + + static char windows_default_document_root[PATH_MAX]; + size_t document_root_length = strlen(grn_windows_base_dir()) + 1 + strlen(GRN_DEFAULT_RELATIVE_DOCUMENT_ROOT) + 1; if (document_root_length >= PATH_MAX) { fprintf(stderr, "can't use default root: too long path\n"); } else { - grn_strcpy(win32_default_document_root, PATH_MAX, grn_win32_base_dir()); - grn_strcat(win32_default_document_root, PATH_MAX, "/"); - grn_strcat(win32_default_document_root, PATH_MAX, + grn_strcpy(windows_default_document_root, PATH_MAX, + grn_windows_base_dir()); + grn_strcat(windows_default_document_root, PATH_MAX, + "/"); + grn_strcat(windows_default_document_root, PATH_MAX, GRN_DEFAULT_RELATIVE_DOCUMENT_ROOT); - default_document_root = win32_default_document_root; + default_document_root = windows_default_document_root; } } #else -------------- next part -------------- HTML����������������������������...Download