Esempio n. 1
0
/* ARGSUSED */
int
killpara(int f, int n)
{
    int	lineno, status;

    if (n == 0)
        return (TRUE);

    if (findpara() == FALSE)
        return (TRUE);

    /* go to the beginning of the paragraph */
    (void)gotobop(FFRAND, 1);

    /* take a note of the line number for after deletions and set mark */
    lineno = curwp->w_dotline;
    curwp->w_markp = curwp->w_dotp;
    curwp->w_marko = curwp->w_doto;

    (void)gotoeop(FFRAND, n);

    if ((status = killregion(FFRAND, 1)) != TRUE)
        return (status);

    curwp->w_dotline = lineno;
    return (TRUE);
}
Esempio n. 2
0
/* ARGSUSED */
int
gotobop(int f, int n)
{
    int col, nospace;

    /* the other way... */
    if (n < 0)
        return (gotoeop(f, -n));

    while (n-- > 0) {
        nospace = 0;
        while (lback(curwp->w_dotp) != curbp->b_headp) {
            curwp->w_doto = 0;
            col = 0;

            while (col < llength(curwp->w_dotp) &&
                    (isspace(lgetc(curwp->w_dotp, col))))
                col++;

            if (col >= llength(curwp->w_dotp)) {
                if (nospace)
                    break;
            } else
                nospace = 1;

            curwp->w_dotline--;
            curwp->w_dotp = lback(curwp->w_dotp);
        }
    }
    /* force screen update */
    curwp->w_rflag |= WFMOVE;
    return (TRUE);
}
Esempio n. 3
0
/* ARGSUSED */
int
killpara(int f, int n)
{
	int	status;		/* returned status of functions */

	/* for each paragraph to delete */
	while (n--) {

		/* mark out the end and beginning of the para to delete */
		(void)gotoeop(FFRAND, 1);

		/* set the mark here */
		curwp->w_markp = curwp->w_dotp;
		curwp->w_marko = curwp->w_doto;

		/* go to the beginning of the paragraph */
		(void)gotobop(FFRAND, 1);

		/* force us to the beginning of line */
		curwp->w_doto = 0;

		/* and delete it */
		if ((status = killregion(FFRAND, 1)) != TRUE)
			return (status);

		/* and clean up the 2 extra lines */
		(void)ldelete((RSIZE) 1, KFORW);
	}
	return (TRUE);
}
Esempio n. 4
0
/*
 * Delete n paragraphs starting with the current one.
 */
int
killpara (int f, int n, int k)
{
  register int status;		/* returned status of functions */

  while (n--)
    {				/* for each paragraph to delete */

      /* mark out the end and begining of the para to delete */
      gotoeop (FALSE, 1, KRANDOM);

      /* set the mark here */
      curwp->w_mark = curwp->w_dot;

      /* go to the begining of the paragraph */
      gotobop (FALSE, 1, KRANDOM);
      curwp->w_dot.o = 0;	/* force us to the begining of line */

      /* and delete it */
      if ((status = killregion (FALSE, 1, KRANDOM)) != TRUE)
	return (status);

      /* and clean up the 2 extra lines */
      ldelete (1, TRUE);
    }
  return (TRUE);
}
Esempio n. 5
0
File: basic.c Progetto: aksr/esnc
/* go back to the begining of the current paragraph here we look for a
 * <NL><NL> or <NL><TAB> or <NL><SPACE> combination to delimit the begining of
 * a paragraph
 */
