Ejemplo n.º 1
0
Archivo: xec.c Proyecto: deadpixi/sam
void
linelooper(File *f, Cmd *cp)
{
    Posn p;
    Range r, linesel;
    Address a3;

    nest++;
    r = addr.r;
    a3.f = f;
    a3.r.p1 = a3.r.p2 = r.p1;
    for(p = r.p1; p<r.p2; p = a3.r.p2){
        a3.r.p1 = a3.r.p2;
/*pjw       if(p!=r.p1 || (linesel = lineaddr((Posn)0, a3, 1)).r.p2==p)*/
        if(p!=r.p1 || ((linesel = lineaddr((Posn)0, a3, 1).r), linesel.p2==p))
            linesel = lineaddr((Posn)1, a3, 1).r;
        if(linesel.p1 >= r.p2)
            break;
        if(linesel.p2 >= r.p2)
            linesel.p2 = r.p2;
        if(linesel.p2 > linesel.p1)
            if(linesel.p1>=a3.r.p2 && linesel.p2>a3.r.p2){
                f->dot.r = linesel;
                cmdexec(f, cp->ccmd);
                a3.r = linesel;
                continue;
            }
        break;
    }
    --nest;
}
Ejemplo n.º 2
0
Archivo: xec.c Proyecto: deadpixi/sam
bool
nl_cmd(File *f, Cmd *cp)
{
    if(cp->addr == 0){
        /* First put it on newline boundaries */
        addr = lineaddr((Posn)0, f->dot, -1);
        addr.r.p2 = lineaddr((Posn)0, f->dot, 1).r.p2;
        if(addr.r.p1==f->dot.r.p1 && addr.r.p2==f->dot.r.p2)
            addr = lineaddr((Posn)1, f->dot, 1);
        display(f);
    }else if(downloaded)
        moveto(f, addr.r);
    else
        display(f);
    return true;
}
Ejemplo n.º 3
0
Address
address(Addr *ap, Address a, int sign)
{
	File *f = a.f;
	Address a1, a2;

	do{
		switch(ap->type){
		case 'l':
		case '#':
			a = (*(ap->type=='#'?charaddr:lineaddr))(ap->num, a, sign);
			break;

		case '.':
			a = f->dot;
			break;

		case '$':
			a.r.p1 = a.r.p2 = f->Buffer.nc;
			break;

		case '\'':
			a.r = f->mark;
			break;

		case '?':
			sign = -sign;
			if(sign == 0)
				sign = -1;
			/* fall through */
		case '/':
			nextmatch(f, ap->are, sign>=0? a.r.p2 : a.r.p1, sign);
			a.r = sel.p[0];
			break;

		case '"':
			a = matchfile(ap->are)->dot;
			f = a.f;
			if(f->unread)
				load(f);
			break;

		case '*':
			a.r.p1 = 0, a.r.p2 = f->Buffer.nc;
			return a;

		case ',':
		case ';':
			if(ap->left)
				a1 = address(ap->left, a, 0);
			else
				a1.f = a.f, a1.r.p1 = a1.r.p2 = 0;
			if(ap->type == ';'){
				f = a1.f;
				a = a1;
				f->dot = a1;
			}
			if(ap->next)
				a2 = address(ap->next, a, 0);
			else
				a2.f = a.f, a2.r.p1 = a2.r.p2 = f->Buffer.nc;
			if(a1.f != a2.f)
				error(Eorder);
			a.f = a1.f, a.r.p1 = a1.r.p1, a.r.p2 = a2.r.p2;
			if(a.r.p2 < a.r.p1)
				error(Eorder);
			return a;

		case '+':
		case '-':
			sign = 1;
			if(ap->type == '-')
				sign = -1;
			if(ap->next==0 || ap->next->type=='+' || ap->next->type=='-')
				a = lineaddr(1L, a, sign);
			break;
		default:
			panic("address");
			return a;
		}
	}while(ap = ap->next);	/* assign = */
	return a;
}