shithub: riscv

Download patch

ref: 828ec57d652618e1d9cecb8fb6cc588afc063dca
parent: 65977417e7cc5919f7c9787f97a528e8c24d2423
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Wed Jun 29 20:46:52 EDT 2016

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

--- a/acme/bin/source/win/dat.h
+++ b/acme/bin/source/win/dat.h
@@ -66,6 +66,7 @@
 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 @@
 #pragma	varargck	argpos	error	1
 #pragma	varargck	argpos	ctlprint	2
 
+extern	char *wname;
+extern	char *wdir;
 extern	Window	*win;
 extern	Channel	*fschan, *writechan;
 
--- a/acme/bin/source/win/fs.c
+++ b/acme/bin/source/win/fs.c
@@ -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 @@
 		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 @@
 		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 @@
 	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);
 }
--- a/acme/bin/source/win/main.c
+++ b/acme/bin/source/win/main.c
@@ -16,6 +16,8 @@
 int	eraseinput;
 int	dirty = 0;
 
+char *wname;
+char *wdir;
 Window *win;		/* the main window */
 
 void
@@ -29,7 +31,6 @@
 threadmain(int argc, char *argv[])
 {
 	int i, j;
-	char *dir, *tag, *name;
 	char buf[1024], **av;
 
 	quotefmtinstall();
@@ -52,27 +53,23 @@
 		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];
 	}
-
+	wname = utfrrune(av[0], '/');
+	if(wname)
+		wname++;
+	else
+		wname = av[0];
 	if(getwd(buf, sizeof buf) == 0)
-		dir = "/";
+		wdir = "/";
 	else
-		dir = buf;
-	dir = estrdup(dir);
-	tag = estrdup(dir);
-	tag = eappend(estrdup(tag), "/-", name);
+		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 @@
 	}
 
 	ctlprint(win->ctl, "scroll");
-	winsetdump(win, dir, buf);
+	winsetdump(win, wdir, buf);
 }
 
 int
--- a/acme/bin/source/win/win.c
+++ b/acme/bin/source/win/win.c
@@ -34,6 +34,15 @@
 }
 
 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)
 {
 	Window *w;
--- a/sys/src/cmd/awd.c
+++ /dev/null
@@ -1,38 +1,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);
-}