mirror of
https://github.com/suchmememanyskill/TegraExplorer.git
synced 2024-11-22 11:56:42 +00:00
Fix a few bugs in the arg parser
This commit is contained in:
parent
34abed91a9
commit
81cf8c201c
1 changed files with 13 additions and 6 deletions
|
@ -18,7 +18,7 @@
|
|||
#include "../utils/utils.h"
|
||||
#include "../../hid/hid.h"
|
||||
|
||||
u32 countchars(const char* in, char target) {
|
||||
int countchars(const char* in, char target) {
|
||||
u32 len = strlen(in);
|
||||
u32 count = 0;
|
||||
|
||||
|
@ -42,15 +42,18 @@ u32 splitargs(const char* in) {
|
|||
// arg like '5, "6", @arg7'
|
||||
u32 i = 0, count = 1, len = strlen(in), curcount = 0, begin, end;
|
||||
|
||||
if ((count += countchars(in, ',')) < 0){
|
||||
count += countchars(in, ',');
|
||||
|
||||
if (!count)
|
||||
return 0;
|
||||
}
|
||||
|
||||
argv = calloc(count + 1, sizeof(char*));
|
||||
|
||||
while (i < len && curcount < count) {
|
||||
while (in[i] == ' ' || in[i] == ',')
|
||||
if (in[i] == ' ' || in[i] == ','){
|
||||
i++;
|
||||
continue;
|
||||
}
|
||||
|
||||
begin = i;
|
||||
|
||||
|
@ -62,6 +65,10 @@ u32 splitargs(const char* in) {
|
|||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
if (in[i] == '\0')
|
||||
return 0;
|
||||
|
||||
i++;
|
||||
}
|
||||
|
||||
|
@ -73,7 +80,7 @@ u32 splitargs(const char* in) {
|
|||
|
||||
argv[curcount++] = utils_copyStringSize(in + begin, (u32)(end - begin));
|
||||
}
|
||||
return count;
|
||||
return curcount;
|
||||
}
|
||||
|
||||
FIL scriptin;
|
||||
|
|
Loading…
Reference in a new issue