printf-stdarg.h File Reference

#include <stdarg.h>

Go to the source code of this file.

Functions

int printk (const char *format,...)
int printk_va (char **out, const char *format, va_list args)


Function Documentation

int printk ( const char *  format,
  ... 
)

int printk_va ( char **  out,
const char *  format,
va_list  args 
)

Definition at line 169 of file printf-stdarg.c.

References PAD_RIGHT, PAD_ZERO, printchar(), printi(), prints(), and width.

Referenced by printk(), and sprintf().

00170 {
00171     register int width, pad;
00172     register int pc = 0;
00173     char scr[2];
00174 
00175     for (; *format != 0; ++format) {
00176         if (*format == '%') {
00177             ++format;
00178             width = pad = 0;
00179             if (*format == '\0') break;
00180             if (*format == '%') goto out;
00181             if (*format == '-') {
00182                 ++format;
00183                 pad = PAD_RIGHT;
00184             }
00185             while (*format == '0') {
00186                 ++format;
00187                 pad |= PAD_ZERO;
00188             }
00189             for ( ; *format >= '0' && *format <= '9'; ++format) {
00190                 width *= 10;
00191                 width += *format - '0';
00192             }
00193             if( *format == 's' ) {
00194                 register char *s = (char *)va_arg( args, int );
00195                 pc += prints (out, s?s:"(null)", width, pad);
00196                 continue;
00197             }
00198             if( *format == 'd' ) {
00199                 pc += printi (out, va_arg( args, int ), 10, 1, width, pad, 'a');
00200                 continue;
00201             }
00202                         if( *format == 'p' ) {
00203                                 pad = 8;
00204                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
00205                 continue;
00206             }
00207             if( *format == 'x' ) {
00208                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'a');
00209                 continue;
00210             }
00211             if( *format == 'X' ) {
00212                 pc += printi (out, va_arg( args, int ), 16, 0, width, pad, 'A');
00213                 continue;
00214             }
00215             if( *format == 'u' ) {
00216                 pc += printi (out, va_arg( args, int ), 10, 0, width, pad, 'a');
00217                 continue;
00218             }
00219             if( *format == 'c' ) {
00220                 /* char are converted to int then pushed on the stack */
00221                 scr[0] = (char)va_arg( args, int );
00222                 scr[1] = '\0';
00223                 pc += prints (out, scr, width, pad);
00224                 continue;
00225             }
00226         }
00227         else {
00228         out:
00229             printchar (out, *format);
00230             ++pc;
00231         }
00232     }
00233     if (out) **out = '\0';
00234     va_end( args );
00235     return pc;
00236 }


Generated on Thu Dec 17 19:57:55 2009 for AVR32 - H&D by  doxygen 1.5.5