From 53914f770f1e1dc1ab4342c64846fd995825b7e6 Mon Sep 17 00:00:00 2001 From: Stef Date: Wed, 17 Sep 2003 18:34:42 +0000 Subject: Initial Import --- src/rtfx.cpp | 68 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 src/rtfx.cpp (limited to 'src/rtfx.cpp') 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 +#include + +#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; +} -- cgit v1.2.3