summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorStef Walter <stef@memberwebs.com>2004-09-02 16:30:12 +0000
committerStef Walter <stef@memberwebs.com>2004-09-02 16:30:12 +0000
commitcc0046b7e7e191443a027a8f1f38855726ae2871 (patch)
tree5fd8e6f690da1a35067e8e7f2b5e09ef493736b6 /src
parent49bf6f309fac68d2e535e92ab0936f4fb6ed79da (diff)
Allow conversions on stdin/stdout
Diffstat (limited to 'src')
-rw-r--r--src/rtfx.cpp60
1 files changed, 47 insertions, 13 deletions
diff --git a/src/rtfx.cpp b/src/rtfx.cpp
index 2a9f3fc..bb26777 100644
--- a/src/rtfx.cpp
+++ b/src/rtfx.cpp
@@ -46,7 +46,7 @@
int usage()
{
- fprintf(stderr, "usage: rtfx [-p] <inrtf> <outxml>\n");
+ fprintf(stderr, "usage: rtfx [-p] [inrtf] [outxml]\n");
exit(2);
}
@@ -85,20 +85,45 @@ int main(int argc, char* argv[])
break;
}
- if(argc < 2)
- usage();
+ if(argc > 2)
+ usage();
try
{
- // The input file
- FILE* file = fopen(argv[0], "rb");
+ // By default no files
+ FILE* file = NULL;
+ FILE* out = stdout;
- if(!file)
+ // An input file
+ if(argc > 0)
{
- fprintf(stderr, "rtfx: couldn't open rtf file: %s: %s\n", argv[0], strerror(errno));
- return 1;
+ file = fopen(argv[0], "rb");
+
+ if(!file)
+ {
+ fprintf(stderr, "rtfx: couldn't open rtf file: %s: %s\n", argv[0], strerror(errno));
+ return 1;
+ }
+
+ argc--;
+ argv++;
+ }
+
+ // Use stdin
+ else
+ {
+ // We have to do this instead of just use 'stdin' because windows
+ // screws with the line endings of stdin.
+ file = fdopen(0, "rb");
+
+ if(!file)
+ {
+ fprintf(stderr, "rtfx: couldn't open stdin: %s", strerror(errno));
+ return 1;
+ }
}
+
// Reads RTF tags and blocks
RtfParser rtf;
@@ -117,15 +142,24 @@ int main(int argc, char* argv[])
DOM::Document doc = composer.getDocument();
- FILE* out = fopen(argv[1], "wb");
- if(!out)
+ if(argc > 0)
{
- fprintf(stderr, "rtfx: couldn't open file: %s: %s\n", argv[1], strerror(errno));
- return 1;
+ out = fopen(argv[0], "wb");
+ if(!out)
+ {
+ fprintf(stderr, "rtfx: couldn't open file: %s: %s\n", argv[0], strerror(errno));
+ return 1;
+ }
+
+ argc--;
+ argv++;
}
doc.serialize(out);
- fclose(out);
+
+ if(out != stdout)
+ fclose(out);
+
return 0;
}
catch(DOM::DOMException& e)