Changes in kernel/generic/src/console/kconsole.c [feeac0d:dc0e41c] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/kconsole.c
rfeeac0d rdc0e41c 59 59 #include <putchar.h> 60 60 #include <str.h> 61 #include <mm/slab.h> 61 62 62 63 /** Simple kernel console. … … 164 165 165 166 /** Try to find a command beginning with prefix */ 166 NO_TRACE static const char *cmdtab_search_one(const char *name, 167 link_t **startpos) 168 { 167 const char *cmdtab_enum(const char *name, const char **h, void **ctx) 168 { 169 link_t **startpos = (link_t**)ctx; 169 170 size_t namelen = str_length(name); 170 171 … … 182 183 183 184 if (str_lcmp(curname, name, namelen) == 0) { 185 *startpos = (*startpos)->next; 186 if (h) { 187 *h = hlp->description; 188 } 184 189 spinlock_unlock(&cmd_lock); 185 190 return (curname + str_lsize(curname, namelen)); … … 199 204 * 200 205 */ 201 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) 202 208 { 203 209 const char *name = input; … … 211 217 size_t max_match_len = size; 212 218 size_t max_match_len_tmp = size; 213 size_t input_len = str_length(input); 214 link_t *pos = NULL; 219 void *pos = NULL; 215 220 const char *hint; 221 const char *help; 216 222 char *output = malloc(MAX_CMDLINE, 0); 217 223 size_t hints_to_show = MAX_TAB_HINTS - 1; … … 221 227 output[0] = 0; 222 228 223 while ((hint = cmdtab_search_one(name, &pos))) {224 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))) 225 231 str_cpy(output, MAX_CMDLINE, hint); 226 232 227 pos = pos->next;228 233 found++; 229 234 } … … 242 247 printf("\n"); 243 248 pos = NULL; 244 while (cmdtab_search_one(name, &pos)) { 245 cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link); 249 while ((hint = hints_enum(name, &help, &pos))) { 246 250 247 251 if (continue_showing_hints) { 248 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 249 258 --hints_to_show; 250 259 ++total_hints_shown; … … 257 266 } 258 267 259 pos = pos->next;260 261 268 for (max_match_len_tmp = 0; 262 269 (output[max_match_len_tmp] == 263 h lp->name[input_len +max_match_len_tmp]) &&270 hint[max_match_len_tmp]) && 264 271 (max_match_len_tmp < max_match_len); ++max_match_len_tmp); 265 272 … … 276 283 free(output); 277 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; 278 322 } 279 323 … … 337 381 if (beg == 0) { 338 382 /* Command completion */ 339 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev); 383 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev, 384 cmdtab_enum); 340 385 } else { 341 /* Symbol completion */ 342 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); 343 392 } 344 393
Note:
See TracChangeset
for help on using the changeset viewer.