Exemple #1
0
int cmdline_tokenize(char *string, char **argv) {
	int argc = 0;

	while (*string != '\0') {

		while (isspace(*string)) {
			string++;
		}

		if (*string == '\0') {
			break;
		} else if (*string == '\'') {
			argv[argc++] = parse_sq(&string);
		} else if (*string == '\"') {
			argv[argc++] = parse_dq(&string);
		} else {
			argv[argc++] = cmdline_next_token(&string);
		}

		if (*string) {
			*string++ = '\0';
		}
	}

	argv[argc] = NULL;

	return argc;
}
Exemple #2
0
/*
 * m_quote_capture() is similar to m_capture(), but it removes
 * quotes from either end of the string.
 */
void
m_quote_capture(char **str, int start, int end)
{
    int i, e;
    char *s;

    e = token[end].start_index + token[end].length - 1;
    *str = gp_realloc(*str, (e - token[start].start_index + 1), "string");
    s = *str;
    for (i = token[start].start_index + 1; i < e && gp_input_line[i] != NUL; i++)
	*s++ = gp_input_line[i];
    *s = NUL;

    if (gp_input_line[token[start].start_index] == '"')
	parse_esc(*str);
    else
        parse_sq(*str);

}
Exemple #3
0
/*
 * quote_str() does the same thing as copy_str, except it ignores the
 *   quotes at both ends.  This seems redundant, but is done for
 *   efficency.
 */
void
quote_str(char *str, int t_num, int max)
{
    int i = 0;
    int start = token[t_num].start_index + 1;
    int count;

    if ((count = token[t_num].length - 2) >= max) {
	count = max - 1;
	FPRINTF((stderr, "str buffer overflow in quote_str"));
    }
    if (count > 0) {
	do {
	    str[i++] = gp_input_line[start++];
	} while (i != count);
    }
    str[i] = NUL;
    /* convert \t and \nnn (octal) to char if in double quotes */
    if (gp_input_line[token[t_num].start_index] == '"')
	parse_esc(str);
    else
        parse_sq(str);
}