Changeset d4d8255 in mainline for kernel/generic/src/console/kconsole.c
- Timestamp:
- 2016-03-09T20:01:43Z (8 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c1b8ad4
- Parents:
- df425da (diff), dc0e41c (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/kconsole.c
rdf425da rd4d8255 165 165 166 166 /** Try to find a command beginning with prefix */ 167 NO_TRACE static const char *cmdtab_search_one(const char *name, 168 link_t **startpos) 169 { 167 const char *cmdtab_enum(const char *name, const char **h, void **ctx) 168 { 169 link_t **startpos = (link_t**)ctx; 170 170 size_t namelen = str_length(name); 171 171 … … 183 183 184 184 if (str_lcmp(curname, name, namelen) == 0) { 185 *startpos = (*startpos)->next; 186 if (h) { 187 *h = hlp->description; 188 } 185 189 spinlock_unlock(&cmd_lock); 186 190 return (curname + str_lsize(curname, namelen)); … … 200 204 * 201 205 */ 202 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev) 206 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev, 207 hints_enum_func_t hints_enum) 203 208 { 204 209 const char *name = input; … … 212 217 size_t max_match_len = size; 213 218 size_t max_match_len_tmp = size; 214 size_t input_len = str_length(input); 215 link_t *pos = NULL; 219 void *pos = NULL; 216 220 const char *hint; 221 const char *help; 217 222 char *output = malloc(MAX_CMDLINE, 0); 218 223 size_t hints_to_show = MAX_TAB_HINTS - 1; … … 222 227 output[0] = 0; 223 228 224 while ((hint = cmdtab_search_one(name, &pos))) {225 if ((found == 0) || (str_length( output) > str_length(hint)))229 while ((hint = hints_enum(name, NULL, &pos))) { 230 if ((found == 0) || (str_length(hint) > str_length(output))) 226 231 str_cpy(output, MAX_CMDLINE, hint); 227 232 228 pos = pos->next;229 233 found++; 230 234 } … … 243 247 printf("\n"); 244 248 pos = NULL; 245 while (cmdtab_search_one(name, &pos)) { 246 cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link); 249 while ((hint = hints_enum(name, &help, &pos))) { 247 250 248 251 if (continue_showing_hints) { 249 printf("%s (%s)\n", hlp->name, hlp->description); 252 253 if (help) 254 printf("%s%s (%s)\n", name, hint, help); 255 else 256 printf("%s%s\n", name, hint); 257 250 258 --hints_to_show; 251 259 ++total_hints_shown; … … 258 266 } 259 267 260 pos = pos->next;261 262 268 for (max_match_len_tmp = 0; 263 269 (output[max_match_len_tmp] == 264 h lp->name[input_len +max_match_len_tmp]) &&270 hint[max_match_len_tmp]) && 265 271 (max_match_len_tmp < max_match_len); ++max_match_len_tmp); 266 272 … … 277 283 free(output); 278 284 return found; 285 } 286 287 NO_TRACE static cmd_info_t *parse_cmd(const wchar_t *cmdline) 288 { 289 size_t start = 0; 290 size_t end; 291 char *tmp; 292 293 while (isspace(cmdline[start])) 294 start++; 295 end = start + 1; 296 while (!isspace(cmdline[end])) 297 end++; 298 299 tmp = malloc(STR_BOUNDS(end - start + 1), 0); 300 301 wstr_to_str(tmp, end - start + 1, &cmdline[start]); 302 303 spinlock_lock(&cmd_lock); 304 305 list_foreach(cmd_list, link, cmd_info_t, hlp) { 306 spinlock_lock(&hlp->lock); 307 308 if (str_cmp(hlp->name, tmp) == 0) { 309 spinlock_unlock(&hlp->lock); 310 spinlock_unlock(&cmd_lock); 311 free(tmp); 312 return hlp; 313 } 314 315 spinlock_unlock(&hlp->lock); 316 } 317 318 free(tmp); 319 spinlock_unlock(&cmd_lock); 320 321 return NULL; 279 322 } 280 323 … … 338 381 if (beg == 0) { 339 382 /* Command completion */ 340 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev); 383 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev, 384 cmdtab_enum); 341 385 } else { 342 /* Symbol completion */ 343 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev); 386 /* Arguments completion */ 387 cmd_info_t *cmd = parse_cmd(current); 388 if (!cmd || !cmd->hints_enum) 389 continue; 390 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev, 391 cmd->hints_enum); 344 392 } 345 393
Note:
See TracChangeset
for help on using the changeset viewer.