Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/wscons make check cleaner, and simplify the code.



details:   https://anonhg.NetBSD.org/src/rev/80d3e942c444
branches:  trunk
changeset: 829179:80d3e942c444
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jan 21 01:18:48 2018 +0000

description:
make check cleaner, and simplify the code.

diffstat:

 sys/dev/wscons/wsemul_vt100.c |  88 +++++++++++++++++-------------------------
 1 files changed, 36 insertions(+), 52 deletions(-)

diffs (truncated from 304 to 300 lines):

diff -r ea823e8c2354 -r 80d3e942c444 sys/dev/wscons/wsemul_vt100.c
--- a/sys/dev/wscons/wsemul_vt100.c     Sat Jan 20 23:27:06 2018 +0000
+++ b/sys/dev/wscons/wsemul_vt100.c     Sun Jan 21 01:18:48 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: wsemul_vt100.c,v 1.42 2018/01/20 23:27:06 rin Exp $ */
+/* $NetBSD: wsemul_vt100.c,v 1.43 2018/01/21 01:18:48 christos Exp $ */
 
 /*
  * Copyright (c) 1998
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.42 2018/01/20 23:27:06 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsemul_vt100.c,v 1.43 2018/01/21 01:18:48 christos Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_wsmsgattrs.h"
@@ -230,7 +230,7 @@
        edp->isolatin1tab = edp->decgraphtab = edp->dectechtab = 0;
        edp->nrctab = 0;
        wsemul_vt100_reset(edp);
-       return (edp);
+       return edp;
 }
 
 void *
@@ -263,7 +263,7 @@
        edp->nrctab = malloc(128 * sizeof(int), M_DEVBUF, M_NOWAIT);
        vt100_initchartables(edp);
        wsemul_vt100_reset(edp);
-       return (edp);
+       return edp;
 }
 
 void
@@ -461,7 +461,7 @@
                break;
        case ASCII_ESC:
                if (kernel) {
-                       printf("wsemul_vt100_output_c0c1: ESC in kernel output ignored\n");
+                       printf("%s: ESC in kernel output ignored\n", __func__);
                        break;  /* ignore the ESC */
                }
 
@@ -490,7 +490,8 @@
        case ST: /* string end 8-bit */
                /* XXX only in VT100_EMUL_STATE_STRING */
                wsemul_vt100_handle_dcs(edp);
-               return (VT100_EMUL_STATE_NORMAL);
+               edp->state = VT100_EMUL_STATE_NORMAL;
+               break;
 #endif
        case ASCII_LF:
        case ASCII_VT:
@@ -504,7 +505,6 @@
 wsemul_vt100_output_esc(struct wsemul_vt100_emuldata *edp, u_char c)
 {
        struct vt100base_data *vd = &edp->bd;
-       u_int newstate = VT100_EMUL_STATE_NORMAL;
        int i;
 
        switch (c) {
@@ -512,8 +512,7 @@
                vd->nargs = 0;
                memset(vd->args, 0, sizeof (vd->args));
                vd->modif1 = vd->modif2 = '\0';
-               newstate = VT100_EMUL_STATE_CSI;
-               break;
+               return VT100_EMUL_STATE_CSI;
        case '7': /* DECSC */
                vd->flags |= VTFL_SAVEDCURS;
                edp->savedcursor_row = vd->crow;
@@ -591,8 +590,7 @@
        case 'P': /* DCS */
                vd->nargs = 0;
                memset(vd->args, 0, sizeof (vd->args));
-               newstate = VT100_EMUL_STATE_DCS;
-               break;
+               return VT100_EMUL_STATE_DCS;
        case 'c': /* RIS */
                wsemul_vt100_reset(edp);
                wsemul_vt100_ed(vd, 2);
@@ -600,24 +598,19 @@
                break;
        case '(': case ')': case '*': case '+': /* SCS */
                edp->designating = c - '(';
-               newstate = VT100_EMUL_STATE_SCS94;
-               break;
+               return VT100_EMUL_STATE_SCS94;
        case '-': case '.': case '/': /* SCS */
                edp->designating = c - '-' + 1;
-               newstate = VT100_EMUL_STATE_SCS96;
-               break;
+               return VT100_EMUL_STATE_SCS96;
        case '#':
-               newstate = VT100_EMUL_STATE_ESC_HASH;
-               break;
+               return VT100_EMUL_STATE_ESC_HASH;
        case ' ': /* 7/8 bit */
-               newstate = VT100_EMUL_STATE_ESC_SPC;
-               break;
+               return VT100_EMUL_STATE_ESC_SPC;
        case ']': /* OSC operating system command */
        case '^': /* PM privacy message */
        case '_': /* APC application program command */
                /* ignored */
-               newstate = VT100_EMUL_STATE_STRING;
-               break;
+               return VT100_EMUL_STATE_STRING;
        case '<': /* exit VT52 mode - ignored */
                break;
        default:
@@ -626,19 +619,15 @@
 #endif
                break;
        }
-
-       return (newstate);
+       return VT100_EMUL_STATE_NORMAL;
 }
 
 static u_int
 wsemul_vt100_output_scs94(struct wsemul_vt100_emuldata *edp, u_char c)
 {
-       u_int newstate = VT100_EMUL_STATE_NORMAL;
-
        switch (c) {
        case '%': /* probably DEC supplemental graphic */
-               newstate = VT100_EMUL_STATE_SCS94_PERCENT;
-               break;
+               return VT100_EMUL_STATE_SCS94_PERCENT;
        case 'A': /* british / national */
                edp->chartab_G[edp->designating] = edp->nrctab;
                break;
@@ -661,7 +650,7 @@
 #endif
                break;
        }
-       return (newstate);
+       return VT100_EMUL_STATE_NORMAL;
 }
 
 static u_int
