Exemple #1
0
int
operyank(int f, int n)
{
    MARK savedot;
    REGION region;
    int s;

    savedot = DOT;
    opcmd = OPDEL;
    wantregion = &region;
    s = vile_op(f, n, yankregion, "Yank");
    wantregion = 0;
    /*
     * If the associated motion was to the left, or up, we want to set DOT to
     * the beginning of the region, to match vi's behavior.  Otherwise leave
     * DOT where it is.
     */
    if (s == TRUE && b_val(curbp, MDYANKMOTION)) {
	if (line_no(curbp, post_op_dot.l) != 0
	    && line_no(curbp, post_op_dot.l) < line_no(curbp, savedot.l)) {
	    savedot = post_op_dot;
	} else if (!samepoint(region.r_orig, region.r_end)) {
	    if (sameline(region.r_orig, savedot)
		&& sameline(region.r_end, savedot)
		&& region.r_orig.o < savedot.o) {
		savedot = region.r_orig;
	    }
	}
    }
    DOT = savedot;
    return s;
}
Exemple #2
0
/*
 * Go to the end of the current paragraph.
 */
int
gotoeop(int f, int n)
{
    MARK odot;
    int was_at_bol;
    int was_on_empty;
    int fc;

    n = need_a_count(f, n, 1);

    fc = firstchar(DOT.l);
    was_on_empty = is_empty_line(DOT);
    was_at_bol = ((fc >= 0 && DOT.o <= fc) || fc < 0);
    odot = DOT;

    while (n) {
	if (findpat(TRUE, 1, b_val_rexp(curbp, VAL_PARAGRAPHS)->reg,
		    FORWARD) != TRUE) {
	    DOT = curbp->b_line;
	} else if (is_empty_line(DOT)) {
	    /* special case -- if we found an empty line. */
	    /* either as the very next line, or at the end of
	       our search */
	    if ((was_on_empty && lback(DOT.l) == odot.l) ||
		(n > 0 && llength(lback(DOT.l)) == 0)) {
		/* then we haven't really found what we
		   wanted.  keep going */
		skipblanksf();
		continue;
	    }
	}
	n--;
    }
    if (doingopcmd) {
	/* if we're now at the beginning of a line and we can back up,
	   do so to avoid eating the newline and leading whitespace */
	fc = firstchar(DOT.l);
	if (((fc >= 0 && DOT.o <= fc) || fc < 0) &&
	    !is_first_line(DOT, curbp) &&
	    !sameline(DOT, odot)) {
	    backchar(TRUE, DOT.o + 1);
	}
	/* if we started at the start of line, eat the whole line */
	if (!sameline(DOT, odot) && was_at_bol)
	    regionshape = rgn_FULLLINE;
    }
    return TRUE;
}
Exemple #3
0
/*
 * Implements the vi "L" command.
 *
 * Move to the last (or nth last) line in window
 */
int
gotoeos(int f, int n)
{
    LINE *last = DOT.l;
    int nn;

    n = need_at_least(f, n, 1);

    /* first get to the end */
    DOT.l = curwp->w_line.l;
    nn = curwp->w_ntrows;
    while ((nn -= line_height(curwp, DOT.l)) > 0) {
	if (is_last_line(DOT, curbp))
	    break;
	DOT.l = lforw(DOT.l);
    }
#ifdef WMDLINEWRAP
    /* adjust if we pointed to a line-fragment */
    if (w_val(curwp, WMDLINEWRAP)
	&& nn < 0
	&& DOT.l != curwp->w_line.l)
	DOT.l = lback(DOT.l);
#endif
    /* and then go back up */
    /* (we're either at eos or eof) */
    while (--n != 0) {
	if (sameline(DOT, curwp->w_line))
	    break;
	DOT.l = lback(DOT.l);
    }
    if (DOT.l != last)
	curwp->w_flag |= WFMOVE;
    return firstnonwhite(FALSE, 1);
}
Exemple #4
0
main()
{
    short line[2][NPERLINE];
    register int n, i, j;
    register int curline = 0;
    int currently_printing = 1;

    for(i = 0;
       (n = fread(line[curline], sizeof(short), NPERLINE, stdin)) > 0;
       i += n, curline = 1-curline) {
        if(i != 0 && n == NPERLINE && sameline(line[0], line[1])) {
            if(currently_printing) {
                printf("*\n");
                currently_printing = 0;
            }
            continue;
        }
        currently_printing = 1;
        printf("%7d ", i);
        for(j = 0; j < n; j++)
            printf("%6d ", line[curline][j]);
        printf("\n");
    }
    printf("%4d\n", i);
}
Exemple #5
0
/*
 * Setup for iteration over region to attribute, ensure that DOT < MK.
 */
