2 * Copyright (c) 2002-2005 The Regents of The University of Michigan
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * Authors: Nathan Binkert
36 #include "base/cprintf.hh"
37 #include "base/misc.hh"
47 string _bar
= "asdfkhasdlkfjhasdlkfhjalksdjfhalksdjhfalksdjfhalksdjhf";
52 memcpy(bar
, _bar
.c_str(), length
);
56 cprintf("%shits%%s + %smisses%%s\n", "test", "test");
57 cprintf("%%s%-10s %c he went home \'\"%d %#o %#x %1.5f %1.2E\n",
58 "hello", 'A', 1, 0xff, 0xfffffffffffffULL
, 3.141592653589, 1.1e10
);
60 cprintf("another test\n");
63 ccprintf(buffer
, "%-10s %c he home \'\"%d %#o %#x %1.5f %1.2E\n",
64 "hello", 'A', 1, 0xff, 0xfffffffffffffULL
, 3.14159265, 1.1e10
);
66 double f
= 314159.26535897932384;
68 #define ctest(x, y) printf(x, y); cprintf(x, y); cprintf("\n");
76 ctest("%1000.8f\n", f
);
99 f
= 0.00000026535897932384;
106 ctest("%12.8f\n", f
);
117 ctest("%1.10f\n", f
);
118 ctest("%1.11f\n", f
);
119 ctest("%1.12f\n", f
);
120 ctest("%1.13f\n", f
);
121 ctest("%1.14f\n", f
);
122 ctest("%1.15f\n", f
);
123 ctest("%1.16f\n", f
);
124 ctest("%1.17f\n", f
);
125 ctest("%1.18f\n", f
);
127 f
= 0.00000026535897932384;
134 ctest("%12.8e\n", f
);
145 ctest("%1.10e\n", f
);
146 ctest("%1.11e\n", f
);
147 ctest("%1.12e\n", f
);
148 ctest("%1.13e\n", f
);
149 ctest("%1.14e\n", f
);
150 ctest("%1.15e\n", f
);
151 ctest("%1.16e\n", f
);
152 ctest("%1.17e\n", f
);
153 ctest("%1.18e\n", f
);
155 cout
<< buffer
.str();
161 string foo1
= "string test";
162 cprintf("%s\n", foo1
);
165 foo2
<< "stringstream test";
166 cprintf("%s\n", foo2
);
168 cprintf("%c %c\n", 'c', 65);
174 cprintf("%08.4f\n", 99.99);
175 cprintf("%0*.*f\n", 8, 4, 99.99);
176 cprintf("%07.*f\n", 4, 1.234);
177 cprintf("%#0*x\n", 9, 123412);