> From: Jeremie Courreges-Anglas <j...@wxcvbn.org>
> Date: Fri, 30 Sep 2016 17:00:45 +0200
> 
> Mark Kettenis <mark.kette...@xs4all.nl> writes:
> 
> [...]
> 
> >> > -        for (i = 0; kbdenc_tab[i].value; i++)
> >> > -                printf("%s\n", kbdenc_tab[i].name);
> >> > +        for (i = 0; i < encs->nencodings; i++) {
> >> > +                n = &kbdenc_tab[0];
> >> > +                found = 0;
> >> > +                encoding = encs->encodings[i];
> >> > +                while (n->value) {
> >> > +                        if (n->value == KB_ENCODING(encoding)) {
> >> > +                                printf("%s", n->name);
> >> > +                                found++;
> >> > +                        }
> >> > +                        n++;
> >> > +                }
> >> 
> >> This looks a lot like a for loop.
> >
> > Right.  But there are some similar loops that are already written this
> > way.  So I left it the way I wrote^H^H^H^H^Hcopied it.  Feel free to
> > submite a separate patch that fixes this.
> 
> Ah, I see.  Here's the diff.

Thanks!  ok kettenis@

> Index: kbd_wscons.c
> ===================================================================
> RCS file: /cvs/src/sbin/kbd/kbd_wscons.c,v
> retrieving revision 1.31
> diff -u -p -p -u -r1.31 kbd_wscons.c
> --- kbd_wscons.c      30 Sep 2016 12:07:23 -0000      1.31
> +++ kbd_wscons.c      30 Sep 2016 14:55:03 -0000
> @@ -100,27 +100,23 @@ kbd_show_enc(struct wskbd_encoding_data 
>           kbtype_tab[idx]);
>  
>       for (i = 0; i < encs->nencodings; i++) {
> -             n = &kbdenc_tab[0];
>               found = 0;
>               encoding = encs->encodings[i];
> -             while (n->value) {
> +             for (n = &kbdenc_tab[0]; n->value; n++) {
>                       if (n->value == KB_ENCODING(encoding)) {
>                               printf("%s", n->name);
>                               found++;
>                       }
> -                     n++;
>               }
>               if (found == 0)
>                       printf("<encoding 0x%04x>", KB_ENCODING(encoding));
> -             n = &kbdvar_tab[0];
>               found = 0;
>               variant = KB_VARIANT(encoding);
> -             while (n->value) {
> +             for (n = &kbdvar_tab[0]; n->value; n++) {
>                       if ((n->value & KB_VARIANT(encoding)) == n->value) {
>                               printf(".%s", n->name);
>                               variant &= ~n->value;
>                       }
> -                     n++;
>               }
>               if (variant != 0)
>                       printf(".<variant 0x%08x>", variant);
> @@ -248,11 +244,9 @@ kbd_set(char *name, int verbose)
>                       *b++ = *c++;
>               *b = '\0';
>               v = 0;
> -             n = &kbdvar_tab[0];
> -             while (n->value) {
> +             for (n = &kbdvar_tab[0]; n->value; n++) {
>                       if (strcmp(n->name, buf) == 0)
>                               v = n->value;
> -                     n++;
>               }
>               if (v == 0)
>                       errx(1, "unknown variant %s", buf);
> 
> -- 
> jca | PGP : 0x1524E7EE / 5135 92C1 AD36 5293 2BDF  DDCC 0DFA 74AE 1524 E7EE
> 

Reply via email to