asm/lex.c
char *token_between(
        const struct Token *start,
        const struct Token *end,
        char *buf,
        usize n
    ) {
    // count total number of tokens, inclusive
    const struct Token *t = start;
    usize num_tokens = 0;
    while (t != end->next) {
        num_tokens++;
        t = t->next;
    }

    // count characters in each token, including whitespace/ignored chars after
    char *p;
    usize i = 0, j = 0, len = 0, lens[num_tokens];
    t = start;
    while (t != end->next) {
        j = 0;
        while ((p = strchr(" ,\t", t->data[t->len + j])) && *p != '\0') {
            j++;
        }

        lens[i] = t->len + j;
        len += lens[i];
        i++;
        t = t->next;
    }

    if (buf == NULL) {
        buf = asmalloc(len + 1);
    } else if (len + 1 > n) {
        return NULL;
    }

    // copy into buffer
    i = 0;
    len = 0;
    t = start;
    while (t != end->next) {
        memcpy(&buf[len], t->data, lens[i]);
        len += lens[i];
        i++;
        t = t->next;
    }

    buf[len] = '\0';
    return buf;
}
// retrieves the string data between start and end (inclusive) into buf of size
// n. if buf is NULL, a buffer of adequate size is asmalloc'd and returned.
// returns NULL on failure.
retrieves the string data between start and end (inclusive) into buf of size
n. if buf is NULL, a buffer of adequate size is asmalloc'd and returned.
returns NULL on failure.
retrieves the string data between start and end ( inclusive ) into buf of size n . if buf is NULL a buffer of adequate size is asmalloc ' d and returned . returns NULL on failure .
char *token_between(
        const struct Token *start,
        const struct Token *end,
        char *buf,
        usize n
    ) {
    const struct Token *t = start;
    usize num_tokens = 0;
    while (t != end->next) {
        num_tokens++;
        t = t->next;
    }
    char *p;
    usize i = 0, j = 0, len = 0, lens[num_tokens];
    t = start;
    while (t != end->next) {
        j = 0;
        while ((p = strchr(" ,\t", t->data[t->len + j])) && *p != '\0') {
            j++;
        }
        lens[i] = t->len + j;
        len += lens[i];
        i++;
        t = t->next;
    }
    if (buf == NULL) {
        buf = asmalloc(len + 1);
    } else if (len + 1 > n) {
        return NULL;
    }
    i = 0;
    len = 0;
    t = start;
    while (t != end->next) {
        memcpy(&buf[len], t->data, lens[i]);
        len += lens[i];
        i++;
        t = t->next;
    }
    buf[len] = '\0';
    return buf;
}
char * token_between ( const struct Token * start , const struct Token * end , char * buf , usize n ) { const struct Token * t = start ; usize num_tokens = 0 ; while ( t != end -> next ) { num_tokens ++ ; t = t -> next ; } char * p ; usize i = 0 , j = 0 , len = 0 , lens [ num_tokens ] ; t = start ; while ( t != end -> next ) { j = 0 ; while ( ( p = strchr ( " \t " , t -> data [ t -> len + j ] ) ) && * p != ' \0 ' ) { j ++ ; } lens [ i ] = t -> len + j ; len += lens [ i ] ; i ++ ; t = t -> next ; } if ( buf == NULL ) { buf = asmalloc ( len + 1 ) ; } else if ( len + 1 > n ) { return NULL ; } i = 0 ; len = 0 ; t = start ; while ( t != end -> next ) { memcpy ( & buf [ len ] , t -> data , lens [ i ] ) ; len += lens [ i ] ; i ++ ; t = t -> next ; } buf [ len ] = ' \0 ' ; return buf ; }
retrieves the string data between start and end (inclusive) into buf of size
n. if buf is NULL, a buffer of adequate size is asmalloc'd and returned.
retrieves the string data between start and end ( inclusive ) into buf of size n . if buf is NULL a buffer of adequate size is asmalloc ' d and returned .
// count total number of tokens, inclusive // count characters in each token, including whitespace/ignored chars after // copy into buffer