search.c (84334) | search.c (148834) |
---|---|
1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. | 1/*- 2 * Copyright (c) 1992, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Christos Zoulas of Cornell University. 7 * 8 * Redistribution and use in source and binary forms, with or without 9 * modification, are permitted provided that the following conditions 10 * are met: 11 * 1. Redistributions of source code must retain the above copyright 12 * notice, this list of conditions and the following disclaimer. 13 * 2. Redistributions in binary form must reproduce the above copyright 14 * notice, this list of conditions and the following disclaimer in the 15 * documentation and/or other materials provided with the distribution. |
16 * 3. All advertising materials mentioning features or use of this software 17 * must display the following acknowledgement: 18 * This product includes software developed by the University of 19 * California, Berkeley and its contributors. 20 * 4. Neither the name of the University nor the names of its contributors | 16 * 3. Neither the name of the University nor the names of its contributors |
21 * may be used to endorse or promote products derived from this software 22 * without specific prior written permission. 23 * 24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 34 * SUCH DAMAGE. 35 * | 17 * may be used to endorse or promote products derived from this software 18 * without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * |
36 * $NetBSD: search.c,v 1.10 2001/01/04 15:56:32 christos Exp $ | 32 * $NetBSD: search.c,v 1.20 2004/11/04 01:16:03 christos Exp $ |
37 */ 38 39#if !defined(lint) && !defined(SCCSID) 40static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93"; 41#endif /* not lint && not SCCSID */ 42#include <sys/cdefs.h> | 33 */ 34 35#if !defined(lint) && !defined(SCCSID) 36static char sccsid[] = "@(#)search.c 8.1 (Berkeley) 6/4/93"; 37#endif /* not lint && not SCCSID */ 38#include <sys/cdefs.h> |
43__FBSDID("$FreeBSD: head/lib/libedit/search.c 84334 2001-10-01 23:00:29Z obrien $"); | 39__FBSDID("$FreeBSD: head/lib/libedit/search.c 148834 2005-08-07 20:55:59Z stefanf $"); |
44 45/* 46 * search.c: History and character search functions 47 */ 48#include "sys.h" 49#include <stdlib.h> 50#if defined(REGEX) 51#include <regex.h> --- 17 unchanged lines hidden (view full) --- 69{ 70 71 el->el_search.patbuf = (char *) el_malloc(EL_BUFSIZ); 72 if (el->el_search.patbuf == NULL) 73 return (-1); 74 el->el_search.patlen = 0; 75 el->el_search.patdir = -1; 76 el->el_search.chacha = '\0'; | 40 41/* 42 * search.c: History and character search functions 43 */ 44#include "sys.h" 45#include <stdlib.h> 46#if defined(REGEX) 47#include <regex.h> --- 17 unchanged lines hidden (view full) --- 65{ 66 67 el->el_search.patbuf = (char *) el_malloc(EL_BUFSIZ); 68 if (el->el_search.patbuf == NULL) 69 return (-1); 70 el->el_search.patlen = 0; 71 el->el_search.patdir = -1; 72 el->el_search.chacha = '\0'; |
77 el->el_search.chadir = -1; | 73 el->el_search.chadir = CHAR_FWD; 74 el->el_search.chatflg = 0; |
78 return (0); 79} 80 81 82/* search_end(): 83 * Initialize the search stuff 84 */ 85protected void --- 132 unchanged lines hidden (view full) --- 218 el->el_search.patlen >= el->el_line.limit) 219 return (CC_ERROR); 220 221 for (;;) { 222 223 if (el->el_search.patlen == 0) { /* first round */ 224 pchar = ':'; 225#ifdef ANCHOR | 75 return (0); 76} 77 78 79/* search_end(): 80 * Initialize the search stuff 81 */ 82protected void --- 132 unchanged lines hidden (view full) --- 215 el->el_search.patlen >= el->el_line.limit) 216 return (CC_ERROR); 217 218 for (;;) { 219 220 if (el->el_search.patlen == 0) { /* first round */ 221 pchar = ':'; 222#ifdef ANCHOR |
223#define LEN 2 |
|
226 el->el_search.patbuf[el->el_search.patlen++] = '.'; 227 el->el_search.patbuf[el->el_search.patlen++] = '*'; | 224 el->el_search.patbuf[el->el_search.patlen++] = '.'; 225 el->el_search.patbuf[el->el_search.patlen++] = '*'; |
226#else 227#define LEN 0 |
|
228#endif 229 } 230 done = redo = 0; 231 *el->el_line.lastchar++ = '\n'; 232 for (cp = (newdir == ED_SEARCH_PREV_HISTORY) ? STRbck : STRfwd; 233 *cp; *el->el_line.lastchar++ = *cp++) 234 continue; 235 *el->el_line.lastchar++ = pchar; | 228#endif 229 } 230 done = redo = 0; 231 *el->el_line.lastchar++ = '\n'; 232 for (cp = (newdir == ED_SEARCH_PREV_HISTORY) ? STRbck : STRfwd; 233 *cp; *el->el_line.lastchar++ = *cp++) 234 continue; 235 *el->el_line.lastchar++ = pchar; |
236 for (cp = &el->el_search.patbuf[1]; | 236 for (cp = &el->el_search.patbuf[LEN]; |
237 cp < &el->el_search.patbuf[el->el_search.patlen]; 238 *el->el_line.lastchar++ = *cp++) 239 continue; 240 *el->el_line.lastchar = '\0'; 241 re_refresh(el); 242 243 if (el_getc(el, &ch) != 1) 244 return (ed_end_of_file(el, 0)); 245 246 switch (el->el_map.current[(unsigned char) ch]) { 247 case ED_INSERT: 248 case ED_DIGIT: | 237 cp < &el->el_search.patbuf[el->el_search.patlen]; 238 *el->el_line.lastchar++ = *cp++) 239 continue; 240 *el->el_line.lastchar = '\0'; 241 re_refresh(el); 242 243 if (el_getc(el, &ch) != 1) 244 return (ed_end_of_file(el, 0)); 245 246 switch (el->el_map.current[(unsigned char) ch]) { 247 case ED_INSERT: 248 case ED_DIGIT: |
249 if (el->el_search.patlen > EL_BUFSIZ - 3) | 249 if (el->el_search.patlen >= EL_BUFSIZ - LEN) |
250 term_beep(el); 251 else { 252 el->el_search.patbuf[el->el_search.patlen++] = 253 ch; 254 *el->el_line.lastchar++ = ch; 255 *el->el_line.lastchar = '\0'; 256 re_refresh(el); 257 } --- 4 unchanged lines hidden (view full) --- 262 redo++; 263 break; 264 265 case EM_INC_SEARCH_PREV: 266 newdir = ED_SEARCH_PREV_HISTORY; 267 redo++; 268 break; 269 | 250 term_beep(el); 251 else { 252 el->el_search.patbuf[el->el_search.patlen++] = 253 ch; 254 *el->el_line.lastchar++ = ch; 255 *el->el_line.lastchar = '\0'; 256 re_refresh(el); 257 } --- 4 unchanged lines hidden (view full) --- 262 redo++; 263 break; 264 265 case EM_INC_SEARCH_PREV: 266 newdir = ED_SEARCH_PREV_HISTORY; 267 redo++; 268 break; 269 |
270 case EM_DELETE_PREV_CHAR: |
|
270 case ED_DELETE_PREV_CHAR: | 271 case ED_DELETE_PREV_CHAR: |
271 if (el->el_search.patlen > 1) | 272 if (el->el_search.patlen > LEN) |
272 done++; 273 else 274 term_beep(el); 275 break; 276 277 default: 278 switch (ch) { 279 case 0007: /* ^G: Abort */ 280 ret = CC_ERROR; 281 done++; 282 break; 283 284 case 0027: /* ^W: Append word */ 285 /* No can do if globbing characters in pattern */ | 273 done++; 274 else 275 term_beep(el); 276 break; 277 278 default: 279 switch (ch) { 280 case 0007: /* ^G: Abort */ 281 ret = CC_ERROR; 282 done++; 283 break; 284 285 case 0027: /* ^W: Append word */ 286 /* No can do if globbing characters in pattern */ |
286 for (cp = &el->el_search.patbuf[1];; cp++) 287 if (cp >= &el->el_search.patbuf[el->el_search.patlen]) { | 287 for (cp = &el->el_search.patbuf[LEN];; cp++) 288 if (cp >= &el->el_search.patbuf[ 289 el->el_search.patlen]) { |
288 el->el_line.cursor += | 290 el->el_line.cursor += |
289 el->el_search.patlen - 1; | 291 el->el_search.patlen - LEN - 1; |
290 cp = c__next_word(el->el_line.cursor, 291 el->el_line.lastchar, 1, 292 ce__isword); 293 while (el->el_line.cursor < cp && 294 *el->el_line.cursor != '\n') { | 292 cp = c__next_word(el->el_line.cursor, 293 el->el_line.lastchar, 1, 294 ce__isword); 295 while (el->el_line.cursor < cp && 296 *el->el_line.cursor != '\n') { |
295 if (el->el_search.patlen > 296 EL_BUFSIZ - 3) { | 297 if (el->el_search.patlen >= 298 EL_BUFSIZ - LEN) { |
297 term_beep(el); 298 break; 299 } 300 el->el_search.patbuf[el->el_search.patlen++] = 301 *el->el_line.cursor; 302 *el->el_line.lastchar++ = 303 *el->el_line.cursor++; 304 } --- 25 unchanged lines hidden (view full) --- 330 *el->el_line.lastchar-- = '\0'; 331 *el->el_line.lastchar = '\0'; 332 333 if (!done) { 334 335 /* Can't search if unmatched '[' */ 336 for (cp = &el->el_search.patbuf[el->el_search.patlen-1], 337 ch = ']'; | 299 term_beep(el); 300 break; 301 } 302 el->el_search.patbuf[el->el_search.patlen++] = 303 *el->el_line.cursor; 304 *el->el_line.lastchar++ = 305 *el->el_line.cursor++; 306 } --- 25 unchanged lines hidden (view full) --- 332 *el->el_line.lastchar-- = '\0'; 333 *el->el_line.lastchar = '\0'; 334 335 if (!done) { 336 337 /* Can't search if unmatched '[' */ 338 for (cp = &el->el_search.patbuf[el->el_search.patlen-1], 339 ch = ']'; |
338 cp > el->el_search.patbuf; | 340 cp >= &el->el_search.patbuf[LEN]; |
339 cp--) 340 if (*cp == '[' || *cp == ']') { 341 ch = *cp; 342 break; 343 } | 341 cp--) 342 if (*cp == '[' || *cp == ']') { 343 ch = *cp; 344 break; 345 } |
344 if (el->el_search.patlen > 1 && ch != '[') { | 346 if (el->el_search.patlen > LEN && ch != '[') { |
345 if (redo && newdir == dir) { 346 if (pchar == '?') { /* wrap around */ 347 el->el_history.eventno = 348 newdir == ED_SEARCH_PREV_HISTORY ? 0 : 0x7fffffff; 349 if (hist_get(el) == CC_ERROR) 350 /* el->el_history.event 351 * no was fixed by 352 * first call */ --- 13 unchanged lines hidden (view full) --- 366 '.'; 367 el->el_search.patbuf[el->el_search.patlen++] = 368 '*'; 369#endif 370 el->el_search.patbuf[el->el_search.patlen] = 371 '\0'; 372 if (el->el_line.cursor < el->el_line.buffer || 373 el->el_line.cursor > el->el_line.lastchar || | 347 if (redo && newdir == dir) { 348 if (pchar == '?') { /* wrap around */ 349 el->el_history.eventno = 350 newdir == ED_SEARCH_PREV_HISTORY ? 0 : 0x7fffffff; 351 if (hist_get(el) == CC_ERROR) 352 /* el->el_history.event 353 * no was fixed by 354 * first call */ --- 13 unchanged lines hidden (view full) --- 368 '.'; 369 el->el_search.patbuf[el->el_search.patlen++] = 370 '*'; 371#endif 372 el->el_search.patbuf[el->el_search.patlen] = 373 '\0'; 374 if (el->el_line.cursor < el->el_line.buffer || 375 el->el_line.cursor > el->el_line.lastchar || |
374 (ret = ce_search_line(el, 375 &el->el_search.patbuf[1], 376 newdir)) == CC_ERROR) { | 376 (ret = ce_search_line(el, newdir)) 377 == CC_ERROR) { |
377 /* avoid c_setpat */ 378 el->el_state.lastcmd = 379 (el_action_t) newdir; 380 ret = newdir == ED_SEARCH_PREV_HISTORY ? 381 ed_search_prev_history(el, 0) : 382 ed_search_next_history(el, 0); 383 if (ret != CC_ERROR) { 384 el->el_line.cursor = newdir == 385 ED_SEARCH_PREV_HISTORY ? 386 el->el_line.lastchar : 387 el->el_line.buffer; 388 (void) ce_search_line(el, | 378 /* avoid c_setpat */ 379 el->el_state.lastcmd = 380 (el_action_t) newdir; 381 ret = newdir == ED_SEARCH_PREV_HISTORY ? 382 ed_search_prev_history(el, 0) : 383 ed_search_next_history(el, 0); 384 if (ret != CC_ERROR) { 385 el->el_line.cursor = newdir == 386 ED_SEARCH_PREV_HISTORY ? 387 el->el_line.lastchar : 388 el->el_line.buffer; 389 (void) ce_search_line(el, |
389 &el->el_search.patbuf[1], | |
390 newdir); 391 } 392 } | 390 newdir); 391 } 392 } |
393 el->el_search.patbuf[--el->el_search.patlen] = | 393 el->el_search.patlen -= LEN; 394 el->el_search.patbuf[el->el_search.patlen] = |
394 '\0'; 395 if (ret == CC_ERROR) { 396 term_beep(el); 397 if (el->el_history.eventno != 398 ohisteventno) { 399 el->el_history.eventno = 400 ohisteventno; 401 if (hist_get(el) == CC_ERROR) --- 39 unchanged lines hidden (view full) --- 441 */ 442protected el_action_t 443cv_search(EditLine *el, int dir) 444{ 445 char ch; 446 char tmpbuf[EL_BUFSIZ]; 447 int tmplen; 448 | 395 '\0'; 396 if (ret == CC_ERROR) { 397 term_beep(el); 398 if (el->el_history.eventno != 399 ohisteventno) { 400 el->el_history.eventno = 401 ohisteventno; 402 if (hist_get(el) == CC_ERROR) --- 39 unchanged lines hidden (view full) --- 442 */ 443protected el_action_t 444cv_search(EditLine *el, int dir) 445{ 446 char ch; 447 char tmpbuf[EL_BUFSIZ]; 448 int tmplen; 449 |
449 tmplen = 0; | |
450#ifdef ANCHOR | 450#ifdef ANCHOR |
451 tmpbuf[tmplen++] = '.'; 452 tmpbuf[tmplen++] = '*'; | 451 tmpbuf[0] = '.'; 452 tmpbuf[1] = '*'; |
453#endif | 453#endif |
454 tmplen = LEN; |
|
454 | 455 |
455 el->el_line.buffer[0] = '\0'; 456 el->el_line.lastchar = el->el_line.buffer; 457 el->el_line.cursor = el->el_line.buffer; | |
458 el->el_search.patdir = dir; 459 | 456 el->el_search.patdir = dir; 457 |
460 c_insert(el, 2); /* prompt + '\n' */ 461 *el->el_line.cursor++ = '\n'; 462 *el->el_line.cursor++ = dir == ED_SEARCH_PREV_HISTORY ? '/' : '?'; 463 re_refresh(el); | 458 tmplen = c_gets(el, &tmpbuf[LEN], 459 dir == ED_SEARCH_PREV_HISTORY ? "\n/" : "\n?" ); 460 if (tmplen == -1) 461 return CC_REFRESH; |
464 | 462 |
465#ifdef ANCHOR 466#define LEN 2 467#else 468#define LEN 0 469#endif 470 471 tmplen = c_gets(el, &tmpbuf[LEN]) + LEN; | 463 tmplen += LEN; |
472 ch = tmpbuf[tmplen]; 473 tmpbuf[tmplen] = '\0'; 474 475 if (tmplen == LEN) { 476 /* 477 * Use the old pattern, but wild-card it. 478 */ 479 if (el->el_search.patlen == 0) { | 464 ch = tmpbuf[tmplen]; 465 tmpbuf[tmplen] = '\0'; 466 467 if (tmplen == LEN) { 468 /* 469 * Use the old pattern, but wild-card it. 470 */ 471 if (el->el_search.patlen == 0) { |
480 el->el_line.buffer[0] = '\0'; 481 el->el_line.lastchar = el->el_line.buffer; 482 el->el_line.cursor = el->el_line.buffer; | |
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) - 1); --- 14 unchanged lines hidden (view full) --- 505#endif 506 tmpbuf[tmplen] = '\0'; 507 (void) strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1); 508 el->el_search.patlen = 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; 512 if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) : | 472 re_refresh(el); 473 return (CC_ERROR); 474 } 475#ifdef ANCHOR 476 if (el->el_search.patbuf[0] != '.' && 477 el->el_search.patbuf[0] != '*') { 478 (void) strncpy(tmpbuf, el->el_search.patbuf, 479 sizeof(tmpbuf) - 1); --- 14 unchanged lines hidden (view full) --- 494#endif 495 tmpbuf[tmplen] = '\0'; 496 (void) strncpy(el->el_search.patbuf, tmpbuf, EL_BUFSIZ - 1); 497 el->el_search.patlen = tmplen; 498 } 499 el->el_state.lastcmd = (el_action_t) dir; /* avoid c_setpat */ 500 el->el_line.cursor = el->el_line.lastchar = el->el_line.buffer; 501 if ((dir == ED_SEARCH_PREV_HISTORY ? ed_search_prev_history(el, 0) : |
513 ed_search_next_history(el, 0)) == CC_ERROR) { | 502 ed_search_next_history(el, 0)) == CC_ERROR) { |
514 re_refresh(el); 515 return (CC_ERROR); | 503 re_refresh(el); 504 return (CC_ERROR); |
516 } else { 517 if (ch == 0033) { 518 re_refresh(el); 519 *el->el_line.lastchar++ = '\n'; 520 *el->el_line.lastchar = '\0'; 521 re_goto_bottom(el); 522 return (CC_NEWLINE); 523 } else 524 return (CC_REFRESH); | |
525 } | 505 } |
506 if (ch == 0033) { 507 re_refresh(el); 508 return ed_newline(el, 0); 509 } 510 return (CC_REFRESH); |
|
526} 527 528 529/* ce_search_line(): 530 * Look for a pattern inside a line 531 */ 532protected el_action_t | 511} 512 513 514/* ce_search_line(): 515 * Look for a pattern inside a line 516 */ 517protected el_action_t |
533ce_search_line(EditLine *el, char *pattern, int dir) | 518ce_search_line(EditLine *el, int dir) |
534{ | 519{ |
535 char *cp; | 520 char *cp = el->el_line.cursor; 521 char *pattern = el->el_search.patbuf; 522 char oc, *ocp; 523#ifdef ANCHOR 524 ocp = &pattern[1]; 525 oc = *ocp; 526 *ocp = '^'; 527#else 528 ocp = pattern; 529 oc = *ocp; 530#endif |
536 537 if (dir == ED_SEARCH_PREV_HISTORY) { | 531 532 if (dir == ED_SEARCH_PREV_HISTORY) { |
538 for (cp = el->el_line.cursor; cp >= el->el_line.buffer; cp--) 539 if (el_match(cp, pattern)) { | 533 for (; cp >= el->el_line.buffer; cp--) { 534 if (el_match(cp, ocp)) { 535 *ocp = oc; |
540 el->el_line.cursor = cp; 541 return (CC_NORM); 542 } | 536 el->el_line.cursor = cp; 537 return (CC_NORM); 538 } |
539 } 540 *ocp = oc; |
|
543 return (CC_ERROR); 544 } else { | 541 return (CC_ERROR); 542 } else { |
545 for (cp = el->el_line.cursor; *cp != '\0' && 546 cp < el->el_line.limit; cp++) 547 if (el_match(cp, pattern)) { | 543 for (; *cp != '\0' && cp < el->el_line.limit; cp++) { 544 if (el_match(cp, ocp)) { 545 *ocp = oc; |
548 el->el_line.cursor = cp; 549 return (CC_NORM); 550 } | 546 el->el_line.cursor = cp; 547 return (CC_NORM); 548 } |
549 } 550 *ocp = oc; |
|
551 return (CC_ERROR); 552 } 553} 554 555 556/* cv_repeat_srch(): 557 * Vi repeat search 558 */ --- 15 unchanged lines hidden (view full) --- 574 case ED_SEARCH_PREV_HISTORY: 575 return (ed_search_prev_history(el, 0)); 576 default: 577 return (CC_ERROR); 578 } 579} 580 581 | 551 return (CC_ERROR); 552 } 553} 554 555 556/* cv_repeat_srch(): 557 * Vi repeat search 558 */ --- 15 unchanged lines hidden (view full) --- 574 case ED_SEARCH_PREV_HISTORY: 575 return (ed_search_prev_history(el, 0)); 576 default: 577 return (CC_ERROR); 578 } 579} 580 581 |
582/* cv_csearch_back(): 583 * Vi character search reverse | 582/* cv_csearch(): 583 * Vi character search |
584 */ 585protected el_action_t | 584 */ 585protected el_action_t |
586cv_csearch_back(EditLine *el, int ch, int count, int tflag) | 586cv_csearch(EditLine *el, int direction, int ch, int count, int tflag) |
587{ 588 char *cp; 589 | 587{ 588 char *cp; 589 |
590 cp = el->el_line.cursor; 591 while (count--) { 592 if (*cp == ch) 593 cp--; 594 while (cp > el->el_line.buffer && *cp != ch) 595 cp--; 596 } | 590 if (ch == 0) 591 return CC_ERROR; |
597 | 592 |
598 if (cp < el->el_line.buffer || (cp == el->el_line.buffer && *cp != ch)) 599 return (CC_ERROR); 600 601 if (*cp == ch && tflag) 602 cp++; 603 604 el->el_line.cursor = cp; 605 606 if (el->el_chared.c_vcmd.action & DELETE) { 607 el->el_line.cursor++; 608 cv_delfini(el); 609 return (CC_REFRESH); | 593 if (ch == -1) { 594 char c; 595 if (el_getc(el, &c) != 1) 596 return ed_end_of_file(el, 0); 597 ch = c; |
610 } | 598 } |
611 re_refresh_cursor(el); 612 return (CC_NORM); 613} | |
614 | 599 |
600 /* Save for ';' and ',' commands */ 601 el->el_search.chacha = ch; 602 el->el_search.chadir = direction; 603 el->el_search.chatflg = tflag; |
|
615 | 604 |
616/* cv_csearch_fwd(): 617 * Vi character search forward 618 */ 619protected el_action_t 620cv_csearch_fwd(EditLine *el, int ch, int count, int tflag) 621{ 622 char *cp; 623 | |
624 cp = el->el_line.cursor; 625 while (count--) { 626 if (*cp == ch) | 605 cp = el->el_line.cursor; 606 while (count--) { 607 if (*cp == ch) |
627 cp++; 628 while (cp < el->el_line.lastchar && *cp != ch) 629 cp++; | 608 cp += direction; 609 for (;;cp += direction) { 610 if (cp >= el->el_line.lastchar) 611 return CC_ERROR; 612 if (cp < el->el_line.buffer) 613 return CC_ERROR; 614 if (*cp == ch) 615 break; 616 } |
630 } 631 | 617 } 618 |
632 if (cp >= el->el_line.lastchar) 633 return (CC_ERROR); | 619 if (tflag) 620 cp -= direction; |
634 | 621 |
635 if (*cp == ch && tflag) 636 cp--; 637 | |
638 el->el_line.cursor = cp; 639 | 622 el->el_line.cursor = cp; 623 |
640 if (el->el_chared.c_vcmd.action & DELETE) { 641 el->el_line.cursor++; | 624 if (el->el_chared.c_vcmd.action != NOP) { 625 if (direction > 0) 626 el->el_line.cursor++; |
642 cv_delfini(el); | 627 cv_delfini(el); |
643 return (CC_REFRESH); | 628 return CC_REFRESH; |
644 } | 629 } |
645 re_refresh_cursor(el); 646 return (CC_NORM); | 630 return CC_CURSOR; |
647} | 631} |