2014-09-23 12:48:16 -07:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2014-02-13 06:21:25 -08:00
|
|
|
#include <getopt.h>
|
2014-07-23 11:37:03 -07:00
|
|
|
#include <libgen.h>
|
2014-02-13 06:21:25 -08:00
|
|
|
|
2014-02-11 05:42:59 -08:00
|
|
|
#include <Eina.h>
|
|
|
|
|
|
|
|
#include "Eolian.h"
|
|
|
|
#include "legacy_generator.h"
|
2014-06-05 00:11:13 -07:00
|
|
|
#include "eo_generator.h"
|
2014-05-01 05:07:26 -07:00
|
|
|
#include "impl_generator.h"
|
2014-07-24 01:55:08 -07:00
|
|
|
#include "types_generator.h"
|
2014-02-20 01:53:01 -08:00
|
|
|
#include "common_funcs.h"
|
2014-02-11 05:42:59 -08:00
|
|
|
|
2014-07-21 08:00:57 -07:00
|
|
|
static Eina_Strbuf *
|
2014-07-21 04:43:17 -07:00
|
|
|
_include_guard_enclose(const char *fname, const char *suffix, Eina_Strbuf *fbody)
|
2014-02-25 07:27:38 -08:00
|
|
|
{
|
2014-03-07 00:43:56 -08:00
|
|
|
char incname[255];
|
2014-07-21 08:00:57 -07:00
|
|
|
if (!fbody || !eina_strbuf_string_get(fbody)) return fbody;
|
2014-03-07 00:43:56 -08:00
|
|
|
memset(incname, 0, sizeof(incname));
|
|
|
|
strncpy (incname, fname, sizeof(incname) - 1);
|
2014-02-25 07:27:38 -08:00
|
|
|
char *p = incname;
|
|
|
|
eina_str_toupper(&p);
|
|
|
|
|
|
|
|
Eina_Strbuf *incguard = eina_strbuf_new();
|
|
|
|
eina_strbuf_append_printf(incguard,
|
2014-07-21 04:43:17 -07:00
|
|
|
"#ifndef _%s_%s\n#define _%s_%s\n\n",
|
|
|
|
incname, suffix?suffix:"",
|
|
|
|
incname, suffix?suffix:"");
|
2014-02-25 07:27:38 -08:00
|
|
|
eina_strbuf_replace_all(incguard, ".", "_");
|
2014-07-21 04:43:17 -07:00
|
|
|
eina_strbuf_append(incguard, eina_strbuf_string_get(fbody));
|
|
|
|
eina_strbuf_append(incguard, "\n#endif\n");
|
2014-07-21 08:00:57 -07:00
|
|
|
eina_strbuf_free(fbody);
|
|
|
|
return incguard;
|
2014-02-25 07:27:38 -08:00
|
|
|
}
|
|
|
|
|
2014-03-03 08:00:45 -08:00
|
|
|
static const char *
|
|
|
|
_filename_get(const char *path)
|
|
|
|
{
|
|
|
|
char *result = NULL;
|
|
|
|
|
|
|
|
if (!path) return NULL;
|
|
|
|
if ((result = strrchr(path, '/'))) result++;
|
|
|
|
else result = (char *)path;
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2014-02-11 05:42:59 -08:00
|
|
|
static Eina_Bool
|
2014-07-21 04:43:17 -07:00
|
|
|
_read_file(char *filename, Eina_Strbuf *buffer)
|
2014-05-01 05:07:26 -07:00
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_FALSE;
|
|
|
|
long file_size = 0;
|
2014-07-21 04:43:17 -07:00
|
|
|
eina_strbuf_reset(buffer);
|
2014-05-01 05:07:26 -07:00
|
|
|
|
2014-07-21 08:00:57 -07:00
|
|
|
FILE *fd = fopen(filename, "rb");
|
2014-05-02 09:20:10 -07:00
|
|
|
if (fd)
|
2014-05-01 05:07:26 -07:00
|
|
|
{
|
2014-05-02 09:20:10 -07:00
|
|
|
fseek(fd, 0, SEEK_END);
|
|
|
|
file_size = ftell(fd);
|
2014-05-26 22:18:33 -07:00
|
|
|
if (file_size <= 0)
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not get length of '%s'\n", filename);
|
2014-05-26 22:18:33 -07:00
|
|
|
goto end;
|
|
|
|
}
|
2014-05-02 09:20:10 -07:00
|
|
|
fseek(fd, 0, SEEK_SET);
|
|
|
|
char *content = malloc(file_size + 1);
|
|
|
|
if (!content)
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not allocate memory for '%s'\n", filename);
|
2014-05-26 22:18:33 -07:00
|
|
|
goto end;
|
|
|
|
}
|
2014-08-04 02:56:15 -07:00
|
|
|
long actual_size = (long)fread(content, 1, file_size, fd);
|
2014-08-04 01:58:32 -07:00
|
|
|
if (actual_size != file_size)
|
2014-05-26 22:18:33 -07:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not read %ld bytes from '%s' (read %ld bytes)\n",
|
2014-08-04 02:56:15 -07:00
|
|
|
file_size, filename, actual_size);
|
2014-05-26 22:18:33 -07:00
|
|
|
free(content);
|
2014-05-02 09:20:10 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2014-05-26 22:18:33 -07:00
|
|
|
content[file_size] = '\0';
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
eina_strbuf_append(buffer, content);
|
|
|
|
free(content);
|
2014-05-29 05:41:10 -07:00
|
|
|
#ifdef _WIN32
|
|
|
|
eina_strbuf_replace_all(buffer, "\r\n", "\n");
|
|
|
|
#endif
|
2014-05-01 05:07:26 -07:00
|
|
|
}
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
ret = EINA_TRUE;
|
|
|
|
end:
|
|
|
|
if (fd) fclose(fd);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-05-01 05:07:26 -07:00
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_write_file(char *filename, const Eina_Strbuf *buffer, Eina_Bool append)
|
|
|
|
{
|
|
|
|
const char *data = eina_strbuf_string_get(buffer);
|
|
|
|
|
|
|
|
FILE* fd = fopen(filename, append ? "ab" : "wb");
|
2014-05-01 05:07:26 -07:00
|
|
|
if (!fd)
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not open '%s' for writing (%s)\n",
|
|
|
|
filename, strerror(errno));
|
2014-07-21 04:43:17 -07:00
|
|
|
return EINA_FALSE;
|
2014-05-01 05:07:26 -07:00
|
|
|
}
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
if (data) fputs(data, fd);
|
|
|
|
fclose(fd);
|
|
|
|
return EINA_TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_generate_eo_header_file(char *filename, const char *eo_filename)
|
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_FALSE;
|
|
|
|
|
|
|
|
Eina_Strbuf *buffer = eina_strbuf_new();
|
2014-07-21 08:00:57 -07:00
|
|
|
|
2015-07-08 04:09:56 -07:00
|
|
|
if (!types_header_generate(eo_filename, buffer, EINA_TRUE, EINA_FALSE))
|
2014-07-24 01:55:08 -07:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename);
|
2014-07-24 01:55:08 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer = _include_guard_enclose(eo_filename, "TYPES", buffer);
|
|
|
|
}
|
|
|
|
|
2014-08-01 07:11:28 -07:00
|
|
|
Eina_Strbuf *ctbuf = eina_strbuf_new();
|
|
|
|
if (types_class_typedef_generate(eo_filename, ctbuf))
|
|
|
|
{
|
|
|
|
ctbuf = _include_guard_enclose(eo_filename, "CLASS_TYPE", ctbuf);
|
|
|
|
eina_strbuf_append_char(ctbuf, '\n');
|
|
|
|
eina_strbuf_prepend(buffer, eina_strbuf_string_get(ctbuf));
|
|
|
|
}
|
|
|
|
eina_strbuf_free(ctbuf);
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
const Eolian_Class *class = eolian_class_get_by_file(eo_filename);
|
|
|
|
if (class)
|
|
|
|
{
|
|
|
|
if (!eo_header_generate(class, buffer))
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate header for '%s'\n",
|
|
|
|
eolian_class_name_get(class));
|
2014-07-21 04:43:17 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
buffer = _include_guard_enclose(_filename_get(filename), NULL, buffer);
|
|
|
|
if (_write_file(filename, buffer, EINA_FALSE))
|
|
|
|
ret = EINA_TRUE;
|
2014-05-01 05:07:26 -07:00
|
|
|
end:
|
|
|
|
eina_strbuf_free(buffer);
|
2014-07-21 08:00:57 -07:00
|
|
|
|
2014-05-01 05:07:26 -07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-08-26 09:08:26 -07:00
|
|
|
static Eina_Bool
|
|
|
|
_generate_stub_header_file(char *filename, const char *eo_filename)
|
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_FALSE;
|
|
|
|
|
|
|
|
Eina_Strbuf *buffer = eina_strbuf_new();
|
|
|
|
|
2015-07-08 04:09:56 -07:00
|
|
|
if (!types_header_generate(eo_filename, buffer, EINA_FALSE, EINA_FALSE))
|
2014-08-26 09:08:26 -07:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename);
|
2014-08-26 09:08:26 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
Eina_Strbuf *ctbuf = eina_strbuf_new();
|
|
|
|
if (types_class_typedef_generate(eo_filename, ctbuf))
|
|
|
|
{
|
|
|
|
eina_strbuf_append_char(ctbuf, '\n');
|
|
|
|
eina_strbuf_prepend(buffer, eina_strbuf_string_get(ctbuf));
|
|
|
|
}
|
|
|
|
eina_strbuf_free(ctbuf);
|
|
|
|
|
|
|
|
buffer = _include_guard_enclose(_filename_get(filename), "STUBS", buffer);
|
|
|
|
if (_write_file(filename, buffer, EINA_FALSE))
|
|
|
|
ret = EINA_TRUE;
|
|
|
|
end:
|
|
|
|
eina_strbuf_free(buffer);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-11 05:42:59 -08:00
|
|
|
static Eina_Bool
|
2014-07-21 04:43:17 -07:00
|
|
|
_generate_c_file(char *filename, const char *eo_filename, Eina_Bool legacy_support)
|
2014-02-11 05:42:59 -08:00
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_FALSE;
|
2014-07-21 04:43:17 -07:00
|
|
|
|
|
|
|
Eina_Strbuf *eo_buf = eina_strbuf_new();
|
|
|
|
Eina_Strbuf *legacy_buf = eina_strbuf_new();
|
|
|
|
|
|
|
|
const Eolian_Class *class = eolian_class_get_by_file(eo_filename);
|
|
|
|
if (class)
|
2014-02-11 05:42:59 -08:00
|
|
|
{
|
2014-07-21 04:43:17 -07:00
|
|
|
if (!eo_source_generate(class, eo_buf))
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate source for '%s'\n",
|
|
|
|
eolian_class_name_get(class));
|
2014-07-21 04:43:17 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (legacy_support)
|
|
|
|
if (!legacy_source_generate(class, legacy_buf))
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate source for '%s'\n",
|
|
|
|
eolian_class_name_get(class));
|
2014-07-21 04:43:17 -07:00
|
|
|
goto end;
|
|
|
|
}
|
2014-02-11 05:42:59 -08:00
|
|
|
}
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
if (_write_file(filename, eo_buf, EINA_FALSE) &&
|
|
|
|
_write_file(filename, legacy_buf, EINA_TRUE))
|
|
|
|
ret = EINA_TRUE;
|
|
|
|
end:
|
|
|
|
eina_strbuf_free(legacy_buf);
|
|
|
|
eina_strbuf_free(eo_buf);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static Eina_Bool
|
|
|
|
_generate_impl_c_file(char *filename, const char *eo_filename)
|
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_FALSE;
|
|
|
|
Eina_Strbuf *buffer = eina_strbuf_new();
|
2014-07-21 08:00:57 -07:00
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
const Eolian_Class *class = eolian_class_get_by_file(eo_filename);
|
|
|
|
if (class)
|
2014-02-25 07:27:38 -08:00
|
|
|
{
|
2014-07-21 04:43:17 -07:00
|
|
|
if (!_read_file(filename, buffer)) goto end;
|
|
|
|
|
|
|
|
if (!impl_source_generate(class, buffer))
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate source for '%s'\n",
|
|
|
|
eolian_class_name_get(class));
|
2014-07-21 04:43:17 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (_write_file(filename, buffer, EINA_FALSE))
|
|
|
|
ret = EINA_TRUE;
|
2014-02-25 07:27:38 -08:00
|
|
|
}
|
2014-07-21 04:43:17 -07:00
|
|
|
end:
|
|
|
|
eina_strbuf_free(buffer);
|
|
|
|
return ret;
|
|
|
|
}
|
2014-02-25 07:27:38 -08:00
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
// TODO join with header gen.
|
|
|
|
static Eina_Bool
|
|
|
|
_generate_legacy_header_file(char *filename, const char *eo_filename)
|
|
|
|
{
|
|
|
|
Eina_Bool ret = EINA_FALSE;
|
2014-07-21 08:00:57 -07:00
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
Eina_Strbuf *buffer = eina_strbuf_new();
|
2014-02-11 05:42:59 -08:00
|
|
|
|
2015-07-08 04:09:56 -07:00
|
|
|
if (!types_header_generate(eo_filename, buffer, EINA_TRUE, EINA_TRUE))
|
2014-07-24 01:55:08 -07:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate types of '%s'\n", eo_filename);
|
2014-07-24 01:55:08 -07:00
|
|
|
goto end;
|
|
|
|
}
|
2014-08-22 06:40:01 -07:00
|
|
|
else
|
|
|
|
{
|
|
|
|
buffer = _include_guard_enclose(eo_filename, "TYPES", buffer);
|
|
|
|
}
|
2014-07-24 01:55:08 -07:00
|
|
|
|
2014-08-01 07:11:28 -07:00
|
|
|
Eina_Strbuf *ctbuf = eina_strbuf_new();
|
|
|
|
if (types_class_typedef_generate(eo_filename, ctbuf))
|
|
|
|
{
|
|
|
|
ctbuf = _include_guard_enclose(eo_filename, "CLASS_TYPE", ctbuf);
|
|
|
|
eina_strbuf_append_char(ctbuf, '\n');
|
|
|
|
eina_strbuf_prepend(buffer, eina_strbuf_string_get(ctbuf));
|
|
|
|
}
|
|
|
|
eina_strbuf_free(ctbuf);
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
const Eolian_Class *class = eolian_class_get_by_file(eo_filename);
|
|
|
|
if (class)
|
|
|
|
{
|
|
|
|
if (!legacy_header_generate(class, buffer))
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not generate header for '%s'\n",
|
|
|
|
eolian_class_name_get(class));
|
2014-07-21 04:43:17 -07:00
|
|
|
goto end;
|
|
|
|
}
|
2014-07-21 08:00:57 -07:00
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
buffer = _include_guard_enclose(_filename_get(filename), NULL, buffer);
|
|
|
|
if (_write_file(filename, buffer, EINA_FALSE))
|
|
|
|
ret = EINA_TRUE;
|
|
|
|
}
|
|
|
|
end:
|
|
|
|
eina_strbuf_free(buffer);
|
2014-02-11 05:42:59 -08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2014-02-20 01:53:01 -08:00
|
|
|
enum
|
|
|
|
{
|
|
|
|
NO_WAY_GEN,
|
|
|
|
H_GEN,
|
2014-08-26 09:08:26 -07:00
|
|
|
H_STUB_GEN,
|
2014-05-01 05:07:26 -07:00
|
|
|
C_GEN,
|
|
|
|
C_IMPL_GEN
|
2014-02-20 01:53:01 -08:00
|
|
|
};
|
2014-04-22 22:55:15 -07:00
|
|
|
static int gen_opt = NO_WAY_GEN;
|
|
|
|
static int eo_needed = 0;
|
2014-05-26 05:37:33 -07:00
|
|
|
static int legacy_support = 0;
|
2014-02-20 01:53:01 -08:00
|
|
|
|
2015-05-20 00:34:58 -07:00
|
|
|
#define EO_SUFFIX ".eo"
|
|
|
|
#define EOT_SUFFIX ".eot"
|
|
|
|
|
2014-02-11 05:42:59 -08:00
|
|
|
int main(int argc, char **argv)
|
|
|
|
{
|
2014-02-18 07:01:17 -08:00
|
|
|
int ret = 1;
|
2015-06-17 06:26:07 -07:00
|
|
|
Eina_Bool help = EINA_FALSE;
|
2014-07-21 04:43:17 -07:00
|
|
|
const char *eo_filename = NULL;
|
2014-02-20 01:53:01 -08:00
|
|
|
char *output_filename = NULL; /* if NULL, have to generate, otherwise use the name stored there */
|
2014-07-21 04:43:17 -07:00
|
|
|
char *eo_filename_copy = NULL, *eo_file_basename;
|
2015-05-20 00:34:58 -07:00
|
|
|
Eina_Bool is_eo = EINA_FALSE;
|
2014-02-11 05:42:59 -08:00
|
|
|
|
2014-02-18 07:01:17 -08:00
|
|
|
eina_init();
|
|
|
|
eolian_init();
|
|
|
|
|
2014-02-20 01:53:01 -08:00
|
|
|
const char *log_dom = "eolian_gen";
|
|
|
|
_eolian_gen_log_dom = eina_log_domain_register(log_dom, EINA_COLOR_GREEN);
|
|
|
|
if (_eolian_gen_log_dom < 0)
|
|
|
|
{
|
|
|
|
EINA_LOG_ERR("Could not register log domain: %s", log_dom);
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
|
|
|
eina_log_timing(_eolian_gen_log_dom,
|
|
|
|
EINA_LOG_STATE_STOP,
|
|
|
|
EINA_LOG_STATE_INIT);
|
|
|
|
|
2014-02-13 06:21:25 -08:00
|
|
|
static struct option long_options[] =
|
2014-02-11 05:42:59 -08:00
|
|
|
{
|
2014-02-13 06:21:25 -08:00
|
|
|
/* These options set a flag. */
|
2014-04-22 22:55:15 -07:00
|
|
|
{"eo", no_argument, &eo_needed, 1},
|
2014-02-13 06:21:25 -08:00
|
|
|
{"help", no_argument, 0, 'h'},
|
2014-02-20 01:53:01 -08:00
|
|
|
{"gh", no_argument, &gen_opt, H_GEN},
|
|
|
|
{"gc", no_argument, &gen_opt, C_GEN},
|
2014-05-01 05:07:26 -07:00
|
|
|
{"gi", no_argument, &gen_opt, C_IMPL_GEN},
|
2014-08-26 09:08:26 -07:00
|
|
|
{"gs", no_argument, &gen_opt, H_STUB_GEN},
|
2014-02-20 01:53:01 -08:00
|
|
|
{"output", required_argument, 0, 'o'},
|
2014-05-26 05:37:33 -07:00
|
|
|
{"legacy", no_argument, &legacy_support, 1},
|
2014-02-13 06:21:25 -08:00
|
|
|
{"include", required_argument, 0, 'I'},
|
|
|
|
{0, 0, 0, 0}
|
|
|
|
};
|
|
|
|
int long_index =0, opt;
|
2014-02-18 07:01:17 -08:00
|
|
|
while ((opt = getopt_long(argc, argv,"vho:I:", long_options, &long_index )) != -1)
|
2014-02-13 06:21:25 -08:00
|
|
|
{
|
|
|
|
switch (opt) {
|
|
|
|
case 0: break;
|
2014-02-20 01:53:01 -08:00
|
|
|
case 'o':
|
|
|
|
{
|
|
|
|
output_filename = strdup(optarg);
|
|
|
|
break;
|
|
|
|
}
|
2014-02-13 06:21:25 -08:00
|
|
|
case 'h': help = EINA_TRUE; break;
|
|
|
|
case 'I':
|
|
|
|
{
|
2014-02-17 23:01:23 -08:00
|
|
|
const char *dir = optarg;
|
2014-04-27 00:03:39 -07:00
|
|
|
if (!eolian_directory_scan(dir))
|
2014-02-13 06:21:25 -08:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: could not scan '%s'\n", dir);
|
2014-04-27 00:03:39 -07:00
|
|
|
goto end;
|
2014-02-13 06:21:25 -08:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: help = EINA_TRUE;
|
|
|
|
}
|
2014-02-11 05:42:59 -08:00
|
|
|
}
|
2014-07-21 04:43:17 -07:00
|
|
|
eo_filename = argv[optind++];
|
2014-02-11 05:42:59 -08:00
|
|
|
|
2014-02-18 07:01:17 -08:00
|
|
|
if (help)
|
2014-02-11 05:42:59 -08:00
|
|
|
{
|
2015-06-17 06:26:07 -07:00
|
|
|
printf("Usage: %s [-h/--help] [-I/--include input_dir] [--legacy] [--gh|--gc|--gi] [--output/-o outfile] file.eo ... \n", argv[0]);
|
2014-02-20 01:53:01 -08:00
|
|
|
printf(" --help/-h Print that help\n");
|
|
|
|
printf(" --include/-I Include 'input_dir' as directory to search .eo files into\n");
|
|
|
|
printf(" --output/-o Force output filename to 'outfile'\n");
|
2014-04-17 05:50:22 -07:00
|
|
|
printf(" --eo Set generator to eo mode. Must be specified\n");
|
2014-05-01 05:07:26 -07:00
|
|
|
printf(" --gh Generate C header file [.h]\n");
|
2014-08-26 09:08:26 -07:00
|
|
|
printf(" --gs Generate C type stubs [.h]\n");
|
2014-05-01 05:07:26 -07:00
|
|
|
printf(" --gc Generate C source file [.c]\n");
|
|
|
|
printf(" --gi Generate C implementation source file [.c]. The output will be a series of functions that have to be filled.\n");
|
2014-02-13 07:12:19 -08:00
|
|
|
printf(" --legacy Generate legacy\n");
|
2014-02-18 07:01:17 -08:00
|
|
|
ret = 0;
|
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
if (!eo_filename)
|
2014-02-18 07:01:17 -08:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: no input file specified\n");
|
2014-02-18 07:01:17 -08:00
|
|
|
goto end;
|
2014-02-11 05:42:59 -08:00
|
|
|
}
|
|
|
|
|
2015-05-20 00:34:58 -07:00
|
|
|
is_eo = eina_str_has_suffix(eo_filename, EO_SUFFIX);
|
|
|
|
|
2015-05-22 09:32:21 -07:00
|
|
|
if (!eolian_file_parse(eo_filename))
|
2014-02-17 23:01:23 -08:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: error parsing file '%s'\n", eo_filename);
|
2014-07-21 04:43:17 -07:00
|
|
|
goto end;
|
2014-02-17 23:01:23 -08:00
|
|
|
}
|
|
|
|
|
2014-08-21 08:34:40 -07:00
|
|
|
if (!eolian_database_validate())
|
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: error validating database\n");
|
2014-08-21 08:34:40 -07:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2014-07-21 04:43:17 -07:00
|
|
|
eo_filename_copy = strdup(eo_filename);
|
|
|
|
eo_file_basename = basename(eo_filename_copy);
|
2014-02-11 05:42:59 -08:00
|
|
|
|
2015-05-20 00:34:58 -07:00
|
|
|
/* Only needed for .eo files */
|
|
|
|
if (is_eo && !eo_needed && !(gen_opt == H_GEN && legacy_support))
|
2014-02-11 05:42:59 -08:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
/* FIXME: perhaps ditch this completely */
|
|
|
|
fprintf(stderr, "eolian: --eo not specified\n");
|
2014-02-11 05:42:59 -08:00
|
|
|
goto end;
|
|
|
|
}
|
|
|
|
|
2014-02-20 01:53:01 -08:00
|
|
|
if (gen_opt)
|
2014-02-11 05:42:59 -08:00
|
|
|
{
|
2014-02-20 01:53:01 -08:00
|
|
|
if (!output_filename)
|
2014-02-16 06:09:06 -08:00
|
|
|
{
|
2015-05-29 06:57:14 -07:00
|
|
|
fprintf(stderr, "eolian: no output file specified\n");
|
2014-05-01 05:07:26 -07:00
|
|
|
goto end;
|
2014-02-16 06:09:06 -08:00
|
|
|
}
|
2014-02-20 01:53:01 -08:00
|
|
|
switch (gen_opt)
|
|
|
|
{
|
2014-03-20 08:33:25 -07:00
|
|
|
case H_GEN:
|
2014-02-20 01:53:01 -08:00
|
|
|
{
|
2014-03-20 08:33:25 -07:00
|
|
|
INF("Generating header file %s\n", output_filename);
|
2014-02-25 07:27:38 -08:00
|
|
|
if (legacy_support)
|
2014-07-21 04:43:17 -07:00
|
|
|
ret = ( _generate_legacy_header_file(output_filename, eo_file_basename) ? 0 : 1 );
|
2014-02-25 07:27:38 -08:00
|
|
|
else
|
2014-07-21 04:43:17 -07:00
|
|
|
ret = ( _generate_eo_header_file(output_filename, eo_file_basename) ? 0 : 1 );
|
2014-02-20 01:53:01 -08:00
|
|
|
break;
|
|
|
|
}
|
2014-08-26 09:08:26 -07:00
|
|
|
case H_STUB_GEN:
|
|
|
|
{
|
|
|
|
INF("Generating stubs header file %s\n", output_filename);
|
|
|
|
ret = _generate_stub_header_file(output_filename, eo_file_basename) ? 0 : 1;
|
|
|
|
break;
|
|
|
|
}
|
2014-02-20 01:53:01 -08:00
|
|
|
case C_GEN:
|
|
|
|
{
|
|
|
|
INF("Generating source file %s\n", output_filename);
|
2014-07-21 04:43:17 -07:00
|
|
|
ret = _generate_c_file(output_filename, eo_file_basename, !!legacy_support)?0:1;
|
2014-02-20 01:53:01 -08:00
|
|
|
break;
|
|
|
|
}
|
2014-05-01 05:07:26 -07:00
|
|
|
case C_IMPL_GEN:
|
|
|
|
{
|
|
|
|
INF("Generating user source file %s\n", output_filename);
|
2014-07-21 04:43:17 -07:00
|
|
|
ret = _generate_impl_c_file(output_filename, eo_file_basename) ? 0 : 1;
|
2014-05-01 05:07:26 -07:00
|
|
|
break;
|
|
|
|
}
|
2014-02-20 01:53:01 -08:00
|
|
|
default:
|
2014-02-20 03:54:12 -08:00
|
|
|
ERR("Bad generation option\n");
|
|
|
|
break;
|
2014-02-20 01:53:01 -08:00
|
|
|
}
|
2014-02-11 05:42:59 -08:00
|
|
|
}
|
2014-02-20 03:54:12 -08:00
|
|
|
else ret = 0;
|
2014-02-11 05:42:59 -08:00
|
|
|
|
|
|
|
end:
|
2014-07-21 04:43:17 -07:00
|
|
|
free(eo_filename_copy);
|
2014-06-19 04:02:46 -07:00
|
|
|
free(output_filename);
|
2014-02-20 01:53:01 -08:00
|
|
|
|
|
|
|
eina_log_timing(_eolian_gen_log_dom,
|
|
|
|
EINA_LOG_STATE_START,
|
|
|
|
EINA_LOG_STATE_SHUTDOWN);
|
|
|
|
eina_log_domain_unregister(_eolian_gen_log_dom);
|
|
|
|
_eolian_gen_log_dom = -1;
|
|
|
|
|
2014-02-11 05:42:59 -08:00
|
|
|
eolian_shutdown();
|
|
|
|
eina_shutdown();
|
|
|
|
return ret;
|
|
|
|
}
|