Changes in kernel/generic/src/console/kconsole.c [e98f1c3e:9b11a971] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/kconsole.c
re98f1c3e r9b11a971 53 53 #include <func.h> 54 54 #include <str.h> 55 #include <macros.h> 55 56 #include <sysinfo/sysinfo.h> 56 57 #include <ddi/device.h> … … 58 59 #include <errno.h> 59 60 #include <putchar.h> 60 #include < mm/slab.h>61 #include <str.h> 61 62 62 63 /** Simple kernel console. … … 118 119 * Make sure the command is not already listed. 119 120 */ 120 list_foreach(cmd_list, link, cmd_info_t, hlp) { 121 list_foreach(cmd_list, cur) { 122 cmd_info_t *hlp = list_get_instance(cur, cmd_info_t, link); 123 121 124 if (hlp == cmd) { 122 125 /* The command is already there. */ … … 164 167 165 168 /** Try to find a command beginning with prefix */ 166 const char *cmdtab_enum(const char *name, const char **h, void **ctx) 167 { 168 link_t **startpos = (link_t**) ctx; 169 NO_TRACE static const char *cmdtab_search_one(const char *name, 170 link_t **startpos) 171 { 169 172 size_t namelen = str_length(name); 170 173 … … 182 185 183 186 if (str_lcmp(curname, name, namelen) == 0) { 184 *startpos = (*startpos)->next;185 if (h)186 *h = hlp->description;187 188 187 spinlock_unlock(&cmd_lock); 189 188 return (curname + str_lsize(curname, namelen)); … … 203 202 * 204 203 */ 205 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev, 206 hints_enum_func_t hints_enum) 204 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev) 207 205 { 208 206 const char *name = input; … … 216 214 size_t max_match_len = size; 217 215 size_t max_match_len_tmp = size; 218 void *pos = NULL; 216 size_t input_len = str_length(input); 217 link_t *pos = NULL; 219 218 const char *hint; 220 const char *help;221 219 char *output = malloc(MAX_CMDLINE, 0); 222 220 size_t hints_to_show = MAX_TAB_HINTS - 1; … … 226 224 output[0] = 0; 227 225 228 while ((hint = hints_enum(name, NULL, &pos))) {229 if ((found == 0) || (str_length( hint) > str_length(output)))226 while ((hint = cmdtab_search_one(name, &pos))) { 227 if ((found == 0) || (str_length(output) > str_length(hint))) 230 228 str_cpy(output, MAX_CMDLINE, hint); 231 229 230 pos = pos->next; 232 231 found++; 233 232 } … … 246 245 printf("\n"); 247 246 pos = NULL; 248 while ((hint = hints_enum(name, &help, &pos))) { 247 while (cmdtab_search_one(name, &pos)) { 248 cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link); 249 249 250 250 if (continue_showing_hints) { 251 if (help) 252 printf("%s%s (%s)\n", name, hint, help); 253 else 254 printf("%s%s\n", name, hint); 255 251 printf("%s (%s)\n", hlp->name, hlp->description); 256 252 --hints_to_show; 257 253 ++total_hints_shown; … … 264 260 } 265 261 262 pos = pos->next; 263 266 264 for (max_match_len_tmp = 0; 267 265 (output[max_match_len_tmp] == 268 h int[max_match_len_tmp]) &&266 hlp->name[input_len + max_match_len_tmp]) && 269 267 (max_match_len_tmp < max_match_len); ++max_match_len_tmp); 270 268 … … 281 279 free(output); 282 280 return found; 283 }284 285 NO_TRACE static cmd_info_t *parse_cmd(const wchar_t *cmdline)286 {287 size_t start = 0;288 size_t end;289 char *tmp;290 291 while (isspace(cmdline[start]))292 start++;293 294 end = start + 1;295 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;322 281 } 323 282 … … 362 321 putchar(current[position]); 363 322 323 if (position == 0) 324 continue; 364 325 365 326 /* … … 368 329 */ 369 330 size_t beg; 370 unsigned narg = 0; 371 if (position == 0) { 372 tmp[0] = '\0'; 373 beg = 0; 331 for (beg = position - 1; (beg > 0) && (!isspace(current[beg])); 332 beg--); 333 334 if (isspace(current[beg])) 335 beg++; 336 337 wstr_to_str(tmp, position - beg + 1, current + beg); 338 339 int found; 340 if (beg == 0) { 341 /* Command completion */ 342 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev); 374 343 } else { 375 for (beg = position - 1; 376 (beg > 0) && (!isspace(current[beg])); 377 beg--); 378 379 if (isspace(current[beg])) 380 beg++; 381 382 wstr_to_str(tmp, position - beg + 1, current + beg); 383 } 384 385 /* Count which argument number are we tabbing (narg=0 is cmd) */ 386 bool sp = false; 387 for (; beg > 0; beg--) { 388 if (isspace(current[beg])) { 389 if (!sp) { 390 narg++; 391 sp = true; 392 } 393 } else 394 sp = false; 395 } 396 397 if (narg && isspace(current[0])) 398 narg--; 399 400 int found; 401 if (narg == 0) { 402 /* Command completion */ 403 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev, 404 cmdtab_enum); 405 } else { 406 /* Arguments completion */ 407 cmd_info_t *cmd = parse_cmd(current); 408 if (!cmd || !cmd->hints_enum || cmd->argc < narg) 409 continue; 410 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev, 411 cmd->hints_enum); 344 /* Symbol completion */ 345 found = symtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev); 412 346 } 413 347 … … 679 613 cmd_info_t *cmd = NULL; 680 614 681 list_foreach(cmd_list, link, cmd_info_t, hlp) { 615 list_foreach(cmd_list, cur) { 616 cmd_info_t *hlp = list_get_instance(cur, cmd_info_t, link); 682 617 spinlock_lock(&hlp->lock); 683 618
Note:
See TracChangeset
for help on using the changeset viewer.