diff options
author | Michal Čihař <nijel@debian.org> | 2016-10-18 14:37:06 +0200 |
---|---|---|
committer | Michal Čihař <nijel@debian.org> | 2016-10-18 14:37:06 +0200 |
commit | 85b8cdaaa4870f65a24fae9b195b79807520099f (patch) | |
tree | 2c73fbe5d06ddeb6258d9378490d3b6f975a4b88 /libgammu/misc/coding/coding.c | |
parent | 69153b508b7834038c9be40e4e8b7e87a35345a1 (diff) |
New upstream version 1.37.90
Diffstat (limited to 'libgammu/misc/coding/coding.c')
-rw-r--r-- | libgammu/misc/coding/coding.c | 74 |
1 files changed, 39 insertions, 35 deletions
diff --git a/libgammu/misc/coding/coding.c b/libgammu/misc/coding/coding.c index e1b3a25..28f9f2e 100644 --- a/libgammu/misc/coding/coding.c +++ b/libgammu/misc/coding/coding.c @@ -279,9 +279,9 @@ char *DecodeUnicodeConsole(const unsigned char *src) } /* Encode string to Unicode. Len is number of input chars */ -void DecodeISO88591 (unsigned char *dest, const char *src, int len) +void DecodeISO88591 (unsigned char *dest, const char *src, size_t len) { - int i; + size_t i; for (i = 0; i < len; i++) { /* Hack for Euro sign */ @@ -298,9 +298,9 @@ void DecodeISO88591 (unsigned char *dest, const char *src, int len) } /* Encode string to Unicode. Len is number of input chars */ -void EncodeUnicode (unsigned char *dest, const char *src, int len) +void EncodeUnicode (unsigned char *dest, const char *src, size_t len) { - int i_len = 0, o_len; + size_t i_len = 0, o_len; wchar_t wc; for (o_len = 0; i_len < len; o_len++) { @@ -325,9 +325,10 @@ int DecodeWithBCDAlphabet(unsigned char value) return 10*(value & 0x0f)+(value >> 4); } -void DecodeBCD (unsigned char *dest, const unsigned char *src, int len) +void DecodeBCD (unsigned char *dest, const unsigned char *src, size_t len) { - int i,current=0,digit; + size_t i,current=0; + int digit; for (i = 0; i < len; i++) { digit=src[i] & 0x0f; @@ -338,9 +339,9 @@ void DecodeBCD (unsigned char *dest, const unsigned char *src, int len) dest[current]=0; } -void EncodeBCD (unsigned char *dest, const unsigned char *src, int len, gboolean fill) +void EncodeBCD (unsigned char *dest, const unsigned char *src, size_t len, gboolean fill) { - int i,current=0; + size_t i,current=0; for (i = 0; i < len; i++) { if (i & 0x01) { @@ -407,9 +408,10 @@ void EncodeHexUnicode (char *dest, const unsigned char *src, size_t len) EncodeHexBin(dest, src, len * 2); } -gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, int len) +gboolean DecodeHexBin (unsigned char *dest, const unsigned char *src, size_t len) { - int i,current=0, low, high; + size_t i,current=0; + int low, high; for (i = 0; i < len/2 ; i++) { low = DecodeWithHexBinAlphabet(src[i*2+1]); @@ -828,7 +830,8 @@ static unsigned char ConvertTable[] = void EncodeDefault(unsigned char *dest, const unsigned char *src, size_t *len, gboolean UseExtensions, unsigned char *ExtraAlphabet) { - size_t i,current=0,j,z; + size_t i,current=0; + int j,z; char ret; gboolean FoundSpecial,FoundNormal; @@ -947,7 +950,7 @@ void FindDefaultAlphabetLen(const unsigned char *src, size_t *srclen, size_t *sm #define ByteMask ((1 << Bits) - 1) -int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length, +int GSM_UnpackEightBitsToSeven(size_t offset, size_t in_length, size_t out_length, const unsigned char *input, unsigned char *output) { /* (c) by Pavel Janik and Pawel Kot */ @@ -955,11 +958,11 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length, unsigned char *output_pos = output; /* Current pointer to the output buffer */ const unsigned char *input_pos = input; /* Current pointer to the input buffer */ unsigned char Rest = 0x00; - int Bits; + size_t Bits; Bits = offset ? offset : 7; - while ((input_pos - input) < in_length) { + while ((size_t)(input_pos - input) < in_length) { *output_pos = ((*input_pos & ByteMask) << (7 - Bits)) | Rest; Rest = *input_pos >> Bits; @@ -970,7 +973,7 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length, if ((input_pos != input) || (Bits == 7)) output_pos++; input_pos++; - if ((output_pos - output) >= out_length) break; + if ((size_t)(output_pos - output) >= out_length) break; /* After reading 7 octets we have read 7 full characters but we have 7 bits as well. This is the next character */ @@ -987,7 +990,7 @@ int GSM_UnpackEightBitsToSeven(int offset, int in_length, int out_length, return output_pos - output; } -int GSM_PackSevenBitsToEight(int offset, const unsigned char *input, unsigned char *output, int length) +int GSM_PackSevenBitsToEight(size_t offset, const unsigned char *input, unsigned char *output, size_t length) { /* (c) by Pavel Janik and Pawel Kot */ @@ -1004,7 +1007,7 @@ int GSM_PackSevenBitsToEight(int offset, const unsigned char *input, unsigned ch output_pos++; } - while ((input_pos - input) < length) { + while ((size_t)(input_pos - input) < length) { unsigned char Byte = *input_pos; *output_pos = Byte >> (7 - Bits); @@ -1242,12 +1245,12 @@ void ReadUnicodeFile(unsigned char *Dest, const unsigned char *Source) Dest[current] = 0; } -INLINE int GetBit(unsigned char *Buffer, size_t BitNum) +int GetBit(unsigned char *Buffer, size_t BitNum) { return Buffer[BitNum / 8] & (1 << (7 - (BitNum % 8))); } -INLINE int SetBit(unsigned char *Buffer, size_t BitNum) +int SetBit(unsigned char *Buffer, size_t BitNum) { return Buffer[BitNum / 8] |= 1 << (7 - (BitNum % 8)); } @@ -1361,9 +1364,9 @@ void GetBufferI(unsigned char *Source, * We replace single ~ chars into it. When user give double ~, it's replaced * to single ~ */ -void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len) +void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len) { - int i,current = 0; + size_t i,current = 0; gboolean special=FALSE; for (i = 0; i < len; i++) { @@ -1395,9 +1398,9 @@ void EncodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *sr dest[current] = 0x00; } -void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, int len) +void DecodeUnicodeSpecialNOKIAChars(unsigned char *dest, const unsigned char *src, size_t len) { - int i=0,current=0; + size_t i=0,current=0; for (i=0;i<len;i++) { switch (src[2*i]) { @@ -1860,7 +1863,7 @@ gboolean EncodeUTF8(char *dest, const unsigned char *src) } /* Decode UTF8 char to Unicode char */ -int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, int len) +int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, size_t len) { if (len < 1) return 0; if (src[0] < 128) { @@ -1883,9 +1886,9 @@ int DecodeWithUTF8Alphabet(const unsigned char *src, wchar_t *dest, int len) /* Make Unicode string from ISO-8859-1 string */ -void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, int len) +void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src, size_t len) { - int i = 0, j = 0; + size_t i = 0, j = 0; while (i < len) { if (src[i] == '=' && i + 2 < len @@ -1905,9 +1908,10 @@ void DecodeISO88591QuotedPrintable(unsigned char *dest, const unsigned char *src } /* Make Unicode string from UTF8 string */ -void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, int len) +void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, size_t len) { - int i,j=0,z; + size_t i,j=0; + int z; unsigned char mychar[10]; wchar_t ret; @@ -1940,9 +1944,9 @@ void DecodeUTF8QuotedPrintable(unsigned char *dest, const char *src, int len) dest[j] = 0; } -void DecodeUTF8(unsigned char *dest, const char *src, int len) +void DecodeUTF8(unsigned char *dest, const char *src, size_t len) { - int i=0,j=0,z; + size_t i=0,j=0,z; wchar_t ret; while (i < len) { @@ -1959,13 +1963,13 @@ void DecodeUTF8(unsigned char *dest, const char *src, int len) dest[j] = 0; } -void DecodeXMLUTF8(unsigned char *dest, const char *src, int len) +void DecodeXMLUTF8(unsigned char *dest, const char *src, size_t len) { char *tmp; char *pos, *pos_end; const char *lastpos; char *entity; - unsigned long int c; + unsigned long long int c; int tmplen; /* Allocate buffer */ @@ -2015,7 +2019,7 @@ void DecodeXMLUTF8(unsigned char *dest, const char *src, int len) } else { c = strtoull(entity + 1, NULL, 10); } - dbgprintf(NULL, "Unicode char 0x%04lx\n", c); + dbgprintf(NULL, "Unicode char 0x%04llx\n", c); tmplen = strlen(tmp); tmplen += EncodeWithUTF8Alphabet(c, tmp + tmplen); tmp[tmplen] = 0; @@ -2044,9 +2048,9 @@ void DecodeXMLUTF8(unsigned char *dest, const char *src, int len) tmp=NULL; } -void DecodeUTF7(unsigned char *dest, const unsigned char *src, int len) +void DecodeUTF7(unsigned char *dest, const unsigned char *src, size_t len) { - int i=0,j=0,z,p; + size_t i=0,j=0,z,p; wchar_t ret; while (i<=len) { |