Changeset e14a103 in mainline
- Timestamp:
- 2011-08-19T18:24:23Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- be61b8f
- Parents:
- 5992e0e
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/compl.c
r5992e0e re14a103 1 1 /* 2 2 * Copyright (c) 2011 Jiri Svoboda 3 * Copyright (c) 2011 Martin Sucha 3 4 * All rights reserved. 4 5 * … … 37 38 #include "compl.h" 38 39 #include "exec.h" 40 #include "tok.h" 39 41 40 42 static int compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state); … … 88 90 { 89 91 compl_t *cs = NULL; 90 size_t p;91 92 size_t pref_size; 92 93 char *stext = NULL; … … 96 97 static const char *dirlist_arg[] = { ".", NULL }; 97 98 int retval; 99 tokenizer_t tok; 100 token_t tokens[WORD_MAX]; 101 unsigned int current_token; 102 size_t tokens_length; 98 103 99 104 cs = calloc(1, sizeof(compl_t)); … … 103 108 } 104 109 105 /*106 * Copy token pointed to by caret from start up to the caret.107 * XXX Ideally we would use the standard tokenizer.108 */109 p = pos;110 while (p > 0 && text[p - 1] != (wchar_t) ' ')111 --p;112 *cstart = p;113 114 110 /* Convert text buffer to string */ 115 stext = wstr_to_astr(text + *cstart);111 stext = wstr_to_astr(text); 116 112 if (stext == NULL) { 117 113 retval = ENOMEM; 118 114 goto error; 119 115 } 120 121 /* Extract the prefix being completed */ 116 117 /* Tokenize the input string */ 118 retval = tok_init(&tok, stext, tokens, WORD_MAX); 119 if (retval != EOK) { 120 goto error; 121 } 122 123 retval = tok_tokenize(&tok, &tokens_length); 124 if (retval != EOK) { 125 goto error; 126 } 127 128 /* Find the current token */ 129 for (current_token = 0; current_token < tokens_length; current_token++) { 130 token_t *t = &tokens[current_token]; 131 size_t end = t->char_start + t->char_length; 132 /* Check if the caret lies inside the token or immediately 133 * after it 134 */ 135 if (t->char_start <= pos && pos <= end) { 136 break; 137 } 138 } 139 140 if (tokens[current_token].type != TOKTYPE_SPACE) { 141 *cstart = tokens[current_token].char_start; 142 } 143 else { 144 *cstart = pos; 145 } 146 147 /* Extract the prefix being completed 148 * XXX: handle strings, etc. 149 */ 122 150 pref_size = str_lsize(stext, pos - *cstart); 123 151 prefix = malloc(pref_size + 1); … … 127 155 } 128 156 129 str_ncpy(prefix, pref_size + 1, stext, pref_size); 157 str_ncpy(prefix, pref_size + 1, stext + 158 tokens[current_token].byte_start, pref_size); 130 159 131 160 /* … … 133 162 * We look at the previous token. If there is none or it is a pipe 134 163 * ('|'), it is a command, otherwise it is an argument. 135 * XXX Again we should use the standard tokenizer/parser.136 164 */ 137 165 138 166 /* Skip any whitespace before current token */ 139 while (p > 0 && text[p - 1] == (wchar_t) ' ') 140 --p; 167 int prev_token = current_token - 1; 168 if (prev_token != -1 && tokens[prev_token].type == TOKTYPE_SPACE) { 169 prev_token--; 170 } 141 171 142 172 /* … … 144 174 * follows a pipe token. 145 175 */ 146 if (p == 0 || text[p - 1] == '|')176 if (prev_token == -1 || tokens[prev_token].type == TOKTYPE_SPACE) 147 177 cs->is_command = true; 148 178 else … … 189 219 190 220 cs->prefix_len = str_length(cs->prefix); 221 222 tok_fini(&tok); 191 223 192 224 *state = cs; … … 195 227 error: 196 228 /* Error cleanup */ 229 230 tok_fini(&tok); 197 231 198 232 if (cs != NULL && cs->path_list != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.