Whitespace cleanup

This commit is contained in:
Matthias Clasen 2010-09-03 19:33:11 -04:00
parent 489b780bb9
commit 5d4ef36f91
2 changed files with 121 additions and 121 deletions

View File

@ -10,7 +10,7 @@
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details. * Library General Public License for more details.
* *
* You should have received a copy of the GNU Library General Public * You should have received a copy of the GNU Library General Public
@ -54,7 +54,7 @@
*/ */
static const char base64_alphabet[] = static const char base64_alphabet[] =
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
/** /**
* g_base64_encode_step: * g_base64_encode_step:
@ -66,10 +66,10 @@ static const char base64_alphabet[] =
* @save: Saved state between steps, initialize to 0 * @save: Saved state between steps, initialize to 0
* *
* Incrementally encode a sequence of binary data into its Base-64 stringified * Incrementally encode a sequence of binary data into its Base-64 stringified
* representation. By calling this function multiple times you can convert * representation. By calling this function multiple times you can convert
* data in chunks to avoid having to have the full encoded data in memory. * data in chunks to avoid having to have the full encoded data in memory.
* *
* When all of the data has been converted you must call * When all of the data has been converted you must call
* g_base64_encode_close() to flush the saved state. * g_base64_encode_close() to flush the saved state.
* *
* The output buffer must be large enough to fit all the data that will * The output buffer must be large enough to fit all the data that will
@ -79,7 +79,7 @@ static const char base64_alphabet[] =
* ((@len / 3 + 1) * 4 + 4) / 72 + 1 bytes of extra space. * ((@len / 3 + 1) * 4 + 4) / 72 + 1 bytes of extra space.
* *
* @break_lines is typically used when putting base64-encoded data in emails. * @break_lines is typically used when putting base64-encoded data in emails.
* It breaks the lines at 72 columns instead of putting all of the text on * It breaks the lines at 72 columns instead of putting all of the text on
* the same line. This avoids problems with long lines in the email system. * the same line. This avoids problems with long lines in the email system.
* *
* Return value: The number of bytes of output that was written * Return value: The number of bytes of output that was written
@ -87,16 +87,16 @@ static const char base64_alphabet[] =
* Since: 2.12 * Since: 2.12
*/ */
gsize gsize
g_base64_encode_step (const guchar *in, g_base64_encode_step (const guchar *in,
gsize len, gsize len,
gboolean break_lines, gboolean break_lines,
gchar *out, gchar *out,
gint *state, gint *state,
gint *save) gint *save)
{ {
char *outptr; char *outptr;
const guchar *inptr; const guchar *inptr;
g_return_val_if_fail (in != NULL, 0); g_return_val_if_fail (in != NULL, 0);
g_return_val_if_fail (out != NULL, 0); g_return_val_if_fail (out != NULL, 0);
g_return_val_if_fail (state != NULL, 0); g_return_val_if_fail (state != NULL, 0);
@ -104,75 +104,75 @@ g_base64_encode_step (const guchar *in,
if (len <= 0) if (len <= 0)
return 0; return 0;
inptr = in; inptr = in;
outptr = out; outptr = out;
if (len + ((char *) save) [0] > 2) if (len + ((char *) save) [0] > 2)
{ {
const guchar *inend = in+len-2; const guchar *inend = in+len-2;
int c1, c2, c3; int c1, c2, c3;
int already; int already;
already = *state; already = *state;
switch (((char *) save) [0]) switch (((char *) save) [0])
{ {
case 1: case 1:
c1 = ((unsigned char *) save) [1];
goto skip1;
case 2:
c1 = ((unsigned char *) save) [1]; c1 = ((unsigned char *) save) [1];
c2 = ((unsigned char *) save) [2]; goto skip1;
case 2:
c1 = ((unsigned char *) save) [1];
c2 = ((unsigned char *) save) [2];
goto skip2; goto skip2;
} }
/* /*
* yes, we jump into the loop, no i'm not going to change it, * yes, we jump into the loop, no i'm not going to change it,
* it's beautiful! * it's beautiful!
*/ */
while (inptr < inend) while (inptr < inend)
{ {
c1 = *inptr++; c1 = *inptr++;
skip1: skip1:
c2 = *inptr++; c2 = *inptr++;
skip2: skip2:
c3 = *inptr++; c3 = *inptr++;
*outptr++ = base64_alphabet [ c1 >> 2 ]; *outptr++ = base64_alphabet [ c1 >> 2 ];
*outptr++ = base64_alphabet [ c2 >> 4 | *outptr++ = base64_alphabet [ c2 >> 4 |
((c1&0x3) << 4) ]; ((c1&0x3) << 4) ];
*outptr++ = base64_alphabet [ ((c2 &0x0f) << 2) | *outptr++ = base64_alphabet [ ((c2 &0x0f) << 2) |
(c3 >> 6) ]; (c3 >> 6) ];
*outptr++ = base64_alphabet [ c3 & 0x3f ]; *outptr++ = base64_alphabet [ c3 & 0x3f ];
/* this is a bit ugly ... */ /* this is a bit ugly ... */
if (break_lines && (++already) >= 19) if (break_lines && (++already) >= 19)
{ {
*outptr++ = '\n'; *outptr++ = '\n';
already = 0; already = 0;
} }
} }
((char *)save)[0] = 0; ((char *)save)[0] = 0;
len = 2 - (inptr - inend); len = 2 - (inptr - inend);
*state = already; *state = already;
} }
if (len>0) if (len>0)
{ {
char *saveout; char *saveout;
/* points to the slot for the next char to save */ /* points to the slot for the next char to save */
saveout = & (((char *)save)[1]) + ((char *)save)[0]; saveout = & (((char *)save)[1]) + ((char *)save)[0];
/* len can only be 0 1 or 2 */ /* len can only be 0 1 or 2 */
switch(len) switch(len)
{ {
case 2: *saveout++ = *inptr++; case 2: *saveout++ = *inptr++;
case 1: *saveout++ = *inptr++; case 1: *saveout++ = *inptr++;
} }
((char *)save)[0] += len; ((char *)save)[0] += len;
} }
return outptr - out; return outptr - out;
} }
@ -195,9 +195,9 @@ g_base64_encode_step (const guchar *in,
*/ */
gsize gsize
g_base64_encode_close (gboolean break_lines, g_base64_encode_close (gboolean break_lines,
gchar *out, gchar *out,
gint *state, gint *state,
gint *save) gint *save)
{ {
int c1, c2; int c1, c2;
char *outptr = out; char *outptr = out;
@ -208,7 +208,7 @@ g_base64_encode_close (gboolean break_lines,
c1 = ((unsigned char *) save) [1]; c1 = ((unsigned char *) save) [1];
c2 = ((unsigned char *) save) [2]; c2 = ((unsigned char *) save) [2];
switch (((char *) save) [0]) switch (((char *) save) [0])
{ {
case 2: case 2:
@ -226,10 +226,10 @@ g_base64_encode_close (gboolean break_lines,
} }
if (break_lines) if (break_lines)
*outptr++ = '\n'; *outptr++ = '\n';
*save = 0; *save = 0;
*state = 0; *state = 0;
return outptr - out; return outptr - out;
} }
@ -242,13 +242,13 @@ g_base64_encode_close (gboolean break_lines,
* representation. * representation.
* *
* Return value: a newly allocated, zero-terminated Base-64 encoded * Return value: a newly allocated, zero-terminated Base-64 encoded
* string representing @data. The returned string must * string representing @data. The returned string must
* be freed with g_free(). * be freed with g_free().
* *
* Since: 2.12 * Since: 2.12
*/ */
gchar * gchar *
g_base64_encode (const guchar *data, g_base64_encode (const guchar *data,
gsize len) gsize len)
{ {
gchar *out; gchar *out;
@ -292,7 +292,7 @@ static const unsigned char mime_base64_rank[256] = {
}; };
/** /**
* g_base64_decode_step: * g_base64_decode_step:
* @in: binary input data * @in: binary input data
* @len: max length of @in data to decode * @len: max length of @in data to decode
* @out: output buffer * @out: output buffer
@ -300,24 +300,24 @@ static const unsigned char mime_base64_rank[256] = {
* @save: Saved state between steps, initialize to 0 * @save: Saved state between steps, initialize to 0
* *
* Incrementally decode a sequence of binary data from its Base-64 stringified * Incrementally decode a sequence of binary data from its Base-64 stringified
* representation. By calling this function multiple times you can convert * representation. By calling this function multiple times you can convert
* data in chunks to avoid having to have the full encoded data in memory. * data in chunks to avoid having to have the full encoded data in memory.
* *
* The output buffer must be large enough to fit all the data that will * The output buffer must be large enough to fit all the data that will
* be written to it. Since base64 encodes 3 bytes in 4 chars you need * be written to it. Since base64 encodes 3 bytes in 4 chars you need
* at least: (@len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero * at least: (@len / 4) * 3 + 3 bytes (+ 3 may be needed in case of non-zero
* state). * state).
* *
* Return value: The number of bytes of output that was written * Return value: The number of bytes of output that was written
* *
* Since: 2.12 * Since: 2.12
**/ **/
gsize gsize
g_base64_decode_step (const gchar *in, g_base64_decode_step (const gchar *in,
gsize len, gsize len,
guchar *out, guchar *out,
gint *state, gint *state,
guint *save) guint *save)
{ {
const guchar *inptr; const guchar *inptr;
guchar *outptr; guchar *outptr;
@ -334,10 +334,10 @@ g_base64_decode_step (const gchar *in,
if (len <= 0) if (len <= 0)
return 0; return 0;
inend = (const guchar *)in+len; inend = (const guchar *)in+len;
outptr = out; outptr = out;
/* convert 4 base64 bytes to 3 normal bytes */ /* convert 4 base64 bytes to 3 normal bytes */
v=*save; v=*save;
i=*state; i=*state;
@ -348,26 +348,26 @@ g_base64_decode_step (const gchar *in,
c = *inptr++; c = *inptr++;
rank = mime_base64_rank [c]; rank = mime_base64_rank [c];
if (rank != 0xff) if (rank != 0xff)
{ {
last[1] = last[0]; last[1] = last[0];
last[0] = c; last[0] = c;
v = (v<<6) | rank; v = (v<<6) | rank;
i++; i++;
if (i==4) if (i==4)
{ {
*outptr++ = v>>16; *outptr++ = v>>16;
if (last[1] != '=') if (last[1] != '=')
*outptr++ = v>>8; *outptr++ = v>>8;
if (last[0] != '=') if (last[0] != '=')
*outptr++ = v; *outptr++ = v;
i=0; i=0;
} }
} }
} }
*save = v; *save = v;
*state = i; *state = i;
return outptr - out; return outptr - out;
} }
@ -386,13 +386,13 @@ g_base64_decode_step (const gchar *in,
*/ */
guchar * guchar *
g_base64_decode (const gchar *text, g_base64_decode (const gchar *text,
gsize *out_len) gsize *out_len)
{ {
guchar *ret; guchar *ret;
gsize input_length; gsize input_length;
gint state = 0; gint state = 0;
guint save = 0; guint save = 0;
g_return_val_if_fail (text != NULL, NULL); g_return_val_if_fail (text != NULL, NULL);
g_return_val_if_fail (out_len != NULL, NULL); g_return_val_if_fail (out_len != NULL, NULL);
@ -401,12 +401,12 @@ g_base64_decode (const gchar *text,
/* We can use a smaller limit here, since we know the saved state is 0, /* We can use a smaller limit here, since we know the saved state is 0,
+1 used to avoid calling g_malloc0(0), and hence retruning NULL */ +1 used to avoid calling g_malloc0(0), and hence retruning NULL */
ret = g_malloc0 ((input_length / 4) * 3 + 1); ret = g_malloc0 ((input_length / 4) * 3 + 1);
*out_len = g_base64_decode_step (text, input_length, ret, &state, &save); *out_len = g_base64_decode_step (text, input_length, ret, &state, &save);
return ret; return ret;
} }
/** /**
* g_base64_decode_inplace: * g_base64_decode_inplace:
* @text: zero-terminated string with base64 text to decode * @text: zero-terminated string with base64 text to decode
@ -426,7 +426,7 @@ g_base64_decode_inplace (gchar *text,
{ {
gint input_length, state = 0; gint input_length, state = 0;
guint save = 0; guint save = 0;
g_return_val_if_fail (text != NULL, NULL); g_return_val_if_fail (text != NULL, NULL);
g_return_val_if_fail (out_len != NULL, NULL); g_return_val_if_fail (out_len != NULL, NULL);
@ -435,6 +435,6 @@ g_base64_decode_inplace (gchar *text,
g_return_val_if_fail (input_length > 1, NULL); g_return_val_if_fail (input_length > 1, NULL);
*out_len = g_base64_decode_step (text, input_length, (guchar *) text, &state, &save); *out_len = g_base64_decode_step (text, input_length, (guchar *) text, &state, &save);
return (guchar *) text; return (guchar *) text;
} }

View File

@ -9,7 +9,7 @@
* *
* This library is distributed in the hope that it will be useful, * This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of * but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details. * Library General Public License for more details.
* *
* You should have received a copy of the GNU Library General Public * You should have received a copy of the GNU Library General Public
@ -29,27 +29,27 @@
G_BEGIN_DECLS G_BEGIN_DECLS
gsize g_base64_encode_step (const guchar *in, gsize g_base64_encode_step (const guchar *in,
gsize len, gsize len,
gboolean break_lines, gboolean break_lines,
gchar *out, gchar *out,
gint *state, gint *state,
gint *save); gint *save);
gsize g_base64_encode_close (gboolean break_lines, gsize g_base64_encode_close (gboolean break_lines,
gchar *out, gchar *out,
gint *state, gint *state,
gint *save); gint *save);
gchar* g_base64_encode (const guchar *data, gchar* g_base64_encode (const guchar *data,
gsize len) G_GNUC_MALLOC; gsize len) G_GNUC_MALLOC;
gsize g_base64_decode_step (const gchar *in, gsize g_base64_decode_step (const gchar *in,
gsize len, gsize len,
guchar *out, guchar *out,
gint *state, gint *state,
guint *save); guint *save);
guchar *g_base64_decode (const gchar *text, guchar *g_base64_decode (const gchar *text,
gsize *out_len) G_GNUC_MALLOC; gsize *out_len) G_GNUC_MALLOC;
guchar *g_base64_decode_inplace (gchar *text, guchar *g_base64_decode_inplace (gchar *text,
gsize *out_len); gsize *out_len);
G_END_DECLS G_END_DECLS