Define code style formatter for eclipse and apply it to source.

This commit is contained in:
Vreixo Formoso
2007-12-28 22:10:17 +01:00
parent 1ecb735e7c
commit 4c9d83f051
31 changed files with 1018 additions and 1019 deletions

View File

@ -28,7 +28,6 @@ int int_pow(int base, int power)
return result;
}
int strconv(const char *str, const char *icharset, const char *ocharset,
char **output)
{
@ -74,8 +73,8 @@ int strconv(const char *str, const char *icharset, const char *ocharset,
* @return
* 1 success, < 0 error
*/
static
int str2wchar(const char *icharset, const char *input, wchar_t **output)
static
int str2wchar(const char *icharset, const char *input, wchar_t **output)
{
iconv_t conv;
size_t inbytes;
@ -84,7 +83,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
char *src;
wchar_t *wstr;
size_t n;
if (icharset == NULL || input == NULL || output == NULL) {
return ISO_NULL_POINTER;
}
@ -93,7 +92,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
if (conv == (iconv_t)-1) {
return ISO_CHARSET_CONV_ERROR;
}
inbytes = strlen(input);
outbytes = (inbytes + 1) * sizeof(wchar_t);
@ -107,7 +106,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
n = iconv(conv, &src, &inbytes, &ret, &outbytes);
while (n == -1) {
if (errno == E2BIG) {
/* error, should never occur */
iconv_close(conv);
@ -115,7 +114,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
return ISO_CHARSET_CONV_ERROR;
} else {
wchar_t *wret;
/*
* Invalid input string charset.
* This can happen if input is in fact encoded in a charset
@ -126,7 +125,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
/* printf("String %s is not encoded in %s\n", str, codeset); */
inbytes--;
src++;
wret = (wchar_t*) ret;
*wret++ = (wchar_t) '_';
ret = (char *) wret;
@ -138,7 +137,7 @@ int str2wchar(const char *icharset, const char *input, wchar_t **output)
}
}
iconv_close(conv);
*( (wchar_t *)ret )='\0';
*output = wstr;
return ISO_SUCCESS;
@ -156,7 +155,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
size_t outbytes;
size_t inbytes;
size_t n;
if (icharset == NULL || input == NULL || output == NULL) {
return ISO_NULL_POINTER;
}
@ -171,7 +170,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
}
src = (char *)wsrc_;
numchars = wcslen(wsrc_);
inbytes = numchars * sizeof(wchar_t);
ret_ = malloc(numchars + 1);
@ -190,7 +189,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
}
n = iconv(conv, &src, &inbytes, &ret, &outbytes);
while(n == -1) {
while (n == -1) {
/* The destination buffer is too small. Stops here. */
if (errno == E2BIG)
break;
@ -226,7 +225,7 @@ int str2ascii(const char *icharset, const char *input, char **output)
*ret='\0';
free(wsrc_);
*output = ret_;
return ISO_SUCCESS;
}
@ -238,25 +237,25 @@ static int valid_d_char(char c)
static int valid_a_char(char c)
{
return (c >= ' ' && c <= '"') || (c >= '%' && c <= '?')
|| (c >= 'A' && c <= 'Z') || (c == '_');
return (c >= ' ' && c <= '"') || (c >= '%' && c <= '?') ||
(c >= 'A' && c <= 'Z') || (c == '_');
}
static
static
char *iso_dirid(const char *src, int size)
{
size_t len, i;
char name[32];
len = strlen(src);
if (len > size) {
len = size;
}
for (i = 0; i < len; i++) {
char c = toupper(src[i]);
char c= toupper(src[i]);
name[i] = valid_d_char(c) ? c : '_';
}
name[len] = '\0';
return strdup(name);
}
@ -274,7 +273,7 @@ char *iso_2_dirid(const char *src)
char *iso_1_fileid(const char *src)
{
char *dot; /* Position of the last dot in the filename, will be used
to calculate lname and lext. */
* to calculate lname and lext. */
int lname, lext, pos, i;
char dest[13]; /* 13 = 8 (name) + 1 (.) + 3 (ext) + 1 (\0) */
@ -292,24 +291,24 @@ char *iso_1_fileid(const char *src)
}
pos = 0;
/* Convert up to 8 characters of the filename. */
for (i = 0; i < lname && i < 8; i++) {
char c = toupper(src[i]);
char c= toupper(src[i]);
dest[pos++] = valid_d_char(c) ? c : '_';
}
/* This dot is mandatory, even if there is no extension. */
dest[pos++] = '.';
/* Convert up to 3 characters of the extension, if any. */
for (i = 0; i < lext && i < 3; i++) {
char c = toupper(src[lname + 1 + i]);
char c= toupper(src[lname + 1 + i]);
dest[pos++] = valid_d_char(c) ? c : '_';
}
dest[pos] = '\0';
return strdup(dest);
}
@ -339,8 +338,8 @@ char *iso_2_fileid(const char *src)
} else {
lext = strlen(dot + 1);
lname = strlen(src) - lext - 1;
lnext = (strlen(src) > 31 && lext > 3)
? (lname < 27 ? 30 - lname : 3) : lext;
lnext = (strlen(src) > 31 && lext > 3) ? (lname < 27 ? 30 - lname : 3)
: lext;
lnname = (strlen(src) > 31) ? 30 - lnext : lname;
}
@ -349,18 +348,18 @@ char *iso_2_fileid(const char *src)
}
pos = 0;
/* Convert up to lnname characters of the filename. */
for (i = 0; i < lnname; i++) {
char c = toupper(src[i]);
char c= toupper(src[i]);
dest[pos++] = valid_d_char(c) ? c : '_';
}
dest[pos++] = '.';
/* Convert up to lnext characters of the extension, if any. */
for (i = 0; i < lnext; i++) {
char c = toupper(src[lname + 1 + i]);
char c= toupper(src[lname + 1 + i]);
dest[pos++] = valid_d_char(c) ? c : '_';
}
@ -368,166 +367,70 @@ char *iso_2_fileid(const char *src)
return strdup(dest);
}
//void iso_dirid(char *src, int maxlen)
//{
// size_t len, i;
//
// len = strlen(src);
// if (len > maxlen) {
// src[maxlen] = '\0';
// len = maxlen;
// }
// for (i = 0; i < len; i++) {
// char c = toupper(src[i]);
// src[i] = valid_d_char(c) ? c : '_';
// }
//}
//void iso_1_fileid(char *src)
//{
// char *dot; /* Position of the last dot in the filename, will be used to
// calculate lname and lext. */
// int lname, lext, pos, i;
//
// dot = strrchr(src, '.');
//
// lext = dot ? strlen(dot + 1) : 0;
// lname = strlen(src) - lext - (dot ? 1 : 0);
//
// /* If we can't build a filename, return. */
// if (lname == 0 && lext == 0) {
// return;
// }
//
// pos = 0;
// /* Convert up to 8 characters of the filename. */
// for (i = 0; i < lname && i < 8; i++) {
// char c = toupper(src[i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
//
// /* This dot is mandatory, even if there is no extension. */
// src[pos++] = '.';
//
// /* Convert up to 3 characters of the extension, if any. */
// for (i = 0; i < lext && i < 3; i++) {
// char c = toupper(src[lname + 1 + i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
// src[pos] = '\0';
//}
//
//void iso_2_fileid(char *src)
//{
// char *dot;
// int lname, lext, lnname, lnext, pos, i;
//
// if (!src)
// return;
//
// dot = strrchr(src, '.');
//
// /*
// * Since the maximum length can be divided freely over the name and
// * extension, we need to calculate their new lengths (lnname and
// * lnext). If the original filename is too long, we start by trimming
// * the extension, but keep a minimum extension length of 3.
// */
// if (dot == NULL || *(dot + 1) == '\0') {
// lname = strlen(src);
// lnname = (lname > 30) ? 30 : lname;
// lext = lnext = 0;
// } else {
// lext = strlen(dot + 1);
// lname = strlen(src) - lext - 1;
// lnext = (strlen(src) > 31 && lext > 3)
// ? (lname < 27 ? 30 - lname : 3) : lext;
// lnname = (strlen(src) > 31) ? 30 - lnext : lname;
// }
//
// if (lnname == 0 && lnext == 0) {
// return;
// }
//
// pos = 0;
// /* Convert up to lnname characters of the filename. */
// for (i = 0; i < lnname; i++) {
// char c = toupper(src[i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
// src[pos++] = '.';
// /* Convert up to lnext characters of the extension, if any. */
// for (i = 0; i < lnext; i++) {
// char c = toupper(src[lname + 1 + i]);
// src[pos++] = valid_d_char(c) ? c : '_';
// }
// src[pos] = '\0';
//}
int str2d_char(const char *icharset, const char *input, char **output)
{
int ret;
char *ascii;
size_t len, i;
if (output == NULL) {
return ISO_MEM_ERROR;
}
/** allow NULL input */
if (input == NULL) {
*output = NULL;
return 0;
}
/* this checks for NULL parameters */
ret = str2ascii(icharset, input, &ascii);
if (ret < 0) {
*output = NULL;
return ret;
}
len = strlen(ascii);
for (i = 0; i < len; ++i) {
char c = toupper(ascii[i]);
char c= toupper(ascii[i]);
ascii[i] = valid_d_char(c) ? c : '_';
}
*output = ascii;
return ISO_SUCCESS;
}
int str2a_char(const char *icharset, const char *input, char **output)
{
int ret;
char *ascii;
size_t len, i;
if (output == NULL) {
return ISO_MEM_ERROR;
}
/** allow NULL input */
if (input == NULL) {
*output = NULL;
return 0;
}
/* this checks for NULL parameters */
ret = str2ascii(icharset, input, &ascii);
if (ret < 0) {
*output = NULL;
return ret;
}
len = strlen(ascii);
for (i = 0; i < len; ++i) {
char c = toupper(ascii[i]);
char c= toupper(ascii[i]);
ascii[i] = valid_a_char(c) ? c : '_';
}
*output = ascii;
return ISO_SUCCESS;
}