4 * This file is part of BeRTOS.
6 * Bertos is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 * As a special exception, you may use this file as part of a free software
21 * library without restriction. Specifically, if other files instantiate
22 * templates or use macros or inline functions from this file, or you compile
23 * this file and link it with other files to produce an executable, this
24 * file does not by itself cause the resulting executable to be covered by
25 * the GNU General Public License. This exception does not however
26 * invalidate any other reasons why the executable file might be covered by
27 * the GNU General Public License.
29 * Copyright (C) 2004 Giovanni Bajo
30 * Copyright (C) 2004 Develer S.r.l. (http://www.develer.com/)
31 * All Rights Reserved.
34 * \brief Line editing support with history
36 * This file implements a kernel for line editing through a terminal, with history of the typed lines.
37 * Basic feature of this module:
39 * \li Abstracted from I/O. The user must provide hooks for getc and putc functions.
40 * \li Basic support for ANSI escape sequences for input of special codes.
41 * \li Support for command name completion (through a hook).
45 * \author Giovanni Bajo <rasky@develer.com>
50 *#* Revision 1.2 2006/07/19 12:56:28 bernie
51 *#* Convert to new Doxygen style.
53 *#* Revision 1.1 2006/06/01 12:27:39 marco
54 *#* Added utilities for protocols
58 #ifndef MWARE_READLINE_H
59 #define MWARE_READLINE_H
61 #include <cfg/compiler.h>
65 #define HISTORY_SIZE 1024
67 typedef int (*getc_hook)(void* user_data);
68 typedef void (*putc_hook)(char ch, void* user_data);
69 typedef const char* (*match_hook)(void* user_data, const char* word, int word_len);
84 char real_history[HISTORY_SIZE];
89 INLINE void rl_init_ctx(struct RLContext *ctx)
91 memset(ctx, 0, sizeof(*ctx));
92 ctx->history = ctx->real_history;
95 INLINE void rl_clear_history(struct RLContext *ctx)
97 memset(ctx->real_history, 0, sizeof(ctx->real_history));
99 ctx->history = ctx->real_history;
102 INLINE void rl_sethook_get(struct RLContext* ctx, getc_hook get, void* get_param)
103 { ctx->get = get; ctx->get_param = get_param; }
105 INLINE void rl_sethook_put(struct RLContext* ctx, putc_hook put, void* put_param)
106 { ctx->put = put; ctx->put_param = put_param; }
108 INLINE void rl_sethook_match(struct RLContext* ctx, match_hook match, void* match_param)
109 { ctx->match = match; ctx->match_param = match_param; }
111 INLINE void rl_setprompt(struct RLContext* ctx, const char* prompt)
112 { ctx->prompt = prompt; }
114 const char* rl_readline(struct RLContext* ctx);
116 void rl_refresh(struct RLContext* ctx);
118 #endif /* MWARE_READLINE_H */