Rev 2089 | Rev 2113 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2089 | Rev 2108 | ||
---|---|---|---|
Line 77... | Line 77... | ||
77 | 77 | ||
78 | SPINLOCK_INITIALIZE(cmd_lock); /**< Lock protecting command list. */ |
78 | SPINLOCK_INITIALIZE(cmd_lock); /**< Lock protecting command list. */ |
79 | LIST_INITIALIZE(cmd_head); /**< Command list. */ |
79 | LIST_INITIALIZE(cmd_head); /**< Command list. */ |
80 | 80 | ||
81 | static cmd_info_t *parse_cmdline(char *cmdline, size_t len); |
81 | static cmd_info_t *parse_cmdline(char *cmdline, size_t len); |
82 | static bool parse_argument(char *cmdline, size_t len, index_t *start, index_t *end); |
82 | static bool parse_argument(char *cmdline, size_t len, index_t *start, |
- | 83 | index_t *end); |
|
83 | static char history[KCONSOLE_HISTORY][MAX_CMDLINE] = {}; |
84 | static char history[KCONSOLE_HISTORY][MAX_CMDLINE] = {}; |
84 | 85 | ||
85 | /** Initialize kconsole data structures. */ |
86 | /** Initialize kconsole data structures. */ |
86 | void kconsole_init(void) |
87 | void kconsole_init(void) |
87 | { |
88 | { |
Line 125... | Line 126... | ||
125 | spinlock_lock(&cmd->lock); |
126 | spinlock_lock(&cmd->lock); |
126 | } else { |
127 | } else { |
127 | spinlock_lock(&cmd->lock); |
128 | spinlock_lock(&cmd->lock); |
128 | spinlock_lock(&hlp->lock); |
129 | spinlock_lock(&hlp->lock); |
129 | } |
130 | } |
130 | if ((strncmp(hlp->name, |
- | |
131 | cmd->name, max(strlen(cmd->name), |
131 | if ((strncmp(hlp->name, cmd->name, max(strlen(cmd->name), |
132 | strlen(hlp->name))) == 0)) { |
132 | strlen(hlp->name))) == 0)) { |
133 | /* The command is already there. */ |
133 | /* The command is already there. */ |
134 | spinlock_unlock(&hlp->lock); |
134 | spinlock_unlock(&hlp->lock); |
135 | spinlock_unlock(&cmd->lock); |
135 | spinlock_unlock(&cmd->lock); |
136 | spinlock_unlock(&cmd_lock); |
136 | spinlock_unlock(&cmd_lock); |
Line 213... | Line 213... | ||
213 | while ((foundtxt = cmdtab_search_one(name, &startpos))) { |
213 | while ((foundtxt = cmdtab_search_one(name, &startpos))) { |
214 | startpos = startpos->next; |
214 | startpos = startpos->next; |
215 | if (!found) |
215 | if (!found) |
216 | strncpy(output, foundtxt, strlen(foundtxt)+1); |
216 | strncpy(output, foundtxt, strlen(foundtxt)+1); |
217 | else { |
217 | else { |
218 | for (i=0; output[i] && foundtxt[i] && output[i]==foundtxt[i]; i++) |
218 | for (i = 0; output[i] && foundtxt[i] && |
- | 219 | output[i] == foundtxt[i]; i++) |
|
219 | ; |
220 | ; |
220 | output[i] = '\0'; |
221 | output[i] = '\0'; |
221 | } |
222 | } |
222 | found++; |
223 | found++; |
223 | } |
224 | } |
Line 272... | Line 273... | ||
272 | } |
273 | } |
273 | if (c == '\t') { /* Tabulator */ |
274 | if (c == '\t') { /* Tabulator */ |
274 | int found; |
275 | int found; |
275 | 276 | ||
276 | /* Move to the end of the word */ |
277 | /* Move to the end of the word */ |
277 | for (;position<curlen && current[position]!=' ';position++) |
278 | for (; position < curlen && current[position] != ' '; |
- | 279 | position++) |
|
278 | putchar(current[position]); |
280 | putchar(current[position]); |
279 | /* Copy to tmp last word */ |
281 | /* Copy to tmp last word */ |
280 | for (i=position-1;i >= 0 && current[i]!=' ' ;i--) |
282 | for (i = position - 1; i >= 0 && current[i] != ' '; i--) |
281 | ; |
283 | ; |
282 | /* If word begins with * or &, skip it */ |
284 | /* If word begins with * or &, skip it */ |
Line 292... | Line 294... | ||
292 | found = symtab_compl(tmp); |
294 | found = symtab_compl(tmp); |
293 | } |
295 | } |
294 | 296 | ||
295 | if (found == 0) |
297 | if (found == 0) |
296 | continue; |
298 | continue; |
297 | for (i=0;tmp[i] && curlen < MAX_CMDLINE;i++,curlen++) |
299 | for (i = 0; tmp[i] && curlen < MAX_CMDLINE; |
- | 300 | i++, curlen++) |
|
298 | insert_char(current, tmp[i], i+position); |
301 | insert_char(current, tmp[i], i + position); |
299 | 302 | ||
300 | if (strlen(tmp) || found==1) { /* If we have a hint */ |
303 | if (strlen(tmp) || found == 1) { /* If we have a hint */ |
301 | for (i=position;i<curlen;i++) |
304 | for (i = position; i < curlen; i++) |
302 | putchar(current[i]); |
305 | putchar(current[i]); |
303 | position += strlen(tmp); |
306 | position += strlen(tmp); |
304 | /* Add space to end */ |
307 | /* Add space to end */ |
305 | if (found == 1 && position == curlen && \ |
308 | if (found == 1 && position == curlen && |
306 | curlen < MAX_CMDLINE) { |
309 | curlen < MAX_CMDLINE) { |
307 | current[position] = ' '; |
310 | current[position] = ' '; |
308 | curlen++; |
311 | curlen++; |
309 | position++; |
312 | position++; |
310 | putchar(' '); |
313 | putchar(' '); |
Line 334... | Line 337... | ||
334 | current[i-1] = current[i]; |
337 | current[i - 1] = current[i]; |
335 | } |
338 | } |
336 | putchar(' '); |
339 | putchar(' '); |
337 | rdln_print_c('\b',curlen-position); |
340 | rdln_print_c('\b', curlen - position); |
338 | curlen--; |
341 | curlen--; |
339 | } |
- | |
340 | else if (c == 0x48) { /* Home */ |
342 | } else if (c == 0x48) { /* Home */ |
341 | rdln_print_c('\b',position); |
343 | rdln_print_c('\b', position); |
342 | position = 0; |
344 | position = 0; |
343 | } |
- | |
344 | else if (c == 0x46) { /* End */ |
345 | } else if (c == 0x46) { /* End */ |
345 | for (i=position;i<curlen;i++) |
346 | for (i = position; i < curlen; i++) |
346 | putchar(current[i]); |
347 | putchar(current[i]); |
347 | position = curlen; |
348 | position = curlen; |
348 | } |
- | |
349 | else if (c == 0x44) { /* Left */ |
349 | } else if (c == 0x44) { /* Left */ |
350 | if (position > 0) { |
350 | if (position > 0) { |
351 | putchar('\b'); |
351 | putchar('\b'); |
352 | position--; |
352 | position--; |
353 | } |
353 | } |
354 | continue; |
354 | continue; |
355 | } |
- | |
356 | else if (c == 0x43) { /* Right */ |
355 | } else if (c == 0x43) { /* Right */ |
357 | if (position < curlen) { |
356 | if (position < curlen) { |
358 | putchar(current[position]); |
357 | putchar(current[position]); |
359 | position++; |
358 | position++; |
360 | } |
359 | } |
361 | continue; |
360 | continue; |
362 | } |
- | |
363 | else if (c == 0x41 || c == 0x42) { |
361 | } else if (c == 0x41 || c == 0x42) { |
364 | /* Up,down */ |
362 | /* Up, down */ |
365 | rdln_print_c('\b',position); |
363 | rdln_print_c('\b', position); |
366 | rdln_print_c(' ',curlen); |
364 | rdln_print_c(' ', curlen); |
367 | rdln_print_c('\b',curlen); |
365 | rdln_print_c('\b', curlen); |
368 | if (c == 0x41) /* Up */ |
366 | if (c == 0x41) /* Up */ |
369 | histposition--; |
367 | histposition--; |
370 | else |
368 | else |
371 | histposition++; |
369 | histposition++; |
372 | if (histposition < 0) |
370 | if (histposition < 0) { |
373 | histposition = KCONSOLE_HISTORY -1 ; |
371 | histposition = KCONSOLE_HISTORY - 1; |
374 | else |
372 | } else { |
- | 373 | histposition = |
|
375 | histposition = histposition % KCONSOLE_HISTORY; |
374 | histposition % KCONSOLE_HISTORY; |
- | 375 | } |
|
376 | current = history[histposition]; |
376 | current = history[histposition]; |
377 | printf("%s", current); |
377 | printf("%s", current); |
378 | curlen = strlen(current); |
378 | curlen = strlen(current); |
379 | position = curlen; |
379 | position = curlen; |
380 | continue; |
380 | continue; |
Line 421... | Line 421... | ||
421 | if (!len) |
421 | if (!len) |
422 | continue; |
422 | continue; |
423 | cmd_info = parse_cmdline(cmdline, len); |
423 | cmd_info = parse_cmdline(cmdline, len); |
424 | if (!cmd_info) |
424 | if (!cmd_info) |
425 | continue; |
425 | continue; |
426 | if (strncmp(cmd_info->name,"exit", \ |
426 | if (strncmp(cmd_info->name, "exit", |
427 | min(strlen(cmd_info->name),5)) == 0) |
427 | min(strlen(cmd_info->name), 5)) == 0) |
428 | break; |
428 | break; |
429 | (void) cmd_info->func(cmd_info->argv); |
429 | (void) cmd_info->func(cmd_info->argv); |
430 | } |
430 | } |
431 | } |
431 | } |
Line 438... | Line 438... | ||
438 | bool isptr = false; |
438 | bool isptr = false; |
439 | 439 | ||
440 | /* If we get a name, try to find it in symbol table */ |
440 | /* If we get a name, try to find it in symbol table */ |
441 | if (text[0] == '&') { |
441 | if (text[0] == '&') { |
442 | isaddr = true; |
442 | isaddr = true; |
443 | text++;len--; |
443 | text++; |
- | 444 | len--; |
|
444 | } else if (text[0] == '*') { |
445 | } else if (text[0] == '*') { |
445 | isptr = true; |
446 | isptr = true; |
446 | text++;len--; |
447 | text++; |
- | 448 | len--; |
|
447 | } |
449 | } |
448 | if (text[0] < '0' || text[0] > '9') { |
450 | if (text[0] < '0' || text[0] > '9') { |
449 | strncpy(symname, text, min(len+1, MAX_SYMBOL_NAME)); |
451 | strncpy(symname, text, min(len + 1, MAX_SYMBOL_NAME)); |
450 | symaddr = get_symbol_addr(symname); |
452 | symaddr = get_symbol_addr(symname); |
451 | if (!symaddr) { |
453 | if (!symaddr) { |
Line 537... | Line 539... | ||
537 | 539 | ||
538 | error = 0; |
540 | error = 0; |
539 | switch (cmd->argv[i].type) { |
541 | switch (cmd->argv[i].type) { |
540 | case ARG_TYPE_STRING: |
542 | case ARG_TYPE_STRING: |
541 | buf = cmd->argv[i].buffer; |
543 | buf = cmd->argv[i].buffer; |
542 | strncpy(buf, (const char *) &cmdline[start], min((end - start) + 2, cmd->argv[i].len)); |
544 | strncpy(buf, (const char *) &cmdline[start], |
- | 545 | min((end - start) + 2, cmd->argv[i].len)); |
|
543 | buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; |
546 | buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; |
544 | break; |
547 | break; |
545 | case ARG_TYPE_INT: |
548 | case ARG_TYPE_INT: |
546 | if (parse_int_arg(cmdline+start, end-start+1, |
549 | if (parse_int_arg(cmdline + start, end - start + 1, |
547 | &cmd->argv[i].intval)) |
550 | &cmd->argv[i].intval)) |
548 | error = 1; |
551 | error = 1; |
549 | break; |
552 | break; |
550 | case ARG_TYPE_VAR: |
553 | case ARG_TYPE_VAR: |
551 | if (start != end && cmdline[start] == '"' && cmdline[end] == '"') { |
554 | if (start != end && cmdline[start] == '"' && |
- | 555 | cmdline[end] == '"') { |
|
552 | buf = cmd->argv[i].buffer; |
556 | buf = cmd->argv[i].buffer; |
553 | strncpy(buf, (const char *) &cmdline[start+1], |
557 | strncpy(buf, (const char *) &cmdline[start + 1], |
554 | min((end-start), cmd->argv[i].len)); |
558 | min((end-start), cmd->argv[i].len)); |
555 | buf[min((end - start), cmd->argv[i].len - 1)] = '\0'; |
559 | buf[min((end - start), cmd->argv[i].len - 1)] = |
- | 560 | '\0'; |
|
556 | cmd->argv[i].intval = (unative_t) buf; |
561 | cmd->argv[i].intval = (unative_t) buf; |
557 | cmd->argv[i].vartype = ARG_TYPE_STRING; |
562 | cmd->argv[i].vartype = ARG_TYPE_STRING; |
558 | } else if (!parse_int_arg(cmdline+start, end-start+1, |
563 | } else if (!parse_int_arg(cmdline + start, end - start + 1, |
559 | &cmd->argv[i].intval)) |
564 | &cmd->argv[i].intval)) { |
560 | cmd->argv[i].vartype = ARG_TYPE_INT; |
565 | cmd->argv[i].vartype = ARG_TYPE_INT; |
561 | else { |
566 | } else { |
562 | printf("Unrecognized variable argument.\n"); |
567 | printf("Unrecognized variable argument.\n"); |
563 | error = 1; |
568 | error = 1; |
564 | } |
569 | } |
565 | break; |
570 | break; |
566 | case ARG_TYPE_INVALID: |
571 | case ARG_TYPE_INVALID: |