Rev 2050 | Rev 2071 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2050 | Rev 2053 | ||
---|---|---|---|
Line 30... | Line 30... | ||
30 | 30 | ||
31 | #define BUFFER_SIZE 32 |
31 | #define BUFFER_SIZE 32 |
32 | 32 | ||
33 | char * test_print1(bool quiet) |
33 | char * test_print1(bool quiet) |
34 | { |
34 | { |
- | 35 | if (!quiet) { |
|
35 | int retval; |
36 | int retval; |
36 | unative_t nat = 0x12345678u; |
37 | unative_t nat = 0x12345678u; |
37 | 38 | ||
38 | char buffer[BUFFER_SIZE]; |
39 | char buffer[BUFFER_SIZE]; |
39 | 40 | ||
40 | printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
41 | printf(" text 10.8s %*.*s \n", 5, 3, "text"); |
41 | printf(" very long text 10.8s %10.8s \n", "very long text"); |
42 | printf(" very long text 10.8s %10.8s \n", "very long text"); |
42 | printf(" text 8.10s %8.10s \n", "text"); |
43 | printf(" text 8.10s %8.10s \n", "text"); |
43 | printf(" very long text 8.10s %8.10s \n", "very long text"); |
44 | printf(" very long text 8.10s %8.10s \n", "very long text"); |
44 | 45 | ||
45 | printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' ); |
46 | printf(" char: c '%c', 3.2c '%3.2c', -3.2c '%-3.2c', 2.3c '%2.3c', -2.3c '%-2.3c' \n",'a', 'b', 'c', 'd', 'e' ); |
46 | printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 ); |
47 | printf(" int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",1, 1, 1, 1, 1 ); |
47 | printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 ); |
48 | printf(" -int: d '%d', 3.2d '%3.2d', -3.2d '%-3.2d', 2.3d '%2.3d', -2.3d '%-2.3d' \n",-1, -1, -1, -1, -1 ); |
48 | printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 ); |
49 | printf(" 0xint: x '%#x', 5.3x '%#5.3x', -5.3x '%#-5.3x', 3.5x '%#3.5x', -3.5x '%#-3.5x' \n",17, 17, 17, 17, 17 ); |
49 | 50 | ||
50 | printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); |
51 | printf("'%#llx' 64bit, '%#x' 32bit, '%#hhx' 8bit, '%#hx' 16bit, unative_t '%#zx'. '%#llx' 64bit and '%s' string.\n", 0x1234567887654321ll, 0x12345678, 0x12, 0x1234, nat, 0x1234567887654321ull, "Lovely string" ); |
51 | 52 | ||
52 | printf(" Print to NULL '%s'\n", NULL); |
53 | printf(" Print to NULL '%s'\n", NULL); |
53 | 54 | ||
54 | retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
55 | retval = snprintf(buffer, BUFFER_SIZE, "Short text without parameters."); |
55 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
56 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
56 | 57 | ||
57 | retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
58 | retval = snprintf(buffer, BUFFER_SIZE, "Very very very long text without parameters."); |
58 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
59 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
59 | 60 | ||
60 | printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
61 | printf("Print short text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
61 | retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); |
62 | retval = snprintf(buffer, BUFFER_SIZE, "Short %s", "text"); |
62 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
63 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
63 | 64 | ||
64 | printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
65 | printf("Print long text to %d char long buffer via snprintf.\n", BUFFER_SIZE); |
65 | retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); |
66 | retval = snprintf(buffer, BUFFER_SIZE, "Very long %s. This text`s length is more than %d. We are interested in the result.", "text" , BUFFER_SIZE); |
66 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
67 | printf("Result is: '%s', retval = %d\n", buffer, retval); |
- | 68 | } |
|
67 | 69 | ||
68 | return NULL; |
70 | return NULL; |
69 | } |
71 | } |