libs/stream_message/src/startprocess.cxx
// ===========================================================================
// To manage a command line on Unix, it is necessary to transform a
// single string into a list of strings.  The arguments found in cmdline
// are appended to the given cmdargs list.
//
// Backslashes, single-quotes, and double-quotes are respected.
// 
To manage a command line on Unix, it is necessary to transform a
single string into a list of strings.  The arguments found in cmdline
are appended to the given cmdargs list.

Backslashes, single-quotes, and double-quotes are respected.
To manage a command line on Unix it is necessary to transform a single string into a list of strings . The arguments found in cmdline are appended to the given cmdargs list . Backslashes single - quotes and double - quotes are respected .
void MBDriver::determine_command_arguments(const string &cmdline,
					   list<string> &cmdargs) {
    const char *p = cmdline.c_str();
    const char *start = NULL;
    string arg;
    char in_quote = '\0';
    for (;;) {
        const char ch = *p;
        if (start != NULL && (ch == '\0' || (ch == ' ' && in_quote == '\0'))) {
	    arg.append(start, p - start);
	    cmdargs.push_back(arg);
	    start = NULL;
	}
	if (ch == '\0') {
	    break;
	}
	if (start == NULL && !(ch == ' ' || ch == '\t')) {
	    start = p;
	    arg = "";
	}
	if (start == NULL) {
	}
	else if (in_quote == '\'') {
	    if (ch == '\\' && p[1] == '\\') {
		arg.append(start, p - start);
		start = p + 1;
		p = start;
	    }
	    else if (ch == '\'') {
		in_quote = '\0';
		arg.append(start, p - start);
		start = p + 1;
	    }
	    else {
	    }
	}
	else if (in_quote == '"') {
	    if (ch == '\\' && (p[1] != '\'' && p[1] != '\0')) {
		arg.append(start, p - start);
		start = p + 1;
		p = start;
	    }
	    else if (ch == '"') {
		in_quote = '\0';
		arg.append(start, p - start);
		start = p + 1;
	    }
	    else {
	    }
	}
	else if (ch == '\\' && p[1] != '\0') {
	    arg.append(start, p - start);
	    start = p + 1;
	    p = start;
	}
	else if (ch == '"') {
	    in_quote = ch;
	    arg.append(start, p - start);
	    start = p + 1;
	}
	else if (ch == '\'') {
	    in_quote = ch;
	    arg.append(start, p - start);
	    start = p + 1;
	}
	p += 1;
    }
}
void MBDriver :: determine_command_arguments ( const string & cmdline , list < string > & cmdargs ) { const char * p = cmdline . c_str ( ) ; const char * start = NULL ; string arg ; char in_quote = ' \0 ' ; for ( ; ; ) { const char ch = * p ; if ( start != NULL && ( ch == ' \0 ' || ( ch == ' ' && in_quote == ' \0 ' ) ) ) { arg . append ( start , p - start ) ; cmdargs . push_back ( arg ) ; start = NULL ; } if ( ch == ' \0 ' ) { break ; } if ( start == NULL && ! ( ch == ' ' || ch == ' \t ' ) ) { start = p ; arg = " " ; } if ( start == NULL ) { } else if ( in_quote == ' \' ' ) { if ( ch == ' \\ ' && p [ 1 ] == ' \\ ' ) { arg . append ( start , p - start ) ; start = p + 1 ; p = start ; } else if ( ch == ' \' ' ) { in_quote = ' \0 ' ; arg . append ( start , p - start ) ; start = p + 1 ; } else { } } else if ( in_quote == ' ' ) { if ( ch == ' \\ ' && ( p [ 1 ] != ' \' ' && p [ 1 ] != ' \0 ' ) ) { arg . append ( start , p - start ) ; start = p + 1 ; p = start ; } else if ( ch == ' ' ) { in_quote = ' \0 ' ; arg . append ( start , p - start ) ; start = p + 1 ; } else { } } else if ( ch == ' \\ ' && p [ 1 ] != ' \0 ' ) { arg . append ( start , p - start ) ; start = p + 1 ; p = start ; } else if ( ch == ' ' ) { in_quote = ch ; arg . append ( start , p - start ) ; start = p + 1 ; } else if ( ch == ' \' ' ) { in_quote = ch ; arg . append ( start , p - start ) ; start = p + 1 ; } p += 1 ; } }
To manage a command line on Unix, it is necessary to transform a
single string into a list of strings.
To manage a command line on Unix it is necessary to transform a single string into a list of strings .
// p points to the current command line character being examined. // start indicates the beginning of the string which needs to be // copied to the argument. // Wait for a non-whitespace character. // Accept ch. // Accept ch.