diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/Makefile.in readline-4.2a-hacked/Makefile.in --- readline-4.2a/Makefile.in Fri Nov 2 16:41:09 2001 +++ readline-4.2a-hacked/Makefile.in Sat May 18 23:11:14 2002 @@ -97,20 +97,23 @@ CSOURCES = $(srcdir)/readline.c $(srcdir $(srcdir)/history.c $(srcdir)/histsearch.c $(srcdir)/histexpand.c \ $(srcdir)/histfile.c $(srcdir)/nls.c $(srcdir)/search.c \ $(srcdir)/shell.c $(srcdir)/savestring.c $(srcdir)/tilde.c \ - $(srcdir)/compat.c + $(srcdir)/compat.c \ + $(srcdir)/formatregion.c # The header files for this library. HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \ posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \ ansi_stdlib.h tcap.h rlstdc.h xmalloc.h rlprivate.h rlshell.h \ - rltypedefs.h + rltypedefs.h \ + formatregion.h + HISTOBJ = history.o histexpand.o histfile.o histsearch.o shell.o TILDEOBJ = tilde.o OBJECTS = readline.o vi_mode.o funmap.o keymaps.o parens.o search.o \ rltty.o complete.o bind.o isearch.o display.o signals.o \ util.o kill.o undo.o macro.o input.o callback.o terminal.o \ - nls.o compat.o xmalloc.o $(HISTOBJ) $(TILDEOBJ) + nls.o compat.o xmalloc.o formatregion.o $(HISTOBJ) $(TILDEOBJ) # The texinfo files which document this library. DOCSOURCE = doc/rlman.texinfo doc/rltech.texinfo doc/rluser.texinfo diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/complete.c readline-4.2a-hacked/complete.c --- readline-4.2a/complete.c Mon Oct 15 19:31:41 2001 +++ readline-4.2a-hacked/complete.c Sat May 18 23:44:12 2002 @@ -543,8 +543,8 @@ rl_quote_filename (s, rtype, qcp) quote, or backslash) anywhere in the string. DP, if non-null, is set to the value of the delimiter character that caused a word break. */ -static char -find_completion_word (fp, dp) +char +_rl_find_completion_word (fp, dp) int *fp, *dp; { int scan, end, found_quote, delimiter, pass_next, isbrk; @@ -870,7 +870,9 @@ postprocess_matches (matchesp, matching_ int nmatch, i; matches = *matchesp; - + if(!matches) + return 0; + /* It seems to me that in all the cases we handle we would like to ignore duplicate possiblilities. Scan for the text to insert being identical to the other completions. */ @@ -1247,17 +1249,50 @@ insert_all_matches (matches, point, qc) rl_end_undo_group (); } -static void -free_match_list (matches) +void +_rl_free_match_list (matches) char **matches; { register int i; - + if(!matches) + return; + for (i = 0; matches[i]; i++) free (matches[i]); free (matches); } +char** +_rl_available_completions(start,end,found_quote,quote_char) + int start; + int end; + int found_quote; + char quote_char; +{ + rl_compentry_func_t *our_func; + char *text; + char**matches; + + our_func = rl_completion_entry_function + ? (rl_compentry_func_t *)rl_completion_entry_function + : (rl_compentry_func_t *)rl_filename_completion_function; + text = rl_copy_text (start, end); + matches = gen_completion_matches (text, start, end, our_func, found_quote, quote_char); + free (text); + + /* If we are matching filenames, the attempted completion function will + have set rl_filename_completion_desired to a non-zero value. The basic + filename_completion_function does this. */ + if(!matches) + return 0; + + if(!postprocess_matches (&matches, rl_filename_completion_desired)) + return 0; /* matches is freed by this function on error */ + + return matches; +} + + /* Complete the word at or before point. WHAT_TO_DO says what to do with the completion. `?' means list the possible completions. @@ -1270,7 +1305,6 @@ rl_complete_internal (what_to_do) int what_to_do; { char **matches; - rl_compentry_func_t *our_func; int start, end, delimiter, found_quote, i, nontrivial_lcd; char *text, *saved_line_buffer; char quote_char; @@ -1282,9 +1316,6 @@ rl_complete_internal (what_to_do) rl_completion_type = what_to_do; saved_line_buffer = rl_line_buffer ? savestring (rl_line_buffer) : (char *)NULL; - our_func = rl_completion_entry_function - ? rl_completion_entry_function - : rl_filename_completion_function; /* We now look backwards for the start of a filename/variable word. */ end = rl_point; @@ -1294,17 +1325,16 @@ rl_complete_internal (what_to_do) if (rl_point) /* This (possibly) changes rl_point. If it returns a non-zero char, we know we have an open quote. */ - quote_char = find_completion_word (&found_quote, &delimiter); + quote_char = _rl_find_completion_word (&found_quote, &delimiter); start = rl_point; rl_point = end; - text = rl_copy_text (start, end); - matches = gen_completion_matches (text, start, end, our_func, found_quote, quote_char); - /* nontrivial_lcd is set if the common prefix adds something to the word + matches = _rl_available_completions(start,end,found_quote,quote_char); + + /* nontrivial_lcd is set if the common prefix adds something to the word being completed. */ - nontrivial_lcd = matches && strcmp (text, matches[0]) != 0; - free (text); + nontrivial_lcd = matches && strncmp(rl_line_buffer+start, matches[0], end-start) != 0; if (matches == 0) { @@ -1375,7 +1405,7 @@ rl_complete_internal (what_to_do) return 1; } - free_match_list (matches); + _rl_free_match_list (matches); /* Check to see if the line has changed through all of this manipulation. */ if (saved_line_buffer) @@ -1735,7 +1765,7 @@ rl_menu_complete (count, ignore) /* Clean up from previous call, if any. */ FREE (orig_text); if (matches) - free_match_list (matches); + _rl_free_match_list (matches); match_list_index = match_list_size = 0; matches = (char **)NULL; @@ -1757,7 +1787,7 @@ rl_menu_complete (count, ignore) if (rl_point) /* This (possibly) changes rl_point. If it returns a non-zero char, we know we have an open quote. */ - quote_char = find_completion_word (&found_quote, &delimiter); + quote_char = _rl_find_completion_word (&found_quote, &delimiter); orig_start = rl_point; rl_point = orig_end; diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/display.c readline-4.2a-hacked/display.c --- readline-4.2a/display.c Tue Oct 30 21:11:44 2001 +++ readline-4.2a-hacked/display.c Sat May 18 23:11:14 2002 @@ -52,6 +52,7 @@ #include "history.h" #include "rlprivate.h" +#include "formatregion.h" #include "xmalloc.h" #if !defined (strchr) && !defined (__STDC__) diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/examples/Makefile.in readline-4.2a-hacked/examples/Makefile.in --- readline-4.2a/examples/Makefile.in Wed May 2 15:15:02 2001 +++ readline-4.2a-hacked/examples/Makefile.in Sat May 18 23:11:14 2002 @@ -55,13 +55,13 @@ OBJECTS = fileman.o rltest.o rl.o rlvers all: $(EXECUTABLES) everything: all rlfe -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) diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/formatregion.c readline-4.2a-hacked/formatregion.c --- readline-4.2a/formatregion.c Thu Jan 1 01:00:00 1970 +++ readline-4.2a-hacked/formatregion.c Sat May 25 15:54:50 2002 @@ -0,0 +1,609 @@ +#define READLINE_LIBRARY + +#if defined (HAVE_CONFIG_H) +# include +#endif + +#include + +#include "readline.h" +#include "rlprivate.h" +#include "rldefs.h" +#include "xmalloc.h" + +#include "formatregion.h" + +//#define DEBUG_FORMATREGION + +#ifdef DEBUG_FORMATREGION +static FILE*debout = 0; +#define debug(x...) do { if(debout) {fprintf(debout,x);fflush(debout);} } while(0) +#else +static inline void debug(format) + char*format; + { } +#endif + +static struct rl_fr_region* fr_regions = 0; + +#define fr_tail_completer(fr) ((struct rl_fr_region*)(fr)->private[0]) +#define fr_completer_tail(fr) ((struct rl_fr_region*)(fr)->private[0]) +#define fr_completer_generator(fr) ((rl_fr_completer_generator)(fr)->private[1]) +#define fr_completer_matcher(fr) ((rl_fr_completer_matcher)(fr)->private[2]) +#define fr_completer_user(fr) ((fr)->private[3]) + +static inline void fr_add_tail __P((struct rl_fr_region*)); + +static char* minimal_suffix(start,end,suffix) + char*start; + char*end; + char*suffix; +{ + char*p,*b,*s; + + for(p=start;p=end) + return s; + + if((*b!=*s) || (!*s)) + break; + } + } + } + + return 0; /* no match at all: probably an expansion like $HOME -> + /home/john where we don't want to print + $HOME/home/john */ +} + +static inline void safeappend(char **buffer, unsigned*len, unsigned* pos, char*str, unsigned slen) +{ + if(!str || !slen) + return; + *len+=slen; + (*buffer)=(char*)xrealloc(*buffer,*len); + + { + char*i=(*buffer+*pos); + char*end=(*buffer+*pos+slen); + *pos += slen; + + while(i!=end)*i++=*str++; + } +} + +static inline void expand_append(char **buffer, unsigned*len, unsigned* pos, char*str, int*new_point) +{ + unsigned slen; + + if(!str || !str[0]) return; + + slen = strlen(str); + + if(*new_point>*pos) + (*new_point)+=slen; + + safeappend(buffer,len,pos,str,slen); +} + +static void inline debug_dump_regions() +{ + struct rl_fr_region* fr; + debug("dumping state; line is \"%s\"\n",rl_line_buffer); + for(fr=fr_regions;fr;fr=fr->next) + { + debug("format at %x (start %d, end %d)\n",(unsigned)fr,fr->start,fr->end); + } +} + +static inline short fr_holds_insertwise(fr,point) + struct rl_fr_region* fr; + int point; +{ + if(fr->end==0 && point==0)return 1; + return (point > fr->start && point <= fr->end); + /* Unexpectedly different in/exclusive rules apply: something + inserted at the end belongs to *this* region */ +} +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); + + xfree(fr); +} + +static 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; + + debug("adding %x\n",(unsigned)fr); + + if(fr_regions) + fr_regions->prev = fr; + + fr_regions = fr; + debug_dump_regions(); +} + +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 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; +{ +} + +char** rl_fr_tail_matcher(fr) + struct rl_fr_region* fr; +{ + if(fr->start >= fr->end) + return 0; + + return + fr_completer_generator(fr) ? + fr_completer_generator(fr)(fr,fr->start,fr->end) : 0; +} + +char** rl_fr_word_matcher(fr) + struct rl_fr_region* fr; +{ + int start = fr->start; + int end = fr->end; + + if(end) + { + int saved = rl_point; + + rl_point = end; + + debug("completing word finding in %s from %d to %d\n",rl_line_buffer,start,end); + _rl_find_completion_word (0,0); + start = rl_point; /* (semantics) should it be checked that this is *after* fr->start? */ + debug("completing word found %d to %d: \"",start,end); + for(rl_point = start; rl_point < end; rl_point++){ + debug("%c",rl_line_buffer[rl_point]); + } + debug("\"\n"); + rl_point = saved; + } + if(start>=end||!rl_line_buffer[start])return 0; + return + fr_completer_generator(fr) ? + fr_completer_generator(fr)(fr,start,end) : 0; +} + + +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; + char*match; + + if(!completer->active || !fr->active) + return; + + debug("--- avoiding insert and delete events\n"); + + completer->active = fr->active = 0; + + /* Some stupid programs like yafc are inserting text in the matcher + * function itself */ + matches = fr_completer_matcher(completer) ? + fr_completer_matcher(completer)(completer) : 0; + + if(oe>0) + rl_delete_text(oce,oce + (oe-os)); + + if(matches && (match=*matches) && *match) { + debug("match selected was \"%s\"\n",match); + match = minimal_suffix(rl_line_buffer+ocs,rl_line_buffer+oce,match); + + debug("the minimal suffix was \"%s\"\n", match?match:""); + + if(match) { + rl_point = oce; + rl_insert_text(match); + fr->end = oce+strlen(match); + + if(oe > 0 && op > oe) + rl_point = op-oe + fr->end; + else + rl_point = op; + } + else + fr->end = oce; + } + else + fr->end = oce; + + _rl_free_match_list (matches); + + completer->start = ocs; + completer->end = oce; + fr->start = oce; + + debug("+++ no longer avoiding insert and delete events\n"); + completer->active = fr->active = 1; + debug_dump_regions(); +} + +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 will be added on by rl_fr_inserted */ +} + +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); + + if(start >= completer->end) + completer->end = start; /* for future syntax coloring, otherwise a NOP */ +} + + +static void fr_tail_dtor(fr) + struct rl_fr_region* fr; +{ + if(fr_tail_completer(fr)) + fr_completer_tail(fr_tail_completer(fr)) = 0; +} + + +static void fr_completer_ins(fr,start,length) + struct rl_fr_region* fr; + int start; + int length; +{ + fr_std_ins(fr,start,length); + if(!fr_completer_tail(fr))fr_add_tail(fr); + + 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(!fr_completer_tail(fr))fr_add_tail(fr); + + if(start + length <= fr->end) + fr_tail_complete(fr_completer_tail(fr)); +} + +static void fr_std_clear(fr) + struct rl_fr_region* fr; +{ + rl_fr_remove(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; +} + +static void fr_persist_clear(fr) + struct rl_fr_region* fr; +{ + fr->start = 0; + fr->end = rl_end; +} + +void rl_fr_inserted(start,length) + int start; + int length; +{ + struct rl_fr_region* fr; + + debug("inserted at %d length %d\n",start,length); + debug_dump_regions(); + + for(fr=fr_regions;fr;fr=fr->next){ + if(!fr->active) + continue; + + if((fr->start || start) && fr->start >= start){ + fr_shr(fr,length); + continue; + } + if(fr->end < start) + continue; + fr->end+=length; + debug("->ins to %x\n",(unsigned)fr); + fr->ins(fr,start,length); + } + + debug("post insert\n"); + debug_dump_regions(); +} + +void rl_fr_deleted(start,length) + int start; + int length; +{ + struct rl_fr_region* fr; + + debug("deleted from %d length %d\n",start,length); + debug_dump_regions(); + if(!length) return; + + for(fr=fr_regions;fr;fr=fr->next) + { + if(!fr->active) + continue; + + if(fr->end <= start) + continue; + + if(fr->start >= start+length) + { + fr_shl(fr,length); + continue; + } + + if(fr->start <= start) /* fr->end > start */ + { + if(start+length < fr->end) + { + fr->end -= length; + } + else + { + fr->end = start; + } + } + else /* fr->start > start */ + { + if(start+length < fr->end) + { + fr->end -= length - (fr->start - start); + fr->start = start; + } + else /* start+length >= fr-> end && fr->start < start*/ + { + fr->start = start; + fr->end = start; + } + } + debug("->del to %x\n",(unsigned)fr); + fr->del(fr,start,length); + } + debug("post delete\n"); + debug_dump_regions(); +} + + +inline static void fr_std_init(fr) + struct rl_fr_region*fr; +{ + fr->active = 1; + 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->clear = fr_std_clear; + + fr->next = fr->prev = 0; +} + +inline static void fr_tail_init(fr,completer) + struct rl_fr_region*fr; + 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_tail_completer(fr) = completer; + fr_completer_tail(completer) = fr; +} + +inline static void fr_add_tail(completer) + struct rl_fr_region*completer; +{ + struct rl_fr_region*fr=(struct rl_fr_region*)xmalloc(sizeof(struct rl_fr_region)); + + fr_tail_init(fr,completer); + fr_start(fr,-1); + fr_end(fr,-1); + + fr_add(fr); +} + +inline static void fr_completer_init(fr,matcher,generator,userhook) + struct rl_fr_region*fr; + rl_fr_completer_matcher matcher; + rl_fr_completer_generator generator; + void* userhook; +{ + fr_std_init(fr); + + fr->ins = fr_completer_ins; + fr->del = fr_completer_del; + + fr_completer_matcher(fr) = matcher; + fr_completer_generator(fr) = generator; + fr_completer_user(fr) = userhook; + fr_completer_tail(fr) = 0; + + fr->dtor = fr_completer_dtor; +} + +void rl_fr_add_completer(start,end,matcher,generator,userhook) + int start; + int end; + rl_fr_completer_matcher matcher; + rl_fr_completer_generator generator; + void* userhook; +{ + struct rl_fr_region*fr=(struct rl_fr_region*)xmalloc(sizeof(struct rl_fr_region)); + + fr_completer_init(fr,matcher,generator,userhook); + fr_start(fr,start); + fr_end(fr,end); + + fr_add(fr); +} + +static void init_fr() +{ +#ifdef DEBUG_FORMATREGION + if(!debout){ + debout = fopen("/tmp/debout","w"); + } +#endif + if(!fr_regions){ + rl_fr_add_completer(0,0, + rl_fr_word_matcher, + rl_fr_cppfunction_generator, + rl_fr_default_matches); + rl_fr_persist(fr_regions); + } +} + + +void rl_fr_clear() + /* called when a new line appears */ +{ + struct rl_fr_region *fr, *next; + init_fr(); + + debug("clearing\n"); + debug_dump_regions(); + for(fr=fr_regions;fr;fr=next) + { + debug("clearing format at %x (start %d, end %d)\n",(unsigned)fr,fr->start,fr->end); + next=fr->next; + fr->clear(fr); /* most probably will delete the poor thing */ + } +} + +void rl_fr_persist(fr) + struct rl_fr_region*fr; +{ + fr->clear = fr_persist_clear; +} + +char** rl_fr_cpfunction_generator(fr,start,end) + struct rl_fr_region* fr; + int start; + int end; +{ + char*text = rl_copy_text(start,end); + char**matches = completion_matches (text,(CPFunction*)fr_completer_user(fr)); + debug("cpfunction generator\n"); + xfree(text); + return matches; +} + +char** rl_fr_cppfunction_generator(fr,start,end) + struct rl_fr_region* fr; + int start; + int end; +{ + debug("cppfunction generator\n"); + + return ((CPPFunction*)fr_completer_user(fr))(rl_line_buffer,start,end); +} + + +char** rl_fr_default_matches(text,start,end) + char*text; + int start; + int end; +{ + if(text != rl_line_buffer)abort(); + + return _rl_available_completions(start,end,0,0); +} diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/formatregion.h readline-4.2a-hacked/formatregion.h --- readline-4.2a/formatregion.h Thu Jan 1 01:00:00 1970 +++ readline-4.2a-hacked/formatregion.h Sat May 25 15:49:18 2002 @@ -0,0 +1,72 @@ +#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_clear_handler) __P((struct rl_fr_region*)); + typedef void (*rl_fr_dtor) __P((struct rl_fr_region*)); + + struct rl_fr_region { + int active; + 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; + rl_fr_clear_handler clear; + + struct rl_fr_region* next; + struct rl_fr_region* prev; + + void*private[8]; + }; + + typedef char** (*rl_fr_completer_matcher) __P((struct rl_fr_region*)); + typedef char** (*rl_fr_completer_generator) __P((struct rl_fr_region*,int,int)); + + extern void rl_fr_add_completer __P((int,int,rl_fr_completer_matcher,rl_fr_completer_generator,void*)); + + /* A selection of rl_fr_completer_matchers: */ + extern char** rl_fr_tail_matcher __P((struct rl_fr_region*)); + extern char** rl_fr_word_matcher __P((struct rl_fr_region*)); + + /* A selection of rl_fr_completer_generators: */ + extern char** rl_fr_cpfunction_generator __P((struct rl_fr_region*,int,int)); + extern char** rl_fr_cppfunction_generator __P((struct rl_fr_region*,int,int)); + + extern void rl_fr_persist __P((struct rl_fr_region*)); + + extern void rl_fr_remove __P((struct rl_fr_region*)); + extern void rl_fr_inserted __P((int,int)); + extern void rl_fr_deleted __P((int,int)); + extern void rl_fr_clear __P((void)); + + extern char** rl_fr_default_matches __P((char*,int,int)); + + /* extern void rl_fr_expand __P((char**,int*,int*));*/ + +#ifdef __cplusplus +} +#endif + +#endif /* !_FORMATREGION_H_ */ diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/isearch.c readline-4.2a-hacked/isearch.c --- readline-4.2a/isearch.c Mon Oct 15 17:25:17 2001 +++ readline-4.2a-hacked/isearch.c Sat May 18 23:11:14 2002 @@ -319,9 +319,8 @@ rl_search_history (direction, invoking_k break; case CTRL ('G'): - strcpy (rl_line_buffer, lines[orig_line]); + rl_replace_line(lines[orig_line]); rl_point = orig_point; - rl_end = strlen (rl_line_buffer); rl_restore_prompt(); rl_clear_message (); if (allocated_line) @@ -417,17 +416,11 @@ rl_search_history (direction, invoking_k the location. */ if (found) { - int line_len; - prev_line_found = lines[i]; - line_len = strlen (lines[i]); - if (line_len >= rl_line_buffer_len) - rl_extend_line_buffer (line_len); + rl_replace_line(lines[i]); - strcpy (rl_line_buffer, lines[i]); rl_point = line_index; - rl_end = line_len; last_found_line = i; rl_display_search (search_string, reverse, (i == orig_line) ? -1 : i); } diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/readline.c readline-4.2a-hacked/readline.c --- readline-4.2a/readline.c Wed Nov 7 22:01:58 2001 +++ readline-4.2a-hacked/readline.c Sat May 18 23:33:23 2002 @@ -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.2a" @@ -510,6 +511,8 @@ _rl_init_line_state () rl_point = rl_end = 0; the_line = rl_line_buffer; the_line[0] = 0; + + rl_fr_clear(); } void @@ -972,7 +975,7 @@ rl_universal_argument (count, key) /* **************************************************************** */ /* */ -/* Insert and Delete */ +/* Insert, replace and Delete */ /* */ /* **************************************************************** */ @@ -1005,12 +1008,31 @@ rl_insert_text (string) 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; } +/* This is the only way in which the_line should be overwritten */ + +void rl_replace_line(string) + char*string; +{ + int len=strlen(string); + + if (len >= rl_line_buffer_len) + rl_extend_line_buffer (len); + + strcpy(the_line, string); + rl_end = len; + + rl_fr_clear(); +} + /* Delete the string between FROM and TO. FROM is inclusive, TO is not. */ int @@ -1029,7 +1051,7 @@ rl_delete_text (from, to) { to = rl_end; if (from > to) - from = to; + return 0; } text = rl_copy_text (from, to); @@ -1047,6 +1069,9 @@ rl_delete_text (from, to) rl_end -= diff; the_line[rl_end] = '\0'; + + rl_fr_deleted(from,diff); + return (diff); } @@ -1943,6 +1968,7 @@ rl_maybe_replace_line () free (temp->line); free (temp); } + return 0; } @@ -1954,16 +1980,12 @@ rl_maybe_unsave_line () if (_rl_saved_line_for_history) { - line_len = strlen (_rl_saved_line_for_history->line); - - if (line_len >= rl_line_buffer_len) - rl_extend_line_buffer (line_len); - - strcpy (the_line, _rl_saved_line_for_history->line); + rl_replace_line(_rl_saved_line_for_history->line); + rl_undo_list = (UNDO_LIST *)_rl_saved_line_for_history->data; _rl_free_history_entry (_rl_saved_line_for_history); _rl_saved_line_for_history = (HIST_ENTRY *)NULL; - rl_end = rl_point = strlen (the_line); + rl_point = rl_end; } else rl_ding (); @@ -2019,13 +2041,35 @@ rl_end_of_history (count, key) return 0; } +/* Replace the current line with one from the history */ +void +rl_become_history(temp) + HIST_ENTRY* temp; +{ + int line_len; + + rl_replace_line(temp->line); + + rl_undo_list = (UNDO_LIST *)temp->data; + rl_point = (_rl_history_preserve_point && _rl_history_saved_point != -1) + ? _rl_history_saved_point + : rl_end; + if (rl_point > rl_end) + rl_point = rl_end; + +#if defined (VI_MODE) + if (rl_editing_mode == vi_mode) + rl_point = 0; +#endif /* VI_MODE */ +} + + /* Move down to the next history line. */ int rl_get_next_history (count, key) int count, key; { HIST_ENTRY *temp; - int line_len; if (count < 0) return (rl_get_previous_history (-count, key)); @@ -2051,25 +2095,8 @@ rl_get_next_history (count, key) if (temp == 0) rl_maybe_unsave_line (); else - { - line_len = strlen (temp->line); + rl_become_history(temp); - if (line_len >= rl_line_buffer_len) - rl_extend_line_buffer (line_len); - - strcpy (the_line, temp->line); - rl_undo_list = (UNDO_LIST *)temp->data; - rl_end = strlen (the_line); - rl_point = (_rl_history_preserve_point && _rl_history_saved_point != -1) - ? _rl_history_saved_point - : rl_end; - if (rl_point > rl_end) - rl_point = rl_end; -#if defined (VI_MODE) - if (rl_editing_mode == vi_mode) - rl_point = 0; -#endif /* VI_MODE */ - } return 0; } @@ -2080,7 +2107,6 @@ rl_get_previous_history (count, key) int count, key; { HIST_ENTRY *old_temp, *temp; - int line_len; if (count < 0) return (rl_get_next_history (-count, key)); @@ -2117,26 +2143,7 @@ rl_get_previous_history (count, key) if (temp == 0) rl_ding (); else - { - line_len = strlen (temp->line); - - if (line_len >= rl_line_buffer_len) - rl_extend_line_buffer (line_len); - - strcpy (the_line, temp->line); - rl_undo_list = (UNDO_LIST *)temp->data; - rl_end = line_len; - rl_point = (_rl_history_preserve_point && _rl_history_saved_point != -1) - ? _rl_history_saved_point - : rl_end; - if (rl_point > rl_end) - rl_point = rl_end; - -#if defined (VI_MODE) - if (rl_editing_mode == vi_mode) - rl_point = 0; -#endif /* VI_MODE */ - } + rl_become_history(temp); return 0; } diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/readline.h readline-4.2a-hacked/readline.h --- readline-4.2a/readline.h Wed Sep 12 15:05:55 2001 +++ readline-4.2a-hacked/readline.h Sat May 18 23:33:14 2002 @@ -366,6 +366,7 @@ extern void rl_restore_prompt PARAMS((vo /* Modifying text. */ extern int rl_insert_text PARAMS((const char *)); +extern void rl_replace_line PARAMS((char*)); extern int rl_delete_text PARAMS((int, int)); extern int rl_kill_text PARAMS((int, int)); extern char *rl_copy_text PARAMS((int, int)); diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/rlprivate.h readline-4.2a-hacked/rlprivate.h --- readline-4.2a/rlprivate.h Mon Oct 29 15:24:34 2001 +++ readline-4.2a-hacked/rlprivate.h Sat May 18 23:11:14 2002 @@ -77,6 +77,11 @@ extern int rl_discard_argument PARAMS((v /* rltty.c */ extern int rl_stop_output PARAMS((int, int)); +/* complete.c */ +extern char** _rl_available_completions __P((int,int,int,char)); +extern char _rl_find_completion_word __P((int*, int*)); +extern void _rl_free_match_list __P((char**)); + /* terminal.c */ extern void _rl_set_screen_size PARAMS((int, int)); diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/search.c readline-4.2a-hacked/search.c --- readline-4.2a/search.c Wed Aug 22 14:39:52 2001 +++ readline-4.2a-hacked/search.c Sat May 18 23:11:14 2002 @@ -80,15 +80,8 @@ static void make_history_line_current (entry) HIST_ENTRY *entry; { - int line_len; - - line_len = strlen (entry->line); - if (line_len >= rl_line_buffer_len) - rl_extend_line_buffer (line_len); - strcpy (rl_line_buffer, entry->line); - + rl_replace_line(entry->line); rl_undo_list = (UNDO_LIST *)entry->data; - rl_end = line_len; if (_rl_saved_line_for_history) _rl_free_history_entry (_rl_saved_line_for_history); @@ -191,6 +184,7 @@ noninc_search (dir, pchar) /* Use the line buffer to read the search string. */ rl_line_buffer[0] = 0; rl_end = rl_point = 0; + rl_fr_clear(); p = _rl_make_prompt_for_search (pchar ? pchar : ':'); rl_message (p, 0, 0); @@ -372,6 +366,7 @@ rl_history_search_internal (count, dir) if (rl_point > rl_history_search_len) { rl_point = rl_end = rl_history_search_len; + rl_fr_clear(); rl_line_buffer[rl_end] = '\0'; } #else diff --new-file -upr --exclude *~ --exclude *.rej --exclude #* readline-4.2a/shlib/Makefile.in readline-4.2a-hacked/shlib/Makefile.in --- readline-4.2a/shlib/Makefile.in Fri Nov 2 16:41:23 2001 +++ readline-4.2a-hacked/shlib/Makefile.in Sat May 18 23:11:14 2002 @@ -114,19 +114,22 @@ CSOURCES = $(topdir)/readline.c $(topdir $(topdir)/history.c $(topdir)/histsearch.c $(topdir)/histexpand.c \ $(topdir)/histfile.c $(topdir)/nls.c $(topdir)/search.c \ $(topdir)/shell.c $(topdir)/savestring.c $(topdir)/compat.c \ - $(topdir)/tilde.c + $(topdir)/tilde.c \ + $(srcdir)/formatregion.c # The header files for this library. HSOURCES = readline.h rldefs.h chardefs.h keymaps.h history.h histlib.h \ posixstat.h posixdir.h posixjmp.h tilde.h rlconf.h rltty.h \ - ansi_stdlib.h tcap.h xmalloc.h rlprivate.h rlshell.h + ansi_stdlib.h tcap.h xmalloc.h rlprivate.h rlshell.h \ + formatregion.h SHARED_HISTOBJ = history.so histexpand.so histfile.so histsearch.so shell.so SHARED_TILDEOBJ = tilde.so SHARED_OBJ = readline.so vi_mode.so funmap.so keymaps.so parens.so search.so \ rltty.so complete.so bind.so isearch.so display.so signals.so \ util.so kill.so undo.so macro.so input.so callback.so terminal.so \ - nls.so xmalloc.so $(SHARED_HISTOBJ) $(SHARED_TILDEOBJ) compat.so + nls.so xmalloc.so $(SHARED_HISTOBJ) $(SHARED_TILDEOBJ) compat.so \ + formatregion.so ##########################################################################