Changeset 5992e0e in mainline


Ignore:
Timestamp:
2011-08-19T18:20:04Z (13 years ago)
Author:
Martin Sucha <sucha14@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e14a103
Parents:
0662451
Message:

Fix bdsh tokenizer

File:
1 edited

Legend:

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

    r0662451 r5992e0e  
    9292{
    9393        int rc;
    94         wchar_t cur_char;
     94        wchar_t next_char;
    9595       
    9696        /* Read the input line char by char and append tokens */
    97         while ((cur_char = tok_get_char(tok)) != 0) {
    98                 if (cur_char == ' ') {
     97        while ((next_char = tok_look_char(tok)) != 0) {
     98                if (next_char == ' ') {
    9999                        /* Push the token if there is any.
    100100                         * There may not be any pending char for a token in case
     
    108108                        }
    109109                        tok_start_token(tok, TOKTYPE_SPACE);
    110                         /* Eat all spaces */
     110                        /* Eat all the spaces */
    111111                        while (tok_look_char(tok) == ' ') {
    112112                                tok_push_char(tok, tok_get_char(tok));
     
    115115                       
    116116                }
    117                 else if (cur_char == '|') {
    118                         /* Pipes are tokens that are delimiters and should be output
    119                          * as a separate token
     117                else if (next_char == '|') {
     118                        /* Pipes are tokens that are delimiters and should be
     119                         * output as a separate token
    120120                         */
    121121                        if (tok_pending_chars(tok)) {
     
    128128                        tok_start_token(tok, TOKTYPE_PIPE);
    129129                       
    130                         rc = tok_push_char(tok, '|');
     130                        rc = tok_push_char(tok, tok_get_char(tok));
    131131                        if (rc != EOK) {
    132132                                return rc;
     
    138138                        }
    139139                }
    140                 else if (cur_char == '\'') {
     140                else if (next_char == '\'') {
    141141                        /* A string starts with a quote (') and ends again with a quote.
    142142                         * A literal quote is written as ''
    143143                         */
    144144                        tok_start_token(tok, TOKTYPE_TEXT);
     145                        /* Eat the quote */
     146                        tok_get_char(tok);
    145147                        rc = tok_finish_string(tok);
    146148                        if (rc != EOK) {
     
    155157                         * the current token.
    156158                         */
    157                         rc = tok_push_char(tok, cur_char);
     159                        rc = tok_push_char(tok, tok_get_char(tok));
    158160                        if (rc != EOK) {
    159161                                return rc;
     
    179181{
    180182        int rc;
    181         wchar_t cur_char;
    182        
    183         while ((cur_char = tok_get_char(tok)) != 0) {
    184                 if (cur_char == '\'') {
     183        wchar_t next_char;
     184       
     185        while ((next_char = tok_look_char(tok)) != 0) {
     186                if (next_char == '\'') {
     187                        /* Eat the quote */
     188                        tok_get_char(tok);
    185189                        if (tok_look_char(tok) == '\'') {
    186190                                /* Encode a single literal quote */
     
    199203                }
    200204                else {
    201                         rc = tok_push_char(tok, cur_char);
     205                        rc = tok_push_char(tok, tok_get_char(tok));
    202206                        if (rc != EOK) {
    203207                                return rc;
     
    255259        tokinfo->text = tok->outbuf + tok->outbuf_last_start;
    256260        tokinfo->byte_start = tok->last_in_offset;
    257         tokinfo->byte_length = tok->in_offset - tok->last_in_offset - 1;
     261        tokinfo->byte_length = tok->in_offset - tok->last_in_offset;
    258262        tokinfo->char_start = tok->last_in_char_offset;
    259         tokinfo->char_length = tok->in_char_offset - tok->last_in_char_offset
    260             - 1;
     263        tokinfo->char_length = tok->in_char_offset - tok->last_in_char_offset;
    261264        tok->outbuf_last_start = tok->outbuf_offset;
    262265       
    263266        /* We have consumed the first char of the next token already */
    264         tok->last_in_offset = tok->in_offset-1;
    265         tok->last_in_char_offset = tok->in_char_offset-1;
     267        tok->last_in_offset = tok->in_offset;
     268        tok->last_in_char_offset = tok->in_char_offset;
    266269       
    267270        return EOK;
Note: See TracChangeset for help on using the changeset viewer.