LINE *
setup_region(void)
{
    BUFFER *bp = curbp;
    LINE *pastline;		/* pointer to line just past EOP */

    if (!sameline(MK, DOT)) {
	REGION region;
	if (getregion(bp, &region) != TRUE)
	    return 0;
	if (sameline(region.r_orig, MK))
	    swapmark();
    }
    pastline = MK.l;
    if (pastline != win_head(curwp))
	pastline = lforw(pastline);
    DOT.o = 0;
    regionshape = rgn_EXACT;

    return pastline;
}
int main()
{
    while ( init() )
    {
        if( n == 1 ) printf("0.0000\n");
        else if( n == 2 ) twocase();
        else if( not sameline() )
        {
            sortleft( 1 , n );
            convex();
            trans();
        }
    }
    return 0;
}
Exemple #7
0
/*
 * Go to the beginning of the current paragraph.
 */
int
gotobop(int f, int n)
{
    MARK odot;
    int was_on_empty;
    int fc;

    n = need_a_count(f, n, 1);

    was_on_empty = is_empty_line(DOT);
    odot = DOT;

    fc = firstchar(DOT.l);
    if (doingopcmd &&
	((fc >= 0 && DOT.o <= fc) || fc < 0) &&
	!is_first_line(DOT, curbp)) {
	backchar(TRUE, DOT.o + 1);
	pre_op_dot = DOT;
    }
    while (n) {
	if (findpat(TRUE, 1, b_val_rexp(curbp, VAL_PARAGRAPHS)->reg,
		    REVERSE) != TRUE) {
	    (void) gotobob(f, n);
	} else if (is_empty_line(DOT)) {
	    /* special case -- if we found an empty line,
	       and it's adjacent to where we started,
	       skip all adjacent empty lines, and try again */
	    if ((was_on_empty && lforw(DOT.l) == odot.l) ||
		(n > 0 && llength(lforw(DOT.l)) == 0)) {
		/* then we haven't really found what we
		   wanted.  keep going */
		skipblanksb();
		continue;
	    }
	}
	n--;
    }
    if (doingopcmd) {
	fc = firstchar(DOT.l);
	if (!sameline(DOT, odot) &&
	    (pre_op_dot.o > lastchar(pre_op_dot.l)) &&
	    ((fc >= 0 && DOT.o <= fc) || fc < 0)) {
	    regionshape = rgn_FULLLINE;
	}
    }
    return TRUE;
}
 int maxPoints(vector<Point> &points) {
     if(points.size()<=1 || allsame(points))
         return points.size();
     
     int maxPoints=2;
     for(int i=0;i<points.size();i++){
         for(int j=i+1;j<points.size();j++){
             if(points[i].x==points[j].x && points[i].y==points[j].y)
                 continue;
             int count=2;
             for(int k=0;k<points.size();k++){
                 if(i!=k && j!=k && sameline(points[i],points[j],points[k]))
                     count++;
             }
             maxPoints=max(maxPoints,count);
         }
     }
     return maxPoints;
 }
Exemple #9
0
/*
 * scanner -- Search for a pattern in either direction.  can optionally
 * wrap around end of buffer.
 */
