diff options
| author | Paul Fisher | 1999-02-07 23:58:09 +0000 |
|---|---|---|
| committer | Paul Fisher | 1999-02-07 23:58:09 +0000 |
| commit | 9a092df0810107a9a572edf1f7835fec3f01a003 (patch) | |
| tree | 91261583d7b4c55b7b521945159f94ce8ae6e426 /src | |
| parent | 4d24213703a612dad8a7deef3db57e2f049705e6 (diff) | |
| download | emacs-9a092df0810107a9a572edf1f7835fec3f01a003.tar.gz emacs-9a092df0810107a9a572edf1f7835fec3f01a003.zip | |
(IS_BASE64_IGNORABLE, READ_QUADRUPLET_BYTE): New macros.
(base64_decode_1): Use READ_QUADRUPLET_BYTE.
Diffstat (limited to 'src')
| -rw-r--r-- | src/fns.c | 55 |
1 files changed, 25 insertions, 30 deletions
| @@ -2762,6 +2762,21 @@ ARGS are passed as extra arguments to the function.") | |||
| 2762 | ((Character) < 128) | 2762 | ((Character) < 128) |
| 2763 | #define IS_BASE64(Character) \ | 2763 | #define IS_BASE64(Character) \ |
| 2764 | (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) | 2764 | (IS_ASCII (Character) && base64_char_to_value[Character] >= 0) |
| 2765 | #define IS_BASE64_IGNORABLE(Character) \ | ||
| 2766 | ((Character) == ' ' || (Character) == '\t' || (Character) == '\n' \ | ||
| 2767 | || (Character) == '\f' || (Character) == '\r') | ||
| 2768 | |||
| 2769 | /* Used by base64_decode_1 to retrieve a non-base64-ignorable | ||
| 2770 | character or return retval if there are no characters left to | ||
| 2771 | process. */ | ||
| 2772 | #define READ_QUADRUPLET_BYTE(retval) \ | ||
| 2773 | do \ | ||
| 2774 | { \ | ||
| 2775 | if (i == length) \ | ||
| 2776 | return (retval); \ | ||
| 2777 | c = from[i++]; \ | ||
| 2778 | } \ | ||
| 2779 | while (IS_BASE64_IGNORABLE (c)) | ||
| 2765 | 2780 | ||
| 2766 | /* Don't use alloca for regions larger than this, lest we overflow | 2781 | /* Don't use alloca for regions larger than this, lest we overflow |
| 2767 | their stack. */ | 2782 | their stack. */ |
| @@ -3095,29 +3110,16 @@ base64_decode_1 (from, to, length) | |||
| 3095 | char *to; | 3110 | char *to; |
| 3096 | int length; | 3111 | int length; |
| 3097 | { | 3112 | { |
| 3098 | int counter = 0, i = 0; | 3113 | int i = 0; |
| 3099 | char *e = to; | 3114 | char *e = to; |
| 3100 | unsigned char c; | 3115 | unsigned char c; |
| 3101 | unsigned long value; | 3116 | unsigned long value; |
| 3102 | 3117 | ||
| 3103 | while (i < length) | 3118 | while (1) |
| 3104 | { | 3119 | { |
| 3105 | /* Accept wrapping lines, reversibly if at each 76 characters. */ | 3120 | /* Process first byte of a quadruplet. */ |
| 3106 | |||
| 3107 | c = from[i++]; | ||
| 3108 | if (c == '\n') | ||
| 3109 | { | ||
| 3110 | if (i == length) | ||
| 3111 | break; | ||
| 3112 | c = from[i++]; | ||
| 3113 | if (i == length) | ||
| 3114 | break; | ||
| 3115 | counter = 1; | ||
| 3116 | } | ||
| 3117 | else | ||
| 3118 | counter++; | ||
| 3119 | 3121 | ||
| 3120 | /* Process first byte of a quadruplet. */ | 3122 | READ_QUADRUPLET_BYTE (e-to); |
| 3121 | 3123 | ||
| 3122 | if (!IS_BASE64 (c)) | 3124 | if (!IS_BASE64 (c)) |
| 3123 | return -1; | 3125 | return -1; |
| @@ -3125,9 +3127,7 @@ base64_decode_1 (from, to, length) | |||
| 3125 | 3127 | ||
| 3126 | /* Process second byte of a quadruplet. */ | 3128 | /* Process second byte of a quadruplet. */ |
| 3127 | 3129 | ||
| 3128 | if (i == length) | 3130 | READ_QUADRUPLET_BYTE (-1); |
| 3129 | return -1; | ||
| 3130 | c = from[i++]; | ||
| 3131 | 3131 | ||
| 3132 | if (!IS_BASE64 (c)) | 3132 | if (!IS_BASE64 (c)) |
| 3133 | return -1; | 3133 | return -1; |
| @@ -3136,14 +3136,13 @@ base64_decode_1 (from, to, length) | |||
| 3136 | *e++ = (unsigned char) (value >> 16); | 3136 | *e++ = (unsigned char) (value >> 16); |
| 3137 | 3137 | ||
| 3138 | /* Process third byte of a quadruplet. */ | 3138 | /* Process third byte of a quadruplet. */ |
| 3139 | 3139 | ||
| 3140 | if (i == length) | 3140 | READ_QUADRUPLET_BYTE (-1); |
| 3141 | return -1; | ||
| 3142 | c = from[i++]; | ||
| 3143 | 3141 | ||
| 3144 | if (c == '=') | 3142 | if (c == '=') |
| 3145 | { | 3143 | { |
| 3146 | c = from[i++]; | 3144 | READ_QUADRUPLET_BYTE (-1); |
| 3145 | |||
| 3147 | if (c != '=') | 3146 | if (c != '=') |
| 3148 | return -1; | 3147 | return -1; |
| 3149 | continue; | 3148 | continue; |
| @@ -3157,9 +3156,7 @@ base64_decode_1 (from, to, length) | |||
| 3157 | 3156 | ||
| 3158 | /* Process fourth byte of a quadruplet. */ | 3157 | /* Process fourth byte of a quadruplet. */ |
| 3159 | 3158 | ||
| 3160 | if (i == length) | 3159 | READ_QUADRUPLET_BYTE (-1); |
| 3161 | return -1; | ||
| 3162 | c = from[i++]; | ||
| 3163 | 3160 | ||
| 3164 | if (c == '=') | 3161 | if (c == '=') |
| 3165 | continue; | 3162 | continue; |
| @@ -3170,8 +3167,6 @@ base64_decode_1 (from, to, length) | |||
| 3170 | 3167 | ||
| 3171 | *e++ = (unsigned char) (0xff & value); | 3168 | *e++ = (unsigned char) (0xff & value); |
| 3172 | } | 3169 | } |
| 3173 | |||
| 3174 | return e - to; | ||
| 3175 | } | 3170 | } |
| 3176 | 3171 | ||
| 3177 | void | 3172 | void |