> From: Jeremie Courreges-Anglas <j...@wxcvbn.org> > Date: Fri, 30 Sep 2016 13:32:57 +0200 > > Mark Kettenis <mark.kette...@xs4all.nl> writes: > > >> Date: Thu, 29 Sep 2016 14:19:43 +0200 (CEST) > >> From: Mark Kettenis <mark.kette...@xs4all.nl> > >> > >> This diff adds a WSKBDIO_GETENCODINGS ioctl and uses it to print a > >> list of supported encodings like the old kvm groveling code did. The > >> ioctl will clamp the number of entries that are returns to the number > >> that was passed in. This means that if the number returned is the > >> same as the number passed in, there might be more entries and you > >> probably want to retry with a larger buffer. The new implementation > >> does this. > > > > Thanks to tb@ for testing this on a ramdisk. Here is a slightly > > better diff that frees the allocated memory. > > > > ok? > > Looks fine to me, ok jca@
Thanks, > Nitpicking below, I selectively applied those; see comments below. > > Index: sbin/kbd/kbd_wscons.c > > =================================================================== > > RCS file: /cvs/src/sbin/kbd/kbd_wscons.c,v > > retrieving revision 1.30 > > diff -u -p -r1.30 kbd_wscons.c > > --- sbin/kbd/kbd_wscons.c 27 Sep 2016 22:03:49 -0000 1.30 > > +++ sbin/kbd/kbd_wscons.c 29 Sep 2016 18:12:48 -0000 > > @@ -34,6 +34,7 @@ > > #include <fcntl.h> > > #include <limits.h> > > #include <stdio.h> > > +#include <stdlib.h> > > #include <string.h> > > #include <unistd.h> > > > > @@ -82,31 +83,83 @@ struct nameint kbdvar_tab[] = { > > > > extern char *__progname; > > > > -void kbd_show_enc(int idx); > > +void kbd_show_enc(struct wskbd_encoding_data *encs, int idx); > > +void kbd_get_encs(int fd, struct wskbd_encoding_data *encs); > > void kbd_list(void); > > void kbd_set(char *name, int verbose); > > > > void > > -kbd_show_enc(int idx) > > +kbd_show_enc(struct wskbd_encoding_data *encs, int idx) > > { > > + int found; > > + kbd_t encoding, variant; > > + struct nameint *n; > > int i; > > > > printf("tables available for %s keyboard:\nencoding\n\n", > > kbtype_tab[idx]); > > > > - 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.