int gotobop (int f, int n)
{
  int suc;			/* success of last backchar */

  if (n < 0)			/* the other way.. */
    return (gotoeop (f, -n));

  while (n-- > 0)
    {				/* for each one asked for */
      /* first scan back until we are in a word */
      suc = backchar (FALSE, 1);
      while (!inword () && suc)
	suc = backchar (FALSE, 1);
      curwp->w_doto = 0;	/* and go to the B-O-Line */

      /* and scan back until we hit a <NL><NL> or <NL><TAB> or a <NL><SPACE> */
      while (lback (curwp->w_dotp) != curbp->b_linep)
	if (llength (curwp->w_dotp) != 0 &&
	    lgetc (curwp->w_dotp, curwp->w_doto) != TAB &&
	    lgetc (curwp->w_dotp, curwp->w_doto) != ' ')
	  curwp->w_dotp = lback (curwp->w_dotp);
	else
	  break;

      /* and then forward until we are in a word */
      suc = forwchar (FALSE, 1);
      while (suc && !inword ())
	suc = forwchar (FALSE, 1);
    }
  curwp->w_flag |= WFMOVE;	/* force screen update */
  return (TRUE);
}
Esempio n. 6
0
/* ARGSUSED */
int
killpara(int f, int n)
{
	int	status, end = FALSE;	/* returned status of functions */

	/* for each paragraph to delete */
	while (n--) {

		/* mark out the end and beginning of the para to delete */
		if (!gotoeop(FFRAND, 1))
			end = TRUE;

		/* set the mark here */
		curwp->w_markp = curwp->w_dotp;
		curwp->w_marko = curwp->w_doto;

		/* go to the beginning of the paragraph */
		(void)gotobop(FFRAND, 1);

		/* force us to the beginning of line */
		curwp->w_doto = 0;

		/* and delete it */
		if ((status = killregion(FFRAND, 1)) != TRUE)
			return (status);

		if (end)
			return (TRUE);
	}
	return (TRUE);
}
Esempio n. 7
0
/* ARGSUSED */
int
gotobop(int f, int n)
{
	/* the other way... */
	if (n < 0)
		return (gotoeop(f, -n));

	while (n-- > 0) {
		/* first scan back until we are in a word */
		while (backchar(FFRAND, 1) && inword() == 0);

		/* and go to the B-O-Line */
		curwp->w_doto = 0;

		/*
		 * and scan back until we hit a <NL><SP> <NL><TAB> or
		 * <NL><NL>
		 */
		while (lback(curwp->w_dotp) != curbp->b_headp)
			if (llength(lback(curwp->w_dotp)) &&
			    lgetc(curwp->w_dotp, 0) != ' ' &&
			    lgetc(curwp->w_dotp, 0) != '.' &&
			    lgetc(curwp->w_dotp, 0) != '\t')
				curwp->w_dotp = lback(curwp->w_dotp);
			else {
				if (llength(lback(curwp->w_dotp)) &&
				    lgetc(curwp->w_dotp, 0) == '.') {
					curwp->w_dotp = lforw(curwp->w_dotp);
					if (curwp->w_dotp == curbp->b_headp) {
						/*
						 * beyond end of buffer,
						 * cleanup time
						 */
						curwp->w_dotp =
						    lback(curwp->w_dotp);
						curwp->w_doto =
						    llength(curwp->w_dotp);
					}
				}
				break;
			}
	}
	/* force screen update */
	curwp->w_rflag |= WFMOVE;
	return (TRUE);
}
Esempio n. 8
0
/* ARGSUSED */
int
transposepara(int f, int n)
{
	int	i = 0, status;
	char	flg;

	if (n == 0)
		return (TRUE);

	undo_boundary_enable(FFRAND, 0);

	/* find a paragraph, set mark, then goto the end */
	gotobop(FFRAND, 1);
	curwp->w_markp = curwp->w_dotp;
	curwp->w_marko = curwp->w_doto;
	(void)gotoeop(FFRAND, 1);

	/* take a note of buffer flags - we may need them */
	flg = curbp->b_flag;	

	/* clean out kill buffer then kill region */
	kdelete();
	if ((status = killregion(FFRAND, 1)) != TRUE)
		return (status);

	/* 
	 * Now step through n paragraphs. If we reach the end of buffer,
	 * stop and paste the killed region back, then display a message.
	 */
	if (do_gotoeop(FFRAND, n, &i) == FALSE) {
		ewprintf("Cannot transpose paragraph, end of buffer reached.");
		(void)gotobop(FFRAND, i);
		(void)yank(FFRAND, 1);
		curbp->b_flag = flg;	
		return (FALSE);
	}
	(void)yank(FFRAND, 1);

	undo_boundary_enable(FFRAND, 1);

	return (TRUE);
}
Esempio n. 9
0
/*
 * Go back to the begining of the current paragraph.
 * We look for a <NL><NL> or <NL><TAB> or <NL><SPACE>
 * or <NL>@ or <NL>. (scribe and nroff commands)
 * combination to delimit the begining of a paragraph.
 */
