Changes in uspace/app/bdsh/compl.c [e14a103:41ff85b] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/compl.c
re14a103 r41ff85b 1 1 /* 2 2 * Copyright (c) 2011 Jiri Svoboda 3 * Copyright (c) 2011 Martin Sucha4 3 * All rights reserved. 5 4 * … … 38 37 #include "compl.h" 39 38 #include "exec.h" 40 #include "tok.h"41 39 42 40 static int compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state); … … 90 88 { 91 89 compl_t *cs = NULL; 90 size_t p; 92 91 size_t pref_size; 93 92 char *stext = NULL; … … 97 96 static const char *dirlist_arg[] = { ".", NULL }; 98 97 int retval; 99 tokenizer_t tok;100 token_t tokens[WORD_MAX];101 unsigned int current_token;102 size_t tokens_length;103 98 104 99 cs = calloc(1, sizeof(compl_t)); … … 108 103 } 109 104 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 110 114 /* Convert text buffer to string */ 111 stext = wstr_to_astr(text );115 stext = wstr_to_astr(text + *cstart); 112 116 if (stext == NULL) { 113 117 retval = ENOMEM; 114 118 goto error; 115 119 } 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 */ 120 121 /* Extract the prefix being completed */ 150 122 pref_size = str_lsize(stext, pos - *cstart); 151 123 prefix = malloc(pref_size + 1); … … 155 127 } 156 128 157 str_ncpy(prefix, pref_size + 1, stext + 158 tokens[current_token].byte_start, pref_size); 129 str_ncpy(prefix, pref_size + 1, stext, pref_size); 159 130 160 131 /* … … 162 133 * We look at the previous token. If there is none or it is a pipe 163 134 * ('|'), it is a command, otherwise it is an argument. 135 * XXX Again we should use the standard tokenizer/parser. 164 136 */ 165 137 166 138 /* Skip any whitespace before current token */ 167 int prev_token = current_token - 1; 168 if (prev_token != -1 && tokens[prev_token].type == TOKTYPE_SPACE) { 169 prev_token--; 170 } 139 while (p > 0 && text[p - 1] == (wchar_t) ' ') 140 --p; 171 141 172 142 /* … … 174 144 * follows a pipe token. 175 145 */ 176 if (p rev_token == -1 || tokens[prev_token].type == TOKTYPE_SPACE)146 if (p == 0 || text[p - 1] == '|') 177 147 cs->is_command = true; 178 148 else … … 219 189 220 190 cs->prefix_len = str_length(cs->prefix); 221 222 tok_fini(&tok);223 191 224 192 *state = cs; … … 227 195 error: 228 196 /* Error cleanup */ 229 230 tok_fini(&tok);231 197 232 198 if (cs != NULL && cs->path_list != NULL) {
Note:
See TracChangeset
for help on using the changeset viewer.