Changeset 2feeb26 in rtems


Ignore:
Timestamp:
Nov 30, 2009, 12:47:44 PM (9 years ago)
Author:
Thomas Doerfler <Thomas.Doerfler@…>
Branches:
4.10, 4.11, master
Children:
51bdbca1
Parents:
f9925bc
Message:

Fixed output of unsigned integers.

Changed type of boolean variables to bool. Use unsigned integer type
for radix and width parameters.

Location:
cpukit
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • cpukit/ChangeLog

    rf9925bc r2feeb26  
    77        CACHED.
    88        * libblock/src/ide_part_table.c: Free memory in case of an error.
     9
     102009-11-30      Sebastian Huber <sebastian.huber@embedded-brains.de>
     11
     12        * libcsupport/src/vprintk.c: Fixed output of unsigned integers.
     13        Changed type of boolean variables to bool.  Use unsigned integer type
     14        for radix and width parameters.
    915
    10162009-11-30      Sebastian Huber <sebastian.huber@embedded-brains.de>
  • cpukit/libcsupport/src/vprintk.c

    rf9925bc r2feeb26  
    2323#include <stdarg.h>
    2424#include <stdio.h>
     25#include <stdbool.h>
    2526#include <rtems/bspIo.h>
    2627
    2728static void printNum(
    2829  long num,
    29   int base,
    30   int sign,
    31   int maxwidth,
    32   int lead
     30  unsigned base,
     31  bool sign,
     32  unsigned maxwidth,
     33  char lead
    3334);
    3435
     
    4748)
    4849{
    49   char     c;
    50   int      lflag, base, sign, width, lead, minus;
     50  for (; *fmt != '\0'; fmt++) {
     51    unsigned base = 0;
     52    unsigned width = 0;
     53    bool lflag = false;
     54    bool minus = false;
     55    bool sign = false;
     56    char lead = ' ';
     57    char c;
    5158
    52   for (; *fmt != '\0'; fmt++) {
    53     lflag = 0;
    54     base  = 0;
    55     sign = 0;
    56     width = 0;
    57     minus = 0;
    58     lead = ' ';
    5959    if (*fmt != '%') {
    6060      BSP_output_char(*fmt);
     
    6767    }
    6868    if (*fmt == '-' ) {
    69       minus = 1;
     69      minus = true;
    7070      fmt++;
    7171    }
    7272    while (*fmt >= '0' && *fmt <= '9' ) {
    7373      width *= 10;
    74       width += (*fmt - '0');
     74      width += ((unsigned) *fmt - '0');
    7575      fmt++;
    7676    }
    7777
    7878    if ((c = *fmt) == 'l') {
    79       lflag = 1;
     79      lflag = true;
    8080      c = *++fmt;
    8181    }
    8282    if ( c == 'c' ) {
    83       char chr = (char) va_arg(ap, int);
     83      char chr = va_arg(ap, char);
    8484      BSP_output_char(chr);
    8585      continue;
    8686    }
    8787    if ( c == 's' ) {
    88       int i, len;
     88      unsigned i, len;
    8989      char *s, *str;
    9090
     
    123123    /* must be a numeric format or something unsupported */
    124124    if ( c == 'o' || c == 'O' ) {
    125       base = 8; sign = 0;
     125      base = 8; sign = false;
    126126    } else if ( c == 'i' || c == 'I' ||
    127127                c == 'd' || c == 'D' ) {
    128       base = 10; sign = 1;
     128      base = 10; sign = true;
    129129    } else if ( c == 'u' || c == 'U' ) {
    130       base = 10; sign = 0;
     130      base = 10; sign = false;
    131131    } else if ( c == 'x' || c == 'X' ) {
    132       base = 16; sign = 0;
     132      base = 16; sign = false;
    133133    } else if ( c == 'p' ) {
    134       base = 16; sign = 0; lflag = 1;
     134      base = 16; sign = false; lflag = true;
    135135    } else {
    136136      BSP_output_char(c);
     
    156156static void printNum(
    157157  long num,
    158   int base,
    159   int sign,
    160   int maxwidth,
    161   int lead
     158  unsigned base,
     159  bool sign,
     160  unsigned maxwidth,
     161  char lead
    162162)
    163163{
    164   long n;
    165   int count;
     164  unsigned long unsigned_num;
     165  unsigned long n;
     166  unsigned count;
    166167  char toPrint[20];
    167168
    168   if ( (sign == 1) && ((long)num <  0) ) {
     169  if ( sign && (num <  0) ) {
    169170    BSP_output_char('-');
    170     num = -num;
     171    unsigned_num = (unsigned long) -num;
    171172    if (maxwidth) maxwidth--;
     173  } else {
     174    unsigned_num = (unsigned long) num;
    172175  }
    173176
    174177  count = 0;
    175   while ((n = num / base) > 0) {
    176     toPrint[count++] = (char) (num - (n*base));
    177     num = n;
     178  while ((n = unsigned_num / base) > 0) {
     179    toPrint[count++] = (char) (unsigned_num - (n * base));
     180    unsigned_num = n;
    178181  }
    179   toPrint[count++] = (char) num;
     182  toPrint[count++] = (char) unsigned_num;
    180183
    181184  for (n=maxwidth ; n > count; n-- )
    182     BSP_output_char((char) lead);
     185    BSP_output_char(lead);
    183186
    184187  for (n = 0; n < count; n++) {
Note: See TracChangeset for help on using the changeset viewer.