Skip to content

Commit 5a67a66

Browse files
committed
fix some other issues related to searching
1 parent e8abf31 commit 5a67a66

File tree

4 files changed

+99
-65
lines changed

4 files changed

+99
-65
lines changed

src/print.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ window_fill(int window_identifier,
101101

102102
is_bookmark_row = (lineinfo != NULL && (lineinfo->mask & LINEINFO_BOOKMARK) != 0) ? true : false;
103103

104-
if (!is_fix_rows && scrdesc->found && *scrdesc->searchterm != '\0' && lnb != NULL && rowstr != NULL
104+
if (!is_fix_rows && *scrdesc->searchterm != '\0' && lnb != NULL && rowstr != NULL
105105
&& !opts->no_highlight_search)
106106
{
107107
if (lineinfo == NULL)
@@ -170,7 +170,7 @@ window_fill(int window_identifier,
170170
/* prepare position cache, when first occurrence is visible */
171171
if (lineinfo != NULL && (lineinfo->mask & LINEINFO_FOUNDSTR_MULTI) != 0 &&
172172
srcx + maxx > lineinfo->start_char &&
173-
scrdesc->found && *scrdesc->searchterm != '\0')
173+
*scrdesc->searchterm != '\0')
174174
{
175175
const char *str = rowstr;
176176

src/pspg.c

+84-57
Original file line numberDiff line numberDiff line change
@@ -1144,12 +1144,32 @@ make_beep(Options *opts)
11441144
* It is used for result of action info
11451145
*/
11461146
static int
1147-
show_info_wait(Options *opts, ScrDesc *scrdesc, char *fmt, char *par, bool beep)
1147+
show_info_wait(Options *opts, ScrDesc *scrdesc, char *fmt, char *par, bool beep, bool refresh_first)
11481148
{
11491149
int c;
11501150
WINDOW *bottom_bar = w_bottom_bar(scrdesc);
11511151
Theme *t = &scrdesc->themes[WINDOW_BOTTOM_BAR];
11521152

1153+
/*
1154+
* When refresh is required first, then store params and quit immediately.
1155+
* Only once can be info moved after refresh
1156+
*/
1157+
if (refresh_first && scrdesc->fmt == NULL)
1158+
{
1159+
if (fmt != NULL)
1160+
scrdesc->fmt = strdup(fmt);
1161+
else
1162+
scrdesc->fmt = NULL;
1163+
1164+
if (par != NULL)
1165+
scrdesc->par = strdup(par);
1166+
else
1167+
scrdesc->par = NULL;
1168+
scrdesc->beep = beep;
1169+
1170+
return 0;
1171+
}
1172+
11531173
wattron(bottom_bar, t->bottom_light_attr);
11541174

11551175
if (par != NULL)
@@ -1204,6 +1224,25 @@ has_upperchr(char *str)
12041224
return false;
12051225
}
12061226

1227+
static void
1228+
reset_searching_lineinfo(LineBuffer *lnb)
1229+
{
1230+
while (lnb != NULL)
1231+
{
1232+
if (lnb->lineinfo != NULL)
1233+
{
1234+
int i;
1235+
1236+
for (i = 0; i < lnb->nrows; i++)
1237+
{
1238+
lnb->lineinfo[i].mask |= LINEINFO_UNKNOWN;
1239+
lnb->lineinfo[i].mask &= ~(LINEINFO_FOUNDSTR | LINEINFO_FOUNDSTR_MULTI);
1240+
}
1241+
}
1242+
lnb = lnb->next;
1243+
}
1244+
}
1245+
12071246

12081247
int
12091248
main(int argc, char *argv[])
@@ -1605,6 +1644,24 @@ main(int argc, char *argv[])
16051644

16061645
doupdate();
16071646

1647+
if (scrdesc.fmt != NULL)
1648+
{
1649+
c2 = show_info_wait(&opts, &scrdesc, scrdesc.fmt, scrdesc.par, scrdesc.beep, false);
1650+
if (scrdesc.fmt != NULL)
1651+
{
1652+
free(scrdesc.fmt);
1653+
scrdesc.fmt = NULL;
1654+
}
1655+
if (scrdesc.par != NULL)
1656+
{
1657+
free(scrdesc.par);
1658+
scrdesc.par = NULL;
1659+
}
1660+
1661+
refresh_aux_windows(&opts, &scrdesc, &desc);
1662+
continue;
1663+
}
1664+
16081665
c = getch();
16091666
redirect_mode = false;
16101667
}
@@ -1647,7 +1704,7 @@ main(int argc, char *argv[])
16471704
use_mouse = true;
16481705
}
16491706

1650-
c2 = show_info_wait(&opts, &scrdesc, " mouse handling: %s ", use_mouse ? "on" : "off", false);
1707+
c2 = show_info_wait(&opts, &scrdesc, " mouse handling: %s ", use_mouse ? "on" : "off", false, false);
16511708
refresh_scr = true;
16521709
}
16531710
if (second_char == 'k') /* ALT k - (un)set bookmark */
@@ -2274,7 +2331,7 @@ main(int argc, char *argv[])
22742331
exit:
22752332

22762333
if (!ok)
2277-
c2 = show_info_wait(&opts, &scrdesc, " Cannot write to %s ", buffer, true);
2334+
c2 = show_info_wait(&opts, &scrdesc, " Cannot write to %s ", buffer, true, false);
22782335

22792336
refresh_scr = true;
22802337

@@ -2295,18 +2352,7 @@ main(int argc, char *argv[])
22952352
scrdesc.searchterm_size = strlen(scrdesc.searchterm);
22962353
scrdesc.searchterm_char_size = utf8len(scrdesc.searchterm);
22972354

2298-
if (!opts.no_highlight_search)
2299-
{
2300-
while (lnb != NULL)
2301-
{
2302-
if (lnb->lineinfo != NULL)
2303-
{
2304-
for (i = 0; i < lnb->nrows; i++)
2305-
lnb->lineinfo[i].mask |= LINEINFO_UNKNOWN;
2306-
}
2307-
lnb = lnb->next;
2308-
}
2309-
}
2355+
reset_searching_lineinfo(&desc.rows);
23102356
}
23112357

