readline.h
Go to the documentation of this file.00001
00052 #ifndef MWARE_READLINE_H
00053 #define MWARE_READLINE_H
00054
00055 #include <cfg/compiler.h>
00056
00057 #include <string.h>
00058
00059 #define HISTORY_SIZE 32
00060
00061 typedef int (*getc_hook)(void* user_data);
00062 typedef void (*putc_hook)(char ch, void* user_data);
00063 typedef const char* (*match_hook)(void* user_data, const char* word, int word_len);
00064 typedef void (*clear_hook)(void* user_data);
00065
00066 struct RLContext
00067 {
00068 getc_hook get;
00069 void* get_param;
00070
00071 putc_hook put;
00072 void* put_param;
00073
00074 match_hook match;
00075 void* match_param;
00076
00077 clear_hook clear;
00078 void* clear_param;
00079
00080 const char* prompt;
00081
00082 char real_history[HISTORY_SIZE];
00083 char* history;
00084 size_t history_pos;
00085 size_t line_pos;
00086 };
00087
00088 INLINE void rl_init_ctx(struct RLContext *ctx)
00089 {
00090 memset(ctx, 0, sizeof(*ctx));
00091 ctx->history = ctx->real_history;
00092 }
00093
00094 INLINE void rl_clear_history(struct RLContext *ctx)
00095 {
00096 memset(ctx->real_history, 0, sizeof(ctx->real_history));
00097 ctx->history_pos = 0;
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