cmd: add initial commands ls and help

This commit is contained in:
Michael Shaw 2023-10-20 23:56:01 -04:00
commit 0029621ada
6 changed files with 133 additions and 6 deletions

View file

@ -144,6 +144,23 @@ char *strtok(char *str, const char *delim, char **llast)
return ret;
}
bool strempty(const char *s)
{
if(!s)
return true;
if(!*s)
return true;
size_t i = strlen(s);
while(i--) {
if(s[i] != ' ')
return false;
}
return true;
}
char **strsplit(const char *s, char delim, int *n)
{
int num = 0;
@ -162,6 +179,11 @@ char **strsplit(const char *s, char delim, int *n)
ret[idx][i - last] = 0;
idx++;
last = i + 1;
if(ret[idx - 1][0] == 0) {
kfree(ret[idx - 1]);
idx--;
}
}
}
ret[idx] = kmalloc(strlen(s) - last + 1, ALLOC_KERN);