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 171 of file printf-stdarg.c.

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

Referenced by printk(), and sprintf().

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


Generated on Fri Feb 19 02:24:08 2010 for AVR32 - H&D by  doxygen 1.5.5