eldbus: support output dir in codegen

@feature
This commit is contained in:
Mike Blumenkrantz 2017-07-17 12:57:19 -04:00
parent f1bcd804ec
commit c5155d2fcc
3 changed files with 16 additions and 1 deletions

View File

@ -4,6 +4,8 @@
#include "codegen.h"
char *output_dir = NULL;
static const Ecore_Getopt optdesc = {
"eldbus_codegen",
"%prog [options] <file.xml>",
@ -16,6 +18,7 @@ static const Ecore_Getopt optdesc = {
ECORE_GETOPT_STORE_STR('p', "prefix", "The prefix for the generated code."),
ECORE_GETOPT_STORE_STR('i', "interface", "To generate code of only one interface of xml."),
ECORE_GETOPT_STORE_STR('o', "output file name", "The name of output files, only used if a interface is selected."),
ECORE_GETOPT_STORE_STR('O', "output dir", "The directory to output files to."),
ECORE_GETOPT_LICENSE('L', "license"),
ECORE_GETOPT_COPYRIGHT('C', "copyright"),
ECORE_GETOPT_VERSION('V', "version"),
@ -36,6 +39,7 @@ main(int argc, char **argv)
ECORE_GETOPT_VALUE_STR(prefix),
ECORE_GETOPT_VALUE_STR(interface),
ECORE_GETOPT_VALUE_STR(output),
ECORE_GETOPT_VALUE_STR(output_dir),
ECORE_GETOPT_VALUE_BOOL(quit_option),
ECORE_GETOPT_VALUE_BOOL(quit_option),
ECORE_GETOPT_VALUE_BOOL(quit_option),

View File

@ -110,3 +110,5 @@ char *replace_string(const char *string, const char *substr, const char *replace
char *dbus_name_to_c(const char *dbus);
char *string_build(const char *fmt, ...);
char *get_pieces(const char *string, char break_in, int amount);
extern char *output_dir;

View File

@ -34,8 +34,16 @@ Eina_Bool
file_write(const char *file_name, const char *buffer)
{
FILE *file_handler;
const char *filename = file_name;
Eina_Strbuf *fname = NULL;
file_handler = fopen(file_name, "wt");
if (output_dir)
{
fname = eina_strbuf_new();
eina_strbuf_append_printf(fname, "%s/%s", output_dir, file_name);
filename = eina_strbuf_string_get(fname);
}
file_handler = fopen(filename, "wt");
if (!file_handler)
{
printf("Error to write file: %s\n", file_name);
@ -47,6 +55,7 @@ file_write(const char *file_name, const char *buffer)
printf("Error writing to file: %s\n", file_name);
}
fclose(file_handler);
eina_strbuf_free(fname);
return EINA_TRUE;
}