vfs: check userland buffers before reading them.
[haiku.git] / src / add-ons / translators / rtf / main.cpp
blobe2357b1eada4c1e119d1c4845fa15b1b572ed211
1 /*
2 * Copyright 2004-2010, Axel Dörfler, axeld@pinc-software.de.
3 * Distributed under the terms of the MIT License.
4 */
7 #include <stdio.h>
8 #include <string.h>
9 #include <syslog.h>
11 #include <Application.h>
12 #include <Catalog.h>
13 #include <FileIO.h>
14 #include <TranslatorRoster.h>
16 #include "TranslatorWindow.h"
18 #include "convert.h"
19 #include "RTF.h"
20 #include "RTFTranslator.h"
22 #undef B_TRANSLATION_CONTEXT
23 #define B_TRANSLATION_CONTEXT "main"
26 int
27 main(int argc, char** argv)
29 if (argc > 1) {
30 // Convert input files to plain text directly
31 BFileIO output(stdout);
32 int result = 0;
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;
45 RTF::Parser parser(input);
46 RTF::Header header;
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;
57 convert_to_plain_text(header, output);
60 return result;
63 BApplication app("application/x-vnd.Haiku-RTFTranslator");
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;
71 app.Run();
72 return 0;