# HG changeset patch # User Mychaela Falconia # Date 1616635588 0 # Node ID f023a1c187a9875cf7d82e3ae27fc0adf376b695 # Parent ccaa1319740c873b1133acafe85df722d70f157a uptools/libcoding: import print_gsm7_string_to_file() function from fc-sim-tools diff -r ccaa1319740c -r f023a1c187a9 uptools/libcoding/Makefile --- a/uptools/libcoding/Makefile Mon Mar 22 00:24:34 2021 +0000 +++ b/uptools/libcoding/Makefile Thu Mar 25 01:26:28 2021 +0000 @@ -1,10 +1,11 @@ CC= gcc CFLAGS= -O2 OBJS= alpha_addr.o decode_helpers.o grokdcs.o gsm7_decode.o \ - gsm7_decode_tables.o gsm7_encode.o gsm7_encode_table.o gsm7_pack.o \ - gsm7_unpack.o gsmtime.o hexdecode.o hexdump.o hexencode.o \ - number_decode.o number_encode.o scaddr.o sms_submit.o sms_submit8.o \ - ucs2_bigend.o ucs2_decode.o utf8_decode.o utf8_decode2.o + gsm7_decode_qstring.o gsm7_decode_tables.o gsm7_encode.o \ + gsm7_encode_table.o gsm7_pack.o gsm7_unpack.o gsmtime.o hexdecode.o \ + hexdump.o hexencode.o number_decode.o number_encode.o scaddr.o \ + sms_submit.o sms_submit8.o ucs2_bigend.o ucs2_decode.o utf8_decode.o \ + utf8_decode2.o LIB= libcoding.a all: ${LIB} diff -r ccaa1319740c -r f023a1c187a9 uptools/libcoding/gsm7_decode_qstring.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uptools/libcoding/gsm7_decode_qstring.c Thu Mar 25 01:26:28 2021 +0000 @@ -0,0 +1,82 @@ +/* + * 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 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 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 +print_gsm7_string_to_file(data, nbytes, outf) + u_char *data; + unsigned nbytes; + FILE *outf; +{ + u_char *dp, *endp; + int b, c; + + dp = data; + endp = data + nbytes; + putc('"', outf); + while (dp < endp) { + b = *dp++; + if (b == 0x1B) { + if (dp >= endp || *dp == 0x1B || *dp == '\n' || + *dp == '\r') { + putc('\\', outf); + putc('e', outf); + continue; + } + b = *dp++; + c = escape_table[b]; + if (!c) { + fprintf(outf, "\\e\\%02X", b); + continue; + } + } else { + c = basic_table[b]; + if (!c) { + fprintf(outf, "\\%02X", b); + continue; + } + } + if (c & 0x80) { + putc('\\', outf); + c &= 0x7F; + } + putc(c, outf); + } + putc('"', outf); +}