From f46e1f207164090050c1b991705dbbf0d1daa04f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Mangano?= Date: Tue, 1 Jan 2013 17:57:55 +0100 Subject: [PATCH] read from stdin, write to stdout --- opustags.c | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) diff --git a/opustags.c b/opustags.c index 13cd1ff..2d74e7d 100644 --- a/opustags.c +++ b/opustags.c @@ -194,19 +194,27 @@ int main(int argc, char **argv){ path_in = argv[optind]; FILE *out = NULL; if(path_out != NULL){ - if(!overwrite){ - if(access(path_out, F_OK) == 0){ - fprintf(stderr, "'%s' already exists (use -y to overwrite)\n", path_out); + if(strcmp(path_out, "-") == 0) + out = stdout; + else{ + if(!overwrite){ + if(access(path_out, F_OK) == 0){ + fprintf(stderr, "'%s' already exists (use -y to overwrite)\n", path_out); + return EXIT_FAILURE; + } + } + out = fopen(path_out, "w"); + if(!out){ + perror("fopen"); return EXIT_FAILURE; } } - out = fopen(path_out, "w"); - if(!out){ - perror("fopen"); - return EXIT_FAILURE; - } } - FILE *in = fopen(path_in, "r"); + FILE *in; + if(strcmp(path_in, "-") == 0) + in = stdin; + else + in = fopen(path_in, "r"); if(!in){ perror("fopen"); if(out)