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 = '"';
}
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) {
case SS_QUOTED_ARG:
if (char_in == QUOTE) {
- end_arg();
+ END_ARG();
} else if (char_in == ESCAPE) {
state = SS_QUOTED_ARG_ESCAPED;
} else {
case SS_ARG:
if (char_in == SPACE) {
- end_arg();
+ END_ARG();
} else if (char_in == ESCAPE) {
state = SS_ARG_ESCAPED;
} else {
.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:
*
}
// 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);