@@ -678,19 +667,17 @@
 #endif
                break;
        }
-       return (VT100_EMUL_STATE_NORMAL);
+       return VT100_EMUL_STATE_NORMAL;
 }
 
 static u_int
 wsemul_vt100_output_scs96(struct wsemul_vt100_emuldata *edp, u_char c)
 {
-       u_int newstate = VT100_EMUL_STATE_NORMAL;
        int nrc;
 
        switch (c) {
        case '%': /* probably portuguese */
-               newstate = VT100_EMUL_STATE_SCS96_PERCENT;
-               break;
+               return VT100_EMUL_STATE_SCS96_PERCENT;
        case 'A': /* ISO-latin-1 supplemental */
                edp->chartab_G[edp->designating] = edp->isolatin1tab;
                break;
@@ -732,7 +719,7 @@
 #endif
                break;
        }
-       return (newstate);
+       return VT100_EMUL_STATE_NORMAL;
 }
 
 static u_int
@@ -748,7 +735,7 @@
 #endif
                break;
        }
-       return (VT100_EMUL_STATE_NORMAL);
+       return VT100_EMUL_STATE_NORMAL;
 }
 
 static u_int
@@ -768,7 +755,7 @@
 #endif
                break;
        }
-       return (VT100_EMUL_STATE_NORMAL);
+       return VT100_EMUL_STATE_NORMAL;
 }
 
 static u_int
@@ -778,7 +765,7 @@
 
        if (vd->dcstype && vd->dcspos < DCS_MAXLEN)
                vd->dcsarg[vd->dcspos++] = c;
-       return (VT100_EMUL_STATE_STRING);
+       return VT100_EMUL_STATE_STRING;
 }
 
 static u_int
@@ -788,16 +775,15 @@
 
        if (c == '\\') { /* ST complete */
                wsemul_vt100_handle_dcs(vd);
-               return (VT100_EMUL_STATE_NORMAL);
+               return VT100_EMUL_STATE_NORMAL;
        } else
-               return (VT100_EMUL_STATE_STRING);
+               return VT100_EMUL_STATE_STRING;
 }
 
 static u_int
 wsemul_vt100_output_dcs(struct wsemul_vt100_emuldata *edp, u_char c)
 {
        struct vt100base_data *vd = &edp->bd;
-       u_int newstate = VT100_EMUL_STATE_DCS;
 
        switch (c) {
        case '0': case '1': case '2': case '3': case '4':
@@ -822,8 +808,7 @@
                newstate = VT100_EMUL_STATE_STRING;
                switch (c) {
                case '$':
-                       newstate = VT100_EMUL_STATE_DCS_DOLLAR;
-                       break;
+                       return VT100_EMUL_STATE_DCS_DOLLAR;
                case '{': /* DECDLD soft charset */
                case '!': /* DECRQUPSS user preferred supplemental set */
                        /* 'u' must follow - need another state */
@@ -840,7 +825,7 @@
                }
        }
 
-       return (newstate);
+       return VT100_EMUL_STATE_DCS;
 }
 
 static u_int
@@ -881,7 +866,7 @@
 #endif
                break;
        }
-       return (VT100_EMUL_STATE_STRING);
+       return VT100_EMUL_STATE_STRING;
 }
 
 static u_int
@@ -937,14 +922,13 @@
 #endif
                break;
        }
-       return (VT100_EMUL_STATE_NORMAL);
+       return VT100_EMUL_STATE_NORMAL;
 }
 
 static u_int
 wsemul_vt100_output_csi(struct wsemul_vt100_emuldata *edp, u_char c)
 {
        struct vt100base_data *vd = &edp->bd;
-       u_int newstate = VT100_EMUL_STATE_CSI;
 
        switch (c) {
        case '0': case '1': case '2': case '3': case '4':
@@ -977,10 +961,9 @@
                        vd->nargs = VT100_EMUL_NARGS;
                }
                wsemul_vt100_handle_csi(vd, c);
-               newstate = VT100_EMUL_STATE_NORMAL;
-               break;
+               return VT100_EMUL_STATE_NORMAL;
        }
-       return (newstate);
+       return VT100_EMUL_STATE_CSI;
 }
 
 void
@@ -991,7 +974,7 @@
 
 #ifdef DIAGNOSTIC
        if (kernel && !edp->console)
-               panic("wsemul_vt100_output: kernel output, not console");
+               panic("%s: kernel output, not console", __func__);
 #endif
 
        if (vd->flags & VTFL_CURSORON)
@@ -1006,12 +989,13 @@
                        wsemul_vt100_output_normal(edp, *data, kernel);
                        continue;
                }
-               KASSERT(edp->state <= __arraycount(vt100_output));
-               edp->state = vt100_output[edp->state - 1](edp, *data);
+               int state = edp->state - 1;
+               KASSERT(state < __arraycount(vt100_output));
+               edp->state = vt100_output[state](edp, *data);
        }
        if (vd->flags & VTFL_CURSORON)
                (*vd->emulops->cursor)(vd->emulcookie, 1,
-                                       vd->crow, vd->ccol << vd->dw);



Home | Main Index | Thread Index | Old Index