diff --git a/components/console/split_argv.c b/components/console/split_argv.c index 79ae918fcb..66b5d0f803 100644 --- a/components/console/split_argv.c +++ b/components/console/split_argv.c @@ -31,6 +31,13 @@ typedef enum { SS_QUOTED_ARG_ESCAPED = SS_QUOTED_ARG | SS_FLAG_ESCAPE, } split_state_t; +/* helper macro, called when done with an argument */ +#define END_ARG() do { \ + char_out = 0; \ + argv[argc++] = next_arg_start; \ + state = SS_SPACE; \ +} while(0) + size_t esp_console_split_argv(char *line, char **argv, size_t argv_size) { const int QUOTE = '"'; @@ -47,13 +54,6 @@ size_t esp_console_split_argv(char *line, char **argv, size_t argv_size) } int char_out = -1; - /* helper function, called when done with an argument */ - void end_arg() { - char_out = 0; - argv[argc++] = next_arg_start; - state = SS_SPACE; - } - switch (state) { case SS_SPACE: if (char_in == SPACE) { @@ -73,7 +73,7 @@ size_t esp_console_split_argv(char *line, char **argv, size_t argv_size) case SS_QUOTED_ARG: if (char_in == QUOTE) { - end_arg(); + END_ARG(); } else if (char_in == ESCAPE) { state = SS_QUOTED_ARG_ESCAPED; } else { @@ -93,7 +93,7 @@ size_t esp_console_split_argv(char *line, char **argv, size_t argv_size) case SS_ARG: if (char_in == SPACE) { - end_arg(); + END_ARG(); } else if (char_in == ESCAPE) { state = SS_ARG_ESCAPED; } else { diff --git a/components/ulp/ulp_macro.c b/components/ulp/ulp_macro.c index eae72ffe02..bf4039df11 100644 --- a/components/ulp/ulp_macro.c +++ b/components/ulp/ulp_macro.c @@ -58,6 +58,27 @@ typedef struct { .unused = 0, \ .type = RELOC_TYPE_BRANCH } +/* Comparison function used to sort the relocations array */ +static int reloc_sort_func(const void* p_lhs, const void* p_rhs) +{ + const reloc_info_t lhs = *(const reloc_info_t*) p_lhs; + const reloc_info_t rhs = *(const reloc_info_t*) p_rhs; + if (lhs.label < rhs.label) { + return -1; + } else if (lhs.label > rhs.label) { + return 1; + } + // label numbers are equal + if (lhs.type < rhs.type) { + return -1; + } else if (lhs.type > rhs.type) { + return 1; + } + + // both label number and type are equal + return 0; +} + /* Processing branch and label macros involves four steps: * @@ -203,24 +224,6 @@ esp_err_t ulp_process_macros_and_load(uint32_t load_addr, const ulp_insn_t* prog } // step 3: sort relocations array - int reloc_sort_func(const void* p_lhs, const void* p_rhs) { - const reloc_info_t lhs = *(const reloc_info_t*) p_lhs; - const reloc_info_t rhs = *(const reloc_info_t*) p_rhs; - if (lhs.label < rhs.label) { - return -1; - } else if (lhs.label > rhs.label) { - return 1; - } - // label numbers are equal - if (lhs.type < rhs.type) { - return -1; - } else if (lhs.type > rhs.type) { - return 1; - } - - // both label number and type are equal - return 0; - } qsort(reloc_info, macro_count, sizeof(reloc_info_t), reloc_sort_func);