From 305940a1a9430c381d04dc181f61123fa80ab74f Mon Sep 17 00:00:00 2001 From: François Revel Date: Sat, 29 Nov 2008 23:26:03 +0000 Subject: C89 svn path=/trunk/libparserutils/; revision=5839 --- src/charset/aliases.c | 4 ++-- src/charset/codecs/codec_8859.c | 14 +++++++++----- src/charset/codecs/codec_ascii.c | 6 ++++-- src/charset/codecs/codec_ext8.c | 14 +++++++++----- src/charset/codecs/codec_utf8.c | 6 ++++-- src/charset/encodings/utf8impl.h | 8 +++++--- 6 files changed, 33 insertions(+), 19 deletions(-) diff --git a/src/charset/aliases.c b/src/charset/aliases.c index a720950..a34ef6f 100644 --- a/src/charset/aliases.c +++ b/src/charset/aliases.c @@ -270,11 +270,11 @@ bool parserutils_charset_mibenum_is_unicode(uint16_t mibenum) */ int aliascmp(const char *s1, const char *s2, size_t s2_len) { + size_t s2_pos = 0; + if (s1 == NULL || s2_len == 0) return 1; - size_t s2_pos = 0; - while (true) { while (IS_PUNCT_OR_SPACE(*s1)) s1++; diff --git a/src/charset/codecs/codec_8859.c b/src/charset/codecs/codec_8859.c index c04eb87..b76a2c7 100644 --- a/src/charset/codecs/codec_8859.c +++ b/src/charset/codecs/codec_8859.c @@ -101,11 +101,12 @@ static inline parserutils_error charset_8859_to_ucs4(charset_8859_codec *c, */ bool charset_8859_codec_handles_charset(const char *charset) { + uint32_t i; uint16_t match = parserutils_charset_mibenum_from_name(charset, strlen(charset)); if (known_charsets[0].mib == 0) { - for (uint32_t i = 0; i < N_ELEMENTS(known_charsets); i++) { + for (i = 0; i < N_ELEMENTS(known_charsets); i++) { known_charsets[i].mib = parserutils_charset_mibenum_from_name( known_charsets[i].name, @@ -113,7 +114,7 @@ bool charset_8859_codec_handles_charset(const char *charset) } } - for (uint32_t i = 0; i < N_ELEMENTS(known_charsets); i++) { + for (i = 0; i < N_ELEMENTS(known_charsets); i++) { if (known_charsets[i].mib == match) return true; } @@ -136,12 +137,13 @@ parserutils_error charset_8859_codec_create(const char *charset, parserutils_alloc alloc, void *pw, parserutils_charset_codec **codec) { + uint32_t i; charset_8859_codec *c; uint16_t match = parserutils_charset_mibenum_from_name( charset, strlen(charset)); uint32_t *table = NULL; - for (uint32_t i = 0; i < N_ELEMENTS(known_charsets); i++) { + for (i = 0; i < N_ELEMENTS(known_charsets); i++) { if (known_charsets[i].mib == match) { table = known_charsets[i].table; break; @@ -231,9 +233,10 @@ parserutils_error charset_8859_codec_encode(parserutils_charset_codec *codec, error = charset_8859_from_ucs4(c, pwrite[0], dest, destlen); if (error != PARSERUTILS_OK) { + uint32_t len; assert(error == PARSERUTILS_NOMEM); - for (uint32_t len = 0; + for (len = 0; len < c->write_len; len++) { c->write_buf[len] = pwrite[len]; } @@ -257,6 +260,7 @@ parserutils_error charset_8859_codec_encode(parserutils_charset_codec *codec, error = charset_8859_from_ucs4(c, towrite[0], dest, destlen); if (error != PARSERUTILS_OK) { + uint32_t len; if (error != PARSERUTILS_NOMEM) { return error; } @@ -269,7 +273,7 @@ parserutils_error charset_8859_codec_encode(parserutils_charset_codec *codec, /* Copy pending chars to save area, for * processing next call. */ - for (uint32_t len = 0; len < towritelen; len++) + for (len = 0; len < towritelen; len++) c->write_buf[len] = towrite[len]; /* Claim character we've just buffered, diff --git a/src/charset/codecs/codec_ascii.c b/src/charset/codecs/codec_ascii.c index 944d354..eb7d66e 100644 --- a/src/charset/codecs/codec_ascii.c +++ b/src/charset/codecs/codec_ascii.c @@ -187,9 +187,10 @@ parserutils_error charset_ascii_codec_encode(parserutils_charset_codec *codec, error = charset_ascii_from_ucs4(c, pwrite[0], dest, destlen); if (error != PARSERUTILS_OK) { + uint32_t len; assert(error == PARSERUTILS_NOMEM); - for (uint32_t len = 0; + for (len = 0; len < c->write_len; len++) { c->write_buf[len] = pwrite[len]; } @@ -213,6 +214,7 @@ parserutils_error charset_ascii_codec_encode(parserutils_charset_codec *codec, error = charset_ascii_from_ucs4(c, towrite[0], dest, destlen); if (error != PARSERUTILS_OK) { + uint32_t len; if (error != PARSERUTILS_NOMEM) { return error; } @@ -225,7 +227,7 @@ parserutils_error charset_ascii_codec_encode(parserutils_charset_codec *codec, /* Copy pending chars to save area, for * processing next call. */ - for (uint32_t len = 0; len < towritelen; len++) + for (len = 0; len < towritelen; len++) c->write_buf[len] = towrite[len]; /* Claim character we've just buffered, diff --git a/src/charset/codecs/codec_ext8.c b/src/charset/codecs/codec_ext8.c index 1f12fea..5151e5f 100644 --- a/src/charset/codecs/codec_ext8.c +++ b/src/charset/codecs/codec_ext8.c @@ -95,11 +95,12 @@ static inline parserutils_error charset_ext8_to_ucs4(charset_ext8_codec *c, */ bool charset_ext8_codec_handles_charset(const char *charset) { + uint32_t i; uint16_t match = parserutils_charset_mibenum_from_name(charset, strlen(charset)); if (known_charsets[0].mib == 0) { - for (uint32_t i = 0; i < N_ELEMENTS(known_charsets); i++) { + for (i = 0; i < N_ELEMENTS(known_charsets); i++) { known_charsets[i].mib = parserutils_charset_mibenum_from_name( known_charsets[i].name, @@ -107,7 +108,7 @@ bool charset_ext8_codec_handles_charset(const char *charset) } } - for (uint32_t i = 0; i < N_ELEMENTS(known_charsets); i++) { + for (i = 0; i < N_ELEMENTS(known_charsets); i++) { if (known_charsets[i].mib == match) return true; } @@ -130,12 +131,13 @@ parserutils_error charset_ext8_codec_create(const char *charset, parserutils_alloc alloc, void *pw, parserutils_charset_codec **codec) { + uint32_t i; charset_ext8_codec *c; uint16_t match = parserutils_charset_mibenum_from_name( charset, strlen(charset)); uint32_t *table = NULL; - for (uint32_t i = 0; i < N_ELEMENTS(known_charsets); i++) { + for (i = 0; i < N_ELEMENTS(known_charsets); i++) { if (known_charsets[i].mib == match) { table = known_charsets[i].table; break; @@ -225,9 +227,10 @@ parserutils_error charset_ext8_codec_encode(parserutils_charset_codec *codec, error = charset_ext8_from_ucs4(c, pwrite[0], dest, destlen); if (error != PARSERUTILS_OK) { + uint32_t len; assert(error == PARSERUTILS_NOMEM); - for (uint32_t len = 0; + for (len = 0; len < c->write_len; len++) { c->write_buf[len] = pwrite[len]; } @@ -251,6 +254,7 @@ parserutils_error charset_ext8_codec_encode(parserutils_charset_codec *codec, error = charset_ext8_from_ucs4(c, towrite[0], dest, destlen); if (error != PARSERUTILS_OK) { + uint32_t len; if (error != PARSERUTILS_NOMEM) { return error; } @@ -263,7 +267,7 @@ parserutils_error charset_ext8_codec_encode(parserutils_charset_codec *codec, /* Copy pending chars to save area, for * processing next call. */ - for (uint32_t len = 0; len < towritelen; len++) + for (len = 0; len < towritelen; len++) c->write_buf[len] = towrite[len]; /* Claim character we've just buffered, diff --git a/src/charset/codecs/codec_utf8.c b/src/charset/codecs/codec_utf8.c index f39b8bb..f9cd00a 100644 --- a/src/charset/codecs/codec_utf8.c +++ b/src/charset/codecs/codec_utf8.c @@ -182,11 +182,12 @@ parserutils_error charset_utf8_codec_encode(parserutils_charset_codec *codec, while (c->write_len > 0) { UTF8_FROM_UCS4(pwrite[0], dest, destlen, error); if (error != PARSERUTILS_OK) { + uint32_t len; if (error != PARSERUTILS_NOMEM) abort(); /* Insufficient output buffer space */ - for (uint32_t len = 0; + for (len = 0; len < c->write_len; len++) { c->write_buf[len] = pwrite[len]; } @@ -209,6 +210,7 @@ parserutils_error charset_utf8_codec_encode(parserutils_charset_codec *codec, while (towritelen > 0) { UTF8_FROM_UCS4(towrite[0], dest, destlen, error); if (error != PARSERUTILS_OK) { + uint32_t len; if (error != PARSERUTILS_NOMEM) abort(); @@ -220,7 +222,7 @@ parserutils_error charset_utf8_codec_encode(parserutils_charset_codec *codec, /* Copy pending chars to save area, for * processing next call. */ - for (uint32_t len = 0; len < towritelen; len++) + for (len = 0; len < towritelen; len++) c->write_buf[len] = towrite[len]; /* Claim character we've just buffered, diff --git a/src/charset/encodings/utf8impl.h b/src/charset/encodings/utf8impl.h index b1721c7..45707aa 100644 --- a/src/charset/encodings/utf8impl.h +++ b/src/charset/encodings/utf8impl.h @@ -35,6 +35,7 @@ extern const uint8_t numContinuations[256]; do { \ uint32_t c, min; \ uint8_t n; \ + uint8_t i; \ \ error = PARSERUTILS_OK; \ \ @@ -83,7 +84,7 @@ do { \ break; \ } \ \ - for (uint8_t i = 1; i < n; i++) { \ + for (i = 1; i < n; i++) { \ uint32_t t = s[i]; \ \ if ((t & 0xC0) != 0x80) { \ @@ -157,8 +158,9 @@ do { \ \ if (l == 1) { \ buf[0] = (uint8_t) ucs4; \ - } else { \ - for (uint8_t i = l; i > 1; i--) { \ + } else { \ + uint8_t i; \ + for (i = l; i > 1; i--) { \ buf[i - 1] = 0x80 | (ucs4 & 0x3F); \ ucs4 >>= 6; \ } \ -- cgit v1.2.3