?lang_form? ?lang_select? ?lang_submit? ?lang_endform?
{HEADER END}
{BLAME START}

library

?curdirlinks? -

Blame information for rev 6

Line No. Rev Author Line
1 6 kaklik <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
2 <html><head><meta http-equiv="Content-Type" content="text/html;charset=iso-8859-1">
3 <title>Procyon AVRlib: rprintf.c Source File</title>
4 <link href="dox.css" rel="stylesheet" type="text/css">
5 </head><body>
6 <!-- Generated by Doxygen 1.4.2 -->
7 <div class="qindex"><a class="qindex" href="main.html">Main&nbsp;Page</a> | <a class="qindex" href="modules.html">Modules</a> | <a class="qindex" href="annotated.html">Data&nbsp;Structures</a> | <a class="qindex" href="dirs.html">Directories</a> | <a class="qindex" href="files.html">File&nbsp;List</a> | <a class="qindex" href="functions.html">Data&nbsp;Fields</a> | <a class="qindex" href="globals.html">Globals</a> | <a class="qindex" href="pages.html">Related&nbsp;Pages</a></div>
8 <h1>rprintf.c</h1><a href="rprintf_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file rprintf.c \brief printf routine and associated routines. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'rprintf.c'</span>
12 00005 <span class="comment">// Title : printf routine and associated routines</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2000-2002</span>
14 00007 <span class="comment">// Created : 2000.12.26</span>
15 00008 <span class="comment">// Revised : 2003.5.1</span>
16 00009 <span class="comment">// Version : 1.0</span>
17 00010 <span class="comment">// Target MCU : Atmel AVR series and other targets</span>
18 00011 <span class="comment">// Editor Tabs : 4</span>
19 00012 <span class="comment">//</span>
20 00013 <span class="comment">// NOTE: This code is currently below version 1.0, and therefore is considered</span>
21 00014 <span class="comment">// to be lacking in some functionality or documentation, or may not be fully</span>
22 00015 <span class="comment">// tested. Nonetheless, you can expect most functions to work.</span>
23 00016 <span class="comment">//</span>
24 00017 <span class="comment">// This code is distributed under the GNU Public License</span>
25 00018 <span class="comment">// which can be found at http://www.gnu.org/licenses/gpl.txt</span>
26 00019 <span class="comment">//</span>
27 00020 <span class="comment">//*****************************************************************************</span>
28 00021
29 00022 <span class="preprocessor">#include &lt;avr/pgmspace.h&gt;</span>
30 00023 <span class="comment">//#include &lt;string-avr.h&gt;</span>
31 00024 <span class="comment">//#include &lt;stdlib.h&gt;</span>
32 00025 <span class="preprocessor">#include &lt;stdarg.h&gt;</span>
33 00026 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span>
34 00027 <span class="preprocessor">#include "<a class="code" href="rprintf_8h.html">rprintf.h</a>"</span>
35 00028
36 00029 <span class="preprocessor">#ifndef TRUE</span>
37 00030 <span class="preprocessor"></span><span class="preprocessor"> #define TRUE -1</span>
38 00031 <span class="preprocessor"></span><span class="preprocessor"> #define FALSE 0</span>
39 00032 <span class="preprocessor"></span><span class="preprocessor">#endif</span>
40 00033 <span class="preprocessor"></span>
41 00034 <span class="preprocessor">#define INF 32766 // maximum field size to print</span>
42 00035 <span class="preprocessor"></span><span class="preprocessor">#define READMEMBYTE(a,char_ptr) ((a)?(pgm_read_byte(char_ptr)):(*char_ptr))</span>
43 00036 <span class="preprocessor"></span>
44 00037 <span class="preprocessor">#ifdef RPRINTF_COMPLEX</span>
45 00038 <span class="preprocessor"></span> <span class="keyword">static</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> buf[128];
46 00039 <span class="preprocessor">#endif</span>
47 00040 <span class="preprocessor"></span>
48 00041 <span class="comment">// use this to store hex conversion in RAM</span>
49 00042 <span class="comment">//static char HexChars[] = "0123456789ABCDEF";</span>
50 00043 <span class="comment">// use this to store hex conversion in program memory</span>
51 00044 <span class="comment">//static prog_char HexChars[] = "0123456789ABCDEF";</span>
52 00045 <span class="keyword">static</span> <span class="keywordtype">char</span> __attribute__ ((progmem)) HexChars[] = "0123456789ABCDEF";
53 00046
54 00047 #define hexchar(x) pgm_read_byte( HexChars+((x)&amp;0x0f) )
55 00048 <span class="comment">//#define hexchar(x) ((((x)&amp;0x0F)&gt;9)?((x)+'A'-10):((x)+'0'))</span>
56 00049
57 00050 <span class="comment">// function pointer to single character output routine</span>
58 00051 static <span class="keywordtype">void</span> (*rputchar)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c);
59 00052
60 00053 <span class="comment">// *** rprintf initialization ***</span>
61 00054 <span class="comment">// you must call this function once and supply the character output</span>
62 00055 <span class="comment">// routine before using other functions in this library</span>
63 00056 <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga0">rprintfInit</a>(<span class="keywordtype">void</span> (*putchar_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c))
64 00057 {
65 00058 rputchar = putchar_func;
66 00059 }
67 00060
68 00061 <span class="comment">// *** rprintfChar ***</span>
69 00062 <span class="comment">// send a character/byte to the current output device</span>
70 <a name="l00063"></a><a class="code" href="group__rprintf.html#ga1">00063</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c)
71 00064 {
72 00065 <span class="comment">// do LF -&gt; CR/LF translation</span>
73 00066 <span class="keywordflow">if</span>(c == <span class="charliteral">'\n'</span>)
74 00067 rputchar(<span class="charliteral">'\r'</span>);
75 00068 <span class="comment">// send character</span>
76 00069 rputchar(c);
77 00070 }
78 00071
79 00072 <span class="comment">// *** rprintfStr ***</span>
80 00073 <span class="comment">// prints a null-terminated string stored in RAM</span>
81 <a name="l00074"></a><a class="code" href="group__rprintf.html#ga2">00074</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga2">rprintfStr</a>(<span class="keywordtype">char</span> str[])
82 00075 {
83 00076 <span class="comment">// send a string stored in RAM</span>
84 00077 <span class="comment">// check to make sure we have a good pointer</span>
85 00078 <span class="keywordflow">if</span> (!str) <span class="keywordflow">return</span>;
86 00079
87 00080 <span class="comment">// print the string until a null-terminator</span>
88 00081 <span class="keywordflow">while</span> (*str)
89 00082 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(*str++);
90 00083 }
91 00084
92 00085 <span class="comment">// *** rprintfStrLen ***</span>
93 00086 <span class="comment">// prints a section of a string stored in RAM</span>
94 00087 <span class="comment">// begins printing at position indicated by &lt;start&gt;</span>
95 00088 <span class="comment">// prints number of characters indicated by &lt;len&gt;</span>
96 <a name="l00089"></a><a class="code" href="group__rprintf.html#ga3">00089</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga3">rprintfStrLen</a>(<span class="keywordtype">char</span> str[], <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> start, <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> len)
97 00090 {
98 00091 <span class="keyword">register</span> <span class="keywordtype">int</span> i=0;
99 00092
100 00093 <span class="comment">// check to make sure we have a good pointer</span>
101 00094 <span class="keywordflow">if</span> (!str) <span class="keywordflow">return</span>;
102 00095 <span class="comment">// spin through characters up to requested start</span>
103 00096 <span class="comment">// keep going as long as there's no null</span>
104 00097 <span class="keywordflow">while</span>((i++&lt;start) &amp;&amp; (*str++));
105 00098 <span class="comment">// for(i=0; i&lt;start; i++)</span>
106 00099 <span class="comment">// {</span>
107 00100 <span class="comment">// // keep steping through string as long as there's no null</span>
108 00101 <span class="comment">// if(*str) str++;</span>
109 00102 <span class="comment">// }</span>
110 00103
111 00104 <span class="comment">// then print exactly len characters</span>
112 00105 <span class="keywordflow">for</span>(i=0; i&lt;len; i++)
113 00106 {
114 00107 <span class="comment">// print data out of the string as long as we haven't reached a null yet</span>
115 00108 <span class="comment">// at the null, start printing spaces</span>
116 00109 <span class="keywordflow">if</span>(*str)
117 00110 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(*str++);
118 00111 <span class="keywordflow">else</span>
119 00112 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">' '</span>);
120 00113 }
121 00114
122 00115 }
123 00116
124 00117 <span class="comment">// *** rprintfProgStr ***</span>
125 00118 <span class="comment">// prints a null-terminated string stored in program ROM</span>
126 <a name="l00119"></a><a class="code" href="group__rprintf.html#ga4">00119</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga4">rprintfProgStr</a>(<span class="keyword">const</span> prog_char str[])
127 00120 {
128 00121 <span class="comment">// print a string stored in program memory</span>
129 00122 <span class="keyword">register</span> <span class="keywordtype">char</span> c;
130 00123
131 00124 <span class="comment">// check to make sure we have a good pointer</span>
132 00125 <span class="keywordflow">if</span> (!str) <span class="keywordflow">return</span>;
133 00126
134 00127 <span class="comment">// print the string until the null-terminator</span>
135 00128 <span class="keywordflow">while</span>((c = pgm_read_byte(str++)))
136 00129 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(c);
137 00130 }
138 00131
139 00132 <span class="comment">// *** rprintfCRLF ***</span>
140 00133 <span class="comment">// prints carriage return and line feed</span>
141 <a name="l00134"></a><a class="code" href="group__rprintf.html#ga5">00134</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga5">rprintfCRLF</a>(<span class="keywordtype">void</span>)
142 00135 {
143 00136 <span class="comment">// print CR/LF</span>
144 00137 <span class="comment">//rprintfChar('\r');</span>
145 00138 <span class="comment">// LF -&gt; CR/LF translation built-in to rprintfChar()</span>
146 00139 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">'\n'</span>);
147 00140 }
148 00141
149 00142 <span class="comment">// *** rprintfu04 ***</span>
150 00143 <span class="comment">// prints an unsigned 4-bit number in hex (1 digit)</span>
151 <a name="l00144"></a><a class="code" href="group__rprintf.html#ga6">00144</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga6">rprintfu04</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data)
152 00145 {
153 00146 <span class="comment">// print 4-bit hex value</span>
154 00147 <span class="comment">// char Character = data&amp;0x0f;</span>
155 00148 <span class="comment">// if (Character&gt;9)</span>
156 00149 <span class="comment">// Character+='A'-10;</span>
157 00150 <span class="comment">// else</span>
158 00151 <span class="comment">// Character+='0';</span>
159 00152 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(hexchar(data));
160 00153 }
161 00154
162 00155 <span class="comment">// *** rprintfu08 ***</span>
163 00156 <span class="comment">// prints an unsigned 8-bit number in hex (2 digits)</span>
164 <a name="l00157"></a><a class="code" href="group__rprintf.html#ga7">00157</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> data)
165 00158 {
166 00159 <span class="comment">// print 8-bit hex value</span>
167 00160 <a class="code" href="group__rprintf.html#ga6">rprintfu04</a>(data&gt;&gt;4);
168 00161 <a class="code" href="group__rprintf.html#ga6">rprintfu04</a>(data);
169 00162 }
170 00163
171 00164 <span class="comment">// *** rprintfu16 ***</span>
172 00165 <span class="comment">// prints an unsigned 16-bit number in hex (4 digits)</span>
173 <a name="l00166"></a><a class="code" href="group__rprintf.html#ga8">00166</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">short</span> data)
174 00167 {
175 00168 <span class="comment">// print 16-bit hex value</span>
176 00169 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(data&gt;&gt;8);
177 00170 <a class="code" href="group__rprintf.html#ga7">rprintfu08</a>(data);
178 00171 }
179 00172
180 00173 <span class="comment">// *** rprintfu32 ***</span>
181 00174 <span class="comment">// prints an unsigned 32-bit number in hex (8 digits)</span>
182 <a name="l00175"></a><a class="code" href="group__rprintf.html#ga9">00175</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga9">rprintfu32</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> data)
183 00176 {
184 00177 <span class="comment">// print 32-bit hex value</span>
185 00178 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(data&gt;&gt;16);
186 00179 <a class="code" href="group__rprintf.html#ga8">rprintfu16</a>(data);
187 00180 }
188 00181
189 00182 <span class="comment">// *** rprintfNum ***</span>
190 00183 <span class="comment">// special printf for numbers only</span>
191 00184 <span class="comment">// see formatting information below</span>
192 00185 <span class="comment">// Print the number "n" in the given "base"</span>
193 00186 <span class="comment">// using exactly "numDigits"</span>
194 00187 <span class="comment">// print +/- if signed flag "isSigned" is TRUE</span>
195 00188 <span class="comment">// use the character specified in "padchar" to pad extra characters</span>
196 00189 <span class="comment">//</span>
197 00190 <span class="comment">// Examples:</span>
198 00191 <span class="comment">// uartPrintfNum(10, 6, TRUE, ' ', 1234); --&gt; " +1234"</span>
199 00192 <span class="comment">// uartPrintfNum(10, 6, FALSE, '0', 1234); --&gt; "001234"</span>
200 00193 <span class="comment">// uartPrintfNum(16, 6, FALSE, '.', 0x5AA5); --&gt; "..5AA5"</span>
201 <a name="l00194"></a><a class="code" href="group__rprintf.html#ga10">00194</a> <span class="keywordtype">void</span> <a class="code" href="group__rprintf.html#ga10">rprintfNum</a>(<span class="keywordtype">char</span> base, <span class="keywordtype">char</span> numDigits, <span class="keywordtype">char</span> isSigned, <span class="keywordtype">char</span> padchar, <span class="keywordtype">long</span> n)
202 00195 {
203 00196 <span class="comment">// define a global HexChars or use line below</span>
204 00197 <span class="comment">//static char HexChars[16] = "0123456789ABCDEF";</span>
205 00198 <span class="keywordtype">char</span> *p, buf[32];
206 00199 <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> x;
207 00200 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> count;
208 00201
209 00202 <span class="comment">// prepare negative number</span>
210 00203 <span class="keywordflow">if</span>( isSigned &amp;&amp; (n &lt; 0) )
211 00204 {
212 00205 x = -n;
213 00206 }
214 00207 <span class="keywordflow">else</span>
215 00208 {
216 00209 x = n;
217 00210 }
218 00211
219 00212 <span class="comment">// setup little string buffer</span>
220 00213 count = (numDigits-1)-(isSigned?1:0);
221 00214 p = buf + <span class="keyword">sizeof</span> (buf);
222 00215 *--p = <span class="charliteral">'\0'</span>;
223 00216
224 00217 <span class="comment">// force calculation of first digit</span>
225 00218 <span class="comment">// (to prevent zero from not printing at all!!!)</span>
226 00219 *--p = hexchar(x%base); x /= base;
227 00220 <span class="comment">// calculate remaining digits</span>
228 00221 <span class="keywordflow">while</span>(count--)
229 00222 {
230 00223 <span class="keywordflow">if</span>(x != 0)
231 00224 {
232 00225 <span class="comment">// calculate next digit</span>
233 00226 *--p = hexchar(x%base); x /= base;
234 00227 }
235 00228 <span class="keywordflow">else</span>
236 00229 {
237 00230 <span class="comment">// no more digits left, pad out to desired length</span>
238 00231 *--p = padchar;
239 00232 }
240 00233 }
241 00234
242 00235 <span class="comment">// apply signed notation if requested</span>
243 00236 <span class="keywordflow">if</span>( isSigned )
244 00237 {
245 00238 <span class="keywordflow">if</span>(n &lt; 0)
246 00239 {
247 00240 *--p = <span class="charliteral">'-'</span>;
248 00241 }
249 00242 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(n &gt; 0)
250 00243 {
251 00244 *--p = <span class="charliteral">'+'</span>;
252 00245 }
253 00246 <span class="keywordflow">else</span>
254 00247 {
255 00248 *--p = <span class="charliteral">' '</span>;
256 00249 }
257 00250 }
258 00251
259 00252 <span class="comment">// print the string right-justified</span>
260 00253 count = numDigits;
261 00254 <span class="keywordflow">while</span>(count--)
262 00255 {
263 00256 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(*p++);
264 00257 }
265 00258 }
266 00259
267 00260 <span class="preprocessor">#ifdef RPRINTF_FLOAT</span>
268 00261 <span class="preprocessor"></span><span class="comment">// *** rprintfFloat ***</span>
269 00262 <span class="comment">// floating-point print</span>
270 00263 <span class="keywordtype">void</span> rprintfFloat(<span class="keywordtype">char</span> numDigits, <span class="keywordtype">double</span> x)
271 00264 {
272 00265 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> firstplace = FALSE;
273 00266 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> negative;
274 00267 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> i, digit;
275 00268 <span class="keywordtype">double</span> place = 1.0;
276 00269
277 00270 <span class="comment">// save sign</span>
278 00271 negative = (x&lt;0);
279 00272 <span class="comment">// convert to absolute value</span>
280 00273 x = (x&gt;0)?(x):(-x);
281 00274
282 00275 <span class="comment">// find starting digit place</span>
283 00276 <span class="keywordflow">for</span>(i=0; i&lt;15; i++)
284 00277 {
285 00278 <span class="keywordflow">if</span>((x/place) &lt; 10.0)
286 00279 <span class="keywordflow">break</span>;
287 00280 <span class="keywordflow">else</span>
288 00281 place *= 10.0;
289 00282 }
290 00283 <span class="comment">// print polarity character</span>
291 00284 <span class="keywordflow">if</span>(negative)
292 00285 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">'-'</span>);
293 00286 <span class="keywordflow">else</span>
294 00287 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">'+'</span>);
295 00288
296 00289 <span class="comment">// print digits</span>
297 00290 <span class="keywordflow">for</span>(i=0; i&lt;numDigits; i++)
298 00291 {
299 00292 digit = (x/place);
300 00293
301 00294 <span class="keywordflow">if</span>(digit | firstplace | (place == 1.0))
302 00295 {
303 00296 firstplace = TRUE;
304 00297 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(digit+0x30);
305 00298 }
306 00299 <span class="keywordflow">else</span>
307 00300 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">' '</span>);
308 00301
309 00302 <span class="keywordflow">if</span>(place == 1.0)
310 00303 {
311 00304 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">'.'</span>);
312 00305 }
313 00306
314 00307 x -= (digit*place);
315 00308 place /= 10.0;
316 00309 }
317 00310 }
318 00311 <span class="preprocessor">#endif</span>
319 00312 <span class="preprocessor"></span>
320 00313 <span class="preprocessor">#ifdef RPRINTF_SIMPLE</span>
321 00314 <span class="preprocessor"></span><span class="comment">// *** rprintf1RamRom ***</span>
322 00315 <span class="comment">// called by rprintf() - does a simple printf (supports %d, %x, %c)</span>
323 00316 <span class="comment">// Supports:</span>
324 00317 <span class="comment">// %d - decimal</span>
325 00318 <span class="comment">// %x - hex</span>
326 00319 <span class="comment">// %c - character</span>
327 <a name="l00320"></a><a class="code" href="group__rprintf.html#ga11">00320</a> <span class="keywordtype">int</span> <a class="code" href="group__rprintf.html#ga11">rprintf1RamRom</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> stringInRom, <span class="keyword">const</span> <span class="keywordtype">char</span> *format, ...)
328 00321 {
329 00322 <span class="comment">// simple printf routine</span>
330 00323 <span class="comment">// define a global HexChars or use line below</span>
331 00324 <span class="comment">//static char HexChars[16] = "0123456789ABCDEF";</span>
332 00325 <span class="keywordtype">char</span> format_flag;
333 00326 <span class="keywordtype">unsigned</span> <span class="keywordtype">int</span> u_val, div_val, base;
334 00327 va_list ap;
335 00328
336 00329 va_start(ap, format);
337 00330 <span class="keywordflow">for</span> (;;)
338 00331 {
339 00332 <span class="keywordflow">while</span> ((format_flag = READMEMBYTE(stringInRom,format++) ) != <span class="charliteral">'%'</span>)
340 00333 { <span class="comment">// Until '%' or '\0'</span>
341 00334 <span class="keywordflow">if</span> (!format_flag)
342 00335 {
343 00336 va_end(ap);
344 00337 <span class="keywordflow">return</span>(0);
345 00338 }
346 00339 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(format_flag);
347 00340 }
348 00341
349 00342 <span class="keywordflow">switch</span> (format_flag = READMEMBYTE(stringInRom,format++) )
350 00343 {
351 00344 <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: format_flag = va_arg(ap,<span class="keywordtype">int</span>);
352 00345 <span class="keywordflow">default</span>: <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(format_flag); <span class="keywordflow">continue</span>;
353 00346 <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: base = 10; div_val = 10000; <span class="keywordflow">goto</span> CONVERSION_LOOP;
354 00347 <span class="comment">// case 'x': base = 16; div_val = 0x10;</span>
355 00348 <span class="keywordflow">case</span> <span class="charliteral">'x'</span>: base = 16; div_val = 0x1000;
356 00349
357 00350 CONVERSION_LOOP:
358 00351 u_val = va_arg(ap,<span class="keywordtype">int</span>);
359 00352 <span class="keywordflow">if</span> (format_flag == <span class="charliteral">'d'</span>)
360 00353 {
361 00354 <span class="keywordflow">if</span> (((<span class="keywordtype">int</span>)u_val) &lt; 0)
362 00355 {
363 00356 u_val = - u_val;
364 00357 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">'-'</span>);
365 00358 }
366 00359 <span class="keywordflow">while</span> (div_val &gt; 1 &amp;&amp; div_val &gt; u_val) div_val /= 10;
367 00360 }
368 00361 <span class="keywordflow">do</span>
369 00362 {
370 00363 <span class="comment">//rprintfChar(pgm_read_byte(HexChars+(u_val/div_val)));</span>
371 00364 <a class="code" href="group__rprintf.html#ga6">rprintfu04</a>(u_val/div_val);
372 00365 u_val %= div_val;
373 00366 div_val /= base;
374 00367 } <span class="keywordflow">while</span> (div_val);
375 00368 }
376 00369 }
377 00370 va_end(ap);
378 00371 }
379 00372 <span class="preprocessor">#endif</span>
380 00373 <span class="preprocessor"></span>
381 00374
382 00375 <span class="preprocessor">#ifdef RPRINTF_COMPLEX</span>
383 00376 <span class="preprocessor"></span><span class="comment">// *** rprintf2RamRom ***</span>
384 00377 <span class="comment">// called by rprintf() - does a more powerful printf (supports %d, %u, %o, %x, %c, %s)</span>
385 00378 <span class="comment">// Supports:</span>
386 00379 <span class="comment">// %d - decimal</span>
387 00380 <span class="comment">// %u - unsigned decimal</span>
388 00381 <span class="comment">// %o - octal</span>
389 00382 <span class="comment">// %x - hex</span>
390 00383 <span class="comment">// %c - character</span>
391 00384 <span class="comment">// %s - strings</span>
392 00385 <span class="comment">// and the width,precision,padding modifiers</span>
393 00386 <span class="comment">// **this printf does not support floating point numbers</span>
394 00387 <span class="keywordtype">int</span> rprintf2RamRom(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> stringInRom, <span class="keyword">const</span> <span class="keywordtype">char</span> *sfmt, ...)
395 00388 {
396 00389 <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *f, *bp;
397 00390 <span class="keyword">register</span> <span class="keywordtype">long</span> l;
398 00391 <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span> u;
399 00392 <span class="keyword">register</span> <span class="keywordtype">int</span> i;
400 00393 <span class="keyword">register</span> <span class="keywordtype">int</span> fmt;
401 00394 <span class="keyword">register</span> <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> pad = <span class="charliteral">' '</span>;
402 00395 <span class="keywordtype">int</span> flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0;
403 00396 <span class="keywordtype">int</span> sign = 0;
404 00397
405 00398 va_list ap;
406 00399 va_start(ap, sfmt);
407 00400
408 00401 f = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) sfmt;
409 00402
410 00403 <span class="keywordflow">for</span> (; READMEMBYTE(stringInRom,f); f++)
411 00404 {
412 00405 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) != <span class="charliteral">'%'</span>)
413 00406 { <span class="comment">// not a format character</span>
414 00407 <span class="comment">// then just output the char</span>
415 00408 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(READMEMBYTE(stringInRom,f));
416 00409 }
417 00410 <span class="keywordflow">else</span>
418 00411 {
419 00412 f++; <span class="comment">// if we have a "%" then skip it</span>
420 00413 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) == <span class="charliteral">'-'</span>)
421 00414 {
422 00415 flush_left = 1; <span class="comment">// minus: flush left</span>
423 00416 f++;
424 00417 }
425 00418 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) == <span class="charliteral">'0'</span>
426 00419 || READMEMBYTE(stringInRom,f) == <span class="charliteral">'.'</span>)
427 00420 {
428 00421 <span class="comment">// padding with 0 rather than blank</span>
429 00422 pad = <span class="charliteral">'0'</span>;
430 00423 f++;
431 00424 }
432 00425 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) == <span class="charliteral">'*'</span>)
433 00426 { <span class="comment">// field width</span>
434 00427 f_width = va_arg(ap, <span class="keywordtype">int</span>);
435 00428 f++;
436 00429 }
437 00430 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (Isdigit(READMEMBYTE(stringInRom,f)))
438 00431 {
439 00432 f_width = atoiRamRom(stringInRom, (<span class="keywordtype">char</span> *) f);
440 00433 <span class="keywordflow">while</span> (Isdigit(READMEMBYTE(stringInRom,f)))
441 00434 f++; <span class="comment">// skip the digits</span>
442 00435 }
443 00436 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) == <span class="charliteral">'.'</span>)
444 00437 { <span class="comment">// precision</span>
445 00438 f++;
446 00439 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) == <span class="charliteral">'*'</span>)
447 00440 {
448 00441 prec = va_arg(ap, <span class="keywordtype">int</span>);
449 00442 f++;
450 00443 }
451 00444 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (Isdigit(READMEMBYTE(stringInRom,f)))
452 00445 {
453 00446 prec = atoiRamRom(stringInRom, (<span class="keywordtype">char</span> *) f);
454 00447 <span class="keywordflow">while</span> (Isdigit(READMEMBYTE(stringInRom,f)))
455 00448 f++; <span class="comment">// skip the digits</span>
456 00449 }
457 00450 }
458 00451 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) == <span class="charliteral">'#'</span>)
459 00452 { <span class="comment">// alternate form</span>
460 00453 hash = 1;
461 00454 f++;
462 00455 }
463 00456 <span class="keywordflow">if</span> (READMEMBYTE(stringInRom,f) == <span class="charliteral">'l'</span>)
464 00457 { <span class="comment">// long format</span>
465 00458 do_long = 1;
466 00459 f++;
467 00460 }
468 00461
469 00462 fmt = READMEMBYTE(stringInRom,f);
470 00463 bp = buf;
471 00464 <span class="keywordflow">switch</span> (fmt) { <span class="comment">// do the formatting</span>
472 00465 <span class="keywordflow">case</span> <span class="charliteral">'d'</span>: <span class="comment">// 'd' signed decimal</span>
473 00466 <span class="keywordflow">if</span> (do_long)
474 00467 l = va_arg(ap, <span class="keywordtype">long</span>);
475 00468 <span class="keywordflow">else</span>
476 00469 l = (long) (va_arg(ap, <span class="keywordtype">int</span>));
477 00470 <span class="keywordflow">if</span> (l &lt; 0)
478 00471 {
479 00472 sign = 1;
480 00473 l = -l;
481 00474 }
482 00475 <span class="keywordflow">do</span> {
483 00476 *bp++ = l % 10 + <span class="charliteral">'0'</span>;
484 00477 } <span class="keywordflow">while</span> ((l /= 10) &gt; 0);
485 00478 <span class="keywordflow">if</span> (sign)
486 00479 *bp++ = <span class="charliteral">'-'</span>;
487 00480 f_width = f_width - (bp - buf);
488 00481 <span class="keywordflow">if</span> (!flush_left)
489 00482 <span class="keywordflow">while</span> (f_width-- &gt; 0)
490 00483 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(pad);
491 00484 <span class="keywordflow">for</span> (bp--; bp &gt;= buf; bp--)
492 00485 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(*bp);
493 00486 <span class="keywordflow">if</span> (flush_left)
494 00487 <span class="keywordflow">while</span> (f_width-- &gt; 0)
495 00488 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">' '</span>);
496 00489 <span class="keywordflow">break</span>;
497 00490 <span class="keywordflow">case</span> <span class="charliteral">'o'</span>: <span class="comment">// 'o' octal number</span>
498 00491 <span class="keywordflow">case</span> <span class="charliteral">'x'</span>: <span class="comment">// 'x' hex number</span>
499 00492 <span class="keywordflow">case</span> <span class="charliteral">'u'</span>: <span class="comment">// 'u' unsigned decimal</span>
500 00493 <span class="keywordflow">if</span> (do_long)
501 00494 u = va_arg(ap, <span class="keywordtype">unsigned</span> <span class="keywordtype">long</span>);
502 00495 <span class="keywordflow">else</span>
503 00496 u = (<span class="keywordtype">unsigned</span> long) (va_arg(ap, <span class="keywordtype">unsigned</span>));
504 00497 <span class="keywordflow">if</span> (fmt == <span class="charliteral">'u'</span>)
505 00498 { <span class="comment">// unsigned decimal</span>
506 00499 <span class="keywordflow">do</span> {
507 00500 *bp++ = u % 10 + <span class="charliteral">'0'</span>;
508 00501 } <span class="keywordflow">while</span> ((u /= 10) &gt; 0);
509 00502 }
510 00503 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fmt == <span class="charliteral">'o'</span>)
511 00504 { <span class="comment">// octal</span>
512 00505 <span class="keywordflow">do</span> {
513 00506 *bp++ = u % 8 + <span class="charliteral">'0'</span>;
514 00507 } <span class="keywordflow">while</span> ((u /= 8) &gt; 0);
515 00508 <span class="keywordflow">if</span> (hash)
516 00509 *bp++ = <span class="charliteral">'0'</span>;
517 00510 }
518 00511 <span class="keywordflow">else</span> <span class="keywordflow">if</span> (fmt == <span class="charliteral">'x'</span>)
519 00512 { <span class="comment">// hex</span>
520 00513 <span class="keywordflow">do</span> {
521 00514 i = u % 16;
522 00515 <span class="keywordflow">if</span> (i &lt; 10)
523 00516 *bp++ = i + <span class="charliteral">'0'</span>;
524 00517 <span class="keywordflow">else</span>
525 00518 *bp++ = i - 10 + <span class="charliteral">'a'</span>;
526 00519 } <span class="keywordflow">while</span> ((u /= 16) &gt; 0);
527 00520 <span class="keywordflow">if</span> (hash)
528 00521 {
529 00522 *bp++ = <span class="charliteral">'x'</span>;
530 00523 *bp++ = <span class="charliteral">'0'</span>;
531 00524 }
532 00525 }
533 00526 i = f_width - (bp - buf);
534 00527 <span class="keywordflow">if</span> (!flush_left)
535 00528 <span class="keywordflow">while</span> (i-- &gt; 0)
536 00529 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(pad);
537 00530 <span class="keywordflow">for</span> (bp--; bp &gt;= buf; bp--)
538 00531 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>((<span class="keywordtype">int</span>) (*bp));
539 00532 <span class="keywordflow">if</span> (flush_left)
540 00533 <span class="keywordflow">while</span> (i-- &gt; 0)
541 00534 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">' '</span>);
542 00535 <span class="keywordflow">break</span>;
543 00536 <span class="keywordflow">case</span> <span class="charliteral">'c'</span>: <span class="comment">// 'c' character</span>
544 00537 i = va_arg(ap, <span class="keywordtype">int</span>);
545 00538 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>((<span class="keywordtype">int</span>) (i));
546 00539 <span class="keywordflow">break</span>;
547 00540 <span class="keywordflow">case</span> <span class="charliteral">'s'</span>: <span class="comment">// 's' string</span>
548 00541 bp = va_arg(ap, <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *);
549 00542 <span class="keywordflow">if</span> (!bp)
550 00543 bp = (<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> *) <span class="stringliteral">"(nil)"</span>;
551 00544 f_width = f_width - strlen((<span class="keywordtype">char</span> *) bp);
552 00545 <span class="keywordflow">if</span> (!flush_left)
553 00546 <span class="keywordflow">while</span> (f_width-- &gt; 0)
554 00547 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(pad);
555 00548 <span class="keywordflow">for</span> (i = 0; *bp &amp;&amp; i &lt; prec; i++)
556 00549 {
557 00550 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(*bp);
558 00551 bp++;
559 00552 }
560 00553 <span class="keywordflow">if</span> (flush_left)
561 00554 <span class="keywordflow">while</span> (f_width-- &gt; 0)
562 00555 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">' '</span>);
563 00556 <span class="keywordflow">break</span>;
564 00557 <span class="keywordflow">case</span> <span class="charliteral">'%'</span>: <span class="comment">// '%' character</span>
565 00558 <a class="code" href="group__rprintf.html#ga1">rprintfChar</a>(<span class="charliteral">'%'</span>);
566 00559 <span class="keywordflow">break</span>;
567 00560 }
568 00561 flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0;
569 00562 sign = 0;
570 00563 pad = <span class="charliteral">' '</span>;
571 00564 }
572 00565 }
573 00566
574 00567 va_end(ap);
575 00568 <span class="keywordflow">return</span> 0;
576 00569 }
577 00570
578 00571 <span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> Isdigit(<span class="keywordtype">char</span> c)
579 00572 {
580 00573 <span class="keywordflow">if</span>((c &gt;= 0x30) &amp;&amp; (c &lt;= 0x39))
581 00574 <span class="keywordflow">return</span> TRUE;
582 00575 <span class="keywordflow">else</span>
583 00576 <span class="keywordflow">return</span> FALSE;
584 00577 }
585 00578
586 00579 <span class="keywordtype">int</span> atoiRamRom(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> stringInRom, <span class="keywordtype">char</span> *str)
587 00580 {
588 00581 <span class="keywordtype">int</span> num = 0;;
589 00582
590 00583 <span class="keywordflow">while</span>(Isdigit(READMEMBYTE(stringInRom,str)))
591 00584 {
592 00585 num *= 10;
593 00586 num += ((READMEMBYTE(stringInRom,str++)) - 0x30);
594 00587 }
595 00588 <span class="keywordflow">return</span> num;
596 00589 }
597 00590
598 00591 <span class="preprocessor">#endif</span>
599 00592 <span class="preprocessor"></span>
600 00593 <span class="comment">//******************************************************************************</span>
601 00594 <span class="comment">// code below this line is commented out and can be ignored</span>
602 00595 <span class="comment">//******************************************************************************</span>
603 00596 <span class="comment">/*</span>
604 00597 <span class="comment">char* sprintf(const char *sfmt, ...)</span>
605 00598 <span class="comment">{</span>
606 00599 <span class="comment"> register unsigned char *f, *bp, *str;</span>
607 00600 <span class="comment"> register long l;</span>
608 00601 <span class="comment"> register unsigned long u;</span>
609 00602 <span class="comment"> register int i;</span>
610 00603 <span class="comment"> register int fmt;</span>
611 00604 <span class="comment"> register unsigned char pad = ' ';</span>
612 00605 <span class="comment"> int flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0;</span>
613 00606 <span class="comment"> int sign = 0;</span>
614 00607 <span class="comment"></span>
615 00608 <span class="comment"> va_list ap;</span>
616 00609 <span class="comment"> va_start(ap, sfmt);</span>
617 00610 <span class="comment"></span>
618 00611 <span class="comment"> str = bufstring;</span>
619 00612 <span class="comment"> f = (unsigned char *) sfmt;</span>
620 00613 <span class="comment"></span>
621 00614 <span class="comment"> for (; *f; f++)</span>
622 00615 <span class="comment"> {</span>
623 00616 <span class="comment"> if (*f != '%')</span>
624 00617 <span class="comment"> { // not a format character</span>
625 00618 <span class="comment"> *str++ = (*f); // then just output the char</span>
626 00619 <span class="comment"> }</span>
627 00620 <span class="comment"> else </span>
628 00621 <span class="comment"> {</span>
629 00622 <span class="comment"> f++; // if we have a "%" then skip it</span>
630 00623 <span class="comment"> if (*f == '-')</span>
631 00624 <span class="comment"> {</span>
632 00625 <span class="comment"> flush_left = 1; // minus: flush left</span>
633 00626 <span class="comment"> f++;</span>
634 00627 <span class="comment"> }</span>
635 00628 <span class="comment"> if (*f == '0' || *f == '.')</span>
636 00629 <span class="comment"> {</span>
637 00630 <span class="comment"> // padding with 0 rather than blank</span>
638 00631 <span class="comment"> pad = '0';</span>
639 00632 <span class="comment"> f++;</span>
640 00633 <span class="comment"> }</span>
641 00634 <span class="comment"> if (*f == '*')</span>
642 00635 <span class="comment"> { // field width</span>
643 00636 <span class="comment"> f_width = va_arg(ap, int);</span>
644 00637 <span class="comment"> f++;</span>
645 00638 <span class="comment"> }</span>
646 00639 <span class="comment"> else if (Isdigit(*f))</span>
647 00640 <span class="comment"> {</span>
648 00641 <span class="comment"> f_width = atoi((char *) f);</span>
649 00642 <span class="comment"> while (Isdigit(*f))</span>
650 00643 <span class="comment"> f++; // skip the digits</span>
651 00644 <span class="comment"> }</span>
652 00645 <span class="comment"> if (*f == '.')</span>
653 00646 <span class="comment"> { // precision</span>
654 00647 <span class="comment"> f++;</span>
655 00648 <span class="comment"> if (*f == '*')</span>
656 00649 <span class="comment"> {</span>
657 00650 <span class="comment"> prec = va_arg(ap, int);</span>
658 00651 <span class="comment"> f++;</span>
659 00652 <span class="comment"> }</span>
660 00653 <span class="comment"> else if (Isdigit(*f))</span>
661 00654 <span class="comment"> {</span>
662 00655 <span class="comment"> prec = atoi((char *) f);</span>
663 00656 <span class="comment"> while (Isdigit(*f))</span>
664 00657 <span class="comment"> f++; // skip the digits</span>
665 00658 <span class="comment"> }</span>
666 00659 <span class="comment"> }</span>
667 00660 <span class="comment"> if (*f == '#')</span>
668 00661 <span class="comment"> { // alternate form</span>
669 00662 <span class="comment"> hash = 1;</span>
670 00663 <span class="comment"> f++;</span>
671 00664 <span class="comment"> }</span>
672 00665 <span class="comment"> if (*f == 'l')</span>
673 00666 <span class="comment"> { // long format</span>
674 00667 <span class="comment"> do_long = 1;</span>
675 00668 <span class="comment"> f++;</span>
676 00669 <span class="comment"> }</span>
677 00670 <span class="comment"></span>
678 00671 <span class="comment"> fmt = *f;</span>
679 00672 <span class="comment"> bp = buf;</span>
680 00673 <span class="comment"> switch (fmt) { // do the formatting</span>
681 00674 <span class="comment"> case 'd': // 'd' signed decimal</span>
682 00675 <span class="comment"> if (do_long)</span>
683 00676 <span class="comment"> l = va_arg(ap, long);</span>
684 00677 <span class="comment"> else</span>
685 00678 <span class="comment"> l = (long) (va_arg(ap, int));</span>
686 00679 <span class="comment"> if (l &lt; 0)</span>
687 00680 <span class="comment"> {</span>
688 00681 <span class="comment"> sign = 1;</span>
689 00682 <span class="comment"> l = -l;</span>
690 00683 <span class="comment"> }</span>
691 00684 <span class="comment"> do {</span>
692 00685 <span class="comment"> *bp++ = l % 10 + '0';</span>
693 00686 <span class="comment"> } while ((l /= 10) &gt; 0);</span>
694 00687 <span class="comment"> if (sign)</span>
695 00688 <span class="comment"> *bp++ = '-';</span>
696 00689 <span class="comment"> f_width = f_width - (bp - buf);</span>
697 00690 <span class="comment"> if (!flush_left)</span>
698 00691 <span class="comment"> while (f_width-- &gt; 0)</span>
699 00692 <span class="comment"> *str++ = (pad);</span>
700 00693 <span class="comment"> for (bp--; bp &gt;= buf; bp--)</span>
701 00694 <span class="comment"> *str++ = (*bp);</span>
702 00695 <span class="comment"> if (flush_left)</span>
703 00696 <span class="comment"> while (f_width-- &gt; 0)</span>
704 00697 <span class="comment"> *str++ = (' ');</span>
705 00698 <span class="comment"> break;</span>
706 00699 <span class="comment"> case 'o': // 'o' octal number</span>
707 00700 <span class="comment"> case 'x': // 'x' hex number</span>
708 00701 <span class="comment"> case 'u': // 'u' unsigned decimal</span>
709 00702 <span class="comment"> if (do_long)</span>
710 00703 <span class="comment"> u = va_arg(ap, unsigned long);</span>
711 00704 <span class="comment"> else</span>
712 00705 <span class="comment"> u = (unsigned long) (va_arg(ap, unsigned));</span>
713 00706 <span class="comment"> if (fmt == 'u')</span>
714 00707 <span class="comment"> { // unsigned decimal</span>
715 00708 <span class="comment"> do {</span>
716 00709 <span class="comment"> *bp++ = u % 10 + '0';</span>
717 00710 <span class="comment"> } while ((u /= 10) &gt; 0);</span>
718 00711 <span class="comment"> }</span>
719 00712 <span class="comment"> else if (fmt == 'o')</span>
720 00713 <span class="comment"> { // octal</span>
721 00714 <span class="comment"> do {</span>
722 00715 <span class="comment"> *bp++ = u % 8 + '0';</span>
723 00716 <span class="comment"> } while ((u /= 8) &gt; 0);</span>
724 00717 <span class="comment"> if (hash)</span>
725 00718 <span class="comment"> *bp++ = '0';</span>
726 00719 <span class="comment"> }</span>
727 00720 <span class="comment"> else if (fmt == 'x')</span>
728 00721 <span class="comment"> { // hex</span>
729 00722 <span class="comment"> do {</span>
730 00723 <span class="comment"> i = u % 16;</span>
731 00724 <span class="comment"> if (i &lt; 10)</span>
732 00725 <span class="comment"> *bp++ = i + '0';</span>
733 00726 <span class="comment"> else</span>
734 00727 <span class="comment"> *bp++ = i - 10 + 'a';</span>
735 00728 <span class="comment"> } while ((u /= 16) &gt; 0);</span>
736 00729 <span class="comment"> if (hash)</span>
737 00730 <span class="comment"> {</span>
738 00731 <span class="comment"> *bp++ = 'x';</span>
739 00732 <span class="comment"> *bp++ = '0';</span>
740 00733 <span class="comment"> }</span>
741 00734 <span class="comment"> }</span>
742 00735 <span class="comment"> i = f_width - (bp - buf);</span>
743 00736 <span class="comment"> if (!flush_left)</span>
744 00737 <span class="comment"> while (i-- &gt; 0)</span>
745 00738 <span class="comment"> *str++ = (pad);</span>
746 00739 <span class="comment"> for (bp--; bp &gt;= buf; bp--)</span>
747 00740 <span class="comment"> *str++ = ((int) (*bp));</span>
748 00741 <span class="comment"> if (flush_left)</span>
749 00742 <span class="comment"> while (i-- &gt; 0)</span>
750 00743 <span class="comment"> *str++ = (' ');</span>
751 00744 <span class="comment"> break;</span>
752 00745 <span class="comment"> case 'c': // 'c' character</span>
753 00746 <span class="comment"> i = va_arg(ap, int);</span>
754 00747 <span class="comment"> *str++ = ((int) (i));</span>
755 00748 <span class="comment"> break;</span>
756 00749 <span class="comment"> case 's': // 's' string</span>
757 00750 <span class="comment"> bp = va_arg(ap, unsigned char *);</span>
758 00751 <span class="comment"> if (!bp)</span>
759 00752 <span class="comment"> bp = (unsigned char *) "(nil)";</span>
760 00753 <span class="comment"> f_width = f_width - strlen((char *) bp);</span>
761 00754 <span class="comment"> if (!flush_left)</span>
762 00755 <span class="comment"> while (f_width-- &gt; 0)</span>
763 00756 <span class="comment"> *str++ = (pad);</span>
764 00757 <span class="comment"> for (i = 0; *bp &amp;&amp; i &lt; prec; i++)</span>
765 00758 <span class="comment"> {</span>
766 00759 <span class="comment"> *str++ = (*bp);</span>
767 00760 <span class="comment"> bp++;</span>
768 00761 <span class="comment"> }</span>
769 00762 <span class="comment"> if (flush_left)</span>
770 00763 <span class="comment"> while (f_width-- &gt; 0)</span>
771 00764 <span class="comment"> *str++ = (' ');</span>
772 00765 <span class="comment"> break;</span>
773 00766 <span class="comment"> case '%': // '%' character</span>
774 00767 <span class="comment"> *str++ = ('%');</span>
775 00768 <span class="comment"> break;</span>
776 00769 <span class="comment"> }</span>
777 00770 <span class="comment"> flush_left = 0, f_width = 0, prec = INF, hash = 0, do_long = 0;</span>
778 00771 <span class="comment"> sign = 0;</span>
779 00772 <span class="comment"> pad = ' ';</span>
780 00773 <span class="comment"> }</span>
781 00774 <span class="comment"> }</span>
782 00775 <span class="comment"></span>
783 00776 <span class="comment"> va_end(ap);</span>
784 00777 <span class="comment"> // terminate string with null</span>
785 00778 <span class="comment"> *str++ = '\0';</span>
786 00779 <span class="comment"> return bufstring;</span>
787 00780 <span class="comment">}</span>
788 00781 <span class="comment"></span>
789 00782 <span class="comment">*/</span>
790 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:07 2006 for Procyon AVRlib by&nbsp;
791 <a href="http://www.doxygen.org/index.html">
792 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
793 </body>
794 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3