?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: cmdline.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>cmdline.c</h1><a href="cmdline_8c.html">Go to the documentation of this file.</a><div class="fragment"><pre class="fragment">00001 <span class="comment">/*! \file cmdline.c \brief Command-Line Interface Library. */</span>
9 00002 <span class="comment">//*****************************************************************************</span>
10 00003 <span class="comment">//</span>
11 00004 <span class="comment">// File Name : 'cmdline.c'</span>
12 00005 <span class="comment">// Title : Command-Line Interface Library</span>
13 00006 <span class="comment">// Author : Pascal Stang - Copyright (C) 2003</span>
14 00007 <span class="comment">// Created : 2003.07.16</span>
15 00008 <span class="comment">// Revised : 2003.07.23</span>
16 00009 <span class="comment">// Version : 0.1</span>
17 00010 <span class="comment">// Target MCU : Atmel AVR Series</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="comment">//----- Include Files ---------------------------------------------------------</span>
30 00023 <span class="preprocessor">#include &lt;avr/io.h&gt;</span> <span class="comment">// include I/O definitions (port names, pin names, etc)</span>
31 00024 <span class="preprocessor">#include &lt;avr/interrupt.h&gt;</span> <span class="comment">// include interrupt support</span>
32 00025 <span class="preprocessor">#include &lt;avr/pgmspace.h&gt;</span> <span class="comment">// include AVR program memory support</span>
33 00026 <span class="preprocessor">#include &lt;string.h&gt;</span> <span class="comment">// include standard C string functions</span>
34 00027 <span class="preprocessor">#include &lt;stdlib.h&gt;</span> <span class="comment">// include stdlib for string conversion functions</span>
35 00028
36 00029 <span class="preprocessor">#include "<a class="code" href="global_8h.html">global.h</a>"</span> <span class="comment">// include our global settings</span>
37 00030 <span class="preprocessor">#include "<a class="code" href="cmdline_8h.html">cmdline.h</a>"</span>
38 00031
39 00032 <span class="comment">// include project-specific configuration</span>
40 00033 <span class="preprocessor">#include "<a class="code" href="cmdlineconf_8h.html">cmdlineconf.h</a>"</span>
41 00034
42 00035 <span class="comment">// defines</span>
43 00036 <span class="preprocessor">#define ASCII_BEL 0x07</span>
44 00037 <span class="preprocessor"></span><span class="preprocessor">#define ASCII_BS 0x08</span>
45 00038 <span class="preprocessor"></span><span class="preprocessor">#define ASCII_CR 0x0D</span>
46 00039 <span class="preprocessor"></span><span class="preprocessor">#define ASCII_LF 0x0A</span>
47 00040 <span class="preprocessor"></span><span class="preprocessor">#define ASCII_ESC 0x1B</span>
48 00041 <span class="preprocessor"></span><span class="preprocessor">#define ASCII_DEL 0x7F</span>
49 00042 <span class="preprocessor"></span>
50 00043 <span class="preprocessor">#define VT100_ARROWUP 'A'</span>
51 00044 <span class="preprocessor"></span><span class="preprocessor">#define VT100_ARROWDOWN 'B'</span>
52 00045 <span class="preprocessor"></span><span class="preprocessor">#define VT100_ARROWRIGHT 'C'</span>
53 00046 <span class="preprocessor"></span><span class="preprocessor">#define VT100_ARROWLEFT 'D'</span>
54 00047 <span class="preprocessor"></span>
55 00048 <span class="preprocessor">#define CMDLINE_HISTORY_SAVE 0</span>
56 00049 <span class="preprocessor"></span><span class="preprocessor">#define CMDLINE_HISTORY_PREV 1</span>
57 00050 <span class="preprocessor"></span><span class="preprocessor">#define CMDLINE_HISTORY_NEXT 2</span>
58 00051 <span class="preprocessor"></span>
59 00052
60 00053 <span class="comment">// Global variables</span>
61 00054
62 00055 <span class="comment">// strings</span>
63 00056 u08 PROGMEM CmdlinePrompt[] = <span class="stringliteral">"cmd&gt;"</span>;
64 00057 u08 PROGMEM CmdlineNotice[] = <span class="stringliteral">"cmdline: "</span>;
65 00058 u08 PROGMEM CmdlineCmdNotFound[] = <span class="stringliteral">"command not found"</span>;
66 00059
67 00060 <span class="comment">// command list</span>
68 00061 <span class="comment">// -commands are null-terminated strings</span>
69 00062 <span class="keyword">static</span> <span class="keywordtype">char</span> CmdlineCommandList[CMDLINE_MAX_COMMANDS][CMDLINE_MAX_CMD_LENGTH];
70 00063 <span class="comment">// command function pointer list</span>
71 00064 <span class="keyword">static</span> CmdlineFuncPtrType CmdlineFunctionList[CMDLINE_MAX_COMMANDS];
72 00065 <span class="comment">// number of commands currently registered</span>
73 00066 u08 CmdlineNumCommands;
74 00067
75 00068 u08 CmdlineBuffer[CMDLINE_BUFFERSIZE];
76 00069 u08 CmdlineBufferLength;
77 00070 u08 CmdlineBufferEditPos;
78 00071 u08 CmdlineInputVT100State;
79 00072 u08 CmdlineHistory[CMDLINE_HISTORYSIZE][CMDLINE_BUFFERSIZE];
80 00073 CmdlineFuncPtrType CmdlineExecFunction;
81 00074
82 00075 <span class="comment">// Functions</span>
83 00076
84 00077 <span class="comment">// function pointer to single character output routine</span>
85 00078 <span class="keyword">static</span> void (*cmdlineOutputFunc)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c);
86 00079
87 <a name="l00080"></a><a class="code" href="group__cmdline.html#ga1">00080</a> <span class="keywordtype">void</span> <a class="code" href="group__cmdline.html#ga1">cmdlineInit</a>(<span class="keywordtype">void</span>)
88 00081 {
89 00082 <span class="comment">// reset vt100 processing state</span>
90 00083 CmdlineInputVT100State = 0;
91 00084 <span class="comment">// initialize input buffer</span>
92 00085 CmdlineBufferLength = 0;
93 00086 CmdlineBufferEditPos = 0;
94 00087 <span class="comment">// initialize executing function</span>
95 00088 CmdlineExecFunction = 0;
96 00089 <span class="comment">// initialize command list</span>
97 00090 CmdlineNumCommands = 0;
98 00091 }
99 00092
100 <a name="l00093"></a><a class="code" href="group__cmdline.html#ga2">00093</a> <span class="keywordtype">void</span> <a class="code" href="group__cmdline.html#ga2">cmdlineAddCommand</a>(u08* newCmdString, CmdlineFuncPtrType newCmdFuncPtr)
101 00094 {
102 00095 <span class="comment">// add command string to end of command list</span>
103 00096 strcpy(CmdlineCommandList[CmdlineNumCommands], newCmdString);
104 00097 <span class="comment">// add command function ptr to end of function list</span>
105 00098 CmdlineFunctionList[CmdlineNumCommands] = newCmdFuncPtr;
106 00099 <span class="comment">// increment number of registered commands</span>
107 00100 CmdlineNumCommands++;
108 00101 }
109 00102
110 <a name="l00103"></a><a class="code" href="group__cmdline.html#ga3">00103</a> <span class="keywordtype">void</span> <a class="code" href="group__cmdline.html#ga3">cmdlineSetOutputFunc</a>(<span class="keywordtype">void</span> (*output_func)(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c))
111 00104 {
112 00105 <span class="comment">// set new output function</span>
113 00106 cmdlineOutputFunc = output_func;
114 00107
115 00108 <span class="comment">// should we really do this?</span>
116 00109 <span class="comment">// print a prompt </span>
117 00110 <span class="comment">//cmdlinePrintPrompt();</span>
118 00111 }
119 00112
120 <a name="l00113"></a><a class="code" href="group__cmdline.html#ga4">00113</a> <span class="keywordtype">void</span> <a class="code" href="group__cmdline.html#ga4">cmdlineInputFunc</a>(<span class="keywordtype">unsigned</span> <span class="keywordtype">char</span> c)
121 00114 {
122 00115 u08 i;
123 00116 <span class="comment">// process the received character</span>
124 00117
125 00118 <span class="comment">// VT100 handling</span>
126 00119 <span class="comment">// are we processing a VT100 command?</span>
127 00120 <span class="keywordflow">if</span>(CmdlineInputVT100State == 2)
128 00121 {
129 00122 <span class="comment">// we have already received ESC and [</span>
130 00123 <span class="comment">// now process the vt100 code</span>
131 00124 <span class="keywordflow">switch</span>(c)
132 00125 {
133 00126 <span class="keywordflow">case</span> VT100_ARROWUP:
134 00127 cmdlineDoHistory(CMDLINE_HISTORY_PREV);
135 00128 <span class="keywordflow">break</span>;
136 00129 <span class="keywordflow">case</span> VT100_ARROWDOWN:
137 00130 cmdlineDoHistory(CMDLINE_HISTORY_NEXT);
138 00131 <span class="keywordflow">break</span>;
139 00132 <span class="keywordflow">case</span> VT100_ARROWRIGHT:
140 00133 <span class="comment">// if the edit position less than current string length</span>
141 00134 <span class="keywordflow">if</span>(CmdlineBufferEditPos &lt; CmdlineBufferLength)
142 00135 {
143 00136 <span class="comment">// increment the edit position</span>
144 00137 CmdlineBufferEditPos++;
145 00138 <span class="comment">// move cursor forward one space (no erase)</span>
146 00139 cmdlineOutputFunc(ASCII_ESC);
147 00140 cmdlineOutputFunc(<span class="charliteral">'['</span>);
148 00141 cmdlineOutputFunc(VT100_ARROWRIGHT);
149 00142 }
150 00143 <span class="keywordflow">else</span>
151 00144 {
152 00145 <span class="comment">// else, ring the bell</span>
153 00146 cmdlineOutputFunc(ASCII_BEL);
154 00147 }
155 00148 <span class="keywordflow">break</span>;
156 00149 <span class="keywordflow">case</span> VT100_ARROWLEFT:
157 00150 <span class="comment">// if the edit position is non-zero</span>
158 00151 <span class="keywordflow">if</span>(CmdlineBufferEditPos)
159 00152 {
160 00153 <span class="comment">// decrement the edit position</span>
161 00154 CmdlineBufferEditPos--;
162 00155 <span class="comment">// move cursor back one space (no erase)</span>
163 00156 cmdlineOutputFunc(ASCII_BS);
164 00157 }
165 00158 <span class="keywordflow">else</span>
166 00159 {
167 00160 <span class="comment">// else, ring the bell</span>
168 00161 cmdlineOutputFunc(ASCII_BEL);
169 00162 }
170 00163 <span class="keywordflow">break</span>;
171 00164 <span class="keywordflow">default</span>:
172 00165 <span class="keywordflow">break</span>;
173 00166 }
174 00167 <span class="comment">// done, reset state</span>
175 00168 CmdlineInputVT100State = 0;
176 00169 <span class="keywordflow">return</span>;
177 00170 }
178 00171 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(CmdlineInputVT100State == 1)
179 00172 {
180 00173 <span class="comment">// we last received [ESC]</span>
181 00174 <span class="keywordflow">if</span>(c == <span class="charliteral">'['</span>)
182 00175 {
183 00176 CmdlineInputVT100State = 2;
184 00177 <span class="keywordflow">return</span>;
185 00178 }
186 00179 <span class="keywordflow">else</span>
187 00180 CmdlineInputVT100State = 0;
188 00181 }
189 00182 <span class="keywordflow">else</span>
190 00183 {
191 00184 <span class="comment">// anything else, reset state</span>
192 00185 CmdlineInputVT100State = 0;
193 00186 }
194 00187
195 00188 <span class="comment">// Regular handling</span>
196 00189 <span class="keywordflow">if</span>( (c &gt;= 0x20) &amp;&amp; (c &lt; 0x7F) )
197 00190 {
198 00191 <span class="comment">// character is printable</span>
199 00192 <span class="comment">// is this a simple append</span>
200 00193 <span class="keywordflow">if</span>(CmdlineBufferEditPos == CmdlineBufferLength)
201 00194 {
202 00195 <span class="comment">// echo character to the output</span>
203 00196 cmdlineOutputFunc(c);
204 00197 <span class="comment">// add it to the command line buffer</span>
205 00198 CmdlineBuffer[CmdlineBufferEditPos++] = c;
206 00199 <span class="comment">// update buffer length</span>
207 00200 CmdlineBufferLength++;
208 00201 }
209 00202 <span class="keywordflow">else</span>
210 00203 {
211 00204 <span class="comment">// edit/cursor position != end of buffer</span>
212 00205 <span class="comment">// we're inserting characters at a mid-line edit position</span>
213 00206 <span class="comment">// make room at the insert point</span>
214 00207 CmdlineBufferLength++;
215 00208 <span class="keywordflow">for</span>(i=CmdlineBufferLength; i&gt;CmdlineBufferEditPos; i--)
216 00209 CmdlineBuffer[i] = CmdlineBuffer[i-1];
217 00210 <span class="comment">// insert character</span>
218 00211 CmdlineBuffer[CmdlineBufferEditPos++] = c;
219 00212 <span class="comment">// repaint</span>
220 00213 cmdlineRepaint();
221 00214 <span class="comment">// reposition cursor</span>
222 00215 <span class="keywordflow">for</span>(i=CmdlineBufferEditPos; i&lt;CmdlineBufferLength; i++)
223 00216 cmdlineOutputFunc(ASCII_BS);
224 00217 }
225 00218 }
226 00219 <span class="comment">// handle special characters</span>
227 00220 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(c == ASCII_CR)
228 00221 {
229 00222 <span class="comment">// user pressed [ENTER]</span>
230 00223 <span class="comment">// echo CR and LF to terminal</span>
231 00224 cmdlineOutputFunc(ASCII_CR);
232 00225 cmdlineOutputFunc(ASCII_LF);
233 00226 <span class="comment">// add null termination to command</span>
234 00227 CmdlineBuffer[CmdlineBufferLength++] = 0;
235 00228 CmdlineBufferEditPos++;
236 00229 <span class="comment">// command is complete, process it</span>
237 00230 cmdlineProcessInputString();
238 00231 <span class="comment">// reset buffer</span>
239 00232 CmdlineBufferLength = 0;
240 00233 CmdlineBufferEditPos = 0;
241 00234 }
242 00235 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(c == ASCII_BS)
243 00236 {
244 00237 <span class="keywordflow">if</span>(CmdlineBufferEditPos)
245 00238 {
246 00239 <span class="comment">// is this a simple delete (off the end of the line)</span>
247 00240 <span class="keywordflow">if</span>(CmdlineBufferEditPos == CmdlineBufferLength)
248 00241 {
249 00242 <span class="comment">// destructive backspace</span>
250 00243 <span class="comment">// echo backspace-space-backspace</span>
251 00244 cmdlineOutputFunc(ASCII_BS);
252 00245 cmdlineOutputFunc(<span class="charliteral">' '</span>);
253 00246 cmdlineOutputFunc(ASCII_BS);
254 00247 <span class="comment">// decrement our buffer length and edit position</span>
255 00248 CmdlineBufferLength--;
256 00249 CmdlineBufferEditPos--;
257 00250 }
258 00251 <span class="keywordflow">else</span>
259 00252 {
260 00253 <span class="comment">// edit/cursor position != end of buffer</span>
261 00254 <span class="comment">// we're deleting characters at a mid-line edit position</span>
262 00255 <span class="comment">// shift characters down, effectively deleting</span>
263 00256 CmdlineBufferLength--;
264 00257 CmdlineBufferEditPos--;
265 00258 <span class="keywordflow">for</span>(i=CmdlineBufferEditPos; i&lt;CmdlineBufferLength; i++)
266 00259 CmdlineBuffer[i] = CmdlineBuffer[i+1];
267 00260 <span class="comment">// repaint</span>
268 00261 cmdlineRepaint();
269 00262 <span class="comment">// add space to clear leftover characters</span>
270 00263 cmdlineOutputFunc(<span class="charliteral">' '</span>);
271 00264 <span class="comment">// reposition cursor</span>
272 00265 <span class="keywordflow">for</span>(i=CmdlineBufferEditPos; i&lt;(CmdlineBufferLength+1); i++)
273 00266 cmdlineOutputFunc(ASCII_BS);
274 00267 }
275 00268 }
276 00269 <span class="keywordflow">else</span>
277 00270 {
278 00271 <span class="comment">// else, ring the bell</span>
279 00272 cmdlineOutputFunc(ASCII_BEL);
280 00273 }
281 00274 }
282 00275 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(c == ASCII_DEL)
283 00276 {
284 00277 <span class="comment">// not yet handled</span>
285 00278 }
286 00279 <span class="keywordflow">else</span> <span class="keywordflow">if</span>(c == ASCII_ESC)
287 00280 {
288 00281 CmdlineInputVT100State = 1;
289 00282 }
290 00283 }
291 00284
292 00285 <span class="keywordtype">void</span> cmdlineRepaint(<span class="keywordtype">void</span>)
293 00286 {
294 00287 u08* ptr;
295 00288 u08 i;
296 00289
297 00290 <span class="comment">// carriage return</span>
298 00291 cmdlineOutputFunc(ASCII_CR);
299 00292 <span class="comment">// print fresh prompt</span>
300 00293 cmdlinePrintPrompt();
301 00294 <span class="comment">// print the new command line buffer</span>
302 00295 i = CmdlineBufferLength;
303 00296 ptr = CmdlineBuffer;
304 00297 <span class="keywordflow">while</span>(i--) cmdlineOutputFunc(*ptr++);
305 00298 }
306 00299
307 00300 <span class="keywordtype">void</span> cmdlineDoHistory(u08 action)
308 00301 {
309 00302 <span class="keywordflow">switch</span>(action)
310 00303 {
311 00304 <span class="keywordflow">case</span> CMDLINE_HISTORY_SAVE:
312 00305 <span class="comment">// copy CmdlineBuffer to history if not null string</span>
313 00306 <span class="keywordflow">if</span>( strlen(CmdlineBuffer) )
314 00307 strcpy(CmdlineHistory[0], CmdlineBuffer);
315 00308 <span class="keywordflow">break</span>;
316 00309 <span class="keywordflow">case</span> CMDLINE_HISTORY_PREV:
317 00310 <span class="comment">// copy history to current buffer</span>
318 00311 strcpy(CmdlineBuffer, CmdlineHistory[0]);
319 00312 <span class="comment">// set the buffer position to the end of the line</span>
320 00313 CmdlineBufferLength = strlen(CmdlineBuffer);
321 00314 CmdlineBufferEditPos = CmdlineBufferLength;
322 00315 <span class="comment">// "re-paint" line</span>
323 00316 cmdlineRepaint();
324 00317 <span class="keywordflow">break</span>;
325 00318 <span class="keywordflow">case</span> CMDLINE_HISTORY_NEXT:
326 00319 <span class="keywordflow">break</span>;
327 00320 }
328 00321 }
329 00322
330 00323 <span class="keywordtype">void</span> cmdlineProcessInputString(<span class="keywordtype">void</span>)
331 00324 {
332 00325 u08 cmdIndex;
333 00326 u08 i=0;
334 00327
335 00328 <span class="comment">// save command in history</span>
336 00329 cmdlineDoHistory(CMDLINE_HISTORY_SAVE);
337 00330
338 00331 <span class="comment">// find the end of the command (excluding arguments)</span>
339 00332 <span class="comment">// find first whitespace character in CmdlineBuffer</span>
340 00333 <span class="keywordflow">while</span>( !((CmdlineBuffer[i] == <span class="charliteral">' '</span>) || (CmdlineBuffer[i] == 0)) ) i++;
341 00334
342 00335 <span class="keywordflow">if</span>(!i)
343 00336 {
344 00337 <span class="comment">// command was null or empty</span>
345 00338 <span class="comment">// output a new prompt</span>
346 00339 cmdlinePrintPrompt();
347 00340 <span class="comment">// we're done</span>
348 00341 <span class="keywordflow">return</span>;
349 00342 }
350 00343
351 00344 <span class="comment">// search command list for match with entered command</span>
352 00345 <span class="keywordflow">for</span>(cmdIndex=0; cmdIndex&lt;CmdlineNumCommands; cmdIndex++)
353 00346 {
354 00347 <span class="keywordflow">if</span>( !strncmp(CmdlineCommandList[cmdIndex], CmdlineBuffer, i) )
355 00348 {
356 00349 <span class="comment">// user-entered command matched a command in the list (database)</span>
357 00350 <span class="comment">// run the corresponding function</span>
358 00351 CmdlineExecFunction = CmdlineFunctionList[cmdIndex];
359 00352 <span class="comment">// new prompt will be output after user function runs</span>
360 00353 <span class="comment">// and we're done</span>
361 00354 <span class="keywordflow">return</span>;
362 00355 }
363 00356 }
364 00357
365 00358 <span class="comment">// if we did not get a match</span>
366 00359 <span class="comment">// output an error message</span>
367 00360 cmdlinePrintError();
368 00361 <span class="comment">// output a new prompt</span>
369 00362 cmdlinePrintPrompt();
370 00363 }
371 00364
372 <a name="l00365"></a><a class="code" href="group__cmdline.html#ga5">00365</a> <span class="keywordtype">void</span> <a class="code" href="group__cmdline.html#ga5">cmdlineMainLoop</a>(<span class="keywordtype">void</span>)
373 00366 {
374 00367 <span class="comment">// do we have a command/function to be executed</span>
375 00368 <span class="keywordflow">if</span>(CmdlineExecFunction)
376 00369 {
377 00370 <span class="comment">// run it</span>
378 00371 CmdlineExecFunction();
379 00372 <span class="comment">// reset</span>
380 00373 CmdlineExecFunction = 0;
381 00374 <span class="comment">// output new prompt</span>
382 00375 cmdlinePrintPrompt();
383 00376 }
384 00377 }
385 00378
386 00379 <span class="keywordtype">void</span> cmdlinePrintPrompt(<span class="keywordtype">void</span>)
387 00380 {
388 00381 <span class="comment">// print a new command prompt</span>
389 00382 u08* ptr = CmdlinePrompt;
390 00383 <span class="keywordflow">while</span>(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );
391 00384 }
392 00385
393 00386 <span class="keywordtype">void</span> cmdlinePrintError(<span class="keywordtype">void</span>)
394 00387 {
395 00388 u08 * ptr;
396 00389
397 00390 <span class="comment">// print a notice header</span>
398 00391 <span class="comment">// (u08*) cast used to avoid compiler warning</span>
399 00392 ptr = (u08*)CmdlineNotice;
400 00393 <span class="keywordflow">while</span>(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );
401 00394
402 00395 <span class="comment">// print the offending command</span>
403 00396 ptr = CmdlineBuffer;
404 00397 <span class="keywordflow">while</span>((*ptr) &amp;&amp; (*ptr != <span class="charliteral">' '</span>)) cmdlineOutputFunc(*ptr++);
405 00398
406 00399 cmdlineOutputFunc(<span class="charliteral">':'</span>);
407 00400 cmdlineOutputFunc(<span class="charliteral">' '</span>);
408 00401
409 00402 <span class="comment">// print the not-found message</span>
410 00403 <span class="comment">// (u08*) cast used to avoid compiler warning</span>
411 00404 ptr = (u08*)CmdlineCmdNotFound;
412 00405 <span class="keywordflow">while</span>(pgm_read_byte(ptr)) cmdlineOutputFunc( pgm_read_byte(ptr++) );
413 00406
414 00407 cmdlineOutputFunc(<span class="charliteral">'\r'</span>);
415 00408 cmdlineOutputFunc(<span class="charliteral">'\n'</span>);
416 00409 }
417 00410
418 00411 <span class="comment">// argument retrieval commands</span>
419 00412
420 00413 <span class="comment">// return string pointer to argument [argnum]</span>
421 <a name="l00414"></a><a class="code" href="group__cmdline.html#ga11">00414</a> u08* <a class="code" href="group__cmdline.html#ga11">cmdlineGetArgStr</a>(u08 argnum)
422 00415 {
423 00416 <span class="comment">// find the offset of argument number [argnum]</span>
424 00417 u08 idx=0;
425 00418 u08 arg;
426 00419
427 00420 <span class="comment">// find the first non-whitespace character</span>
428 00421 <span class="keywordflow">while</span>( (CmdlineBuffer[idx] != 0) &amp;&amp; (CmdlineBuffer[idx] == <span class="charliteral">' '</span>)) idx++;
429 00422
430 00423 <span class="comment">// we are at the first argument</span>
431 00424 <span class="keywordflow">for</span>(arg=0; arg&lt;argnum; arg++)
432 00425 {
433 00426 <span class="comment">// find the next whitespace character</span>
434 00427 <span class="keywordflow">while</span>( (CmdlineBuffer[idx] != 0) &amp;&amp; (CmdlineBuffer[idx] != <span class="charliteral">' '</span>)) idx++;
435 00428 <span class="comment">// find the first non-whitespace character</span>
436 00429 <span class="keywordflow">while</span>( (CmdlineBuffer[idx] != 0) &amp;&amp; (CmdlineBuffer[idx] == <span class="charliteral">' '</span>)) idx++;
437 00430 }
438 00431 <span class="comment">// we are at the requested argument or the end of the buffer</span>
439 00432 <span class="keywordflow">return</span> &amp;CmdlineBuffer[idx];
440 00433 }
441 00434
442 00435 <span class="comment">// return argument [argnum] interpreted as a decimal integer</span>
443 <a name="l00436"></a><a class="code" href="group__cmdline.html#ga12">00436</a> <span class="keywordtype">long</span> <a class="code" href="group__cmdline.html#ga12">cmdlineGetArgInt</a>(u08 argnum)
444 00437 {
445 00438 <span class="keywordtype">char</span>* endptr;
446 00439 <span class="keywordflow">return</span> strtol(<a class="code" href="group__cmdline.html#ga11">cmdlineGetArgStr</a>(argnum), &amp;endptr, 10);
447 00440 }
448 00441
449 00442 <span class="comment">// return argument [argnum] interpreted as a hex integer</span>
450 <a name="l00443"></a><a class="code" href="group__cmdline.html#ga13">00443</a> <span class="keywordtype">long</span> <a class="code" href="group__cmdline.html#ga13">cmdlineGetArgHex</a>(u08 argnum)
451 00444 {
452 00445 <span class="keywordtype">char</span>* endptr;
453 00446 <span class="keywordflow">return</span> strtol(<a class="code" href="group__cmdline.html#ga11">cmdlineGetArgStr</a>(argnum), &amp;endptr, 16);
454 00447 }
455 </pre></div><hr size="1"><address style="align: right;"><small>Generated on Sun Oct 29 03:41:06 2006 for Procyon AVRlib by&nbsp;
456 <a href="http://www.doxygen.org/index.html">
457 <img src="doxygen.png" alt="doxygen" align="middle" border="0"></a> 1.4.2 </small></address>
458 </body>
459 </html>
{BLAME END}
{FOOTER START}

Powered by WebSVN v2.8.3