From 919237127dacfc36f1eb8bbd6f5efc6324eb03ca Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Mon, 7 May 2012 10:25:24 +0200 Subject: [PATCH] fex2bin: call generate_bin() and write data out on success --- fex2bin.c | 24 ++++++++++++++++++++---- script_bin.c | 8 +++++++- script_bin.h | 3 +++ 3 files changed, 30 insertions(+), 5 deletions(-) diff --git a/fex2bin.c b/fex2bin.c index 71bb95e..d9e846b 100644 --- a/fex2bin.c +++ b/fex2bin.c @@ -234,8 +234,6 @@ int main(int argc, char *argv[]) const char *fn[] = {"stdin", "stdout"}; struct script *script; - pr_info("WARNING: this tool is still not functional, sorry\n"); - if (argc>1) { if (strcmp(argv[1],"-") == 0) ; /* we are using stdin anyway */ @@ -262,11 +260,29 @@ int main(int argc, char *argv[]) if (parse_fex(in, fn[0], script)) { size_t sections, entries, bin_size; + void *bin; bin_size = calculate_bin_size(script, §ions, &entries); - ret = 0; + bin = calloc(1, bin_size); + if (!bin) + perror("malloc"); + else if (generate_bin(bin, bin_size, script, sections, entries)) { - (void)bin_size; + while(bin_size) { + ssize_t wc = write(out, bin, bin_size); + + if (wc>0) { + bin += wc; + bin_size -= wc; + } else if (wc < 0 && errno != EINTR) { + pr_err("%s: write: %s\n", fn[2], + strerror(errno)); + break; + } + } + if (bin_size == 0) + ret = 0; + } } script_delete(script); diff --git a/script_bin.c b/script_bin.c index 5face09..7098fa8 100644 --- a/script_bin.c +++ b/script_bin.c @@ -87,4 +87,10 @@ size_t calculate_bin_size(struct script *script, bin_size); return bin_size; } -#undef WORDS + +int generate_bin(void *bin, size_t bin_size, struct script *script, + size_t sections, size_t entries) +{ + pr_err("bin generation not yet implemented\n"); + return 0; +} diff --git a/script_bin.h b/script_bin.h index b3f76b2..5604c24 100644 --- a/script_bin.h +++ b/script_bin.h @@ -19,4 +19,7 @@ size_t calculate_bin_size(struct script *script, size_t *sections, size_t *entries); + +int generate_bin(void *bin, size_t bin_size, struct script *script, + size_t sections, size_t entries); #endif