xref: /haiku/src/add-ons/translators/rtf/main.cpp (revision e81a954787e50e56a7f06f72705b7859b6ab06d1)
1 /*
2  * Copyright 2004-2010, Axel Dörfler, axeld@pinc-software.de.
3  * Distributed under the terms of the MIT License.
4  */
5 
6 
7 #include <stdio.h>
8 #include <string.h>
9 #include <syslog.h>
10 
11 #include <Application.h>
12 #include <Catalog.h>
13 #include <FileIO.h>
14 #include <TranslatorRoster.h>
15 
16 #include "TranslatorWindow.h"
17 
18 #include "convert.h"
19 #include "RTF.h"
20 #include "RTFTranslator.h"
21 
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "main"
24 
25 
26 int
27 main(int argc, char** argv)
28 {
29 	if (argc > 1) {
30 		// Convert input files to plain text directly
31 		BFileIO output(stdout);
32 		int result = 0;
33 
34 		for (int i = 1; i < argc; i++) {
35 			BFile input;
36 			status_t status = input.SetTo(argv[i], B_READ_ONLY);
37 			if (status != B_OK) {
38 				syslog(LOG_ERR,
39 						"RTFTranslator:Could not open file \"%s\": %s\n",
40 											argv[i], strerror(status));
41 				result = 1;
42 				continue;
43 			}
44 
45 			RTF::Parser parser(input);
46 			RTF::Header header;
47 
48 			status = parser.Parse(header);
49 			if (status != B_OK) {
50 				syslog(LOG_ERR,
51 						"RTFTranslator:Could not convert file \"%s\": %s\n",
52 											argv[i], strerror(status));
53 				result = 1;
54 				continue;
55 			}
56 
57 			convert_to_plain_text(header, output);
58 		}
59 
60 		return result;
61 	}
62 
63 	BApplication app("application/x-vnd.Haiku-RTFTranslator");
64 
65 	status_t result;
66 	result = LaunchTranslatorWindow(new RTFTranslator,
67 		B_TRANSLATE("RTF Settings"), BRect(0, 0, 225, 175));
68 	if (result != B_OK)
69 		return 1;
70 
71 	app.Run();
72 	return 0;
73 }
74 
75