Commit Graph

167 Commits

Author SHA1 Message Date
580f08b823
Output info messages to stderr with --debug. 2021-06-01 13:52:41 +02:00
28c0a5a797
Add --debug switch and enable debugging if it is on. 2021-06-01 13:41:54 +02:00
b12f88003b
Fix text logging and debug logging. 2021-06-01 13:41:20 +02:00
17b6017fe0
Rename init_debug() → enable_debug(), add documentation. 2021-06-01 13:36:34 +02:00
12a1c47259
Make log_path a variable again.
We don't need log_dir() twice afterall.
2021-06-01 11:09:40 +02:00
a8f2b7dfb6
Add equipment for debug logs. 2021-06-01 11:02:06 +02:00
c35434e745
Simplify LOG macro.
All checks were successful
continuous-integration/drone/push Build is passing
We only have one logger, no need to specify it every time.
2021-05-31 22:43:30 +02:00
4c1bae86ba
Add fatal errors.
Errors are fatal if the program has to stop immediately.
2021-05-31 22:29:35 +02:00
1fee4f5afd
Fix file error reporting.
Not sure why exceptions don't have that info… 🤷
2021-05-31 22:22:04 +02:00
80e2e9d05d
Re-add -DBOOST_LOG_DYN_LINK
All checks were successful
continuous-integration/drone/push Build is passing
It seems we still need it. The combination of Boost 1.65.1 and CMake 3.12
does not work otherwise. Not sure whose fault it is.
2021-05-31 21:20:41 +02:00
c30a8b40be
Older Boost version need log_setup in addition to log.
Some checks failed
continuous-integration/drone/push Build is failing
1.75.0 works without it, 1.74.0 not.
Removed -DBOOST_LOG_DYN_LINK again.
2021-05-31 20:57:36 +02:00
1d02c3bd6d
Add workaround for old CMake←→Boost combinations.
Some checks failed
continuous-integration/drone/push Build is failing
2021-05-31 20:15:54 +02:00
77d013c12a
Change config file path.
Some checks reported errors
continuous-integration/drone/push Build was killed
Existing old config file is copied over.
2021-05-31 19:37:11 +02:00
b966be3021
Log suppressed errors to log file. 2021-05-31 19:27:36 +02:00
18f8600174
Change log file directory. 2021-05-31 19:26:19 +02:00
11572d5b29
Use logger for warnings end errors. 2021-05-31 19:12:07 +02:00
ac5b31f2d5
Add logger. 2021-05-31 18:50:41 +02:00
cf583c6d7f
Don't compile sources twice.
Not sure why it would compile them twice if they are set to PUBLIC, but okay. 🤷
2021-05-31 17:24:08 +02:00
78ada56226
Make input files required.
It will be difficult to parse EPUB files from stdin and the usefulness is
questionable.
2021-05-31 15:31:41 +02:00
11a8989370
CMake: Make GLOB work with new files (most of the time).
All checks were successful
continuous-integration/drone/push Build is passing
Caveats: <https://cmake.org/cmake/help/latest/command/file.html#filesystem>
2021-05-31 11:06:29 +02:00
76ed0c9dbf
Un-escape named and numbered entities in documents before searching.
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-30 23:32:35 +02:00
8a9be5d45b
Add helpers::unescape_html() &amp; tests. 2021-05-30 23:32:30 +02:00
7ddfe32e30
Move is_whitespace() and urldecode() to helpers. 2021-05-30 21:52:52 +02:00
94564fa914
Strip whitespace from headlines. 2021-05-30 21:16:24 +02:00
22cae4c3cd
Output metadata italic, chapters underlined. 2021-05-30 19:03:59 +02:00
fe23fcf04b
Rename prefix to metadata in print_matches(). 2021-05-30 18:09:31 +02:00
03138c1dbf
Remove unnecessary include. 2021-05-30 18:07:13 +02:00
e7633fe134
Rename prefix to before and suffix to after.
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-30 14:47:18 +02:00
6255d665af
Replace tabs with a space in search::cleanup(). 2021-05-30 14:37:05 +02:00
d7ad180721
Use iterators in search::context() and don't return extra whitespace
Should be easier to understand now.
2021-05-30 13:45:56 +02:00
790e60a055
Fix end-of-headline detection. 2021-05-29 23:00:16 +02:00
160ff20387
Revert "Fix pugixml target."
All checks were successful
continuous-integration/drone/push Build is passing
pugixml 1.8.1 (the version in Ubuntu bionic) does not have that target.

