readline.h
Go to the documentation of this file.00001
00051 #ifndef MWARE_READLINE_H
00052 #define MWARE_READLINE_H
00053
00054 #include <cfg/compiler.h>
00055
00056 #include <string.h>
00057
00058 #define HISTORY_SIZE 32
00059
00060 typedef int (*getc_hook)(void* user_data);
00061 typedef void (*putc_hook)(char ch, void* user_data);
00062 typedef const char* (*match_hook)(void* user_data, const char* word, int word_len);
00063 typedef void (*clear_hook)(void* user_data);
00064
00065 struct RLContext
00066 {
00067 getc_hook get;
00068 void* get_param;
00069
00070 putc_hook put;
00071 void* put_param;
00072
00073 match_hook match;
00074 void* match_param;
00075
00076 clear_hook clear;
00077 void* clear_param;
00078
00079 const char* prompt;
00080
00081 char real_history[HISTORY_SIZE];
00082 char* history;
00083 size_t history_pos;
00084 size_t line_pos;
00085 };
00086
00087 INLINE void rl_init_ctx(struct RLContext *ctx)
00088 {
00089 memset(ctx, 0, sizeof(*ctx));
00090 ctx->history = ctx->real_history;
00091 }
00092
00093 INLINE void rl_clear_history(struct RLContext *ctx)
00094 {
00095 memset(ctx->real_history, 0, sizeof(ctx->real_history));
00096 ctx->history_pos = 0;
00097 ctx->line_pos = ctx->history_pos;
00098 ctx->history = ctx->real_history;
00099 }
00100
00101 INLINE void rl_sethook_get(struct RLContext* ctx, getc_hook get, void* get_param)
00102 { ctx->get = get; ctx->get_param = get_param; }
00103
00104 INLINE void rl_sethook_put(struct RLContext* ctx, putc_hook put, void* put_param)
00105 { ctx->put = put; ctx->put_param = put_param; }
00106
00107 INLINE void rl_sethook_match(struct RLContext* ctx, match_hook match, void* match_param)
00108 { ctx->match = match; ctx->match_param = match_param; }
00109
00110 INLINE void rl_sethook_clear(struct RLContext* ctx, clear_hook clear, void* clear_param)
00111 { ctx->clear = clear; ctx->clear_param = clear_param; }
00112
00113 INLINE void rl_setprompt(struct RLContext* ctx, const char* prompt)
00114 { ctx->prompt = prompt; }
00115
00116 const char* rl_readline(struct RLContext* ctx);
00117
00118 void rl_refresh(struct RLContext* ctx);
00119
00120 #endif