-
Notifications
You must be signed in to change notification settings - Fork 0
/
rtftohtml.cpp
executable file
·119 lines (100 loc) · 2.44 KB
/
rtftohtml.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*Copyright 2001
*
* rtftohtml.cpp
*
* Author: Gregory Ford [email protected]
* RTF token parser based on:
* rtf2html by Dmitry Porapov <[email protected]>,
* based on earlier work of Chuck Shotton.
* distributed under BSD-style license
* RTF token lists and hashing algorithm based on
* RTF Tools, Release 1.10
* 6 April 1994
* Paul DuBois [email protected]
*
* Copying permitted under GNU licence (see COPYING)
*/
// rtftohtml.cpp
#include <string>
#include <cstring>
#include <vector>
#include <stack>
#include <iostream>
using namespace std ;
#include <stdio.h>
#include "linktracker.h"
#include "charoutput.h"
#include "charsource.h"
#include "filecharsource.h"
#include "tag.h"
#include "stylemap.h"
#include "token.h"
#include "tokeniser.h"
#include "graphicstate.h"
#include "destination.h"
#include "bodydestination.h"
#include "ignoredestination.h"
#include "stylesheetdestination.h"
#include "infodestination.h"
#include "rtfparser.h"
void indent( int groupLevel ) {
cout << endl;
for ( int i = 0 ; i < groupLevel ; i++ ) {
cout << "\t";
}
}
void usage( const char *app_name )
{
cout << "usage: " << app_name << " [ -options ] filename" << endl;
cout << "where -options are:" << endl;
cout << "\t-o outputfile" << endl;
cout << "\t-help" << endl;
}
int
main( int argc, char *argv[ ] )
{
int argno;
char *infile = NULL;
char *outfile = NULL;
// parse the command line parameters.
if ( argc == 1 ) { // called with no parameters
usage(argv[0]);
return 1; // is this an error? (maybe should take input from stdin --> stdout??)
}
for ( argno = 1; argno < argc; argno++ ) {
switch ( *argv[argno] ) {
case '-':
// we have an option
if ( strcmp( argv[argno], "-help" ) == 0 ) {
usage(argv[0]);
return 0;
} else if ( strcmp( argv[argno], "-o" ) == 0 ) {
if ( argno >= argc ) {
usage (argv[0]);
return 2;
}
argno++;
outfile = argv[argno];
}
break;
default:
infile = argv[argno];
}
}
FileCharSource *src;
// note: we are ignoring outfile if it was specified and always writing to stdout
if ( infile != NULL ) {
src = new FileCharSource( infile );
} else {
src = new FileCharSource( stdin );
}
CharOutput *dest = NULL;
if ( outfile != NULL ) {
dest = (CharOutput *) new FileCharOutput( outfile );
} else {
dest = new CharOutput();
}
RtfParser parser( dest );
parser.parseDocument( src, dest);
return 0;
};