This reverts commit 2a3e3f87b5.
2021-05-29 22:10:21 +02:00
2a3e3f87b5
Fix pugixml target. 2021-05-29 21:37:40 +02:00
37e868b3f2
Remove <style> and <script> snippets.
Closes: #8
2021-05-29 18:52:03 +02:00
2d65961688
Output XML errors. 2021-05-29 18:42:29 +02:00
ba5716c585
Skip in-epub file if it is not found, except it's the container.
We skipped the whole EPUB before.
2021-05-29 18:20:23 +02:00
5bd1030ad8
Try opf: variants of XML tags if normal variants are not found. 2021-05-29 18:09:44 +02:00
03b367ee98
Don't print same file path twice in error message.
zip::exception always has  the filename in the message.
2021-05-29 17:37:41 +02:00
00e3edb9f2
Only search files in spine, in the right order.
The spine lists all content documents in their linear reading order. So we're
finally getting our results in the right order! 🎉

Since we skip the images and fonts, which usually make up the most bytes in an
EPUB file, the performance increase is immense. I measured 60-70% in a very
short test.

Closes: #1
2021-05-29 17:34:43 +02:00
c94d9de0db
Reformat error messages.
One line per error message.
2021-05-29 12:53:14 +02:00
4ff796a590
Make regular expressions static variables.
All checks were successful
continuous-integration/drone/push Build is passing
Fewer allocations → faster program. About 17% speed increase with 89 books on up
to 3 cores. Measured using the average of 4 runs.
Before: ~15,5 seconds
 After: ~12,8 seconds

Calls to allocation functions went down from 16.652.583 to 5.059.301.
2021-05-28 19:11:32 +02:00
4df7b36dfc
Print matches while still searching.
All checks were successful
continuous-integration/drone/push Build is passing
Previously we printed the matches at the end.
2021-05-28 17:18:34 +02:00
59759b5934
Put output stuff into own function in different file.
It got a little crowded in main(). 😊
2021-05-28 17:07:11 +02:00
308e2d271f
Skip rest of file if encoding of files in EPUB is broken.
Standard says UTF-8. I don't want to deal with weird Windows-encodings or
whatever this is.

Closes: #7
2021-05-28 13:57:51 +02:00
65b46ca846
Do not allow more threads than max_threads. 2021-05-28 11:48:38 +02:00
c3131e01f0
Add setting to suppress this-is-not-an-EPUB errors. 2021-05-27 21:48:35 +02:00
84f600196c
Add error code to zip::exception. 2021-05-27 21:39:01 +02:00
b96315f8bb
Don't add extra newlines before errors. 2021-05-27 21:03:42 +02:00
2b91a839cc
Add --raw and --context again.
Forgot to re-implement them when I overhauled the option parsing…
2021-05-27 21:01:07 +02:00
8d5565a72c
Don't write to matches_all simultaneously from different threads.
What did I do yesterday?!? 😬

Closes: #6
2021-05-27 20:42:20 +02:00
38bf9be948
Fix some more memory leaks. 2021-05-27 20:11:59 +02:00
b24ea9b71e
Fix memory leak. 🤦
All checks were successful
continuous-integration/drone/push Build is passing
That's why I don't write C. 😄

This seems to fix issue #6 in single-threaded mode but sometimes throws “double
free or corruption (out)” in multi-threaded mode.

Bug: #6
2021-05-27 20:05:02 +02:00
fbb87cac81
Remove a few unnecessary .data(), remove unnecessary include. 2021-05-27 19:08:53 +02:00
c50659a339
Chunk error string to make it better translatable. 2021-05-27 17:24:19 +02:00
e64591f204
Rework option parsing, change --no-filename.
Some checks failed
continuous-integration/drone/push Build is failing
Options are now better accessible, --no-filename accepts the values filesystem,
in-epub or all.
2021-05-27 17:20:00 +02:00
c376ce8466
Print the EPUB file name if more than 1 input file.
Change --no-filename to mean: Don't print the EPUB file name.
2021-05-27 14:46:23 +02:00
0c45e7ac98
Add --recursive and --dereference-recursive.
Closes: #5
2021-05-27 14:45:52 +02:00
b764f5423c
Put input files into a std::vector<filesystem::path>.
We need that for supporting recursive directory search later.

#
# Previous commits:
#   29ae22c Make regex const.
#   8ed72af Update german translation.
#   a3b0964 Remove old comment.
#   d107ce5 Modify config file example.
2021-05-27 13:46:47 +02:00
29ae22cc4a
Make regex const. 2021-05-27 09:46:59 +02:00
a3b0964873
Remove old comment. 2021-05-26 20:20:21 +02:00
7dcf6d599c
Remove debug statements. 2021-05-26 18:25:53 +02:00
fe02b155f5
Import std::string into epubgrep::search namespace.
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-26 18:02:27 +02:00
fc0aa02bc9
Use threads if more than one input file is searched.
Use 75% of the available threads (rounded up).

