aboutsummaryrefslogtreecommitdiff
path: root/bin/chio
diff options
context:
space:
mode:
authorSimon J. Gerraty <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
committerSimon J. Gerraty <sjg@FreeBSD.org>2013-09-05 20:18:59 +0000
commitd1d015864103b253b3fcb2f72a0da5b0cfeb31b6 (patch)
tree22b131dceb13c3df96da594fbaadb693504797c7 /bin/chio
parent12d4083451fc39b3e831d4ea0bfa67d3b32cfb54 (diff)
parentb6f49c23a36f329cbf1e7f28078e17fd87f0e245 (diff)
downloadsrc-d1d015864103b253b3fcb2f72a0da5b0cfeb31b6.tar.gz
src-d1d015864103b253b3fcb2f72a0da5b0cfeb31b6.zip
Merge from head
Notes
Notes: svn path=/projects/bmake/; revision=255263
Diffstat (limited to 'bin/chio')
-rw-r--r--bin/chio/chio.c70
1 files changed, 70 insertions, 0 deletions
diff --git a/bin/chio/chio.c b/bin/chio/chio.c
index 9bb11d75f325..5a2a7ba215c3 100644
--- a/bin/chio/chio.c
+++ b/bin/chio/chio.c
@@ -54,6 +54,8 @@ __FBSDID("$FreeBSD$");
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
+#include <langinfo.h>
+#include <locale.h>
#include "defs.h"
#include "pathnames.h"
@@ -81,6 +83,7 @@ static int do_status(const char *, int, char **);
static int do_ielem(const char *, int, char **);
static int do_return(const char *, int, char **);
static int do_voltag(const char *, int, char **);
+static void print_designator(const char *, u_int8_t, u_int8_t);
#ifndef CHET_VT
#define CHET_VT 10 /* Completely Arbitrary */
@@ -723,6 +726,10 @@ do_status(const char *cname, int argc, char **argv)
putchar('?');
putchar('>');
}
+ if (ces->ces_designator_length > 0)
+ print_designator(ces->ces_designator,
+ ces->ces_code_set,
+ ces->ces_designator_length);
putchar('\n');
}
@@ -1177,3 +1184,66 @@ usage(void)
"arg1 arg2 [arg3 [...]]\n", getprogname());
exit(1);
}
+
+#define UTF8CODESET "UTF-8"
+
+static void
+print_designator(const char *designator, u_int8_t code_set,
+ u_int8_t designator_length)
+{
+ printf(" serial number: <");
+ switch (code_set) {
+ case CES_CODE_SET_ASCII: {
+ /*
+ * The driver insures that the string is always NUL terminated.
+ */
+ printf("%s", designator);
+ break;
+ }
+ case CES_CODE_SET_UTF_8: {
+ char *cs_native;
+
+ setlocale(LC_ALL, "");
+ cs_native = nl_langinfo(CODESET);
+
+ /* See if we can natively print UTF-8 */
+ if (strcmp(cs_native, UTF8CODESET) == 0)
+ cs_native = NULL;
+
+ if (cs_native == NULL) {
+ /* We can natively print UTF-8, so use printf. */
+ printf("%s", designator);
+ } else {
+ int i;
+
+ /*
+ * We can't natively print UTF-8. We should
+ * convert it to the terminal's codeset, but that
+ * requires iconv(3) and FreeBSD doesn't have
+ * iconv(3) in the base system yet. So we use %XX
+ * notation for non US-ASCII characters instead.
+ */
+ for (i = 0; i < designator_length &&
+ designator[i] != '\0'; i++) {
+ if ((unsigned char)designator[i] < 0x80)
+ printf("%c", designator[i]);
+ else
+ printf("%%%02x",
+ (unsigned char)designator[i]);
+ }
+ }
+ break;
+ }
+ case CES_CODE_SET_BINARY: {
+ int i;
+
+ for (i = 0; i < designator_length; i++)
+ printf("%02X%s", designator[i],
+ (i == designator_length - 1) ? "" : " ");
+ break;
+ }
+ default:
+ break;
+ }
+ printf(">");
+}