Commit Graph

90 Commits

Author SHA1 Message Date
Andrew Borodin
6718b3ec26 Indentation using GNU indent-2.2.13.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-06-02 12:49:13 +03:00
Andrew Borodin
aa38245e85 Merge lib/strescape.h into lib/strutil.h. Rename functions.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-04-07 16:38:11 +03:00
Andrew Borodin
fe42478b97 Update copyright years.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2024-01-01 09:46:17 +03:00
Andrew Borodin
2e33fd4fad (mc_search_regex__get_max_num_of_replace_tokens): refactor loop.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-12-31 19:28:44 +03:00
Andrew Borodin
49624e473b Ticket #4450: support PCRE2 in the search engine.
* m4.include/ax_path_lib_pcre.m4: replace by recent version from GNU
Autoconf Archive.
  * m4.include/ax_check_pcre2.m4: get grom GNU Autoconf Archive.
  * m4.include/mc-check-search-type.m4: support both PCRE versions.
  * */*/Makefile.am: remove @CHECK_CFLAGS@ and @PCRE_LIBS@ ads they are
added via AX_PATH_LIB_PCRE and AX_CHECK_PCRE2.
  * lib/search.h, lib/search/: add support of PCRE2. Thanks broly <gagan@hotmail.com>
for the initial patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-03-25 10:07:41 +03:00
Andrew Borodin
7257f794d2 Update template for .c files.
Add section for forward declarations of local functions. This section is
located before file scope variables because functions can be used in
strucutres (see find.c for example):

/*** forward declarations (file scope functions) *************************************************/

/* button callbacks */
static int start_stop (WButton * button, int action);
static int find_do_view_file (WButton * button, int action);
static int find_do_edit_file (WButton * button, int action);

/*** file scope variables ************************************************************************/

static struct
{
    ...
    bcback_fn callback;
} fbuts[] =
{
    ...
    { B_STOP, NORMAL_BUTTON, N_("S&uspend"), 0, 0, NULL, start_stop },
    ...
    { B_VIEW, NORMAL_BUTTON, N_("&View - F3"), 0, 0, NULL, find_do_view_file },
    { B_VIEW, NORMAL_BUTTON, N_("&Edit - F4"), 0, 0, NULL, find_do_edit_file }
};

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-03-19 20:34:24 +03:00
Andrew Borodin
57c61b7681 Update copyright years.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-01-28 21:38:05 +03:00
Andrew Borodin
a4d254c6ec Ticket #4429: multi-line search is buggy.
Revert "Ticket #400: support multi-line search."

This reverts commit e370818c09.

Update doc/README.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2023-01-15 16:10:38 +03:00
Andrew Borodin
f8c0a21904 (mc_search__cond_struct_new_regex_ci_str): fix out of boundary access in string.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-10-10 21:07:40 +03:00
Andrew Borodin
955e88f0d0 (mc_search__tolower_case_str, mc_search__tolower_case_str): take GString.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-10-10 21:07:40 +03:00
Andrew Borodin
76835c05af (mc_search__cond_struct_new_regex_hex_add): take GString.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-10-10 21:07:40 +03:00
Andrew Borodin
1da094ae4a (mc_search__recode_str): return GString.
(mc_search__get_one_symbol): likewise.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-10-10 21:07:40 +03:00
Andrew Borodin
7a65d5200b (mc_search_regex__process_append_str): free string at end of loop.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-10-10 21:07:40 +03:00
Steef Boerrigter
e370818c09 Ticket #400: support multi-line search.
In order to use multiline search, select "Regular expression" mode and
use "\n" in the input line:

For example, if file contains lines

aaa
bbb

search string should be "aaa\nbbb".

As a side effect, non-printable ASCII symbols (\r, \t, etc) in the
search string can be used too.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-08-14 18:02:23 +03:00
Andrew Borodin
0222169206 (mc_search_prepare): cache result.
mc_search_struct: add new member prepared.result to keep the result of
the mc_search_prepare() first call. It can be used to check a regexp
before call of mc_search_run() in a loop.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-04-10 17:42:43 +03:00
Andrew Borodin
975bf17d3b mc_search_struct: rename member: conditions -> prepared_conditions.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-04-10 17:42:43 +03:00
Andrew Borodin
c83f989a11 Fix coding style.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-03-13 13:17:27 +03:00
Andrew Borodin
2c205c5928 Update copyright years.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2022-03-13 13:17:26 +03:00
Andreas Mohr
3c287cef95 Ticket #4222: fix segfault in search.
(mc_search__g_regex_match_full_safe): fix out of bound read:
g_utf8_get_char_validated() expects a nul-terminated string.

