Changes in uspace/app/bdsh/compl.c [587867a:ac2caecb] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/bdsh/compl.c
r587867a rac2caecb 35 35 #include <vfs/vfs.h> 36 36 #include <str.h> 37 37 #include <adt/odict.h> 38 39 #include "scli.h" 38 40 #include "cmds/cmds.h" 39 41 #include "compl.h" 40 42 #include "exec.h" 41 43 #include "tok.h" 42 #include "util.h"43 44 44 45 static errno_t compl_init(wchar_t *text, size_t pos, size_t *cstart, void **state); … … 63 64 /** Length of string prefix (number of characters) */ 64 65 size_t prefix_len; 66 67 /* Pointer to the current alias */ 68 odlink_t *alias_link; 65 69 66 70 /** Pointer inside list of modules */ … … 210 214 } 211 215 *cstart += rpath_sep + 1 - prefix; 216 free(prefix); 217 prefix = NULL; 212 218 213 219 cs->path_list = malloc(sizeof(char *) * 2); … … 216 222 goto error; 217 223 } 218 219 if (!is_path(prefix) && cs->is_command) { 220 cs->path_list[0] = malloc(sizeof(char) * PATH_MAX); 221 if (cs->path_list[0] == NULL) { 222 retval = ENOMEM; 223 goto error; 224 } 225 226 int ret = snprintf(cs->path_list[0], PATH_MAX, "%s/%s", search_dir[0], dirname); 227 if (ret < 0 || ret >= PATH_MAX) { 228 retval = ENOMEM; 229 goto error; 230 } 231 } else { 232 cs->path_list[0] = dirname; 233 } 234 235 free(prefix); 224 cs->path_list[0] = dirname; 236 225 cs->path_list[1] = NULL; 237 226 /* … … 243 232 } else if (cs->is_command) { 244 233 /* Command without path */ 234 cs->alias_link = odict_first(&alias_dict); 245 235 cs->module = modules; 246 236 cs->builtin = builtins; … … 321 311 } 322 312 313 /* Alias */ 314 if (cs->alias_link != NULL) { 315 while (*compl == NULL && cs->alias_link != NULL) { 316 alias_t *data = odict_get_instance(cs->alias_link, alias_t, odict); 317 if (compl_match_prefix(cs, data->name)) { 318 asprintf(compl, "%s ", data->name); 319 cs->last_compl = *compl; 320 if (*compl == NULL) 321 return ENOMEM; 322 } 323 cs->alias_link = odict_next(cs->alias_link, &alias_dict); 324 } 325 } 326 323 327 /* Modules */ 324 328 if (cs->module != NULL) { 325 329 while (*compl == NULL && cs->module->name != NULL) { 330 /* prevents multiple listing of an overriden cmd */ 326 331 if (compl_match_prefix(cs, cs->module->name)) { 327 asprintf(compl, "%s ", cs->module->name); 328 cs->last_compl = *compl; 329 if (*compl == NULL) 330 return ENOMEM; 332 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cs->module->name, NULL); 333 if (alias_link == NULL) { 334 asprintf(compl, "%s ", cs->module->name); 335 cs->last_compl = *compl; 336 if (*compl == NULL) 337 return ENOMEM; 338 } 331 339 } 332 340 cs->module++; … … 338 346 while (*compl == NULL && cs->builtin->name != NULL) { 339 347 if (compl_match_prefix(cs, cs->builtin->name)) { 340 asprintf(compl, "%s ", cs->builtin->name); 341 cs->last_compl = *compl; 342 if (*compl == NULL) 343 return ENOMEM; 348 /* prevents multiple listing of an overriden cmd */ 349 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)cs->module->name, NULL); 350 if (alias_link == NULL) { 351 asprintf(compl, "%s ", cs->builtin->name); 352 cs->last_compl = *compl; 353 if (*compl == NULL) 354 return ENOMEM; 355 } 344 356 } 345 357 cs->builtin++; … … 389 401 free(ent_path); 390 402 403 /* prevents multiple listing of an overriden cmd */ 404 if (cs->is_command && !ent_stat.is_directory) { 405 odlink_t *alias_link = odict_find_eq(&alias_dict, (void *)dent->d_name, NULL); 406 if (alias_link != NULL) { 407 continue; 408 } 409 } 410 391 411 asprintf(compl, "%s%c", dent->d_name, 392 412 ent_stat.is_directory ? '/' : ' ');
Note:
See TracChangeset
for help on using the changeset viewer.