9
9
#include "mruby/ext/io.h"
10
10
11
11
#if defined(_WIN32 ) || defined(_WIN64 )
12
+ #include <windows.h>
13
+ #include <stdio.h>
14
+ #include <string.h>
12
15
#define SYSTEM_SHELL "cmd.exe"
13
16
#define DEFAULT_JAVA_OPTS ""
14
17
#define IS_WINDOWS "true"
22
25
#define IS_WINDOWS "false"
23
26
#endif
24
27
28
+ mrb_value mrb_cygpath (mrb_state * mrb )
29
+ {
30
+ #if defined(_WIN32 ) || defined(_WIN64 )
31
+ char * windowsPath = NULL ;
32
+ char psBuffer [128 ];
33
+ FILE * pPipe ;
34
+ mrb_value * argv ;
35
+ mrb_int argc ;
36
+ char cmd [32 * 1024 ] = "cygpath -w -p " ;
37
+
38
+ mrb_get_args (mrb , "*" , & argv , & argc );
39
+
40
+ const char * cygwinPath = mrb_string_value_cstr (mrb , & argv [0 ]);
41
+ strcat (cmd , cygwinPath );
42
+
43
+ if ( (pPipe = _popen (cmd , "rt" )) == NULL )
44
+ mrb_raise (mrb , E_RUNTIME_ERROR , "Could not execute cygpath" );
45
+
46
+ windowsPath = fgets (psBuffer , 128 , pPipe );
47
+ _pclose (pPipe );
48
+
49
+ return mrb_str_new_cstr (mrb , windowsPath );
50
+ #else
51
+ mrb_raise (mrb , E_RUNTIME_ERROR , "Could not execute cygpath outside of Windows" );
52
+ #endif
53
+ }
54
+
25
55
mrb_bool mrb_is_windows (mrb_state * mrb )
26
56
{
27
57
#if defined(_WIN32 ) || defined(_WIN64 )
28
58
return TRUE;
29
59
#else
30
- return NULL ;
60
+ return FALSE ;
31
61
#endif
32
62
}
33
63
@@ -37,6 +67,8 @@ mrb_init_jruby_support(mrb_state *mrb)
37
67
struct RClass * c ;
38
68
c = mrb_define_class (mrb , "JRubySupport" , mrb -> object_class );
39
69
70
+ mrb_define_class_method (mrb , c , "cygpath" , mrb_cygpath , MRB_ARGS_ANY ());
71
+
40
72
mrb_define_const (mrb , c , "IS_WINDOWS" , mrb_str_new_cstr (mrb , IS_WINDOWS ));
41
73
mrb_define_const (mrb , c , "SYSTEM_SHELL" , mrb_str_new_cstr (mrb , SYSTEM_SHELL ));
42
74
mrb_define_const (mrb , c , "DEFAULT_JAVA_OPTS" , mrb_str_new_cstr (mrb , DEFAULT_JAVA_OPTS ));
0 commit comments