Test case: search for "test" in
https://mirrors.edge.kernel.org/pub/linux/kernel/firmware/linux-firmware-20201218.tar.xz

Found by clang-11

==10142==ERROR: AddressSanitizer: SEGV on unknown address 0x60c001e00000 (pc 0x7ffb352111c0 bp 0x7ffcb5745150 sp 0x7ffcb57450e8 T0)
==10142==The signal is caused by a READ memory access.
    #0 0x7ffb352111c0 in g_utf8_get_char_validated (/usr/lib64/libglib-2.0.so.0+0x811c0)
    #1 0x851e6d in mc_search__g_regex_match_full_safe /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/search/regex.c:297:22
    #2 0x851824 in mc_search__regex_found_cond_one /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/search/regex.c:328:10
    #3 0x84b955 in mc_search__regex_found_cond /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/search/regex.c:377:13
    #4 0x84aa07 in mc_search__run_regex /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/search/regex.c:955:17
    #5 0x848969 in mc_search__run_normal /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/search/normal.c:104:12
    #6 0x77270c in mc_search_run /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/search/search.c:308:15
    #7 0x514fd9 in search_content /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/find.c:1123:20
    #8 0x511917 in do_search /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/find.c:1405:26
    #9 0x512028 in find_callback /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/find.c:1597:9
    #10 0x7e285f in send_message /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/../../lib/widget/widget-common.h:243:15
    #11 0x7e36d8 in frontend_dlg_run /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/dialog.c:307:17
    #12 0x7e34c5 in dlg_run /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/dialog.c:583:5
    #13 0x510aa1 in run_process /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/find.c:1755:11
    #14 0x50c29e in do_find /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/find.c:1789:20
    #15 0x5098e7 in find_cmd /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/find.c:1917:17
    #16 0x504735 in midnight_execute_cmd /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/filemanager.c:1251:9
    #17 0x502e00 in midnight_callback /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/filemanager.c:1604:21
    #18 0x7eaa5c in send_message /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/../../lib/widget/widget-common.h:243:15
    #19 0x7e7ae9 in group_handle_key /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/group.c:442:19
    #20 0x7e6a4f in group_default_callback /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/group.c:567:16
    #21 0x7e31bf in dlg_key_event /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/dialog.c:251:19
    #22 0x7e2c12 in dlg_process_event /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/dialog.c:549:9
    #23 0x7e3746 in frontend_dlg_run /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/dialog.c:320:9
    #24 0x7e34c5 in dlg_run /tmp/portage/app-misc/mc-9999/work/mc-9999/lib/widget/dialog.c:583:5
    #25 0x502866 in do_nc /tmp/portage/app-misc/mc-9999/work/mc-9999/src/filemanager/filemanager.c:1838:16
    #26 0x4ceb15 in main /tmp/portage/app-misc/mc-9999/work/mc-9999/src/main.c:455:21
    #27 0x7ffb34f16b49 in __libc_start_main (/lib64/libc.so.6+0x23b49)
    #28 0x4230f9 in _start (/tmp/portage/app-misc/mc-9999/work/mc-9999/src/mc+0x4230f9)

Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2021-04-03 12:33:54 +03:00
Andrew Borodin
d88f439a69 (mc_g_string_dup): new API that extends GString one.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2021-03-14 19:57:24 +03:00
Andrew Borodin
9ee52e77c3 Ticket #4179: code clean up before 4.8.27 release.
Update copyright years.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2021-03-14 19:30:42 +03:00
Andrew Borodin
31b37a1f79 Ticket #4050: code cleanup before 4.8.25 release.
Update copyright years.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2020-02-29 19:10:17 +03:00
Andrew Borodin
1dd8a47987 Ticket #3955: code cleanup before 4.8.23 release.
Update copyright years.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2019-02-03 12:44:40 +03:00
Andrew Borodin
ddd645526a Update copyright years. 2018-02-04 11:30:22 +03:00
Andrew Borodin
e9fd11bfcd Update copyright years.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2017-01-22 19:12:55 +03:00
Andrew Borodin
37de8e6253 (mc_search__g_regex_match_full_safe): don't use negative string length.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2017-01-22 18:44:22 +03:00
Mooffie
c0abaa6508 (mc_search__cond_struct_new_regex_ci_str): add documentation.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2017-01-22 18:44:22 +03:00
Andrew Borodin
7f8ab40a44 Do not recreate "String not found" error string every time.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-05-22 14:16:19 +03:00
Andrew Borodin
8252345666 Allow search be interruptible.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-05-22 14:16:19 +03:00
Andrew Borodin
1101ef2cd9 (mc_search__run_regex): minor optimization.
Since mc_search__run_regex() pften is called in various iterative
procedures, don't reallocate regex buffer every time and use already
allocated one before.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-05-22 14:16:19 +03:00
Andrew Borodin
1c22d44970 Ticket #3637: fix memory leaks in search engine.
(mc_search_set_error): new search API to set the code and message
of search error.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-05-22 14:16:19 +03:00
Andrew Borodin
bc14ff44c8 Remove min() and max() macros. Use MIN() and MAX() macros from GLib.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-05-07 16:19:02 +03:00
Andreas Mohr
f3f927c19e lib/search/regex.c: cleanup -Wcast-qual warning.
Signed-off-by: Andreas Mohr <and@gmx.li>
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-04-16 10:23:44 +03:00
Andrew Borodin
98e66fe406 Ticket #3491: fix case insensitive search in non-unicode locales.
In non-unicode locales, search for non-latin symbols in any acharset was
case sensitive only.  This bug was introduced in
1a1496fc0d.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-02-02 09:37:15 +03:00
Andrew Borodin
471ea781ca Update copyright years.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2016-01-01 11:48:10 +03:00
Egmont Koblinger
7cdb3e47c0 Ticket #3449: Segfault in "Find file" due to invalid UTF-8 sequences
Signed-off-by: Yury V. Zaytsev <yury@shurup.com>
2015-10-18 19:26:42 +02:00
Egmont Koblinger
1f0dee6b52 Ticket #3525: fix "Whole words" search.
The "Whole words" feature of search only worked in Normal mode, not in
any of the other modes (Regex, Hex, Wildcard).

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2015-09-19 20:26:31 +03:00
Egmont Koblinger
a0741b0a08 Ticket #3524: fix highliht of search result...
...in case of "Regular expression" and "Whole words".

