2005-11-11, 12:36 h
Micha1701
Posts: 938
User
|
Hallo!
Ich werd gleich irre... ;-)
Ich versuche ein kleines Programm (nur ANSI C) durch den GNU-C compiler zu jagen. Aber er mag nicht. Gibt mir ständig die Fehlermeldung "parse error before 'int'". Und zwar für die Zeile "int main(void)" und "int isascii(int num)".
Keine Ahnung was der da von mir will. StormCV3 und VBCC machen dabei keine Probleme...
hier mal der Code:
code:
#include <ctype.h>
#include <stdio.h>
#include <string.h>
#define BAD -1
#define DECODE64(c) (isascii(c) ? base64val[c] : BAD)
static const char base64digits[] = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
static const char base64val[] =
{
BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,
BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,
BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD,BAD, 62,BAD,BAD,BAD, 63,
52, 53, 54, 55, 56, 57, 58, 59, 60, 61,BAD,BAD,BAD,BAD,BAD,BAD,
BAD, 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,BAD,BAD,BAD,BAD,BAD,
BAD, 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,BAD,BAD,BAD,BAD,BAD
};
int isascii(int num);
void to64frombits(unsigned char *out, const unsigned char *in, int inlen);
int from64tobits(char *out, const char *in);
int main(void)
{
char buffer[100];
char buffer2[100];
char teststring[] = "test123";
int i;
printf("Decodiere String: %sn", teststring);
to64frombits(buffer, teststring, strlen(teststring));
printf("base64 String: %snund zurückn", buffer);
i = from64tobits(buffer2, buffer);
buffer2[i] = 0;
printf("alter String: %sn", buffer2);
return 0;
}
void to64frombits(unsigned char *out, const unsigned char *in, int inlen)
{
unsigned char fragment;
for (; inlen >= 3; inlen -= 3)
{
*out++ = base64digits[in[0] >> 2];
*out++ = base64digits[((in[0] << 4) & 0x30) | (in[1] >> 4)];
*out++ = base64digits[((in[1] << 2) & 0x3c) | (in[2] >> 6)];
*out++ = base64digits[in[2] & 0x3f];
in += 3;
}
if (inlen > 0)
{
*out++ = base64digits[in[0] >> 2];
fragment = (in[0] << 4) & 0x30;
if (inlen > 1)
fragment |= in[1] >> 4;
*out++ = base64digits[fragment];
*out++ = (inlen < 2) ? '=' : base64digits[(in[1] << 2) & 0x3c];
*out++ = '=';
}
*out = ' ';
}
int from64tobits(char *out, const char *in)
{
int len = 0;
register unsigned char digit1, digit2, digit3, digit4;
if (in[0] == '+' && in[1] == ' ')
in += 2;
if (*in == 'r')
return(0);
do
{
digit1 = in[0];
/*if (DECODE64(digit1) == BAD) */
if((isascii(digit1) ? base64val[digit1] : BAD) == BAD)
return(-1);
digit2 = in[1];
/*if (DECODE64(digit2) == BAD)*/
if((isascii(digit2) ? base64val[digit2] : BAD) == BAD)
return(-1);
digit3 = in[2];
/*if (digit3 != '=' && DECODE64(digit3) == BAD) */
if (digit3 != '=' && (isascii(digit3) ? base64val[digit3] : BAD) == BAD)
return(-1);
digit4 = in[3];
/*if (digit4 != '=' && DECODE64(digit4) == BAD) */
if(digit3 != '=' && (isascii(digit4) ? base64val[digit4] : BAD) ==BAD)
return(-1);
in += 4;
/**out++ = (DECODE64(digit1) << 2) | (DECODE64(digit2) >> 4); */
*out++ = ((isascii(digit1) ? base64val[digit1] : BAD) << 2) |
((isascii(digit2) ? base64val[digit2] : BAD) >> 4);
++len;
if (digit3 != '=')
{
/**out++ = ((DECODE64(digit2) << 4) & 0xf0) | (DECODE64(digit3) >> 2); */
*out++ = (((isascii(digit2) ? base64val[digit2] : BAD) << 4) & 0xf0) |
((isascii(digit3) ? base64val[digit3] : BAD) >> 2);
++len;
if (digit4 != '=')
{
/**out++ = ((DECODE64(digit3) << 6) & 0xc0) | DECODE64(digit4); */
*out++ = (((isascii(digit3) ? base64val[digit3] : BAD) << 6) & 0xc0) |
(isascii(digit4) ? base64val[digit4] : BAD);
++len;
}
}
} while (*in && *in != 'r' && digit4 != '=');
return (len);
}
int isascii(int num)
{
if(num >= 0 && num <= 127)
return 1;
else
return 0;
}
Einer ne Ahnung was der GNU von mir möchte?
--
Micha
Look at my HPs:
http://www.Silicon-Wizards.com
http://www.RealmsofPower.de.vu
[ - Answer - Quote - Direct link - ]
|