frontend/console/parser.c
/*
 * Function that parses a text string and returns a NULL separated
 * string with the translated result.
 */
Function that parses a text string and returns a NULL separated
string with the translated result.
Function that parses a text string and returns a NULL separated string with the translated result .
static char *
parse(const char *text) {
    int len = strlen(text);
    char *out = malloc(len + 1);
    int i;
    parser_mode mode = PARSER_NORMAL;
    out[len] = '\0';
    for (i = 0; i < len; i++) {
        if (mode & PARSER_ESCAPE) {
            if (text[i] == ' ' ||
                text[i] == '\"') {
                out[i] = text[i];
            } else {
                lprintf(LOG_ERROR,
                        "Unknown escape code received in parser.\n");
            }
        } else {
            if (text[i] == '\\')
                mode |= PARSER_ESCAPE;
            else if (text[i] == '\"')
                mode ^= PARSER_QUOTE;
            else if (!(mode & PARSER_QUOTE) &&
                     isspace((int)text[i])) {
                out[i] = '\0';
            } else {
                out[i] = text[i];
            }
        }
    }
    return out;
}
static char * parse ( const char * text ) { int len = strlen ( text ) ; char * out = malloc ( len + 1 ) ; int i ; parser_mode mode = PARSER_NORMAL ; out [ len ] = ' \0 ' ; for ( i = 0 ; i < len ; i ++ ) { if ( mode & PARSER_ESCAPE ) { if ( text [ i ] == ' ' || text [ i ] == ' \" ' ) { out [ i ] = text [ i ] ; } else { lprintf ( LOG_ERROR , " \n " ) ; } } else { if ( text [ i ] == ' \\ ' ) mode |= PARSER_ESCAPE ; else if ( text [ i ] == ' \" ' ) mode ^= PARSER_QUOTE ; else if ( ! ( mode & PARSER_QUOTE ) && isspace ( ( int ) text [ i ] ) ) { out [ i ] = ' \0 ' ; } else { out [ i ] = text [ i ] ; } } } return out ; }
Function that parses a text string and returns a NULL separated
 string with the translated result.
Function that parses a text string and returns a NULL separated string with the translated result .