2016-10-31 16:04:15 +00:00
|
|
|
/*
|
2017-02-05 20:30:57 +00:00
|
|
|
* Copyright (c) 2017 Alex Yatskov <alex@foosoft.net>
|
2016-10-31 16:04:15 +00:00
|
|
|
* Author: Alex Yatskov <alex@foosoft.net>
|
|
|
|
*
|
2017-02-05 20:30:57 +00:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy of
|
|
|
|
* this software and associated documentation files (the "Software"), to deal in
|
|
|
|
* the Software without restriction, including without limitation the rights to
|
|
|
|
* use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
|
|
|
* the Software, and to permit persons to whom the Software is furnished to do so,
|
|
|
|
* subject to the following conditions:
|
2016-10-31 16:04:15 +00:00
|
|
|
*
|
2017-02-05 20:30:57 +00:00
|
|
|
* The above copyright notice and this permission notice shall be included in all
|
|
|
|
* copies or substantial portions of the Software.
|
2016-10-31 16:04:15 +00:00
|
|
|
*
|
2017-02-05 20:30:57 +00:00
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
|
|
|
* FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
|
|
|
* COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
|
|
|
* IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
|
|
|
* CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2016-10-31 16:04:15 +00:00
|
|
|
*/
|
|
|
|
|
2016-12-04 02:24:56 +00:00
|
|
|
#include <stdlib.h>
|
2016-12-04 07:29:48 +00:00
|
|
|
#include <getopt.h>
|
2016-11-01 02:32:40 +00:00
|
|
|
|
2016-11-29 04:42:10 +00:00
|
|
|
#include "util.h"
|
2016-11-21 02:23:50 +00:00
|
|
|
#include "book.h"
|
2016-10-30 00:38:50 +00:00
|
|
|
|
2016-11-19 20:23:06 +00:00
|
|
|
/*
|
|
|
|
* Entry point
|
|
|
|
*/
|
|
|
|
|
2016-12-04 02:24:56 +00:00
|
|
|
int main(int argc, char *argv[]) {
|
2016-12-04 07:29:48 +00:00
|
|
|
const struct option options[] = {
|
2017-01-01 00:08:28 +00:00
|
|
|
{ "pretty", no_argument, NULL, 'p' },
|
|
|
|
{ "markup", no_argument, NULL, 'm' },
|
|
|
|
{ "positions", no_argument, NULL, 's' },
|
2017-02-12 03:46:46 +00:00
|
|
|
{ "fonts", no_argument, NULL, 'f' },
|
2017-02-12 18:24:57 +00:00
|
|
|
{ "entries", no_argument, NULL, 'e' },
|
2017-01-01 00:08:28 +00:00
|
|
|
{ NULL, 0, NULL, 0 },
|
2016-12-04 07:29:48 +00:00
|
|
|
};
|
|
|
|
|
2016-12-04 01:14:18 +00:00
|
|
|
char* dict_path = NULL;
|
|
|
|
int flags = 0;
|
|
|
|
|
2016-12-04 07:29:48 +00:00
|
|
|
int c = 0;
|
|
|
|
while ((c = getopt_long(argc, argv, "f:d:pmst", options, NULL)) != -1) {
|
2016-12-04 02:24:56 +00:00
|
|
|
switch (c) {
|
|
|
|
case 'p':
|
|
|
|
flags |= FLAG_PRETTY_PRINT;
|
|
|
|
break;
|
|
|
|
case 'm':
|
|
|
|
flags |= FLAG_HOOK_MARKUP;
|
|
|
|
break;
|
|
|
|
case 's':
|
|
|
|
flags |= FLAG_POSITIONS;
|
|
|
|
break;
|
2017-02-12 03:46:46 +00:00
|
|
|
case 'f':
|
|
|
|
flags |= FLAG_FONTS;
|
|
|
|
break;
|
2017-02-12 18:24:57 +00:00
|
|
|
case 'e':
|
|
|
|
flags |= FLAG_ENTRIES;
|
|
|
|
break;
|
2016-12-04 02:24:56 +00:00
|
|
|
default:
|
2016-12-04 02:46:57 +00:00
|
|
|
return 1;
|
2016-12-04 02:24:56 +00:00
|
|
|
}
|
|
|
|
}
|
2016-12-04 01:14:18 +00:00
|
|
|
|
2016-12-04 02:24:56 +00:00
|
|
|
if (optind == argc) {
|
2017-01-01 00:08:28 +00:00
|
|
|
fprintf(stderr, "error: dictionary path was not provided\n");
|
2016-12-04 02:46:57 +00:00
|
|
|
return 1;
|
2016-12-04 01:14:18 +00:00
|
|
|
}
|
2016-11-03 03:37:11 +00:00
|
|
|
|
2016-12-04 02:24:56 +00:00
|
|
|
dict_path = argv[optind];
|
|
|
|
|
2017-02-12 18:42:30 +00:00
|
|
|
Book* book = book_create();
|
2016-12-05 02:36:06 +00:00
|
|
|
const int success =
|
2017-02-12 18:42:30 +00:00
|
|
|
book_import(book, dict_path, flags) &&
|
|
|
|
book_export(stdout, book, flags);
|
|
|
|
book_destroy(book);
|
2016-11-03 03:37:11 +00:00
|
|
|
|
2016-11-29 05:04:55 +00:00
|
|
|
return success ? 0 : 1;
|
2016-10-29 23:58:09 +00:00
|
|
|
}
|