diff --new-file --recursive --unified --ignore-space-change readline-4.1/display.c readline-hacked/display.c --- readline-4.1/display.c Thu Sep 16 16:19:40 1999 +++ readline-hacked/display.c Sun Sep 17 14:55:07 2000 @@ -53,6 +53,7 @@ #include "rlprivate.h" #include "xmalloc.h" +#include "formatregion.h" #if !defined (strchr) && !defined (__STDC__) extern char *strchr (), *strrchr (); @@ -343,6 +344,9 @@ int c_pos, inv_botlin, lb_botlin, lb_linenum; int newlines, lpos, temp; char *prompt_this_line; + char* new_line_buffer; + int new_end; + int new_point; if (!readline_echoing_p) return; @@ -478,10 +482,13 @@ lpos -= screenwidth; } + new_point = rl_point; + rl_fr_expand(&new_line_buffer,&new_end,&new_point); + lb_linenum = 0; - for (in = 0; in < rl_end; in++) + for (in = 0; in < new_end; in++) { - c = (unsigned char)rl_line_buffer[in]; + c = (unsigned char)new_line_buffer[in]; if (out + 8 >= line_size) /* XXX - 8 for \t */ { @@ -491,7 +498,7 @@ line = invisible_line; } - if (in == rl_point) + if (in == new_point) { c_pos = out; lb_linenum = newlines; @@ -557,7 +564,8 @@ inv_lbreaks[++newlines] = out; lpos = 0; } - else if (CTRL_CHAR (c) || c == RUBOUT) + else if (CTRL_CHAR (c) || + c == RUBOUT) { line[out++] = '^'; CHECK_LPOS(); @@ -829,6 +837,7 @@ else visible_wrap_offset = wrap_offset; } + } /* PWP: update_line() is based on finding the middle difference of each diff --new-file --recursive --unified --ignore-space-change readline-4.1/examples/Makefile.in readline-hacked/examples/Makefile.in --- readline-4.1/examples/Makefile.in Tue Sep 21 21:45:37 1999 +++ readline-hacked/examples/Makefile.in Tue Aug 15 17:04:19 2000 @@ -50,13 +50,13 @@ all: $(EXECUTABLES) -rl: rl.o +rl: rl.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ rl.o -lreadline $(TERMCAP_LIB) -fileman: fileman.o +fileman: fileman.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ fileman.o -lreadline $(TERMCAP_LIB) -rltest: rltest.o +rltest: rltest.o $(READLINE_LIB) $(CC) $(LDFLAGS) -o $@ rltest.o -lreadline $(TERMCAP_LIB) rlversion: rlversion.o $(READLINE_LIB) Binary files readline-4.1/examples/core and readline-hacked/examples/core differ diff --new-file --recursive --unified --ignore-space-change readline-4.1/examples/fileman.c readline-hacked/examples/fileman.c --- readline-4.1/examples/fileman.c Thu Sep 2 21:45:52 1999 +++ readline-hacked/examples/fileman.c Sun Sep 17 20:41:23 2000 @@ -36,9 +36,11 @@ #else # include # include +# include #endif extern char *xmalloc (); +char **fileman_completion (); /* The names of functions that actually do the manipulation. */ int com_list (), com_view (), com_rename (), com_stat (), com_pwd (); @@ -98,6 +100,7 @@ progname = argv[0]; initialize_readline (); /* Bind our completer. */ + rl_fr_add_completer(0,1,fileman_completion); /* Loop reading and executing lines until the user quits. */ for ( ; done == 0; ) @@ -206,7 +209,6 @@ /* **************************************************************** */ char *command_generator (); -char **fileman_completion (); /* Tell the GNU Readline library how to complete. We want to try to complete on command names if this is the first word in the line, or on filenames diff --new-file --recursive --unified --ignore-space-change readline-4.1/formatregion.c readline-hacked/formatregion.c --- readline-4.1/formatregion.c Thu Jan 1 01:00:00 1970 +++ readline-hacked/formatregion.c Sun Sep 17 21:28:08 2000 @@ -0,0 +1,485 @@ +#define READLINE_LIBRARY + +#if defined (HAVE_CONFIG_H) +# include +#endif + +#include + +#include "readline.h" +#include "rldefs.h" +#include "formatregion.h" + +#define debug(x...) fprintf(stderr, x) + +static struct rl_fr_region* fr_regions = 0; + +#define fr_tail_completer(fr) ((struct rl_fr_region*)(fr)->private[0]) +#define fr_completer_completer(fr) ((CPPFunction*)(fr)->private[0]) +#define fr_completer_tail(fr) ((struct rl_fr_region*)(fr)->private[1]) + +static char* minimal_suffix(start,end,suffix) + char*start; + char*end; + char*suffix; +{ + char*b,*p,*s; + for(p=start;p*pos) + (*new_point)+=slen; + + safeappend(buffer,len,pos,str,slen); +} + +static inline short fr_holds(fr,point) + struct rl_fr_region* fr; + int point; +{ + return (point >= fr->start && point < fr->end); +} + +static inline short fr_after(fr,point) + struct rl_fr_region* fr; + int point; +{ + return point < fr->start; +} + +static inline void fr_shr(fr,step) + struct rl_fr_region* fr; + int step; +{ + fr->start += step; + fr->end += step; +} + +static inline void fr_shl(fr,step) + struct rl_fr_region* fr; + int step; +{ + fr_shr(fr,-step); +} + + +inline void rl_fr_remove(fr) + struct rl_fr_region* fr; +{ + if(fr->next) + fr->next->prev = fr->prev; + if(fr->prev) + fr->prev->next = fr->next; + if(fr==fr_regions) + fr_regions=fr->next; + + fr->dtor(fr); + + free(fr); +} + +inline short fr_remove_empty(fr) + struct rl_fr_region* fr; +{ + if(fr->end <= fr->start) + { + debug("removing %x from %d - %d\n",(unsigned)fr,fr->start,fr->end); + rl_fr_remove(fr); + return 1; + } + else return 0; +} + +static inline void fr_add(fr) + struct rl_fr_region* fr; +{ + fr->prev = 0; + fr->next = fr_regions; + + if(fr_regions) + fr_regions->prev = fr; + + fr_regions = fr; +} + +static inline void fr_start(fr,start) + struct rl_fr_region* fr; + int start; +{ + fr->start = start; +} + +static inline void fr_end(fr,end) + struct rl_fr_region* fr; + int end; +{ + fr->end = end; +} + +static inline void fr_grow(fr,step) + struct rl_fr_region* fr; + int step; +{ + fr->end += step; +} + +static inline void fr_shrink(fr,step) + struct rl_fr_region* fr; + int step; +{ + fr->end -= step; +} + +static void fr_std_ins(fr,start,length) + struct rl_fr_region* fr; + int start; + int length; +{ +} + +static void fr_std_del(fr,start,length) + struct rl_fr_region* fr; + int start; + int length; +{ +} + +static void fr_std_ponder(fr,buffer) + struct rl_fr_region*fr; + const char*buffer; +{ +} + +static void fr_tail_complete(fr) + struct rl_fr_region* fr; +{ + struct rl_fr_region* completer = fr_tail_completer(fr); + int os=fr->start,oe=fr->end,op=rl_point; + int ocs=completer->start, oce=completer->end; + char**matches = fr_completer_completer(completer) ? + fr_completer_completer(completer)(rl_line_buffer,completer->start,completer->end) : 0; + char*match; + + completer->start = fr->start = -2; + completer->end = fr->end = -1; + + rl_delete_text(os,oe+1); + + + if(matches && (match=*matches)) { + rl_point = os; + + match = minimal_suffix(rl_line_buffer+ocs,rl_line_buffer+oce,match); + + rl_insert_text(match); + fr->end = os+strlen(match); + + free(matches); + + if(op>oe) + rl_point = op-oe + fr->end; + else + rl_point = op; + } + else + fr->end = os; + + fr->start = os; + + completer->start = ocs; + completer->end = oce; + +} + +static void fr_tail_ins(fr,start,length) + struct rl_fr_region* fr; + int start; + int length; +{ + struct rl_fr_region* completer = fr_tail_completer(fr); + fr_end(completer,start+length); + fr_start(fr,start+length); + fr_tail_complete(fr); +} + +static void fr_tail_del(fr,start,length) + struct rl_fr_region* fr; + int start; + int length; +{ + struct rl_fr_region* completer = fr_tail_completer(fr); + int os=fr->start; + + if(start >= fr->start) + { + fr_end(completer,start); + fr_start(fr,start); + } + + fr_tail_complete(fr); +} + + +static void fr_tail_dtor(fr) + struct rl_fr_region* fr; +{ + if(fr_tail_completer(fr)) + { + fr_completer_tail(fr_tail_completer(fr)) = 0; + rl_fr_remove(fr_tail_completer(fr)); + } +} + + +static void fr_completer_ins(fr,start,length) + struct rl_fr_region* fr; + int start; + int length; +{ + fr_std_ins(fr,start,length); + fr_start(fr_completer_tail(fr),fr->end-1); + fr_tail_complete(fr_completer_tail(fr)); +} + +static void fr_completer_del(fr,start,length) + struct rl_fr_region* fr; + int start; + int length; +{ + fr_std_del(fr,start,length); + if(start + length <= fr->end) + fr_tail_complete(fr_completer_tail(fr)); +} + +static void fr_std_dtor(fr) + struct rl_fr_region* fr; +{ +} + +static void fr_completer_dtor(fr) + struct rl_fr_region* fr; +{ + if(fr_completer_tail(fr)) + { + fr_tail_completer(fr_completer_tail(fr)) = 0; + rl_fr_remove(fr_completer_tail(fr)); + } +} + + + + +void rl_fr_inserted(start,length) + int start; + int length; +{ + struct rl_fr_region* fr; + + debug("inserted at %d length %d\n",start,length); + + for(fr=fr_regions;fr;fr=fr->next) + if(fr_after(fr,start)) + fr_shr(fr,length); + else + if(fr_holds(fr,start)) + { + fr_grow(fr,length); + fr->ins(fr,start,length); + } +} + +void rl_fr_deleted(start,length) + int start; + int length; +{ + struct rl_fr_region* fr; + + debug("deleted from %d length %d\n",start,length); + + for(fr=fr_regions;fr;fr=fr->next) + { + if(fr->end <= start) + continue; + + if(fr->start >= start+length) + { + fr_shl(fr,length); + continue; + } + + if(fr->start <= start) + { + if(fr->end >= start+length) + { + fr_shrink(fr,length); + fr->del(fr,start,length); + } + else + { + fr_end(fr,start); + fr->del(fr,start,length); + } + } + else + { + if(fr->end >= start+length) + { + fr_shrink(fr,fr->end - (start+length)); + fr_start(fr,start); + fr->del(fr,start,length); + } + else + { + fr_start(start); + fr_end(start); + fr->del(fr,start,length); + } + } + } +} + +extern int rl_line_buffer_len; + +void rl_fr_expand(new_line_buffer,new_end,new_point) + char**new_line_buffer; + int*new_end; + int*new_point; +{ + char* old_buffer = rl_line_buffer; + unsigned old_len = rl_end; + unsigned rd; + char* buffer; + unsigned wrt = 0; + struct rl_fr_region* fr; + *new_end = old_len; + + buffer = xmalloc(old_len+2); + + for(rd=0;rd<=old_len;rd++) + { + for(fr=fr_regions;fr;fr=fr->next) + { + debug("format at %x (start %d, end %d)\n",(unsigned)fr,fr->start,fr->end); + // fr->ponder(fr,old_buffer); + if(fr->start==rd) + expand_append(&buffer,new_end,&wrt,fr->on,new_point); + if(fr->end-1==rd) + expand_append(&buffer,new_end,&wrt,fr->off,new_point); + } + buffer[wrt++] = old_buffer[rd]; + } + + /* FIXME: free(old_buffer); */ + buffer[wrt] = 0; + + *new_line_buffer=buffer; +} + +inline static void fr_std_init(fr) + struct rl_fr_region*fr; +{ + fr->on = 0; + fr->off = 0; + fr->start = 0; + fr->end = 0; + fr->ponder = fr_std_ponder; + fr->ins = fr_std_ins; + fr->del = fr_std_del; + fr->dtor = fr_std_dtor; + fr->next = fr->prev = 0; +} + +inline static void fr_tail_init(fr,start,completer) + struct rl_fr_region*fr; + int start; + struct rl_fr_region*completer; +{ + fr_std_init(fr); + fr->ins = fr_tail_ins; + fr->del = fr_tail_del; + fr->dtor = fr_tail_dtor; + + fr->start = start; + fr->end = start; + + fr_tail_completer(fr) = completer; + fr_completer_tail(completer) = fr; +} + +inline static void fr_add_tail(start,completer) + int start; + struct rl_fr_region*completer; +{ + struct rl_fr_region*fr=(struct rl_fr_region*)xmalloc(sizeof(struct rl_fr_region)); + + fr_tail_init(fr,start,completer); + fr_add(fr); +} + +inline static void fr_completer_init(fr,start,end,completer) + struct rl_fr_region*fr; + int start; + int end; + CPPFunction*completer; +{ + fr_std_init(fr); + + fr->ins = fr_completer_ins; + fr->del = fr_completer_del; + + fr->start = start; + fr->end = end; + + fr_completer_completer(fr) = completer; + fr->dtor = fr_completer_dtor; +} + +void rl_fr_add_completer(start,end,completer) + int start; + int end; + CPPFunction*completer; +{ + struct rl_fr_region*fr=(struct rl_fr_region*)xmalloc(sizeof(struct rl_fr_region)); + + fr_completer_init(fr,start,end,completer); + fr_add(fr); + fr_add_tail(end,fr); +} + diff --new-file --recursive --unified --ignore-space-change readline-4.1/formatregion.h readline-hacked/formatregion.h --- readline-4.1/formatregion.h Thu Jan 1 01:00:00 1970 +++ readline-hacked/formatregion.h Sun Sep 17 20:29:55 2000 @@ -0,0 +1,51 @@ +#ifndef _FORMATREGION_H_ +#define _FORMATREGION_H_ + +#ifdef __cplusplus +extern "C" { +#endif + + + /* **************************************************************** */ + /* */ + /* Special format region support */ + /* */ + /* **************************************************************** */ + + struct rl_fr_region; + + typedef void (*rl_fr_ponder) __P((struct rl_fr_region*,const char*)); + typedef void (*rl_fr_ins_handler) __P((struct rl_fr_region*,int,int)); + typedef void (*rl_fr_del_handler) __P((struct rl_fr_region*,int,int)); + typedef void (*rl_fr_dtor) __P((struct rl_fr_region*)); + + struct rl_fr_region { + int start; /* inclusive */ + int end; /* exclusive */ + + /* terminal commands */ + char* on; + char* off; + + rl_fr_ponder ponder; + rl_fr_ins_handler ins; + rl_fr_del_handler del; + rl_fr_dtor dtor; + + struct rl_fr_region* next; + struct rl_fr_region* prev; + + void*private[4]; + }; + + extern void rl_fr_add_completer __P((int,int,CPPFunction*)); + extern void rl_fr_remove __P((struct rl_fr_region*)); + extern void rl_fr_expand __P((char**,int*,int*)); + extern void rl_fr_inserted __P((int,int)); + extern void rl_fr_deleted __P((int,int)); + +#ifdef __cplusplus +} +#endif + +#endif /* !_FORMATREGION_H_ */ diff --new-file --recursive --unified --ignore-space-change readline-4.1/readline.c readline-hacked/readline.c --- readline-4.1/readline.c Thu Aug 5 13:10:46 1999 +++ readline-hacked/readline.c Mon Sep 11 19:33:36 2000 @@ -65,6 +65,7 @@ #include "rlprivate.h" #include "rlshell.h" #include "xmalloc.h" +#include "formatregion.h" #ifndef RL_LIBRARY_VERSION # define RL_LIBRARY_VERSION "4.1" @@ -930,9 +931,12 @@ else rl_add_undo (UNDO_INSERT, rl_point, rl_point + l, (char *)NULL); } - rl_point += l; rl_end += l; the_line[rl_end] = '\0'; + + rl_fr_inserted(rl_point,l); + rl_point += l; + return l; } @@ -954,7 +958,7 @@ { to = rl_end; if (from > to) - from = to; + return 0; } text = rl_copy_text (from, to); @@ -972,6 +976,9 @@ rl_end -= diff; the_line[rl_end] = '\0'; + + rl_fr_deleted(from,diff); + return (diff); }