svn commit: r199793 - user/ed/newcons/sys/kern

Ed Schouten ed at FreeBSD.org
Wed Nov 25 10:56:51 UTC 2009


Author: ed
Date: Wed Nov 25 10:56:50 2009
New Revision: 199793
URL: http://svn.freebsd.org/changeset/base/199793

Log:
  Tidy up this code by moving the TTY == NULL checks to the top.

Modified:
  user/ed/newcons/sys/kern/subr_terminal.c

Modified: user/ed/newcons/sys/kern/subr_terminal.c
==============================================================================
--- user/ed/newcons/sys/kern/subr_terminal.c	Wed Nov 25 10:52:41 2009	(r199792)
+++ user/ed/newcons/sys/kern/subr_terminal.c	Wed Nov 25 10:56:50 2009	(r199793)
@@ -233,45 +233,46 @@ terminal_input_char(struct terminal *tm,
 {
 	struct tty *tp;
 
+	tp = tm->tm_tty;
+	if (tp == NULL)
+		return;
+
 	/* Strip off any attributes. */
 	c = TCHAR_CHARACTER(c);
 
-	tp = tm->tm_tty;
-	if (tp != NULL) {
-		tty_lock(tp);
-		/*
-		 * Conversion to UTF-8.
-		 */
-		if (c < 0x80) {
-			ttydisc_rint(tp, c, 0);
-		} else if (c < 0x800) {
-			char str[2] = {
-				0xc0 | (c >> 6),
-				0x80 | (c & 0x3f)
-			};
-
-			ttydisc_rint_simple(tp, str, sizeof str);
-		} else if (c < 0x10000) {
-			char str[3] = {
-				0xe0 | (c >> 12),
-				0x80 | ((c >> 6) & 0x3f),
-				0x80 | (c & 0x3f)
-			};
-
-			ttydisc_rint_simple(tp, str, sizeof str);
-		} else {
-			char str[4] = {
-				0xf0 | (c >> 18),
-				0x80 | ((c >> 12) & 0x3f),
-				0x80 | ((c >> 6) & 0x3f),
-				0x80 | (c & 0x3f)
-			};
+	tty_lock(tp);
+	/*
+	 * Conversion to UTF-8.
+	 */
+	if (c < 0x80) {
+		ttydisc_rint(tp, c, 0);
+	} else if (c < 0x800) {
+		char str[2] = {
+			0xc0 | (c >> 6),
+			0x80 | (c & 0x3f)
+		};
+
+		ttydisc_rint_simple(tp, str, sizeof str);
+	} else if (c < 0x10000) {
+		char str[3] = {
+			0xe0 | (c >> 12),
+			0x80 | ((c >> 6) & 0x3f),
+			0x80 | (c & 0x3f)
+		};
+
+		ttydisc_rint_simple(tp, str, sizeof str);
+	} else {
+		char str[4] = {
+			0xf0 | (c >> 18),
+			0x80 | ((c >> 12) & 0x3f),
+			0x80 | ((c >> 6) & 0x3f),
+			0x80 | (c & 0x3f)
+		};
 
-			ttydisc_rint_simple(tp, str, sizeof str);
-		}
-		ttydisc_rint_done(tp);
-		tty_unlock(tp);
+		ttydisc_rint_simple(tp, str, sizeof str);
 	}
+	ttydisc_rint_done(tp);
+	tty_unlock(tp);
 }
 
 void
@@ -280,12 +281,13 @@ terminal_input_raw(struct terminal *tm, 
 	struct tty *tp;
 
 	tp = tm->tm_tty;
-	if (tp != NULL) {
-		tty_lock(tp);
-		ttydisc_rint(tp, c, 0);
-		ttydisc_rint_done(tp);
-		tty_unlock(tp);
-	}
+	if (tp == NULL)
+		return;
+
+	tty_lock(tp);
+	ttydisc_rint(tp, c, 0);
+	ttydisc_rint_done(tp);
+	tty_unlock(tp);
 }
 
 void
@@ -533,9 +535,10 @@ termteken_respond(void *softc, const voi
 	 * input.
 	 */
 	tp = tm->tm_tty;
-	if (tp != NULL) {
-		ttydisc_rint_simple(tp, buf, len);
-		ttydisc_rint_done(tp);
-	}
+	if (tp == NULL)
+		return;
+
+	ttydisc_rint_simple(tp, buf, len);
+	ttydisc_rint_done(tp);
 #endif
 }


More information about the svn-src-user mailing list