shithub: riscv

Download patch

ref: 5b5416aa05b0f66632ded929383c32c0a5aaa375
parent: 8152e9d075e507d36b6edb48ac1e15082fabeed5
author: cinap_lenrek <[email protected]>
date: Mon Jan 28 18:29:22 EST 2019

devdraw: simplify drawgen()

--- a/sys/src/9/port/devdraw.c
+++ b/sys/src/9/port/devdraw.c
@@ -239,31 +239,36 @@
 	 * Top level directory contains the name of the device.
 	 */
 	t = QID(c->qid);
-	if(t == Qtopdir || t == Qwinname){
-		if(s == 1 || t == Qwinname){
-			mkqid(&q, Qwinname, 0, QTFILE);
-			devdir(c, q, "winname", 0, eve, 0444, dp);
-		}
-		else if(s == 0){
+	switch(t){
+	case Qtopdir:
+		if(s == 0){
 			mkqid(&q, Q2nd, 0, QTDIR);
 			devdir(c, q, "draw", 0, eve, 0555, dp);
+			return 1;
 		}
-		else
-			return -1;
-		return 1;
+		if(s == 1){
+	case Qwinname:
+			mkqid(&q, Qwinname, 0, QTFILE);
+			devdir(c, q, "winname", 0, eve, 0444, dp);
+			return 1;
+		}
+		return -1;
 	}
 
 	/*
 	 * Second level contains "new" plus all the clients.
 	 */
-	if(t == Q2nd || t == Qnew){
+	switch(t){
+	case Q2nd:
 		if(s == 0){
+	case Qnew:
 			mkqid(&q, Qnew, 0, QTFILE);
 			devdir(c, q, "new", 0, eve, 0666, dp);
+			return 1;
 		}
-		else if(s <= sdraw.nclient){
+		if(s <= sdraw.nclient){
 			cl = sdraw.client[s-1];
-			if(cl == 0)
+			if(cl == nil)
 				return 0;
 			sprint(up->genbuf, "%d", cl->clientid);
 			mkqid(&q, (s<<QSHIFT)|Q3rd, 0, QTDIR);
@@ -270,9 +275,7 @@
 			devdir(c, q, up->genbuf, 0, eve, 0555, dp);
 			return 1;
 		}
-		else
-			return -1;
-		return 1;
+		return -1;
 	}
 
 	/*
--- a/sys/src/cmd/vnc/devdraw.c
+++ b/sys/src/cmd/vnc/devdraw.c
@@ -237,31 +237,36 @@
 	 * Top level directory contains the name of the device.
 	 */
 	t = QID(c->qid);
-	if(t == Qtopdir || t == Qwinname){
-		if(s == 1 || t == Qwinname){
-			mkqid(&q, Qwinname, 0, QTFILE);
-			devdir(c, q, "winname", 0, eve, 0444, dp);
-		}
-		else if(s == 0){
+	switch(t){
+	case Qtopdir:
+		if(s == 0){
 			mkqid(&q, Q2nd, 0, QTDIR);
 			devdir(c, q, "draw", 0, eve, 0555, dp);
+			return 1;
 		}
-		else
-			return -1;
-		return 1;
+		if(s == 1){
+	case Qwinname:
+			mkqid(&q, Qwinname, 0, QTFILE);
+			devdir(c, q, "winname", 0, eve, 0444, dp);
+			return 1;
+		}
+		return -1;
 	}
 
 	/*
 	 * Second level contains "new" plus all the clients.
 	 */
-	if(t == Q2nd || t == Qnew){
+	switch(t){
+	case Q2nd:
 		if(s == 0){
+	case Qnew:
 			mkqid(&q, Qnew, 0, QTFILE);
 			devdir(c, q, "new", 0, eve, 0666, dp);
+			return 1;
 		}
-		else if(s <= sdraw.nclient){
+		if(s <= sdraw.nclient){
 			cl = sdraw.client[s-1];
-			if(cl == 0)
+			if(cl == nil)
 				return 0;
 			sprint(up->genbuf, "%d", cl->clientid);
 			mkqid(&q, (s<<QSHIFT)|Q3rd, 0, QTDIR);
@@ -268,9 +273,7 @@
 			devdir(c, q, up->genbuf, 0, eve, 0555, dp);
 			return 1;
 		}
-		else
-			return -1;
-		return 1;
+		return -1;
 	}
 
 	/*