Print utf8 text.

This commit is contained in:
Serge Vakulenko 2018-08-27 16:42:50 -07:00
parent 4600413c2e
commit 05f6883a1a
4 changed files with 32 additions and 6 deletions

View File

@ -312,12 +312,11 @@ static void print_unicode(FILE *out, const uint16_t *text, unsigned nchars, int
unsigned i;
for (i=0; i<nchars && *text; i++) {
//TODO: convert to utf8
putc(*text++, out);
putc_utf8(*text++, out);
}
if (fill_flag) {
for (; i<nchars; i++) {
putc(' ', out);
putc_utf8(' ', out);
}
}
}

23
util.c
View File

@ -185,3 +185,26 @@ void print_options(FILE *out, const char **tab, int num, const char *info)
}
fprintf(out, "\n");
}
//
// Write Unicode symbol to file.
// Convert to UTF-8 encoding:
// 00000000.0xxxxxxx -> 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);
}
}

5
util.h
View File

@ -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);

View File

@ -328,8 +328,7 @@ static void print_unicode(FILE *out, const uint16_t *text, unsigned nchars, int
unsigned i;
for (i=0; i<nchars && *text; i++) {
//TODO: convert to utf8
putc(*text++, out);
putc_utf8(*text++, out);
}
if (fill_flag) {
for (; i<nchars; i++) {
@ -1144,7 +1143,7 @@ badtx: fprintf(stderr, "Bad transmit frequency.\n");
if (! is_valid_frequency(tx_mhz))
goto badtx;
//TODO
//TODO: parse CTSS/DCS tone
tmode = 0;
if (strcasecmp("High", power_str) == 0) {