# HG changeset patch # User Mychaela Falconia # Date 1517948323 0 # Node ID dbeb4a5628f5a8902ca332713147faaf7fab6b08 # Parent 8fee530f785035e4ca32a31df89936a02cefefa1 uptools/libcoding: implemented 8859-1 -> GSM7 encoding function diff -r 8fee530f7850 -r dbeb4a5628f5 uptools/libcoding/Makefile --- a/uptools/libcoding/Makefile Tue Feb 06 19:27:19 2018 +0000 +++ b/uptools/libcoding/Makefile Tue Feb 06 20:18:43 2018 +0000 @@ -1,8 +1,8 @@ CC= gcc CFLAGS= -O2 OBJS= alpha_addr.o decode_helpers.o grokdcs.o gsm7_decode.o \ - gsm7_decode_tables.o gsm7_encode_table.o gsm7_unpack.o gsmtime.o \ - hexdecode.o hexdump.o number_decode.o scaddr.o ucs2_decode.o \ + gsm7_decode_tables.o gsm7_encode.o gsm7_encode_table.o gsm7_unpack.o \ + gsmtime.o hexdecode.o hexdump.o number_decode.o scaddr.o ucs2_decode.o \ utf8_decode.o LIB= libcoding.a diff -r 8fee530f7850 -r dbeb4a5628f5 uptools/libcoding/gsm7_encode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uptools/libcoding/gsm7_encode.c Tue Feb 06 20:18:43 2018 +0000 @@ -0,0 +1,35 @@ +/* + * This library module implements the function for encoding from ISO 8859-1 + * into the GSM 7-bit default alphabet (03.38 or 23.038). + */ + +#include + +extern u_char gsm7_encode_table[256]; + +latin1_to_gsm7(inbuf, outbuf, outmax, outlenp) + u_char *inbuf, *outbuf; + unsigned outmax, *outlenp; +{ + u_char *ip = inbuf, *op = outbuf; + unsigned outcnt = 0, c, n; + + while (c = *ip++) { + c = gsm7_encode_table[c]; + if (c == 0xFF) + return(-1); + if (c & 0x80) + n = 2; + else + n = 1; + if (outcnt + n > outmax) + return(-2); + if (c & 0x80) { + *op++ = 0x1B; + *op++ = c & 0x7F; + } else + *op++ = c; + } + *outlenp = outcnt; + return(0); +}