MCPcopy Create free account
hub / github.com/FirebirdSQL/firebird / cv_search

Function cv_search

extern/editline/src/search.c:454–522  ·  view source on GitHub ↗

cv_search(): * Vi search. */

Source from the content-addressed store, hash-verified

452 * Vi search.
453 */
454protected el_action_t
455cv_search(EditLine *el, int dir)
456{
457 Char ch;
458 Char tmpbuf[EL_BUFSIZ];
459 ssize_t tmplen;
460
461#ifdef ANCHOR
462 tmpbuf[0] = '.';
463 tmpbuf[1] = '*';
464#endif
465 tmplen = LEN;
466
467 el->el_search.patdir = dir;
468
469 tmplen = c_gets(el, &tmpbuf[LEN],
470 dir == ED_SEARCH_PREV_HISTORY ? STR("\n/") : STR("\n?") );
471 if (tmplen == -1)
472 return CC_REFRESH;
473
474 tmplen += LEN;
475 ch = tmpbuf[tmplen];
476 tmpbuf[tmplen] = '\0';
477
478 if (tmplen == LEN) {
479 /*
480 * Use the old pattern, but wild-card it.
481 */
482 if (el->el_search.patlen == 0) {
483 re_refresh(el);
484 return CC_ERROR;
485 }
486#ifdef ANCHOR
487 if (el->el_search.patbuf[0] != '.' &&
488 el->el_search.patbuf[0] != '*') {
489 (void) Strncpy(tmpbuf, el->el_search.patbuf,
490 sizeof(tmpbuf) / sizeof(*tmpbuf) - 1);
491 el->el_search.patbuf[0] = '.';
492 el->el_search.patbuf[1] = '*';
493 (void) Strncpy(&el->el_search.patbuf[2], tmpbuf,
494 EL_BUFSIZ - 3);
495 el->el_search.patlen++;
496 el->el_search.patbuf[el->el_search.patlen++] = '.';
497 el->el_search.patbuf[el->el_search.patlen++] = '*';
498 el->el_search.patbuf[el->el_search.patlen] = '\0';
499 }
500#endif
501 } else {
502#ifdef ANCHOR
503 tmpbuf[tmplen++] = '.';
504 tmpbuf[tmplen++] = '*';
505#endif
506 tmpbuf[tmplen] = '\0';
507 (void) Strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1);
508 el->el_search.patlen = (size_t)tmplen;
509 }
510 el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */
511 el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer;

Callers 2

vi_search_prevFunction · 0.85
vi_search_nextFunction · 0.85

Calls 5

c_getsFunction · 0.85
re_refreshFunction · 0.85
ed_search_prev_historyFunction · 0.85
ed_search_next_historyFunction · 0.85
ed_newlineFunction · 0.85

Tested by

no test coverage detected