Rev 1197 | Rev 1234 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 1197 | Rev 1199 | ||
---|---|---|---|
Line 293... | Line 293... | ||
293 | 293 | ||
294 | return written; |
294 | return written; |
295 | } |
295 | } |
296 | 296 | ||
297 | 297 | ||
298 | - | ||
299 | /** General formatted text print |
298 | /** General formatted text print |
300 | * |
299 | * |
301 | * Print text formatted according the fmt parameter |
300 | * Print string formatted according the fmt parameter |
302 | * and variant arguments. Each formatting directive |
301 | * and variant arguments. Each formatting directive |
303 | * begins with \% (percentage) character and one of the |
- | |
304 | * following character: |
302 | * must have the following form: |
305 | * |
- | |
306 | * \% Prints the percentage character. |
- | |
307 | * |
- | |
308 | * s The next variant argument is treated as char* |
- | |
309 | * and printed as a NULL terminated string. |
- | |
310 | * |
- | |
311 | * c The next variant argument is treated as a single char. |
- | |
312 | * |
- | |
313 | * p The next variant argument is treated as a maximum |
- | |
314 | * bit-width integer with respect to architecture |
303 | * % [ flags ] [ width ] [ .precision ] [ type ] conversion |
315 | * and printed in full hexadecimal width. |
- | |
316 | * |
- | |
317 | * P As with 'p', but '0x' is prefixed. |
- | |
318 | * |
- | |
319 | * q The next variant argument is treated as a 64b integer |
- | |
320 | * and printed in full hexadecimal width. |
- | |
321 | * |
- | |
322 | * Q As with 'q', but '0x' is prefixed. |
- | |
323 | * |
- | |
324 | * l The next variant argument is treated as a 32b integer |
- | |
325 | * and printed in full hexadecimal width. |
- | |
326 | * |
- | |
327 | * L As with 'l', but '0x' is prefixed. |
- | |
328 | * |
- | |
329 | * w The next variant argument is treated as a 16b integer |
- | |
330 | * and printed in full hexadecimal width. |
- | |
331 | * |
- | |
332 | * W As with 'w', but '0x' is prefixed. |
- | |
333 | * |
- | |
334 | * b The next variant argument is treated as a 8b integer |
- | |
335 | * and printed in full hexadecimal width. |
- | |
336 | * |
- | |
337 | * B As with 'b', but '0x' is prefixed. |
- | |
338 | * |
304 | * |
- | 305 | * FLAGS: |
|
- | 306 | * # Force to print prefix. For conversion %o is prefix 0, for %x and %X are prefixes 0x and 0X and for conversion %b is prefix 0b. |
|
- | 307 | * - Align to left. |
|
- | 308 | * + Print positive sign just as negative. |
|
- | 309 | * (space) If printed number is positive and '+' flag is not set, print space in place of sign. |
|
- | 310 | * 0 Print 0 as padding instead of spaces. Zeroes are placed between sign and the rest of number. This flag is ignored if '-' flag is specified. |
|
- | 311 | * |
|
- | 312 | * WIDTH: |
|
- | 313 | * Specify minimal width of printed argument. If it is bigger, width is ignored. |
|
- | 314 | * If width is specified with a '*' character instead of number, width is taken from parameter list. |
|
- | 315 | * Int parameter expected before parameter for processed conversion specification. |
|
- | 316 | * If this value is negative it is taken its absolute value and the '-' flag is set. |
|
- | 317 | * |
|
- | 318 | * PRECISION: |
|
- | 319 | * Value precision. For numbers it specifies minimum valid numbers. |
|
- | 320 | * Smaller numbers are printed with leading zeroes. Bigger numbers are not affected. |
|
- | 321 | * Strings with more than precision characters are cutted of. |
|
339 | * d The next variant argument is treated as integer |
322 | * Just as width could be '*' used instead a number. |
- | 323 | * A int value is then expected in parameters. When both width and precision are specified using '*', |
|
340 | * and printed in standard decimal format (only significant |
324 | * first parameter is used for width and second one for precision. |
- | 325 | * |
|
- | 326 | * TYPE: |
|
- | 327 | * hh signed or unsigned char |
|
- | 328 | * h signed or usigned short |
|
- | 329 | * signed or usigned int (default value) |
|
- | 330 | * l signed or usigned long int |
|
- | 331 | * ll signed or usigned long long int |
|
341 | * digits). |
332 | * z size_t type |
- | 333 | * |
|
- | 334 | * |
|
- | 335 | * CONVERSIONS: |
|
- | 336 | * |
|
- | 337 | * % Print percentage character. |
|
- | 338 | * |
|
- | 339 | * c Print single character. |
|
- | 340 | * |
|
- | 341 | * s Print zero terminated string. If a NULL value is passed as value, "(NULL)" is printed instead. |
|
- | 342 | * |
|
- | 343 | * P, p Print value of a pointer. Void * value is expected and it is printed in hexadecimal notation with prefix |
|
- | 344 | * ( as with %#X or %#x for 32bit or %#X / %#x for 64bit long pointers) |
|
- | 345 | * |
|
- | 346 | * b Print value as unsigned binary number. Prefix is not printed by default. (Nonstandard extension.) |
|
- | 347 | * |
|
- | 348 | * o Print value as unsigned octal number. Prefix is not printed by default. |
|
342 | * |
349 | * |
343 | * x The next variant argument is treated as integer |
- | |
344 | * and printed in standard hexadecimal format (only significant |
350 | * d,i Print signed decimal number. There is no difference between d and i conversion. |
345 | * digits). |
- | |
346 | * |
351 | * |
347 | * X As with 'x', but '0x' is prefixed. |
352 | * u Print unsigned decimal number. |
348 | * |
353 | * |
- | 354 | * X, x Print hexadecimal number with upper- or lower-case. Prefix is not printed by default. |
|
- | 355 | * |
|
349 | * All other characters from fmt except the formatting directives |
356 | * All other characters from fmt except the formatting directives |
350 | * are printed in verbatim. |
357 | * are printed in verbatim. |
351 | * |
358 | * |
352 | * @param fmt Formatting NULL terminated string. |
359 | * @param fmt Formatting NULL terminated string. |
- | 360 | * @return count of printed characters or negative value on fail. |
|
353 | */ |
361 | */ |
354 | int printf(const char *fmt, ...) |
362 | int printf(const char *fmt, ...) |
355 | { |
363 | { |
356 | int i = 0, j = 0; /* i is index of currently processed char from fmt, j is index to the first not printed nonformating character */ |
364 | int i = 0, j = 0; /* i is index of currently processed char from fmt, j is index to the first not printed nonformating character */ |
357 | int end; |
365 | int end; |