diff --git a/src/dev.c b/src/dev.c index 8512e2d..6bd343a 100644 --- a/src/dev.c +++ b/src/dev.c @@ -61,45 +61,6 @@ int check_range(int number, int low, int high) return 0; } -/** - * @brief Accept an string input like 123:456 and splits them into two ids - * - * @param input input string - * @param id1 the first (left) id - * @param id2 the secound it - * @return int 0 if successfull, or 1 if not two ids provided - */ -int get_two_ids(char* input, int* id1, int* id2) -{ - const char* delim = " :.,"; - - size_t sz = strlen(input); - char* str = (char*)malloc(sz + 1); - strcpy(str, input); - - char* token = strtok(input, delim); - int i = 0; - while (token) { - char* endptr; - long int val = strtol(token, &endptr, 0); - - if (i == 0) - *id1 = val; - else if (i == 1) - *id2 = val; - - i++; - token = strtok(NULL, delim); - } - - free(str); - - if (i != 2) // not exactly supplied two ids - return 1; - - return 0; -} - static void print_help() { printf("HeadsetControl Developer menu. Take caution.\n\n"); diff --git a/src/dev.h b/src/dev.h index 4dd83b4..b7db835 100644 --- a/src/dev.h +++ b/src/dev.h @@ -1,5 +1,3 @@ #pragma once -int get_two_ids(char* input, int* id1, int* id2); - int dev_main(int argc, char* argv[]); diff --git a/src/utility.c b/src/utility.c index b618563..0e5c79d 100644 --- a/src/utility.c +++ b/src/utility.c @@ -137,6 +137,37 @@ int get_float_data_from_parameter(char* input, float* dest, size_t len) return i; } +int get_two_ids(char* input, int* id1, int* id2) +{ + const char* delim = " :.,"; + + size_t sz = strlen(input); + char* str = (char*)malloc(sz + 1); + strcpy(str, input); + + char* token = strtok(input, delim); + int i = 0; + while (token) { + char* endptr; + long int val = strtol(token, &endptr, 0); + + if (i == 0) + *id1 = val; + else if (i == 1) + *id2 = val; + + i++; + token = strtok(NULL, delim); + } + + free(str); + + if (i != 2) // not exactly supplied two ids + return 1; + + return 0; +} + // ----------------- asprintf / vasprintf ----------------- /* * Copyright (c) 2004 Darren Tucker. diff --git a/src/utility.h b/src/utility.h index f12568d..5e23114 100644 --- a/src/utility.h +++ b/src/utility.h @@ -92,6 +92,16 @@ int get_byte_data_from_parameter(char* input, unsigned char* dest, size_t len); */ int get_float_data_from_parameter(char* input, float* dest, size_t len); +/** + * @brief Accept an string input like 123:456 and splits them into two ids + * + * @param input input string + * @param id1 the first (left) id + * @param id2 the secound it + * @return int 0 if successfull, or 1 if not two ids provided + */ +int get_two_ids(char* input, int* id1, int* id2); + int vasprintf(char** str, const char* fmt, va_list ap); int _asprintf(char** str, const char* fmt, ...);