rc

[fork] interactive rc shell
git clone https://hhvn.uk/rc
git clone git://hhvn.uk/rc
Log | Files | Refs | README | LICENSE

edit-editline.c (1670B)


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