Style fixes in libruntime.

This commit is contained in:
Ruben Ayrapetyan
2014-08-12 14:16:05 +04:00
parent aa43e06366
commit b4a29f754a
11 changed files with 830 additions and 673 deletions
+26
View File
@@ -37,45 +37,71 @@ jerry_exit( jerry_status_t code) /**< status code */
switch (code)
{
case ERR_OK:
{
JERRY_UNREACHABLE();
break;
}
case ERR_IO:
{
__printf ("ERR_IO\n");
break;
}
case ERR_BUFFER_SIZE:
{
__printf ("ERR_BUFFER_SIZE\n");
break;
}
case ERR_SEVERAL_FILES:
{
__printf ("ERR_SEVERAL_FILES\n");
break;
}
case ERR_NO_FILES:
{
__printf ("ERR_NO_FILES\n");
break;
}
case ERR_NON_CHAR:
{
__printf ("ERR_NON_CHAR\n");
break;
}
case ERR_UNCLOSED:
{
__printf ("ERR_UNCLOSED\n");
break;
}
case ERR_INT_LITERAL:
{
__printf ("ERR_INT_LITERAL\n");
break;
}
case ERR_STRING:
{
__printf ("ERR_STRING\n");
break;
}
case ERR_PARSER:
{
__printf ("ERR_PARSER\n");
break;
}
case ERR_MEMORY:
{
__printf ("ERR_MEMORY\n");
break;
}
case ERR_SYSCALL:
{
JERRY_UNREACHABLE();
break;
}
case ERR_GENERAL:
{
__printf ("ERR_GENERAL\n");
break;
}
}
/* The failed assertion is 'Return code is zero' */
jerry_assert_fail ("Return code is zero", __FILE__, __LINE__);
+71 -1
View File
@@ -208,42 +208,60 @@ libc_printf_write_d_i( _FILE *stream, /**< stream pointer */
switch (length)
{
case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE:
{
value = (uintmax_t)va_arg (*args_list_p, int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH:
{
value = (uintmax_t)va_arg (*args_list_p, int); /* char is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_H:
{
value = (uintmax_t)va_arg (*args_list_p, int); /* short int is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_L:
{
value = (uintmax_t)va_arg (*args_list_p, long int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_LL:
{
value = (uintmax_t)va_arg (*args_list_p, long long int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_J:
{
value = (uintmax_t)va_arg (*args_list_p, intmax_t);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_Z:
{
is_signed = false;
value = (uintmax_t)va_arg (*args_list_p, size_t);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_T:
{
is_signed = false;
value = (uintmax_t)va_arg (*args_list_p, ptrdiff_t);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL:
{
JERRY_UNREACHABLE();
}
}
if (is_signed)
{
@@ -309,40 +327,58 @@ libc_printf_write_u_o_x_X( _FILE *stream, /**< stream pointer */
switch (length)
{
case LIBC_PRINTF_ARG_LENGTH_TYPE_NONE:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HH:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned int); /* char is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_H:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned int); /* short int is promoted to int */
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_L:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned long int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_LL:
{
value = (uintmax_t)va_arg (*args_list_p, unsigned long long int);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_J:
{
value = (uintmax_t)va_arg (*args_list_p, uintmax_t);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_Z:
{
value = (uintmax_t)va_arg (*args_list_p, size_t);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_T:
{
value = (uintmax_t)va_arg (*args_list_p, ptrdiff_t);
break;
}
case LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL:
{
JERRY_UNREACHABLE();
}
}
if (flags & LIBC_PRINTF_ARG_FLAG_SHARP)
{
@@ -371,28 +407,38 @@ libc_printf_write_u_o_x_X( _FILE *stream, /**< stream pointer */
switch (specifier)
{
case 'u':
{
alphabet = "0123456789";
radix = 10;
break;
}
case 'o':
{
alphabet = "01234567";
radix = 8;
break;
}
case 'x':
{
alphabet = "0123456789abcdef";
radix = 16;
break;
}
case 'X':
{
alphabet = "0123456789ABCDEF";
radix = 16;
break;
}
default:
{
JERRY_UNREACHABLE();
}
}
char str_buffer[ 32 ];
const char *string_p = libc_printf_uint_to_string (value,
@@ -508,6 +554,7 @@ __vfprintf( _FILE *stream, /**< stream pointer */
switch (*format_iter_p)
{
case 'h':
{
format_iter_p++;
if (*format_iter_p == 'h')
{
@@ -520,8 +567,10 @@ __vfprintf( _FILE *stream, /**< stream pointer */
length = LIBC_PRINTF_ARG_LENGTH_TYPE_H;
}
break;
}
case 'l':
{
format_iter_p++;
if (*format_iter_p == 'l')
{
@@ -534,41 +583,54 @@ __vfprintf( _FILE *stream, /**< stream pointer */
length = LIBC_PRINTF_ARG_LENGTH_TYPE_L;
}
break;
}
case 'j':
{
format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_J;
break;
}
case 'z':
{
format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_Z;
break;
}
case 't':
{
format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_T;
break;
}
case 'L':
{
format_iter_p++;
length = LIBC_PRINTF_ARG_LENGTH_TYPE_HIGHL;
break;
}
}
switch (*format_iter_p)
{
case 'd':
case 'i':
{
libc_printf_write_d_i (stream, &args_copy, flags, length, width);
break;
}
case 'u':
case 'o':
case 'x':
case 'X':
{
libc_printf_write_u_o_x_X(stream, *format_iter_p, &args_copy, flags, length, width);
break;
}
case 'f':
case 'F':
@@ -578,10 +640,13 @@ __vfprintf( _FILE *stream, /**< stream pointer */
case 'G':
case 'a':
case 'A':
{
JERRY_UNIMPLEMENTED();
break;
}
case 'c':
{
if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L)
{
JERRY_UNIMPLEMENTED();
@@ -601,8 +666,10 @@ __vfprintf( _FILE *stream, /**< stream pointer */
flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING);
}
break;
}
case 's':
{
if (length & LIBC_PRINTF_ARG_LENGTH_TYPE_L)
{
JERRY_UNIMPLEMENTED();
@@ -618,6 +685,7 @@ __vfprintf( _FILE *stream, /**< stream pointer */
flags & LIBC_PRINTF_ARG_FLAG_ZERO_PADDING);
}
break;
}
case 'p':
{
@@ -639,14 +707,16 @@ __vfprintf( _FILE *stream, /**< stream pointer */
LIBC_PRINTF_ARG_LENGTH_TYPE_Z,
width);
}
}
break;
}
case 'n':
{
JERRY_UNIMPLEMENTED();
break;
}
}
}
format_iter_p++;
}
+35 -2
View File
@@ -124,7 +124,8 @@ __memcmp(const void *s1, /**< first area */
if (area1_p[ index ] < area2_p[ index ])
{
return -1;
} else if ( area1_p[ index ] > area2_p[ index ] )
}
else if (area1_p[ index ] > area2_p[ index ])
{
return 1;
}
@@ -171,7 +172,8 @@ __memmove(void *s1, /**< destination */
{
dest_p[ index ] = src_p[ index ];
}
} else if ( dest_p > src_p )
}
else if (dest_p > src_p)
{ /* from end to begin */
for (size_t index = 1; index <= n; index++)
{
@@ -191,23 +193,35 @@ __strcmp (const char *s1, const char *s2)
if (s1 == NULL)
{
if (s2 != NULL)
{
return -1;
}
else
{
return 0;
}
}
if (s2 == NULL)
{
return 1;
}
for (i = 0; s1[i]; i++)
{
if (s1[i] > s2[i])
{
return 1;
}
else if (s1[i] < s2[i])
{
return -1;
}
}
if (s2[i])
{
return -1;
}
return 0;
}
@@ -222,20 +236,30 @@ __strncmp (const char *s1, const char *s2, size_t n)
if (s1 == NULL)
{
if (s2 != NULL)
{
return -1;
}
else
{
return 0;
}
}
if (s2 == NULL)
{
return 1;
}
for (i = 0; i < n; i++)
{
if (s1[i] > s2[i])
{
return 1;
}
else if (s1[i] < s2[i])
{
return -1;
}
}
return 0;
}
@@ -252,8 +276,10 @@ __strncpy(char *dest, const char *src, size_t n)
{
dest[i] = src[i];
if (src[i] == '\0')
{
break;
}
}
return dest;
}
@@ -274,7 +300,10 @@ __strlen (const char *s)
{
size_t i;
for (i = 0; s[i]; i++)
{
;
}
return i;
}
@@ -291,11 +320,15 @@ __isspace (int c)
case '\r':
case '\t':
case '\v':
{
return 1;
}
default:
{
return 0;
}
}
}
/** Checks for an uppercase letter. */
int
+37 -9
View File
@@ -146,11 +146,11 @@ _FILE*
__fopen (const char *path, /**< file path */
const char *mode) /**< file open mode */
{
bool may_read = false,
may_write = false,
truncate = false,
create_if_not_exist = false,
position_at_end = false;
bool may_read = false;
bool may_write = false;
bool truncate = false;
bool create_if_not_exist = false;
bool position_at_end = false;
JERRY_ASSERT(path != NULL && mode != NULL);
JERRY_ASSERT(mode[1] == '+' || mode[1] == '\0');
@@ -158,16 +158,21 @@ __fopen(const char *path, /**< file path */
switch (mode[0])
{
case 'r':
{
may_read = true;
may_write = (mode[1] == '+');
break;
}
case 'w':
{
may_write = true;
truncate = true;
create_if_not_exist = true;
may_read = (mode[1] == '+');
break;
}
case 'a':
{
may_write = true;
position_at_end = true;
create_if_not_exist = true;
@@ -176,9 +181,12 @@ __fopen(const char *path, /**< file path */
JERRY_UNIMPLEMENTED();
}
break;
}
default:
{
JERRY_UNREACHABLE();
}
}
int flags = 0;
int access = S_IRUSR | S_IWUSR;
@@ -254,15 +262,21 @@ __fseek(_FILE * fp, /**< stream pointer */
switch (whence)
{
case __SEEK_SET:
{
whence_real = SEEK_SET;
break;
}
case __SEEK_CUR:
{
whence_real = SEEK_CUR;
break;
}
case __SEEK_END:
{
whence_real = SEEK_END;
break;
}
}
syscall_3 (__NR_lseek, (long int)fp, offset, whence_real);
@@ -296,10 +310,14 @@ __fread(void *ptr, /**< address of buffer to read to */
do
{
ret = syscall_3( __NR_read, (long int)stream, (long int) ((uint8_t*)ptr + bytes_read), (long int) (size * nmemb - bytes_read));
ret = syscall_3 (__NR_read,
(long int) stream,
(long int) ((uint8_t*) ptr + bytes_read),
(long int) (size * nmemb - bytes_read));
bytes_read += (size_t)ret;
} while (bytes_read != size * nmemb && ret != 0);
}
while (bytes_read != size * nmemb && ret != 0);
return bytes_read;
} /* __fread */
@@ -319,10 +337,14 @@ __fwrite(const void *ptr, /**< data to write */
do
{
long int ret = syscall_3( __NR_write, (long int)stream, (long int) ((uint8_t*)ptr + bytes_written), (long int) (size * nmemb - bytes_written));
long int ret = syscall_3 (__NR_write,
(long int) stream,
(long int) ((uint8_t*) ptr + bytes_written),
(long int) (size * nmemb - bytes_written));
bytes_written += (size_t)ret;
} while (bytes_written != size * nmemb);
}
while (bytes_written != size * nmemb);
return bytes_written;
} /* __fwrite */
@@ -396,15 +418,21 @@ __fseek(_FILE * fp, /**< stream pointer */
switch (whence)
{
case __SEEK_SET:
{
whence_real = SEEK_SET;
break;
}
case __SEEK_CUR:
{
whence_real = SEEK_CUR;
break;
}
case __SEEK_END:
{
whence_real = SEEK_END;
break;
}
}
return fseek (fp, offset, whence_real);
} /* __fseek */