Navigation Menu

Skip to content

Commit

Permalink
windows: use "windows" instead of "win32"
Browse files Browse the repository at this point in the history
Because we also support win64.
  • Loading branch information
kou committed Oct 17, 2015
1 parent 40f20ee commit ec931d9
Show file tree
Hide file tree
Showing 10 changed files with 145 additions and 81 deletions.
1 change: 1 addition & 0 deletions include/groonga.h
Expand Up @@ -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 */
2 changes: 2 additions & 0 deletions include/groonga/plugin.h
Expand Up @@ -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);
Expand Down
34 changes: 34 additions & 0 deletions include/groonga/windows.h
@@ -0,0 +1,34 @@
/*
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
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.
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
*/

#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 */
1 change: 0 additions & 1 deletion lib/grn_util.h
Expand Up @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions lib/mrb.c
Expand Up @@ -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 */
Expand Down
26 changes: 16 additions & 10 deletions lib/plugin.c
Expand Up @@ -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 */
Expand Down Expand Up @@ -1023,9 +1023,15 @@ 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 */
Expand Down
1 change: 1 addition & 0 deletions lib/sources.am
Expand Up @@ -76,4 +76,5 @@ libgroonga_la_SOURCES = \
token_filter.c \
util.c \
grn_util.h \
windows.c \
windows_event_logger.c
55 changes: 0 additions & 55 deletions lib/util.c
Expand Up @@ -1317,61 +1317,6 @@ grn_p_expr_code(grn_ctx *ctx, grn_expr_code *code)
grn_obj_unlink(ctx, &buffer);
}

#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)
Expand Down
74 changes: 74 additions & 0 deletions lib/windows.c
@@ -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
14 changes: 8 additions & 6 deletions src/groonga.c
Expand Up @@ -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
Expand Down

0 comments on commit ec931d9

Please sign in to comment.