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