# HG changeset patch # User Mychaela Falconia # Date 1616630648 0 # Node ID c5e7c9e1d857ba8deb448445e37b528c9153cc8a # Parent 1b905e730abdfd1d2b37e768a09d6c4b8f1c0cdc GSM7 to qstring decoding: rework in a new way, emit \E for Euro diff -r 1b905e730abd -r c5e7c9e1d857 libutil/gsm7_decode.c --- 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 #include -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);