FreeCalypso > hg > fc-sim-tools
changeset 68:c5e7c9e1d857
GSM7 to qstring decoding: rework in a new way, emit \E for Euro
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 25 Mar 2021 00:04:08 +0000 |
parents | 1b905e730abd |
children | 4c475732660b |
files | libutil/gsm7_decode.c |
diffstat | 1 files changed, 34 insertions(+), 40 deletions(-) [+] |
line wrap: on
line diff
--- a/libutil/gsm7_decode.c Wed Mar 24 23:30:14 2021 +0000 +++ b/libutil/gsm7_decode.c Thu Mar 25 00:04:08 2021 +0000 @@ -1,39 +1,41 @@ /* - * This module contains functions for decoding GSM7 strings - * that exist in various SIM files. + * This module implements a function for decoding GSM7 strings + * to ASCII with output to a stdio file; it is an implementation + * of lossless conversion per our SIM-data-formats spec + * in freecalypso-docs. */ #include <sys/types.h> #include <stdio.h> -static char gsm7_decode_table[128] = { - '@', 0, '$', 0, 0, 0, 0, 0, - 0, 0, '\n', 0, 0, '\r', 0, 0, - 0, '_', 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, - ' ', '!', '"', '#', 0, '%', '&', 0x27, - '(', ')', '*', '+', ',', '-', '.', '/', - '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', ':', ';', '<', '=', '>', '?', - 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', - 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', - 'X', 'Y', 'Z', 0, 0, 0, 0, 0, - 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', - 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', - 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', - 'x', 'y', 'z', 0, 0, 0, 0, 0 +static char basic_table[128] = { + '@', 0, '$', 0, 0, 0, 0, 0, + 0, 0, 'n'|0x80, 0, 0, 'r'|0x80, 0, 0, + 0, '_', 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, + ' ', '!', '"'|0x80, '#', 0, '%', '&', 0x27, + '(', ')', '*', '+', ',', '-', '.', '/', + '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', ':', ';', '<', '=', '>', '?', + 0, 'A', 'B', 'C', 'D', 'E', 'F', 'G', + 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', + 'X', 'Y', 'Z', 0, 0, 0, 0, 0, + 0, 'a', 'b', 'c', 'd', 'e', 'f', 'g', + 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', + 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', + 'x', 'y', 'z', 0, 0, 0, 0, 0 }; -static char gsm7ext_decode_table[128] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, '^', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, '{', '}', 0, 0, 0, 0, 0, '\\', - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[', '~', ']', 0, - '|', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 +static char escape_table[128] = { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, '^', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, '{', '}', 0, 0, 0, 0, 0, '\\'|0x80, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, '[', '~', ']', 0, + '|', 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0,'E'|0x80,0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; void @@ -58,30 +60,22 @@ continue; } b = *dp++; - c = gsm7ext_decode_table[b]; + c = escape_table[b]; if (!c) { fprintf(outf, "\\e\\%02X", b); continue; } } else { - c = gsm7_decode_table[b]; + c = basic_table[b]; if (!c) { fprintf(outf, "\\%02X", b); continue; } } - if (c == '\n') { + if (c & 0x80) { putc('\\', outf); - putc('n', outf); - continue; + c &= 0x7F; } - if (c == '\r') { - putc('\\', outf); - putc('r', outf); - continue; - } - if (c == '"' || c == '\\') - putc('\\', outf); putc(c, outf); } putc('"', outf);