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