Ejemplo n.º 1
0
Archivo: error.c Proyecto: 4ad/sam
void
termwrite(char *s)
{
	String *p;

	if(downloaded){
		p = tmpcstr(s);
		if(cmd)
			Finsert(cmd, p, cmdpt);
		else
			Strinsert(&cmdstr, p, cmdstr.n);
		cmdptadv += p->n;
	}else
		Write(2, s, strlen(s));
}
Ejemplo n.º 2
0
void
fixname(String *name)
{
	String *t;
	char *s;

	fullname(name);
	s = Strtoc(name);
	if(strlen(s) > 0)
		s = cleanname(s);
	t = tmpcstr(s);
	Strduplstr(name, t);
	free(s);
	freetmpstr(t);

	if(Strispre(&curwd, name))
		Strdelete(name, 0, curwd.n);
}
Ejemplo n.º 3
0
int
filematch(File *f, String *r)
{
	char *c, buf[STRSIZE+100];
	String *t;

	c = Strtoc(&f->name);
	sprint(buf, "%c%c%c %s\n", " '"[f->mod],
		"-+"[f->rasp!=0], " ."[f==curfile], c);
	free(c);
	t = tmpcstr(buf);
	Strduplstr(&genstr, t);
	freetmpstr(t);
	/* A little dirty... */
	if(menu == 0)
		menu = fileopen();
	bufreset(&menu->Buffer);
	bufinsert(&menu->Buffer, 0, genstr.s, genstr.n);
	compile(r);
	return execute(menu, 0, menu->Buffer.nc);
}
Ejemplo n.º 4
0
Archivo: address.c Proyecto: 8l/sam
int
filematch(File *f, String *r)
{
	char *c, buf[STRSIZE+100];
	String *t;

	c = Strtoc(&f->name);
	sprint(buf, "%c%c%c %s\n", " '"[f->state==Dirty],
		"-+"[f->rasp!=0], " ."[f==curfile], c);
	free(c);
	t = tmpcstr(buf);
	Strduplstr(&genstr, t);
	freetmpstr(t);
	/* A little dirty... */
	if(menu == 0)
		(menu=Fopen())->state=Clean;
	Bdelete(menu->buf, 0, menu->buf->nrunes);
	Binsert(menu->buf, &genstr, 0);
	menu->nrunes = menu->buf->nrunes;
	compile(r);
	return execute(menu, 0, menu->nrunes);
}
Ejemplo n.º 5
0
Archivo: mesg.c Proyecto: rennis250/sam
int
inmesg(Tmesg type)
{
	Rune buf[1025];
	char cbuf[64];
	int i, m;
	short s;
	long l, l1;
	vlong v;
	File *f;
	Posn p0, p1, p;
	Range r;
	String *str;
	char *c, *wdir;
	Rune *rp;
	Plumbmsg *pm;

	if(type > TMAX)
		panic("inmesg");

	journal(0, tname[type]);

	inp = indata;
	switch(type){
	case -1:
		panic("rcv error");

	default:
		fprint(2, "unknown type %d\n", type);
		panic("rcv unknown");

	case Tversion:
		tversion = inshort();
		journaln(0, tversion);
		break;

	case Tstartcmdfile:
		v = invlong();		/* for 64-bit pointers */
		journaln(0, v);
		Strdupl(&genstr, samname);
		cmd = newfile();
		cmd->unread = 0;
		outTsv(Hbindname, cmd->tag, v);
		outTs(Hcurrent, cmd->tag);
		logsetname(cmd, &genstr);
		cmd->rasp = listalloc('P');
		cmd->mod = 0;
		if(cmdstr.n){
			loginsert(cmd, 0L, cmdstr.s, cmdstr.n);
			Strdelete(&cmdstr, 0L, (Posn)cmdstr.n);
		}
		fileupdate(cmd, FALSE, TRUE);
		outT0(Hunlock);
		break;

	case Tcheck:
		/* go through whichfile to check the tag */
		outTs(Hcheck, whichfile(inshort())->tag);
		break;

	case Trequest:
		f = whichfile(inshort());
		p0 = inlong();
		p1 = p0+inshort();
		journaln(0, p0);
		journaln(0, p1-p0);
		if(f->unread)
			panic("Trequest: unread");
		if(p1>f->b.nc)
			p1 = f->b.nc;
		if(p0>f->b.nc) /* can happen e.g. scrolling during command */
			p0 = f->b.nc;
		if(p0 == p1){
			i = 0;
			r.p1 = r.p2 = p0;
		}else{
			r = rdata(f->rasp, p0, p1-p0);
			i = r.p2-r.p1;
			bufread(&f->b, r.p1, buf, i);
		}
		buf[i]=0;
		outTslS(Hdata, f->tag, r.p1, tmprstr(buf, i+1));
		break;

	case Torigin:
		s = inshort();
		l = inlong();
		l1 = inlong();
		journaln(0, l1);
		lookorigin(whichfile(s), l, l1);
		break;

	case Tstartfile:
		termlocked++;
		f = whichfile(inshort());
		if(!f->rasp)	/* this might be a duplicate message */
			f->rasp = listalloc('P');
		current(f);
		outTsv(Hbindname, f->tag, invlong());	/* for 64-bit pointers */
		outTs(Hcurrent, f->tag);
		journaln(0, f->tag);
		if(f->unread)
			load(f);
		else{
			if(f->b.nc>0){
				rgrow(f->rasp, 0L, f->b.nc);
				outTsll(Hgrow, f->tag, 0L, f->b.nc);
			}
			outTs(Hcheck0, f->tag);
			moveto(f, f->dot.r);
		}
		break;

	case Tworkfile:
		i = inshort();
		f = whichfile(i);
		current(f);
		f->dot.r.p1 = inlong();
		f->dot.r.p2 = inlong();
		f->tdot = f->dot.r;
		journaln(0, i);
		journaln(0, f->dot.r.p1);
		journaln(0, f->dot.r.p2);
		break;

	case Ttype:
		f = whichfile(inshort());
		p0 = inlong();
		journaln(0, p0);
		journal(0, (char*)inp);
		str = tmpcstr((char*)inp);
		i = str->n;
		loginsert(f, p0, str->s, str->n);
		if(fileupdate(f, FALSE, FALSE))
			seq++;
		if(f==cmd && p0==f->b.nc-i && i>0 && str->s[i-1]=='\n'){
			freetmpstr(str);
			termlocked++;
			termcommand();
		}else
			freetmpstr(str);
		f->dot.r.p1 = f->dot.r.p2 = p0+i; /* terminal knows this already */
		f->tdot = f->dot.r;
		break;

	case Tcut:
		f = whichfile(inshort());
		p0 = inlong();
		p1 = inlong();
		journaln(0, p0);
		journaln(0, p1);
		logdelete(f, p0, p1);
		if(fileupdate(f, FALSE, FALSE))
			seq++;
		f->dot.r.p1 = f->dot.r.p2 = p0;
		f->tdot = f->dot.r;   /* terminal knows the value of dot already */
		break;

	case Tpaste:
		f = whichfile(inshort());
		p0 = inlong();
		journaln(0, p0);
		for(l=0; l<snarfbuf.nc; l+=m){
			m = snarfbuf.nc-l;
			if(m>BLOCKSIZE)
				m = BLOCKSIZE;
			bufread(&snarfbuf, l, genbuf, m);
			loginsert(f, p0, tmprstr(genbuf, m)->s, m);
		}
		if(fileupdate(f, FALSE, TRUE))
			seq++;
		f->dot.r.p1 = p0;
		f->dot.r.p2 = p0+snarfbuf.nc;
		f->tdot.p1 = -1; /* force telldot to tell (arguably a BUG) */
		telldot(f);
		outTs(Hunlockfile, f->tag);
		break;

	case Tsnarf:
		i = inshort();
		p0 = inlong();
		p1 = inlong();
		snarf(whichfile(i), p0, p1, &snarfbuf, 0);
		break;

	case Tstartnewfile:
		v = invlong();
		Strdupl(&genstr, empty);
		f = newfile();
		f->rasp = listalloc('P');
		outTsv(Hbindname, f->tag, v);
		logsetname(f, &genstr);
		outTs(Hcurrent, f->tag);
		current(f);
		load(f);
		break;

	case Twrite:
		termlocked++;
		i = inshort();
		journaln(0, i);
		f = whichfile(i);
		addr.r.p1 = 0;
		addr.r.p2 = f->b.nc;
		if(f->name.s[0] == 0)
			error(Enoname);
		Strduplstr(&genstr, &f->name);
		writef(f);
		break;

	case Tclose:
		termlocked++;
		i = inshort();
		journaln(0, i);
		f = whichfile(i);
		current(f);
		trytoclose(f);
		/* if trytoclose fails, will error out */
		delete(f);
		break;

	case Tlook:
		f = whichfile(inshort());
		termlocked++;
		p0 = inlong();
		p1 = inlong();
		journaln(0, p0);
		journaln(0, p1);
		setgenstr(f, p0, p1);
		for(l = 0; l<genstr.n; l++){
			i = genstr.s[l];
			if(utfrune(".*+?(|)\\[]^$", i)){
				str = tmpcstr("\\");
				Strinsert(&genstr, str, l++);
				freetmpstr(str);
			}
		}
		Straddc(&genstr, '\0');
		nextmatch(f, &genstr, p1, 1);
		moveto(f, sel.p[0]);
		break;

	case Tsearch:
		termlocked++;
		if(curfile == 0)
			error(Enofile);
		if(lastpat.s[0] == 0)
			panic("Tsearch");
		nextmatch(curfile, &lastpat, curfile->dot.r.p2, 1);
		moveto(curfile, sel.p[0]);
		break;

	case Tsend:
		termlocked++;
		inshort();	/* ignored */
		p0 = inlong();
		p1 = inlong();
		setgenstr(cmd, p0, p1);
		bufreset(&snarfbuf);
		bufinsert(&snarfbuf, (Posn)0, genstr.s, genstr.n);
		outTl(Hsnarflen, genstr.n);
		if(genstr.s[genstr.n-1] != '\n')
			Straddc(&genstr, '\n');
		loginsert(cmd, cmd->b.nc, genstr.s, genstr.n);
		fileupdate(cmd, FALSE, TRUE);
		cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->b.nc;
		telldot(cmd);
		termcommand();
		break;

	case Tdclick:
		f = whichfile(inshort());
		p1 = inlong();
		doubleclick(f, p1);
		f->tdot.p1 = f->tdot.p2 = p1;
		telldot(f);
		outTs(Hunlockfile, f->tag);
		break;

	case Tstartsnarf:
		if (snarfbuf.nc <= 0) {	/* nothing to export */
			outTs(Hsetsnarf, 0);
			break;
		}
		c = 0;
		i = 0;
		m = snarfbuf.nc;
		if(m > SNARFSIZE) {
			m = SNARFSIZE;
			dprint("?warning: snarf buffer truncated\n");
		}
		rp = malloc(m*sizeof(Rune));
		if(rp){
			bufread(&snarfbuf, 0, rp, m);
			c = Strtoc(tmprstr(rp, m));
			free(rp);
			i = strlen(c);
		}
		outTs(Hsetsnarf, i);
		if(c){
			Write(1, c, i);
			free(c);
		} else
			dprint("snarf buffer too long\n");
		break;

	case Tsetsnarf:
		m = inshort();
		if(m > SNARFSIZE)
			error(Etoolong);
		c = malloc(m+1);
		if(c){
			for(i=0; i<m; i++)
				c[i] = rcvchar();
			c[m] = 0;
			str = tmpcstr(c);
			free(c);
			bufreset(&snarfbuf);
			bufinsert(&snarfbuf, (Posn)0, str->s, str->n);
			freetmpstr(str);
			outT0(Hunlock);
		}
		break;

	case Tack:
		waitack = 0;
		break;

	case Tplumb:
		f = whichfile(inshort());
		p0 = inlong();
		p1 = inlong();
		pm = emalloc(sizeof(Plumbmsg));
		pm->src = strdup("sam");
		pm->dst = 0;
		/* construct current directory */
		c = Strtoc(&f->name);
		if(c[0] == '/')
			pm->wdir = c;
		else{
			wdir = emalloc(1024);
			getwd(wdir, 1024);
			pm->wdir = emalloc(1024);
			snprint(pm->wdir, 1024, "%s/%s", wdir, c);
			cleanname(pm->wdir);
			free(wdir);
			free(c);
		}
		c = strrchr(pm->wdir, '/');
		if(c)
			*c = '\0';
		pm->type = strdup("text");
		if(p1 > p0)
			pm->attr = nil;
		else{
			p = p0;
			while(p0>0 && (i=filereadc(f, p0 - 1))!=' ' && i!='\t' && i!='\n')
				p0--;
			while(p1<f->b.nc && (i=filereadc(f, p1))!=' ' && i!='\t' && i!='\n')
				p1++;
			sprint(cbuf, "click=%ld", p-p0);
			pm->attr = plumbunpackattr(cbuf);
		}
		if(p0==p1 || p1-p0>=BLOCKSIZE){
			plumbfree(pm);
			break;
		}
		setgenstr(f, p0, p1);
		pm->data = Strtoc(&genstr);
		pm->ndata = strlen(pm->data);
		c = plumbpack(pm, &i);
		if(c != 0){
			outTs(Hplumb, i);
			Write(1, c, i);
			free(c);
		}
		plumbfree(pm);
		break;

	case Texit:
		exits(0);
	}
	return TRUE;
}
Ejemplo n.º 6
0
Archivo: sam.c Proyecto: deadpixi/sam
int
main(int argc, char *argv[])
{
    int i, o;
    String *t;
    char *arg[argc + 1], **ap;
    int targc = 1;

    ap = &arg[argc];
    arg[0] = "samterm";
    setlocale(LC_ALL, "");

    while ((o = getopt(argc, argv, "efdRr:t:s:")) != -1) {
        switch (o) {
        case 'e':
            arg[targc++] = "-e";
            break;

        case 'f':
            arg[targc++] = "-f";
            break;

        case 'd':
            dflag = true;
            break;

        case 'r':
            machine = optarg;
            rsamname = "rsam";
            arg[targc++] = "-r";
            arg[targc++] = optarg;
            break;

        case 'R':
            Rflag = true;
            break;

        case 't':
            samterm = optarg;
            break;

        case 's':
            rsamname = optarg;
            break;

        default:
            usage();
        }
    }
    argv += optind;
    argc -= optind;
    arg[targc] = NULL;

    Strinit(&cmdstr);
    Strinit0(&lastpat);
    Strinit0(&lastregexp);
    Strinit0(&genstr);
    Strinit0(&rhs);
    Strinit0(&wd);
    Strinit0(&plan9cmd);

    tempfile.listptr = emalloc(0);
    home = getenv("HOME") ? getenv("HOME") : "/";
    shpath = getenv("SHELL") ? getenv("SHELL") : shpath;
    sh = basename(shpath);
    if(!dflag)
        startup(machine, Rflag, arg, ap);
    Fstart();

    signal(SIGINT, SIG_IGN);
    signal(SIGHUP, hup);
    signal(SIGPIPE, SIG_IGN);

    if(argc > 0) {
        for(i=0; i<argc; i++)
            if(!setjmp(mainloop)) {
                t = tmpcstr(argv[i]);
                Straddc(t, '\0');
                Strduplstr(&genstr, t);
                freetmpstr(t);
                Fsetname(newfile(), &genstr);
            }
    } else if(!downloaded)
        newfile()->state = Clean;
    modnum++;
    if(file.nused)
        current(file.filepptr[0]);

    atexit(shutdown);
    setjmp(mainloop);
    cmdloop();

    trytoquit();    /* if we already q'ed, quitok will be true */

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 7
0
void main(int argc, char *argv[])
{
    int i;
    String *t;
    char *termargs[10], **ap;

    ap = termargs;
    *ap++ = "samterm";
    ARGBEGIN{
    case 'd':
        dflag++;
        break;
    case 'r':
        machine = EARGF(usage());
        break;
    case 'R':
        Rflag++;
        break;
    case 't':
        samterm = EARGF(usage());
        break;
    case 's':
        rsamname = EARGF(usage());
        break;
    default:
        dprint("sam: unknown flag %c\n", ARGC());
        usage();
        /* options for samterm */
    case 'a':
        *ap++ = "-a";
        break;
    } ARGEND
    *ap = nil;

    Strinit(&cmdstr);
    Strinit0(&lastpat);
    Strinit0(&lastregexp);
    Strinit0(&genstr);
    Strinit0(&rhs);
    Strinit0(&curwd);
    Strinit0(&plan9cmd);
    home = getenv(HOME);
    disk = diskinit();
    if(home == 0)
        home = "/";
    if(!dflag)
        startup(machine, Rflag, termargs, argv);
    notify(notifyf);
    getcurwd();
    if(argc>0) {
        for(i=0; i<argc; i++) {
            if(!setjmp(mainloop)) {
                t = tmpcstr(argv[i]);
                Straddc(t, '\0');
                Strduplstr(&genstr, t);
                freetmpstr(t);
                fixname(&genstr);
                logsetname(newfile(), &genstr);
            }
        }
    } else if(!downloaded)
        newfile();
    seq++;
    if(file.nused)
        current(file.filepptr[0]);
    setjmp(mainloop);
    cmdloop();
    trytoquit();	/* if we already q'ed, quitok will be TRUE */
    exits(0);
}
Ejemplo n.º 8
0
Archivo: sam.c Proyecto: pocket7878/sam
int
sammain(int argc, char *argv[])
{
    bool trylock = true;
    int i, o;
    String *t;
    char *arg[argc + 1], **ap;

    ap = &arg[argc];
    arg[0] = "samterm";
    setlocale(LC_ALL, "");

    while ((o = getopt(argc, argv, "SedR:r:t:s:")) != -1){
        switch (o){
            case 'd':
                dflag = true;
                break;

            case 'r':
                machine = optarg;
                break;

            case 'R':
                rmsocketname = optarg;
                atexit(rmsocket);
                break;

            case 't':
                samterm = optarg;
                break;

            case 's':
                rsamname = optarg;
                break;

            case 'S':
                trylock = false;
                break;

            default:
                usage();
        }
    }

    if (trylock && !canlocksocket(machine) && !dflag)
        return bmain(argc, argv);

    argv += optind;
    argc -= optind;

    Strinit(&cmdstr);
    Strinit0(&lastpat);
    Strinit0(&lastregexp);
    Strinit0(&genstr);
    Strinit0(&rhs);
    Strinit0(&wd);
    Strinit0(&plan9cmd);

    tempfile.listptr = emalloc(0);
    home = getenv("HOME") ? getenv("HOME") : "/";
    shpath = getenv("SHELL") ? getenv("SHELL") : shpath;
    sh = basename(shpath);
    if(!dflag)
        startup(machine, rmsocketname != NULL, trylock);
    Fstart();

    signal(SIGINT, SIG_IGN);
    signal(SIGHUP, hup);
    signal(SIGPIPE, SIG_IGN);

    if(argc > 0){
        for(i=0; i<argc; i++)
            if(!setjmp(mainloop)){
                t = tmpcstr(argv[i]);
                Straddc(t, '\0');
                Strduplstr(&genstr, t);
                freetmpstr(t);
                Fsetname(newfile(), &genstr);
            }
    }else if(!downloaded)
        newfile()->state = Clean;
    modnum++;
    if(file.nused)
        current(file.filepptr[0]);

    atexit(scram);
    setjmp(mainloop);
    cmdloop();

    trytoquit();    /* if we already q'ed, quitok will be true */

    exit(EXIT_SUCCESS);
}
Ejemplo n.º 9
0
int
inmesg(Tmesg type)
{
    Rune buf[1025];
    int i, m;
    short s;
    long l, l1;
    File *f;
    Posn p0, p1;
    Range r;
    String *str;
    char *c;
    Rune *rp;

    if(type > TMAX)
        panic("inmesg");

    journal(0, tname[type]);

    inp = indata;
    switch(type) {
    case -1:
        panic("rcv error");

    default:
        fprint(2, "unknown type %d\n", type);
        panic("rcv unknown");

    case Tversion:
        tversion = inshort();
        journaln(0, tversion);
        break;

    case Tstartcmdfile:
        l = invlong();		/* for 64-bit pointers */
        journaln(0, l);
        Strdupl(&genstr, samname);
        cmd = newfile();
        outTsv(Hbindname, cmd->tag, l);
        outTs(Hcurrent, cmd->tag);
        Fsetname(cmd, &genstr);
        cmd->rasp = emalloc(sizeof(List));
        cmd->state = Clean;
        if(cmdstr.n) {
            Finsert(cmd, &cmdstr, 0L);
            Strdelete(&cmdstr, 0L, (Posn)cmdstr.n);
        }
        Fupdate(cmd, FALSE, TRUE);
        outT0(Hunlock);
        break;

    case Tcheck:
        /* go through whichfile to check the tag */
        outTs(Hcheck, whichfile(inshort())->tag);
        break;

    case Trequest:
        f = whichfile(inshort());
        p0 = inlong();
        p1 = p0+inshort();
        journaln(0, p0);
        journaln(0, p1-p0);
        if(f->state == Unread)
            panic("Trequest: unread");
        if(p1>f->nrunes)
            p1 = f->nrunes;
        if(p0>f->nrunes) /* can happen e.g. scrolling during command */
            p0 = f->nrunes;
        if(p0 == p1) {
            i = 0;
            r.p1 = r.p2 = p0;
        } else {
            r = rdata(f->rasp, p0, p1-p0);
            i = r.p2-r.p1;
            if(Fchars(f, buf, r.p1, r.p2)!=i)
                panic("Trequest 2");
        }
        buf[i]=0;
        outTslS(Hdata, f->tag, r.p1, tmprstr(buf, i+1));
        break;

    case Torigin:
        s = inshort();
        l = inlong();
        l1 = inlong();
        journaln(0, l1);
        lookorigin(whichfile(s), l, l1);
        break;

    case Tstartfile:
        termlocked++;
        f = whichfile(inshort());
        if(!f->rasp)	/* this might be a duplicate message */
            f->rasp = emalloc(sizeof(List));
        current(f);
        outTsv(Hbindname, f->tag, invlong());	/* for 64-bit pointers */
        outTs(Hcurrent, f->tag);
        journaln(0, f->tag);
        if(f->state == Unread)
            load(f);
        else {
            if(f->nrunes>0) {
                rgrow(f->rasp, 0L, f->nrunes);
                outTsll(Hgrow, f->tag, 0L, f->nrunes);
            }
            outTs(Hcheck0, f->tag);
            moveto(f, f->dot.r);
        }
        break;

    case Tworkfile:
        i = inshort();
        f = whichfile(i);
        current(f);
        f->dot.r.p1 = inlong();
        f->dot.r.p2 = inlong();
        f->tdot = f->dot.r;
        journaln(0, i);
        journaln(0, f->dot.r.p1);
        journaln(0, f->dot.r.p2);
        break;

    case Ttype:
        f = whichfile(inshort());
        p0 = inlong();
        journaln(0, p0);
        journal(0, (char*)inp);
        str = tmpcstr((char*)inp);
        i = str->n;
        Finsert(f, str, p0);
        if(Fupdate(f, FALSE, FALSE))
            modnum++;
        if(f==cmd && p0==f->nrunes-i && i>0 && str->s[i-1]=='\n') {
            freetmpstr(str);
            termlocked++;
            termcommand();
        } else
            freetmpstr(str);
        f->dot.r.p1 = f->dot.r.p2 = p0+i; /* terminal knows this already */
        f->tdot = f->dot.r;
        break;

    case Tcut:
        f = whichfile(inshort());
        p0 = inlong();
        p1 = inlong();
        journaln(0, p0);
        journaln(0, p1);
        Fdelete(f, p0, p1);
        if(Fupdate(f, FALSE, FALSE))
            modnum++;
        f->dot.r.p1 = f->dot.r.p2 = p0;
        f->tdot = f->dot.r;   /* terminal knows the value of dot already */
        break;

    case Tpaste:
        f = whichfile(inshort());
        p0 = inlong();
        journaln(0, p0);
        for(l=0; l<snarfbuf->nrunes; l+=m) {
            m = snarfbuf->nrunes-l;
            if(m>BLOCKSIZE)
                m = BLOCKSIZE;
            Bread(snarfbuf, genbuf, m, l);
            Finsert(f, tmprstr(genbuf, m), p0);
        }
        if(Fupdate(f, FALSE, TRUE))
            modnum++;
        f->dot.r.p1 = p0;
        f->dot.r.p2 = p0+snarfbuf->nrunes;
        f->tdot.p1 = -1; /* force telldot to tell (arguably a BUG) */
        telldot(f);
        outTs(Hunlockfile, f->tag);
        break;

    case Tsnarf:
        i = inshort();
        p0 = inlong();
        p1 = inlong();
        snarf(whichfile(i), p0, p1, snarfbuf, 0);
        break;

    case Tstartnewfile:
        l = invlong();
        Strdupl(&genstr, empty);
        f = newfile();
        f->rasp = emalloc(sizeof(List));
        outTsv(Hbindname, f->tag, l);
        Fsetname(f, &genstr);
        outTs(Hcurrent, f->tag);
        current(f);
        load(f);
        break;

    case Twrite:
        termlocked++;
        i = inshort();
        journaln(0, i);
        f = whichfile(i);
        addr.r.p1 = 0;
        addr.r.p2 = f->nrunes;
        if(f->name.s[0] == 0)
            error(Enoname);
        Strduplstr(&genstr, &f->name);
        writef(f);
        break;

    case Tclose:
        termlocked++;
        i = inshort();
        journaln(0, i);
        f = whichfile(i);
        current(f);
        trytoclose(f);
        /* if trytoclose fails, will error out */
        delete(f);
        break;

    case Tlook:
        f = whichfile(inshort());
        termlocked++;
        p0 = inlong();
        p1 = inlong();
        journaln(0, p0);
        journaln(0, p1);
        setgenstr(f, p0, p1);
        for(l = 0; l<genstr.n; l++) {
            i = genstr.s[l];
            if(utfrune(".*+?(|)\\[]^$", i))
                Strinsert(&genstr, tmpcstr("\\"), l++);
        }
        Straddc(&genstr, '\0');
        nextmatch(f, &genstr, p1, 1);
        moveto(f, sel.p[0]);
        break;

    case Tsearch:
        termlocked++;
        if(curfile == 0)
            error(Enofile);
        if(lastpat.s[0] == 0)
            panic("Tsearch");
        nextmatch(curfile, &lastpat, curfile->dot.r.p2, 1);
        moveto(curfile, sel.p[0]);
        break;

    case Tsend:
        termlocked++;
        inshort();	/* ignored */
        p0 = inlong();
        p1 = inlong();
        setgenstr(cmd, p0, p1);
        Bdelete(snarfbuf, (Posn)0, snarfbuf->nrunes);
        Binsert(snarfbuf, &genstr, (Posn)0);
        outTl(Hsnarflen, genstr.n);
        if(genstr.s[genstr.n-1] != '\n')
            Straddc(&genstr, '\n');
        Finsert(cmd, &genstr, cmd->nrunes);
        Fupdate(cmd, FALSE, TRUE);
        cmd->dot.r.p1 = cmd->dot.r.p2 = cmd->nrunes;
        telldot(cmd);
        termcommand();
        break;

    case Tdclick:
        f = whichfile(inshort());
        p1 = inlong();
        doubleclick(f, p1);
        f->tdot.p1 = f->tdot.p2 = p1;
        telldot(f);
        outTs(Hunlockfile, f->tag);
        break;

    case Tstartsnarf:
        if (snarfbuf->nrunes <= 0) {	/* nothing to export */
            outTs(Hsetsnarf, 0);
            break;
        }
        c = 0;
        i = 0;
        m = snarfbuf->nrunes;
        if(m > 32000) {		/* tmprstr stores len in a short */
            m = 32000;
            dprint("?warning: snarf buffer truncated\n");
        }
        rp = malloc(m*sizeof(Rune));
        if(rp) {
            Bread(snarfbuf, rp, m, 0);
            c = Strtoc(tmprstr(rp, m));
            free(rp);
            i = strlen(c);
        }
        outTs(Hsetsnarf, i);
        if(c) {
            Write(1, c, i);
            free(c);
        } else
            dprint("snarf buffer too long\n");
        break;

    case Tsetsnarf:
        m = inshort();
        if(m > SNARFSIZE)
            error(Etoolong);
        c = malloc(m+1);
        if(c) {
            for(i=0; i<m; i++)
                c[i] = rcvchar();
            c[m] = 0;
            str = tmpcstr(c);
            free(c);
            Bdelete(snarfbuf, (Posn)0, snarfbuf->nrunes);
            Binsert(snarfbuf, str, (Posn)0);
            freetmpstr(str);
            outT0(Hunlock);
        }
        break;

    case Tack:
        waitack = 0;
        break;

    case Texit:
        exits(0);
    }
    return TRUE;
}