int
gotobop (int f, int n, int k)
{
  register int c;		/* first character in current line */
  register LINE *prev;		/* previous line */

  if (n < 0)			/* the other way... */
    return (gotoeop (f, -n, KRANDOM));

  while (n-- > 0)
    {				/* for each one asked for */

      /* first scan back until we are in a word */
      while (backchar (FALSE, 1, KRANDOM))
	if (inword ())
	  break;
      curwp->w_dot.o = 0;	/* and go to the B-O-Line */

      /* and scan back until we hit a paragraph delimiter as
       * described above.
       */
      while ((prev = lback (curwp->w_dot.p)) != curbp->b_linep)
	{
	  if (llength (prev) == 0)
	    break;
	  c = lgetc (curwp->w_dot.p, 0);
	  if (c == ' ' || c == '\t')
	    break;
	  c = lgetc (prev, 0);
	  if (c == '@' || c == '.')
	    break;
	  else
	    curwp->w_dot.p = prev;
	}
    }
  curwp->w_flag |= WFMOVE;	/* force screen update */
  return TRUE;
}
Esempio n. 10
0
/*
 * Fill the current paragraph according to the current fill column
 */
int
fillpara(int f, int n)
{
    UCS    *qstr, qstr2[NSTRING], c;
    int     quotelevel = -1;
    REGION  addedregion;
    char    action = 'P';

    if(curbp->b_mode&MDVIEW){		/* don't allow this command if	*/
	return(rdonly());		/* we are in read only mode	*/
    }
    else if (fillcol == 0) {		/* no fill column set */
	mlwrite_utf8("No fill column set", NULL);
	return(FALSE);
    }
    else if(curwp->w_dotp == curbp->b_linep && !curwp->w_markp) /* don't wrap! */
      return(FALSE);

    /*
     * If there is already a region set, then we may use it
     * instead of the current paragraph.
     */

    if(curwp->w_markp){
	int k, rv;
	KEYMENU menu_justify[12];
	char prompt[100];

	for(k = 0; k < 12; k++){
	    menu_justify[k].name = NULL;
	    KS_OSDATASET(&menu_justify[k], KS_NONE);
	}

	menu_justify[1].name  = "R";
	menu_justify[1].label = "[" N_("Region") "]";
	menu_justify[6].name  = "^C";
	menu_justify[6].label = N_("Cancel");
	menu_justify[7].name  = "P";
	menu_justify[7].label = N_("Paragraph");
	menu_justify[2].name  = "Q";
	menu_justify[2].label = N_("Quotelevel");

	wkeyhelp(menu_justify);		/* paint menu */
	sgarbk = TRUE;
	if(Pmaster && curwp)
	  curwp->w_flag |= WFMODE;

	strncpy(prompt, "justify Region, Paragraph; or fix Quotelevel ? ", sizeof(prompt));
	prompt[sizeof(prompt)-1] = '\0';
	mlwrite_utf8(prompt, NULL);
	(*term.t_rev)(1);
	rv = -1;
	while(1){
	    switch(c = GetKey()){

	      case (CTRL|'C') :		/* Bail out! */
	      case F2         :
		pputs_utf8(_("ABORT"), 1);
		rv = ABORT;
		emlwrite("", NULL);
		break;

	      case (CTRL|'M') :		/* default */
	      case 'r' :
	      case 'R' :
	      case F3  :
		pputs_utf8(_("Region"), 1);
		rv = 'R';
		break;

	      case 'p' :
	      case 'P' :
	      case F7  :
		pputs_utf8(_("Paragraph"), 1);
		rv = 'P';
		break;

	      case 'q' :
	      case 'Q' :
	      case F8  :
	      case '0' : case '1' : case '2' : case '3' : case '4' :
	      case '5' : case '6' : case '7' : case '8' : case '9' :
		pputs_utf8(_("Quotelevel"), 1);
		while(rv == -1){
		  switch(c){
		    case 'q' :
		    case 'Q' :
		    case F8  :
		     {char num[20];

		      num[0] = '\0';
		      switch(mlreplyd_utf8("Quote Level ? ", num, sizeof(num), QNORML, NULL)){
		        case TRUE:
			  if(isdigit(num[0])){
			      quotelevel = atoi(num);
			      if(quotelevel < 0){
				  emlwrite("Quote Level cannot be negative", NULL);
				  sleep(3);
			      }
			      else if(quotelevel > 20){
				  emlwrite("Quote Level should be less than 20", NULL);
				  rv = ABORT;
			      }
			      else{
				  rv = 'Q';
			      }
			  }
			  else if(num[0]){
			      emlwrite("Quote Level should be a number", NULL);
			      sleep(3);
			  }

			  break;

		        case HELPCH:
			  emlwrite("Enter the number of quotes you want before the text", NULL);
			  sleep(3);
			  break;

		        default:
			  emlwrite("Quote Level is a number", NULL);
			  rv = ABORT;
			  break;
		      }
		     }

		      break;

		    case '0' : case '1' : case '2' : case '3' : case '4' :
		    case '5' : case '6' : case '7' : case '8' : case '9' :
		      rv = 'Q';
		      quotelevel = (int) (c - '0');
		      break;
		  }
		}

		break;

	      case (CTRL|'G') :
		if(term.t_mrow == 0 && km_popped == 0){
		    movecursor(term.t_nrow-2, 0);
		    peeol();
		    term.t_mrow = 2;
		    (*term.t_rev)(0);
		    wkeyhelp(menu_justify);
		    mlwrite_utf8(prompt, NULL);
		    (*term.t_rev)(1);
		    sgarbk = TRUE;			/* mark menu dirty */
		    km_popped++;
		    break;
		}
		/* else fall through */

	      default:
		(*term.t_beep)();

	      case NODATA :
		break;
	    }

	    (*term.t_flush)();
	    if(rv != -1){
		(*term.t_rev)(0);
		if(km_popped){
		    term.t_mrow = 0;
		    movecursor(term.t_nrow, 0);
		    peeol();
		    sgarbf = 1;
		    km_popped = 0;
		}

		action = rv;
		break;
	    }
	}

	if(action != ABORT)
	  emlwrite("", NULL);
    }

    if(action == 'R' && curwp->w_markp){
	/* let yank() know that it may be restoring a paragraph */
	thisflag |= CFFILL;

	if(!Pmaster)
	  sgarbk = TRUE;
	
	curwp->w_flag |= WFMODE;

	swap_mark_and_dot_if_mark_comes_first();

	/* determine if we're justifying quoted text or not */
	qstr = (glo_quote_str
		&& quote_match(glo_quote_str, 
			       curwp->w_doto > 0 ? curwp->w_dotp->l_fp : curwp->w_dotp,
			       qstr2, NSTRING)
		&& *qstr2) ? qstr2 : NULL;


	/*
	 * Fillregion moves dot to the end of the filled region.
	 */
	if(!fillregion(qstr, &addedregion))
	  return(FALSE);

	set_last_region_added(&addedregion);
    }
    else if(action == 'P'){

	/*
	 * Justfiy the current paragraph.
	 */

	if(curwp->w_markp)		/* clear mark if already set */
	  setmark(0,0);

	if(gotoeop(FALSE, 1) == FALSE)
	  return(FALSE);

	/* determine if we're justifying quoted text or not */
	qstr = (glo_quote_str
		&& quote_match(glo_quote_str, 
			       curwp->w_dotp, qstr2, NSTRING)
		&& *qstr2) ? qstr2 : NULL;

	setmark(0,0);			/* mark last line of para */

	/* jump back to the beginning of the paragraph */
	gotobop(FALSE, 1);

	/* let yank() know that it may be restoring a paragraph */
	thisflag |= (CFFILL | CFFLPA);

	if(!Pmaster)
	  sgarbk = TRUE;
	
	curwp->w_flag |= WFMODE;

	curwp->w_doto = 0;		/* start region at beginning of line */

	/*
	 * Fillregion moves dot to the end of the filled region.
	 */
	if(!fillregion(qstr, &addedregion))
	  return(FALSE);

	set_last_region_added(&addedregion);

	/* Leave cursor on first char of first line after justified region */
	curwp->w_dotp = lforw(curwp->w_dotp);
	curwp->w_doto = 0;

	if(curwp->w_markp)
	  setmark(0,0);			/* clear mark */
    }
    else if(action == 'Q'){
	/* let yank() know that it may be restoring a paragraph */
	thisflag |= CFFILL;

	if(!Pmaster)
	  sgarbk = TRUE;
	
	curwp->w_flag |= WFHARD;

	swap_mark_and_dot_if_mark_comes_first();

	if(!setquotelevelinregion(quotelevel, &addedregion))
	  return(FALSE);

	set_last_region_added(&addedregion);
    }
    else{
	/* abort */
    }

    return(TRUE);
}
Esempio n. 11
0
/* ARGSUSED */
int
fillpara(int f, int n)
{
    int	 c;		/* current char during scan		*/
    int	 wordlen;	/* length of current word		*/
    int	 clength;	/* position on line during fill		*/
    int	 i;		/* index during word copy		*/
    int	 eopflag;	/* Are we at the End-Of-Paragraph?	*/
    int	 firstflag;	/* first word? (needs no space)		*/
    int	 newlength;	/* tentative new line length		*/
    int	 eolflag;	/* was at end of line			*/
    int	 retval;	/* return value				*/
    struct line	*eopline;	/* pointer to line just past EOP	*/
    char	 wbuf[MAXWORD];	/* buffer for current word		*/

    if (n == 0)
        return (TRUE);

    undo_boundary_enable(FFRAND, 0);

    /* record the pointer to the line just past the EOP */
    (void)gotoeop(FFRAND, 1);
    if (curwp->w_doto != 0) {
        /* paragraph ends at end of buffer */
        (void)lnewline();
        eopline = lforw(curwp->w_dotp);
    } else
        eopline = curwp->w_dotp;

    /* and back top the beginning of the paragraph */
    (void)gotobop(FFRAND, 1);

    /* initialize various info */
    while (inword() == 0 && forwchar(FFRAND, 1));

    clength = curwp->w_doto;
    wordlen = 0;

    /* scan through lines, filling words */
    firstflag = TRUE;
    eopflag = FALSE;
    while (!eopflag) {

        /* get the next character in the paragraph */
        if ((eolflag = (curwp->w_doto == llength(curwp->w_dotp)))) {
            c = ' ';
            if (lforw(curwp->w_dotp) == eopline)
                eopflag = TRUE;
        } else
            c = lgetc(curwp->w_dotp, curwp->w_doto);

        /* and then delete it */
        if (ldelete((RSIZE) 1, KNONE) == FALSE && !eopflag) {
            retval = FALSE;
            goto cleanup;
        }

        /* if not a separator, just add it in */
        if (c != ' ' && c != '\t') {
            if (wordlen < MAXWORD - 1)
                wbuf[wordlen++] = c;
            else {
                /*
                 * You lose chars beyond MAXWORD if the word
                 * is too long. I'm too lazy to fix it now; it
                 * just silently truncated the word before,
                 * so I get to feel smug.
                 */
                ewprintf("Word too long!");
            }
        } else if (wordlen) {

            /* calculate tentative new length with word added */
            newlength = clength + 1 + wordlen;

            /*
             * if at end of line or at doublespace and previous
             * character was one of '.','?','!' doublespace here.
             * behave the same way if a ')' is preceded by a
             * [.?!] and followed by a doublespace.
             */
            if (dblspace && (!eopflag && ((eolflag ||
                                           curwp->w_doto == llength(curwp->w_dotp) ||
                                           (c = lgetc(curwp->w_dotp, curwp->w_doto)) == ' '
                                           || c == '\t') && (ISEOSP(wbuf[wordlen - 1]) ||
                                                   (wbuf[wordlen - 1] == ')' && wordlen >= 2 &&
                                                    ISEOSP(wbuf[wordlen - 2])))) &&
                             wordlen < MAXWORD - 1))
                wbuf[wordlen++] = ' ';

            /* at a word break with a word waiting */
            if (newlength <= fillcol) {
                /* add word to current line */
                if (!firstflag) {
                    (void)linsert(1, ' ');
                    ++clength;
                }
                firstflag = FALSE;
            } else {
                if (curwp->w_doto > 0 &&
                        lgetc(curwp->w_dotp, curwp->w_doto - 1) == ' ') {
                    curwp->w_doto -= 1;
                    (void)ldelete((RSIZE) 1, KNONE);
                }
                /* start a new line */
                (void)lnewline();
                clength = 0;
            }

            /* and add the word in in either case */
            for (i = 0; i < wordlen; i++) {
                (void)linsert(1, wbuf[i]);
                ++clength;
            }
            wordlen = 0;
        }
    }
    /* and add a last newline for the end of our new paragraph */
    (void)lnewline();

    /*
     * We really should wind up where we started, (which is hard to keep
     * track of) but I think the end of the last line is better than the
     * beginning of the blank line.
     */
    (void)backchar(FFRAND, 1);
    retval = TRUE;
cleanup:
    undo_boundary_enable(FFRAND, 1);
    return (retval);
}
Esempio n. 12
0
/*
 * Fill the current paragraph according to the current fill column.
 */
