@@ -35,12 +35,12 @@ generate(const idl_pstate_t *pstate, const idlc_generator_config_t *config)
35
35
idlpy_ctx ctx ;
36
36
idl_retcode_t ret = IDL_RETCODE_NO_MEMORY ;
37
37
38
- const char * sep , * file , * path , * ext ;
38
+ const char * sep , * file , * path , * ext , * dir ;
39
+ char empty [1 ] = {'\0' };
39
40
char * basename = NULL ;
40
41
41
42
assert (pstate -> paths );
42
43
assert (pstate -> paths -> name );
43
- (void ) config ;
44
44
45
45
path = pstate -> sources -> path -> name ;
46
46
sep = ext = NULL ;
@@ -52,10 +52,28 @@ generate(const idl_pstate_t *pstate, const idlc_generator_config_t *config)
52
52
}
53
53
54
54
file = sep ? sep + 1 : path ;
55
+ if (idl_isabsolute (path ) || !sep )
56
+ dir = empty ;
57
+ else if (!(dir = idl_strndup (path , (size_t )(sep - path ))))
58
+ goto err ;
55
59
if (!(basename = idl_strndup (file , ext ? (size_t )(ext - file ) : strlen (file ))))
60
+ goto err ;
61
+
62
+ char * output_dir = config -> output_dir ;
63
+ char * output_path = "./" ;
64
+ sep = dir [0 ] == '\0' ? "" : "/" ;
65
+ if (output_dir && output_dir [0 ] != '\0' ) {
66
+ if (idl_asprintf (& output_path , "%s%s%s/" , output_dir , sep , dir ) < 0 )
56
67
goto err ;
68
+ sep = "/" ;
69
+ } else {
70
+ if (!(output_path = idl_strdup (dir )))
71
+ goto err ;
72
+ }
73
+ if (!strcmp (output_path , "" ))
74
+ output_path = "./" ;
57
75
58
- ctx = idlpy_ctx_new ("./" , basename , prefix_root_module );
76
+ ctx = idlpy_ctx_new (output_path , basename , prefix_root_module );
59
77
60
78
// Enter root
61
79
if (idlpy_ctx_enter_module (ctx , "" ) != IDL_VISIT_REVISIT ) {
@@ -92,4 +110,5 @@ static const idlc_option_t *opts[] = {
92
110
const idlc_option_t * * generator_options (void )
93
111
{
94
112
return opts ;
95
- }
113
+ }
114
+
0 commit comments