Changes in uspace/app/bdsh/compl.c [5935c079:e14a103] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/compl.c
r5935c079 re14a103 90 90 { 91 91 compl_t *cs = NULL; 92 size_t pref_size; 92 93 char *stext = NULL; 93 94 char *prefix = NULL; 94 95 char *dirname = NULL; 95 int retval;96 97 token_t *tokens = calloc(WORD_MAX, sizeof(token_t));98 if (tokens == NULL) {99 retval = ENOMEM;100 goto error;101 }102 103 size_t pref_size;104 96 char *rpath_sep; 105 97 static const char *dirlist_arg[] = { ".", NULL }; 98 int retval; 106 99 tokenizer_t tok; 107 ssize_t current_token; 100 token_t tokens[WORD_MAX]; 101 unsigned int current_token; 108 102 size_t tokens_length; 109 103 110 104 cs = calloc(1, sizeof(compl_t)); 111 105 if (!cs) { … … 113 107 goto error; 114 108 } 115 109 116 110 /* Convert text buffer to string */ 117 111 stext = wstr_to_astr(text); … … 133 127 134 128 /* Find the current token */ 135 for (current_token = 0; current_token < (ssize_t) tokens_length; 136 current_token++) { 129 for (current_token = 0; current_token < tokens_length; current_token++) { 137 130 token_t *t = &tokens[current_token]; 138 131 size_t end = t->char_start + t->char_length; 139 140 /* 141 * Check if the caret lies inside the token or immediately 132 /* Check if the caret lies inside the token or immediately 142 133 * after it 143 134 */ … … 147 138 } 148 139 149 if (tokens_length == 0) 150 current_token = -1; 151 152 if ((current_token >= 0) && (tokens[current_token].type != TOKTYPE_SPACE)) 140 if (tokens[current_token].type != TOKTYPE_SPACE) { 153 141 *cstart = tokens[current_token].char_start; 154 else 142 } 143 else { 155 144 *cstart = pos; 156 157 /*158 145 } 146 147 /* Extract the prefix being completed 159 148 * XXX: handle strings, etc. 160 149 */ … … 165 154 goto error; 166 155 } 167 prefix[pref_size] = 0; 168 169 if (current_token >= 0) { 170 str_ncpy(prefix, pref_size + 1, stext + 171 tokens[current_token].byte_start, pref_size); 172 } 156 157 str_ncpy(prefix, pref_size + 1, stext + 158 tokens[current_token].byte_start, pref_size); 173 159 174 160 /* … … 179 165 180 166 /* Skip any whitespace before current token */ 181 ssize_t prev_token = current_token - 1;182 if ( (prev_token >= 0) && (tokens[prev_token].type == TOKTYPE_SPACE))167 int prev_token = current_token - 1; 168 if (prev_token != -1 && tokens[prev_token].type == TOKTYPE_SPACE) { 183 169 prev_token--; 184 170 } 171 185 172 /* 186 173 * It is a command if it is the first token or if it immediately 187 174 * follows a pipe token. 188 175 */ 189 if ( (prev_token < 0) || (tokens[prev_token].type == TOKTYPE_SPACE))176 if (prev_token == -1 || tokens[prev_token].type == TOKTYPE_SPACE) 190 177 cs->is_command = true; 191 178 else … … 262 249 if (cs != NULL) 263 250 free(cs); 264 if (tokens != NULL)265 free(tokens);266 251 267 252 return retval;
Note:
See TracChangeset
for help on using the changeset viewer.