diff options
Diffstat (limited to 'src/rtfx.cpp')
-rw-r--r-- | src/rtfx.cpp | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/src/rtfx.cpp b/src/rtfx.cpp new file mode 100644 index 0000000..6a68a28 --- /dev/null +++ b/src/rtfx.cpp @@ -0,0 +1,68 @@ +// rtfm.cpp : Defines the entry point for the console application. +// + +#include "stdafx.h" +#include <stdlib.h> +#include <stdio.h> + +#include "RtfReader.h" +#include "RtfAnalyser.h" + +int usage() +{ + fprintf(stderr, "usage: rtfm inrtf outxml\n"); + return 2; +} + +int main(int argc, char* argv[]) +{ + if(argc < 3) + return usage(); + + try + { + FILE* file = fopen(argv[1], "rb"); + + if(!file) + { + fprintf(stderr, "rtfm: couldn't open file: %s: %s\n", argv[1], strerror(errno)); + return 1; + } + + RtfParserOptions options; + + RtfParser handler(options); + RtfReader rtf; + rtf.setHandler(&handler); + bool ret = rtf.parse(file); + fclose(file); + + if(!ret) + { + fprintf(stderr, "rtfm: rtf parse failed: %s\n", rtf.getParseErrors().c_str()); + return 1; + } + + + DOM::Document doc = handler.getDocument(); + string xml = doc.serialize(); + + FILE* out = fopen(argv[2], "wb"); + if(!out) + { + fprintf(stderr, "rtfm: couldn't open file: %s: %s\n", argv[2], strerror(errno)); + return 1; + } + + fwrite(xml.c_str(), 1, xml.length(), out); + fclose(out); + return 0; + + } + catch(DOM::DOMException& e) + { + fprintf(stderr, "rtfm: xml dom error: %s\n", e.getMessage()); + } + + return 1; +} |