Changeset cf5ddf6 in mainline
- Timestamp:
- 2007-02-04T11:22:53Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 5573942
- Parents:
- f619ec11
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/src/console/kconsole.c
rf619ec11 rcf5ddf6 80 80 81 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 84 static char history[KCONSOLE_HISTORY][MAX_CMDLINE] = {}; 84 85 … … 89 90 90 91 cmd_init(); 91 for (i =0; i<KCONSOLE_HISTORY; i++)92 for (i = 0; i < KCONSOLE_HISTORY; i++) 92 93 history[i][0] = '\0'; 93 94 } … … 128 129 spinlock_lock(&hlp->lock); 129 130 } 130 if ((strncmp(hlp->name, 131 cmd->name, max(strlen(cmd->name), 132 strlen(hlp->name))) == 0)) { 131 if ((strncmp(hlp->name, cmd->name, max(strlen(cmd->name), 132 strlen(hlp->name))) == 0)) { 133 133 /* The command is already there. */ 134 134 spinlock_unlock(&hlp->lock); … … 155 155 { 156 156 int i; 157 for (i =0;i<count;i++)157 for (i = 0; i < count; i++) 158 158 putchar(ch); 159 159 } … … 164 164 int i; 165 165 166 for (i =strlen(str);i > pos; i--)167 str[i] = str[i -1];166 for (i = strlen(str); i > pos; i--) 167 str[i] = str[i - 1]; 168 168 str[pos] = ch; 169 169 } … … 180 180 *startpos = cmd_head.next; 181 181 182 for (; *startpos != &cmd_head;*startpos = (*startpos)->next) {182 for (; *startpos != &cmd_head; *startpos = (*startpos)->next) { 183 183 cmd_info_t *hlp; 184 184 hlp = list_get_instance(*startpos, cmd_info_t, link); … … 216 216 strncpy(output, foundtxt, strlen(foundtxt)+1); 217 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 221 output[i] = '\0'; … … 260 261 if (position == 0) 261 262 continue; 262 for (i =position; i<curlen;i++)263 current[i -1] = current[i];263 for (i = position; i < curlen; i++) 264 current[i - 1] = current[i]; 264 265 curlen--; 265 266 position--; 266 267 putchar('\b'); 267 for (i =position;i<curlen;i++)268 for (i = position; i < curlen; i++) 268 269 putchar(current[i]); 269 270 putchar(' '); 270 rdln_print_c('\b', curlen-position+1);271 rdln_print_c('\b', curlen - position + 1); 271 272 continue; 272 273 } … … 275 276 276 277 /* Move to the end of the word */ 277 for (;position<curlen && current[position]!=' ';position++) 278 for (; position < curlen && current[position] != ' '; 279 position++) 278 280 putchar(current[position]); 279 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 284 /* If word begins with * or &, skip it */ 283 285 if (tmp[0] == '*' || tmp[0] == '&') 284 for (i =1;tmp[i];i++)285 tmp[i -1] = tmp[i];286 for (i = 1; tmp[i]; i++) 287 tmp[i - 1] = tmp[i]; 286 288 i++; /* I is at the start of the word */ 287 strncpy(tmp, current +i, position-i+1);288 289 if (i ==0) { /* Command completion */289 strncpy(tmp, current + i, position - i + 1); 290 291 if (i == 0) { /* Command completion */ 290 292 found = cmdtab_compl(tmp); 291 293 } else { /* Symtab completion */ … … 295 297 if (found == 0) 296 298 continue; 297 for (i=0;tmp[i] && curlen < MAX_CMDLINE;i++,curlen++) 298 insert_char(current, tmp[i], i+position); 299 300 if (strlen(tmp) || found==1) { /* If we have a hint */ 301 for (i=position;i<curlen;i++) 299 for (i = 0; tmp[i] && curlen < MAX_CMDLINE; 300 i++, curlen++) 301 insert_char(current, tmp[i], i + position); 302 303 if (strlen(tmp) || found == 1) { /* If we have a hint */ 304 for (i = position; i < curlen; i++) 302 305 putchar(current[i]); 303 306 position += strlen(tmp); 304 307 /* Add space to end */ 305 if (found == 1 && position == curlen && \308 if (found == 1 && position == curlen && 306 309 curlen < MAX_CMDLINE) { 307 310 current[position] = ' '; … … 312 315 } else { /* No hint, table was printed */ 313 316 printf("%s> ", prompt); 314 for (i =0; i<curlen;i++)317 for (i = 0; i < curlen; i++) 315 318 putchar(current[i]); 316 319 position += strlen(tmp); 317 320 } 318 rdln_print_c('\b', curlen -position);321 rdln_print_c('\b', curlen - position); 319 322 continue; 320 323 } … … 330 333 if (position == curlen) 331 334 continue; 332 for (i =position+1; i<curlen;i++) {335 for (i = position + 1; i < curlen; i++) { 333 336 putchar(current[i]); 334 current[i -1] = current[i];337 current[i - 1] = current[i]; 335 338 } 336 339 putchar(' '); 337 rdln_print_c('\b', curlen-position);340 rdln_print_c('\b', curlen - position); 338 341 curlen--; 339 } 340 else if (c == 0x48) { /* Home */ 341 rdln_print_c('\b',position); 342 } else if (c == 0x48) { /* Home */ 343 rdln_print_c('\b', position); 342 344 position = 0; 343 } 344 else if (c == 0x46) { /* End */ 345 for (i=position;i<curlen;i++) 345 } else if (c == 0x46) { /* End */ 346 for (i = position; i < curlen; i++) 346 347 putchar(current[i]); 347 348 position = curlen; 348 } 349 else if (c == 0x44) { /* Left */ 349 } else if (c == 0x44) { /* Left */ 350 350 if (position > 0) { 351 351 putchar('\b'); … … 353 353 } 354 354 continue; 355 } 356 else if (c == 0x43) { /* Right */ 355 } else if (c == 0x43) { /* Right */ 357 356 if (position < curlen) { 358 357 putchar(current[position]); … … 360 359 } 361 360 continue; 362 } 363 else if (c == 0x41 || c == 0x42) { 364 /* Up,down */ 365 rdln_print_c('\b',position); 366 rdln_print_c(' ',curlen); 367 rdln_print_c('\b',curlen); 361 } else if (c == 0x41 || c == 0x42) { 362 /* Up, down */ 363 rdln_print_c('\b', position); 364 rdln_print_c(' ', curlen); 365 rdln_print_c('\b', curlen); 368 366 if (c == 0x41) /* Up */ 369 367 histposition--; 370 368 else 371 369 histposition++; 372 if (histposition < 0) 373 histposition = KCONSOLE_HISTORY -1 ; 374 else 375 histposition = histposition % KCONSOLE_HISTORY; 370 if (histposition < 0) { 371 histposition = KCONSOLE_HISTORY - 1; 372 } else { 373 histposition = 374 histposition % KCONSOLE_HISTORY; 375 } 376 376 current = history[histposition]; 377 377 printf("%s", current); … … 388 388 389 389 curlen++; 390 for (i =position;i<curlen;i++)390 for (i = position; i < curlen; i++) 391 391 putchar(current[i]); 392 392 position++; 393 rdln_print_c('\b',curlen -position);393 rdln_print_c('\b',curlen - position); 394 394 } 395 395 if (curlen) { … … 424 424 if (!cmd_info) 425 425 continue; 426 if (strncmp(cmd_info->name, "exit", \427 min(strlen(cmd_info->name),5)) == 0)426 if (strncmp(cmd_info->name, "exit", 427 min(strlen(cmd_info->name), 5)) == 0) 428 428 break; 429 429 (void) cmd_info->func(cmd_info->argv); … … 441 441 if (text[0] == '&') { 442 442 isaddr = true; 443 text++;len--; 443 text++; 444 len--; 444 445 } else if (text[0] == '*') { 445 446 isptr = true; 446 text++;len--; 447 text++; 448 len--; 447 449 } 448 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 452 symaddr = get_symbol_addr(symname); 451 453 if (!symaddr) { 452 printf("Symbol %s not found.\n", symname);454 printf("Symbol %s not found.\n", symname); 453 455 return -1; 454 456 } 455 457 if (symaddr == (uintptr_t) -1) { 456 printf("Duplicate symbol %s.\n", symname);458 printf("Duplicate symbol %s.\n", symname); 457 459 symtab_print_search(symname); 458 460 return -1; … … 502 504 503 505 if (strncmp(hlp->name, &cmdline[start], max(strlen(hlp->name), 504 end-start+1)) == 0) {506 end - start + 1)) == 0) { 505 507 cmd = hlp; 506 508 break; … … 540 542 case ARG_TYPE_STRING: 541 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 546 buf[min((end - start) + 1, cmd->argv[i].len - 1)] = '\0'; 544 547 break; 545 548 case ARG_TYPE_INT: 546 if (parse_int_arg(cmdline +start, end-start+1,547 549 if (parse_int_arg(cmdline + start, end - start + 1, 550 &cmd->argv[i].intval)) 548 551 error = 1; 549 552 break; 550 553 case ARG_TYPE_VAR: 551 if (start != end && cmdline[start] == '"' && cmdline[end] == '"') { 554 if (start != end && cmdline[start] == '"' && 555 cmdline[end] == '"') { 552 556 buf = cmd->argv[i].buffer; 553 strncpy(buf, (const char *) &cmdline[start+1], 554 min((end-start), cmd->argv[i].len)); 555 buf[min((end - start), cmd->argv[i].len - 1)] = '\0'; 557 strncpy(buf, (const char *) &cmdline[start + 1], 558 min((end-start), cmd->argv[i].len)); 559 buf[min((end - start), cmd->argv[i].len - 1)] = 560 '\0'; 556 561 cmd->argv[i].intval = (unative_t) buf; 557 562 cmd->argv[i].vartype = ARG_TYPE_STRING; 558 } else if (!parse_int_arg(cmdline +start, end-start+1,559 &cmd->argv[i].intval))563 } else if (!parse_int_arg(cmdline + start, end - start + 1, 564 &cmd->argv[i].intval)) { 560 565 cmd->argv[i].vartype = ARG_TYPE_INT; 561 else {566 } else { 562 567 printf("Unrecognized variable argument.\n"); 563 568 error = 1;
Note:
See TracChangeset
for help on using the changeset viewer.