28 #define BUFFER_SIZE 2048
32 static char *win32_ruby_scripts_dir = NULL;
33 static char win32_ruby_scripts_dir_buffer[
PATH_MAX];
35 grn_mrb_get_system_ruby_scripts_dir(
void)
37 if (!win32_ruby_scripts_dir) {
39 const char *relative_path = GRN_RELATIVE_RUBY_SCRIPTS_DIR;
41 size_t base_dir_length;
44 base_dir_length = strlen(base_dir);
45 strcpy(win32_ruby_scripts_dir_buffer, base_dir);
46 strcat(win32_ruby_scripts_dir_buffer,
"/");
47 strcat(win32_ruby_scripts_dir_buffer, relative_path);
48 win32_ruby_scripts_dir = win32_ruby_scripts_dir_buffer;
50 return win32_ruby_scripts_dir;
55 grn_mrb_get_system_ruby_scripts_dir(
void)
57 return GRN_RUBY_SCRIPTS_DIR;
62 grn_mrb_open_script(
grn_ctx *ctx,
const char *path)
64 const char *ruby_scripts_dir;
67 int path_length, max_path_length;
68 FILE *script_file = NULL;
71 expanded_path[0] =
'\0';
73 ruby_scripts_dir = getenv(
"GRN_RUBY_SCRIPTS_DIR");
74 if (!ruby_scripts_dir) {
75 ruby_scripts_dir = grn_mrb_get_system_ruby_scripts_dir();
77 strcpy(expanded_path, ruby_scripts_dir);
79 dir_last_char = ruby_scripts_dir[strlen(expanded_path) - 1];
80 if (dir_last_char !=
'/') {
81 strcat(expanded_path,
"/");
85 path_length = strlen(path);
86 max_path_length =
PATH_MAX - strlen(expanded_path) - 1;
87 if (path_length > max_path_length) {
89 "script path is too long: %d (max: %d) <%s%s>",
90 path_length, max_path_length,
95 strcat(expanded_path, path);
96 script_file = fopen(expanded_path,
"r");
100 "fopen: failed to open mruby script file: <%s>", path);
109 grn_mrb_load(
grn_ctx *ctx,
const char *path)
118 return mrb_nil_value();
121 file = grn_mrb_open_script(ctx, path);
127 return mrb_nil_value();
130 parser = mrb_parse_file(mrb, file, NULL);
143 grn_mrb_eval(
grn_ctx *ctx,
const char *script,
int script_length)
151 return mrb_nil_value();
154 if (script_length < 0) {
155 script_length = strlen(script);