From cc0046b7e7e191443a027a8f1f38855726ae2871 Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Thu, 2 Sep 2004 16:30:12 +0000 Subject: Allow conversions on stdin/stdout --- AUTHORS | 2 -- ChangeLog | 3 +++ config.win32.h | 6 +++--- configure.in | 4 ++-- libs/.cvsignore | 1 + src/rtfx.cpp | 60 ++++++++++++++++++++++++++++++++++++++++++++------------- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/AUTHORS b/AUTHORS index 6e0dc44..0e1c809 100644 --- a/AUTHORS +++ b/AUTHORS @@ -1,7 +1,5 @@ - Nate Nielsen - DOMC Library by: Michael B. Allen http://www.ioplex.com/~miallen/domc/ diff --git a/ChangeLog b/ChangeLog index e5e2102..1868e4d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,6 @@ +Version 0.9.5 + - Allow conversions on stdin and stdout + Version 0.9.4 - Switched from Sablotron to DOMC (due to speed and dependency issues) - Added support for ANSI to Unicode conversions diff --git a/config.win32.h b/config.win32.h index 1d253c3..5fcd53a 100644 --- a/config.win32.h +++ b/config.win32.h @@ -98,13 +98,13 @@ #define PACKAGE_NAME "rtfx" /* Define to the full name and version of this package. */ -#define PACKAGE_STRING "rtfx 0.9.2" +#define PACKAGE_STRING "rtfx 0.9.5" /* Define to the one symbol short name of this package. */ #define PACKAGE_TARNAME "rtfx" /* Define to the version of this package. */ -#define PACKAGE_VERSION "0.9.2" +#define PACKAGE_VERSION "0.9.5" /* If using the C implementation of alloca, define if you know the direction of stack growth for your system; otherwise it will be @@ -118,7 +118,7 @@ #define STDC_HEADERS 1 /* Version number of package */ -#define VERSION "0.9.2" +#define VERSION "0.9.5" /* Define to empty if `const' does not conform to ANSI C. */ /* #undef const */ diff --git a/configure.in b/configure.in index 363734d..3ce26de 100644 --- a/configure.in +++ b/configure.in @@ -36,8 +36,8 @@ dnl Nate Nielsen dnl dnl Process this file with autoconf to produce a configure script. -AC_INIT(rtfx, 0.9.4, nielsen@memberwebs.com) -AM_INIT_AUTOMAKE(rtfx, 0.9.4) +AC_INIT(rtfx, 0.9.5, nielsen@memberwebs.com) +AM_INIT_AUTOMAKE(rtfx, 0.9.5) LDFLAGS="$LDFLAGS -L/usr/local/lib" CPPFLAGS="$CPPFLAGS -I/usr/local/include" diff --git a/libs/.cvsignore b/libs/.cvsignore index eb7fb70..5f7e60a 100644 --- a/libs/.cvsignore +++ b/libs/.cvsignore @@ -2,3 +2,4 @@ domc libmba Makefile Makefile.in + 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] \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) -- cgit v1.2.3