int
scanner(
	   regexp * exp,	/* the compiled expression */
	   int direct,		/* up or down */
	   int wrapok,		/* ok to wrap around end of buffer? */
	   int *wrappedp)
{
    MARK curpos;
    int found;
    int wrapped = FALSE;
    int leftmargin = b_left_margin(curbp);

    TRACE((T_CALLED "scanner %s %s\n",
	   ((direct == FORWARD) ? "forward" : "backward"),
	   (wrapok ? "wrapok" : "nowrapok")));

    if (!exp) {
	mlforce("BUG: null exp");
	returnCode(FALSE);
    }

    /* Set starting search position to current position
     */
    curpos = DOT;
    if (curpos.o < leftmargin)
	curpos.o = leftmargin;

    /* Scan each character until we hit the scan boundary */
    for_ever {
	int startoff, srchlim;

	if (interrupted()) {
	    if (wrappedp)
		*wrappedp = wrapped;
	    returnCode(ABORT);
	}

	if (sameline(curpos, scanboundpos)) {
	    if (scanbound_is_header) {
		/* if we're on the header, nothing can match */
		found = FALSE;
		srchlim = leftmargin;
	    } else {
		if (direct == FORWARD) {
		    if (wrapped) {
			startoff = curpos.o;
			srchlim = scanboundpos.o;
		    } else {
			startoff = curpos.o;
			srchlim = ((scanboundpos.o > startoff)
				   ? scanboundpos.o
				   : llength(curpos.l));
		    }
		} else {
		    if (wrapped) {
			startoff = scanboundpos.o;
			srchlim = llength(curpos.l);
		    } else {
			startoff = leftmargin;
			srchlim = scanboundpos.o + 1;
		    }
		}
		found = lregexec(exp, curpos.l, startoff, srchlim);
	    }
	} else {
	    if (direct == FORWARD) {
		startoff = curpos.o;
		srchlim = llength(curpos.l);
	    } else {
		startoff = leftmargin;
		srchlim = curpos.o + 1;
		if (srchlim > llength(curpos.l))
		    srchlim = llength(curpos.l);
	    }
	    found = lregexec(exp, curpos.l, startoff, srchlim);
	}
	if (found) {
	    char *txt = lvalue(curpos.l);
	    char *got = exp->startp[0];
	    C_NUM next;
	    C_NUM last = curpos.o;

	    if (direct == REVERSE) {	/* find the last one */
		int end = FALSE;
		char *tst = 0;

		last++;
		while (testit(curpos.l, exp, &end, srchlim)) {
		    got = exp->startp[0];
		    /* guard against infinite loop:  "?$"
		     * or "?.*"
		     */
		    if (tst == got)
			break;
		    tst = got;
		}
		if (end)
		    last++;
		if (!lregexec(exp, curpos.l, (int) (got - txt), srchlim)) {
		    mlforce("BUG: prev. match no good");
		    returnCode(FALSE);
		}
	    } else if (llength(curpos.l) <= leftmargin
		       || last < llength(curpos.l)) {
		last--;
	    }
	    next = (C_NUM) (got - txt);
	    if (next != last) {
		DOT.l = curpos.l;
		DOT.o = next;
		curwp->w_flag |= WFMOVE;	/* flag that we have moved */
		if (wrappedp)
		    *wrappedp = wrapped;
#if OPT_TRACE
		trace_mark("...scanner", &DOT, curbp);
#endif
		returnCode(TRUE);
	    }
	} else {
	    if (sameline(curpos, scanboundpos) &&
		(!wrapok || wrapped))
		break;
	}
	if (direct == FORWARD) {
	    curpos.l = lforw(curpos.l);
	} else {
	    curpos.l = lback(curpos.l);
	}
	if (is_header_line(curpos, curbp)) {
	    wrapped = TRUE;
	    if (sameline(curpos, scanboundpos) &&
		(!wrapok || wrapped))
		break;
	    if (direct == FORWARD)
		curpos.l = lforw(curpos.l);
	    else
		curpos.l = lback(curpos.l);
	}
	if (direct == FORWARD) {
	    curpos.o = leftmargin;
	} else {
	    if ((curpos.o = llength(curpos.l) - 1) < leftmargin)
		curpos.o = leftmargin;
	}

    }

    if (wrappedp)
	*wrappedp = wrapped;
    returnCode(FALSE);		/* We could not find a match. */
}