From bef3628f699c3d747292bd6c87a733818e618e6c Mon Sep 17 00:00:00 2001 From: Adam Dickmeiss Date: Thu, 11 Aug 2011 10:43:06 +0200 Subject: [PATCH] yaz-url: Opt -O writes output to file instead of stdout --- util/yaz-url.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/util/yaz-url.c b/util/yaz-url.c index 9cdb388..98bf594 100644 --- a/util/yaz-url.c +++ b/util/yaz-url.c @@ -19,6 +19,7 @@ static void usage(void) printf("yaz-icu [options] url ..\n"); printf(" -H name:value Set HTTP header (repeat if necessary)\n"); printf(" -m method HTTP method\n"); + printf(" -O file Write to file, instead of stdout\n"); printf(" -p file POSTs file at following url\n"); printf(" -u user/password Basic HTTP auth\n"); printf(" -x proxy HTTP proxy\n"); @@ -63,8 +64,9 @@ int main(int argc, char **argv) ODR odr = odr_createmem(ODR_ENCODE); int exit_code = 0; int no_urls = 0; + const char *outfname = 0; - while ((ret = options("hH:m:p:u:x:", argv, argc, &arg)) + while ((ret = options("hH:m:O:p:u:x:", argv, argc, &arg)) != YAZ_OPTIONS_EOF) { switch (ret) @@ -93,6 +95,9 @@ int main(int argc, char **argv) case 'm': method = arg; break; + case 'O': + outfname = arg; + break; case 'p': xfree(post_buf); post_buf = get_file(arg, &post_len); @@ -122,8 +127,20 @@ int main(int argc, char **argv) exit_code = 1; else { + FILE *outf = stdout; + if (outfname) + { + outf = fopen(outfname, "w"); + if (!outf) + { + yaz_log(YLOG_FATAL|YLOG_ERRNO, "open %s", outfname); + exit(1); + } + } fwrite(http_response->content_buf, 1, - http_response->content_len, stdout); + http_response->content_len, outf); + if (outfname) + fclose(outf); } no_urls++; break; -- 1.7.10.4