int
fillpara (int f, int n, int k)
{
  register int c;		/* current char durring scan    */
  register int wordlen;		/* length of current word       */
  register int clength;		/* position on line during fill */
  register int eopflag;		/* Are we at the End-Of-Paragraph? */
  int firstflag;		/* first word? (needs no space) */
  int newlength;		/* tentative new line length    */
  int eolflag;			/* was at end of line           */
  LINE *eopline;		/* pointer to line just past EOP */
  char wbuf[MAXWORD];		/* buffer for current word      */

  /* Record the pointer to the line just past the
   * end of the paragraph.
   */
  gotoeop (FALSE, 1, KRANDOM);
  eopline = curwp->w_dot.p;
  if (lforw (eopline) == curbp->b_linep)
    eopline = curbp->b_linep;

  /* Move to the begining of the paragraph.
   */
  gotobop (FALSE, 1, KRANDOM);

  /* Skip to the start of the first word in the paragraph,
   * and set our current column position.
   */
  while (!inword ())
    if (forwchar (FALSE, 1, KRANDOM) == FALSE)
      break;
  clength = getcolpos () - 1;
  wordlen = 0;

  /* scan through lines, filling words
   */
  firstflag = TRUE;
  eopflag = FALSE;
  while (!eopflag)
    {
      /* get the next character in the paragraph
       */
      if ((eolflag = (curwp->w_dot.o == llength (curwp->w_dot.p))) == TRUE)
	{
	  c = ' ';
	  if (lforw (curwp->w_dot.p) == eopline)
	    eopflag = TRUE;
	}
      else
	c = lgetc (curwp->w_dot.p, curwp->w_dot.o);

      /* and then delete it
       */
      if (ldelete (1, FALSE) == FALSE)
	return (FALSE);

      /* if not a separator, just add it in
       */
      if (c != ' ' && c != '\t')
	{
	  if (wordlen < MAXWORD - 1)
	    wbuf[wordlen++] = c;
	  else
	    {
	      /* You lose chars beyond MAXWORD if the word
	       * is to long. I'm to lazy to fix it now; it
	       * just silently truncated the word before, so
	       * I get to feel smug.
	       */
	      eprintf ("Word too long!");
	    }
	}
      else if (wordlen)
	{
	  /* calculate tenatitive new length with word added
	   */
	  newlength = clength + 1 + wordlen;

	  /* if at end of line or at doublespace and previous
	   * character was one of '.','?','!' doublespace here.
	   */
	  if ((eolflag || curwp->w_dot.o == llength (curwp->w_dot.p)
	       || (c = lgetc (curwp->w_dot.p, curwp->w_dot.o)) == ' '
	       || c == '\t')
	      && ISEOSP (wbuf[wordlen - 1]) && wordlen < MAXWORD - 1)
	    wbuf[wordlen++] = ' ';

	  /* at a word break with a word waiting
	   */
	  if (newlength <= fillcol)
	    {
	      /* add word to current line */
	      if (!firstflag)
		{
		  linsert (1, ' ', NULLPTR);
		  ++clength;
		}
	      firstflag = FALSE;
	    }
	  else
	    {
	      if (curwp->w_dot.o > 0 &&
		  lgetc (curwp->w_dot.p, curwp->w_dot.o - 1) == ' ')
		{
		  curwp->w_dot.o -= 1;
		  ldelete (1, FALSE);
		}
	      /* start a new line */
	      lnewline ();
	      clength = 0;
	    }

	  /* and add the word in in either case */
	  linsert (wordlen, 0, wbuf);
	  clength += wordlen;
	  wordlen = 0;
	}
    }
  /* and add a last newline for the end of our new paragraph */
  lnewline ();

  /* we realy should wind up where we started, (which is hard to keep
   * track of) but I think the end of the last line is better than the
   * begining of the blank line.
   */
  backchar (FALSE, 1, KRANDOM);
  return (TRUE);
}
Esempio n. 13
0
PASCAL NEAR gotobop( /* go back to the beginning of the current paragraph
		   here we look for a blank line or a character from
		   $paralead to delimit the beginning of a paragraph or
		   $fmtlead to delimit a line before the paragraph
		   OR A START OF FOLD (MJB: 03-Oct-89) */

  int f,
  int n )	/* default Flag & Numeric argument */

