From 48fdba03378932c8ed3a09c3b4c7dd599d0c71d4 Mon Sep 17 00:00:00 2001 From: kelson42 Date: Mon, 13 Feb 2012 13:39:13 +0000 Subject: [PATCH] + reader --- src/reader/kiwix-read.cpp | 91 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 91 insertions(+) create mode 100644 src/reader/kiwix-read.cpp diff --git a/src/reader/kiwix-read.cpp b/src/reader/kiwix-read.cpp new file mode 100644 index 0000000..1c486dc --- /dev/null +++ b/src/reader/kiwix-read.cpp @@ -0,0 +1,91 @@ +/* + * Copyright 2011 Emmanuel Engelhart + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 3 of the License, or + * any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, + * MA 02110-1301, USA. + */ + +#include +#include +#include + +void usage() { + cout << "Usage: kiwix-read ZIM_FILE_PATH" << endl; + exit(1); +} + +int main(int argc, char **argv) { + + /* Init the variables */ + const char *filePath = NULL; + int option_index = 0; + int c = 0; + + kiwix::Reader *reader = NULL; + + /* Argument parsing */ + while (42) { + + static struct option long_options[] = { + {"verbose", no_argument, 0, 'v'}, + {0, 0, 0, 0} + }; + + if (c != -1) { + c = getopt_long(argc, argv, "v", long_options, &option_index); + + switch (c) { + case 'v': + break; + } + } else { + if (optind < argc) { + if (filePath == NULL) { + filePath = argv[optind++]; + } else { + usage(); + } + } else { + break; + } + } + } + + /* Check if we have enough arguments */ + if (filePath == NULL) { + usage(); + } + + /* Instanciate the reader */ + reader = new kiwix::Reader(filePath); + + /* Start to read an article */ + if (reader != NULL) { + string mainPageUrl = reader->getMainPageUrl(); + string content; + string contentType; + unsigned int contentLength = 0; + + if (reader->getContentByUrl(mainPageUrl, content, contentLength, contentType)) { + cout << content << endl; + } + delete reader; + } else { + cerr << "Unable instanciate the Kiwix reader." << endl; + exit(1); + } + + exit(0); +}