2 * Copyright Droids Corporation
3 * Olivier Matz <zer0@droids-corp.org>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 * Revision : $Id: cmdline.c,v 1.5 2009-05-02 10:08:09 zer0 Exp $
27 #include <aversive/error.h>
40 /******** See in commands.c for the list of commands. */
41 extern parse_pgm_ctx_t main_ctx[];
43 void write_char(char c)
45 uart_send(CMDLINE_UART, c);
48 void valid_buffer(const char *buf, __attribute__((unused)) uint8_t size)
52 ret = parse(main_ctx, buf);
53 if (ret == PARSE_AMBIGUOUS)
54 printf_P(PSTR("Ambiguous command\r\n"));
55 else if (ret == PARSE_NOMATCH)
56 printf_P(PSTR("Command not found\r\n"));
57 else if (ret == PARSE_BAD_ARGS)
58 printf_P(PSTR("Bad arguments\r\n"));
61 int8_t complete_buffer(const char *buf, char *dstbuf, uint8_t dstsize,
64 return complete(main_ctx, buf, state, dstbuf, dstsize);
67 int cmdline_process(void)
69 const char *history, *buffer;
73 while ( (c = uart_recv_nowait(CMDLINE_UART)) != -1) {
75 ret = rdline_char_in(&beacon_tsop.rdl, c);
76 if (ret != 2 && ret != 0) {
77 buffer = rdline_get_buffer(&beacon_tsop.rdl);
78 history = rdline_get_history_item(&beacon_tsop.rdl, 0);
80 same = !memcmp(buffer, history, strlen(history)) &&
81 buffer[strlen(history)] == '\n';
85 if (strlen(buffer) > 1 && !same)
86 rdline_add_history(&beacon_tsop.rdl, buffer);
87 rdline_newline(&beacon_tsop.rdl, beacon_tsop.prompt);