Skip to content

Commit

Permalink
mrb: export system Ruby scripts directory
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Dec 22, 2014
1 parent 34bbe84 commit ec352e3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
3 changes: 2 additions & 1 deletion lib/grn_mrb.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* -*- c-basic-offset: 2 -*- */
/*
Copyright(C) 2013 Brazil
Copyright(C) 2013-2014 Brazil
This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
Expand Down Expand Up @@ -34,6 +34,7 @@ extern "C" {
GRN_API mrb_value grn_mrb_eval(grn_ctx *ctx, const char *script, int script_length);
GRN_API mrb_value grn_mrb_load(grn_ctx *ctx, const char *path);
GRN_API grn_rc grn_mrb_to_grn(grn_ctx *ctx, mrb_value mrb_object, grn_obj *grn_object);
GRN_API const char *grn_mrb_get_system_ruby_scripts_dir(grn_ctx *ctx);
#endif

#ifdef __cplusplus
Expand Down
22 changes: 16 additions & 6 deletions lib/mrb.c
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
static char *win32_ruby_scripts_dir = NULL;
static char win32_ruby_scripts_dir_buffer[PATH_MAX];
static const char *
grn_mrb_get_system_ruby_scripts_dir(void)
grn_mrb_get_default_system_ruby_scripts_dir(void)
{
if (!win32_ruby_scripts_dir) {
const char *base_dir;
Expand All @@ -53,12 +53,25 @@ grn_mrb_get_system_ruby_scripts_dir(void)

# else /* WIN32 */
static const char *
grn_mrb_get_system_ruby_scripts_dir(void)
grn_mrb_get_default_system_ruby_scripts_dir(void)
{
return GRN_RUBY_SCRIPTS_DIR;
}
# endif /* WIN32 */

const char *
grn_mrb_get_system_ruby_scripts_dir(grn_ctx *ctx)
{
const char *ruby_scripts_dir;

ruby_scripts_dir = getenv("GRN_RUBY_SCRIPTS_DIR");
if (!ruby_scripts_dir) {
ruby_scripts_dir = grn_mrb_get_default_system_ruby_scripts_dir();
}

return ruby_scripts_dir;
}

static grn_bool
grn_mrb_expand_script_path(grn_ctx *ctx, const char *path, char *expanded_path)
{
Expand All @@ -72,10 +85,7 @@ grn_mrb_expand_script_path(grn_ctx *ctx, const char *path, char *expanded_path)
strcpy(expanded_path, ctx->impl->mrb.base_directory);
strcat(expanded_path, "/");
} else {
ruby_scripts_dir = getenv("GRN_RUBY_SCRIPTS_DIR");
if (!ruby_scripts_dir) {
ruby_scripts_dir = grn_mrb_get_system_ruby_scripts_dir();
}
ruby_scripts_dir = grn_mrb_get_system_ruby_scripts_dir(ctx);
strcpy(expanded_path, ruby_scripts_dir);

dir_last_char = ruby_scripts_dir[strlen(expanded_path) - 1];
Expand Down

0 comments on commit ec352e3

Please sign in to comment.