Changeset db25906 in mainline
- Timestamp:
- 2007-10-05T05:16:18Z (17 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- c4e75ea
- Parents:
- f7fad5a
- Location:
- kernel
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/kbd/key.c
rf7fad5a rdb25906 145 145 break; 146 146 default: 147 letter = is_lower(ascii); 148 capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); 147 letter = islower(ascii); 148 capslock = (keyflags & PRESSED_CAPSLOCK) || 149 (lockflags & LOCKED_CAPSLOCK); 149 150 shift = keyflags & PRESSED_SHIFT; 150 151 if (letter && capslock) … … 233 234 break; 234 235 default: 235 letter = is_lower(ascii); 236 capslock = (keyflags & PRESSED_CAPSLOCK) || (lockflags & LOCKED_CAPSLOCK); 236 letter = islower(ascii); 237 capslock = (keyflags & PRESSED_CAPSLOCK) || 238 (lockflags & LOCKED_CAPSLOCK); 237 239 shift = keyflags & PRESSED_SHIFT; 238 240 if (letter && capslock) -
kernel/generic/include/macros.h
rf7fad5a rdb25906 38 38 #include <arch/types.h> 39 39 40 #define is _digit(d) (((d) >= '0') && ((d) <= '9'))41 #define is _lower(c) (((c) >= 'a') && ((c) <= 'z'))42 #define is _upper(c) (((c) >= 'A') && ((c) <= 'Z'))43 #define is _alpha(c) (is_lower(c) || is_upper(c))44 #define is _alphanum(c) (is_alpha(c) || is_digit(c))45 #define is _white(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') || \40 #define isdigit(d) (((d) >= '0') && ((d) <= '9')) 41 #define islower(c) (((c) >= 'a') && ((c) <= 'z')) 42 #define isupper(c) (((c) >= 'A') && ((c) <= 'Z')) 43 #define isalpha(c) (is_lower(c) || is_upper(c)) 44 #define isalphanum(c) (is_alpha(c) || is_digit(c)) 45 #define isspace(c) (((c) == ' ') || ((c) == '\t') || ((c) == '\n') || \ 46 46 ((c) == '\r')) 47 47 -
kernel/generic/src/console/kconsole.c
rf7fad5a rdb25906 617 617 for (i = *start; i < len; i++) { 618 618 if (!found_start) { 619 if (is _white(cmdline[i]))619 if (isspace(cmdline[i])) 620 620 (*start)++; 621 621 else 622 622 found_start = true; 623 623 } else { 624 if (is _white(cmdline[i]))624 if (isspace(cmdline[i])) 625 625 break; 626 626 } -
kernel/generic/src/printf/printf_core.c
rf7fad5a rdb25906 40 40 #include <print.h> 41 41 #include <arch/arg.h> 42 #include <macros.h> 43 #include <func.h> 42 44 #include <arch.h> 43 45 44 #define __PRINTF_FLAG_PREFIX 0x00000001 /**< show prefixes 0x or 0*/ 45 #define __PRINTF_FLAG_SIGNED 0x00000002 /**< signed / unsigned number */ 46 #define __PRINTF_FLAG_ZEROPADDED 0x00000004 /**< print leading zeroes */ 47 #define __PRINTF_FLAG_LEFTALIGNED 0x00000010 /**< align to left */ 48 #define __PRINTF_FLAG_SHOWPLUS 0x00000020 /**< always show + sign */ 49 #define __PRINTF_FLAG_SPACESIGN 0x00000040 /**< print space instead of plus */ 50 #define __PRINTF_FLAG_BIGCHARS 0x00000080 /**< show big characters */ 51 #define __PRINTF_FLAG_NEGATIVE 0x00000100 /**< number has - sign */ 52 53 #define PRINT_NUMBER_BUFFER_SIZE (64+5) /**< Buffer big enought for 64 bit number 54 * printed in base 2, sign, prefix and 55 * 0 to terminate string.. (last one is only for better testing 56 * end of buffer by zero-filling subroutine)*/ 46 /** show prefixes 0x or 0 */ 47 #define __PRINTF_FLAG_PREFIX 0x00000001 48 /** signed / unsigned number */ 49 #define __PRINTF_FLAG_SIGNED 0x00000002 50 /** print leading zeroes */ 51 #define __PRINTF_FLAG_ZEROPADDED 0x00000004 52 /** align to left */ 53 #define __PRINTF_FLAG_LEFTALIGNED 0x00000010 54 /** always show + sign */ 55 #define __PRINTF_FLAG_SHOWPLUS 0x00000020 56 /** print space instead of plus */ 57 #define __PRINTF_FLAG_SPACESIGN 0x00000040 58 /** show big characters */ 59 #define __PRINTF_FLAG_BIGCHARS 0x00000080 60 /** number has - sign */ 61 #define __PRINTF_FLAG_NEGATIVE 0x00000100 62 63 /** 64 * Buffer big enough for 64-bit number printed in base 2, sign, prefix and 0 65 * to terminate string... (last one is only for better testing end of buffer by 66 * zero-filling subroutine) 67 */ 68 #define PRINT_NUMBER_BUFFER_SIZE (64 + 5) 57 69 58 70 /** Enumeration of possible arguments types. … … 68 80 } qualifier_t; 69 81 70 static char digits_small[] = "0123456789abcdef"; /**< Small hexadecimal characters */ 71 static char digits_big[] = "0123456789ABCDEF"; /**< Big hexadecimal characters */ 72 73 /** Checks c for a digit. 74 * @param c One character. 75 * @return nonzero if c is from interval '0 to '9'. 76 */ 77 static inline int isdigit(int c) 78 { 79 return ((c >= '0' )&&( c <= '9')); 80 } 81 82 /** Compute length of given zero terminated string. 83 * @param str Pointer to valid string. 84 * @return string length without trailing zero. 85 */ 86 static unative_t strlen(const char *str) 87 { 88 unative_t counter = 0; 89 90 while (str[counter] != 0) { 91 counter++; 92 } 93 94 return counter; 95 } 96 97 /** Print count chars from buffer without adding newline 98 * @param buf Buffer with size at least count bytes - NULL pointer NOT allowed! 99 * @param count 100 * @param ps output method and its data 101 * @return number of printed characters 102 */ 103 static int printf_putnchars(const char * buf, size_t count, struct printf_spec *ps) 82 static char digits_small[] = "0123456789abcdef"; 83 static char digits_big[] = "0123456789ABCDEF"; 84 85 /** Print one or more characters without adding newline. 86 * 87 * @param buf Buffer with size at least count bytes. NULL pointer is 88 * not allowed! 89 * @param count Number of characters to print. 90 * @param ps Output method and its data. 91 * @return Number of characters printed. 92 */ 93 static int printf_putnchars(const char * buf, size_t count, 94 struct printf_spec *ps) 104 95 { 105 96 return ps->write((void *)buf, count, ps->data); 106 97 } 107 98 108 /** Print string without added newline 109 * @param str string to print 110 * @param ps write function specification and support data 111 * @return number of printed characters 99 /** Print a string without adding a newline. 100 * 101 * @param str String to print. 102 * @param ps Write function specification and support data. 103 * @return Number of characters printed. 112 104 */ 113 105 static int printf_putstr(const char * str, struct printf_spec *ps) … … 116 108 117 109 if (str == NULL) { 118 return printf_putnchars("(NULL)", 6, ps); 110 char *nullstr = "(NULL)"; 111 return printf_putnchars(nullstr, strlen(nullstr), ps); 119 112 } 120 113 … … 124 117 } 125 118 126 /** Print one character to output 127 * @param c one character 128 * @param ps output method 129 * @return number of printed characters 119 /** Print one character. 120 * 121 * @param c Character to be printed. 122 * @param ps Output method. 123 * 124 * @return Number of characters printed. 130 125 */ 131 126 static int printf_putchar(int c, struct printf_spec *ps) … … 136 131 } 137 132 138 /** Print one formatted character 139 * @param c character to print 140 * @param width 141 * @param flags 142 * @return number of printed characters, negative value on fail 133 /** Print one formatted character. 134 * 135 * @param c Character to print. 136 * @param width Width modifier. 137 * @param flags Flags that change the way the character is printed. 138 * 139 * @return Number of characters printed, negative value on failure. 143 140 */ 144 141 static int print_char(char c, int width, uint64_t flags, struct printf_spec *ps) … … 147 144 148 145 if (!(flags & __PRINTF_FLAG_LEFTALIGNED)) { 149 while (--width > 0) { /* one space is consumed by character itself hence predecrement */ 146 while (--width > 0) { 147 /* 148 * One space is consumed by the character itself, hence 149 * the predecrement. 150 */ 150 151 if (printf_putchar(' ', ps) > 0) 151 152 ++counter; … … 156 157 counter++; 157 158 158 while (--width > 0) { /* one space is consumed by character itself hence predecrement */ 159 while (--width > 0) { 160 /* 161 * One space is consumed by the character itself, hence 162 * the predecrement. 163 */ 159 164 if (printf_putchar(' ', ps) > 0) 160 165 ++counter; … … 164 169 } 165 170 166 /** Print one string 167 * @param s string 168 * @param width 169 * @param precision 170 * @param flags 171 * @return number of printed characters or negative value on fail 172 */ 173 174 static int print_string(char *s, int width, int precision, uint64_t flags, struct printf_spec *ps) 171 /** Print string. 172 * 173 * @param s String to be printed. 174 * @param width Width modifier. 175 * @param precision Precision modifier. 176 * @param flags Flags that modify the way the string is printed. 177 * 178 * @return Number of characters printed, negative value on failure. 179 */ 180 static int print_string(char *s, int width, int precision, uint64_t flags, 181 struct printf_spec *ps) 175 182 { 176 183 int counter = 0; … … 198 205 } 199 206 200 if ((retval = printf_putnchars(s, size < precision ? size : precision, 201 ps)) < 0) { 207 if ((retval = printf_putnchars(s, min(size, precision), ps)) < 0) { 202 208 return -counter; 203 209 } … … 213 219 214 220 215 /** Print number in given base216 * 217 * Print significant digits of a number in given 218 * base.219 * 220 * @param num Number to print.221 * @param width222 * @param precision223 * @param base Base to print the number in (should224 * be in range 2 .. 16).225 * @ param flags output modifiers226 * @return number of written characters or EOF227 * 228 */ 229 static int print_number(uint64_t num, int width, int precision, int base ,uint64_t flags, struct printf_spec *ps)221 /** Print a number in a given base. 222 * 223 * Print significant digits of a number in given base. 224 * 225 * @param num Number to print. 226 * @param widt Width modifier.h 227 * @param precision Precision modifier. 228 * @param base Base to print the number in (must be between 2 and 16). 229 * @param flags Flags that modify the way the number is printed. 230 * 231 * @return Number of characters printed. 232 * 233 */ 234 static int print_number(uint64_t num, int width, int precision, int base, 235 uint64_t flags, struct printf_spec *ps) 230 236 { 231 237 char *digits = digits_small; 232 char d[PRINT_NUMBER_BUFFER_SIZE]; /* this is good enough even for base == 2, prefix and sign */238 char d[PRINT_NUMBER_BUFFER_SIZE]; 233 239 char *ptr = &d[PRINT_NUMBER_BUFFER_SIZE - 1]; 234 int size = 0; 235 int number_size; /* size of plain number */240 int size = 0; /* size of number with all prefixes and signs */ 241 int number_size; /* size of plain number */ 236 242 char sgn; 237 243 int retval; … … 255 261 number_size = size; 256 262 257 /* Collect sum of all prefixes/signs/... to calculate padding and leading zeroes */ 263 /* 264 * Collect the sum of all prefixes/signs/... to calculate padding and 265 * leading zeroes. 266 */ 258 267 if (flags & __PRINTF_FLAG_PREFIX) { 259 268 switch(base) { … … 276 285 size++; 277 286 } else if (flags & __PRINTF_FLAG_SHOWPLUS) { 278 279 280 281 282 283 287 sgn = '+'; 288 size++; 289 } else if (flags & __PRINTF_FLAG_SPACESIGN) { 290 sgn = ' '; 291 size++; 292 } 284 293 } 285 294 … … 288 297 } 289 298 290 /* if number is leftaligned or precision is specified then zeropadding is ignored */ 299 /* 300 * If the number is leftaligned or precision is specified then 301 * zeropadding is ignored. 302 */ 291 303 if (flags & __PRINTF_FLAG_ZEROPADDED) { 292 304 if ((precision == 0) && (width > size)) { … … 296 308 297 309 /* print leading spaces */ 298 if (number_size > precision) /* We must print whole number not only a part */ 310 if (number_size > precision) { 311 /* print the whole number not only a part */ 299 312 precision = number_size; 313 } 300 314 301 315 width -= precision + size - number_size; … … 375 389 /** Print formatted string. 376 390 * 377 * Print string formatted according to the fmt parameter 378 * and variadic arguments. Each formatting directive 379 * must have the following form: 391 * Print string formatted according to the fmt parameter and variadic arguments. 392 * Each formatting directive must have the following form: 380 393 * 381 394 * \% [ FLAGS ] [ WIDTH ] [ .PRECISION ] [ TYPE ] CONVERSION 382 395 * 383 396 * FLAGS:@n 384 * - "#" Force to print prefix.385 * For conversion \%o the prefix is 0, for \%x and \%X prefixes are 0x and 0X386 * and for conversion \%b theprefix is 0b.397 * - "#" Force to print prefix.For \%o conversion, the prefix is 0, for 398 * \%x and \%X prefixes are 0x and 0X and for conversion \%b the 399 * prefix is 0b. 387 400 * 388 401 * - "-" Align to left. … … 390 403 * - "+" Print positive sign just as negative. 391 404 * 392 * - " " If the printed number is positive and "+" flag is not set, print space in 393 * place of sign. 394 * 395 * - "0" Print 0 as padding instead of spaces. Zeroes are placed between sign and the 396 * rest of the number. This flag is ignored if "-" flag is specified. 405 * - " " If the printed number is positive and "+" flag is not set, 406 * print space in place of sign. 407 * 408 * - "0" Print 0 as padding instead of spaces. Zeroes are placed between 409 * sign and the rest of the number. This flag is ignored if "-" 410 * flag is specified. 397 411 * 398 412 * WIDTH:@n 399 * - Specify minimal width of printed argument. If it is bigger, width is ignored. 400 * If width is specified with a "*" character instead of number, width is taken from 401 * parameter list. And integer parameter is expected before parameter for processed 402 * conversion specification. If this value is negative its absolute value is taken 403 * and the "-" flag is set. 413 * - Specify the minimal width of a printed argument. If it is bigger, 414 * width is ignored. If width is specified with a "*" character instead of 415 * number, width is taken from parameter list. And integer parameter is 416 * expected before parameter for processed conversion specification. If 417 * this value is negative its absolute value is taken and the "-" flag is 418 * set. 404 419 * 405 420 * PRECISION:@n 406 421 * - Value precision. For numbers it specifies minimum valid numbers. 407 * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected.408 * Strings with more than precision characters are cut off.409 * Just as with width, an "*" can be used used instead of a number.410 * An integer value is then expected in parameters. When both width and precision411 * are specified using "*", the first parameter is used for width and the second one412 * for precision.422 * Smaller numbers are printed with leading zeroes. Bigger numbers are not 423 * affected. Strings with more than precision characters are cut off. Just 424 * as with width, an "*" can be used used instead of a number. An integer 425 * value is then expected in parameters. When both width and precision are 426 * specified using "*", the first parameter is used for width and the 427 * second one for precision. 413 428 * 414 429 * TYPE:@n … … 426 441 * - c Print single character. 427 442 * 428 * - s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead. 443 * - s Print zero terminated string. If a NULL value is passed as 444 * value, "(NULL)" is printed instead. 429 445 * 430 * - P, p Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix 431 * (as with \%#X / \%#x for 32bit or \%#X / \%#x for 64bit long pointers). 432 * 433 * - b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.) 446 * - P, p Print value of a pointer. Void * value is expected and it is 447 * printed in hexadecimal notation with prefix (as with \%#X / \%#x 448 * for 32-bit or \%#X / \%#x for 64-bit long pointers). 449 * 450 * - b Print value as unsigned binary number. Prefix is not printed by 451 * default. (Nonstandard extension.) 434 452 * 435 * - o Print value as unsigned octal number. Prefix is not printed by default. 436 * 437 * - d,i Print signed decimal number. There is no difference between d and i conversion. 453 * - o Print value as unsigned octal number. Prefix is not printed by 454 * default. 455 * 456 * - d, i Print signed decimal number. There is no difference between d 457 * and i conversion. 438 458 * 439 459 * - u Print unsigned decimal number. 440 460 * 441 * - X, x Print hexadecimal number with upper- or lower-case. Prefix is not printed by default. 461 * - X, x Print hexadecimal number with upper- or lower-case. Prefix isi 462 * not printed by default. 442 463 * 443 * All other characters from fmt except the formatting directives 444 * are printed inverbatim.445 * 446 * @param fmt 447 * @return Number of printed characters ornegative value on failure.464 * All other characters from fmt except the formatting directives are printed in 465 * verbatim. 466 * 467 * @param fmt Formatting NULL terminated string. 468 * @return Number of characters printed, negative value on failure. 448 469 */ 449 470 int printf_core(const char *fmt, struct printf_spec *ps, va_list ap) 450 471 { 451 int i = 0, j = 0; /**< i is index of currently processed char from fmt, j is index to the first not printed nonformating character */ 472 int i = 0; /* index of the currently processed char from fmt */ 473 int j = 0; /* index to the first not printed nonformating character */ 452 474 int end; 453 int counter; /* *<counter of printed characters */454 int retval; /* *<used to store return values from called functions */475 int counter; /* counter of printed characters */ 476 int retval; /* used to store return values from called functions */ 455 477 char c; 456 qualifier_t qualifier; 457 int base; /**< base in which will be parameter (numbers only)printed */458 uint64_t number; /* *<argument value */459 size_t size; /* *<byte size of integer parameter */478 qualifier_t qualifier; /* type of argument */ 479 int base; /* base in which a numeric parameter will be printed */ 480 uint64_t number; /* argument value */ 481 size_t size; /* byte size of integer parameter */ 460 482 int width, precision; 461 483 uint64_t flags; … … 468 490 /* print common characters if any processed */ 469 491 if (i > j) { 470 if ((retval = printf_putnchars(&fmt[j], (size_t)(i - j), ps)) < 0) { /* error */ 492 if ((retval = printf_putnchars(&fmt[j], 493 (size_t)(i - j), ps)) < 0) { /* error */ 471 494 counter = -counter; 472 495 goto out; … … 483 506 ++i; 484 507 switch (c = fmt[i]) { 485 case '#': flags |= __PRINTF_FLAG_PREFIX; break; 486 case '-': flags |= __PRINTF_FLAG_LEFTALIGNED; break; 487 case '+': flags |= __PRINTF_FLAG_SHOWPLUS; break; 488 case ' ': flags |= __PRINTF_FLAG_SPACESIGN; break; 489 case '0': flags |= __PRINTF_FLAG_ZEROPADDED; break; 490 default: end = 1; 508 case '#': 509 flags |= __PRINTF_FLAG_PREFIX; 510 break; 511 case '-': 512 flags |= __PRINTF_FLAG_LEFTALIGNED; 513 break; 514 case '+': 515 flags |= __PRINTF_FLAG_SHOWPLUS; 516 break; 517 case ' ': 518 flags |= __PRINTF_FLAG_SPACESIGN; 519 break; 520 case '0': 521 flags |= __PRINTF_FLAG_ZEROPADDED; 522 break; 523 default: 524 end = 1; 491 525 }; 492 526 … … 501 535 } 502 536 } else if (fmt[i] == '*') { 503 /* get width value from argument list */537 /* get width value from argument list */ 504 538 i++; 505 539 width = (int)va_arg(ap, int); 506 540 if (width < 0) { 507 /* negative width means to set'-' flag */541 /* negative width sets '-' flag */ 508 542 width *= -1; 509 543 flags |= __PRINTF_FLAG_LEFTALIGNED; … … 521 555 } 522 556 } else if (fmt[i] == '*') { 523 /* get precision value from argument list*/ 557 /* 558 * Get precision value from the argument 559 * list. 560 */ 524 561 i++; 525 562 precision = (int)va_arg(ap, int); 526 563 if (precision < 0) { 527 /* negative precision means to ignore it*/564 /* ignore negative precision */ 528 565 precision = 0; 529 566 } … … 532 569 533 570 switch (fmt[i++]) { 534 /** TODO:unimplemented qualifiers:571 /** @todo unimplemented qualifiers: 535 572 * t ptrdiff_t - ISO C 99 536 573 */ … … 553 590 break; 554 591 default: 555 qualifier = PrintfQualifierInt; /* default type */ 592 /* default type */ 593 qualifier = PrintfQualifierInt; 556 594 --i; 557 595 } … … 565 603 */ 566 604 case 's': 567 if ((retval = print_string(va_arg(ap, char*), width, precision, flags, ps)) < 0) { 605 if ((retval = print_string(va_arg(ap, char *), 606 width, precision, flags, ps)) < 0) { 568 607 counter = -counter; 569 608 goto out; … … 575 614 case 'c': 576 615 c = va_arg(ap, unsigned int); 577 if ((retval = print_char(c, width, flags, ps)) < 0) { 616 retval = print_char(c, width, flags, ps); 617 if (retval < 0) { 578 618 counter = -counter; 579 619 goto out; … … 618 658 */ 619 659 default: 620 /* Unknown format621 * now, j is index of '%' so we will622 * print whole bad format sequence660 /* 661 * Unknown format. Now, j is the index of '%' 662 * so we will print whole bad format sequence. 623 663 */ 624 664 goto next_char; … … 647 687 case PrintfQualifierLongLong: 648 688 size = sizeof(unsigned long long); 649 number = (uint64_t)va_arg(ap, unsigned long long); 689 number = (uint64_t)va_arg(ap, 690 unsigned long long); 650 691 break; 651 692 case PrintfQualifierPointer: 652 693 size = sizeof(void *); 653 number = (uint64_t)(unsigned long)va_arg(ap, void *); 694 number = (uint64_t)(unsigned long)va_arg(ap, 695 void *); 654 696 break; 655 697 case PrintfQualifierNative: … … 663 705 664 706 if (flags & __PRINTF_FLAG_SIGNED) { 665 if (number & (0x1 << (size *8 - 1))) {707 if (number & (0x1 << (size * 8 - 1))) { 666 708 flags |= __PRINTF_FLAG_NEGATIVE; 667 709 … … 670 712 } else { 671 713 number = ~number; 672 number &= (~((0xFFFFFFFFFFFFFFFFll) << (size * 8))); 714 number &= 715 ~(0xFFFFFFFFFFFFFFFFll << 716 (size * 8)); 673 717 number++; 674 718 } … … 676 720 } 677 721 678 if ((retval = print_number(number, width, precision, base, flags, ps)) < 0) { 722 if ((retval = print_number(number, width, precision, 723 base, flags, ps)) < 0) { 679 724 counter = -counter; 680 725 goto out; 681 } ;726 } 682 727 683 728 counter += retval; … … 690 735 691 736 if (i > j) { 692 if ((retval = printf_putnchars(&fmt[j], (unative_t)(i - j), ps)) < 0) { /* error */ 737 if ((retval = printf_putnchars(&fmt[j], (unative_t)(i - j), 738 ps)) < 0) { /* error */ 693 739 counter = -counter; 694 740 goto out;
Note:
See TracChangeset
for help on using the changeset viewer.