From 05f6883a1ad7e135c4c0014a5dc586c4e25fc70c Mon Sep 17 00:00:00 2001 From: Serge Vakulenko Date: Mon, 27 Aug 2018 16:42:50 -0700 Subject: [PATCH] Print utf8 text. --- md380.c | 5 ++--- util.c | 23 +++++++++++++++++++++++ util.h | 5 +++++ uv380.c | 5 ++--- 4 files changed, 32 insertions(+), 6 deletions(-) diff --git a/md380.c b/md380.c index 8978485..a4df42f 100644 --- a/md380.c +++ b/md380.c @@ -312,12 +312,11 @@ static void print_unicode(FILE *out, const uint16_t *text, unsigned nchars, int unsigned i; for (i=0; i 0xxxxxxx +// 00000xxx.xxyyyyyy -> 110xxxxx, 10yyyyyy +// xxxxyyyy.yyzzzzzz -> 1110xxxx, 10yyyyyy, 10zzzzzz +// +void putc_utf8(unsigned short ch, FILE *out) +{ + if (ch < 0x80) { + putc (ch, out); + + } else if (ch < 0x800) { + putc (ch >> 6 | 0xc0, out); + putc ((ch & 0x3f) | 0x80, out); + + } else { + putc (ch >> 12 | 0xe0, out); + putc (((ch >> 6) & 0x3f) | 0x80, out); + putc ((ch & 0x3f) | 0x80, out); + } +} diff --git a/util.h b/util.h index 89e625d..f23a9f1 100644 --- a/util.h +++ b/util.h @@ -119,3 +119,8 @@ void print_options(FILE *out, const char **tab, int num, const char *info); // Print list of all squelch tones. // void print_squelch_tones(FILE *out, int normal_only); + +// +// Write Unicode symbol to a file in UTF-8 encoding. +// +void putc_utf8(unsigned short ch, FILE *out); diff --git a/uv380.c b/uv380.c index 8a1e5ae..1b5694d 100644 --- a/uv380.c +++ b/uv380.c @@ -328,8 +328,7 @@ static void print_unicode(FILE *out, const uint16_t *text, unsigned nchars, int unsigned i; for (i=0; i