acme/win: implement /dev/wdir file in win to change directory tagline, remove awd

This commit is contained in:
cinap_lenrek 2016-06-30 00:46:52 +02:00
parent 65977417e7
commit 828ec57d65
5 changed files with 52 additions and 56 deletions

View file

@ -66,6 +66,7 @@ extern int winselect(Window*, char*, int);
extern int winsetaddr(Window*, char*, int);
extern void windormant(Window*);
extern void winsetdump(Window*, char*, char*);
extern void winsetdir(Window*, char*, char*);
extern void ctlprint(int, char*, ...);
extern void* emalloc(uint);
@ -90,6 +91,8 @@ extern void pipectl(void*);
#pragma varargck argpos error 1
#pragma varargck argpos ctlprint 2
extern char *wname;
extern char *wdir;
extern Window *win;
extern Channel *fschan, *writechan;

View file

@ -8,7 +8,7 @@
Channel *fschan;
Channel *writechan;
static File *devcons, *devnew;
static File *devcons, *devnew, *devwdir;
static void
fsread(Req *r)
@ -25,7 +25,12 @@ fsread(Req *r)
return;
}
assert(r->fid->file == devcons);
if(r->fid->file == devwdir){
readstr(r, wdir);
respond(r, nil);
return;
}
e.type = 'r';
e.r = r;
send(fschan, &e);
@ -72,6 +77,23 @@ fswrite(Req *r)
return;
}
if(r->fid->file == devwdir){
s = emalloc(r->ifcall.count+1);
memmove(s, r->ifcall.data, r->ifcall.count);
s[r->ifcall.count] = 0;
if(s[0] == '#' || s[0] == '/'){
free(wdir);
wdir = s;
} else {
wdir = eappend(wdir, "/", s);
free(s);
}
cleanname(wdir);
winsetdir(win, wdir, wname);
respond(r, nil);
return;
}
if(r->fid->file != devcons){
respond(r, "bug in fswrite");
return;
@ -161,5 +183,8 @@ mountcons(void)
devnew = createfile(fs.tree->root, "wnew", "win", 0666, nil);
if(devnew == nil)
sysfatal("creating /dev/wnew: %r");
devwdir = createfile(fs.tree->root, "wdir", "win", 0666, nil);
if(devwdir == nil)
sysfatal("creating /dev/wdir: %r");
threadpostmountsrv(&fs, nil, "/dev", MBEFORE);
}

View file

@ -16,6 +16,8 @@ int notepg;
int eraseinput;
int dirty = 0;
char *wname;
char *wdir;
Window *win; /* the main window */
void
@ -29,7 +31,6 @@ void
threadmain(int argc, char *argv[])
{
int i, j;
char *dir, *tag, *name;
char buf[1024], **av;
quotefmtinstall();
@ -52,27 +53,23 @@ threadmain(int argc, char *argv[])
av = emalloc(3*sizeof(char*));
av[0] = "rc";
av[1] = "-i";
name = getenv("sysname");
}else{
av = argv;
name = utfrrune(av[0], '/');
if(name)
name++;
else
name = av[0];
}
if(getwd(buf, sizeof buf) == 0)
dir = "/";
wname = utfrrune(av[0], '/');
if(wname)
wname++;
else
dir = buf;
dir = estrdup(dir);
tag = estrdup(dir);
tag = eappend(estrdup(tag), "/-", name);
wname = av[0];
if(getwd(buf, sizeof buf) == 0)
wdir = "/";
else
wdir = buf;
wdir = estrdup(wdir);
win = newwindow();
snprint(buf, sizeof buf, "%d", win->id);
putenv("winid", buf);
winname(win, tag);
winsetdir(win, wdir, wname);
wintagwrite(win, "Send Noscroll", 5+8);
threadcreate(mainctl, win, STACK);
mountcons();
@ -89,7 +86,7 @@ threadmain(int argc, char *argv[])
}
ctlprint(win->ctl, "scroll");
winsetdump(win, dir, buf);
winsetdump(win, wdir, buf);
}
int

View file

@ -33,6 +33,15 @@ winsetdump(Window *w, char *dir, char *cmd)
ctlprint(w->ctl, "dump %s\n", cmd);
}
void
winsetdir(Window *w, char *dir, char *name)
{
ctlprint(w->ctl, "dumpdir %s\n", dir);
if(strcmp(dir, "/")==0)
dir++;
ctlprint(w->ctl, "name %s/-%s\n", dir, name);
}
void
wineventproc(void *v)
{

View file

@ -1,38 +0,0 @@
#include <u.h>
#include <libc.h>
/*
* like fprint but be sure to deliver as a single write.
* (fprint uses a small write buffer.)
*/
void
xfprint(int fd, char *fmt, ...)
{
char *s;
va_list arg;
va_start(arg, fmt);
s = vsmprint(fmt, arg);
va_end(arg);
if(s == nil)
sysfatal("smprint: %r");
write(fd, s, strlen(s));
free(s);
}
void
main(int argc, char **argv)
{
int fd;
char dir[512];
fd = open("/dev/acme/ctl", OWRITE);
if(fd < 0)
exits(0);
getwd(dir, 512);
if(dir[0]!=0 && dir[strlen(dir)-1]=='/')
dir[strlen(dir)-1] = 0;
xfprint(fd, "name %s/-%s\n", dir, argc > 1 ? argv[1] : "rc");
xfprint(fd, "dumpdir %s\n", dir);
exits(0);
}