Changeset 7dcb7981 in mainline


Ignore:
Timestamp:
2011-08-19T11:35:08Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
89660f2
Parents:
42a619b
Message:

Change bdsh tokenizer

Location:
uspace/app/bdsh
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • uspace/app/bdsh/tok.c

    r42a619b r7dcb7981  
    5050 * @param max_tokens number of elements of the out_tokens array
    5151 */
    52 int tok_init(tokenizer_t *tok, char *input, char **out_tokens,
     52int tok_init(tokenizer_t *tok, char *input, token_t *out_tokens,
    5353    size_t max_tokens)
    5454{       
    5555        tok->in = input;
    5656        tok->in_offset = 0;
     57        tok->last_in_offset = 0;
     58        tok->in_char_offset = 0;
     59        tok->last_in_char_offset = 0;
    5760       
    5861        tok->outtok = out_tokens;
     
    201204wchar_t tok_get_char(tokenizer_t *tok)
    202205{
     206        tok->in_char_offset++;
    203207        return str_decode(tok->in, &tok->in_offset, STR_NO_LIMIT);
    204208}
     
    207211wchar_t tok_look_char(tokenizer_t *tok)
    208212{
    209         size_t old_offset = tok->in_offset;
     213        off_t old_offset = tok->in_offset;
     214        off_t old_char_offset = tok->in_char_offset;
    210215        wchar_t ret = tok_get_char(tok);
    211216        tok->in_offset = old_offset;
     217        tok->in_char_offset = old_char_offset;
    212218        return ret;
    213219}
     
    231237       
    232238        tok->outbuf[tok->outbuf_offset++] = 0;
    233         tok->outtok[tok->outtok_offset++] = tok->outbuf + tok->outbuf_last_start;
     239        token_t *tokinfo = &tok->outtok[tok->outtok_offset++]
     240        tokinfo.text = tok->outbuf + tok->outbuf_last_start;
     241        tokinfo.byte_start = tok->last_in_offset;
     242        tokinfo.byte_length = tok->in_offset - tok->last_in_offset - 1;
     243        tokinfo.char_start = tok->last_in_char_offset;
     244        tokinfo.char_length = tok->in_char_offset - tok->last_in_char_offset
     245            - 1;
     246        tok->outtok[tok->outtok_offset]
    234247        tok->outbuf_last_start = tok->outbuf_offset;
     248       
     249        /* We have consumed the first char of the next token already */
     250        tok->last_in_offset = tok->in_offset-1;
     251        tok->last_in_char_offset = tok->in_char_offset-1;
    235252       
    236253        return EOK;
  • uspace/app/bdsh/tok.h

    r42a619b r7dcb7981  
    3030#define TOK_H
    3131
     32typedef enum {
     33        TOKTYPE_TEXT,
     34        TOKTYPE_PIPE,
     35        TOKTYPE_SPACE
     36} token_type_t;
     37
     38typedef struct {
     39        char *text;
     40        off_t byte_start;
     41        off_t char_start;
     42        size_t byte_length;
     43        size_t char_length;
     44        token_type_t type;
     45} token_t;
     46
    3247typedef struct {
    3348        char *in;
    34         size_t in_offset;
     49        off_t in_offset;
     50        off_t last_in_offset;
     51        off_t in_char_offset;
     52        off_t last_in_char_offset;
    3553       
    3654        char *outbuf;
     
    3957        size_t outbuf_last_start;
    4058       
    41         char **outtok;
     59        token_t *outtok;
    4260        size_t outtok_offset;
    4361        size_t outtok_size;
    4462} tokenizer_t;
    4563
    46 extern int tok_init(tokenizer_t *, char *, char **, size_t);
     64extern int tok_init(tokenizer_t *, char *, token_t *, size_t);
    4765extern void tok_fini(tokenizer_t *);
    4866extern int tok_tokenize(tokenizer_t *);
Note: See TracChangeset for help on using the changeset viewer.