aboutsummaryrefslogtreecommitdiff
path: root/jerry-main
diff options
context:
space:
mode:
authorAkos Kiss <akiss@inf.u-szeged.hu>2017-06-26 17:10:07 +0200
committerGitHub <noreply@github.com>2017-06-26 17:10:07 +0200
commit2f140e3b7f1e265eba93ba70fcb81a87d48bfb2d (patch)
treead91fbd5aa84f0b7909321fabaae37d65e01e780 /jerry-main
parentb15347509358776649954e689edb0b2af25985cb (diff)
Add strtol to jerry-libc and make use of it in jerry-main (#1891)
As a side effect, refactor the variable types in `print_unhandled_exception` to reduce the overuse of sized integer types (generic `unsigned int` is better than `uint32_t` if there is no actual requirement on integer width). JerryScript-DCO-1.0-Signed-off-by: Akos Kiss akiss@inf.u-szeged.hu
Diffstat (limited to 'jerry-main')
-rw-r--r--jerry-main/main-unix.c46
1 files changed, 12 insertions, 34 deletions
diff --git a/jerry-main/main-unix.c b/jerry-main/main-unix.c
index 7586a4eb..5f8f7e5a 100644
--- a/jerry-main/main-unix.c
+++ b/jerry-main/main-unix.c
@@ -127,30 +127,6 @@ jerry_value_is_syntax_error (jerry_value_t error_value) /**< error value */
} /* jerry_value_is_syntax_error */
/**
- * Convert string into unsigned integer
- *
- * @return converted number
- */
-static uint32_t
-str_to_uint (const char *num_str_p) /**< string to convert */
-{
- assert (jerry_is_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES));
-
- uint32_t result = 0;
-
- while (*num_str_p != '\0')
- {
- assert (*num_str_p >= '0' && *num_str_p <= '9');
-
- result *= 10;
- result += (uint32_t) (*num_str_p - '0');
- num_str_p++;
- }
-
- return result;
-} /* str_to_uint */
-
-/**
* Print error value
*/
static void
@@ -177,18 +153,18 @@ print_unhandled_exception (jerry_value_t error_value) /**< error value */
if (jerry_is_feature_enabled (JERRY_FEATURE_ERROR_MESSAGES) && jerry_value_is_syntax_error (error_value))
{
- uint32_t err_line = 0;
- uint32_t err_col = 0;
+ unsigned int err_line = 0;
+ unsigned int err_col = 0;
/* 1. parse column and line information */
- for (uint32_t i = 0; i < sz; i++)
+ for (jerry_size_t i = 0; i < sz; i++)
{
if (!strncmp ((char *) (err_str_buf + i), "[line: ", 7))
{
i += 7;
char num_str[8];
- uint32_t j = 0;
+ unsigned int j = 0;
while (i < sz && err_str_buf[i] != ',')
{
@@ -198,7 +174,7 @@ print_unhandled_exception (jerry_value_t error_value) /**< error value */
}
num_str[j] = '\0';
- err_line = str_to_uint (num_str);
+ err_line = (unsigned int) strtol (num_str, NULL, 10);
if (strncmp ((char *) (err_str_buf + i), ", column: ", 10))
{
@@ -216,17 +192,17 @@ print_unhandled_exception (jerry_value_t error_value) /**< error value */
}
num_str[j] = '\0';
- err_col = str_to_uint (num_str);
+ err_col = (unsigned int) strtol (num_str, NULL, 10);
break;
}
} /* for */
if (err_line != 0 && err_col != 0)
{
- uint32_t curr_line = 1;
+ unsigned int curr_line = 1;
bool is_printing_context = false;
- uint32_t pos = 0;
+ unsigned int pos = 0;
/* 2. seek and print */
while (buffer[pos] != '\0')
@@ -519,10 +495,12 @@ main (int argc,
}
case OPT_LOG_LEVEL:
{
- check_usage (strlen (cli_state.arg[1]) == 1 && cli_state.arg[1][0] >= '0' && cli_state.arg[1][0] <= '3',
+ char *endptr;
+ long int log_level = strtol (cli_state.arg[1], &endptr, 10);
+ check_usage (log_level >= 0 && log_level <= 3 && !*endptr,
argv[0], "Error: wrong format for ", cli_state.arg[0]);
- jerry_port_default_set_log_level ((jerry_log_level_t) (cli_state.arg[1][0] - '0'));
+ jerry_port_default_set_log_level ((jerry_log_level_t) log_level);
break;
}
case OPT_ABORT_ON_FAIL: