Skip to content

Commit

Permalink
app_rpt: Refactor explode_string
Browse files Browse the repository at this point in the history
  • Loading branch information
mkmer authored Feb 18, 2025
1 parent 5fb5e50 commit da38bf2
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions utils/radio-tune-menu.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,8 @@
#include <errno.h>
#include <sys/wait.h>

#include "asterisk/utils.h"

/*! \brief type of signal detection used for carrier (cd) or ctcss (sd) */
static const char * const cd_signal_type[] = {"no", "dsp", "vox", "usb", "usbinvert", "pp", "ppinvert"};
static const char * const sd_signal_type[] = {"no", "usb", "usbinvert", "dsp", "pp", "ppinvert"};
Expand Down Expand Up @@ -124,9 +126,9 @@ static void ourhandler(int sig)
*
* \retval Returns number of substrings found.
*/
static int explode_string(char *str, char *strp[], int limit, char delim, char quote)
static int explode_string(char *str, char *strp[], size_t limit, char delim, char quote)
{
int i, l, inquo;
int i, inquo;

inquo = 0;
i = 0;
Expand All @@ -136,7 +138,7 @@ static int explode_string(char *str, char *strp[], int limit, char delim, char q
strp[0] = 0;
return (0);
}
for (l = 0; *str && (l < limit); str++) {
for (; *str && (i < (limit - 1)); str++) {
if (quote) {
if (*str == quote) {
if (inquo) {
Expand All @@ -151,7 +153,6 @@ static int explode_string(char *str, char *strp[], int limit, char delim, char q
}
if ((*str == delim) && (!inquo)) {
*str = 0;
l++;
strp[i++] = str + 1;
}
}
Expand Down Expand Up @@ -432,7 +433,7 @@ static int astgetresp(char *cmd)
if (astgetline(COMMAND_PREFIX "tune menu-support 1", buf, sizeof(buf) - 1)) {
exit(255);
}
n = explode_string(buf, strs, 100, ',', 0);
n = explode_string(buf, strs, ARRAY_LEN(strs), ',', 0);
if (n < 1) {
fprintf(stderr, "Error parsing USB device information\n");
return;
Expand Down Expand Up @@ -490,7 +491,7 @@ static void menu_swapusb(void)
if (astgetline(COMMAND_PREFIX "tune menu-support 3", buf, sizeof(buf) - 1)) {
exit(255);
}
n = explode_string(buf, strs, 100, ',', 0);
n = explode_string(buf, strs, ARRAY_LEN(strs), ',', 0);
if ((n < 1) || (!*strs[0])) {
fprintf(stderr, "No additional USB devices found\n");
return;
Expand Down

0 comments on commit da38bf2

Please sign in to comment.