summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBoris Faure <billiob@gmail.com>2012-01-07 13:33:15 +0000
committerBoris Faure <billiob@gmail.com>2012-01-07 13:33:15 +0000
commit44509d51614a2592dc55fdb74d430e0cbe652919 (patch)
treedb3e281f15ef757f0ddaa338f07da3081866fbb7
parent873b833c8f38340af5b1181e6475e66a44cf7b2f (diff)
downloadeet-44509d51614a2592dc55fdb74d430e0cbe652919.tar.gz
eet: write to standard output if no output file given.
SVN revision: 66958
-rw-r--r--ChangeLog4
-rw-r--r--src/bin/eet_main.c88
2 files changed, 65 insertions, 27 deletions
diff --git a/ChangeLog b/ChangeLog
index 160fab8..795d102 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -560,4 +560,8 @@
2011-12-29 Carsten Haitzler (The Rasterman)
* increase eet_connection packet size to 1Mb - more reasonable.
+
+2012-01-07 Boris Faure (billiob)
+
+ * make eet tool write to standard output if no output file given.
diff --git a/src/bin/eet_main.c b/src/bin/eet_main.c
index 7ab5555..0d577ad 100644
--- a/src/bin/eet_main.c
+++ b/src/bin/eet_main.c
@@ -77,7 +77,7 @@ do_eet_extract(const char *file,
Eet_File *ef;
void *data;
int size = 0;
- FILE *f;
+ FILE *f = stdout;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
@@ -93,20 +93,23 @@ do_eet_extract(const char *file,
exit(-1);
}
- f = fopen(out, "wb");
- if (!f)
+ if (out)
{
- ERR("cannot open %s", out);
- exit(-1);
+ f = fopen(out, "wb");
+ if (!f)
+ {
+ ERR("cannot open %s", out);
+ exit(-1);
+ }
}
if (fwrite(data, size, 1, f) != 1)
{
- ERR("cannot write to %s", out);
+ ERR("cannot write to %s", out ? out : "standard output");
exit(-1);
}
- fclose(f);
+ if (out) fclose(f);
free(data);
eet_close(ef);
} /* do_eet_extract */
@@ -125,7 +128,7 @@ do_eet_decode(const char *file,
const char *crypto_key)
{
Eet_File *ef;
- FILE *f;
+ FILE *f = stdout;
ef = eet_open(file, EET_FILE_MODE_READ);
if (!ef)
@@ -134,20 +137,23 @@ do_eet_decode(const char *file,
exit(-1);
}
- f = fopen(out, "wb");
- if (!f)
+ if (out)
{
- ERR("cannot open %s", out);
- exit(-1);
+ f = fopen(out, "wb");
+ if (!f)
+ {
+ ERR("cannot open %s", out);
+ exit(-1);
+ }
}
if (!eet_data_dump_cipher(ef, key, crypto_key, do_eet_decode_dump, f))
{
- ERR("cannot write to %s", out);
+ ERR("cannot write to %s", out ? out : "standard output");
exit(-1);
}
- fclose(f);
+ if (out) fclose(f);
eet_close(ef);
} /* do_eet_decode */
@@ -352,9 +358,9 @@ main(int argc,
help:
printf(
"Usage:\n"
- " eet -l FILE.EET list all keys in FILE.EET\n"
- " eet -x FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE\n"
- " eet -d FILE.EET KEY OUT-FILE [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE\n"
+ " eet -l FILE.EET list all keys in FILE.EET\n"
+ " eet -x FILE.EET KEY [OUT-FILE] [CRYPTO_KEY] extract data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
+ " eet -d FILE.EET KEY [OUT-FILE] [CRYPTO_KEY] extract and decode data stored in KEY in FILE.EET and write to OUT-FILE or standard output\n"
" eet -i FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert data to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
" eet -e FILE.EET KEY IN-FILE COMPRESS [CRYPTO_KEY] insert and encode to KEY in FILE.EET from IN-FILE and if COMPRESS is 1, compress it\n"
" eet -r FILE.EET KEY remove KEY in FILE.EET\n"
@@ -369,19 +375,47 @@ help:
goto help;
else if ((!strcmp(argv[1], "-l")) && (argc > 2))
do_eet_list(argv[2]);
- else if ((!strcmp(argv[1], "-x")) && (argc > 4))
+ else if ((!strcmp(argv[1], "-x")) && (argc > 3))
{
- if (argc > 5)
- do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
- else
- do_eet_extract(argv[2], argv[3], argv[4], NULL);
+ switch (argc)
+ {
+ case 4:
+ {
+ do_eet_extract(argv[2], argv[3], NULL, NULL);
+ break;
+ }
+ case 5:
+ {
+ do_eet_extract(argv[2], argv[3], argv[4], NULL);
+ break;
+ }
+ default:
+ {
+ do_eet_extract(argv[2], argv[3], argv[4], argv[5]);
+ break;
+ }
+ }
}
- else if ((!strcmp(argv[1], "-d")) && (argc > 4))
+ else if ((!strcmp(argv[1], "-d")) && (argc > 3))
{
- if (argc > 5)
- do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
- else
- do_eet_decode(argv[2], argv[3], argv[4], NULL);
+ switch (argc)
+ {
+ case 4:
+ {
+ do_eet_decode(argv[2], argv[3], NULL, NULL);
+ break;
+ }
+ case 5:
+ {
+ do_eet_decode(argv[2], argv[3], argv[4], NULL);
+ break;
+ }
+ default:
+ {
+ do_eet_decode(argv[2], argv[3], argv[4], argv[5]);
+ break;
+ }
+ }
}
else if ((!strcmp(argv[1], "-i")) && (argc > 5))
{