Exemple #1
0
int forwhunt (int f, int n)
{
  int status=FALSE;

  /* resolve the repeat count */
  if (n == 0)
    n = 1;
  if (n < 1)			/* search backwards */
    return (backhunt (f, -n));

  /* Make sure a pattern exists */
  if (pat[0] == 0)
    {
      mlwrite ("No pattern set");
      return (FALSE);
    }
  /* search for the pattern */
  while (n-- > 0)
    {
      if ((status = forscan (&pat[0], PTEND)) == FALSE)
	break;
    }

  /* and complain if not there */
  if (status == FALSE)
    mlwrite ("Not found");
  return (status);
}
Exemple #2
0
/* reverse the search direction */
int
revsearch(int f, int n)
{
    if (last_srch_direc == FORWARD)
	return (backhunt(f, n));
    else
	return (forwhunt(f, n));
}
Exemple #3
0
/*
 * forwhunt -- repeat previous forward search
 */
int
forwhunt(int f, int n)
{
    int status = TRUE;
    int wrapok;
    MARK curpos;
    int didwrap;

    assert(curwp != 0);

    wrapok = window_b_val(curwp, MDWRAPSCAN);

    if (f && n < 0)		/* search backwards */
	return (backhunt(f, -n));

    if (n == 0)
	n = 1;

    /* Make sure a pattern exists */
    if (tb_length(searchpat) == 0) {
	mlforce("[No pattern set]");
	return FALSE;
    }

    ignorecase = window_b_val(curwp, MDIGNCASE);

    if (curwp == 0)
	return FALSE;

    /* find n'th occurrence of pattern
     */
    curpos = DOT;
    scanboundry(wrapok, DOT, FORWARD);
    didwrap = FALSE;
    while (n--) {
	movenext(&(DOT), FORWARD);
	status = scanner(gregexp, FORWARD, wrapok, &didwrap);
	if (didwrap) {
	    mlwrite("[Search wrapped past end of buffer]");
	    didwrap = FALSE;
	}
	if (status != TRUE)
	    break;
    }

    if (status == TRUE) {
	savematch(DOT, gregexp->mlen);
	if (samepoint(DOT, curpos)) {
	    mlwrite(onlyonemsg);
	} else if (gregexp->mlen == 0
		   && is_header_line(DOT, curbp)) {
	    movenext(&(DOT), FORWARD);
	}
    } else if (status == FALSE) {
	movenext(&(DOT), REVERSE);
	not_found_msg(wrapok, FORWARD);
    } else if (status == ABORT) {
	mlwarn("[Aborted]");
	DOT = curpos;
	return status;
    }
    attrib_matches();
    return status;
}