Changeset 36b0490e in mainline
- Timestamp:
- 2016-03-08T09:16:26Z (9 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 83b2e73
- Parents:
- b6bbc74
- Location:
- kernel/generic
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/console/kconsole.h
rb6bbc74 r36b0490e 42 42 #define MAX_CMDLINE 256 43 43 #define KCONSOLE_HISTORY 10 44 45 /** Callback to be used to enum hints for cmd tab completion. */ 46 typedef const char *(*hints_enum_func_t)(const char *, const char **, void **); 44 47 45 48 typedef enum { -
kernel/generic/src/console/kconsole.c
rb6bbc74 r36b0490e 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 NO_TRACE static const char *cmdtab_enum(const char *name, 168 const char **h, void **ctx) 169 { 170 link_t **startpos = (link_t**)ctx; 170 171 size_t namelen = str_length(name); 171 172 … … 183 184 184 185 if (str_lcmp(curname, name, namelen) == 0) { 186 *startpos = (*startpos)->next; 187 if (h) { 188 *h = hlp->description; 189 } 185 190 spinlock_unlock(&cmd_lock); 186 191 return (curname + str_lsize(curname, namelen)); … … 200 205 * 201 206 */ 202 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev) 207 NO_TRACE static int cmdtab_compl(char *input, size_t size, indev_t *indev, 208 hints_enum_func_t hints_enum) 203 209 { 204 210 const char *name = input; … … 212 218 size_t max_match_len = size; 213 219 size_t max_match_len_tmp = size; 214 size_t input_len = str_length(input); 215 link_t *pos = NULL; 220 void *pos = NULL; 216 221 const char *hint; 222 const char *help; 217 223 char *output = malloc(MAX_CMDLINE, 0); 218 224 size_t hints_to_show = MAX_TAB_HINTS - 1; … … 222 228 output[0] = 0; 223 229 224 while ((hint = cmdtab_search_one(name, &pos))) {230 while ((hint = hints_enum(name, NULL, &pos))) { 225 231 if ((found == 0) || (str_length(output) > str_length(hint))) 226 232 str_cpy(output, MAX_CMDLINE, hint); 227 233 228 pos = pos->next;229 234 found++; 230 235 } … … 243 248 printf("\n"); 244 249 pos = NULL; 245 while (cmdtab_search_one(name, &pos)) { 246 cmd_info_t *hlp = list_get_instance(pos, cmd_info_t, link); 250 while ((hint = hints_enum(name, &help, &pos))) { 247 251 248 252 if (continue_showing_hints) { 249 printf("%s (%s)\n", hlp->name, hlp->description); 253 254 if (help) 255 printf("%s%s (%s)\n", name, hint, help); 256 else 257 printf("%s%s\n", name, hint); 258 250 259 --hints_to_show; 251 260 ++total_hints_shown; … … 258 267 } 259 268 260 pos = pos->next;261 262 269 for (max_match_len_tmp = 0; 263 270 (output[max_match_len_tmp] == 264 h lp->name[input_len +max_match_len_tmp]) &&271 hint[max_match_len_tmp]) && 265 272 (max_match_len_tmp < max_match_len); ++max_match_len_tmp); 266 273 … … 338 345 if (beg == 0) { 339 346 /* Command completion */ 340 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev );347 found = cmdtab_compl(tmp, STR_BOUNDS(MAX_CMDLINE), indev, cmdtab_enum); 341 348 } else { 342 349 /* Symbol completion */
Note:
See TracChangeset
for help on using the changeset viewer.