Deleted Added
full compact
chio.c (225736) chio.c (252214)
1/* $NetBSD: chio.c,v 1.6 1998/01/04 23:53:58 thorpej Exp $ */
2/*-
3 * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 29 unchanged lines hidden (view full) ---

38#if 0
39#ifndef lint
40static const char copyright[] =
41 "@(#) Copyright (c) 1996 Jason R. Thorpe. All rights reserved.";
42#endif /* not lint */
43#endif
44
45#include <sys/cdefs.h>
1/* $NetBSD: chio.c,v 1.6 1998/01/04 23:53:58 thorpej Exp $ */
2/*-
3 * Copyright (c) 1996 Jason R. Thorpe <thorpej@and.com>
4 * All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:

--- 29 unchanged lines hidden (view full) ---

38#if 0
39#ifndef lint
40static const char copyright[] =
41 "@(#) Copyright (c) 1996 Jason R. Thorpe. All rights reserved.";
42#endif /* not lint */
43#endif
44
45#include <sys/cdefs.h>
46__FBSDID("$FreeBSD: stable/9/bin/chio/chio.c 208730 2010-06-02 09:34:41Z uqs $");
46__FBSDID("$FreeBSD: stable/9/bin/chio/chio.c 252214 2013-06-25 21:43:49Z ken $");
47
48#include <sys/param.h>
49#include <sys/chio.h>
50#include <err.h>
51#include <fcntl.h>
52#include <stdio.h>
53#include <stdint.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
47
48#include <sys/param.h>
49#include <sys/chio.h>
50#include <err.h>
51#include <fcntl.h>
52#include <stdio.h>
53#include <stdint.h>
54#include <stdlib.h>
55#include <string.h>
56#include <unistd.h>
57#include <langinfo.h>
58#include <locale.h>
57
58#include "defs.h"
59#include "pathnames.h"
60
61static void usage(void);
62static void cleanup(void);
63static u_int16_t parse_element_type(char *);
64static u_int16_t parse_element_unit(char *);

--- 11 unchanged lines hidden (view full) ---

76static int do_position(const char *, int, char **);
77static int do_params(const char *, int, char **);
78static int do_getpicker(const char *, int, char **);
79static int do_setpicker(const char *, int, char **);
80static int do_status(const char *, int, char **);
81static int do_ielem(const char *, int, char **);
82static int do_return(const char *, int, char **);
83static int do_voltag(const char *, int, char **);
59
60#include "defs.h"
61#include "pathnames.h"
62
63static void usage(void);
64static void cleanup(void);
65static u_int16_t parse_element_type(char *);
66static u_int16_t parse_element_unit(char *);

--- 11 unchanged lines hidden (view full) ---

78static int do_position(const char *, int, char **);
79static int do_params(const char *, int, char **);
80static int do_getpicker(const char *, int, char **);
81static int do_setpicker(const char *, int, char **);
82static int do_status(const char *, int, char **);
83static int do_ielem(const char *, int, char **);
84static int do_return(const char *, int, char **);
85static int do_voltag(const char *, int, char **);
86static void print_designator(const char *, u_int8_t, u_int8_t);
84
85#ifndef CHET_VT
86#define CHET_VT 10 /* Completely Arbitrary */
87#endif
88
89/* Valid changer element types. */
90const struct element_type elements[] = {
91 { "drive", CHET_DT },

--- 626 unchanged lines hidden (view full) ---

718 putchar('?');
719 putchar(':');
720 if (ces->ces_flags & CES_LUN_VALID)
721 printf("%d", ces->ces_scsi_lun);
722 else
723 putchar('?');
724 putchar('>');
725 }
87
88#ifndef CHET_VT
89#define CHET_VT 10 /* Completely Arbitrary */
90#endif
91
92/* Valid changer element types. */
93const struct element_type elements[] = {
94 { "drive", CHET_DT },

--- 626 unchanged lines hidden (view full) ---

721 putchar('?');
722 putchar(':');
723 if (ces->ces_flags & CES_LUN_VALID)
724 printf("%d", ces->ces_scsi_lun);
725 else
726 putchar('?');
727 putchar('>');
728 }
729 if (ces->ces_designator_length > 0)
730 print_designator(ces->ces_designator,
731 ces->ces_code_set,
732 ces->ces_designator_length);
726 putchar('\n');
727 }
728
729 free(cesr.cesr_element_status);
730 count = 0;
731 }
732
733 return (0);

--- 438 unchanged lines hidden (view full) ---

1172
1173static void
1174usage(void)
1175{
1176 (void)fprintf(stderr, "usage: %s [-f changer] command [-<flags>] "
1177 "arg1 arg2 [arg3 [...]]\n", getprogname());
1178 exit(1);
1179}
733 putchar('\n');
734 }
735
736 free(cesr.cesr_element_status);
737 count = 0;
738 }
739
740 return (0);

--- 438 unchanged lines hidden (view full) ---

1179
1180static void
1181usage(void)
1182{
1183 (void)fprintf(stderr, "usage: %s [-f changer] command [-<flags>] "
1184 "arg1 arg2 [arg3 [...]]\n", getprogname());
1185 exit(1);
1186}
1187
1188#define UTF8CODESET "UTF-8"
1189
1190static void
1191print_designator(const char *designator, u_int8_t code_set,
1192 u_int8_t designator_length)
1193{
1194 printf(" serial number: <");
1195 switch (code_set) {
1196 case CES_CODE_SET_ASCII: {
1197 /*
1198 * The driver insures that the string is always NUL terminated.
1199 */
1200 printf("%s", designator);
1201 break;
1202 }
1203 case CES_CODE_SET_UTF_8: {
1204 char *cs_native;
1205
1206 setlocale(LC_ALL, "");
1207 cs_native = nl_langinfo(CODESET);
1208
1209 /* See if we can natively print UTF-8 */
1210 if (strcmp(cs_native, UTF8CODESET) == 0)
1211 cs_native = NULL;
1212
1213 if (cs_native == NULL) {
1214 /* We can natively print UTF-8, so use printf. */
1215 printf("%s", designator);
1216 } else {
1217 int i;
1218
1219 /*
1220 * We can't natively print UTF-8. We should
1221 * convert it to the terminal's codeset, but that
1222 * requires iconv(3) and FreeBSD doesn't have
1223 * iconv(3) in the base system yet. So we use %XX
1224 * notation for non US-ASCII characters instead.
1225 */
1226 for (i = 0; i < designator_length &&
1227 designator[i] != '\0'; i++) {
1228 if ((unsigned char)designator[i] < 0x80)
1229 printf("%c", designator[i]);
1230 else
1231 printf("%%%02x",
1232 (unsigned char)designator[i]);
1233 }
1234 }
1235 break;
1236 }
1237 case CES_CODE_SET_BINARY: {
1238 int i;
1239
1240 for (i = 0; i < designator_length; i++)
1241 printf("%02X%s", designator[i],
1242 (i == designator_length - 1) ? "" : " ");
1243 break;
1244 }
1245 default:
1246 break;
1247 }
1248 printf(">");
1249}