16 static char *strtrim (char *s)
18 char *t = s + strlen (s) - 1;
20 while (t >= s && *t && isspace (*t))
23 while (*s && isspace (*s))
30 // bufferLength includes the space reserved for the \0
32 int argsGetLine (int fd __attribute__ ((unused)), U8 *buffer, int bufferLength)
45 if (read (fd, &c, sizeof (c)) == sizeof (c))
52 return strlen ((char *) buffer);
76 if (p < buffer + bufferLength - 1 && c >= ' ' && c < 0x7f)
105 int argsParse (char *cmd, char **argv, int sizeofArgv, int *argc)
107 int maxArgs = (sizeofArgv / sizeof (argv [0])) - 1;
108 char *s = strtrim (cmd);
109 PSTATE pstate = P_EATWHITESPACE;
112 memset (argv, 0, sizeofArgv);
118 case P_EATWHITESPACE :
121 pstate = P_GETCHARFIRST;
127 case P_GETCHARFIRST :
131 if (++*argc == maxArgs)
134 pstate = P_QUOTEDGETCHAR;
145 pstate = P_EATWHITESPACE;
149 pstate = P_QUOTEDGETCHAR;
155 case P_QUOTEDGETCHAR :