readline.h
Go to the documentation of this file.
00001
00084 #ifndef MWARE_READLINE_H
00085 #define MWARE_READLINE_H
00086 
00087 #include <cfg/compiler.h>
00088
00089 #include <string.h>
00090
00091 #define HISTORY_SIZE 32
00092 
00093 typedef int (*getc_hook)(void* user_data);
00094 typedef void (*putc_hook)(char ch, void* user_data);
00095 typedef const char* (*match_hook)(void* user_data, const char* word, int word_len);
00096 typedef void (*clear_hook)(void* user_data);
00097
00098 struct RLContext
00099 {
00100     getc_hook get;
00101     void* get_param;
00102
00103     putc_hook put;
00104     void* put_param;
00105
00106     match_hook match;
00107     void* match_param;
00108
00109     clear_hook clear;
00110     void* clear_param;
00111
00112     const char* prompt;
00113
00114     char real_history[HISTORY_SIZE];
00115     char* history;
00116     size_t history_pos;
00117     size_t line_pos;
00118 };
00119
00120 INLINE void rl_init_ctx(struct RLContext *ctx)
00121 {
00122     memset(ctx, 0, sizeof(*ctx));
00123     ctx->history = ctx->real_history;
00124 }
00125
00126 INLINE void rl_clear_history(struct RLContext *ctx)
00127 {
00128     memset(ctx->real_history, 0, sizeof(ctx->real_history));
00129     ctx->history_pos = 0;
00130     ctx->line_pos = ctx->history_pos;
00131     ctx->history = ctx->real_history;
00132 }
00133
00134 INLINE void rl_sethook_get(struct RLContext* ctx, getc_hook get, void* get_param)
00135 { ctx->get = get; ctx->get_param = get_param; }
00136
00137 INLINE void rl_sethook_put(struct RLContext* ctx, putc_hook put, void* put_param)
00138 { ctx->put = put; ctx->put_param = put_param; }
00139
00140 INLINE void rl_sethook_match(struct RLContext* ctx, match_hook match, void* match_param)
00141 { ctx->match = match; ctx->match_param = match_param; }
00142
00143 INLINE void rl_sethook_clear(struct RLContext* ctx, clear_hook clear, void* clear_param)
00144 { ctx->clear = clear; ctx->clear_param = clear_param; }
00145
00146 INLINE void rl_setprompt(struct RLContext* ctx, const char* prompt)
00147 { ctx->prompt = prompt; }
00148
00149 const char* rl_readline(struct RLContext* ctx);
00150
00151 void rl_refresh(struct RLContext* ctx);
00152
00153 /* Test prototype */
00154 int readline_testSetup(void);
00155 int readline_testRun(void);
00156 int readline_testTearDown(void);
00157  //defgroup readline.
00159
00160 #endif /* MWARE_READLINE_H */