@@ -35,12 +35,12 @@ generate(const idl_pstate_t *pstate, const idlc_generator_config_t *config)
3535 idlpy_ctx ctx ;
3636 idl_retcode_t ret = IDL_RETCODE_NO_MEMORY ;
3737
38- const char * sep , * file , * path , * ext ;
38+ const char * sep , * file , * path , * ext , * dir ;
39+ char empty [1 ] = {'\0' };
3940 char * basename = NULL ;
4041
4142 assert (pstate -> paths );
4243 assert (pstate -> paths -> name );
43- (void ) config ;
4444
4545 path = pstate -> sources -> path -> name ;
4646 sep = ext = NULL ;
@@ -52,10 +52,28 @@ generate(const idl_pstate_t *pstate, const idlc_generator_config_t *config)
5252 }
5353
5454 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 ;
5559 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 )
5667 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 = "./" ;
5775
58- ctx = idlpy_ctx_new ("./" , basename , prefix_root_module );
76+ ctx = idlpy_ctx_new (output_path , basename , prefix_root_module );
5977
6078 // Enter root
6179 if (idlpy_ctx_enter_module (ctx , "" ) != IDL_VISIT_REVISIT ) {
@@ -92,4 +110,5 @@ static const idlc_option_t *opts[] = {
92110const idlc_option_t * * generator_options (void )
93111{
94112 return opts ;
95- }
113+ }
114+
0 commit comments