| 1 |
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: t; c-basic-offset: 4 -*- */ |
| 2 |
/* |
| 3 |
* This file is part of the libabw project. |
| 4 |
* |
| 5 |
* This Source Code Form is subject to the terms of the Mozilla Public |
| 6 |
* License, v. 2.0. If a copy of the MPL was not distributed with this |
| 7 |
* file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 8 |
*/ |
| 9 |
|
| 10 |
|
| 11 |
#include <stdio.h> |
| 12 |
#include <string.h> |
| 13 |
#include <librevenge-stream/librevenge-stream.h> |
| 14 |
#include <librevenge-generators/librevenge-generators.h> |
| 15 |
#include <libabw/libabw.h> |
| 16 |
|
| 17 |
#ifdef HAVE_CONFIG_H |
| 18 |
#include "config.h" |
| 19 |
#endif |
| 20 |
|
| 21 |
#ifndef VERSION |
| 22 |
#define VERSION "UNKNOWN VERSION" |
| 23 |
#endif |
| 24 |
|
| 25 |
namespace |
| 26 |
{ |
| 27 |
|
| 28 |
int printUsage() |
| 29 |
{ |
| 30 |
printf("`abw2text' converts AbiWord documents to plain text.\n"); |
| 31 |
printf("\n"); |
| 32 |
printf("Usage: abw2text [OPTION] INPUT\n"); |
| 33 |
printf("\n"); |
| 34 |
printf("Options:\n"); |
| 35 |
printf("\t--info display document metadata instead of the text\n"); |
| 36 |
printf("\t--help show this help message\n"); |
| 37 |
printf("\t--version show version information\n"); |
| 38 |
printf("\n"); |
| 39 |
printf("Report bugs to <https://bugs.documentfoundation.org/>.\n"); |
| 40 |
return -1; |
| 41 |
} |
| 42 |
|
| 43 |
int printVersion() |
| 44 |
{ |
| 45 |
printf("abw2text %s\n", VERSION); |
| 46 |
return 0; |
| 47 |
} |
| 48 |
|
| 49 |
} // anonymous namespace |
| 50 |
|
| 51 |
int main(int argc, char *argv[]) |
| 52 |
{ |
| 53 |
if (argc < 2) |
| 54 |
return printUsage(); |
| 55 |
|
| 56 |
char *szInputFile = nullptr; |
| 57 |
bool isInfo = false; |
| 58 |
|
| 59 |
for (int i = 1; i < argc; i++) |
| 60 |
{ |
| 61 |
if (!strcmp(argv[i], "--info")) |
| 62 |
isInfo = true; |
| 63 |
else if (!strcmp(argv[i], "--version")) |
| 64 |
return printVersion(); |
| 65 |
else if (!szInputFile && strncmp(argv[i], "--", 2)) |
| 66 |
szInputFile = argv[i]; |
| 67 |
else |
| 68 |
return printUsage(); |
| 69 |
} |
| 70 |
|
| 71 |
if (!szInputFile) |
| 72 |
return printUsage(); |
| 73 |
|
| 74 |
librevenge::RVNGFileStream input(szInputFile); |
| 75 |
|
| 76 |
if (!libabw::AbiDocument::isFileFormatSupported(&input)) |
| 77 |
{ |
| 78 |
fprintf(stderr, "ERROR: Unsupported file format!\n"); |
| 79 |
return 1; |
| 80 |
} |
| 81 |
|
| 82 |
librevenge::RVNGString document; |
| 83 |
librevenge::RVNGTextTextGenerator documentGenerator(document, isInfo); |
| 84 |
if (!libabw::AbiDocument::parse(&input, &documentGenerator)) |
| 85 |
return 1; |
| 86 |
|
| 87 |
printf("%s", document.cstr()); |
| 88 |
|
| 89 |
return 0; |
| 90 |
} |
| 91 |
/* vim:set shiftwidth=2 softtabstop=2 expandtab: */ |