-
Notifications
You must be signed in to change notification settings - Fork 24
/
edit-vrl.c
109 lines (81 loc) · 1.7 KB
/
edit-vrl.c
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#include "rc.h"
#include <errno.h>
#include <stdio.h>
#include "edit.h"
extern char *readline(char *);
extern void add_history(char *);
bool editing = 1;
struct cookie {
char *buffer;
};
static char *prompt;
void *edit_begin(int fd) {
List *hist;
struct cookie *c;
hist = varlookup("history");
if (hist != NULL)
;
/* XXX will need to loop calling add_history() */
c = ealloc(sizeof *c);
c->buffer = NULL;
return c;
}
/*
static void (*oldint)(int), (*oldquit)(int);
static void edit_catcher(int sig) {
sys_signal(SIGINT, oldint);
sys_signal(SIGQUIT, oldquit);
write(2, "\n", 1);
rc_raise(eError);
}
*/
char *edit_alloc(void *cookie, size_t *count) {
struct cookie *c = cookie;
/*
int len = 0;
const char *r;
HistEvent he;
struct cookie *c = cookie;
oldint = sys_signal(SIGINT, edit_catcher);
oldquit = sys_signal(SIGQUIT, edit_catcher);
r = el_gets(c->el, &len);
*count = len;
sys_signal(SIGINT, oldint);
sys_signal(SIGQUIT, oldquit);
if (r)
history(c->hist, &he, H_ENTER, r);
*/
c->buffer = readline(prompt);
if (c->buffer) {
add_history(c->buffer);
*count = strlen(c->buffer);
c->buffer[*count] = '\n';
++*count;
}
return c->buffer;
}
/*
static char *edit_prompter(ne *e) {
return prompt;
}
*/
void edit_prompt(void *cookie, char *pr) {
//struct cookie *c = cookie;
prompt = pr;
//el_set(c->el, EL_PROMPT, edit_prompter);
}
void edit_free(void *cookie) {
struct cookie *c = cookie;
efree(c->buffer);
c->buffer = NULL; /* allow "overfrees" */
}
void edit_end(void *cookie) {
//struct cookie *c = cookie;
//el_end(c->el);
//history_end(c->hist);
//efree(c);
}
void edit_reset(void *cookie) {
//struct cookie *c = cookie;
//el_set(c->el, EL_TERMINAL, NULL);
}