The bug:
If there's no match, it's properly reported so.
If there's a match, however, the mcview's viewport is properly scrolled
vertically, but the search result is not highlighted. Plus, you can
press "Search again" once (or more times if there are multiple matches
in the line) and it won't progress to the next match.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2015-09-19 18:24:07 +03:00
Egmont Koblinger
1a1496fc0d Ticket #3416: viewer case insensitive search doesn't find accents.
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2015-03-19 11:16:24 +03:00
Andrew Borodin
454479549c Update copyright years. 2015-02-26 09:12:08 +03:00
Andrew Borodin
6ed1eba88f (mc_search_regex_prepare_replace_str): refactoring.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2015-02-26 09:12:08 +03:00
Andrew Borodin
fa7d2ea110 lib/search/regex.c: use [] to get char in string. 2015-02-26 09:12:08 +03:00
Andrew Borodin
589d0bea0b (mc_search__regex_str_append_if_special): refactoring of loop and conditions.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2015-02-26 09:12:08 +03:00
Andrew Borodin
8ce85a419b Ticket #3265: code cleanup before 4.8.14 release.
(mc_search_regex__process_append_str): fix condition.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2015-02-26 09:12:07 +03:00
Boris Savelev
933fd255d0 Ticket #2743: File selection by patterns uses bytes instead of (unicode) characters.
Using the "?" pattern in the file selection dialog brought up with '+',
mc uses the file name length in bytes instead of characters.

Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2015-02-25 12:59:57 +03:00
Andrew Borodin
5ecf12483a Ticket #2952: search: fix zero-length substitution.
Problem:
Suppose you want to replace a substring in some file names with another,
so you do a File Rename operation with source pattern:

*OLDSTRING*

and target pattern:

\1NEWSTRING\2

If OLDSTRING occurs inside a filename, it is replaced correctly, but if
at the beginning or end of the filename, the corresponding zero-length
wildcard match is replaced by literal \1 or \2, respectively.

Expected
Wildcards that match a zero-length substring should be substituted with
an empty string.

Thanks boris<> for the original patch.

Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2015-01-14 09:50:50 +03:00
Slava Zanko
512ad7d962 Make working with GError in more right way (like with exceptions).
Signed-off-by: Slava Zanko <slavazanko@gmail.com>
2014-07-22 13:12:07 +04:00
Andrew Borodin
708f474d1e (mc_search_regex__process_append_str): fix possible dereference of null pointer.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2014-07-22 13:10:41 +04:00
Andrew Borodin
e5203cb023 Fix name of FSF in all *.c files.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2014-02-28 13:33:17 +04:00
Andrew Borodin
f0da49345a Collapse list of copyright years to ranges. Add 2014 year.
Signed-off-by: Andrew Borodin <aborodin@vmail.ru>
2014-02-10 16:27:03 +04:00