diff options
author | Stef Walter <stef@memberwebs.com> | 2003-09-17 18:34:42 +0000 |
---|---|---|
committer | Stef Walter <stef@memberwebs.com> | 2003-09-17 18:34:42 +0000 |
commit | 69aa93c828303dcc44253fe88ff3d6024d10817b (patch) | |
tree | 63d14dacbd3d81363fcbea1036c47a0210b0f397 /src/rtfx.cpp | |
parent | 15f3015d2e8305b729d7996faad410b3378497da (diff) |
Initial Import
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; +} |