Refactored command parsing.
Allows for automatically tested command parsing by splitting parsing and invokation of the commands.
This commit is contained in:
@@ -35,9 +35,11 @@ extern char* debug_mem_strndup(const char* s, size_t n);
|
||||
|
||||
#define hub_malloc malloc
|
||||
#define hub_free free
|
||||
#define hub_realloc realloc
|
||||
#define hub_strdup strdup
|
||||
#define hub_strndup strndup
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
extern void* hub_malloc_zero(size_t size);
|
||||
|
||||
@@ -281,6 +281,27 @@ int uhub_atoi(const char* value) {
|
||||
return value[0] == '-' ? -val : val;
|
||||
}
|
||||
|
||||
int is_number(const char* value, int* num)
|
||||
{
|
||||
int len = strlen(value);
|
||||
int offset = (value[0] == '-') ? 1 : 0;
|
||||
int val = 0;
|
||||
int i = offset;
|
||||
|
||||
if (!*(value + offset))
|
||||
return 0;
|
||||
|
||||
for (; i < len; i++)
|
||||
if (value[i] > '9' || value[i] < '0')
|
||||
return 0;
|
||||
|
||||
for (i = offset; i< len; i++)
|
||||
val = val*10 + (value[i] - '0');
|
||||
*num = value[0] == '-' ? -val : val;
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* FIXME: -INTMIN is wrong!
|
||||
|
||||
@@ -36,6 +36,12 @@ extern char* strip_white_space(char* string);
|
||||
extern void strip_off_ini_line_comments(char* line, int line_count);
|
||||
extern char* strip_off_quotes(char* line);
|
||||
|
||||
/**
|
||||
* Convert number in str to integer and store it in num.
|
||||
* @return 1 on success, or 0 on error.
|
||||
*/
|
||||
extern int is_number(const char* str, int* num);
|
||||
|
||||
extern int file_read_lines(const char* file, void* data, file_line_handler_t handler);
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user