+ if (buf[len] == '\0') {
+ argv[0] = NULL;
+ goto got_command;
+ }
+
+ buf[len] = '\0';
+ p = &buf[len+1];
+ p += strspn (p, " \t");
+
+ /* Get the parameters. */
+ while (*p && i < sizeof argv / sizeof argv[0]) {
+ /* Parameters which start with quotes or square brackets
+ * are treated specially. Bare parameters are delimited
+ * by whitespace.
+ */
+ if (*p == '"') {
+ p++;
+ len = strcspn (p, "\"");
+ if (p[len] == '\0') {
+ fprintf (stderr, "guestfish: unterminated double quote\n");
+ if (!prompt) exit (1);
+ goto next_command;
+ }
+ if (p[len+1] && (p[len+1] != ' ' && p[len+1] != '\t')) {
+ fprintf (stderr, "guestfish: command arguments not separated by whitespace\n");
+ if (!prompt) exit (1);
+ goto next_command;
+ }
+ p[len] = '\0';
+ pend = &p[len+2];
+ } else if (*p == '\'') {
+ p++;
+ len = strcspn (p, "'");
+ if (p[len] == '\0') {
+ fprintf (stderr, "guestfish: unterminated single quote\n");
+ if (!prompt) exit (1);
+ goto next_command;
+ }
+ if (p[len+1] && (p[len+1] != ' ' && p[len+1] != '\t')) {
+ fprintf (stderr, "guestfish: command arguments not separated by whitespace\n");
+ if (!prompt) exit (1);
+ goto next_command;
+ }
+ p[len] = '\0';
+ pend = &p[len+2];
+ /*
+ } else if (*p == '[') {
+ int c = 1;
+ p++;
+ pend = p;
+ while (*pend && c != 0) {
+ if (*pend == '[') c++;
+ else if (*pend == ']') c--;
+ pend++;
+ }
+ if (c != 0) {
+ fprintf (stderr, "guestfish: unterminated \"[...]\" sequence\n");
+ if (!prompt) exit (1);
+ goto next_command;
+ }
+ if (*pend && (*pend != ' ' && *pend != '\t')) {
+ fprintf (stderr, "guestfish: command arguments not separated by whitespace\n");
+ if (!prompt) exit (1);
+ goto next_command;
+ }
+ *(pend-1) = '\0';
+ */
+ } else if (*p != ' ' && *p != '\t') {
+ len = strcspn (p, " \t");
+ if (p[len]) {
+ p[len] = '\0';
+ pend = &p[len+1];
+ } else
+ pend = &p[len];
+ } else {
+ fprintf (stderr, "guestfish: internal error parsing string at '%s'\n",
+ p);
+ abort ();
+ }
+
+ argv[i++] = p;
+ p = pend;
+
+ if (*p)
+ p += strspn (p, " \t");
+ }
+