Closes: #4
2021-05-26 17:50:52 +02:00
694cb3bc44
Add --no-filename switch.
All checks were successful
continuous-integration/drone/push Build is passing
Suppresses the mentioning of file names on output.
2021-05-26 09:04:16 +02:00
fd8db544bd
Add --nocolor switch.
Closes: #2
2021-05-25 11:52:13 +02:00
b72d3f3420
Color matches bright magenta. 2021-05-25 11:00:05 +02:00
d3c3062cc0
Add Termcolor dependency and bundle it in dist/. 2021-05-25 10:55:44 +02:00
ce015954ea
Only initialize search::options once. 2021-05-25 10:02:34 +02:00
4644c2afd4
Support CMake 3.12.
All checks were successful
continuous-integration/drone/push Build is passing
Ubuntu 20.04 has 3.16, so requiring 3.17 is a bit mean.
2021-05-25 07:38:07 +02:00
be229d25d6
Don't demand required options if --help or --version is requested.
All checks were successful
continuous-integration/drone/push Build is passing
Bump version to 0.1.2.
2021-05-25 07:15:04 +02:00
e1d29c5893
Don't replace stuff in search::cleanup_text() if nothing matched. 2021-05-24 20:02:27 +02:00
09090a1c13
Fix bugs in search::context().
- Don't add context if words == 0
- Handle beginning / end of text correctly.
2021-05-24 19:57:15 +02:00
1f25daed26
Add basic error handling to search. 2021-05-24 19:10:00 +02:00
c790c4952c
Extract page numbers. 2021-05-24 18:56:43 +02:00
bb4a4c719f
Wrap headlines in <H> and </H> during cleanup. 2021-05-24 18:08:40 +02:00
8ab7d0f655
Extract headlines. 2021-05-24 17:27:30 +02:00
8b21f4a8b9
Don't output empty fields. 2021-05-24 16:37:43 +02:00
972ce1d0fe
Don't strip headlines. 2021-05-24 16:37:30 +02:00
bb1a43ca92
Move cleanup_text(), document functions. 2021-05-24 16:23:07 +02:00
84e2b387e5
Clean up text before searching. 2021-05-24 16:01:41 +02:00
1979956f03
Add basic search functionality and context output. 2021-05-24 15:35:49 +02:00
4e01032c6f
Put regex type and --grep in search::options. 2021-05-24 13:13:15 +02:00
b2e70a6faa
Mark everything [[nodiscard]], fix some comments. 2021-05-24 13:00:03 +02:00
9c769f664d
Clarify documentation: NUM → NUMBER. 2021-05-24 08:23:52 +02:00
44ffeb07ec
Add calls to search::search() to main().
All that's missing now is the actual search functionality. 😊
2021-05-24 08:15:04 +02:00
3222019c69
Add default value (0) to --context. 2021-05-24 08:14:29 +02:00
1f82d9927a
Add skeleton for search::search().
- Type for matches
- Type for options.
2021-05-24 07:52:36 +02:00
f388dd0511
Add --raw and --context switches. 2021-05-24 07:50:50 +02:00
5ac7f92f1d
Add hint to man page. 2021-05-24 06:03:32 +02:00
3ad4e49e3d
Don't dump zip files to stdout. 2021-05-24 05:46:12 +02:00
2ab4705475
Make --regexp required, show help if it is not given. 2021-05-24 05:45:42 +02:00
4b2fbecf93
Print all options at start.
All checks were successful
continuous-integration/drone/push Build is passing
2021-05-23 16:52:32 +02:00
03e07dfc3e
Rework option parsing a bit.
- Add --basic-regexp
- Add --grep
- Remove --input-file
- Make it possible to have multiple --regexp
2021-05-23 16:23:07 +02:00
e773d4b78a
Implement zip::read_file() – Read file in archive; add test.
Also added zip::open_file() and zip::close_file() to deduplicate code.
2021-05-23 08:56:58 +02:00
6334b7051f
Newline before printing error messages. 2021-05-23 08:55:15 +02:00
28c6c80def
Set C locale, treat EPUB file names as UTF-8.
EPUB file names MUST be UTF-8. ASCII is a subset of UTF-8.
2021-05-23 06:32:56 +02:00
6c040fa951
Add first test.
Some checks failed
continuous-integration/drone/push Build is failing
- Compile everything in src/ except main.cpp into a static library
- Link the static library into tests
- Add test for zip::list()
2021-05-21 09:27:31 +02:00
8c8a19b86b
Cosmetic changes. 2021-05-21 07:10:46 +02:00
a941bcced3
Initialize the variables where they're needed. 2021-05-21 07:05:44 +02:00
354583bcbd
Add short descriptions. 2021-05-21 06:54:01 +02:00