23122358
search_direction = SEARCH_FORWARD;
@@ -2350,24 +2396,19 @@ main(int argc, char *argv[])
23502396
const char *str;
23512397

23522398
if (opts.ignore_case || (opts.ignore_lower_case && !scrdesc.has_upperchr))
2353-
{
2354-
if ((str = utf8_nstrstr(lnb->rows[rownum_cursor_row] + skip_bytes, scrdesc.searchterm)))
2355-
{
2356-
scrdesc.found_start_x = utf8len_start_stop(lnb->rows[rownum_cursor_row], str);
2357-
scrdesc.found_start_bytes = str - lnb->rows[rownum_cursor_row];
2358-
scrdesc.found = true;
2359-
goto found_next_pattern;
2360-
}
2361-
}
2399+
str = utf8_nstrstr(lnb->rows[rownum_cursor_row] + skip_bytes, scrdesc.searchterm);
2400+
else if (opts.ignore_lower_case && scrdesc.has_upperchr)
2401+
str = utf8_nstrstr_ignore_lower_case(lnb->rows[rownum_cursor_row] + skip_bytes,
2402+
scrdesc.searchterm);
23622403
else
2404+
str = str = strstr(lnb->rows[rownum_cursor_row] + skip_bytes, scrdesc.searchterm);
2405+
2406+
if (str != NULL)
23632407
{
2364-
if ((str = strstr(lnb->rows[rownum_cursor_row] + skip_bytes, scrdesc.searchterm)))
2365-
{
2366-
scrdesc.found_start_x = utf8len_start_stop(lnb->rows[rownum_cursor_row], str);
2367-
scrdesc.found_start_bytes = str - lnb->rows[rownum_cursor_row];
2368-
scrdesc.found = true;
2369-
goto found_next_pattern;
2370-
}
2408+
scrdesc.found_start_x = utf8len_start_stop(lnb->rows[rownum_cursor_row], str);
2409+
scrdesc.found_start_bytes = str - lnb->rows[rownum_cursor_row];
2410+
scrdesc.found = true;
2411+
goto found_next_pattern;
23712412
}
23722413

