From: Pierre Habouzit Date: Tue, 31 Oct 2006 23:23:46 +0000 (+0100) Subject: push more things in the str lib. X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=commitdiff_plain;h=bec523bb3ad78ec9100efb18fb58d43d38b304de;hp=81884ccb464c69a8dba9de1b97af261a8a02b2c7 push more things in the str lib. remove many duplicated arrays :| Signed-off-by: Pierre Habouzit --- diff --git a/base64.c b/base64.c index df55689..728171b 100644 --- a/base64.c +++ b/base64.c @@ -51,10 +51,10 @@ void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len, size_t olen) { while (len >= 3 && olen > 10) { - *out++ = B64Chars[in[0] >> 2]; - *out++ = B64Chars[((in[0] << 4) & 0x30) | (in[1] >> 4)]; - *out++ = B64Chars[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; - *out++ = B64Chars[in[2] & 0x3f]; + *out++ = __m_b64chars[in[0] >> 2]; + *out++ = __m_b64chars[((in[0] << 4) & 0x30) | (in[1] >> 4)]; + *out++ = __m_b64chars[((in[1] << 2) & 0x3c) | (in[2] >> 6)]; + *out++ = __m_b64chars[in[2] & 0x3f]; olen -= 4; len -= 3; in += 3; @@ -64,12 +64,12 @@ void mutt_to_base64 (unsigned char *out, const unsigned char *in, size_t len, if (len > 0 && olen > 4) { unsigned char fragment; - *out++ = B64Chars[in[0] >> 2]; + *out++ = __m_b64chars[in[0] >> 2]; fragment = (in[0] << 4) & 0x30; if (len > 1) fragment |= in[1] >> 4; - *out++ = B64Chars[fragment]; - *out++ = (len < 2) ? '=' : B64Chars[(in[1] << 2) & 0x3c]; + *out++ = __m_b64chars[fragment]; + *out++ = (len < 2) ? '=' : __m_b64chars[(in[1] << 2) & 0x3c]; *out++ = '='; } *out = '\0'; diff --git a/imap/utf7.c b/imap/utf7.c index 76ea696..e2b3340 100644 --- a/imap/utf7.c +++ b/imap/utf7.c @@ -17,25 +17,6 @@ #include "charset.h" #include "imap_private.h" -static int Index_64[128] = { - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, - -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, 62, 63, -1, -1, -1, - 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, -1, -1, -1, -1, -1, -1, - -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, - 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, -1, -1, -1, -1, -1, - -1, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, - 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, -1, -1, -1, -1, -1 -}; - -static char B64Chars[64] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', - 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '+', ',' -}; - /* * Convert the data (u7,u7len) from RFC 2060's UTF-7 to UTF-8. * The result is null-terminated and returned, and also stored @@ -66,7 +47,7 @@ static char *utf7_to_utf8 (const char *u7, size_t u7len, char **u8, ch = 0; k = 10; for (; u7len; u7++, u7len--) { - if ((*u7 & 0x80) || (b = Index_64[(int) *u7]) == -1) + if ((b = base64val(*u7)) < 0) break; if (k > 0) { ch |= b << k; @@ -185,17 +166,17 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7, } if (ch & ~0xffff) ch = 0xfffe; - *p++ = B64Chars[b | ch >> k]; + *p++ = __m_b64chars[b | ch >> k]; k -= 6; for (; k >= 0; k -= 6) - *p++ = B64Chars[(ch >> k) & 0x3f]; + *p++ = __m_b64chars[(ch >> k) & 0x3f]; b = (ch << (-k)) & 0x3f; k += 16; } else { if (base64) { if (k > 10) - *p++ = B64Chars[b]; + *p++ = __m_b64chars[b]; *p++ = '-'; base64 = 0; } @@ -212,7 +193,7 @@ static char *utf8_to_utf7 (const char *u8, size_t u8len, char **u7, if (base64) { if (k > 10) - *p++ = B64Chars[b]; + *p++ = __m_b64chars[b]; *p++ = '-'; } diff --git a/lib-lib/str.c b/lib-lib/str.c index 6bdc25c..7225483 100644 --- a/lib-lib/str.c +++ b/lib-lib/str.c @@ -46,6 +46,15 @@ signed char const __m_b64digits[128] = { }; #undef XX +char const __m_b64chars[64] = { + 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', + 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', + 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', + 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', + '8', '9', '+', '/' +}; + + ssize_t m_strcpy(char *dst, ssize_t n, const char *src) { ssize_t len = m_strlen(src); diff --git a/lib-lib/str.h b/lib-lib/str.h index 01e6c62..88af4d7 100644 --- a/lib-lib/str.h +++ b/lib-lib/str.h @@ -37,6 +37,7 @@ extern unsigned char const __m_strdigits[128]; extern signed char const __m_b64digits[128]; +extern char const __m_b64chars[64]; /****************************************************************************/ /* char related */ diff --git a/mime.h b/mime.h index d102594..887a4c4 100644 --- a/mime.h +++ b/mime.h @@ -41,10 +41,6 @@ enum { /* MIME encoding/decoding global vars */ -#ifndef _SENDLIB_C -extern char B64Chars[]; -#endif - #define is_multipart(x) \ ((x)->type == TYPEMULTIPART \ || ((x)->type == TYPEMESSAGE && (!strcasecmp((x)->subtype, "rfc822") \ diff --git a/rfc2047.c b/rfc2047.c index d973d26..9ac1cd7 100644 --- a/rfc2047.c +++ b/rfc2047.c @@ -154,24 +154,24 @@ static size_t b_encoder (char *s, const char *d, size_t dlen, if (!dlen) break; else if (dlen == 1) { - *s++ = B64Chars[(*d >> 2) & 0x3f]; - *s++ = B64Chars[(*d & 0x03) << 4]; + *s++ = __m_b64chars[(*d >> 2) & 0x3f]; + *s++ = __m_b64chars[(*d & 0x03) << 4]; *s++ = '='; *s++ = '='; break; } else if (dlen == 2) { - *s++ = B64Chars[(*d >> 2) & 0x3f]; - *s++ = B64Chars[((*d & 0x03) << 4) | ((d[1] >> 4) & 0x0f)]; - *s++ = B64Chars[(d[1] & 0x0f) << 2]; + *s++ = __m_b64chars[(*d >> 2) & 0x3f]; + *s++ = __m_b64chars[((*d & 0x03) << 4) | ((d[1] >> 4) & 0x0f)]; + *s++ = __m_b64chars[(d[1] & 0x0f) << 2]; *s++ = '='; break; } else { - *s++ = B64Chars[(*d >> 2) & 0x3f]; - *s++ = B64Chars[((*d & 0x03) << 4) | ((d[1] >> 4) & 0x0f)]; - *s++ = B64Chars[((d[1] & 0x0f) << 2) | ((d[2] >> 6) & 0x03)]; - *s++ = B64Chars[d[2] & 0x3f]; + *s++ = __m_b64chars[(*d >> 2) & 0x3f]; + *s++ = __m_b64chars[((*d & 0x03) << 4) | ((d[1] >> 4) & 0x0f)]; + *s++ = __m_b64chars[((d[1] & 0x0f) << 2) | ((d[2] >> 6) & 0x03)]; + *s++ = __m_b64chars[d[2] & 0x3f]; d += 3, dlen -= 3; } } diff --git a/sendlib.c b/sendlib.c index 7ec942c..b06696f 100644 --- a/sendlib.c +++ b/sendlib.c @@ -75,14 +75,6 @@ extern char RFC822Specials[]; const char MimeSpecials[] = "@.,;:<>[]\\\"()?/= \t"; -char B64Chars[64] = { - 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', - 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', 'a', 'b', 'c', 'd', - 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', - 't', 'u', 'v', 'w', 'x', 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', - '8', '9', '+', '/' -}; - static char MsgIdPfx = 'A'; static void transform_to_7bit (BODY * a, FILE * fpin); @@ -223,19 +215,19 @@ static void b64_flush (FILE * fout) for (i = b64_num; i < 3; i++) b64_buffer[i] = '\0'; - fputc (B64Chars[(b64_buffer[0] >> 2) & 0x3f], fout); + fputc(__m_b64chars[(b64_buffer[0] >> 2) & 0x3f], fout); b64_linelen++; - fputc (B64Chars + fputc(__m_b64chars [((b64_buffer[0] & 0x3) << 4) | ((b64_buffer[1] >> 4) & 0xf)], fout); b64_linelen++; if (b64_num > 1) { - fputc (B64Chars + fputc (__m_b64chars [((b64_buffer[1] & 0xf) << 2) | ((b64_buffer[2] >> 6) & 0x3)], fout); b64_linelen++; if (b64_num > 2) { - fputc (B64Chars[b64_buffer[2] & 0x3f], fout); + fputc (__m_b64chars[b64_buffer[2] & 0x3f], fout); b64_linelen++; } } @@ -457,7 +449,7 @@ void mutt_generate_boundary (PARAMETER ** parm) rs[BOUNDARYLEN] = 0; for (i = 0; i < BOUNDARYLEN; i++) - *p++ = B64Chars[LRAND () % sizeof (B64Chars)]; + *p++ = __m_b64chars[LRAND() % sizeof(__m_b64chars)]; *p = 0; mutt_set_parameter ("boundary", rs, parm);