github.com/golang-haiku/go-1.4.3@v0.0.0-20190609233734-1f5ae41cc308/src/lib9/fmt/test.c (about)

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