Changes in kernel/generic/src/console/kconsole.c [9b11a971:059a8e4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/kconsole.c
r9b11a971 r059a8e4 43 43 #include <console/chardev.h> 44 44 #include <console/cmd.h> 45 #include <console/prompt.h>46 45 #include <print.h> 47 46 #include <panic.h> … … 202 201 * 203 202 */ 204 NO_TRACE static int cmdtab_compl(char *input, size_t size , indev_t *indev)203 NO_TRACE static int cmdtab_compl(char *input, size_t size) 205 204 { 206 205 const char *name = input; 207 206 208 207 size_t found = 0; 209 210 /*211 * Maximum Match Length: Length of longest matching common212 * substring in case more than one match is found.213 */214 size_t max_match_len = size;215 size_t max_match_len_tmp = size;216 size_t input_len = str_length(input);217 208 link_t *pos = NULL; 218 209 const char *hint; 219 210 char *output = malloc(MAX_CMDLINE, 0); 220 size_t hints_to_show = MAX_TAB_HINTS - 1;221 size_t total_hints_shown = 0;222 bool continue_showing_hints = true;223 211 224 212 output[0] = 0; … … 230 218 pos = pos->next; 231 219 found++; 232 }233 234 /*235 * If the number of possible completions is more than MAX_TAB_HINTS,236 * ask the user whether to display them or not.237 */238 if (found > MAX_TAB_HINTS) {239 printf("\n");240 continue_showing_hints =241 console_prompt_display_all_hints(indev, found);242 220 } 243 221 … … 247 225 while (cmdtab_search_one(name, &pos)) { 248 226 cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link); 249 250 if (continue_showing_hints) { 251 printf("%s (%s)\n", hlp->name, hlp->description); 252 --hints_to_show; 253 ++total_hints_shown; 254 255 if ((hints_to_show == 0) && (total_hints_shown != found)) { 256 /* Ask user to continue */ 257 continue_showing_hints = 258 console_prompt_more_hints(indev, &hints_to_show); 259 } 260 } 261 227 printf("%s (%s)\n", hlp->name, hlp->description); 262 228 pos = pos->next; 263 264 for (max_match_len_tmp = 0; 265 (output[max_match_len_tmp] == 266 hlp->name[input_len + max_match_len_tmp]) && 267 (max_match_len_tmp < max_match_len); ++max_match_len_tmp); 268 269 max_match_len = max_match_len_tmp; 270 } 271 272 /* Keep only the characters common in all completions */ 273 output[max_match_len] = 0; 229 } 274 230 } 275 231 … … 324 280 continue; 325 281 326 /* 327 * Find the beginning of the word 328 * and copy it to tmp 329 */ 282 /* Find the beginning of the word 283 and copy it to tmp */ 330 284 size_t beg; 331 285 for (beg = position - 1; (beg > 0) && (!isspace(current[beg])); … … 340 294 if (beg == 0) { 341 295 /* Command completion */ 342 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE) , indev);296 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE)); 343 297 } else { 344 298 /* Symbol completion */ 345 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE) , indev);299 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE)); 346 300 } 347 301 348 302 if (found == 0) 349 303 continue; 350 351 /* 352 * We have hints, possibly many. In case of more than one hint, 353 * tmp will contain the common prefix. 354 */ 304 305 if (found > 1) { 306 /* No unique hint, list was printed */ 307 printf("%s> ", prompt); 308 printf("%ls", current); 309 print_cc('\b', wstr_length(current) - position); 310 continue; 311 } 312 313 /* We have a hint */ 314 355 315 size_t off = 0; 356 316 size_t i = 0; … … 358 318 if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE)) 359 319 break; 360 361 320 i++; 362 321 } 363 364 if (found > 1) {365 /* No unique hint, list was printed */366 printf("%s> ", prompt);367 printf("%ls", current);368 position += str_length(tmp);369 print_cc('\b', wstr_length(current) - position);370 continue;371 }372 373 /* We have a hint */374 322 375 323 printf("%ls", current + position); … … 524 472 /* It's a number - convert it */ 525 473 uint64_t value; 526 char *end; 527 int rc = str_uint64_t(text, &end, 0, false, &value); 528 if (end != text + len) 529 rc = EINVAL; 474 int rc = str_uint64_t(text, NULL, 0, true, &value); 530 475 switch (rc) { 531 476 case EINVAL: 532 printf("Invalid number '%s'.\n", text);477 printf("Invalid number.\n"); 533 478 return false; 534 479 case EOVERFLOW: 535 printf("Integer overflow in '%s'.\n", text);480 printf("Integer overflow.\n"); 536 481 return false; 537 482 case EOK: … … 541 486 break; 542 487 default: 543 printf("Unknown error parsing '%s'.\n", text);488 printf("Unknown error.\n"); 544 489 return false; 545 490 } … … 595 540 /** Parse command line. 596 541 * 597 * @param cmdline Command line as read from input device. 542 * @param cmdline Command line as read from input device. 598 543 * @param size Size (in bytes) of the string. 599 544 *
Note:
See TracChangeset
for help on using the changeset viewer.