23732414
rownum += 1;
@@ -2400,11 +2441,8 @@ main(int argc, char *argv[])
24002441
first_row = max_first_row;
24012442
}
24022443
else
2403-
{
2404-
c2 = show_info_wait(&opts, &scrdesc, " Not found ", NULL, true);
2405-
/* reset search term */
2406-
scrdesc.searchterm[0] = '\0';
2407-
}
2444+
c2 = show_info_wait(&opts, &scrdesc, " Not found ", NULL, true, true);
2445+
24082446
refresh_scr = true;
24092447
}
24102448
break;
@@ -2416,25 +2454,12 @@ main(int argc, char *argv[])
24162454
get_string(&scrdesc, "?", locsearchterm, sizeof(locsearchterm) - 1);
24172455
if (locsearchterm[0] != '\0')
24182456
{
2419-
LineBuffer *lnb = &desc.rows;
2420-
24212457
strncpy(scrdesc.searchterm, locsearchterm, sizeof(scrdesc.searchterm) - 1);
24222458
scrdesc.has_upperchr = has_upperchr(scrdesc.searchterm);
24232459
scrdesc.searchterm_size = strlen(scrdesc.searchterm);
24242460
scrdesc.searchterm_char_size = utf8len(scrdesc.searchterm);
24252461

2426-
if (!opts.no_highlight_search)
2427-
{
2428-
while (lnb != NULL)
2429-
{
2430-
if (lnb->lineinfo != NULL)
2431-
{
2432-
for (i = 0; i < lnb->nrows; i++)
2433-
lnb->lineinfo[i].mask |= LINEINFO_UNKNOWN;
2434-
}
2435-
lnb = lnb->next;
2436-
}
2437-
}
2462+
reset_searching_lineinfo(&desc.rows);
24382463
}
24392464

24402465
search_direction = SEARCH_BACKWARD;
@@ -2515,9 +2540,14 @@ main(int argc, char *argv[])
25152540
/* try to find most right pattern */
25162541
while (str != NULL)
25172542
{
2518-
if (((opts.ignore_case || (opts.ignore_lower_case && !scrdesc.has_upperchr))
2519-
&& (str = utf8_nstrstr(str, scrdesc.searchterm)) != NULL)
2520-
|| (str = strstr(str, scrdesc.searchterm)) != NULL)
2543+
if (opts.ignore_case || (opts.ignore_lower_case && !scrdesc.has_upperchr))
2544+
str = utf8_nstrstr(str, scrdesc.searchterm);
2545+
else if (opts.ignore_lower_case && scrdesc.has_upperchr)
2546+
str = utf8_nstrstr_ignore_lower_case(str, scrdesc.searchterm);
2547+
else
2548+
str = str = strstr(str, scrdesc.searchterm);
2549+
2550+
if (str != NULL)
25212551
{
25222552
cursor_row = search_row;
25232553
if (first_row > cursor_row)
@@ -2546,10 +2576,7 @@ main(int argc, char *argv[])
25462576
}
25472577

25482578
if (!scrdesc.found)
2549-
{
2550-
c2 = show_info_wait(&opts, &scrdesc, " Not found ", NULL, true);
2551-
scrdesc.searchterm[0] = '\0';
2552-
}
2579+
c2 = show_info_wait(&opts, &scrdesc, " Not found ", NULL, true, true);
25532580

25542581
refresh_scr = true;
25552582
}

src/pspg.h

+3
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ typedef struct
125125
int found_row; /* row of found pattern */
126126
int first_rec_title_y; /* y of first displayed record title in expanded mode */
127127
int last_rec_title_y; /* y of last displayed record title in expanded mode */
128+
char *fmt; /* format string for info when refresh first is required */
129+
char *par; /* parameter for info when refresh first is required */
130+
bool beep; /* beep for info when refresh is required */
128131
} ScrDesc;
129132

130133
#define w_luc(scrdesc) ((scrdesc)->wins[WINDOW_LUC])

src/unicode.c

+10-6
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,7 @@ utf8_nstrstr_ignore_lower_case(const char *haystack, const char *needle)
431431
{
432432
int needle_char_len;
433433
int haystack_char_len;
434+
bool needle_char_is_upper;
434435

435436
if (*haystack_cur == '\0')
436437
return NULL;
@@ -441,21 +442,24 @@ utf8_nstrstr_ignore_lower_case(const char *haystack, const char *needle)
441442
{
442443
needle_prev = needle_cur;
443444
needle_char_len = utf8charlen(*needle_cur);
445+
needle_char_is_upper = utf8_isupper(needle_cur);
444446
f1 = utf8_tofold(needle_cur);
445447
}
446448

447-
if (!utf8_isupper(haystack_cur))
448-
{
449-
f2 = utf8_tofold(haystack_cur);
450-
eq = f1 == f2;
451-
}
452-
else
449+
if (needle_char_is_upper)
453450
{
451+
/* case sensitive */
454452
if (needle_char_len == haystack_char_len)
455453
eq = memcmp(haystack_cur, needle_cur, needle_char_len) == 0;
456454
else
457455
eq = false;
458456
}
457+
else
458+
{
459+
/* case insensitive */
460+
f2 = utf8_tofold(haystack_cur);
461+
eq = f1 == f2;
462+
}
459463

460464
if (eq)
461465
{

0 commit comments

Comments
 (0)