edit-vrl.c (1713B)
1 #include "rc.h" 2 3 #include <errno.h> 4 #include <stdio.h> 5 6 #include "edit.h" 7 8 extern char *readline(char *); 9 extern void add_history(char *); 10 11 bool editing = 1; 12 13 struct cookie { 14 char *buffer; 15 }; 16 17 static char *prompt; 18 19 void *edit_begin(int fd) { 20 List *hist; 21 struct cookie *c; 22 23 24 hist = varlookup("history"); 25 if (hist != NULL) 26 ; 27 /* XXX will need to loop calling add_history() */ 28 29 c = ealloc(sizeof *c); 30 c->buffer = NULL; 31 return c; 32 } 33 34 /* 35 static void (*oldint)(int), (*oldquit)(int); 36 37 static void edit_catcher(int sig) { 38 sys_signal(SIGINT, oldint); 39 sys_signal(SIGQUIT, oldquit); 40 write(2, "\n", 1); 41 rc_raise(eError); 42 } 43 44 */ 45 46 char *edit_alloc(void *cookie, size_t *count) { 47 struct cookie *c = cookie; 48 /* 49 const char *r; 50 HistEvent he; 51 struct cookie *c = cookie; 52 53 oldint = sys_signal(SIGINT, edit_catcher); 54 oldquit = sys_signal(SIGQUIT, edit_catcher); 55 56 r = el_gets(c->el, count); 57 58 sys_signal(SIGINT, oldint); 59 sys_signal(SIGQUIT, oldquit); 60 61 if (r) 62 history(c->hist, &he, H_ENTER, r); 63 */ 64 65 c->buffer = readline(prompt); 66 if (c->buffer) { 67 add_history(c->buffer); 68 *count = strlen(c->buffer); 69 c->buffer[*count] = '\n'; 70 ++*count; 71 } 72 return c->buffer; 73 } 74 75 /* 76 static char *edit_prompter(ne *e) { 77 return prompt; 78 } 79 */ 80 81 void edit_prompt(void *cookie, char *pr) { 82 //struct cookie *c = cookie; 83 84 prompt = pr; 85 //el_set(c->el, EL_PROMPT, edit_prompter); 86 } 87 88 void edit_free(void *cookie) { 89 struct cookie *c = cookie; 90 91 efree(c->buffer); 92 c->buffer = NULL; /* allow "overfrees" */ 93 } 94 95 void edit_end(void *cookie) { 96 //struct cookie *c = cookie; 97 98 //el_end(c->el); 99 //history_end(c->hist); 100 //efree(c); 101 } 102 103 void edit_reset(void *cookie) { 104 //struct cookie *c = cookie; 105 106 //el_set(c->el, EL_TERMINAL, NULL); 107 }