kernel/utility/doprintf.c
/*
 * PrintFormattedInteger();
 *
 * Prints buf in the correct direction. Handles flags, padding and field width
 */


Prints buf in the correct direction. Handles flags, padding and field width
Prints buf in the correct direction . Handles flags padding and field width
void PrintFormattedInteger(char *buf, int32_t base, uint32_t flags,
                           int32_t width, void (*printchar_fp)(char, void *),
                           void *printchar_arg) {
  int32_t forepadding = 0;
  int32_t zeropadding = 0;
  int32_t tailpadding = 0;
  char *signstr = "";
  char *annotatestr = "";
  int32_t len, i, t;
  char sign;
  char *s;
  for (i = 0; buf[i] != '\0'; i++)
    ;
  sign = buf[i - 1];
  len = i - 1;
  if (sign == '-') {
    len += 1;
    signstr = "-";
  } else if (flags & FLAG_SIGN) {
    len += 1;
    signstr = (sign == '+') ? "+" : "-";
  }
  if (flags & FLAG_ALTERNATE) {
    if (base == 16) {
      len += 2;
      annotatestr = "0x";
    } else if (base == 8) {
      len += 1;
      annotatestr = "0";
    }
  }
  if (len < width) {
    if (flags & FLAG_ZERO)
      zeropadding = width - len;
    else if ((flags & FLAG_LEFT) == 0)
      forepadding = width - len;
    else
      tailpadding = width - len;
  }
  for (t = 0; t < forepadding; t++) 
    printchar_fp(' ', printchar_arg);
  for (s = signstr; *s != '\0'; s++) 
    printchar_fp(*s, printchar_arg);
  for (s = annotatestr; *s != '\0'; s++) 
    printchar_fp(*s, printchar_arg);
  for (t = 0; t < zeropadding; t++) 
    printchar_fp('0', printchar_arg);
  for (s = &buf[i - 2]; s >= &buf[0]; s--) 
  {
    if ((flags & FLAG_UPPERCASE) && *s >= 'a' && *s <= 'z')
      printchar_fp(ASCII_TO_UPPER(*s), printchar_arg);
    else
      printchar_fp(*s, printchar_arg);
  }
  for (t = 0; t < tailpadding; t++) 
    printchar_fp(' ', printchar_arg);
}
void PrintFormattedInteger ( char * buf , int32_t base , uint32_t flags , int32_t width , void ( * printchar_fp ) ( char , void * ) , void * printchar_arg ) { int32_t forepadding = 0 ; int32_t zeropadding = 0 ; int32_t tailpadding = 0 ; char * signstr = " " ; char * annotatestr = " " ; int32_t len , i , t ; char sign ; char * s ; for ( i = 0 ; buf [ i ] != ' \0 ' ; i ++ ) ; sign = buf [ i - 1 ] ; len = i - 1 ; if ( sign == ' ' ) { len += 1 ; signstr = " " ; } else if ( flags & FLAG_SIGN ) { len += 1 ; signstr = ( sign == ' ' ) ? " " : " " ; } if ( flags & FLAG_ALTERNATE ) { if ( base == 16 ) { len += 2 ; annotatestr = " " ; } else if ( base == 8 ) { len += 1 ; annotatestr = " " ; } } if ( len < width ) { if ( flags & FLAG_ZERO ) zeropadding = width - len ; else if ( ( flags & FLAG_LEFT ) == 0 ) forepadding = width - len ; else tailpadding = width - len ; } for ( t = 0 ; t < forepadding ; t ++ ) printchar_fp ( ' ' , printchar_arg ) ; for ( s = signstr ; * s != ' \0 ' ; s ++ ) printchar_fp ( * s , printchar_arg ) ; for ( s = annotatestr ; * s != ' \0 ' ; s ++ ) printchar_fp ( * s , printchar_arg ) ; for ( t = 0 ; t < zeropadding ; t ++ ) printchar_fp ( ' ' , printchar_arg ) ; for ( s = & buf [ i - 2 ] ; s >= & buf [ 0 ] ; s -- ) { if ( ( flags & FLAG_UPPERCASE ) && * s >= ' ' && * s <= ' ' ) printchar_fp ( ASCII_TO_UPPER ( * s ) , printchar_arg ) ; else printchar_fp ( * s , printchar_arg ) ; } for ( t = 0 ; t < tailpadding ; t ++ ) printchar_fp ( ' ' , printchar_arg ) ; }
PrintFormattedInteger();
PrintFormattedInteger () ;
/* Space padding */ /* Sign */ /* Base prefix */ /* Zero padding */ /* Digits in Buf */ /* Space padding */