Changes in / [c2cf033:89660f2] in mainline
- Location:
- uspace/app/bdsh
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/tok.c
rc2cf033 r89660f2 50 50 * @param max_tokens number of elements of the out_tokens array 51 51 */ 52 int tok_init(tokenizer_t *tok, char *input, char **out_tokens,52 int tok_init(tokenizer_t *tok, char *input, token_t *out_tokens, 53 53 size_t max_tokens) 54 54 { 55 55 tok->in = input; 56 56 tok->in_offset = 0; 57 tok->last_in_offset = 0; 58 tok->in_char_offset = 0; 59 tok->last_in_char_offset = 0; 57 60 58 61 tok->outtok = out_tokens; … … 201 204 wchar_t tok_get_char(tokenizer_t *tok) 202 205 { 206 tok->in_char_offset++; 203 207 return str_decode(tok->in, &tok->in_offset, STR_NO_LIMIT); 204 208 } … … 207 211 wchar_t tok_look_char(tokenizer_t *tok) 208 212 { 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; 210 215 wchar_t ret = tok_get_char(tok); 211 216 tok->in_offset = old_offset; 217 tok->in_char_offset = old_char_offset; 212 218 return ret; 213 219 } … … 231 237 232 238 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] 234 247 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; 235 252 236 253 return EOK; -
uspace/app/bdsh/tok.h
rc2cf033 r89660f2 30 30 #define TOK_H 31 31 32 typedef enum { 33 TOKTYPE_TEXT, 34 TOKTYPE_PIPE, 35 TOKTYPE_SPACE 36 } token_type_t; 37 38 typedef 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 32 47 typedef struct { 33 48 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; 35 53 36 54 char *outbuf; … … 39 57 size_t outbuf_last_start; 40 58 41 char **outtok;59 token_t *outtok; 42 60 size_t outtok_offset; 43 61 size_t outtok_size; 44 62 } tokenizer_t; 45 63 46 extern int tok_init(tokenizer_t *, char *, char **, size_t);64 extern int tok_init(tokenizer_t *, char *, token_t *, size_t); 47 65 extern void tok_fini(tokenizer_t *); 48 66 extern int tok_tokenize(tokenizer_t *);
Note:
See TracChangeset
for help on using the changeset viewer.