Changes in kernel/generic/src/console/kconsole.c [059a8e4:9b11a971] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/kconsole.c
r059a8e4 r9b11a971 43 43 #include <console/chardev.h> 44 44 #include <console/cmd.h> 45 #include <console/prompt.h> 45 46 #include <print.h> 46 47 #include <panic.h> … … 201 202 * 202 203 */ 203 NO_TRACE static int cmdtab_compl(char *input, size_t size )204 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev) 204 205 { 205 206 const char *name = input; 206 207 207 208 size_t found = 0; 209 210 /* 211 * Maximum Match Length: Length of longest matching common 212 * 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); 208 217 link_t *pos = NULL; 209 218 const char *hint; 210 219 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; 211 223 212 224 output[0] = 0; … … 218 230 pos = pos->next; 219 231 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); 220 242 } 221 243 … … 225 247 while (cmdtab_search_one(name, &pos)) { 226 248 cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link); 227 printf("%s (%s)\n", hlp->name, hlp->description); 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 228 262 pos = pos->next; 229 } 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; 230 274 } 231 275 … … 280 324 continue; 281 325 282 /* Find the beginning of the word 283 and copy it to tmp */ 326 /* 327 * Find the beginning of the word 328 * and copy it to tmp 329 */ 284 330 size_t beg; 285 331 for (beg = position - 1; (beg > 0) && (!isspace(current[beg])); … … 294 340 if (beg == 0) { 295 341 /* Command completion */ 296 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE) );342 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev); 297 343 } else { 298 344 /* Symbol completion */ 299 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE) );345 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev); 300 346 } 301 347 302 348 if (found == 0) 303 349 continue; 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 350 351 /* 352 * We have hints, possibly many. In case of more than one hint, 353 * tmp will contain the common prefix. 354 */ 315 355 size_t off = 0; 316 356 size_t i = 0; … … 318 358 if (!wstr_linsert(current, ch, position + i, MAX_CMDLINE)) 319 359 break; 360 320 361 i++; 321 362 } 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 */ 322 374 323 375 printf("%ls", current + position); … … 472 524 /* It's a number - convert it */ 473 525 uint64_t value; 474 int rc = str_uint64_t(text, NULL, 0, true, &value); 526 char *end; 527 int rc = str_uint64_t(text, &end, 0, false, &value); 528 if (end != text + len) 529 rc = EINVAL; 475 530 switch (rc) { 476 531 case EINVAL: 477 printf("Invalid number .\n");532 printf("Invalid number '%s'.\n", text); 478 533 return false; 479 534 case EOVERFLOW: 480 printf("Integer overflow .\n");535 printf("Integer overflow in '%s'.\n", text); 481 536 return false; 482 537 case EOK: … … 486 541 break; 487 542 default: 488 printf("Unknown error .\n");543 printf("Unknown error parsing '%s'.\n", text); 489 544 return false; 490 545 } … … 540 595 /** Parse command line. 541 596 * 542 * @param cmdline Command line as read from input device. 597 * @param cmdline Command line as read from input device. 543 598 * @param size Size (in bytes) of the string. 544 599 *
Note:
See TracChangeset
for help on using the changeset viewer.