1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
|
#include <stdio.h>
#include "BReadline.h"
using namespace Balau;
#ifdef USE_EDITLINE
Readline::Readline(const Balau::String & program) {
}
Readline::~Readline() {
}
Balau::String Readline::gets() {
return "";
}
bool Readline::gotEOF() {
return true;
}
void Readline::setPrompt(const Balau::String & prompt) {
}
#endif
#ifdef USE_HISTEDIT
#include <BStdIO.h>
Readline::Readline(const String & program)
: m_in(new StdIn())
{
HistEvent ev;
m_hist = history_init();
history(m_hist, &ev, H_SETSIZE, 5000);
m_el = el_init(program.to_charp(), stdin, stdout, stderr);
el_set(m_el, EL_CLIENTDATA, this);
el_set(m_el, EL_PROMPT, (const char * (*)(EditLine *)) &Readline::elPrompt);
el_set(m_el, EL_SIGNAL, 1);
el_set(m_el, EL_GETCFN, (int (*)(EditLine *, char *)) &Readline::elGetCFN);
el_set(m_el, EL_HIST, history, m_hist);
}
Readline::~Readline() {
el_end(m_el);
history_end(m_hist);
}
void Readline::setPrompt(const String & prompt) {
m_prompt = prompt;
}
String Readline::gets() {
int count;
const char * line = el_gets(m_el, &count);
if (!line) {
m_eof = true;
return "";
}
if (*line) {
HistEvent ev;
history(m_hist, &ev, H_ENTER, line);
}
return line;
}
const char * Readline::elPrompt(EditLine * el) {
Readline * rl;
el_get(el, EL_CLIENTDATA, &rl);
return rl->elPrompt();
}
int Readline::elGetCFN(EditLine * el, char * c) {
Readline * rl;
el_get(el, EL_CLIENTDATA, &rl);
return rl->elGetCFN(c);
}
int Readline::elGetCFN(char * c) {
return m_in->read(c, 1);
}
#endif
|