FreeCalypso > hg > sms-coding-utils
diff libcoding/gsm7_encode.c @ 23:e56bb9f09ff1
sms-encode-text: port over -e option from fcup-smsend
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sat, 02 Sep 2023 19:22:05 +0000 (21 months ago) |
parents | 2d0082216916 |
children |
line wrap: on
line diff
--- a/libcoding/gsm7_encode.c Thu Aug 31 23:03:38 2023 +0000 +++ b/libcoding/gsm7_encode.c Sat Sep 02 19:22:05 2023 +0000 @@ -4,10 +4,40 @@ */ #include <sys/types.h> +#include <ctype.h> extern u_char gsm7_encode_table[256]; -latin1_to_gsm7(inbuf, outbuf, outmax, outlenp) +static unsigned +handle_escape(ipp) + u_char **ipp; +{ + unsigned c; + + c = *(*ipp)++; + if (c >= '0' && c <= '7' && isxdigit(**ipp)) { + c = ((c - '0') << 4) | decode_hex_digit(*(*ipp)++); + return c; + } + switch (c) { + case 'n': + return '\n'; + case 'r': + return '\r'; + case 'e': + return 0x1B; + case 'E': /* Euro currency symbol */ + return 0xE5; + case '"': + case '\\': + c = gsm7_encode_table[c]; + return c; + default: + return 0xFF; + } +} + +latin1_to_gsm7(inbuf, outbuf, outmax, outlenp, allow_escape) u_char *inbuf, *outbuf; unsigned outmax, *outlenp; { @@ -15,9 +45,15 @@ unsigned outcnt = 0, c, n; while (c = *ip++) { - c = gsm7_encode_table[c]; - if (c == 0xFF) - return(-1); + if (c == '\\' && allow_escape) { + c = handle_escape(&ip); + if (c == 0xFF) + return(-3); + } else { + c = gsm7_encode_table[c]; + if (c == 0xFF) + return(-1); + } if (c & 0x80) n = 2; else