1 /*
2 * The authors of this software are Rob Pike and Ken Thompson,
3 * with contributions from Mike Burrows and Sean Dorward.
4 *
5 * Copyright (c) 2002-2006 by Lucent Technologies.
6 * Portions Copyright (c) 2004 Google Inc.
7 *
8 * Permission to use, copy, modify, and distribute this software for any
9 * purpose without fee is hereby granted, provided that this entire notice
10 * is included in all copies of any software which is or includes a copy
11 * or modification of this software and in all copies of the supporting
12 * documentation for such software.
13 * THIS SOFTWARE IS BEING PROVIDED "AS IS", WITHOUT ANY EXPRESS OR IMPLIED
14 * WARRANTY. IN PARTICULAR, NEITHER THE AUTHORS NOR LUCENT TECHNOLOGIES
15 * NOR GOOGLE INC MAKE ANY REPRESENTATION OR WARRANTY OF ANY KIND CONCERNING
16 * THE MERCHANTABILITY OF THIS SOFTWARE OR ITS FITNESS FOR ANY PARTICULAR PURPOSE.
17 */
18
19 #include <u.h>
20 #include <libc.h>
21 #include "fmtdef.h"
22
23 int
24 main(int argc, char *argv[])
25 {
26 quotefmtinstall();
27 print("hello world\n");
28 print("x: %x\n", 0x87654321);
29 print("u: %u\n", 0x87654321);
30 print("d: %d\n", 0x87654321);
31 print("s: %s\n", "hi there");
32 print("q: %q\n", "hi i'm here");
33 print("c: %c\n", '!');
34 print("g: %g %g %g\n", 3.14159, 3.14159e10, 3.14159e-10);
35 print("e: %e %e %e\n", 3.14159, 3.14159e10, 3.14159e-10);
36 print("f: %f %f %f\n", 3.14159, 3.14159e10, 3.14159e-10);
37 print("smiley: %C\n", (Rune)0x263a);
38 print("%g %.18g\n", 2e25, 2e25);
39 print("%2.18g\n", 1.0);
40 print("%2.18f\n", 1.0);
41 print("%f\n", 3.1415927/4);
42 print("%d\n", 23);
43 print("%i\n", 23);
44 print("%0.10d\n", 12345);
45
46 /* test %4$d formats */
47 print("%3$d %4$06d %2$d %1$d\n", 444, 333, 111, 222);
48 print("%3$d %4$06d %2$d %1$d\n", 444, 333, 111, 222);
49 print("%3$d %4$*5$06d %2$d %1$d\n", 444, 333, 111, 222, 20);
50 print("%3$hd %4$*5$06d %2$d %1$d\n", 444, 333, (short)111, 222, 20);
51 print("%3$lld %4$*5$06d %2$d %1$d\n", 444, 333, 111LL, 222, 20);
52
53 /* test %'d formats */
54 print("%'d %'d %'d\n", 1, 2222, 33333333);
55 print("%'019d\n", 0);
56 print("%08d %08d %08d\n", 1, 2222, 33333333);
57 print("%'08d %'08d %'08d\n", 1, 2222, 33333333);
58 print("%'x %'X %'b\n", 0x11111111, 0xabcd1234, 12345);
59 print("%'lld %'lld %'lld\n", 1LL, 222222222LL, 3333333333333LL);
60 print("%019lld %019lld %019lld\n", 1LL, 222222222LL, 3333333333333LL);
61 print("%'019lld %'019lld %'019lld\n", 1LL, 222222222LL, 3333333333333LL);
62 print("%'020lld %'020lld %'020lld\n", 1LL, 222222222LL, 3333333333333LL);
63 print("%'llx %'llX %'llb\n", 0x111111111111LL, 0xabcd12345678LL, 112342345LL);
64 return 0;
65 }