Module Name: src Committed By: plunky Date: Sat Aug 20 09:18:48 UTC 2011
Modified Files: src/usr.bin/sdpquery: print.c Log Message: 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 To generate a diff of this commit: cvs rdiff -u -r1.17 -r1.18 src/usr.bin/sdpquery/print.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/usr.bin/sdpquery/print.c diff -u src/usr.bin/sdpquery/print.c:1.17 src/usr.bin/sdpquery/print.c:1.18 --- src/usr.bin/sdpquery/print.c:1.17 Sun Aug 14 13:27:47 2011 +++ src/usr.bin/sdpquery/print.c Sat Aug 20 09:18:47 2011 @@ -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,38 +827,57 @@ printf("v%d.%d\n", (v >> 8), (v & 0xff)); } -/* - * This should only be called through print_language_attribute() which - * sets codeset of the string to be printed. - */ static void -print_language_string(sdp_data_t *data) +print_codeset_string(const char *src, size_t srclen, const char *codeset) { - char buf[50], *dst, *src; + char buf[50], *dst; iconv_t ih; - size_t n, srcleft, dstleft; - - if (!sdp_get_str(data, &src, &srcleft)) - return; + size_t n, dstlen; dst = buf; - dstleft = sizeof(buf); + dstlen = sizeof(buf); - ih = iconv_open(nl_langinfo(CODESET), language[current].codeset); + ih = iconv_open(nl_langinfo(CODESET), codeset); if (ih == (iconv_t)-1) { - printf("Can't convert %s string\n", language[current].codeset); + printf("Can't convert %s string\n", codeset); return; } - n = iconv(ih, (void *)&src, &srcleft, &dst, &dstleft); + n = iconv(ih, &src, &srclen, &dst, &dstlen); iconv_close(ih); - if (Nflag || n > 0) - printf("(%s) ", language[current].codeset); + 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. + */ +static void +print_language_string(sdp_data_t *data) +{ + char *str; + size_t len; + + if (!sdp_get_str(data, &str, &len)) + return; + + print_codeset_string(str, len, language[current].codeset); +} + + +static void +print_utf8_string(sdp_data_t *data) +{ + char *str; + size_t len; + + 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