frontend/console/parser.c
/*
 * Function that parses and splits text and creates an
 * array with with string pointers in *out. Returns
 * the number of tokens.
 *
 * The caller is responsible for freeing up the memory
 * in (*out)[n].
 */
Function that parses and splits text and creates an
array with with string pointers in *out. Returns
the number of tokens.

The caller is responsible for freeing up the memory
in (*out)[n].
Function that parses and splits text and creates an array with with string pointers in * out . Returns the number of tokens . The caller is responsible for freeing up the memory in ( * out ) [ n ] .
static int
split(const char *text, char ***out) {
    int i;
    int num_tokens = 0;
    token_list* tokens = NULL;
    token_list* t = NULL;
    char* parsed = parse(text);
    int len = strlen(text);
    int t_len;
    for (i = 0; i < len; i++) {
        t_len = strlen(&parsed[i]);
        if (t_len == 0)
            continue;
        if (t == NULL) {
            tokens = malloc(sizeof(token_list));
            t = tokens;
        } else {
            t->n = malloc(sizeof(token_list));
            t = t->n;
        }
        t->n = NULL;
        t->l = t_len;
        t->t = &parsed[i];
        i += t->l;
        num_tokens++;
    }
    *out = malloc(sizeof(char*) * num_tokens);
    t = tokens;
    for (i = 0; t; i++) {
        (*out)[i] = malloc(t->l + 1);
        memcpy((*out)[i], t->t, t->l + 1);
        t = t->n;
    }
    free(parsed);
    return num_tokens;
}
static int split ( const char * text , char * * * out ) { int i ; int num_tokens = 0 ; token_list * tokens = NULL ; token_list * t = NULL ; char * parsed = parse ( text ) ; int len = strlen ( text ) ; int t_len ; for ( i = 0 ; i < len ; i ++ ) { t_len = strlen ( & parsed [ i ] ) ; if ( t_len == 0 ) continue ; if ( t == NULL ) { tokens = malloc ( sizeof ( token_list ) ) ; t = tokens ; } else { t -> n = malloc ( sizeof ( token_list ) ) ; t = t -> n ; } t -> n = NULL ; t -> l = t_len ; t -> t = & parsed [ i ] ; i += t -> l ; num_tokens ++ ; } * out = malloc ( sizeof ( char * ) * num_tokens ) ; t = tokens ; for ( i = 0 ; t ; i ++ ) { ( * out ) [ i ] = malloc ( t -> l + 1 ) ; memcpy ( ( * out ) [ i ] , t -> t , t -> l + 1 ) ; t = t -> n ; } free ( parsed ) ; return num_tokens ; }
Function that parses and splits text and creates an
 array with with string pointers in *out.
Function that parses and splits text and creates an array with with string pointers in * out .