From bc07766ad26cf20be629c428a61fa338a061f69a Mon Sep 17 00:00:00 2001 From: sinikang Date: Wed, 5 Sep 2018 14:54:38 +0900 Subject: [PATCH] Rmove a duplicate code Change-Id: Ib299114671029c8fb2616f0bbe35ecf08f63131e --- packaging/libtcore.spec | 2 +- src/util.c | 51 +++---------------------------------------------- 2 files changed, 4 insertions(+), 49 deletions(-) diff --git a/packaging/libtcore.spec b/packaging/libtcore.spec index f3a9443..9fcac00 100644 --- a/packaging/libtcore.spec +++ b/packaging/libtcore.spec @@ -1,6 +1,6 @@ %define major 0 %define minor 3 -%define patchlevel 27 +%define patchlevel 28 Name: libtcore Version: %{major}.%{minor}.%{patchlevel} diff --git a/src/util.c b/src/util.c index d033126..9b772af 100644 --- a/src/util.c +++ b/src/util.c @@ -1635,55 +1635,10 @@ unsigned char *tcore_util_unpack_gsm7bit_ex(const unsigned char *src, unsigned i unsigned char *tcore_util_unpack_gsm7bit(const unsigned char *src, unsigned int src_len) { unsigned char *dest; - int i = 0, j = 0; - unsigned int pos = 0; - unsigned char shift = 0; - int outlen = 0; - - if (!src || src_len == 0) - return NULL; - - outlen = (src_len * 8) / 7; - - dest = calloc(1, outlen + 1); - if (!dest) - return NULL; - - for (i = 0; pos < src_len; i++, pos++) { - dest[i] = (src[pos] << shift) & 0x7F; - - if (pos != 0) { - /* - * except the first byte, a character contains some bits - * from the previous byte. - */ - dest[i] |= src[pos - 1] >> (8 - shift); - } - - shift++; - - if (shift == 7) { - shift = 0; - - /* a possible extra complete character is available */ - i++; - dest[i] = src[pos] >> 1; - } - } - - /* If a character is '\r'(13), change it to space(32) */ - for (i = 0, j = 0; i < outlen; i++, j++) { - if (dest[i] == '\r') - dest[j] = ' '; - else if (dest[i] == 0x1B) /* If a charater is 0x1B (escape), next charater is changed on gsm 7bit extension table */ - dest[j] = _convert_gsm7bit_extension(dest[++i]); - else - dest[j] = dest[i]; - } - - outlen -= (i - j); + unsigned int outlen = 0; - dest[outlen] = '\0'; + dest = tcore_util_unpack_gsm7bit_ex(src, src_len, &outlen); + info("length of unpacked data = %d", outlen); return dest; } -- 2.7.4