Changeset 5992e0e in mainline for uspace/app/bdsh/tok.c
- Timestamp:
- 2011-08-19T18:20:04Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- e14a103
- Parents:
- 0662451
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/tok.c
r0662451 r5992e0e 92 92 { 93 93 int rc; 94 wchar_t cur_char;94 wchar_t next_char; 95 95 96 96 /* 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 == ' ') { 99 99 /* Push the token if there is any. 100 100 * There may not be any pending char for a token in case … … 108 108 } 109 109 tok_start_token(tok, TOKTYPE_SPACE); 110 /* Eat all spaces */110 /* Eat all the spaces */ 111 111 while (tok_look_char(tok) == ' ') { 112 112 tok_push_char(tok, tok_get_char(tok)); … … 115 115 116 116 } 117 else if ( cur_char == '|') {118 /* Pipes are tokens that are delimiters and should be output119 * as a separate token117 else if (next_char == '|') { 118 /* Pipes are tokens that are delimiters and should be 119 * output as a separate token 120 120 */ 121 121 if (tok_pending_chars(tok)) { … … 128 128 tok_start_token(tok, TOKTYPE_PIPE); 129 129 130 rc = tok_push_char(tok, '|');130 rc = tok_push_char(tok, tok_get_char(tok)); 131 131 if (rc != EOK) { 132 132 return rc; … … 138 138 } 139 139 } 140 else if ( cur_char == '\'') {140 else if (next_char == '\'') { 141 141 /* A string starts with a quote (') and ends again with a quote. 142 142 * A literal quote is written as '' 143 143 */ 144 144 tok_start_token(tok, TOKTYPE_TEXT); 145 /* Eat the quote */ 146 tok_get_char(tok); 145 147 rc = tok_finish_string(tok); 146 148 if (rc != EOK) { … … 155 157 * the current token. 156 158 */ 157 rc = tok_push_char(tok, cur_char);159 rc = tok_push_char(tok, tok_get_char(tok)); 158 160 if (rc != EOK) { 159 161 return rc; … … 179 181 { 180 182 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); 185 189 if (tok_look_char(tok) == '\'') { 186 190 /* Encode a single literal quote */ … … 199 203 } 200 204 else { 201 rc = tok_push_char(tok, cur_char);205 rc = tok_push_char(tok, tok_get_char(tok)); 202 206 if (rc != EOK) { 203 207 return rc; … … 255 259 tokinfo->text = tok->outbuf + tok->outbuf_last_start; 256 260 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; 258 262 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; 261 264 tok->outbuf_last_start = tok->outbuf_offset; 262 265 263 266 /* 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; 266 269 267 270 return EOK;
Note:
See TracChangeset
for help on using the changeset viewer.