Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.bin/sdpquery add print_utf8_string for some profiles tha...
details: https://anonhg.NetBSD.org/src/rev/fbe0799407f2
branches: trunk
changeset: 768555:fbe0799407f2
user: plunky <plunky%NetBSD.org@localhost>
date: Sat Aug 20 09:18:47 2011 +0000
description:
add print_utf8_string for some profiles that specify UTF-8 specifically,
and supply a print_codeset_string() so we don't need void * casts to avoid
the char ** -> const char ** complaint
diffstat:
usr.bin/sdpquery/print.c | 73 ++++++++++++++++++++++++++++++-----------------
1 files changed, 47 insertions(+), 26 deletions(-)
diffs (137 lines):
diff -r 5a403df3a8ad -r fbe0799407f2 usr.bin/sdpquery/print.c
--- a/usr.bin/sdpquery/print.c Sat Aug 20 07:32:34 2011 +0000
+++ b/usr.bin/sdpquery/print.c Sat Aug 20 09:18:47 2011 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: print.c,v 1.17 2011/08/14 13:27:47 christos Exp $ */
+/* $NetBSD: print.c,v 1.18 2011/08/20 09:18:47 plunky Exp $ */
/*-
* Copyright (c) 2009 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__RCSID("$NetBSD: print.c,v 1.17 2011/08/14 13:27:47 christos Exp $");
+__RCSID("$NetBSD: print.c,v 1.18 2011/08/20 09:18:47 plunky Exp $");
#include <ctype.h>
#include <iconv.h>
@@ -85,7 +85,9 @@
static void print_string_list(sdp_data_t *);
static void print_url(sdp_data_t *);
static void print_profile_version(sdp_data_t *);
+static void print_codeset_string(const char *, size_t, const char *);
static void print_language_string(sdp_data_t *);
+static void print_utf8_string(sdp_data_t *);
static void print_service_class_id_list(sdp_data_t *);
static void print_protocol_descriptor(sdp_data_t *);
@@ -251,8 +253,8 @@
{ 0x0354, "XHTML-PrintImageFormatsSupported", print_string_list },
{ 0x0356, "ColorSupported", print_bool },
{ 0x0358, "1284ID", print_1284id },
- { 0x035a, "PrinterName", print_string },
- { 0x035c, "PrinterLocation", print_string },
+ { 0x035a, "PrinterName", print_utf8_string },
+ { 0x035c, "PrinterLocation", print_utf8_string },
{ 0x035e, "DuplexSupported", print_bool },
{ 0x0360, "MediaTypesSupported", print_string_list },
{ 0x0362, "MaxMediaWidth", print_uint16d },
@@ -263,7 +265,7 @@
{ 0x0372, "DirectPrintingRUISupported", print_bool },
{ 0x0374, "ReferencePrintingTopURL", print_url },
{ 0x0376, "DirectPrintingTopURL", print_url },
- { 0x037a, "DeviceName", print_string },
+ { 0x037a, "DeviceName", print_utf8_string },
};
attr_t bi_attrs[] = { /* Basic Imaging */
@@ -307,9 +309,9 @@
attr_t hcr_attrs[] = { /* Hardcopy Cable Replacement */
{ 0x0300, "1284ID", print_1284id },
- { 0x0302, "DeviceName", print_string },
- { 0x0304, "FriendlyName", print_string },
- { 0x0306, "DeviceLocation", print_string },
+ { 0x0302, "DeviceName", print_utf8_string },
+ { 0x0304, "FriendlyName", print_utf8_string },
+ { 0x0306, "DeviceLocation", print_utf8_string },
};
attr_t pnp_attrs[] = { /* Device ID */
@@ -825,6 +827,30 @@
printf("v%d.%d\n", (v >> 8), (v & 0xff));
}
+static void
+print_codeset_string(const char *src, size_t srclen, const char *codeset)
+{
+ char buf[50], *dst;
+ iconv_t ih;
+ size_t n, dstlen;
+
+ dst = buf;
+ dstlen = sizeof(buf);
+
+ ih = iconv_open(nl_langinfo(CODESET), codeset);
+ if (ih == (iconv_t)-1) {
+ printf("Can't convert %s string\n", codeset);
+ return;
+ }
+
+ n = iconv(ih, &src, &srclen, &dst, &dstlen);
+
+ iconv_close(ih);
+
+ printf("\"%.*s%s\n", (int)(sizeof(buf) - dstlen), buf,
+ (srclen > 0 ? " ..." : "\""));
+}
+
/*
* This should only be called through print_language_attribute() which
* sets codeset of the string to be printed.
@@ -832,31 +858,26 @@
static void
print_language_string(sdp_data_t *data)
{
- char buf[50], *dst, *src;
- iconv_t ih;
- size_t n, srcleft, dstleft;
+ char *str;
+ size_t len;
- if (!sdp_get_str(data, &src, &srcleft))
+ if (!sdp_get_str(data, &str, &len))
return;
- dst = buf;
- dstleft = sizeof(buf);
+ print_codeset_string(str, len, language[current].codeset);
+}
- ih = iconv_open(nl_langinfo(CODESET), language[current].codeset);
- if (ih == (iconv_t)-1) {
- printf("Can't convert %s string\n", language[current].codeset);
- return;
- }
- n = iconv(ih, (void *)&src, &srcleft, &dst, &dstleft);
-
- iconv_close(ih);
+static void
+print_utf8_string(sdp_data_t *data)
+{
+ char *str;
+ size_t len;
- if (Nflag || n > 0)
- printf("(%s) ", language[current].codeset);
+ if (!sdp_get_str(data, &str, &len))
+ return;
- printf("\"%.*s%s\n", (int)(sizeof(buf) - dstleft), buf,
- (srcleft > 0 ? " ..." : "\""));
+ print_codeset_string(str, len, "UTF-8");
}
static void
Home |
Main Index |
Thread Index |
Old Index