Changeset a35b458 in mainline for uspace/app/bdsh/tok.c
- Timestamp:
- 2018-03-02T20:10:49Z (6 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f1380b7
- Parents:
- 3061bc1
- git-author:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-02-28 17:38:31)
- git-committer:
- Jiří Zárevúcky <zarevucky.jiri@…> (2018-03-02 20:10:49)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/tok.c
r3061bc1 ra35b458 59 59 tok->in_char_offset = 0; 60 60 tok->last_in_char_offset = 0; 61 61 62 62 tok->outtok = out_tokens; 63 63 tok->outtok_offset = 0; 64 64 tok->outtok_size = max_tokens; 65 65 66 66 /* Prepare a buffer where all the token strings will be stored */ 67 67 size_t len = str_size(input) + max_tokens + 1; 68 68 char *tmp = malloc(len); 69 69 70 70 if (tmp == NULL) { 71 71 return ENOMEM; 72 72 } 73 73 74 74 tok->outbuf = tmp; 75 75 tok->outbuf_offset = 0; 76 76 tok->outbuf_size = len; 77 77 tok->outbuf_last_start = 0; 78 78 79 79 return EOK; 80 80 } … … 93 93 errno_t rc; 94 94 wchar_t next_char; 95 95 96 96 /* Read the input line char by char and append tokens */ 97 97 while ((next_char = tok_look_char(tok)) != 0) { … … 113 113 } 114 114 tok_push_token(tok); 115 115 116 116 } 117 117 else if (next_char == '|') { … … 125 125 } 126 126 } 127 127 128 128 tok_start_token(tok, TOKTYPE_PIPE); 129 129 130 130 rc = tok_push_char(tok, tok_get_char(tok)); 131 131 if (rc != EOK) { 132 132 return rc; 133 133 } 134 134 135 135 rc = tok_push_token(tok); 136 136 if (rc != EOK) { … … 163 163 } 164 164 } 165 165 166 166 /* Push the last token */ 167 167 if (tok_pending_chars(tok)) { … … 171 171 } 172 172 } 173 173 174 174 *tokens_length = tok->outtok_offset; 175 175 176 176 return EOK; 177 177 } … … 182 182 errno_t rc; 183 183 wchar_t next_char; 184 184 185 185 while ((next_char = tok_look_char(tok)) != 0) { 186 186 if (next_char == '\'') { … … 193 193 return rc; 194 194 } 195 195 196 196 /* Swallow the additional one in the input */ 197 197 tok_get_char(tok); … … 209 209 } 210 210 } 211 211 212 212 /* If we are here, the string run to the end without being closed */ 213 213 return EINVAL; … … 249 249 return EOVERFLOW; 250 250 } 251 251 252 252 if (tok->outbuf_offset >= tok->outbuf_size) { 253 253 return EOVERFLOW; 254 254 } 255 255 256 256 tok->outbuf[tok->outbuf_offset++] = 0; 257 257 token_t *tokinfo = &tok->outtok[tok->outtok_offset++]; … … 263 263 tokinfo->char_length = tok->in_char_offset - tok->last_in_char_offset; 264 264 tok->outbuf_last_start = tok->outbuf_offset; 265 265 266 266 /* We have consumed the first char of the next token already */ 267 267 tok->last_in_offset = tok->in_offset; 268 268 tok->last_in_char_offset = tok->in_char_offset; 269 269 270 270 return EOK; 271 271 }
Note:
See TracChangeset
for help on using the changeset viewer.