{
	register int suc;	/* success of last backchar */
	register int c;		/* current character in scan */
	register char *sp;	/* ptr into character leadin lists */

	if (n < 0)	/* the other way...*/
		return(gotoeop(f, -n));

	while (n-- > 0) {	/* for each one asked for */

		/* first scan back until we are in a word or foldline */
		suc = backchar(FALSE, 1);
		while (!inword() && suc && 
                       ((curwp->w_dotp->l_type == LNORMAL) ||
			(curwp->w_dotp->l_type == LEOEFOLD)))
			suc = backchar(FALSE, 1);
		curwp->w_doto = 0;	/* and go to the B-O-Line */

		/* scan back through the text */
		if (curwp->w_dotp->l_type == LNORMAL)
			while (lback(curwp->w_dotp) != curbp->b_linep) {

			/* at blank line */
				if (llength(curwp->w_dotp) == 0 ||
				    curwp->w_dotp->l_type != LNORMAL ||
				    lgetc(curwp->w_dotp, curwp->w_doto) == TAB ||
				    lgetc(curwp->w_dotp, curwp->w_doto) == ' ')
					break;

			/* current line start with member of $paralead? */
			c = lgetc(curwp->w_dotp, 0);
			sp = paralead;
			while (*sp) {
				if (c == *sp)
					break;
				++sp;
			}
			if (c == *sp)
				break;			

			/* last line start with member of $fmtlead? */
			c = lgetc(lback(curwp->w_dotp), 0);
			sp = fmtlead;
			while (*sp) {
				if (c == *sp)
					break;
				++sp;
			}
			if (c == *sp)
				break;			

			/* back one line... */
			curwp->w_dotp = lback(curwp->w_dotp);
		}

		/* and then forward until we are in a word */
		if (curwp->w_dotp->l_type == LNORMAL) {
			suc = TRUE;
			while (suc && !inword())
				suc = forwchar(FALSE, 1);
		}
		else { /* find the fold symbol */
			suc = lgetc(curwp->w_dotp, curwp->w_doto);
			while (suc && ((suc == ' ') || (suc == TAB)))
				suc = forwchar(FALSE, 1);
		}
	}

	curwp->w_flag |= WFMOVE;	/* force screen update */
	return(TRUE);
}
Esempio n. 14
0
int
forwsearch(int f, int n)
{
  int              status;
  int              wrapt = FALSE, wrapt2 = FALSE;
  int              repl_mode = FALSE;
  UCS              defpat[NPAT];
  int              search = FALSE;
  EML              eml;

    /* resolve the repeat count */
    if (n == 0)
      n = 1;

    if (n < 1)			/* search backwards */
      FWS_RETURN(0);

    defpat[0] = '\0';

    /* ask the user for the text of a pattern */
    while(1){

	if (gmode & MDREPLACE)
	  status = srpat("Search", defpat, NPAT, repl_mode);
	else
	  status = readpattern("Search", TRUE);

	switch(status){
	  case TRUE:                         /* user typed something */
	    search = TRUE;
	    break;

	  case HELPCH:			/* help requested */
	    if(Pmaster){
		VARS_TO_SAVE *saved_state;

		saved_state = save_pico_state();
		(*Pmaster->helper)(Pmaster->search_help,
				   _("Help for Searching"), 1);
		if(saved_state){
		    restore_pico_state(saved_state);
		    free_pico_state(saved_state);
		}
	    }
	    else
	      pico_help(SearchHelpText, _("Help for Searching"), 1);

	  case (CTRL|'L'):			/* redraw requested */
	    pico_refresh(FALSE, 1);
	    update();
	    break;

	  case  (CTRL|'V'):
	    gotoeob(0, 1);
	    mlerase();
	    FWS_RETURN(TRUE);

	  case (CTRL|'Y'):
	    gotobob(0, 1);
	    mlerase();
	    FWS_RETURN(TRUE); 

	  case (CTRL|'T') :
	    switch(status = readnumpat(_("Search to Line Number : "))){
	      case -1 :
		emlwrite(_("Search to Line Number Cancelled"), NULL);
		FWS_RETURN(FALSE);

	      case  0 :
		emlwrite(_("Line number must be greater than zero"), NULL);
		FWS_RETURN(FALSE);

	      case -2 :
		emlwrite(_("Line number must contain only digits"), NULL);
		FWS_RETURN(FALSE);
		
	      case -3 :
		continue;

	      default :
		gotoline(0, status);
		mlerase();
		FWS_RETURN(TRUE);
	    }

	    break;

	  case  (CTRL|'W'):
	    {
		LINE *linep = curwp->w_dotp;
		int   offset = curwp->w_doto;

		gotobop(0, 1);
		gotobol(0, 1);

		/*
		 * if we're asked to backup and we're already
		 *
		 */
		if((lastflag & CFSRCH)
		   && linep == curwp->w_dotp
		   && offset == curwp->w_doto
		   && !(offset == 0 && lback(linep) == curbp->b_linep)){
		    backchar(0, 1);
		    gotobop(0, 1);
		    gotobol(0, 1);
		}
	    }

	    mlerase();
	    FWS_RETURN(TRUE);

	  case  (CTRL|'O'):
	    if(curwp->w_dotp != curbp->b_linep){
		gotoeop(0, 1);
		forwchar(0, 1);
	    }

	    mlerase();
	    FWS_RETURN(TRUE);

	  case (CTRL|'U'):
	    fillbuf(0, 1);
	    mlerase();
	    FWS_RETURN(TRUE);

	  case  (CTRL|'R'):        /* toggle replacement option */
	    repl_mode = !repl_mode;
	    break;

	  default:
	    if(status == ABORT)
	      emlwrite(_("Search Cancelled"), NULL);
	    else
	      mlerase();

	    FWS_RETURN(FALSE);
	}

	/* replace option is disabled */
	if (!(gmode & MDREPLACE)){
	    ucs4_strncpy(defpat, pat, NPAT);
	    defpat[NPAT-1] = '\0';
	    break;
	}
	else if (search){  /* search now */
	    ucs4_strncpy(pat, defpat, NPAT);	/* remember this search for the future */
	    pat[NPAT-1] = '\0';
	    break;
	}
    }

    /*
     * This code is kind of dumb.  What I want is successive C-W 's to 
     * move dot to successive occurences of the pattern.  So, if dot is
     * already sitting at the beginning of the pattern, then we'll move
     * forward a char before beginning the search.  We'll let the
     * automatic wrapping handle putting the dot back in the right 
     * place...
     */
    status = 0;		/* using "status" as int temporarily! */
    while(1){
	if(defpat[status] == '\0'){
	    forwchar(0, 1);
	    break;		/* find next occurence! */
	}

	if(status + curwp->w_doto >= llength(curwp->w_dotp) ||
	   !eq(defpat[status],lgetc(curwp->w_dotp, curwp->w_doto + status).c))
	  break;		/* do nothing! */
	status++;
    }

    /* search for the pattern */
    
    while (n-- > 0) {
	if((status = forscan(&wrapt,defpat,NULL,0,PTBEG)) == FALSE)
	  break;
    }

    /* and complain if not there */
    if (status == FALSE){
      char *utf8;
      UCS x[1];

      x[0] = '\0';

      utf8 = ucs4_to_utf8_cpystr(defpat ? defpat : x); 
      /* TRANSLATORS: reporting the result of a failed search */
      eml.s = utf8;
      emlwrite(_("\"%s\" not found"), &eml);
      if(utf8)
	fs_give((void **) &utf8);
    }
    else if((gmode & MDREPLACE) && repl_mode == TRUE){
        status = replace_pat(defpat, &wrapt2);    /* replace pattern */
	if (wrapt == TRUE || wrapt2 == TRUE){
	    eml.s = (status == ABORT) ? "cancelled but wrapped" : "Wrapped";
	    emlwrite("Replacement %s", &eml);
	}
    }
    else if(wrapt == TRUE){
	emlwrite("Search Wrapped", NULL);
    }
    else if(status == TRUE){
	emlwrite("", NULL);
    }

    FWS_RETURN(status);
}